Bug 53597 - consistent gamma correction. r=dbaron, sr=brendan

This commit is contained in:
tor%cs.brown.edu 2002-04-13 10:03:59 +00:00
Родитель 5d57d5b5c6
Коммит c5d399ffb4
38 изменённых файлов: 220 добавлений и 222 удалений

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

@ -3930,7 +3930,6 @@ nsDocShell::EnsureDeviceContext()
float twip2dev;
mDeviceContext->GetTwipsToDevUnits(twip2dev);
mDeviceContext->SetAppUnitsToDevUnits(twip2dev);
mDeviceContext->SetGamma(1.0f);
return NS_OK;
}

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

@ -30,6 +30,7 @@ interface nsIScreen : nsISupports
readonly attribute long pixelDepth;
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
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___ */

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

@ -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<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
float mZoom;
float mTextZoom;
float mGammaValue;
PRUint8 *mGammaTable;
nsHashtable* mFontAliasTable;
float mCPixelScale;

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

@ -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

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

@ -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) {

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

@ -224,7 +224,6 @@ protected:
nsCOMPtr<nsIRegion> mClipRegion;
nsVoidArray *mStateCache;
BView *mView;
PRUint8 *mGammaTable;
nscolor mCurrentColor;
BFont *mCurrentFont;
nsLineStyle mCurrentLineStyle;

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

@ -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

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

@ -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())) {

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

@ -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

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

@ -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 ;

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

@ -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

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

@ -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 <math.h>
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<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
// 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

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

@ -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<nsIObserverService> 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;

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

@ -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 ;

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

@ -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;

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

@ -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

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

@ -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);

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

@ -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

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

@ -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;

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

@ -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
}
//------------------------------------------------------------

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

@ -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;
}

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

@ -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

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

@ -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;

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

@ -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

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

@ -120,6 +120,8 @@ Initialize(nsIModule* self)
nsCSSFrameConstructor::InitGlobals();
NS_InitializeGamma();
return nsTextTransformer::Initialize();
}

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

@ -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 \

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

@ -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;
}

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

@ -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;
}

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

@ -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);

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

@ -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 \

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

@ -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 \

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

@ -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<mInfo.output_width;++i) {
ptrOutputBuf[2] = *j1++;
ptrOutputBuf[1] = *j1++;
ptrOutputBuf[0] = *j1++;
ptrOutputBuf[2] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf[1] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf[0] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf += 3;
}
@ -534,9 +535,9 @@ nsJPEGDecoder::OutputScanlines(int num_scanlines)
JSAMPLE *j1 = mSamples[0];
for (PRUint32 i=0;i<mInfo.output_width;++i) {
ptrOutputBuf[0] = 0;
ptrOutputBuf[1] = *j1++;
ptrOutputBuf[2] = *j1++;
ptrOutputBuf[3] = *j1++;
ptrOutputBuf[1] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf[2] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf[3] = NS_GAMMA_CORRECT_COMPONENT(*j1++);
ptrOutputBuf += 4;
}

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

@ -30,9 +30,7 @@ EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsMNGDecoderModule
ifeq ($(OS_ARCH),WINNT)
EXTRA_DSO_LIBS = gkgfx
endif
REQUIRES = string \
xpcom \

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

@ -29,6 +29,7 @@
#include "imgIDecoderObserver.h"
#include "nsMemory.h"
#include "prinrval.h"
#include "nsColor.h"
static void il_mng_timeout_func(nsITimer *timer, void *data);
@ -522,34 +523,8 @@ imgContainerMNG::InitMNG(nsMNGDecoder *decoder)
// pass mng container as user data
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_displaygamma(mHandle, display_exponent);
////////////
mng_set_displaygamma(mHandle, NS_DisplayGammaValue());
mng_setcb_openstream(mHandle, il_mng_openstream);
mng_setcb_closestream(mHandle, il_mng_closestream);
@ -563,7 +538,7 @@ imgContainerMNG::InitMNG(nsMNGDecoder *decoder)
mng_setcb_memalloc(mHandle, il_mng_alloc);
mng_setcb_memfree(mHandle, il_mng_free);
mng_set_suspensionmode(mHandle, MNG_TRUE);
int ret = mng_readdisplay(mHandle);
if (ret == MNG_NEEDMOREDATA)
mResumeNeeded = PR_TRUE;

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

@ -32,9 +32,7 @@ EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsPNGDecoderModule
ifeq ($(OS_ARCH),WINNT)
EXTRA_DSO_LIBS = gkgfx
endif
REQUIRES = xpcom \
gfx \

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

@ -32,6 +32,8 @@
#include "imgIContainerObserver.h"
#include "nsColor.h"
#include "nspr.h"
#include "png.h"
@ -168,7 +170,7 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type, filter_type;
int channels;
double LUT_exponent, CRT_exponent = 2.2, display_exponent, aGamma;
double aGamma;
png_bytep trans=NULL;
int num_trans =0;
@ -201,34 +203,13 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
png_set_bgr(png_ptr);
#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 (aGamma < 0)
aGamma = 0.45455;
png_set_gamma(png_ptr, display_exponent, aGamma);
png_set_gamma(png_ptr, NS_DisplayGammaValue(), aGamma);
}
else
png_set_gamma(png_ptr, display_exponent, 0.45455);
png_set_gamma(png_ptr, NS_DisplayGammaValue(), 0.45455);
/* let libpng expand interlaced images */
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))) {
// 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);
return NS_OK;
}