Skip to content
Myr

Merge branch '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 a7c8694, 6639ef6 · Browse files · 1 file+11 added−7 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+11 added−7 removed

  • other:+11 added−7 removed

1 file+11 added−7 removed

modified:stb_image_write.h+11 added-7 removed
106 unmodified lines
107 arr[0] = a, arr[1] = b, arr[2] = c;108 fwrite(arr, 3, 1, f);109}110111static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad)111static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono)112{113 unsigned char bg[3] = { 255, 0, 255}, px[3];114 stbiw_uint32 zero = 0;115 int i,j,k, j_end;
11 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: fwrite(d, 1, 1, f);131 case 1: fwrite(d, 1, 1, f);132 break;133 case 2: if (expand_mono)134 write3(f, d[0],d[0],d[0]); // monochrome bmp135 else136 fwrite(d, 1, 1, f); // monochrome TGA137 break;138 case 4:139 if (!write_alpha) {140 // composite against pink background141 for (k=0; k < 3; ++k)
12 unmodified lines
154 fwrite(&zero,scanline_pad,1,f);155 }156}157154static int outfile(char const *filename, int rgb_dir, int vdir, int x, int y, int comp, void *data, int alpha, int pad, const char *fmt, ...)158static int outfile(char const *filename, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...)159{160 FILE *f;161 if (y < 0 || x < 0) return 0;162 f = fopen(filename, "wb");
1 unmodified line
164 va_list v;165 va_start(v, fmt);166 writefv(f, fmt, v);167 va_end(v);164 write_pixels(f,rgb_dir,vdir,x,y,comp,data,alpha,pad);168 write_pixels(f,rgb_dir,vdir,x,y,comp,data,alpha,pad,expand_mono);169 fclose(f);170 }171 return f != NULL;172}173174int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data)175{176 int pad = (-x*3) & 3;173 return outfile(filename,-1,-1,x,y,comp,(void *) data,0,pad,177 return outfile(filename,-1,-1,x,y,comp,1,(void *) data,0,pad,178 "11 4 22 4" "4 44 22 444444",179 'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header180 40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header181}
2 unmodified lines
184{185 int has_alpha = (comp == 2 || comp == 4);186 int colorbytes = has_alpha ? comp-1 : comp;187 int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3184 return outfile(filename, -1,-1, x, y, comp, (void *) data, has_alpha, 0,188 return outfile(filename, -1,-1, x, y, comp, 0, (void *) data, has_alpha, 0,189 "111 221 2222 11", 0,0,format, 0,0,0, 0,0,x,y, (colorbytes+has_alpha)*8, has_alpha*8);190}191192// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size()
333 unmodified lines