@@ -65,31 +65,31 @@ namespace
65
65
png_structp pngPtrCurrent = NULL ; // This will be either the same as above, or a temp image when using disk caching
66
66
FILE *gPngPartialFileHandle = NULL ;
67
67
68
- inline void blend (uint8_t *destination, const uint8_t *source);
69
- inline void modColor (uint8_t *color, const int mod);
70
- inline void addColor (uint8_t *color, uint8_t *add);
68
+ inline void blend (uint8_t * const destination, const uint8_t * const source);
69
+ inline void modColor (uint8_t * const color, const int mod);
70
+ inline void addColor (uint8_t * const color, const uint8_t * const add);
71
71
72
72
// Split them up so setPixel won't be one hell of a mess
73
- void setSnow (const size_t x, const size_t y, const uint8_t *color);
74
- void setTorch (const size_t x, const size_t y, const uint8_t *color);
75
- void setFlower (const size_t x, const size_t y, const uint8_t *color);
76
- void setRedwire (const size_t x, const size_t y, const uint8_t *color);
77
- void setFire (const size_t x, const size_t y, uint8_t *color, uint8_t *light, uint8_t *dark);
78
- void setGrass (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark, const int & sub);
79
- void setFence (const size_t x, const size_t y, const uint8_t *color);
80
- void setStep (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark);
73
+ void setSnow (const size_t x, const size_t y, const uint8_t * const color);
74
+ void setTorch (const size_t x, const size_t y, const uint8_t * const color);
75
+ void setFlower (const size_t x, const size_t y, const uint8_t * const color);
76
+ void setRedwire (const size_t x, const size_t y, const uint8_t * const color);
77
+ void setFire (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark);
78
+ void setGrass (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark, const int sub);
79
+ void setFence (const size_t x, const size_t y, const uint8_t * const color);
80
+ void setStep (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark);
81
81
# define setRailroad setSnowBA
82
82
83
83
// Then make duplicate copies so it is one hell of a mess
84
84
// ..but hey, its for speeeeeeeeed!
85
- void setSnowBA (const size_t x, const size_t y, const uint8_t *color);
86
- void setTorchBA (const size_t x, const size_t y, const uint8_t *color);
87
- void setFlowerBA (const size_t x, const size_t y, const uint8_t *color);
88
- void setGrassBA (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark, const int & sub);
89
- void setStepBA (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark);
85
+ void setSnowBA (const size_t x, const size_t y, const uint8_t * const color);
86
+ void setTorchBA (const size_t x, const size_t y, const uint8_t * const color);
87
+ void setFlowerBA (const size_t x, const size_t y, const uint8_t * const color);
88
+ void setGrassBA (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark, const int sub);
89
+ void setStepBA (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark);
90
90
}
91
91
92
- void createImageBuffer (size_t width, size_t height, bool splitUp)
92
+ void createImageBuffer (const size_t width, const size_t height, const bool splitUp)
93
93
{
94
94
gPngLocalWidth = gPngWidth = (int )width;
95
95
gPngLocalHeight = gPngHeight = (int )height;
@@ -102,7 +102,7 @@ void createImageBuffer(size_t width, size_t height, bool splitUp)
102
102
}
103
103
}
104
104
105
- bool createImage (FILE *fh, size_t width, size_t height, bool splitUp)
105
+ bool createImage (FILE *fh, const size_t width, const size_t height, const bool splitUp)
106
106
{
107
107
gPngLocalWidth = gPngWidth = (int )width;
108
108
gPngLocalHeight = gPngHeight = (int )height;
@@ -293,7 +293,7 @@ bool saveImage()
293
293
/* *
294
294
* @return 0 = OK, -1 = Error, 1 = Zero/Negative size
295
295
*/
296
- int loadImagePart (int startx, int starty, int width, int height)
296
+ int loadImagePart (const int startx, const int starty, const int width, const int height)
297
297
{
298
298
// These are set to NULL in saveImahePartPng to make sure the two functions are called in turn
299
299
if (pngPtrCurrent != NULL || gPngPartialFileHandle != NULL ) {
@@ -303,29 +303,31 @@ int loadImagePart(int startx, int starty, int width, int height)
303
303
// In case the image needs to be cropped the offsets will be negative
304
304
gOffsetX = MIN (startx, 0 );
305
305
gOffsetY = MIN (starty, 0 );
306
- // Also modify width and height in these cases
307
- if (startx < 0 ) {
308
- width += startx;
309
- startx = 0 ;
306
+ gPngLocalWidth = width;
307
+ gPngLocalHeight = height;
308
+ int localX = startx;
309
+ int localY = starty;
310
+ // Also modify gPngLocalWidth and gPngLocalHeight in these cases
311
+ if (localX < 0 ) {
312
+ gPngLocalWidth += localX;
313
+ localX = 0 ;
310
314
}
311
- if (starty < 0 ) {
312
- height += starty ;
313
- starty = 0 ;
315
+ if (localY < 0 ) {
316
+ gPngLocalHeight += localY ;
317
+ localY = 0 ;
314
318
}
315
- if (startx + width > gPngWidth ) {
316
- width = gPngWidth - startx ;
319
+ if (localX + gPngLocalWidth > gPngWidth ) {
320
+ gPngLocalWidth = gPngWidth - localX ;
317
321
}
318
- if (starty + height > gPngHeight ) {
319
- height = gPngHeight - starty ;
322
+ if (localY + gPngLocalHeight > gPngHeight ) {
323
+ gPngLocalHeight = gPngHeight - localY ;
320
324
}
321
- if (width < 1 || height < 1 ) return 1 ;
325
+ if (gPngLocalWidth < 1 || gPngLocalHeight < 1 ) return 1 ;
322
326
char name[200 ];
323
- snprintf (name, 200 , " cache/%d.%d.%d.%d.%d.png" , startx, starty, width, height , (int )time (NULL ));
324
- ImagePart *img = new ImagePart (name, startx, starty, width, height );
327
+ snprintf (name, 200 , " cache/%d.%d.%d.%d.%d.png" , localX, localY, gPngLocalWidth , gPngLocalHeight , (int )time (NULL ));
328
+ ImagePart *img = new ImagePart (name, localX, localY, gPngLocalWidth , gPngLocalHeight );
325
329
partialImages.push_back (img);
326
330
// alloc mem for image and open tempfile
327
- gPngLocalWidth = width;
328
- gPngLocalHeight = height;
329
331
gPngLocalLineWidthChans = gPngLocalWidth * CHANSPERPIXEL;
330
332
uint64_t size = (uint64_t )gPngLocalLineWidthChans * (uint64_t )gPngLocalHeight ;
331
333
printf (" Creating temporary image: %dx%d, 32bpp, %.2fMiB\n " , gPngLocalWidth , gPngLocalHeight , float (size / float (1024 * 1024 )));
@@ -599,14 +601,14 @@ bool composeFinalImage()
599
601
return true ;
600
602
}
601
603
602
- uint64_t calcImageSize (int mapChunksX, int mapChunksZ, size_t mapHeight, int &pixelsX, int &pixelsY, bool tight)
604
+ uint64_t calcImageSize (const int mapChunksX, const int mapChunksZ, const size_t mapHeight, int &pixelsX, int &pixelsY, const bool tight)
603
605
{
604
606
pixelsX = (mapChunksX * CHUNKSIZE_X + mapChunksZ * CHUNKSIZE_Z) * 2 + (tight ? 3 : 10 );
605
607
pixelsY = (mapChunksX * CHUNKSIZE_X + mapChunksZ * CHUNKSIZE_Z + int (mapHeight) * g_OffsetY) + (tight ? 3 : 10 );
606
608
return uint64_t (pixelsX) * BYTESPERPIXEL * uint64_t (pixelsY);
607
609
}
608
610
609
- void setPixel (size_t x, size_t y, uint8_t color, float fsub)
611
+ void setPixel (const size_t x, const size_t y, const uint8_t color, const float fsub)
610
612
{
611
613
// Sets pixels around x,y where A is the anchor
612
614
// T = given color, D = darker, L = lighter
@@ -791,7 +793,7 @@ void setPixel(size_t x, size_t y, uint8_t color, float fsub)
791
793
// The above two branches are almost the same, maybe one could just create a function pointer and...
792
794
}
793
795
794
- void blendPixel (size_t x, size_t y, uint8_t color, float fsub)
796
+ void blendPixel (const size_t x, const size_t y, const uint8_t color, const float fsub)
795
797
{
796
798
// This one is used for cave overlay
797
799
// Sets pixels around x,y where A is the anchor
@@ -835,7 +837,7 @@ void blendPixel(size_t x, size_t y, uint8_t color, float fsub)
835
837
namespace
836
838
{
837
839
838
- inline void blend (uint8_t *destination, const uint8_t *source)
840
+ inline void blend (uint8_t * const destination, const uint8_t * const source)
839
841
{
840
842
if (destination[PALPHA] == 0 || source[PALPHA] == 255 ) {
841
843
memcpy (destination, source, BYTESPERPIXEL);
@@ -848,14 +850,14 @@ namespace
848
850
destination[PALPHA] += (size_t (source[PALPHA]) * size_t (255 - destination[PALPHA])) / 255 ;
849
851
}
850
852
851
- inline void modColor (uint8_t *color, const int mod)
853
+ inline void modColor (uint8_t * const color, const int mod)
852
854
{
853
855
color[0 ] = clamp (color[0 ] + mod);
854
856
color[1 ] = clamp (color[1 ] + mod);
855
857
color[2 ] = clamp (color[2 ] + mod);
856
858
}
857
859
858
- inline void addColor (uint8_t *color, uint8_t *add)
860
+ inline void addColor (uint8_t * const color, const uint8_t * const add)
859
861
{
860
862
const float v2 = (float (add[PALPHA]) / 255 .0f );
861
863
const float v1 = (1 .0f - (v2 * .2f ));
@@ -864,7 +866,7 @@ namespace
864
866
color[2 ] = clamp (uint16_t (float (color[2 ]) * v1 + float (add[2 ]) * v2));
865
867
}
866
868
867
- void setSnow (const size_t x, const size_t y, const uint8_t *color)
869
+ void setSnow (const size_t x, const size_t y, const uint8_t * const color)
868
870
{
869
871
// Top row (second row)
870
872
uint8_t *pos = &PIXEL (x, y+1 );
@@ -873,7 +875,7 @@ namespace
873
875
}
874
876
}
875
877
876
- void setTorch (const size_t x, const size_t y, const uint8_t *color)
878
+ void setTorch (const size_t x, const size_t y, const uint8_t * const color)
877
879
{
878
880
// Maybe the orientation should be considered when drawing, but it probably isn't worth the efford
879
881
uint8_t *pos = &PIXEL (x+2 , y+1 );
@@ -882,7 +884,7 @@ namespace
882
884
memcpy (pos, color, BYTESPERPIXEL);
883
885
}
884
886
885
- void setFlower (const size_t x, const size_t y, const uint8_t *color)
887
+ void setFlower (const size_t x, const size_t y, const uint8_t * const color)
886
888
{
887
889
uint8_t *pos = &PIXEL (x, y+1 );
888
890
memcpy (pos+(CHANSPERPIXEL), color, BYTESPERPIXEL);
@@ -893,7 +895,7 @@ namespace
893
895
memcpy (pos, color, BYTESPERPIXEL);
894
896
}
895
897
896
- void setFire (const size_t x, const size_t y, uint8_t *color, uint8_t *light, uint8_t *dark)
898
+ void setFire (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark)
897
899
{
898
900
// This basically just leaves out a few pixels
899
901
// Top row
@@ -913,7 +915,7 @@ namespace
913
915
blend (pos+(CHANSPERPIXEL*2 ), light);
914
916
}
915
917
916
- void setGrass (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark, const int & sub)
918
+ void setGrass (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark, const int sub)
917
919
{
918
920
// this will make grass look like dirt from the side
919
921
uint8_t L[CHANSPERPIXEL], D[CHANSPERPIXEL];
@@ -954,7 +956,7 @@ namespace
954
956
memcpy (pos+CHANSPERPIXEL*3 , L, BYTESPERPIXEL);
955
957
}
956
958
957
- void setFence (const size_t x, const size_t y, const uint8_t *color)
959
+ void setFence (const size_t x, const size_t y, const uint8_t * const color)
958
960
{
959
961
// First row
960
962
uint8_t *pos = &PIXEL (x, y);
@@ -969,7 +971,7 @@ namespace
969
971
blend (pos+CHANSPERPIXEL*2 , color);
970
972
}
971
973
972
- void setStep (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark)
974
+ void setStep (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark)
973
975
{
974
976
uint8_t *pos = &PIXEL (x, y+1 );
975
977
for (size_t i = 0 ; i < 4 ; ++i, pos += CHANSPERPIXEL) {
@@ -981,7 +983,7 @@ namespace
981
983
}
982
984
}
983
985
984
- void setRedwire (const size_t x, const size_t y, const uint8_t *color)
986
+ void setRedwire (const size_t x, const size_t y, const uint8_t * const color)
985
987
{
986
988
uint8_t *pos = &PIXEL (x+1 , y+2 );
987
989
blend (pos, color);
@@ -990,7 +992,7 @@ namespace
990
992
991
993
// The g_BlendAll versions of the block set functions
992
994
//
993
- void setSnowBA (const size_t x, const size_t y, const uint8_t *color)
995
+ void setSnowBA (const size_t x, const size_t y, const uint8_t * const color)
994
996
{
995
997
// Top row (second row)
996
998
uint8_t *pos = &PIXEL (x, y+1 );
@@ -999,7 +1001,7 @@ namespace
999
1001
}
1000
1002
}
1001
1003
1002
- void setTorchBA (const size_t x, const size_t y, const uint8_t *color)
1004
+ void setTorchBA (const size_t x, const size_t y, const uint8_t * const color)
1003
1005
{
1004
1006
// Maybe the orientation should be considered when drawing, but it probably isn't worth the effort
1005
1007
uint8_t *pos = &PIXEL (x+2 , y+1 );
@@ -1008,7 +1010,7 @@ namespace
1008
1010
blend (pos, color);
1009
1011
}
1010
1012
1011
- void setFlowerBA (const size_t x, const size_t y, const uint8_t *color)
1013
+ void setFlowerBA (const size_t x, const size_t y, const uint8_t * const color)
1012
1014
{
1013
1015
uint8_t *pos = &PIXEL (x, y+1 );
1014
1016
blend (pos+CHANSPERPIXEL, color);
@@ -1019,7 +1021,7 @@ namespace
1019
1021
blend (pos, color);
1020
1022
}
1021
1023
1022
- void setGrassBA (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark, const int & sub)
1024
+ void setGrassBA (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark, const int sub)
1023
1025
{
1024
1026
// this will make grass look like dirt from the side
1025
1027
uint8_t L[CHANSPERPIXEL], D[CHANSPERPIXEL];
@@ -1060,7 +1062,7 @@ namespace
1060
1062
blend (pos+CHANSPERPIXEL*3 , L);
1061
1063
}
1062
1064
1063
- void setStepBA (const size_t x, const size_t y, const uint8_t *color, const uint8_t *light, const uint8_t *dark)
1065
+ void setStepBA (const size_t x, const size_t y, const uint8_t * const color, const uint8_t * const light, const uint8_t * const dark)
1064
1066
{
1065
1067
uint8_t *pos = &PIXEL (x, y+1 );
1066
1068
for (size_t i = 0 ; i < 3 ; ++i, pos += CHANSPERPIXEL) {
0 commit comments