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.
This commit is contained in:
parent
26a71f67fe
commit
ebc2d23d47
@ -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,
|
|||||||
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
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user