stb_image: JPEG: Convert RGB to grayscale properly
This commit is contained in:
parent
59a5a155b4
commit
552c548a0e
20
stb_image.h
20
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
|
// 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;
|
||||||
@ -3674,11 +3674,19 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
|
|||||||
out += n;
|
out += n;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stbi_uc *y = coutput[0];
|
if (z->rgb == 3) {
|
||||||
if (n == 1)
|
for (i=0; i < z->s->img_x; ++i) {
|
||||||
for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
|
out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
|
||||||
else
|
out[1] = 255;
|
||||||
for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 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);
|
stbi__cleanup_jpeg(z);
|
||||||
|
Loading…
Reference in New Issue
Block a user