diff --git a/stb_image.h b/stb_image.h index 3940f38..b3944b5 100644 --- a/stb_image.h +++ b/stb_image.h @@ -3596,7 +3596,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 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; else decode_n = z->s->img_n; @@ -3674,11 +3674,19 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp out += n; } } else { - stbi_uc *y = coutput[0]; - if (n == 1) - for (i=0; i < z->s->img_x; ++i) out[i] = y[i]; - else - for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255; + 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 { + stbi_uc *y = coutput[0]; + if (n == 1) + for (i=0; i < z->s->img_x; ++i) out[i] = y[i]; + else + for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255; + } } } stbi__cleanup_jpeg(z);