|  |  |  | @ -1,4 +1,4 @@ | 
			
		
	
		
			
				
					|  |  |  |  | /* stb_image_write - v0.99 - public domain - http://nothings.org/stb/stb_image_write.h
 | 
			
		
	
		
			
				
					|  |  |  |  | /* stb_image_write - v1.00 - public domain - http://nothings.org/stb/stb_image_write.h
 | 
			
		
	
		
			
				
					|  |  |  |  |    writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010 | 
			
		
	
		
			
				
					|  |  |  |  |                                      no warranty implied; use at your own risk | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -89,7 +89,7 @@ CREDITS: | 
			
		
	
		
			
				
					|  |  |  |  |       Tim Kelsey | 
			
		
	
		
			
				
					|  |  |  |  |    TGA RLE | 
			
		
	
		
			
				
					|  |  |  |  |       Alan Hickman | 
			
		
	
		
			
				
					|  |  |  |  |    file IO callback | 
			
		
	
		
			
				
					|  |  |  |  |    initial file IO callback implementation | 
			
		
	
		
			
				
					|  |  |  |  |       Emmanuel Julien | 
			
		
	
		
			
				
					|  |  |  |  |    bugfixes: | 
			
		
	
		
			
				
					|  |  |  |  |       github:Chribba | 
			
		
	
	
		
			
				
					|  |  |  | @ -220,7 +220,7 @@ static int stbi_write_tga_with_rle = 1; | 
			
		
	
		
			
				
					|  |  |  |  | int stbi_write_tga_with_rle = 1; | 
			
		
	
		
			
				
					|  |  |  |  | #endif | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static void writefv(stbi__write_context *s, const char *fmt, va_list v) | 
			
		
	
		
			
				
					|  |  |  |  | static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    while (*fmt) { | 
			
		
	
		
			
				
					|  |  |  |  |       switch (*fmt++) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -249,22 +249,22 @@ static void writefv(stbi__write_context *s, const char *fmt, va_list v) | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static void writef(stbi__write_context *s, const char *fmt, ...) | 
			
		
	
		
			
				
					|  |  |  |  | static void stbiw__writef(stbi__write_context *s, const char *fmt, ...) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    va_list v; | 
			
		
	
		
			
				
					|  |  |  |  |    va_start(v, fmt); | 
			
		
	
		
			
				
					|  |  |  |  |    writefv(s, fmt, v); | 
			
		
	
		
			
				
					|  |  |  |  |    stbiw__writefv(s, fmt, v); | 
			
		
	
		
			
				
					|  |  |  |  |    va_end(v); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static void write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) | 
			
		
	
		
			
				
					|  |  |  |  | static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    unsigned char arr[3]; | 
			
		
	
		
			
				
					|  |  |  |  |    arr[0] = a, arr[1] = b, arr[2] = c; | 
			
		
	
		
			
				
					|  |  |  |  |    s->func(s->context, arr, 3); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static void write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) | 
			
		
	
		
			
				
					|  |  |  |  | static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    unsigned char bg[3] = { 255, 0, 255}, px[3]; | 
			
		
	
		
			
				
					|  |  |  |  |    int k; | 
			
		
	
	
		
			
				
					|  |  |  | @ -278,7 +278,7 @@ static void write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write | 
			
		
	
		
			
				
					|  |  |  |  |          break; | 
			
		
	
		
			
				
					|  |  |  |  |       case 2: | 
			
		
	
		
			
				
					|  |  |  |  |          if (expand_mono) | 
			
		
	
		
			
				
					|  |  |  |  |             write3(s, d[0], d[0], d[0]); // monochrome bmp
 | 
			
		
	
		
			
				
					|  |  |  |  |             stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp
 | 
			
		
	
		
			
				
					|  |  |  |  |          else | 
			
		
	
		
			
				
					|  |  |  |  |             s->func(s->context, d, 1);  // monochrome TGA
 | 
			
		
	
		
			
				
					|  |  |  |  |          break; | 
			
		
	
	
		
			
				
					|  |  |  | @ -287,19 +287,19 @@ static void write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write | 
			
		
	
		
			
				
					|  |  |  |  |             // composite against pink background
 | 
			
		
	
		
			
				
					|  |  |  |  |             for (k = 0; k < 3; ++k) | 
			
		
	
		
			
				
					|  |  |  |  |                px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255; | 
			
		
	
		
			
				
					|  |  |  |  |             write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); | 
			
		
	
		
			
				
					|  |  |  |  |             stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); | 
			
		
	
		
			
				
					|  |  |  |  |             break; | 
			
		
	
		
			
				
					|  |  |  |  |          } | 
			
		
	
		
			
				
					|  |  |  |  |          /* FALLTHROUGH */ | 
			
		
	
		
			
				
					|  |  |  |  |       case 3: | 
			
		
	
		
			
				
					|  |  |  |  |          write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); | 
			
		
	
		
			
				
					|  |  |  |  |          stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); | 
			
		
	
		
			
				
					|  |  |  |  |          break; | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  |    if (write_alpha > 0) | 
			
		
	
		
			
				
					|  |  |  |  |       s->func(s->context, &d[comp - 1], 1); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static void write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) | 
			
		
	
		
			
				
					|  |  |  |  | static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    stbiw_uint32 zero = 0; | 
			
		
	
		
			
				
					|  |  |  |  |    int i,j, j_end; | 
			
		
	
	
		
			
				
					|  |  |  | @ -315,30 +315,30 @@ static void write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, i | 
			
		
	
		
			
				
					|  |  |  |  |    for (; j != j_end; j += vdir) { | 
			
		
	
		
			
				
					|  |  |  |  |       for (i=0; i < x; ++i) { | 
			
		
	
		
			
				
					|  |  |  |  |          unsigned char *d = (unsigned char *) data + (j*x+i)*comp; | 
			
		
	
		
			
				
					|  |  |  |  |          write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); | 
			
		
	
		
			
				
					|  |  |  |  |          stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  |  |       s->func(s->context, &zero, scanline_pad); | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static int outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...) | 
			
		
	
		
			
				
					|  |  |  |  | static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    if (y < 0 || x < 0) { | 
			
		
	
		
			
				
					|  |  |  |  |       return 0; | 
			
		
	
		
			
				
					|  |  |  |  |    } else { | 
			
		
	
		
			
				
					|  |  |  |  |       va_list v; | 
			
		
	
		
			
				
					|  |  |  |  |       va_start(v, fmt); | 
			
		
	
		
			
				
					|  |  |  |  |       writefv(s, fmt, v); | 
			
		
	
		
			
				
					|  |  |  |  |       stbiw__writefv(s, fmt, v); | 
			
		
	
		
			
				
					|  |  |  |  |       va_end(v); | 
			
		
	
		
			
				
					|  |  |  |  |       write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono); | 
			
		
	
		
			
				
					|  |  |  |  |       stbiw__write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono); | 
			
		
	
		
			
				
					|  |  |  |  |       return 1; | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | STBIWDEF int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data) | 
			
		
	
		
			
				
					|  |  |  |  | static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    int pad = (-x*3) & 3; | 
			
		
	
		
			
				
					|  |  |  |  |    return outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, | 
			
		
	
		
			
				
					|  |  |  |  |    return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, | 
			
		
	
		
			
				
					|  |  |  |  |            "11 4 22 4" "4 44 22 444444", | 
			
		
	
		
			
				
					|  |  |  |  |            'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40,  // file header
 | 
			
		
	
		
			
				
					|  |  |  |  |             40, x,y, 1,24, 0,0,0,0,0,0);             // bitmap header
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -364,7 +364,7 @@ STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | #endif //!STBI_WRITE_NO_STDIO
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | STBIWDEF int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data) | 
			
		
	
		
			
				
					|  |  |  |  | static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    int has_alpha = (comp == 2 || comp == 4); | 
			
		
	
		
			
				
					|  |  |  |  |    int colorbytes = has_alpha ? comp-1 : comp; | 
			
		
	
	
		
			
				
					|  |  |  | @ -374,12 +374,12 @@ STBIWDEF int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, | 
			
		
	
		
			
				
					|  |  |  |  |       return 0; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |    if (!stbi_write_tga_with_rle) { | 
			
		
	
		
			
				
					|  |  |  |  |       return outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, | 
			
		
	
		
			
				
					|  |  |  |  |       return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, | 
			
		
	
		
			
				
					|  |  |  |  |          "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8); | 
			
		
	
		
			
				
					|  |  |  |  |    } else { | 
			
		
	
		
			
				
					|  |  |  |  |       int i,j,k; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8); | 
			
		
	
		
			
				
					|  |  |  |  |       stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       for (j = y - 1; j >= 0; --j) { | 
			
		
	
		
			
				
					|  |  |  |  |           unsigned char *row = (unsigned char *) data + j * x * comp; | 
			
		
	
	
		
			
				
					|  |  |  | @ -419,12 +419,12 @@ STBIWDEF int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, | 
			
		
	
		
			
				
					|  |  |  |  |                unsigned char header = (unsigned char) (len - 1); | 
			
		
	
		
			
				
					|  |  |  |  |                s->func(s->context, &header, 1); | 
			
		
	
		
			
				
					|  |  |  |  |                for (k = 0; k < len; ++k) { | 
			
		
	
		
			
				
					|  |  |  |  |                   write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); | 
			
		
	
		
			
				
					|  |  |  |  |                   stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); | 
			
		
	
		
			
				
					|  |  |  |  |                } | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                unsigned char header = (unsigned char) (len - 129); | 
			
		
	
		
			
				
					|  |  |  |  |                s->func(s->context, &header, 1); | 
			
		
	
		
			
				
					|  |  |  |  |                write_pixel(s, -1, comp, has_alpha, 0, begin); | 
			
		
	
		
			
				
					|  |  |  |  |                stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |          } | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
	
		
			
				
					|  |  |  | @ -440,7 +440,7 @@ int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, i | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #ifndef STBI_WRITE_NO_STDIO | 
			
		
	
		
			
				
					|  |  |  |  | int stbi_write_tga_to_file(char const *filename, int x, int y, int comp, const void *data) | 
			
		
	
		
			
				
					|  |  |  |  | int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    stbi__write_context s; | 
			
		
	
		
			
				
					|  |  |  |  |    if (stbi__start_write_file(&s,filename)) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -581,7 +581,7 @@ void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, uns | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | STBIWDEF int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data) | 
			
		
	
		
			
				
					|  |  |  |  | static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    if (y <= 0 || x <= 0 || data == NULL) | 
			
		
	
		
			
				
					|  |  |  |  |       return 0; | 
			
		
	
	
		
			
				
					|  |  |  | @ -610,7 +610,7 @@ int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x, int y, i | 
			
		
	
		
			
				
					|  |  |  |  |    return stbi_write_hdr_core(&s, x, y, comp, (float *) data); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int stbi_write_hdr_to_file(char const *filename, int x, int y, int comp, const float *data) | 
			
		
	
		
			
				
					|  |  |  |  | int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |    stbi__write_context s; | 
			
		
	
		
			
				
					|  |  |  |  |    if (stbi__start_write_file(&s,filename)) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -965,6 +965,8 @@ STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, | 
			
		
	
		
			
				
					|  |  |  |  | #endif // STB_IMAGE_WRITE_IMPLEMENTATION
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | /* Revision history
 | 
			
		
	
		
			
				
					|  |  |  |  |       1.00 (2015-09-14) | 
			
		
	
		
			
				
					|  |  |  |  |              installable file IO function | 
			
		
	
		
			
				
					|  |  |  |  |       0.99 (2015-09-13) | 
			
		
	
		
			
				
					|  |  |  |  |              warning fixes; TGA rle support | 
			
		
	
		
			
				
					|  |  |  |  |       0.98 (2015-04-08) | 
			
		
	
	
		
			
				
					|  |  |  | 
 |