remove white matting when loading transparent PSD
This commit is contained in:
parent
a8876b884d
commit
591c7f8cb3
18
stb_image.h
18
stb_image.h
@ -203,8 +203,9 @@
|
|||||||
Laurent Gomila Cort Stratton Sergio Gonzalez romigrou@github
|
Laurent Gomila Cort Stratton Sergio Gonzalez romigrou@github
|
||||||
Aruelien Pocheville Thibault Reuille Cass Everitt
|
Aruelien Pocheville Thibault Reuille Cass Everitt
|
||||||
Ryamond Barbiero Paul Du Bois Engin Manap
|
Ryamond Barbiero Paul Du Bois Engin Manap
|
||||||
|
Michaelangel007@github Oriol Ferrer Mesia
|
||||||
Blazej Dariusz Roszkowski
|
Blazej Dariusz Roszkowski
|
||||||
Michaelangel007@github
|
Oriol Ferrer Mesia
|
||||||
|
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
@ -5453,6 +5454,21 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (channelCount >= 3) {
|
||||||
|
for (i=0; i < w*h; ++i) {
|
||||||
|
unsigned char *pixel = out + 4*i;
|
||||||
|
if (pixel[3] != 0 && pixel[3] != 255) {
|
||||||
|
// remove weird white matte from PSD
|
||||||
|
float a = pixel[3] / 255.0f;
|
||||||
|
float ra = 1.0f / a;
|
||||||
|
float inv_a = 255.0f * (1 - ra);
|
||||||
|
pixel[0] = (unsigned char) (pixel[0]*ra + inv_a);
|
||||||
|
pixel[1] = (unsigned char) (pixel[1]*ra + inv_a);
|
||||||
|
pixel[2] = (unsigned char) (pixel[2]*ra + inv_a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (req_comp && req_comp != 4) {
|
if (req_comp && req_comp != 4) {
|
||||||
out = stbi__convert_format(out, 4, req_comp, w, h);
|
out = stbi__convert_format(out, 4, req_comp, w, h);
|
||||||
if (out == NULL) return out; // stbi__convert_format frees input on failure
|
if (out == NULL) return out; // stbi__convert_format frees input on failure
|
||||||
|
Loading…
Reference in New Issue
Block a user