зеркало из https://github.com/mozilla/gecko-dev.git
patch from Owen Taylor <otaylor@redhat.com> to fix fix the GBR->RGB conversion
for images.
This commit is contained in:
Родитель
e9a7d36567
Коммит
0cb2e3c66d
|
@ -78,9 +78,10 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
|
||||||
mWidget = aNativeWidget;
|
mWidget = aNativeWidget;
|
||||||
|
|
||||||
// Calculate mTwipsToPixels as (pixels/inch) / (twips/inch)
|
// Calculate mTwipsToPixels as (pixels/inch) / (twips/inch)
|
||||||
mTwipsToPixels =
|
mTwipsToPixels = ((gdk_screen_width()/gdk_screen_width_mm()) * 25.4) / (float)NSIntPointsToTwips(72);
|
||||||
(float)(((::gdk_screen_width()/::gdk_screen_width_mm()) * 25.4) /
|
|
||||||
(float)NSIntPointsToTwips(72));
|
g_print("*********** *%f/%f)*25.4 / %f = %f\n",gdk_screen_width(),
|
||||||
|
gdk_screen_width_mm(), NSIntPointsToTwips(72), mTwipsToPixels);
|
||||||
|
|
||||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||||
|
|
||||||
|
@ -115,8 +116,8 @@ NS_IMETHODIMP nsDeviceContextGTK::SupportsNativeWidgets(PRBool &aSupportsWidgets
|
||||||
NS_IMETHODIMP nsDeviceContextGTK::GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
NS_IMETHODIMP nsDeviceContextGTK::GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
||||||
{
|
{
|
||||||
// how are we going to get this? Must be set by the widget library FRV
|
// how are we going to get this? Must be set by the widget library FRV
|
||||||
aWidth = 0.0;
|
aWidth = 11.0 * mTwipsToPixels;
|
||||||
aHeight = 0.0;
|
aHeight = 24.0 * mTwipsToPixels;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,100 @@ void nsImageGTK :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRe
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is really ugly. Mozilla uses BGR image data, while
|
||||||
|
// gdk_rgb uses RGB data. So before we draw an image
|
||||||
|
// we copy it to a temp buffer and swap R and B.
|
||||||
|
//
|
||||||
|
// The code here comes from gdk_rgb_convert_888_lsb.
|
||||||
|
//
|
||||||
|
static void
|
||||||
|
moz_gdk_draw_bgr_image (GdkDrawable *drawable,
|
||||||
|
GdkGC *gc,
|
||||||
|
gint x,
|
||||||
|
gint y,
|
||||||
|
gint width,
|
||||||
|
gint height,
|
||||||
|
GdkRgbDither dith,
|
||||||
|
guchar *rgb_buf,
|
||||||
|
gint rowstride)
|
||||||
|
{
|
||||||
|
int tx, ty;
|
||||||
|
|
||||||
|
guchar *tmp_buf;
|
||||||
|
guchar *obuf, *obptr;
|
||||||
|
gint bpl;
|
||||||
|
guchar *bptr, *bp2;
|
||||||
|
int r, g, b;
|
||||||
|
|
||||||
|
bpl = (width * 3 + 3) & ~0x3;
|
||||||
|
tmp_buf = (guchar *)g_malloc (bpl * height);
|
||||||
|
|
||||||
|
bptr = rgb_buf;
|
||||||
|
obuf = tmp_buf;
|
||||||
|
for (ty = 0; ty < height; ty++)
|
||||||
|
{
|
||||||
|
bp2 = bptr;
|
||||||
|
obptr = obuf;
|
||||||
|
if (((unsigned long)obuf | (unsigned long) bp2) & 3)
|
||||||
|
{
|
||||||
|
for (tx = 0; tx < width; tx++)
|
||||||
|
{
|
||||||
|
r = bp2[0];
|
||||||
|
g = bp2[1];
|
||||||
|
b = bp2[2];
|
||||||
|
*obptr++ = b;
|
||||||
|
*obptr++ = g;
|
||||||
|
*obptr++ = r;
|
||||||
|
bp2 += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (tx = 0; tx < width - 3; tx += 4)
|
||||||
|
{
|
||||||
|
guint32 r1b0g0r0;
|
||||||
|
guint32 g2r2b1g1;
|
||||||
|
guint32 b3g3r3b2;
|
||||||
|
|
||||||
|
r1b0g0r0 = ((guint32 *)bp2)[0];
|
||||||
|
g2r2b1g1 = ((guint32 *)bp2)[1];
|
||||||
|
b3g3r3b2 = ((guint32 *)bp2)[2];
|
||||||
|
((guint32 *)obptr)[0] =
|
||||||
|
(r1b0g0r0 & 0xff00) |
|
||||||
|
((r1b0g0r0 & 0xff0000) >> 16) |
|
||||||
|
(((g2r2b1g1 & 0xff00) | (r1b0g0r0 & 0xff)) << 16);
|
||||||
|
((guint32 *)obptr)[1] =
|
||||||
|
(g2r2b1g1 & 0xff0000ff) |
|
||||||
|
((r1b0g0r0 & 0xff000000) >> 16) |
|
||||||
|
((b3g3r3b2 & 0xff) << 16);
|
||||||
|
((guint32 *)obptr)[2] =
|
||||||
|
(((g2r2b1g1 & 0xff0000) | (b3g3r3b2 & 0xff000000)) >> 16) |
|
||||||
|
((b3g3r3b2 & 0xff00) << 16) |
|
||||||
|
((b3g3r3b2 & 0xff0000));
|
||||||
|
bp2 += 12;
|
||||||
|
obptr += 12;
|
||||||
|
}
|
||||||
|
for (; tx < width; tx++)
|
||||||
|
{
|
||||||
|
r = bp2[0];
|
||||||
|
g = bp2[1];
|
||||||
|
b = bp2[2];
|
||||||
|
*obptr++ = b;
|
||||||
|
*obptr++ = g;
|
||||||
|
*obptr++ = r;
|
||||||
|
bp2 += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bptr += rowstride;
|
||||||
|
obuf += bpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_draw_rgb_image (drawable, gc, x, y, width, height,
|
||||||
|
dith, tmp_buf, bpl);
|
||||||
|
|
||||||
|
g_free (tmp_buf);
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|
||||||
// Draw the bitmap, this method has a source and destination coordinates
|
// Draw the bitmap, this method has a source and destination coordinates
|
||||||
|
@ -129,12 +223,12 @@ NS_IMETHODIMP nsImageGTK :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
|
||||||
{
|
{
|
||||||
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*)aSurface;
|
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*)aSurface;
|
||||||
|
|
||||||
gdk_draw_rgb_image (drawing->drawable,
|
moz_gdk_draw_bgr_image (drawing->drawable,
|
||||||
drawing->gc,
|
drawing->gc,
|
||||||
aDX, aDY, aDWidth, aDHeight,
|
aDX, aDY, aDWidth, aDHeight,
|
||||||
GDK_RGB_DITHER_MAX,
|
GDK_RGB_DITHER_MAX,
|
||||||
mImageBits + mRowBytes * aSY + 3 * aDX,
|
mImageBits + mRowBytes * aSY + 3 * aDX,
|
||||||
mRowBytes);
|
mRowBytes);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -149,11 +243,11 @@ NS_IMETHODIMP nsImageGTK :: Draw(nsIRenderingContext &aContext,
|
||||||
{
|
{
|
||||||
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*) aSurface;
|
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*) aSurface;
|
||||||
|
|
||||||
gdk_draw_rgb_image (drawing->drawable,
|
moz_gdk_draw_bgr_image (drawing->drawable,
|
||||||
drawing->gc,
|
drawing->gc,
|
||||||
aX, aY, aWidth, aHeight,
|
aX, aY, aWidth, aHeight,
|
||||||
GDK_RGB_DITHER_MAX,
|
GDK_RGB_DITHER_MAX,
|
||||||
mImageBits, mRowBytes);
|
mImageBits, mRowBytes);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче