зеркало из https://github.com/mozilla/pjs.git
b=359002, single pixel background image is incorrect color (third line of acid2), r=stuart
This commit is contained in:
Родитель
bb15b03b15
Коммит
d3bfcb9752
|
@ -216,16 +216,13 @@ nsThebesImage::Optimize(nsIDeviceContext* aContext)
|
|||
if (mFormat == gfxImageSurface::ImageFormatARGB32 ||
|
||||
mFormat == gfxImageSurface::ImageFormatRGB24)
|
||||
{
|
||||
PRUint32 *pxl = (PRUint32 *) mImageSurface->Data();
|
||||
mSinglePixelColor = gfxRGBA(*pxl);
|
||||
if (mFormat == gfxImageSurface::ImageFormatRGB24)
|
||||
mSinglePixelColor.a = 1.0;
|
||||
else if (mSinglePixelColor.a != 0.0) {
|
||||
// unpremultiply alpha
|
||||
mSinglePixelColor.r = mSinglePixelColor.r / mSinglePixelColor.a;
|
||||
mSinglePixelColor.g = mSinglePixelColor.g / mSinglePixelColor.a;
|
||||
mSinglePixelColor.b = mSinglePixelColor.b / mSinglePixelColor.a;
|
||||
}
|
||||
PRUint32 pixel = *((PRUint32 *) mImageSurface->Data());
|
||||
|
||||
mSinglePixelColor = gfxRGBA
|
||||
(pixel,
|
||||
(mFormat == gfxImageSurface::ImageFormatRGB24 ?
|
||||
gfxRGBA::PACKED_XRGB :
|
||||
gfxRGBA::PACKED_ARGB_PREMULTIPLIED));
|
||||
|
||||
mSinglePixel = PR_TRUE;
|
||||
|
||||
|
|
|
@ -52,6 +52,17 @@
|
|||
struct THEBES_API gfxRGBA {
|
||||
gfxFloat r, g, b, a;
|
||||
|
||||
enum PackedColorType {
|
||||
PACKED_ABGR,
|
||||
PACKED_ABGR_PREMULTIPLIED,
|
||||
|
||||
PACKED_ARGB,
|
||||
PACKED_ARGB_PREMULTIPLIED,
|
||||
|
||||
PACKED_XBGR,
|
||||
PACKED_XRGB
|
||||
};
|
||||
|
||||
gfxRGBA() { }
|
||||
gfxRGBA(const gfxRGBA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
|
||||
/**
|
||||
|
@ -59,39 +70,87 @@ struct THEBES_API gfxRGBA {
|
|||
* values.
|
||||
*/
|
||||
gfxRGBA(gfxFloat _r, gfxFloat _g, gfxFloat _b, gfxFloat _a=1.0) : r(_r), g(_g), b(_b), a(_a) {}
|
||||
|
||||
/**
|
||||
* Initialize this color from a packed 32-bit color.
|
||||
* Premultiplied alpha isn't used.
|
||||
* This uses ABGR byte order in the native endianness.
|
||||
* The color value is interpreted based on colorType;
|
||||
* all values use the native platform endianness.
|
||||
*
|
||||
* @see gfxRGBA::Packed
|
||||
*/
|
||||
gfxRGBA(PRUint32 c) {
|
||||
r = ((c >> 0) & 0xff) / 255.0;
|
||||
g = ((c >> 8) & 0xff) / 255.0;
|
||||
b = ((c >> 16) & 0xff) / 255.0;
|
||||
a = ((c >> 24) & 0xff) / 255.0;
|
||||
gfxRGBA(PRUint32 c, PackedColorType colorType = PACKED_ABGR) {
|
||||
if (colorType == PACKED_ABGR ||
|
||||
colorType == PACKED_XBGR)
|
||||
{
|
||||
r = ((c >> 0) & 0xff) / 255.0;
|
||||
g = ((c >> 8) & 0xff) / 255.0;
|
||||
b = ((c >> 16) & 0xff) / 255.0;
|
||||
a = ((c >> 24) & 0xff) / 255.0;
|
||||
} else if (colorType == PACKED_ARGB ||
|
||||
colorType == PACKED_XRGB)
|
||||
{
|
||||
b = ((c >> 0) & 0xff) / 255.0;
|
||||
g = ((c >> 8) & 0xff) / 255.0;
|
||||
r = ((c >> 16) & 0xff) / 255.0;
|
||||
a = ((c >> 24) & 0xff) / 255.0;
|
||||
}
|
||||
|
||||
if (colorType == PACKED_ABGR_PREMULTIPLIED ||
|
||||
colorType == PACKED_ARGB_PREMULTIPLIED)
|
||||
{
|
||||
if (a > 0.0) {
|
||||
r /= a;
|
||||
g /= a;
|
||||
b /= a;
|
||||
}
|
||||
} else if (colorType == PACKED_XBGR ||
|
||||
colorType == PACKED_XRGB)
|
||||
{
|
||||
a = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this color by parsing the given string.
|
||||
* XXX implement me!
|
||||
*/
|
||||
#if 0
|
||||
gfxRGBA(const char* str) {
|
||||
a = 1.0;
|
||||
// if aString[0] is a #, parse it as hex
|
||||
// if aString[0] is a letter, parse it as a color name
|
||||
// if aString[0] is a number, parse it loosely as hex
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns this color value as a packed 32-bit integer. This uses ABGR
|
||||
* byte order in the native endianness, as accepted by the corresponding
|
||||
* constructor of this class.
|
||||
* Returns this color value as a packed 32-bit integer. This reconstructs
|
||||
* the int32 based on the given colorType, always in the native byte order.
|
||||
*/
|
||||
PRUint32 Packed() const {
|
||||
return (((PRUint8)(a * 255.0) << 24) |
|
||||
((PRUint8)(b * 255.0) << 16) |
|
||||
((PRUint8)(g * 255.0) << 8) |
|
||||
((PRUint8)(r * 255.0)));
|
||||
PRUint32 Packed(PackedColorType colorType = PACKED_ABGR) const {
|
||||
if (colorType == PACKED_ABGR || colorType == PACKED_XBGR) {
|
||||
return (((PRUint8)(a * 255.0) << 24) |
|
||||
((PRUint8)(b * 255.0) << 16) |
|
||||
((PRUint8)(g * 255.0) << 8) |
|
||||
((PRUint8)(r * 255.0)));
|
||||
} else if (colorType == PACKED_ARGB || colorType == PACKED_XRGB) {
|
||||
return (((PRUint8)(a * 255.0) << 24) |
|
||||
((PRUint8)(r * 255.0) << 16) |
|
||||
((PRUint8)(g * 255.0) << 8) |
|
||||
((PRUint8)(b * 255.0)));
|
||||
} else if (colorType == PACKED_ABGR_PREMULTIPLIED) {
|
||||
return (((PRUint8)(a * 255.0) << 24) |
|
||||
((PRUint8)((b*a) * 255.0) << 16) |
|
||||
((PRUint8)((g*a) * 255.0) << 8) |
|
||||
((PRUint8)((r*a) * 255.0)));
|
||||
} else if (colorType == PACKED_ARGB_PREMULTIPLIED) {
|
||||
return (((PRUint8)(a * 255.0) << 24) |
|
||||
((PRUint8)((r*a) * 255.0) << 16) |
|
||||
((PRUint8)((g*a) * 255.0) << 8) |
|
||||
((PRUint8)((b*a) * 255.0)));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче