Bug 1255106 - Part 4. Ensure we don't apply CMS transforms in cases we missed. r=tnikkel

GIF images should not apply CMS transforms if disabled by caller via
SurfaceFlags::NO_COLORSPACE_CONVERSION. WebP images should reject any
non-RGB ICC profiles, not just grayscale profiles.

Differential Revision: https://phabricator.services.mozilla.com/D26372
This commit is contained in:
Andrew Osmond 2019-04-04 16:30:10 -04:00
Родитель 741028ad6b
Коммит 1f049d2787
3 изменённых файлов: 13 добавлений и 9 удалений

Просмотреть файл

@ -392,9 +392,10 @@ Tuple<int32_t, Maybe<WriteState>> nsGIFDecoder2::YieldPixels(
/// Expand the colormap from RGB to Packed ARGB as needed by Cairo.
/// And apply any LCMS transformation.
static void ConvertColormap(uint32_t* aColormap, uint32_t aColors) {
void nsGIFDecoder2::ConvertColormap(uint32_t* aColormap, uint32_t aColors) {
// Apply CMS transformation if enabled and available
if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
if (!(GetSurfaceFlags() & SurfaceFlags::NO_COLORSPACE_CONVERSION) &&
gfxPlatform::GetCMSMode() == eCMSMode_All) {
qcms_transform* transform = gfxPlatform::GetCMSRGBTransform();
if (transform) {
qcms_transform_data(transform, aColormap, aColormap, aColors);

Просмотреть файл

@ -58,6 +58,9 @@ class nsGIFDecoder2 : public Decoder {
/// Called when we finish decoding the entire image.
void FlushImageData();
/// Convert color map to BGRA, applying any necessary CMS tranforms.
void ConvertColormap(uint32_t* aColormap, uint32_t aColors);
/// Transforms a palette index into a pixel.
template <typename PixelSize>
PixelSize ColormapIndexToPixel(uint8_t aIndex);

Просмотреть файл

@ -271,15 +271,15 @@ void nsWebPDecoder::ApplyColorProfile(const char* aProfile, size_t aLength) {
}
auto mode = gfxPlatform::GetCMSMode();
if (mode == eCMSMode_Off || (mode == eCMSMode_TaggedOnly && !aProfile)) {
if (mode == eCMSMode_Off || (mode == eCMSMode_TaggedOnly && !aProfile) ||
!gfxPlatform::GetCMSOutputProfile()) {
return;
}
if (!aProfile || !gfxPlatform::GetCMSOutputProfile()) {
if (!aProfile) {
MOZ_LOG(sWebPLog, LogLevel::Debug,
("[this=%p] nsWebPDecoder::ApplyColorProfile -- not tagged or no "
"output "
"profile , use sRGB transform\n",
("[this=%p] nsWebPDecoder::ApplyColorProfile -- not tagged, use "
"sRGB transform\n",
this));
mTransform = gfxPlatform::GetCMSBGRATransform();
return;
@ -295,10 +295,10 @@ void nsWebPDecoder::ApplyColorProfile(const char* aProfile, size_t aLength) {
}
uint32_t profileSpace = qcms_profile_get_color_space(mInProfile);
if (profileSpace == icSigGrayData) {
if (profileSpace != icSigRgbData) {
// WebP doesn't produce grayscale data, this must be corrupt.
MOZ_LOG(sWebPLog, LogLevel::Error,
("[this=%p] nsWebPDecoder::ApplyColorProfile -- ignoring grayscale "
("[this=%p] nsWebPDecoder::ApplyColorProfile -- ignoring non-rgb "
"color profile\n",
this));
return;