提交 ebc2d23d 编写于 作者: J Jean-Sbastien Guay

realized the 2 colorbytes case is impossible.

also updated the comment at the top of the file to reflect stbi_write_tga's new capabilities.
上级 26a71f67
...@@ -42,7 +42,7 @@ USAGE: ...@@ -42,7 +42,7 @@ USAGE:
a row of pixels to the first byte of the next row of pixels. a row of pixels to the first byte of the next row of pixels.
PNG creates output files with the same number of components as the input. PNG creates output files with the same number of components as the input.
The BMP and TGA formats expand Y to RGB in the file format. BMP does not The BMP format expands Y to RGB in the file format and does not
output alpha. output alpha.
PNG supports writing rectangles of data even when the bytes storing rows of PNG supports writing rectangles of data even when the bytes storing rows of
...@@ -128,9 +128,8 @@ static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp, ...@@ -128,9 +128,8 @@ static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp,
if (write_alpha < 0) if (write_alpha < 0)
fwrite(&d[comp-1], 1, 1, f); fwrite(&d[comp-1], 1, 1, f);
switch (comp) { switch (comp) {
case 1: fwrite(d, 1, 1, f); case 1:
break; case 2: fwrite(d, 1, 1, f);
case 2: fwrite(d, 2, 1, f);
break; break;
case 4: case 4:
if (!write_alpha) { if (!write_alpha) {
...@@ -182,7 +181,6 @@ int stbi_write_tga(char const *filename, int x, int y, int comp, const void *dat ...@@ -182,7 +181,6 @@ int stbi_write_tga(char const *filename, int x, int y, int comp, const void *dat
int has_alpha = !(comp & 1); int has_alpha = !(comp & 1);
int colorbytes = comp - has_alpha; int colorbytes = comp - has_alpha;
int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3 int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3
if (format == 2) colorbytes = 3; // is 2 color channels (RG/RGA) even possible? write as RGB/RGBA
return outfile(filename, -1,-1, x, y, comp, (void *) data, has_alpha, 0, return outfile(filename, -1,-1, x, y, comp, (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); "111 221 2222 11", 0,0,format, 0,0,0, 0,0,x,y, (colorbytes+has_alpha)*8, has_alpha*8);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册