зеркало из https://github.com/mozilla/gecko-dev.git
added gamma correction methods to the device context. the windows rendering context now
gamma corrects colors. fixed tablecellframe to call the right nsStyleCoord constructor.
This commit is contained in:
Родитель
d8462c68d7
Коммит
d55497643c
|
@ -80,6 +80,13 @@ public:
|
|||
//already one in the device context. the drawing surface is then cached
|
||||
//in the device context for re-use.
|
||||
virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext) = 0;
|
||||
|
||||
//functions for handling gamma correction of output device
|
||||
virtual float GetGamma(void) = 0;
|
||||
virtual void SetGamma(float aGamma) = 0;
|
||||
|
||||
//XXX the return from this really needs to be ref counted somehow. MMP
|
||||
virtual PRUint8 * GetGammaTable(void) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIDeviceContext_h___ */
|
||||
|
|
|
@ -39,6 +39,9 @@ nsDeviceContextWin :: nsDeviceContextWin()
|
|||
mDevUnitsToAppUnits = 1.0f;
|
||||
mAppUnitsToDevUnits = 1.0f;
|
||||
|
||||
mGammaValue = 1.0f;
|
||||
mGammaTable = new PRUint8[256];
|
||||
|
||||
mZoom = 1.0f;
|
||||
|
||||
mSurface = NULL;
|
||||
|
@ -53,6 +56,12 @@ nsDeviceContextWin :: ~nsDeviceContextWin()
|
|||
DeleteDC(mSurface);
|
||||
mSurface = NULL;
|
||||
}
|
||||
|
||||
if (nsnull != mGammaTable)
|
||||
{
|
||||
delete mGammaTable;
|
||||
mGammaTable = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextWin, kDeviceContextIID)
|
||||
|
@ -61,6 +70,9 @@ NS_IMPL_RELEASE(nsDeviceContextWin)
|
|||
|
||||
nsresult nsDeviceContextWin :: Init()
|
||||
{
|
||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
mGammaTable[cnt] = cnt;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -180,3 +192,38 @@ nsDrawingSurface nsDeviceContextWin :: GetDrawingSurface(nsIRenderingContext &aC
|
|||
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
float nsDeviceContextWin :: GetGamma(void)
|
||||
{
|
||||
return mGammaValue;
|
||||
}
|
||||
|
||||
void nsDeviceContextWin :: 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;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint8 * nsDeviceContextWin :: GetGammaTable(void)
|
||||
{
|
||||
//XXX we really need to ref count this somehow. MMP
|
||||
|
||||
return mGammaTable;
|
||||
}
|
||||
|
||||
void nsDeviceContextWin :: SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma)
|
||||
{
|
||||
float fgval = (1.0f / aCurrentGamma) * (1.0f / aNewGamma);
|
||||
|
||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
aTable[cnt] = (PRUint8)(pow(cnt * (1. / 256.), fgval) * 255.99999999);
|
||||
}
|
||||
|
|
|
@ -61,10 +61,15 @@ public:
|
|||
|
||||
virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext);
|
||||
|
||||
virtual float GetGamma(void);
|
||||
virtual void SetGamma(float aGamma);
|
||||
virtual PRUint8 * GetGammaTable(void);
|
||||
|
||||
protected:
|
||||
~nsDeviceContextWin();
|
||||
|
||||
nsresult CreateFontCache();
|
||||
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
|
||||
|
||||
float mTwipsToPixels;
|
||||
float mPixelsToTwips;
|
||||
|
@ -73,6 +78,8 @@ protected:
|
|||
nsIFontCache *mFontCache;
|
||||
float mZoom;
|
||||
HDC mSurface;
|
||||
float mGammaValue;
|
||||
PRUint8 *mGammaTable;
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextWin_h___ */
|
||||
|
|
|
@ -286,6 +286,8 @@ nsresult nsRenderingContextWin :: CommonInit(void)
|
|||
mBlackPen = ::CreatePen(PS_SOLID, 0, RGB(0, 0, 0));
|
||||
mOrigSolidPen = ::SelectObject(mDC, mBlackPen);
|
||||
|
||||
mGammaTable = mContext->GetGammaTable();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -438,7 +440,9 @@ const nsRect& nsRenderingContextWin :: GetClipRect()
|
|||
void nsRenderingContextWin :: SetColor(nscolor aColor)
|
||||
{
|
||||
mCurrentColor = aColor;
|
||||
mColor = RGB(NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
|
||||
mColor = RGB(mGammaTable[NS_GET_R(aColor)],
|
||||
mGammaTable[NS_GET_G(aColor)],
|
||||
mGammaTable[NS_GET_B(aColor)]);
|
||||
}
|
||||
|
||||
nscolor nsRenderingContextWin :: GetColor() const
|
||||
|
|
|
@ -158,6 +158,7 @@ protected:
|
|||
nscolor mCurrPenColor;
|
||||
HPEN mCurrPen;
|
||||
HPEN mNullPen;
|
||||
PRUint8 *mGammaTable;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool mInitialized;
|
||||
|
|
|
@ -47,6 +47,7 @@ GalleyContext::GalleyContext()
|
|||
mDeviceContext->Init();
|
||||
mDeviceContext->SetDevUnitsToAppUnits(mDeviceContext->GetDevUnitsToTwips());
|
||||
mDeviceContext->SetAppUnitsToDevUnits(mDeviceContext->GetTwipsToDevUnits());
|
||||
mDeviceContext->SetGamma(1.7f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ nsStyleCoord::nsStyleCoord(nscoord aValue)
|
|||
nsStyleCoord::nsStyleCoord(PRInt32 aValue, nsStyleUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
//if you want to pass in eStyleUnit_Coord, don't. instead, use the
|
||||
//constructor just above this one... MMP
|
||||
NS_ASSERTION((aUnit == eStyleUnit_Proportional) ||
|
||||
(aUnit == eStyleUnit_Enumerated) ||
|
||||
(aUnit == eStyleUnit_Integer), "not an int value");
|
||||
|
|
|
@ -440,8 +440,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
|||
{
|
||||
|
||||
PRInt32 value;
|
||||
nsStyleCoord padding(0, eStyleUnit_Coord);
|
||||
nsStyleCoord spacing(0, eStyleUnit_Coord);
|
||||
nsStyleCoord padding(0);
|
||||
nsStyleCoord spacing(0);
|
||||
|
||||
if (padding_result == eContentAttr_HasValue && ConvertToIntValue(padding_value,0,value))
|
||||
padding.SetCoordValue((nscoord)(p2t*(float)value));
|
||||
|
|
|
@ -440,8 +440,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
|||
{
|
||||
|
||||
PRInt32 value;
|
||||
nsStyleCoord padding(0, eStyleUnit_Coord);
|
||||
nsStyleCoord spacing(0, eStyleUnit_Coord);
|
||||
nsStyleCoord padding(0);
|
||||
nsStyleCoord spacing(0);
|
||||
|
||||
if (padding_result == eContentAttr_HasValue && ConvertToIntValue(padding_value,0,value))
|
||||
padding.SetCoordValue((nscoord)(p2t*(float)value));
|
||||
|
|
Загрузка…
Ссылка в новой задаче