diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index d02919a23cd..84249b623bc 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3930,7 +3930,6 @@ nsDocShell::EnsureDeviceContext() float twip2dev; mDeviceContext->GetTwipsToDevUnits(twip2dev); mDeviceContext->SetAppUnitsToDevUnits(twip2dev); - mDeviceContext->SetGamma(1.0f); return NS_OK; } diff --git a/mozilla/gfx/idl/nsIScreen.idl b/mozilla/gfx/idl/nsIScreen.idl index 21582f47b17..60a2e5577b3 100644 --- a/mozilla/gfx/idl/nsIScreen.idl +++ b/mozilla/gfx/idl/nsIScreen.idl @@ -30,6 +30,7 @@ interface nsIScreen : nsISupports readonly attribute long pixelDepth; readonly attribute long colorDepth; + readonly attribute double gammaValue; }; diff --git a/mozilla/gfx/public/nsColor.h b/mozilla/gfx/public/nsColor.h index 460daad5bd9..383b3e6296e 100644 --- a/mozilla/gfx/public/nsColor.h +++ b/mozilla/gfx/public/nsColor.h @@ -121,4 +121,22 @@ extern "C" NS_GFX_(void) NS_RGB2HSV(nscolor aColor,PRUint16 &aHue,PRUint16 &aSat // function to convert from HSV color space to RGB color space extern "C" NS_GFX_(void) NS_HSV2RGB(nscolor &aColor,PRUint16 aHue,PRUint16 aSat,PRUint16 aValue); +// Gamma correction +PR_EXPORT_DATA(PRUint8) nsGammaRamp[256], nsInverseGammaRamp[256]; + +double NS_DisplayGammaValue(void); +void NS_InitializeGamma(void); + +#define NS_GAMMA_CORRECT_COMPONENT(x) (nsGammaRamp[x]) +#define NS_INVERSE_GAMMA_CORRECT_COMPONENT(x) (nsInverseGammaRamp[x]) + +#define NS_GAMMA_CORRECT_COLOR(x) NS_RGBA(nsGammaRamp[NS_GET_R(x)], \ + nsGammaRamp[NS_GET_G(x)], \ + nsGammaRamp[NS_GET_B(x)], \ + NS_GET_A(x)) +#define NS_INVERSE_GAMMA_CORRECT_COLOR(x) NS_RGBA(nsInverseGammaRamp[NS_GET_R(x)], \ + nsInverseGammaRamp[NS_GET_G(x)], \ + nsInverseGammaRamp[NS_GET_B(x)], \ + NS_GET_A(x)) + #endif /* nsColor_h___ */ diff --git a/mozilla/gfx/public/nsDeviceContext.h b/mozilla/gfx/public/nsDeviceContext.h index 8e3de7e0166..895fc4aebfa 100644 --- a/mozilla/gfx/public/nsDeviceContext.h +++ b/mozilla/gfx/public/nsDeviceContext.h @@ -118,11 +118,6 @@ public: NS_IMETHOD SetTextZoom(float aTextZoom); NS_IMETHOD GetTextZoom(float &aTextZoom) const; - NS_IMETHOD GetGamma(float &aGamma); - NS_IMETHOD SetGamma(float aGamma); - - NS_IMETHOD GetGammaTable(PRUint8 *&aGammaTable); - NS_IMETHOD FirstExistingFont(const nsFont& aFont, nsString& aFaceName); NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName, @@ -150,7 +145,6 @@ protected: virtual ~DeviceContextImpl(); void CommonInit(void); - void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma); nsresult CreateIconILGroupContext(); virtual nsresult CreateFontAliasTable(); nsresult AliasFont(const nsString& aFont, @@ -166,8 +160,6 @@ protected: nsCOMPtr mLocaleLangGroup; // XXX temp fix for performance bug - erik float mZoom; float mTextZoom; - float mGammaValue; - PRUint8 *mGammaTable; nsHashtable* mFontAliasTable; float mCPixelScale; diff --git a/mozilla/gfx/public/nsIDeviceContext.h b/mozilla/gfx/public/nsIDeviceContext.h index 2a9e29188b9..ba09fdcb6a4 100644 --- a/mozilla/gfx/public/nsIDeviceContext.h +++ b/mozilla/gfx/public/nsIDeviceContext.h @@ -381,13 +381,6 @@ public: //in the device context for re-use. NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface) = 0; - //functions for handling gamma correction of output device - NS_IMETHOD GetGamma(float &aGamms) = 0; - NS_IMETHOD SetGamma(float aGamma) = 0; - - //XXX the return from this really needs to be ref counted somehow. MMP - NS_IMETHOD GetGammaTable(PRUint8 *&aGammaTable) = 0; - /** * Check to see if a particular named font exists. * @param aFontName character string of font face name diff --git a/mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp b/mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp index 40650c49bed..be370550f08 100644 --- a/mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp +++ b/mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp @@ -118,7 +118,6 @@ NS_IMETHODIMP nsRenderingContextBeOS::CommonInit() { float app2dev; mContext->GetAppUnitsToDevUnits(app2dev); mTranMatrix->AddScale(app2dev, app2dev); - mContext->GetGammaTable(mGammaTable); return NS_OK; } @@ -298,8 +297,10 @@ void nsRenderingContextBeOS::UpdateView() { if (mCurrentFont == nsnull) mCurrentFont = (BFont *)be_plain_font; mView->SetFont(mCurrentFont); - mView->SetHighColor(mGammaTable[NS_GET_R(mCurrentColor)], - mGammaTable[NS_GET_G(mCurrentColor)], mGammaTable[NS_GET_B(mCurrentColor)], 255); + mView->SetHighColor(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor)), + 255); BRegion *region = nsnull; if (mClipRegion) { diff --git a/mozilla/gfx/src/beos/nsRenderingContextBeOS.h b/mozilla/gfx/src/beos/nsRenderingContextBeOS.h index 5b435904a47..53bc9c354a4 100644 --- a/mozilla/gfx/src/beos/nsRenderingContextBeOS.h +++ b/mozilla/gfx/src/beos/nsRenderingContextBeOS.h @@ -224,7 +224,6 @@ protected: nsCOMPtr mClipRegion; nsVoidArray *mStateCache; BView *mView; - PRUint8 *mGammaTable; nscolor mCurrentColor; BFont *mCurrentFont; nsLineStyle mCurrentLineStyle; diff --git a/mozilla/gfx/src/beos/nsScreenBeOS.cpp b/mozilla/gfx/src/beos/nsScreenBeOS.cpp index 1f0968ac58a..6a040d204ab 100644 --- a/mozilla/gfx/src/beos/nsScreenBeOS.cpp +++ b/mozilla/gfx/src/beos/nsScreenBeOS.cpp @@ -135,3 +135,12 @@ nsScreenBeOS :: GetColorDepth(PRInt32 *aColorDepth) } // GetColorDepth +NS_IMETHODIMP +nsScreenBeOS :: GetGammaValue(double *aGammaValue) +{ + // XXX - Replace this with code to query the gamma value for your platform + + *aGammaValue = 2.2; + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp index 1e28ecc497f..d80f168491b 100644 --- a/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -522,7 +522,8 @@ void nsRenderingContextGTK::UpdateGC() memset(&values, 0, sizeof(GdkGCValues)); - values.foreground.pixel = gdk_rgb_xpixel_from_rgb(NS_TO_GDK_RGB(mCurrentColor)); + values.foreground.pixel = + gdk_rgb_xpixel_from_rgb(NS_TO_GDK_RGB(NS_GAMMA_CORRECT_COLOR(mCurrentColor))); valuesMask = GDK_GC_FOREGROUND; if ((mCurrentFont) && (mCurrentFont->GetGDKFont())) { diff --git a/mozilla/gfx/src/gtk/nsScreenGtk.cpp b/mozilla/gfx/src/gtk/nsScreenGtk.cpp index 94c98ad2588..de72d29a087 100644 --- a/mozilla/gfx/src/gtk/nsScreenGtk.cpp +++ b/mozilla/gfx/src/gtk/nsScreenGtk.cpp @@ -110,3 +110,28 @@ nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth) } // GetColorDepth +NS_IMETHODIMP +nsScreenGtk :: GetGammaValue(double *aGammaValue) +{ + // XXX - Add more query options (XSolarisGetVisualGamma, XF86VidModeGetGamma) + +#if defined(__sgi) + *aGammaValue = 2.2/1.7; + FILE *infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + char tmpline[80]; + + fgets(tmpline, sizeof(tmpline), infile); + fclose(infile); + double sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + *aGammaValue = 2.2/sgi_gamma; + } +#elif defined(NeXT) + *aGammaValue = 1.0; +#else + *aGammaValue = 2.2; +#endif + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/mac/nsRenderingContextMac.cpp b/mozilla/gfx/src/mac/nsRenderingContextMac.cpp index 29bd80e1093..3a0bc43e6f9 100644 --- a/mozilla/gfx/src/mac/nsRenderingContextMac.cpp +++ b/mozilla/gfx/src/mac/nsRenderingContextMac.cpp @@ -762,9 +762,9 @@ NS_IMETHODIMP nsRenderingContextMac::SetColor(nscolor aColor) #define COLOR8TOCOLOR16(color8) ((color8 << 8) | color8) RGBColor color; - color.red = COLOR8TOCOLOR16(NS_GET_R(aColor)); - color.green = COLOR8TOCOLOR16(NS_GET_G(aColor)); - color.blue = COLOR8TOCOLOR16(NS_GET_B(aColor)); + color.red = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(aColor))); + color.green = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(aColor))); + color.blue = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(aColor))); ::RGBForeColor(&color); mGS->mColor = aColor ; diff --git a/mozilla/gfx/src/mac/nsScreenMac.cpp b/mozilla/gfx/src/mac/nsScreenMac.cpp index 055bdae5ad3..0790bb3b1aa 100644 --- a/mozilla/gfx/src/mac/nsScreenMac.cpp +++ b/mozilla/gfx/src/mac/nsScreenMac.cpp @@ -138,3 +138,13 @@ nsScreenMac :: SubtractMenuBar ( const Rect & inScreenRect, Rect* outAdjustedRec } #endif + +NS_IMETHODIMP +nsScreenMac :: GetGammaValue(double *aGammaValue) +{ + // XXX - Replace this with code to query the gamma value for your platform + + *aGammaValue = 2.2*(1.8/2.61); + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/nsColor.cpp b/mozilla/gfx/src/nsColor.cpp index c864d223703..804480ee02c 100644 --- a/mozilla/gfx/src/nsColor.cpp +++ b/mozilla/gfx/src/nsColor.cpp @@ -43,6 +43,11 @@ #include "nscore.h" #include "nsCoord.h" #include "nsUnitConversion.h" +#include "nsCOMPtr.h" +#include "nsIServiceManager.h" +#include "nsIScreen.h" +#include "nsIScreenManager.h" +#include static int ComponentValue(const char* aColorSpec, int aLen, int color, int dpc) { @@ -449,6 +454,38 @@ extern "C" NS_GFX_(nscolor) NS_DarkenColor(nscolor inColor) return NS_RGBA(r, g, b, NS_GET_A(inColor)); } + +/* Gamma correction stuff */ + +PR_IMPLEMENT_DATA(PRUint8) nsGammaRamp[256], nsInverseGammaRamp[256]; +static double gammaValue = 2.2; + +double NS_DisplayGammaValue(void) +{ + return gammaValue; +} + +void NS_InitializeGamma(void) +{ + nsresult result; + + nsCOMPtr screenmgr = + do_GetService("@mozilla.org/gfx/screenmanager;1", &result); + if (NS_SUCCEEDED(result)) { + nsCOMPtr screen; + screenmgr->GetPrimaryScreen(getter_AddRefs(screen)); + if (screen) + screen->GetGammaValue(&gammaValue); + } + + double gamma = 2.2/gammaValue; + + for (int i=0; i<256; i++) { + nsGammaRamp[i] = pow(double(i)/255.0, gamma) * 255.0 + 0.5; + nsInverseGammaRamp[i] = pow(double(i)/255.0, 1/gamma) * 255.0 + 0.5; + } +} + // Function to convert RGB color space into the HSV colorspace // Hue is the primary color defined from 0 to 359 degrees // Saturation is defined from 0 to 255. The higher the number.. the deeper the color diff --git a/mozilla/gfx/src/nsDeviceContext.cpp b/mozilla/gfx/src/nsDeviceContext.cpp index 4681b309f47..85a33a9f34a 100644 --- a/mozilla/gfx/src/nsDeviceContext.cpp +++ b/mozilla/gfx/src/nsDeviceContext.cpp @@ -42,9 +42,7 @@ DeviceContextImpl::DeviceContextImpl() mFontCache = nsnull; mDevUnitsToAppUnits = 1.0f; mAppUnitsToDevUnits = 1.0f; - mGammaValue = 1.0f; mCPixelScale = 1.0f; - mGammaTable = new PRUint8[256]; mZoom = 1.0f; mTextZoom = 1.0f; mWidget = nsnull; @@ -76,12 +74,6 @@ DeviceContextImpl::~DeviceContextImpl() mFontCache = nsnull; } - if (nsnull != mGammaTable) - { - delete[] mGammaTable; - mGammaTable = nsnull; - } - if (nsnull != mFontAliasTable) { mFontAliasTable->Enumerate(DeleteValue); delete mFontAliasTable; @@ -114,9 +106,6 @@ void DeviceContextImpl::CommonInit(void) mInitialized = PR_TRUE; #endif - for (PRInt32 cnt = 0; cnt < 256; cnt++) - mGammaTable[cnt] = cnt; - // register as a memory-pressure observer to free font resources // in low-memory situations. nsCOMPtr obs(do_GetService("@mozilla.org/observer-service;1")); @@ -347,43 +336,6 @@ NS_IMETHODIMP DeviceContextImpl::GetTextZoom(float &aTextZoom) const return NS_OK; } -NS_IMETHODIMP DeviceContextImpl::GetGamma(float &aGamma) -{ - aGamma = mGammaValue; - return NS_OK; -} - -NS_IMETHODIMP DeviceContextImpl::SetGamma(float aGamma) -{ - if (aGamma != mGammaValue) - { - //we don't need to-recorrect existing images for this case - //so pass in 1.0 for the current gamma regardless of what it - //really happens to be. existing images will get a one time - //re-correction when they're rendered the next time. MMP - - SetGammaTable(mGammaTable, 1.0f, aGamma); - - mGammaValue = aGamma; - } - return NS_OK; -} - -NS_IMETHODIMP DeviceContextImpl::GetGammaTable(PRUint8 *&aGammaTable) -{ - //XXX we really need to ref count this somehow. MMP - aGammaTable = mGammaTable; - return NS_OK; -} - -void DeviceContextImpl::SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma) -{ - double fgval = (1.0f / aCurrentGamma) * (1.0f / aNewGamma); - - for (PRInt32 cnt = 0; cnt < 256; cnt++) - aTable[cnt] = (PRUint8)(pow((double)cnt * (1. / 256.), fgval) * 255.99999999); -} - NS_IMETHODIMP DeviceContextImpl::GetDepth(PRUint32& aDepth) { aDepth = 24; diff --git a/mozilla/gfx/src/os2/nsRenderingContextOS2.cpp b/mozilla/gfx/src/os2/nsRenderingContextOS2.cpp index ebece8c4e5b..465790ef02c 100644 --- a/mozilla/gfx/src/os2/nsRenderingContextOS2.cpp +++ b/mozilla/gfx/src/os2/nsRenderingContextOS2.cpp @@ -328,8 +328,6 @@ nsresult nsRenderingContextOS2::CommonInit() mTranMatrix->AddScale( app2dev, app2dev); mContext->GetDevUnitsToAppUnits( mP2T); - mContext->GetGammaTable(mGammaTable); - return SetupPS (); } @@ -890,9 +888,9 @@ NS_IMETHODIMP nsRenderingContextOS2::DestroyDrawingSurface( nsDrawingSurface aDS LONG nsRenderingContextOS2::GetGPIColor (void) { - LONG gcolor = MK_RGB (mGammaTable [NS_GET_R (mColor)], - mGammaTable [NS_GET_G (mColor)], - mGammaTable [NS_GET_B (mColor)]); + LONG gcolor = MK_RGB (NS_GAMMA_CORRECT_COMPONENT(NS_GET_R (mColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G (mColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_B (mColor)); return (mPaletteMode) ? GFX (::GpiQueryColorIndex (mPS, 0, gcolor), GPI_ALTERROR) : gcolor ; diff --git a/mozilla/gfx/src/os2/nsRenderingContextOS2.h b/mozilla/gfx/src/os2/nsRenderingContextOS2.h index 36bc1efcc54..8adc5389529 100644 --- a/mozilla/gfx/src/os2/nsRenderingContextOS2.h +++ b/mozilla/gfx/src/os2/nsRenderingContextOS2.h @@ -256,7 +256,6 @@ protected: nscolor mCurrFillColor; // currently selected fill color PRBool mPreservedInitialClipRegion; PRBool mPaletteMode; // GPI colors are indexes into selected palette - PRUint8 *mGammaTable; HPS mPS; // GPI presentation space of current drawing surface nsIWidget *mDCOwner; // Parent widget FATTRS mCurrFont; diff --git a/mozilla/gfx/src/os2/nsScreenOS2.cpp b/mozilla/gfx/src/os2/nsScreenOS2.cpp index 2d9f5c49b31..4f478ef23b4 100644 --- a/mozilla/gfx/src/os2/nsScreenOS2.cpp +++ b/mozilla/gfx/src/os2/nsScreenOS2.cpp @@ -132,3 +132,12 @@ nsScreenOS2 :: GetColorDepth(PRInt32 *aColorDepth) } // GetColorDepth +NS_IMETHODIMP +nsScreenOS2 :: GetGammaValue(double *aGammaValue) +{ + // XXX - Replace this with code to query the gamma value for your platform + + *aGammaValue = 2.2; + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/photon/nsRenderingContextPh.cpp b/mozilla/gfx/src/photon/nsRenderingContextPh.cpp index 7db4f162112..76991b02f29 100644 --- a/mozilla/gfx/src/photon/nsRenderingContextPh.cpp +++ b/mozilla/gfx/src/photon/nsRenderingContextPh.cpp @@ -1216,10 +1216,12 @@ NS_IMETHODIMP nsRenderingContextPh::GetBoundingMetrics(const PRUnichar* aStrin void nsRenderingContextPh::UpdateGC() { + nscolor acolor = NS_GAMMA_CORRECT_COLOR(mCurrentColor); + PgSetGC(mGC); /* new */ - PgSetStrokeColor(NS_TO_PH_RGB(mCurrentColor)); - PgSetTextColor(NS_TO_PH_RGB(mCurrentColor)); - PgSetFillColor(NS_TO_PH_RGB(mCurrentColor)); + PgSetStrokeColor(NS_TO_PH_RGB(acolor)); + PgSetTextColor(NS_TO_PH_RGB(acolor)); + PgSetFillColor(NS_TO_PH_RGB(acolor)); PgSetStrokeDash(mLineStyle, strlen((char *)mLineStyle), 0x10000); // valuesMask = GdkGCValuesMask(valuesMask | GDK_GC_FUNCTION); diff --git a/mozilla/gfx/src/photon/nsScreenPh.cpp b/mozilla/gfx/src/photon/nsScreenPh.cpp index a98ca408825..74c900e941c 100644 --- a/mozilla/gfx/src/photon/nsScreenPh.cpp +++ b/mozilla/gfx/src/photon/nsScreenPh.cpp @@ -101,3 +101,13 @@ NS_IMETHODIMP nsScreenPh :: GetAvailRect( PRInt32 *outLeft, PRInt32 *outTop, PRI *outHeight = mHeight; return NS_OK; } + +NS_IMETHODIMP +nsScreenPh :: GetGammaValue(double *aGammaValue) +{ + // XXX - Replace this with code to query the gamma value for your platform + + *aGammaValue = 2.2; + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/ps/nsRenderingContextPS.cpp b/mozilla/gfx/src/ps/nsRenderingContextPS.cpp index 9e3b231b166..ab816771c2f 100644 --- a/mozilla/gfx/src/ps/nsRenderingContextPS.cpp +++ b/mozilla/gfx/src/ps/nsRenderingContextPS.cpp @@ -474,7 +474,7 @@ nsRenderingContextPS :: GetClipRegion(nsIRegion **aRegion) NS_IMETHODIMP nsRenderingContextPS :: SetColor(nscolor aColor) { - mPSObj->setcolor(aColor); + mPSObj->setcolor(NS_GAMMA_CORRECT_COLOR(aColor)); mCurrentColor = aColor; return NS_OK; diff --git a/mozilla/gfx/src/qt/nsRenderingContextQT.cpp b/mozilla/gfx/src/qt/nsRenderingContextQT.cpp index 3054d6c57f4..1278259b971 100644 --- a/mozilla/gfx/src/qt/nsRenderingContextQT.cpp +++ b/mozilla/gfx/src/qt/nsRenderingContextQT.cpp @@ -648,9 +648,9 @@ NS_IMETHODIMP nsRenderingContextQT::DestroyDrawingSurface(nsDrawingSurface aDS) void nsRenderingContextQT::UpdateGC() { QPainter *pGC; - QColor color(NS_GET_R(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); + QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor))); QPen pen(color,0,mQLineStyle); QBrush brush(color); @@ -822,8 +822,9 @@ NS_IMETHODIMP nsRenderingContextQT::FillRect(nscoord aX,nscoord aY, ConditionRect(x,y,w,h); UpdateGC(); - QColor color(NS_GET_R(mCurrentColor),NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); + QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor))); mSurface->GetGC()->fillRect(x,y,w,h,color); return NS_OK; @@ -859,8 +860,9 @@ NS_IMETHODIMP nsRenderingContextQT::InvertRect(nscoord aX,nscoord aY, UpdateGC(); // Fill the rect - QColor color(NS_GET_R(mCurrentColor),NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); + QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor))); mSurface->GetGC()->fillRect(x,y,w,h,color); diff --git a/mozilla/gfx/src/qt/nsScreenQT.cpp b/mozilla/gfx/src/qt/nsScreenQT.cpp index cad2c6c4aea..b6ca7d16508 100644 --- a/mozilla/gfx/src/qt/nsScreenQT.cpp +++ b/mozilla/gfx/src/qt/nsScreenQT.cpp @@ -110,3 +110,29 @@ nsScreenQT::GetColorDepth(PRInt32 *aColorDepth) { return GetPixelDepth(aColorDepth); } // GetColorDepth + +NS_IMETHODIMP +nsScreenQT :: GetGammaValue(double *aGammaValue) +{ + // XXX - Add more query options (XSolarisGetVisualGamma, XF86VidModeGetGamma) + +#if defined(__sgi) + *aGammaValue = 2.2/1.7; + FILE *infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + char tmpline[80]; + + fgets(tmpline, sizeof(tmpline), infile); + fclose(infile); + double sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + *aGammaValue = 2.2/sgi_gamma; + } +#elif defined(NeXT) + *aGammaValue = 1.0; +#else + *aGammaValue = 2.2; +#endif + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/windows/nsImageWin.cpp b/mozilla/gfx/src/windows/nsImageWin.cpp index 49127020cf6..617055c4bb0 100644 --- a/mozilla/gfx/src/windows/nsImageWin.cpp +++ b/mozilla/gfx/src/windows/nsImageWin.cpp @@ -232,50 +232,6 @@ nsresult nsImageWin :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMa void nsImageWin :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect) { - // XXX Any gamma correction should be done in the image library, and not - // here... -#if 0 - if (aFlags & nsImageUpdateFlags_kColorMapChanged){ - PRUint8 *gamma = aContext->GetGammaTable(); - - if (mColorMap->NumColors > 0){ - PRUint8* cpointer = mColorTable; - - for(PRInt32 i = 0; i < mColorMap->NumColors; i++){ - *cpointer++ = gamma[mColorMap->Index[(3 * i) + 2]]; - *cpointer++ = gamma[mColorMap->Index[(3 * i) + 1]]; - *cpointer++ = gamma[mColorMap->Index[(3 * i)]]; - *cpointer++ = 0; - } - } - }else if ((aFlags & nsImageUpdateFlags_kBitsChanged) &&(nsnull != aUpdateRect)){ - if (0 == mNumPaletteColors){ - PRInt32 x, y, span = CalcBytesSpan(mBHead->biWidth), idx; - PRUint8 *pixels = mImageBits + - (mBHead->biHeight - aUpdateRect->y - aUpdateRect->height) * span + - aUpdateRect->x * 3; - PRUint8 *gamma; - float gammaValue; - aContext->GetGammaTable(gamma); - aContext->GetGamma(gammaValue); - - // Gamma correct the image - if (1.0 != gammaValue){ - for (y = 0; y < aUpdateRect->height; y++){ - for (x = 0, idx = 0; x < aUpdateRect->width; x++){ - pixels[idx] = gamma[pixels[idx]]; - idx++; - pixels[idx] = gamma[pixels[idx]]; - idx++; - pixels[idx] = gamma[pixels[idx]]; - idx++; - } - pixels += span; - } - } - } - } -#endif } //------------------------------------------------------------ diff --git a/mozilla/gfx/src/windows/nsRenderingContextWin.cpp b/mozilla/gfx/src/windows/nsRenderingContextWin.cpp index 23d644da66b..f7fd9bd342d 100644 --- a/mozilla/gfx/src/windows/nsRenderingContextWin.cpp +++ b/mozilla/gfx/src/windows/nsRenderingContextWin.cpp @@ -507,8 +507,6 @@ nsresult nsRenderingContextWin :: CommonInit(void) mInitialized = PR_TRUE; #endif - mContext->GetGammaTable(mGammaTable); - return SetupDC(nsnull, mDC); } @@ -964,9 +962,9 @@ NS_IMETHODIMP nsRenderingContextWin :: GetClipRegion(nsIRegion **aRegion) NS_IMETHODIMP nsRenderingContextWin :: SetColor(nscolor aColor) { mCurrentColor = aColor; - mColor = RGB(mGammaTable[NS_GET_R(aColor)], - mGammaTable[NS_GET_G(aColor)], - mGammaTable[NS_GET_B(aColor)]); + mColor = RGB(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(aColor)), + NS_GAMMA_CORRECT_COMPONENT(NG_GET_G(aColor)), + NS_GAMMA_CORRECT_COMPONENT(NG_GET_B(aColor))); return NS_OK; } diff --git a/mozilla/gfx/src/windows/nsScreenWin.cpp b/mozilla/gfx/src/windows/nsScreenWin.cpp index b4fbe8c556b..396812a5059 100644 --- a/mozilla/gfx/src/windows/nsScreenWin.cpp +++ b/mozilla/gfx/src/windows/nsScreenWin.cpp @@ -190,3 +190,12 @@ nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth) } // GetColorDepth +NS_IMETHODIMP +nsScreenWin :: GetGammaValue(double *aGammaValue) +{ + // XXX - Replace this with code to query the gamma value for your platform + + *aGammaValue = 2.2; + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp b/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp index f9638b1fbfb..02555a8927a 100644 --- a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -546,9 +546,9 @@ void nsRenderingContextXlib::UpdateGC() unsigned long color; color = xxlib_rgb_xpixel_from_rgb (mXlibRgbHandle, - NS_RGB(NS_GET_B(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_R(mCurrentColor))); + NS_RGB(NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)), + NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)))); values.foreground = color; valuesMask |= GCForeground; diff --git a/mozilla/gfx/src/xlib/nsScreenXlib.cpp b/mozilla/gfx/src/xlib/nsScreenXlib.cpp index bf1cfa4503a..a1f851162b4 100644 --- a/mozilla/gfx/src/xlib/nsScreenXlib.cpp +++ b/mozilla/gfx/src/xlib/nsScreenXlib.cpp @@ -118,3 +118,28 @@ nsScreenXlib :: GetColorDepth(PRInt32 *aColorDepth) } // GetColorDepth +NS_IMETHODIMP +nsScreenXlib :: GetGammaValue(double *aGammaValue) +{ + // XXX - Add more query options (XSolarisGetVisualGamma, XF86VidModeGetGamma) + +#if defined(__sgi) + *aGammaValue = 2.2/1.7; + FILE *infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + char tmpline[80]; + + fgets(tmpline, sizeof(tmpline), infile); + fclose(infile); + double sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + *aGammaValue = 2.2/sgi_gamma; + } +#elif defined(NeXT) + *aGammaValue = 1.0; +#else + *aGammaValue = 2.2; +#endif + + return NS_OK; +} // GetGammaValue diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 5757af6a1a2..dccdf547ce9 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -120,6 +120,8 @@ Initialize(nsIModule* self) nsCSSFrameConstructor::InitGlobals(); + NS_InitializeGamma(); + return nsTextTransformer::Initialize(); } diff --git a/mozilla/modules/libpr0n/decoders/bmp/Makefile.in b/mozilla/modules/libpr0n/decoders/bmp/Makefile.in index ea5d6cccc45..f0b412a09e2 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/Makefile.in +++ b/mozilla/modules/libpr0n/decoders/bmp/Makefile.in @@ -33,9 +33,7 @@ EXPORT_LIBRARY = 1 IS_COMPONENT = 1 MODULE_NAME = nsBMPModule -ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx -endif REQUIRES = xpcom \ gfx \ diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp index c7a224f7c12..fc3e1abc495 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp @@ -156,13 +156,13 @@ inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 *aDecoded++ = 0; // Mac needs this padding byte #endif #ifdef USE_RGB - *aDecoded++ = aRed; - *aDecoded++ = aGreen; - *aDecoded++ = aBlue; + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue); #else - *aDecoded++ = aBlue; - *aDecoded++ = aGreen; - *aDecoded++ = aRed; + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed); #endif return NS_OK; } diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp index 542af286522..a9592715418 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp @@ -77,13 +77,13 @@ inline nsresult nsICODecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 *aDecoded++ = 0; // Mac needs this padding byte #endif #ifdef USE_RGBA1 - *aDecoded++ = aRed; - *aDecoded++ = aGreen; - *aDecoded++ = aBlue; + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue); #else - *aDecoded++ = aBlue; - *aDecoded++ = aGreen; - *aDecoded++ = aRed; + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen); + *aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed); #endif return NS_OK; } diff --git a/mozilla/modules/libpr0n/decoders/gif/GIF2.cpp b/mozilla/modules/libpr0n/decoders/gif/GIF2.cpp index b7be1354e7d..bd528b56ef1 100644 --- a/mozilla/modules/libpr0n/decoders/gif/GIF2.cpp +++ b/mozilla/modules/libpr0n/decoders/gif/GIF2.cpp @@ -78,6 +78,7 @@ mailing address. #include "nsCRT.h" #include "nsRecyclingAllocator.h" #include "nsAutoLock.h" +#include "nsColor.h" /******************************************************************************* * Gif decoder allocator @@ -951,9 +952,9 @@ PRStatus gif_write(gif_struct *gs, const PRUint8 *buf, PRUint32 len) #endif /* M12N */ for (int i=0; i < gs->global_colormap_size; i++, map++) { - map->red = *q++; - map->green = *q++; - map->blue = *q++; + map->red = NS_GAMMA_CORRECT_COMPONENT(*q++); + map->green = NS_GAMMA_CORRECT_COMPONENT(*q++); + map->blue = NS_GAMMA_CORRECT_COMPONENT(*q++); } GETN(1,gif_image_start); @@ -1334,9 +1335,9 @@ PRStatus gif_write(gif_struct *gs, const PRUint8 *buf, PRUint32 len) for (int i=0; i < gs->local_colormap_size; i++, map++) { - map->red = *q++; - map->green = *q++; - map->blue = *q++; + map->red = NS_GAMMA_CORRECT_COMPONENT(*q++); + map->green = NS_GAMMA_CORRECT_COMPONENT(*q++); + map->blue = NS_GAMMA_CORRECT_COMPONENT(*q++); } GETN(1,gif_lzw_start); diff --git a/mozilla/modules/libpr0n/decoders/gif/Makefile.in b/mozilla/modules/libpr0n/decoders/gif/Makefile.in index d0d0889d2ef..4f413e1ba42 100644 --- a/mozilla/modules/libpr0n/decoders/gif/Makefile.in +++ b/mozilla/modules/libpr0n/decoders/gif/Makefile.in @@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1 IS_COMPONENT = 1 MODULE_NAME = nsGIFModule2 -ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx -endif REQUIRES = xpcom \ gfx \ diff --git a/mozilla/modules/libpr0n/decoders/jpeg/Makefile.in b/mozilla/modules/libpr0n/decoders/jpeg/Makefile.in index d1596342743..1d69c2230fa 100644 --- a/mozilla/modules/libpr0n/decoders/jpeg/Makefile.in +++ b/mozilla/modules/libpr0n/decoders/jpeg/Makefile.in @@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1 IS_COMPONENT = 1 MODULE_NAME = nsJPEGDecoderModule -ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx -endif REQUIRES = xpcom \ string \ diff --git a/mozilla/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp b/mozilla/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp index 5ceaeade3ef..01a0ebe2f38 100644 --- a/mozilla/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp @@ -32,6 +32,7 @@ #include "nspr.h" #include "nsCRT.h" #include "ImageLogging.h" +#include "nsColor.h" NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder) @@ -497,14 +498,14 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines) /* Convert from grayscale to RGB. */ while (j1 < j1end) { #if defined(XP_MAC) || defined(XP_MACOSX) - j = *j1++; + j = NS_GAMMA_CORRECT_COMPONENT(*j1++); j3[0] = 0; j3[1] = j; j3[2] = j; j3[3] = j; j3 += 4; #else - j = *j1++; + j = NS_GAMMA_CORRECT_COMPONENT(*j1++); j3[0] = j; j3[1] = j; j3[2] = j; @@ -520,9 +521,9 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines) JSAMPLE *j1 = mSamples[0]; for (PRUint32 i=0;i