Skip to content
Myr

TGA RLE flag and regression fix

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

Add requested flag for controlling TGA RLE compression and fix a regression when writing monochrome TGAs.

authored by fahickman · committed by fahickman · parent 126ec22 · Browse files · 1 file+9 added−2 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+9 added−2 removed

  • other:+9 added−2 removed

1 file+9 added−2 removed

modified:stb_image_write.h+9 added-2 removed
127 unmodified lines
128129typedef unsigned int stbiw_uint32;130typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];131132static int stbi__write_tga_with_rle = 1;133134static void writefv(FILE *f, const char *fmt, va_list v)135{136 while (*fmt) {137 switch (*fmt++) {
110 unmodified lines
248int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)249{250 int has_alpha = (comp == 2 || comp == 4);251 int colorbytes = has_alpha ? comp-1 : comp;250 int format = colorbytes < 2 ? 11 : 10; // 3 color channels (RGB/RGBA) = 10, 1 color channel (Y/YA) = 11252 int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3253 FILE *f;254255 if (!stbi__write_tga_with_rle) {256 return outfile(filename, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0,257 "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);258 }259260 if (y < 0 || x < 0) return 0;261 f = fopen(filename, "wb");262 if (f) {263 int i,j,k;264258 writef(f, "111 221 2222 11", 0,0,format, 0,0,0, 0,0,x,y, 24+8*has_alpha, 8*has_alpha);265 writef(f, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8);266267 for (j = y - 1; j >= 0; --j) {268 const unsigned char *row = (unsigned char *) data + j * x * comp;269 int len;
542 unmodified lines