@@ -103,7 +103,6 @@ void* lodepng_realloc(void* ptr, size_t new_size);
103103#define LODEPNG_RESTRICT /* not available */
104104#endif
105105
106- #define LODEPNG_ABS (x ) ((x) < 0 ? -(x) : (x))
107106#define LODEPNG_MAX (a, b ) (((a) > (b)) ? (a) : (b))
108107
109108#if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)
@@ -228,7 +227,7 @@ static char* alloc_string(const char* in) {
228227#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG)
229228static unsigned lodepng_read32bitInt (const unsigned char * buffer) {
230229 return (((unsigned )buffer[0 ] << 24u ) | ((unsigned )buffer[1 ] << 16u ) |
231- ((unsigned )buffer[2 ] << 8u ) | (unsigned )buffer[3 ]);
230+ ((unsigned )buffer[2 ] << 8u ) | (unsigned )buffer[3 ]);
232231}
233232#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG)*/
234233
@@ -664,11 +663,11 @@ static unsigned checkColorValidity(LodePNGColorType colortype, unsigned bd) {
664663
665664static unsigned getNumColorChannels (LodePNGColorType colortype) {
666665 switch (colortype) {
667- case LCT_GREY: return 1 ;
668- case LCT_RGB: return 3 ;
669- case LCT_PALETTE: return 1 ;
670- case LCT_GREY_ALPHA: return 2 ;
671- case LCT_RGBA: return 4 ;
666+ case LCT_GREY: return 1 ;
667+ case LCT_RGB: return 3 ;
668+ case LCT_PALETTE: return 1 ;
669+ case LCT_GREY_ALPHA: return 2 ;
670+ case LCT_RGBA: return 4 ;
672671 case LCT_MAX_OCTET_VALUE: return 0 ; /* invalid color type */
673672 default : return 0 ; /* invalid color type*/
674673 }
@@ -1612,11 +1611,10 @@ static unsigned getValueRequiredBits(unsigned char value) {
16121611}
16131612
16141613/* stats must already have been inited. */
1615- unsigned lodepng_compute_color_stats (LodePNGColorStats* stats,
1616- const unsigned char * in, const size_t numpixels,
1617- const LodePNGColorMode* mode_in) {
1614+ void lodepng_compute_color_stats (LodePNGColorStats* stats,
1615+ const unsigned char * in, const size_t numpixels,
1616+ const LodePNGColorMode* mode_in) {
16181617 size_t i;
1619- unsigned error = 0 ;
16201618
16211619 /* mark things as done already if it would be impossible to have a more expensive case */
16221620 unsigned colored_done = lodepng_is_greyscale_type (mode_in) ? 1 : 0 ;
@@ -2047,9 +2045,9 @@ The parameters are of type short, but should come from unsigned chars, the short
20472045are only needed to make the paeth calculation correct.
20482046*/
20492047static unsigned char paethPredictor (short a, short b, short c) {
2050- short pa = LODEPNG_ABS (b - c);
2051- short pb = LODEPNG_ABS (a - c);
2052- short pc = LODEPNG_ABS (a + b - c - c);
2048+ short pa = abs (b - c);
2049+ short pb = abs (a - c);
2050+ short pc = abs (a + b - c - c);
20532051 /* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */
20542052 if (pb < pa) { a = b; pa = pb; }
20552053 return (pc < pa) ? c : a;
@@ -3179,7 +3177,7 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
31793177 break ;
31803178 case 1 : { /* Sub*/
31813179 size_t j = 0 ;
3182- memcpy (out, scanline, bytewidth) ;
3180+ for (i = 0 ; i != bytewidth; ++i) out[i] = scanline[i] ;
31833181 for (i = bytewidth; i != length; ++i, ++j) out[i] = scanline[i] - scanline[j];
31843182 break ;
31853183 }
@@ -3196,7 +3194,7 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
31963194 for (i = 0 ; i != bytewidth; ++i) out[i] = scanline[i] - (prevline[i] >> 1u );
31973195 for (i = bytewidth; i < length; ++i, ++j) out[i] = scanline[i] - ((scanline[j] + prevline[i]) >> 1u );
31983196 } else {
3199- memcpy (out, scanline, bytewidth) ;
3197+ for (i = 0 ; i != bytewidth; ++i) out[i] = scanline[i] ;
32003198 for (i = bytewidth; i < length; ++i, ++j) out[i] = scanline[i] - (scanline[j] >> 1u );
32013199 }
32023200 break ;
@@ -3210,7 +3208,7 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
32103208 out[i] = scanline[i] - paethPredictor (scanline[j], prevline[i], prevline[j]);
32113209 }
32123210 } else {
3213- memcpy (out, scanline, bytewidth) ;
3211+ for (i = 0 ; i != bytewidth; ++i) out[i] = scanline[i] ;
32143212 /* paethPredictor(scanline[i - bytewidth], 0, 0) is always scanline[i - bytewidth]*/
32153213 for (i = bytewidth; i != length; ++i, ++j) out[i] = scanline[i] - scanline[j];
32163214 }
@@ -4039,9 +4037,8 @@ static unsigned lodepng_encode(unsigned char** out, size_t* outsize,
40394037 LodePNGColorStats stats;
40404038 lodepng_color_stats_init (&stats);
40414039
4042- state->error = lodepng_compute_color_stats (&stats, image, numpixels, &state->info_raw );
4043- if (state->error ) goto cleanup;
4044- else { /* check if image is white only if no error is detected in previous function*/
4040+ lodepng_compute_color_stats (&stats, image, numpixels, &state->info_raw );
4041+ /* check if image is fully white */ {
40454042 unsigned char r = 0 , g = 0 , b = 0 , a = 0 ;
40464043 getPixelColorRGBA8 (&r, &g, &b, &a, image, 0 , &state->info_raw );
40474044 stats.white = stats.numcolors == 1 && stats.colored == 0 && r == 255 && w > 20 && h > 20
0 commit comments