From 7a02732eb3cb59d9d255455a1fde92e5038052fa Mon Sep 17 00:00:00 2001 From: jarnoh Date: Thu, 26 Jul 2018 17:10:40 +0300 Subject: [PATCH 1/2] allow STBIW_CRC32 override default crc32 --- stb_image_write.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stb_image_write.h b/stb_image_write.h index c05e958..78a02aa 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -923,6 +923,9 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l static unsigned int stbiw__crc32(unsigned char *buffer, int len) { +#ifdef STBIW_CRC32 + return STBIW_CRC32(buffer, len); +#else static unsigned int crc_table[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, @@ -964,6 +967,7 @@ static unsigned int stbiw__crc32(unsigned char *buffer, int len) for (i=0; i < len; ++i) crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)]; return ~crc; +#endif } #define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4) From 60a5755478b4a8a564e20948daf926a1bb0a1d74 Mon Sep 17 00:00:00 2001 From: jarnoh Date: Thu, 26 Jul 2018 17:37:50 +0300 Subject: [PATCH 2/2] use simple memcpy if png filter=0 --- stb_image_write.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stb_image_write.h b/stb_image_write.h index 78a02aa..08c1f67 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -998,6 +998,14 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int int type = mymap[filter_type]; unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y); int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes; + + // sorry for not optimizing the other paths + if(type==0) + { + memcpy(line_buffer, z, width*n); + return; + } + for (i = 0; i < n; ++i) { switch (type) { case 0: line_buffer[i] = z[i]; break;