Bug 53597 - consistent gamma correction. r=dbaron, sr=brendan
git-svn-id: svn://10.0.0.236/trunk@118919 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
920e9131fd
commit
b8025de88e
@ -3930,7 +3930,6 @@ nsDocShell::EnsureDeviceContext()
|
|||||||
float twip2dev;
|
float twip2dev;
|
||||||
mDeviceContext->GetTwipsToDevUnits(twip2dev);
|
mDeviceContext->GetTwipsToDevUnits(twip2dev);
|
||||||
mDeviceContext->SetAppUnitsToDevUnits(twip2dev);
|
mDeviceContext->SetAppUnitsToDevUnits(twip2dev);
|
||||||
mDeviceContext->SetGamma(1.0f);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ interface nsIScreen : nsISupports
|
|||||||
|
|
||||||
readonly attribute long pixelDepth;
|
readonly attribute long pixelDepth;
|
||||||
readonly attribute long colorDepth;
|
readonly attribute long colorDepth;
|
||||||
|
readonly attribute double gammaValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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
|
// 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);
|
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___ */
|
#endif /* nsColor_h___ */
|
||||||
|
|||||||
@ -118,11 +118,6 @@ public:
|
|||||||
NS_IMETHOD SetTextZoom(float aTextZoom);
|
NS_IMETHOD SetTextZoom(float aTextZoom);
|
||||||
NS_IMETHOD GetTextZoom(float &aTextZoom) const;
|
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 FirstExistingFont(const nsFont& aFont, nsString& aFaceName);
|
||||||
|
|
||||||
NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
|
NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
|
||||||
@ -150,7 +145,6 @@ protected:
|
|||||||
virtual ~DeviceContextImpl();
|
virtual ~DeviceContextImpl();
|
||||||
|
|
||||||
void CommonInit(void);
|
void CommonInit(void);
|
||||||
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
|
|
||||||
nsresult CreateIconILGroupContext();
|
nsresult CreateIconILGroupContext();
|
||||||
virtual nsresult CreateFontAliasTable();
|
virtual nsresult CreateFontAliasTable();
|
||||||
nsresult AliasFont(const nsString& aFont,
|
nsresult AliasFont(const nsString& aFont,
|
||||||
@ -166,8 +160,6 @@ protected:
|
|||||||
nsCOMPtr<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
|
nsCOMPtr<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
|
||||||
float mZoom;
|
float mZoom;
|
||||||
float mTextZoom;
|
float mTextZoom;
|
||||||
float mGammaValue;
|
|
||||||
PRUint8 *mGammaTable;
|
|
||||||
nsHashtable* mFontAliasTable;
|
nsHashtable* mFontAliasTable;
|
||||||
float mCPixelScale;
|
float mCPixelScale;
|
||||||
|
|
||||||
|
|||||||
@ -381,13 +381,6 @@ public:
|
|||||||
//in the device context for re-use.
|
//in the device context for re-use.
|
||||||
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface) = 0;
|
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.
|
* Check to see if a particular named font exists.
|
||||||
* @param aFontName character string of font face name
|
* @param aFontName character string of font face name
|
||||||
|
|||||||
@ -118,7 +118,6 @@ NS_IMETHODIMP nsRenderingContextBeOS::CommonInit() {
|
|||||||
float app2dev;
|
float app2dev;
|
||||||
mContext->GetAppUnitsToDevUnits(app2dev);
|
mContext->GetAppUnitsToDevUnits(app2dev);
|
||||||
mTranMatrix->AddScale(app2dev, app2dev);
|
mTranMatrix->AddScale(app2dev, app2dev);
|
||||||
mContext->GetGammaTable(mGammaTable);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,8 +297,10 @@ void nsRenderingContextBeOS::UpdateView() {
|
|||||||
if (mCurrentFont == nsnull) mCurrentFont = (BFont *)be_plain_font;
|
if (mCurrentFont == nsnull) mCurrentFont = (BFont *)be_plain_font;
|
||||||
|
|
||||||
mView->SetFont(mCurrentFont);
|
mView->SetFont(mCurrentFont);
|
||||||
mView->SetHighColor(mGammaTable[NS_GET_R(mCurrentColor)],
|
mView->SetHighColor(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)),
|
||||||
mGammaTable[NS_GET_G(mCurrentColor)], mGammaTable[NS_GET_B(mCurrentColor)], 255);
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)),
|
||||||
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor)),
|
||||||
|
255);
|
||||||
|
|
||||||
BRegion *region = nsnull;
|
BRegion *region = nsnull;
|
||||||
if (mClipRegion) {
|
if (mClipRegion) {
|
||||||
|
|||||||
@ -224,7 +224,6 @@ protected:
|
|||||||
nsCOMPtr<nsIRegion> mClipRegion;
|
nsCOMPtr<nsIRegion> mClipRegion;
|
||||||
nsVoidArray *mStateCache;
|
nsVoidArray *mStateCache;
|
||||||
BView *mView;
|
BView *mView;
|
||||||
PRUint8 *mGammaTable;
|
|
||||||
nscolor mCurrentColor;
|
nscolor mCurrentColor;
|
||||||
BFont *mCurrentFont;
|
BFont *mCurrentFont;
|
||||||
nsLineStyle mCurrentLineStyle;
|
nsLineStyle mCurrentLineStyle;
|
||||||
|
|||||||
@ -135,3 +135,12 @@ nsScreenBeOS :: GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -522,7 +522,8 @@ void nsRenderingContextGTK::UpdateGC()
|
|||||||
|
|
||||||
memset(&values, 0, sizeof(GdkGCValues));
|
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;
|
valuesMask = GDK_GC_FOREGROUND;
|
||||||
|
|
||||||
if ((mCurrentFont) && (mCurrentFont->GetGDKFont())) {
|
if ((mCurrentFont) && (mCurrentFont->GetGDKFont())) {
|
||||||
|
|||||||
@ -110,3 +110,28 @@ nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -762,9 +762,9 @@ NS_IMETHODIMP nsRenderingContextMac::SetColor(nscolor aColor)
|
|||||||
#define COLOR8TOCOLOR16(color8) ((color8 << 8) | color8)
|
#define COLOR8TOCOLOR16(color8) ((color8 << 8) | color8)
|
||||||
|
|
||||||
RGBColor color;
|
RGBColor color;
|
||||||
color.red = COLOR8TOCOLOR16(NS_GET_R(aColor));
|
color.red = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(aColor)));
|
||||||
color.green = COLOR8TOCOLOR16(NS_GET_G(aColor));
|
color.green = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(aColor)));
|
||||||
color.blue = COLOR8TOCOLOR16(NS_GET_B(aColor));
|
color.blue = COLOR8TOCOLOR16(NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(aColor)));
|
||||||
::RGBForeColor(&color);
|
::RGBForeColor(&color);
|
||||||
mGS->mColor = aColor ;
|
mGS->mColor = aColor ;
|
||||||
|
|
||||||
|
|||||||
@ -138,3 +138,13 @@ nsScreenMac :: SubtractMenuBar ( const Rect & inScreenRect, Rect* outAdjustedRec
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
|
|||||||
@ -43,6 +43,11 @@
|
|||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsCoord.h"
|
#include "nsCoord.h"
|
||||||
#include "nsUnitConversion.h"
|
#include "nsUnitConversion.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsIScreen.h"
|
||||||
|
#include "nsIScreenManager.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
static int ComponentValue(const char* aColorSpec, int aLen, int color, int dpc)
|
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));
|
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<nsIScreenManager> screenmgr =
|
||||||
|
do_GetService("@mozilla.org/gfx/screenmanager;1", &result);
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
nsCOMPtr<nsIScreen> 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
|
// Function to convert RGB color space into the HSV colorspace
|
||||||
// Hue is the primary color defined from 0 to 359 degrees
|
// 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
|
// Saturation is defined from 0 to 255. The higher the number.. the deeper the color
|
||||||
|
|||||||
@ -42,9 +42,7 @@ DeviceContextImpl::DeviceContextImpl()
|
|||||||
mFontCache = nsnull;
|
mFontCache = nsnull;
|
||||||
mDevUnitsToAppUnits = 1.0f;
|
mDevUnitsToAppUnits = 1.0f;
|
||||||
mAppUnitsToDevUnits = 1.0f;
|
mAppUnitsToDevUnits = 1.0f;
|
||||||
mGammaValue = 1.0f;
|
|
||||||
mCPixelScale = 1.0f;
|
mCPixelScale = 1.0f;
|
||||||
mGammaTable = new PRUint8[256];
|
|
||||||
mZoom = 1.0f;
|
mZoom = 1.0f;
|
||||||
mTextZoom = 1.0f;
|
mTextZoom = 1.0f;
|
||||||
mWidget = nsnull;
|
mWidget = nsnull;
|
||||||
@ -76,12 +74,6 @@ DeviceContextImpl::~DeviceContextImpl()
|
|||||||
mFontCache = nsnull;
|
mFontCache = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsnull != mGammaTable)
|
|
||||||
{
|
|
||||||
delete[] mGammaTable;
|
|
||||||
mGammaTable = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsnull != mFontAliasTable) {
|
if (nsnull != mFontAliasTable) {
|
||||||
mFontAliasTable->Enumerate(DeleteValue);
|
mFontAliasTable->Enumerate(DeleteValue);
|
||||||
delete mFontAliasTable;
|
delete mFontAliasTable;
|
||||||
@ -114,9 +106,6 @@ void DeviceContextImpl::CommonInit(void)
|
|||||||
mInitialized = PR_TRUE;
|
mInitialized = PR_TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
|
||||||
mGammaTable[cnt] = cnt;
|
|
||||||
|
|
||||||
// register as a memory-pressure observer to free font resources
|
// register as a memory-pressure observer to free font resources
|
||||||
// in low-memory situations.
|
// in low-memory situations.
|
||||||
nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
|
nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
|
||||||
@ -347,43 +336,6 @@ NS_IMETHODIMP DeviceContextImpl::GetTextZoom(float &aTextZoom) const
|
|||||||
return NS_OK;
|
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)
|
NS_IMETHODIMP DeviceContextImpl::GetDepth(PRUint32& aDepth)
|
||||||
{
|
{
|
||||||
aDepth = 24;
|
aDepth = 24;
|
||||||
|
|||||||
@ -328,8 +328,6 @@ nsresult nsRenderingContextOS2::CommonInit()
|
|||||||
mTranMatrix->AddScale( app2dev, app2dev);
|
mTranMatrix->AddScale( app2dev, app2dev);
|
||||||
mContext->GetDevUnitsToAppUnits( mP2T);
|
mContext->GetDevUnitsToAppUnits( mP2T);
|
||||||
|
|
||||||
mContext->GetGammaTable(mGammaTable);
|
|
||||||
|
|
||||||
return SetupPS ();
|
return SetupPS ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,9 +888,9 @@ NS_IMETHODIMP nsRenderingContextOS2::DestroyDrawingSurface( nsDrawingSurface aDS
|
|||||||
|
|
||||||
LONG nsRenderingContextOS2::GetGPIColor (void)
|
LONG nsRenderingContextOS2::GetGPIColor (void)
|
||||||
{
|
{
|
||||||
LONG gcolor = MK_RGB (mGammaTable [NS_GET_R (mColor)],
|
LONG gcolor = MK_RGB (NS_GAMMA_CORRECT_COMPONENT(NS_GET_R (mColor)),
|
||||||
mGammaTable [NS_GET_G (mColor)],
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_G (mColor)),
|
||||||
mGammaTable [NS_GET_B (mColor)]);
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_B (mColor));
|
||||||
|
|
||||||
return (mPaletteMode) ? GFX (::GpiQueryColorIndex (mPS, 0, gcolor), GPI_ALTERROR) :
|
return (mPaletteMode) ? GFX (::GpiQueryColorIndex (mPS, 0, gcolor), GPI_ALTERROR) :
|
||||||
gcolor ;
|
gcolor ;
|
||||||
|
|||||||
@ -256,7 +256,6 @@ protected:
|
|||||||
nscolor mCurrFillColor; // currently selected fill color
|
nscolor mCurrFillColor; // currently selected fill color
|
||||||
PRBool mPreservedInitialClipRegion;
|
PRBool mPreservedInitialClipRegion;
|
||||||
PRBool mPaletteMode; // GPI colors are indexes into selected palette
|
PRBool mPaletteMode; // GPI colors are indexes into selected palette
|
||||||
PRUint8 *mGammaTable;
|
|
||||||
HPS mPS; // GPI presentation space of current drawing surface
|
HPS mPS; // GPI presentation space of current drawing surface
|
||||||
nsIWidget *mDCOwner; // Parent widget
|
nsIWidget *mDCOwner; // Parent widget
|
||||||
FATTRS mCurrFont;
|
FATTRS mCurrFont;
|
||||||
|
|||||||
@ -132,3 +132,12 @@ nsScreenOS2 :: GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -1216,10 +1216,12 @@ NS_IMETHODIMP nsRenderingContextPh::GetBoundingMetrics(const PRUnichar* aStrin
|
|||||||
|
|
||||||
void nsRenderingContextPh::UpdateGC()
|
void nsRenderingContextPh::UpdateGC()
|
||||||
{
|
{
|
||||||
|
nscolor acolor = NS_GAMMA_CORRECT_COLOR(mCurrentColor);
|
||||||
|
|
||||||
PgSetGC(mGC); /* new */
|
PgSetGC(mGC); /* new */
|
||||||
PgSetStrokeColor(NS_TO_PH_RGB(mCurrentColor));
|
PgSetStrokeColor(NS_TO_PH_RGB(acolor));
|
||||||
PgSetTextColor(NS_TO_PH_RGB(mCurrentColor));
|
PgSetTextColor(NS_TO_PH_RGB(acolor));
|
||||||
PgSetFillColor(NS_TO_PH_RGB(mCurrentColor));
|
PgSetFillColor(NS_TO_PH_RGB(acolor));
|
||||||
PgSetStrokeDash(mLineStyle, strlen((char *)mLineStyle), 0x10000);
|
PgSetStrokeDash(mLineStyle, strlen((char *)mLineStyle), 0x10000);
|
||||||
|
|
||||||
// valuesMask = GdkGCValuesMask(valuesMask | GDK_GC_FUNCTION);
|
// valuesMask = GdkGCValuesMask(valuesMask | GDK_GC_FUNCTION);
|
||||||
|
|||||||
@ -101,3 +101,13 @@ NS_IMETHODIMP nsScreenPh :: GetAvailRect( PRInt32 *outLeft, PRInt32 *outTop, PRI
|
|||||||
*outHeight = mHeight;
|
*outHeight = mHeight;
|
||||||
return NS_OK;
|
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
|
||||||
|
|||||||
@ -474,7 +474,7 @@ nsRenderingContextPS :: GetClipRegion(nsIRegion **aRegion)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsRenderingContextPS :: SetColor(nscolor aColor)
|
nsRenderingContextPS :: SetColor(nscolor aColor)
|
||||||
{
|
{
|
||||||
mPSObj->setcolor(aColor);
|
mPSObj->setcolor(NS_GAMMA_CORRECT_COLOR(aColor));
|
||||||
mCurrentColor = aColor;
|
mCurrentColor = aColor;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|||||||
@ -648,9 +648,9 @@ NS_IMETHODIMP nsRenderingContextQT::DestroyDrawingSurface(nsDrawingSurface aDS)
|
|||||||
void nsRenderingContextQT::UpdateGC()
|
void nsRenderingContextQT::UpdateGC()
|
||||||
{
|
{
|
||||||
QPainter *pGC;
|
QPainter *pGC;
|
||||||
QColor color(NS_GET_R(mCurrentColor),
|
QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)),
|
||||||
NS_GET_G(mCurrentColor),
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)),
|
||||||
NS_GET_B(mCurrentColor));
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor)));
|
||||||
QPen pen(color,0,mQLineStyle);
|
QPen pen(color,0,mQLineStyle);
|
||||||
QBrush brush(color);
|
QBrush brush(color);
|
||||||
|
|
||||||
@ -822,8 +822,9 @@ NS_IMETHODIMP nsRenderingContextQT::FillRect(nscoord aX,nscoord aY,
|
|||||||
ConditionRect(x,y,w,h);
|
ConditionRect(x,y,w,h);
|
||||||
UpdateGC();
|
UpdateGC();
|
||||||
|
|
||||||
QColor color(NS_GET_R(mCurrentColor),NS_GET_G(mCurrentColor),
|
QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)),
|
||||||
NS_GET_B(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);
|
mSurface->GetGC()->fillRect(x,y,w,h,color);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@ -859,8 +860,9 @@ NS_IMETHODIMP nsRenderingContextQT::InvertRect(nscoord aX,nscoord aY,
|
|||||||
UpdateGC();
|
UpdateGC();
|
||||||
|
|
||||||
// Fill the rect
|
// Fill the rect
|
||||||
QColor color(NS_GET_R(mCurrentColor),NS_GET_G(mCurrentColor),
|
QColor color(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor)),
|
||||||
NS_GET_B(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);
|
mSurface->GetGC()->fillRect(x,y,w,h,color);
|
||||||
|
|
||||||
|
|||||||
@ -110,3 +110,29 @@ nsScreenQT::GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
{
|
{
|
||||||
return GetPixelDepth(aColorDepth);
|
return GetPixelDepth(aColorDepth);
|
||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -232,50 +232,6 @@ nsresult nsImageWin :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMa
|
|||||||
void
|
void
|
||||||
nsImageWin :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|||||||
@ -507,8 +507,6 @@ nsresult nsRenderingContextWin :: CommonInit(void)
|
|||||||
mInitialized = PR_TRUE;
|
mInitialized = PR_TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mContext->GetGammaTable(mGammaTable);
|
|
||||||
|
|
||||||
return SetupDC(nsnull, mDC);
|
return SetupDC(nsnull, mDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -964,9 +962,9 @@ NS_IMETHODIMP nsRenderingContextWin :: GetClipRegion(nsIRegion **aRegion)
|
|||||||
NS_IMETHODIMP nsRenderingContextWin :: SetColor(nscolor aColor)
|
NS_IMETHODIMP nsRenderingContextWin :: SetColor(nscolor aColor)
|
||||||
{
|
{
|
||||||
mCurrentColor = aColor;
|
mCurrentColor = aColor;
|
||||||
mColor = RGB(mGammaTable[NS_GET_R(aColor)],
|
mColor = RGB(NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(aColor)),
|
||||||
mGammaTable[NS_GET_G(aColor)],
|
NS_GAMMA_CORRECT_COMPONENT(NG_GET_G(aColor)),
|
||||||
mGammaTable[NS_GET_B(aColor)]);
|
NS_GAMMA_CORRECT_COMPONENT(NG_GET_B(aColor)));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -190,3 +190,12 @@ nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -546,9 +546,9 @@ void nsRenderingContextXlib::UpdateGC()
|
|||||||
|
|
||||||
unsigned long color;
|
unsigned long color;
|
||||||
color = xxlib_rgb_xpixel_from_rgb (mXlibRgbHandle,
|
color = xxlib_rgb_xpixel_from_rgb (mXlibRgbHandle,
|
||||||
NS_RGB(NS_GET_B(mCurrentColor),
|
NS_RGB(NS_GAMMA_CORRECT_COMPONENT(NS_GET_B(mCurrentColor)),
|
||||||
NS_GET_G(mCurrentColor),
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_G(mCurrentColor)),
|
||||||
NS_GET_R(mCurrentColor)));
|
NS_GAMMA_CORRECT_COMPONENT(NS_GET_R(mCurrentColor))));
|
||||||
values.foreground = color;
|
values.foreground = color;
|
||||||
valuesMask |= GCForeground;
|
valuesMask |= GCForeground;
|
||||||
|
|
||||||
|
|||||||
@ -118,3 +118,28 @@ nsScreenXlib :: GetColorDepth(PRInt32 *aColorDepth)
|
|||||||
} // GetColorDepth
|
} // 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
|
||||||
|
|||||||
@ -120,6 +120,8 @@ Initialize(nsIModule* self)
|
|||||||
|
|
||||||
nsCSSFrameConstructor::InitGlobals();
|
nsCSSFrameConstructor::InitGlobals();
|
||||||
|
|
||||||
|
NS_InitializeGamma();
|
||||||
|
|
||||||
return nsTextTransformer::Initialize();
|
return nsTextTransformer::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,9 +33,7 @@ EXPORT_LIBRARY = 1
|
|||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
MODULE_NAME = nsBMPModule
|
MODULE_NAME = nsBMPModule
|
||||||
|
|
||||||
ifeq ($(OS_ARCH),WINNT)
|
|
||||||
EXTRA_DSO_LIBS = gkgfx
|
EXTRA_DSO_LIBS = gkgfx
|
||||||
endif
|
|
||||||
|
|
||||||
REQUIRES = xpcom \
|
REQUIRES = xpcom \
|
||||||
gfx \
|
gfx \
|
||||||
|
|||||||
@ -156,13 +156,13 @@ inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8
|
|||||||
*aDecoded++ = 0; // Mac needs this padding byte
|
*aDecoded++ = 0; // Mac needs this padding byte
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_RGB
|
#ifdef USE_RGB
|
||||||
*aDecoded++ = aRed;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed);
|
||||||
*aDecoded++ = aGreen;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen);
|
||||||
*aDecoded++ = aBlue;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue);
|
||||||
#else
|
#else
|
||||||
*aDecoded++ = aBlue;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue);
|
||||||
*aDecoded++ = aGreen;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen);
|
||||||
*aDecoded++ = aRed;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed);
|
||||||
#endif
|
#endif
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,13 +77,13 @@ inline nsresult nsICODecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8
|
|||||||
*aDecoded++ = 0; // Mac needs this padding byte
|
*aDecoded++ = 0; // Mac needs this padding byte
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_RGBA1
|
#ifdef USE_RGBA1
|
||||||
*aDecoded++ = aRed;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed);
|
||||||
*aDecoded++ = aGreen;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen);
|
||||||
*aDecoded++ = aBlue;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue);
|
||||||
#else
|
#else
|
||||||
*aDecoded++ = aBlue;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aBlue);
|
||||||
*aDecoded++ = aGreen;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aGreen);
|
||||||
*aDecoded++ = aRed;
|
*aDecoded++ = NS_GAMMA_CORRECT_COMPONENT(aRed);
|
||||||
#endif
|
#endif
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,7 @@ mailing address.
|
|||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsRecyclingAllocator.h"
|
#include "nsRecyclingAllocator.h"
|
||||||
#include "nsAutoLock.h"
|
#include "nsAutoLock.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Gif decoder allocator
|
* Gif decoder allocator
|
||||||
@ -951,9 +952,9 @@ PRStatus gif_write(gif_struct *gs, const PRUint8 *buf, PRUint32 len)
|
|||||||
#endif /* M12N */
|
#endif /* M12N */
|
||||||
for (int i=0; i < gs->global_colormap_size; i++, map++)
|
for (int i=0; i < gs->global_colormap_size; i++, map++)
|
||||||
{
|
{
|
||||||
map->red = *q++;
|
map->red = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
map->green = *q++;
|
map->green = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
map->blue = *q++;
|
map->blue = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
}
|
}
|
||||||
|
|
||||||
GETN(1,gif_image_start);
|
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++)
|
for (int i=0; i < gs->local_colormap_size; i++, map++)
|
||||||
{
|
{
|
||||||
map->red = *q++;
|
map->red = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
map->green = *q++;
|
map->green = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
map->blue = *q++;
|
map->blue = NS_GAMMA_CORRECT_COMPONENT(*q++);
|
||||||
}
|
}
|
||||||
|
|
||||||
GETN(1,gif_lzw_start);
|
GETN(1,gif_lzw_start);
|
||||||
|
|||||||
@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1
|
|||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
MODULE_NAME = nsGIFModule2
|
MODULE_NAME = nsGIFModule2
|
||||||
|
|
||||||
ifeq ($(OS_ARCH),WINNT)
|
|
||||||
EXTRA_DSO_LIBS = gkgfx
|
EXTRA_DSO_LIBS = gkgfx
|
||||||
endif
|
|
||||||
|
|
||||||
REQUIRES = xpcom \
|
REQUIRES = xpcom \
|
||||||
gfx \
|
gfx \
|
||||||
|
|||||||
@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1
|
|||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
MODULE_NAME = nsJPEGDecoderModule
|
MODULE_NAME = nsJPEGDecoderModule
|
||||||
|
|
||||||
ifeq ($(OS_ARCH),WINNT)
|
|
||||||
EXTRA_DSO_LIBS = gkgfx
|
EXTRA_DSO_LIBS = gkgfx
|
||||||
endif
|
|
||||||
|
|
||||||
REQUIRES = xpcom \
|
REQUIRES = xpcom \
|
||||||
string \
|
string \
|
||||||
|
|||||||
@ -32,6 +32,7 @@
|
|||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "ImageLogging.h"
|
#include "ImageLogging.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder)
|
NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder)
|
||||||
|
|
||||||
@ -497,14 +498,14 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines)
|
|||||||
/* Convert from grayscale to RGB. */
|
/* Convert from grayscale to RGB. */
|
||||||
while (j1 < j1end) {
|
while (j1 < j1end) {
|
||||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||||
j = *j1++;
|
j = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
j3[0] = 0;
|
j3[0] = 0;
|
||||||
j3[1] = j;
|
j3[1] = j;
|
||||||
j3[2] = j;
|
j3[2] = j;
|
||||||
j3[3] = j;
|
j3[3] = j;
|
||||||
j3 += 4;
|
j3 += 4;
|
||||||
#else
|
#else
|
||||||
j = *j1++;
|
j = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
j3[0] = j;
|
j3[0] = j;
|
||||||
j3[1] = j;
|
j3[1] = j;
|
||||||
j3[2] = j;
|
j3[2] = j;
|
||||||
@ -520,9 +521,9 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines)
|
|||||||
|
|
||||||
JSAMPLE *j1 = mSamples[0];
|
JSAMPLE *j1 = mSamples[0];
|
||||||
for (PRUint32 i=0;i<mInfo.output_width;++i) {
|
for (PRUint32 i=0;i<mInfo.output_width;++i) {
|
||||||
ptrOutputBuf[2] = *j1++;
|
ptrOutputBuf[2] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf[1] = *j1++;
|
ptrOutputBuf[1] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf[0] = *j1++;
|
ptrOutputBuf[0] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf += 3;
|
ptrOutputBuf += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,9 +535,9 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines)
|
|||||||
JSAMPLE *j1 = mSamples[0];
|
JSAMPLE *j1 = mSamples[0];
|
||||||
for (PRUint32 i=0;i<mInfo.output_width;++i) {
|
for (PRUint32 i=0;i<mInfo.output_width;++i) {
|
||||||
ptrOutputBuf[0] = 0;
|
ptrOutputBuf[0] = 0;
|
||||||
ptrOutputBuf[1] = *j1++;
|
ptrOutputBuf[1] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf[2] = *j1++;
|
ptrOutputBuf[2] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf[3] = *j1++;
|
ptrOutputBuf[3] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
|
||||||
ptrOutputBuf += 4;
|
ptrOutputBuf += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,7 @@ EXPORT_LIBRARY = 1
|
|||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
MODULE_NAME = nsMNGDecoderModule
|
MODULE_NAME = nsMNGDecoderModule
|
||||||
|
|
||||||
ifeq ($(OS_ARCH),WINNT)
|
|
||||||
EXTRA_DSO_LIBS = gkgfx
|
EXTRA_DSO_LIBS = gkgfx
|
||||||
endif
|
|
||||||
|
|
||||||
REQUIRES = string \
|
REQUIRES = string \
|
||||||
xpcom \
|
xpcom \
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include "imgIDecoderObserver.h"
|
#include "imgIDecoderObserver.h"
|
||||||
#include "nsMemory.h"
|
#include "nsMemory.h"
|
||||||
#include "prinrval.h"
|
#include "prinrval.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
|
||||||
static void il_mng_timeout_func(nsITimer *timer, void *data);
|
static void il_mng_timeout_func(nsITimer *timer, void *data);
|
||||||
|
|
||||||
@ -522,34 +523,8 @@ imgContainerMNG::InitMNG(nsMNGDecoder *decoder)
|
|||||||
// pass mng container as user data
|
// pass mng container as user data
|
||||||
mHandle = mng_initialize(this, il_mng_alloc, il_mng_free, NULL);
|
mHandle = mng_initialize(this, il_mng_alloc, il_mng_free, NULL);
|
||||||
|
|
||||||
////////////
|
|
||||||
// Gamma correction - gross hack, but it's what mozilla's PNG
|
|
||||||
// decoder does and nobody has complained yet (except
|
|
||||||
// for me, but the bug is in eternal limbo)
|
|
||||||
double LUT_exponent, CRT_exponent = 2.2, display_exponent;
|
|
||||||
|
|
||||||
/* set up gamma correction for Mac, Unix and (Win32 and everything else)
|
|
||||||
* using educated guesses for display-system exponents; do preferences
|
|
||||||
* later */
|
|
||||||
|
|
||||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
|
||||||
LUT_exponent = 1.8 / 2.61;
|
|
||||||
#elif defined(XP_UNIX)
|
|
||||||
# if defined(__sgi)
|
|
||||||
LUT_exponent = 1.0 / 1.7; /* typical default for SGI console */
|
|
||||||
# elif defined(NeXT)
|
|
||||||
LUT_exponent = 1.0 / 2.2; /* typical default for NeXT cube */
|
|
||||||
# else
|
|
||||||
LUT_exponent = 1.0; /* default for most other Unix workstations */
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
LUT_exponent = 1.0; /* virtually all PCs and most other systems */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
display_exponent = LUT_exponent * CRT_exponent;
|
|
||||||
mng_set_dfltimggamma(mHandle, 0.45455);
|
mng_set_dfltimggamma(mHandle, 0.45455);
|
||||||
mng_set_displaygamma(mHandle, display_exponent);
|
mng_set_displaygamma(mHandle, NS_DisplayGammaValue());
|
||||||
////////////
|
|
||||||
|
|
||||||
mng_setcb_openstream(mHandle, il_mng_openstream);
|
mng_setcb_openstream(mHandle, il_mng_openstream);
|
||||||
mng_setcb_closestream(mHandle, il_mng_closestream);
|
mng_setcb_closestream(mHandle, il_mng_closestream);
|
||||||
@ -563,7 +538,7 @@ imgContainerMNG::InitMNG(nsMNGDecoder *decoder)
|
|||||||
mng_setcb_memalloc(mHandle, il_mng_alloc);
|
mng_setcb_memalloc(mHandle, il_mng_alloc);
|
||||||
mng_setcb_memfree(mHandle, il_mng_free);
|
mng_setcb_memfree(mHandle, il_mng_free);
|
||||||
mng_set_suspensionmode(mHandle, MNG_TRUE);
|
mng_set_suspensionmode(mHandle, MNG_TRUE);
|
||||||
|
|
||||||
int ret = mng_readdisplay(mHandle);
|
int ret = mng_readdisplay(mHandle);
|
||||||
if (ret == MNG_NEEDMOREDATA)
|
if (ret == MNG_NEEDMOREDATA)
|
||||||
mResumeNeeded = PR_TRUE;
|
mResumeNeeded = PR_TRUE;
|
||||||
|
|||||||
@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1
|
|||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
MODULE_NAME = nsPNGDecoderModule
|
MODULE_NAME = nsPNGDecoderModule
|
||||||
|
|
||||||
ifeq ($(OS_ARCH),WINNT)
|
|
||||||
EXTRA_DSO_LIBS = gkgfx
|
EXTRA_DSO_LIBS = gkgfx
|
||||||
endif
|
|
||||||
|
|
||||||
REQUIRES = xpcom \
|
REQUIRES = xpcom \
|
||||||
gfx \
|
gfx \
|
||||||
|
|||||||
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include "imgIContainerObserver.h"
|
#include "imgIContainerObserver.h"
|
||||||
|
|
||||||
|
#include "nsColor.h"
|
||||||
|
|
||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
@ -168,7 +170,7 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
|||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
int bit_depth, color_type, interlace_type, compression_type, filter_type;
|
int bit_depth, color_type, interlace_type, compression_type, filter_type;
|
||||||
int channels;
|
int channels;
|
||||||
double LUT_exponent, CRT_exponent = 2.2, display_exponent, aGamma;
|
double aGamma;
|
||||||
|
|
||||||
png_bytep trans=NULL;
|
png_bytep trans=NULL;
|
||||||
int num_trans =0;
|
int num_trans =0;
|
||||||
@ -201,34 +203,13 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
|||||||
png_set_bgr(png_ptr);
|
png_set_bgr(png_ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set up gamma correction for Mac, Unix and (Win32 and everything else)
|
|
||||||
* using educated guesses for display-system exponents; do preferences
|
|
||||||
* later */
|
|
||||||
|
|
||||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
|
||||||
LUT_exponent = 1.8 / 2.61;
|
|
||||||
#elif defined(XP_UNIX)
|
|
||||||
# if defined(__sgi)
|
|
||||||
LUT_exponent = 1.0 / 1.7; /* typical default for SGI console */
|
|
||||||
# elif defined(NeXT)
|
|
||||||
LUT_exponent = 1.0 / 2.2; /* typical default for NeXT cube */
|
|
||||||
# else
|
|
||||||
LUT_exponent = 1.0; /* default for most other Unix workstations */
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
LUT_exponent = 1.0; /* virtually all PCs and most other systems */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* (alternatively, could check for SCREEN_GAMMA environment variable) */
|
|
||||||
display_exponent = LUT_exponent * CRT_exponent;
|
|
||||||
|
|
||||||
if (png_get_gAMA(png_ptr, info_ptr, &aGamma)) {
|
if (png_get_gAMA(png_ptr, info_ptr, &aGamma)) {
|
||||||
if (aGamma < 0)
|
if (aGamma < 0)
|
||||||
aGamma = 0.45455;
|
aGamma = 0.45455;
|
||||||
png_set_gamma(png_ptr, display_exponent, aGamma);
|
png_set_gamma(png_ptr, NS_DisplayGammaValue(), aGamma);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
png_set_gamma(png_ptr, display_exponent, 0.45455);
|
png_set_gamma(png_ptr, NS_DisplayGammaValue(), 0.45455);
|
||||||
|
|
||||||
/* let libpng expand interlaced images */
|
/* let libpng expand interlaced images */
|
||||||
if (interlace_type == PNG_INTERLACE_ADAM7) {
|
if (interlace_type == PNG_INTERLACE_ADAM7) {
|
||||||
|
|||||||
@ -433,6 +433,11 @@ NS_IMETHODIMP nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(NativeGetColor(aID, aColor))) {
|
if (NS_SUCCEEDED(NativeGetColor(aID, aColor))) {
|
||||||
|
// All colors going through gfx for output will be gamma corrected,
|
||||||
|
// so we push system colors through an inverse gamma transform so
|
||||||
|
// they will end up the same (modula rounding errors).
|
||||||
|
aColor = NS_INVERSE_GAMMA_CORRECT_COLOR(aColor);
|
||||||
|
|
||||||
CACHE_COLOR(aID, aColor);
|
CACHE_COLOR(aID, aColor);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user