Skip to content
Myr

stbi_write_tga can now write 1 and 2 channel (grayscale and grayscale-alpha) images.

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

authored by Jean-S�bastien Guay · committed by Jean-S�bastien Guay · parent aaea13b · Browse files · 1 file+7 added−3 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+7 added−3 removed

  • other:+7 added−3 removed

1 file+7 added−3 removed

modified:stb_image_write.h+7 added-3 removed
126 unmodified lines
127 unsigned char *d = (unsigned char *) data + (j*x+i)*comp;128 if (write_alpha < 0)129 fwrite(&d[comp-1], 1, 1, f);130 switch (comp) {131 case 1:132 case 2: write3(f, d[0],d[0],d[0]);131 case 1: fwrite(d, 1, 1, f);132 break;133 case 2: fwrite(d, 2, 1, f);134 break;135 case 4:136 if (!write_alpha) {137 // composite against pink background138 for (k=0; k < 3; ++k)
40 unmodified lines
179180int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)181{182 int has_alpha = !(comp & 1);183 int colorbytes = comp - has_alpha;184 int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 3, 1 color channel (Y/YA) = 2185 if (format == 2) colorbytes = 3; // is 2 color channels (RG/RGA) even possible? write as RGB/RGBA186 return outfile(filename, -1,-1, x, y, comp, (void *) data, has_alpha, 0,183 "111 221 2222 11", 0,0,2, 0,0,0, 0,0,x,y, 24+8*has_alpha, 8*has_alpha);187 "111 221 2222 11", 0,0,format, 0,0,0, 0,0,x,y, (colorbytes+has_alpha)*8, has_alpha*8);188}189190// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size()191#define stbiw__sbraw(a) ((int *) (a) - 2)
330 unmodified lines