diff --git a/gfx/thebes/src/gfxPlatform.cpp b/gfx/thebes/src/gfxPlatform.cpp index 1aa3e0a96914..db712c2106f6 100644 --- a/gfx/thebes/src/gfxPlatform.cpp +++ b/gfx/thebes/src/gfxPlatform.cpp @@ -602,10 +602,6 @@ gfxPlatform::GetCMSOutputProfile() getter_Copies(fname)); if (NS_SUCCEEDED(rv) && !fname.IsEmpty()) { gCMSOutputProfile = cmsOpenProfileFromFile(fname, "r"); - if (gCMSOutputProfile) - fprintf(stderr, - "ICM profile read from %s successfully\n", - fname.get()); } } } @@ -615,6 +611,15 @@ gfxPlatform::GetCMSOutputProfile() gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile(); } + /* Determine if the profile looks bogus. If so, close the profile + * and use sRGB instead. See bug 460629, */ + if (gCMSOutputProfile && cmsProfileIsBogus(gCMSOutputProfile)) { + NS_ASSERTION(gCMSOutputProfile != GetCMSsRGBProfile(), + "Builtin sRGB profile tagged as bogus!!!"); + cmsCloseProfile(gCMSOutputProfile); + gCMSOutputProfile = nsnull; + } + if (!gCMSOutputProfile) { gCMSOutputProfile = GetCMSsRGBProfile(); } diff --git a/modules/lcms/include/lcms.h b/modules/lcms/include/lcms.h index 99b8b6bf6368..cdfbc37490ce 100644 --- a/modules/lcms/include/lcms.h +++ b/modules/lcms/include/lcms.h @@ -855,6 +855,7 @@ LCMSAPI LPcmsCIExyY LCMSEXPORT cmsD50_xyY(void); LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromFile(const char *ICCProfile, const char *sAccess); LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize); LCMSAPI LCMSBOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsProfileIsBogus(cmsHPROFILE hProfile); // Predefined run-time profiles diff --git a/modules/lcms/src/cmsio1.c b/modules/lcms/src/cmsio1.c index 52c554b1af46..b1b4e58281dc 100644 --- a/modules/lcms/src/cmsio1.c +++ b/modules/lcms/src/cmsio1.c @@ -2523,7 +2523,47 @@ cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize) } +// Checks a profile for obvious inconsistencies and returns +// TRUE if the profile looks bogus and should probably be +// ignored. +LCMSBOOL LCMSEXPORT cmsProfileIsBogus(cmsHPROFILE hProfile) +{ + cmsCIEXYZTRIPLE primaries; + VEC3 sum, target, tolerance; + unsigned i; + + // Read the primaries + cmsTakeColorants(&primaries, hProfile); + + // Sum the values + sum.n[0] = primaries.Red.X + primaries.Green.X + primaries.Blue.X; + sum.n[1] = primaries.Red.Y + primaries.Green.Y + primaries.Blue.Y; + sum.n[2] = primaries.Red.Z + primaries.Green.Z + primaries.Blue.Z; + + // Build our target vector (see mozilla bug 460629) + target.n[0] = 0.96420; + target.n[1] = 1.00000; + target.n[2] = 0.82491; + + // Our tolerance vector - Recommended by Chris Murphy based on + // conversion from the LAB space criterion of no more than 3 in any one + // channel. This is similar to, but slightly more tolerant than Adobe's + // criterion. + tolerance.n[0] = 0.02; + tolerance.n[1] = 0.02; + tolerance.n[2] = 0.04; + + // Compare with our tolerance + for (i = 0; i < 3; ++i) { + if (!(((sum.n[i] - tolerance.n[i]) <= target.n[i]) && + ((sum.n[i] + tolerance.n[i]) >= target.n[i]))) + return TRUE; + } + + // All Good + return FALSE; +} LCMSBOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) { diff --git a/modules/lcms/src/lcms.def b/modules/lcms/src/lcms.def index fd1994b97597..1d49f93ad0f4 100644 --- a/modules/lcms/src/lcms.def +++ b/modules/lcms/src/lcms.def @@ -10,6 +10,7 @@ EXPORTS cmsSmoothGamma = cmsSmoothGamma cmsBuildRGB2XYZtransferMatrix= cmsBuildRGB2XYZtransferMatrix cmsPrecacheProfile = cmsPrecacheProfile + cmsProfileIsBogus = cmsProfileIsBogus cmsCloseProfile = cmsCloseProfile cmsCreateProofingTransform = cmsCreateProofingTransform cmsCreateRGBProfile = cmsCreateRGBProfile