Skip to content
Myr

Merge branch 'master' of https://github.com/ab-cpp/stb into working

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 · parents 476c1f8, eee50c0 · Browse files · 2 files+8 added−6 removed
This commit

State

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

Diff stats

2 files+8 added−6 removed

  • other:+8 added−6 removed

2 files+8 added−6 removed

modified:stb_image_write.h+6 added-6 removed
1066 unmodified lines
1067 }1068 }1069}10701071unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)1071unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)1072{1073 int force_filter = stbi_write_force_png_filter;1074 int ctype[5] = { -1, 0, 4, 2, 6 };1075 unsigned char sig[8] = { 137,80,78,71,13,10,26,10 };
13 unmodified lines
1089 for (j=0; j < y; ++j) {1090 int filter_type;1091 if (force_filter > -1) {1092 filter_type = force_filter;1093 stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer);1093 stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer);1094 } else { // Estimate the best filter by running through all of them:1095 int best_filter = 0, best_filter_val = 0x7fffffff, est, i;1096 for (filter_type = 0; filter_type < 5; filter_type++) {1097 stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer);1097 stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer);10981099 // Estimate the entropy of the line using this filter; the less, the better.1100 est = 0;1101 for (i = 0; i < x*n; ++i) {
4 unmodified lines
1106 best_filter = filter_type;1107 }1108 }1109 if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it1110 stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer);1110 stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer);1111 filter_type = best_filter;1112 }1113 }1114 // when we get here, filter_type contains the filter type, and line_buffer contains the data
43 unmodified lines
1158STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes)1159{1160 FILE *f;1161 int len;1162 unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);1162 unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);1163 if (png == NULL) return 0;11641165 f = stbiw__fopen(filename, "wb");1166 if (!f) { STBIW_FREE(png); return 0; }
6 unmodified lines
11731174STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)1175{1176 int len;1177 unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);1177 unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);1178 if (png == NULL) return 0;1179 func(context, png, len);1180 STBIW_FREE(png);1181 return 1;
435 unmodified lines
modified:stb_image.h+2 added
6384 unmodified lines
6385// this function is designed to support animated gifs, although stb_image doesn't support it6386// two back is the image from two frames ago, used for a very specific disposal format6387static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back)6388{6389 STBI_NOTUSED(req_comp);6390 int dispose; 6391 int first_frame; 6392 int pi; 6393 int pcount;
216 unmodified lines
6610}66116612static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)6613{6614 STBI_NOTUSED(ri);6615 stbi_uc *u = 0;6616 stbi__gif g;6617 memset(&g, 0, sizeof(g));6618
894 unmodified lines