Merge branch 'rgb-grayscale' of https://github.com/jeremysawicki/stb into working

pull/415/merge
Sean Barrett 2017-03-03 08:25:29 -08:00
commit 64e1799f24
1 changed files with 16 additions and 8 deletions

View File

@ -95,7 +95,7 @@ RECENT REVISION HISTORY:
Ryamond Barbiero Paul Du Bois Engin Manap github:snagar Ryamond Barbiero Paul Du Bois Engin Manap github:snagar
Michaelangel007@github Oriol Ferrer Mesia Dale Weiler github:Zelex Michaelangel007@github Oriol Ferrer Mesia Dale Weiler github:Zelex
Philipp Wiesemann Josh Tobin github:rlyeh github:grim210@github Philipp Wiesemann Josh Tobin github:rlyeh github:grim210@github
Blazej Dariusz Roszkowski github:sammyhw Blazej Dariusz Roszkowski github:sammyhw Jeremy Sawicki
*/ */
@ -3486,7 +3486,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
// determine actual number of components to generate // determine actual number of components to generate
n = req_comp ? req_comp : z->s->img_n; n = req_comp ? req_comp : z->s->img_n;
if (z->s->img_n == 3 && n < 3) if (z->s->img_n == 3 && n < 3 && z->rgb != 3)
decode_n = 1; decode_n = 1;
else else
decode_n = z->s->img_n; decode_n = z->s->img_n;
@ -3563,6 +3563,13 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
out[3] = 255; // not used if n==3 out[3] = 255; // not used if n==3
out += n; out += n;
} }
} else {
if (z->rgb == 3) {
for (i=0; i < z->s->img_x; ++i) {
out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
out[1] = 255;
out += n;
}
} else { } else {
stbi_uc *y = coutput[0]; stbi_uc *y = coutput[0];
if (n == 1) if (n == 1)
@ -3571,6 +3578,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255; for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255;
} }
} }
}
stbi__cleanup_jpeg(z); stbi__cleanup_jpeg(z);
*out_x = z->s->img_x; *out_x = z->s->img_x;
*out_y = z->s->img_y; *out_y = z->s->img_y;
@ -5266,7 +5274,7 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
unsigned char *tga_data; unsigned char *tga_data;
unsigned char *tga_palette = NULL; unsigned char *tga_palette = NULL;
int i, j; int i, j;
unsigned char raw_data[4]; unsigned char raw_data[4] = {0};
int RLE_count = 0; int RLE_count = 0;
int RLE_repeating = 0; int RLE_repeating = 0;
int read_next_pixel = 1; int read_next_pixel = 1;