Skip to content
Myr

stb_image_write: optimize other PNG loops besides previous merge

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent d27796b · Browse files · 1 file+10 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−15 removed

  • other:+10 added−15 removed

1 file+10 added−15 removed

modified:stb_image_write.h+10 added-15 removed
1047 unmodified lines
1048 int type = mymap[filter_type];1049 unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);1050 int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;1051 1052 // sorry for not optimizing the other paths1053 if(type==0)1052 if (type==0) {1054 {1053 memcpy(line_buffer, z, width*n);1054 return;1055 }1058 10561057 // first loop isn't optimized since it's just one pixel 1058 for (i = 0; i < n; ++i) {1059 switch (type) {1061 case 0: line_buffer[i] = z[i]; break;1060 case 1: line_buffer[i] = z[i]; break;1061 case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;1062 case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;1063 case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break;1064 case 5: line_buffer[i] = z[i]; break;1065 case 6: line_buffer[i] = z[i]; break;1066 }1067 }1070 for (i=n; i < width*n; ++i) {1071 switch (type) {1072 case 0: line_buffer[i] = z[i]; break;1073 case 1: line_buffer[i] = z[i] - z[i-n]; break;1074 case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;1075 case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;1076 case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;1077 case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;1078 case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;1079 }1068 switch (type) {1069 case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break;1070 case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break;1071 case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;1072 case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;1073 case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break;1074 case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;1075 }1076}10771078unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
545 unmodified lines