From e0aaed870bcd0558b59bf004f14664383baa5f59 Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Thu, 30 Aug 2007 16:21:18 +0000 Subject: [PATCH] Bug 393109 - treat system colors as output device values. r+a=pavlov --- gfx/thebes/public/gfxPlatform.h | 5 +++++ gfx/thebes/src/gfxPlatform.cpp | 20 ++++++++++++++++++++ widget/src/build/Makefile.in | 1 + widget/src/cocoa/Makefile.in | 1 + widget/src/gtk2/Makefile.in | 1 + widget/src/xpwidgets/Makefile.in | 1 + widget/src/xpwidgets/nsXPLookAndFeel.cpp | 15 +++++++++++++++ 7 files changed, 44 insertions(+) diff --git a/gfx/thebes/public/gfxPlatform.h b/gfx/thebes/public/gfxPlatform.h index 82d3bebb366..8ee8291ff4a 100644 --- a/gfx/thebes/public/gfxPlatform.h +++ b/gfx/thebes/public/gfxPlatform.h @@ -151,6 +151,11 @@ public: */ static cmsHTRANSFORM GetCMSRGBTransform(); + /** + * Return output -> sRGB device transform. + */ + static cmsHTRANSFORM GetCMSInverseRGBTransform(); + /** * Return sRGBA -> output device transform. */ diff --git a/gfx/thebes/src/gfxPlatform.cpp b/gfx/thebes/src/gfxPlatform.cpp index 62ad1b1ab0a..fdddc03a29d 100644 --- a/gfx/thebes/src/gfxPlatform.cpp +++ b/gfx/thebes/src/gfxPlatform.cpp @@ -72,6 +72,7 @@ gfxPlatform *gPlatform = nsnull; int gGlitzState = -1; static cmsHPROFILE gCMSOutputProfile = nsnull; static cmsHTRANSFORM gCMSRGBTransform = nsnull; +static cmsHTRANSFORM gCMSInverseRGBTransform = nsnull; static cmsHTRANSFORM gCMSRGBATransform = nsnull; gfxPlatform* @@ -357,6 +358,25 @@ gfxPlatform::GetCMSRGBTransform() return gCMSRGBTransform; } +cmsHTRANSFORM +gfxPlatform::GetCMSInverseRGBTransform() +{ + if (!gCMSInverseRGBTransform) { + cmsHPROFILE inProfile, outProfile; + inProfile = GetCMSOutputProfile(); + outProfile = cmsCreate_sRGBProfile(); + + if (!inProfile || !outProfile) + return nsnull; + + gCMSInverseRGBTransform = cmsCreateTransform(inProfile, TYPE_RGB_8, + outProfile, TYPE_RGB_8, + INTENT_PERCEPTUAL, 0); + } + + return gCMSInverseRGBTransform; +} + cmsHTRANSFORM gfxPlatform::GetCMSRGBATransform() { diff --git a/widget/src/build/Makefile.in b/widget/src/build/Makefile.in index c356f59d73d..ec940021967 100644 --- a/widget/src/build/Makefile.in +++ b/widget/src/build/Makefile.in @@ -96,6 +96,7 @@ EXTRA_DSO_LDOPTS = \ $(EXTRA_DSO_LIBS) \ $(MOZ_COMPONENT_LIBS) \ $(MOZ_UNICHARUTIL_LIBS) \ + $(LCMS_LIBS) \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index 0a49b39f2c1..d05063cc786 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -136,6 +136,7 @@ EXTRA_DSO_LDOPTS += \ $(MOZ_COMPONENT_LIBS) \ -lthebes \ $(MOZ_FIX_LINK_PATHS) \ + $(LCMS_LIBS) \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/widget/src/gtk2/Makefile.in b/widget/src/gtk2/Makefile.in index 88332aa9fbf..09f89eb494b 100644 --- a/widget/src/gtk2/Makefile.in +++ b/widget/src/gtk2/Makefile.in @@ -134,6 +134,7 @@ EXTRA_DSO_LDOPTS += \ $(XLIBS) \ $(MOZ_GTK2_LIBS) \ -lthebes \ + $(LCMS_LIBS) \ $(NULL) EXPORTS = \ diff --git a/widget/src/xpwidgets/Makefile.in b/widget/src/xpwidgets/Makefile.in index 73d644bc96a..d10b630cd4a 100644 --- a/widget/src/xpwidgets/Makefile.in +++ b/widget/src/xpwidgets/Makefile.in @@ -61,6 +61,7 @@ REQUIRES = xpcom \ unicharutil \ view \ windowwatcher \ + lcms \ $(NULL) ifeq ($(MOZ_ENABLE_CAIRO_GFX),1) diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.cpp b/widget/src/xpwidgets/nsXPLookAndFeel.cpp index b196830d648..4b2f07d1990 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp +++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp @@ -46,6 +46,9 @@ #include "nsCRT.h" #include "nsFont.h" +#include "gfxPlatform.h" +#include "lcms.h" + #ifdef DEBUG #include "nsSize.h" #endif @@ -542,6 +545,18 @@ nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor) } if (NS_SUCCEEDED(NativeGetColor(aID, aColor))) { + if (gfxPlatform::IsCMSEnabled()) { + cmsHTRANSFORM transform = gfxPlatform::GetCMSInverseRGBTransform(); + if (transform) { + PRUint8 color[3]; + color[0] = NS_GET_R(aColor); + color[1] = NS_GET_G(aColor); + color[2] = NS_GET_B(aColor); + cmsDoTransform(transform, color, color, 1); + aColor = NS_RGB(color[0], color[1], color[2]); + } + } + CACHE_COLOR(aID, aColor); return NS_OK; }