[maemo-commits] [maemo-commits] r17412 - in projects/haf/trunk/clutter: clutter/cogl clutter/cogl/common clutter/x11 debian
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Feb 13 11:26:04 EET 2009
- Previous message: [maemo-commits] r17411 - in projects/haf/trunk/ke-recv-extra: debian src
- Next message: [maemo-commits] r17413 - in projects/haf/trunk/libmatchbox2: . matchbox/core
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: gw
Date: 2009-02-13 11:25:59 +0200 (Fri, 13 Feb 2009)
New Revision: 17412
Modified:
projects/haf/trunk/clutter/clutter/cogl/cogl.h.in
projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-fallback.c
projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-pixbuf.c
projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap.c
projects/haf/trunk/clutter/clutter/x11/clutter-x11-texture-pixmap.c
projects/haf/trunk/clutter/debian/changelog
Log:
* Fixed possible uninitialised pointer in x11-texture
* Re-implemented the format conversion code to make it much quicker and
tidier using preprocessor
Modified: projects/haf/trunk/clutter/clutter/cogl/cogl.h.in
===================================================================
--- projects/haf/trunk/clutter/clutter/cogl/cogl.h.in 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/clutter/cogl/cogl.h.in 2009-02-13 09:25:59 UTC (rev 17412)
@@ -103,9 +103,16 @@
COGL_BGR_BIT),
COGL_PIXEL_FORMAT_RGBA_4444 = (COGL_PIXEL_FORMAT_16 |
COGL_A_BIT),
+ COGL_PIXEL_FORMAT_BGRA_4444 = (COGL_PIXEL_FORMAT_16 |
+ COGL_BGR_BIT |
+ COGL_A_BIT),
COGL_PIXEL_FORMAT_RGBA_5551 = (1 |
COGL_PIXEL_FORMAT_16 |
COGL_A_BIT),
+ COGL_PIXEL_FORMAT_BGRA_5551 = (1 |
+ COGL_PIXEL_FORMAT_16 |
+ COGL_BGR_BIT |
+ COGL_A_BIT),
COGL_PIXEL_FORMAT_YUV = (1 |
COGL_PIXEL_FORMAT_16),
COGL_PIXEL_FORMAT_G_8 = COGL_PIXEL_FORMAT_8,
Modified: projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-fallback.c
===================================================================
--- projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-fallback.c 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-fallback.c 2009-02-13 09:25:59 UTC (rev 17412)
@@ -33,9 +33,20 @@
#include <string.h>
+
+/* we really want everything inlined here, or we'll be insanely slow */
+
/* TO rgba */
inline static void
+_cogl_swap_r_b (guchar *dst)
+{
+ guchar tmp = dst[0];
+ dst[0] = dst[2];
+ dst[2] = tmp;
+}
+
+inline static void
_cogl_g_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[0];
@@ -45,33 +56,24 @@
}
inline static void
-_cogl_rgb_to_rgba (const guchar *src, guchar *dst)
+_cogl_a_to_rgba (const guchar *src, guchar *dst)
{
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = 255;
+ dst[0] = 255;
+ dst[1] = 255;
+ dst[2] = 255;
+ dst[3] = src[0];
}
inline static void
-_cogl_bgr_to_rgba (const guchar *src, guchar *dst)
+_cogl_rgb_to_rgba (const guchar *src, guchar *dst)
{
- dst[0] = src[2];
+ dst[0] = src[0];
dst[1] = src[1];
- dst[2] = src[0];
+ dst[2] = src[2];
dst[3] = 255;
}
inline static void
-_cogl_bgra_to_rgba (const guchar *src, guchar *dst)
-{
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
-}
-
-inline static void
_cogl_argb_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[1];
@@ -81,15 +83,6 @@
}
inline static void
-_cogl_abgr_to_rgba (const guchar *src, guchar *dst)
-{
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
-}
-
-inline static void
_cogl_rgba_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[0];
@@ -102,22 +95,32 @@
_cogl_rgb565_to_rgba (const guchar *src, guchar *dst)
{
gushort *c = (gushort*)src;
- dst[0] = (((*c << 3) & 0xf8) | ((*c >> 2) & 0x7));
+ dst[0] = (((*c >> 8) & 0xf8) | ((*c >> 13) & 0x7));
dst[1] = (((*c >> 3) & 0xfc) | ((*c >> 9) & 0x3));
- dst[2] = (((*c >> 8) & 0xf8) | ((*c >> 5) & 0x7));
+ dst[2] = (((*c << 3) & 0xf8) | ((*c >> 2) & 0x7));
dst[3] = 255;
}
inline static void
-_cogl_bgr565_to_rgba (const guchar *src, guchar *dst)
+_cogl_rgba5551_to_rgba (const guchar *src, guchar *dst)
{
gushort *c = (gushort*)src;
- dst[0] = (((*c >> 8) & 0xf8) | ((*c >> 5) & 0x7));
- dst[1] = (((*c >> 3) & 0xfc) | ((*c >> 9) & 0x3));
- dst[2] = (((*c << 3) & 0xf8) | ((*c >> 2) & 0x7));
- dst[3] = 255;
+ dst[0] = (((*c >> 8) & 0xf8) | ((*c >> 13) & 0x7));
+ dst[1] = (((*c >> 3) & 0xf8) | ((*c >> 8) & 0x7));
+ dst[2] = (((*c << 2) & 0xf8) | ((*c >> 3) & 0x7));
+ dst[3] = (*c & 0x0001) ? 255 : 0;
}
+inline static void
+_cogl_rgba4444_to_rgba (const guchar *src, guchar *dst)
+{
+ gushort *c = (gushort*)src;
+ dst[0] = (((*c >> 8) & 0xf0) | ((*c >> 12) & 0xF));
+ dst[1] = (((*c >> 4) & 0xf0) | ((*c >> 8) & 0xF));
+ dst[2] = (((*c ) & 0xf0) | ((*c >> 4) & 0xF));
+ dst[3] = (((*c << 4) & 0xf0) | ((*c ) & 0xF));
+}
+
/* FROM rgba */
inline static void
@@ -127,6 +130,12 @@
}
inline static void
+_cogl_rgba_to_a (const guchar *src, guchar *dst)
+{
+ dst[0] = src[3];
+}
+
+inline static void
_cogl_rgba_to_rgb (const guchar *src, guchar *dst)
{
dst[0] = src[0];
@@ -135,38 +144,41 @@
}
inline static void
-_cogl_rgba_to_bgr (const guchar *src, guchar *dst)
+_cogl_rgba_to_argb (const guchar *src, guchar *dst)
{
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
+ dst[0] = src[3];
+ dst[1] = src[0];
+ dst[2] = src[1];
+ dst[3] = src[2];
}
inline static void
-_cogl_rgba_to_bgra (const guchar *src, guchar *dst)
+_cogl_rgba_to_rgb565 (const guchar *src, guchar *dst)
{
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
+ gushort *c = (gushort*)dst;
+ *c = ((src[2] ) >> 3) |
+ ((src[1] & 0xFC) << 3) |
+ ((src[0] & 0xF8) << 8);
}
inline static void
-_cogl_rgba_to_argb (const guchar *src, guchar *dst)
+_cogl_rgba_to_rgba5551 (const guchar *src, guchar *dst)
{
- dst[0] = src[3];
- dst[1] = src[0];
- dst[2] = src[1];
- dst[3] = src[2];
+ gushort *c = (gushort*)dst;
+ *c = ((src[3] & 0xF0) >> 7) |
+ ((src[2] & 0xF8) >> 2) |
+ ((src[1] & 0xF8) << 3) |
+ ((src[0] & 0xF8) << 8);
}
inline static void
-_cogl_rgba_to_abgr (const guchar *src, guchar *dst)
+_cogl_rgba_to_rgba4444 (const guchar *src, guchar *dst)
{
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
+ gushort *c = (gushort*)dst;
+ *c = ((src[3] ) >> 4) |
+ ((src[2] & 0xF0) ) |
+ ((src[1] & 0xF0) << 4) |
+ ((src[0] & 0xF0) << 8);
}
/* (Un)Premultiplication */
@@ -203,32 +215,6 @@
}
gboolean
-_cogl_bitmap_fallback_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
-{
- if (src == dst)
- return FALSE;
-
- switch (src & COGL_UNORDERED_MASK)
- {
- case COGL_PIXEL_FORMAT_G_8:
- case COGL_PIXEL_FORMAT_RGB_888:
- case COGL_PIXEL_FORMAT_RGBA_8888:
- case COGL_PIXEL_FORMAT_RGB_565:
-
- if ((dst & COGL_PIXEL_SIZE_MASK) != COGL_PIXEL_FORMAT_24 &&
- (dst & COGL_PIXEL_SIZE_MASK) != COGL_PIXEL_FORMAT_32 &&
- (dst & COGL_PIXEL_SIZE_MASK) != COGL_PIXEL_FORMAT_G_8)
- return FALSE;
- break;
-
- default:
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
_cogl_bitmap_fallback_can_unpremult (CoglPixelFormat format)
{
return ((format & COGL_UNORDERED_MASK) == COGL_PIXEL_FORMAT_32);
@@ -246,10 +232,6 @@
gint x,y;
guchar temp_rgba[4] = {0,0,0,0};
- /* Make sure conversion supported */
- if (!_cogl_bitmap_fallback_can_convert (bmp->format, dst_format))
- return FALSE;
-
src_bpp = _cogl_get_format_bpp (bmp->format);
dst_bpp = _cogl_get_format_bpp (dst_format);
@@ -257,74 +239,95 @@
*dst_bmp = *bmp;
dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
+ (dst_format & COGL_UNPREMULT_MASK));
/* Allocate a new buffer to hold converted data */
dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
+ * dst_bmp->height
+ * dst_bmp->rowstride);
+ /* This preprocessor hack is able to generate all the fast conversion
+ * code we need */
- /* FIXME: Optimize */
- for (y = 0; y < bmp->height; y++)
- {
- src = (guchar*)bmp->data + y * bmp->rowstride;
- dst = (guchar*)dst_bmp->data + y * dst_bmp->rowstride;
+#define TRY_CONVERSION(TFROM, TTO, TSWAP, FMT_DST) \
+ if (FMT_DST == dst_format) \
+ { \
+ for (y = 0; y < bmp->height; y++) \
+ { \
+ src = (guchar*)bmp->data + y * bmp->rowstride; \
+ dst = (guchar*)dst_bmp->data + y * dst_bmp->rowstride; \
+ \
+ for (x = 0; x < bmp->width; x++) \
+ { \
+ _cogl_##TFROM##_to_rgba (src, temp_rgba); \
+ \
+ if (TSWAP) \
+ _cogl_swap_r_b(temp_rgba); \
+ \
+ _cogl_rgba_to_##TTO (temp_rgba, dst); \
+ \
+ src += src_bpp; \
+ dst += dst_bpp; \
+ } \
+ } \
+ return TRUE; \
+ }
- for (x = 0; x < bmp->width; x++)
- {
- /* FIXME: Would be nice to at least remove this inner
- * branching, but not sure it can be done without
- * rewriting of the whole loop */
- switch (bmp->format & COGL_UNPREMULT_MASK)
- {
- case COGL_PIXEL_FORMAT_G_8:
- _cogl_g_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_RGB_565:
- _cogl_rgb565_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_BGR_565:
- _cogl_bgr565_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_RGB_888:
- _cogl_rgb_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_BGR_888:
- _cogl_bgr_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_RGBA_8888:
- _cogl_rgba_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_BGRA_8888:
- _cogl_bgra_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_ARGB_8888:
- _cogl_argb_to_rgba (src, temp_rgba); break;
- case COGL_PIXEL_FORMAT_ABGR_8888:
- _cogl_abgr_to_rgba (src, temp_rgba); break;
- default:
- break;
- }
+#define TRY_CONVERSIONS(TFROM, SWAP) \
+ { \
+ TRY_CONVERSION(TFROM, g, SWAP, COGL_PIXEL_FORMAT_G_8) \
+ TRY_CONVERSION(TFROM, rgb565, SWAP, COGL_PIXEL_FORMAT_RGB_565) \
+ TRY_CONVERSION(TFROM, rgb565, !SWAP, COGL_PIXEL_FORMAT_BGR_565) \
+ TRY_CONVERSION(TFROM, rgba5551, SWAP, COGL_PIXEL_FORMAT_RGBA_5551) \
+ TRY_CONVERSION(TFROM, rgba5551, !SWAP, COGL_PIXEL_FORMAT_BGRA_5551) \
+ TRY_CONVERSION(TFROM, rgba4444, SWAP, COGL_PIXEL_FORMAT_RGBA_4444) \
+ TRY_CONVERSION(TFROM, rgba4444, !SWAP, COGL_PIXEL_FORMAT_BGRA_4444) \
+ TRY_CONVERSION(TFROM, rgb, SWAP, COGL_PIXEL_FORMAT_RGB_888) \
+ TRY_CONVERSION(TFROM, rgb, !SWAP, COGL_PIXEL_FORMAT_BGR_888) \
+ TRY_CONVERSION(TFROM, rgba, SWAP, COGL_PIXEL_FORMAT_RGBA_8888) \
+ TRY_CONVERSION(TFROM, rgba, !SWAP, COGL_PIXEL_FORMAT_BGRA_8888) \
+ TRY_CONVERSION(TFROM, argb, SWAP, COGL_PIXEL_FORMAT_ARGB_8888) \
+ TRY_CONVERSION(TFROM, argb, !SWAP, COGL_PIXEL_FORMAT_ABGR_8888) \
+ }
- switch (dst_format & COGL_UNPREMULT_MASK)
- {
- case COGL_PIXEL_FORMAT_G_8:
- _cogl_rgba_to_g (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_RGB_888:
- _cogl_rgba_to_rgb (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_BGR_888:
- _cogl_rgba_to_bgr (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_RGBA_8888:
- _cogl_rgba_to_rgba (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_BGRA_8888:
- _cogl_rgba_to_bgra (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_ARGB_8888:
- _cogl_rgba_to_argb (temp_rgba, dst); break;
- case COGL_PIXEL_FORMAT_ABGR_8888:
- _cogl_rgba_to_abgr (temp_rgba, dst); break;
- default:
- break;
- }
+ switch (bmp->format & COGL_UNPREMULT_MASK)
+ {
+ case COGL_PIXEL_FORMAT_G_8:
+ TRY_CONVERSIONS(g, FALSE); break;
+ case COGL_PIXEL_FORMAT_RGB_565:
+ TRY_CONVERSIONS(rgb565, FALSE); break;
+ case COGL_PIXEL_FORMAT_BGR_565:
+ TRY_CONVERSIONS(rgb565, TRUE); break;
+ case COGL_PIXEL_FORMAT_RGBA_5551:
+ TRY_CONVERSIONS(rgba5551, FALSE); break;
+ case COGL_PIXEL_FORMAT_BGRA_5551:
+ TRY_CONVERSIONS(rgba5551, TRUE); break;
+ case COGL_PIXEL_FORMAT_RGBA_4444:
+ TRY_CONVERSIONS(rgba4444, FALSE); break;
+ case COGL_PIXEL_FORMAT_BGRA_4444:
+ TRY_CONVERSIONS(rgba4444, TRUE); break;
+ case COGL_PIXEL_FORMAT_RGB_888:
+ TRY_CONVERSIONS(rgb, FALSE); break;
+ case COGL_PIXEL_FORMAT_BGR_888:
+ TRY_CONVERSIONS(rgb, TRUE); break;
+ case COGL_PIXEL_FORMAT_RGBA_8888:
+ TRY_CONVERSIONS(rgba, FALSE); break;
+ case COGL_PIXEL_FORMAT_BGRA_8888:
+ TRY_CONVERSIONS(rgba, TRUE); break;
+ case COGL_PIXEL_FORMAT_ARGB_8888:
+ TRY_CONVERSIONS(argb, FALSE); break;
+ case COGL_PIXEL_FORMAT_ABGR_8888:
+ TRY_CONVERSIONS(argb, TRUE); break;
+ default:
+ break;
+ }
- src += src_bpp;
- dst += dst_bpp;
- }
- }
+#undef TRY_CONVERSIONS
+#undef TRY_CONVERSION
- return TRUE;
+ g_free(dst_bmp->data);
+ dst_bmp->data = 0;
+ /* We can't do anything we haven't got here */
+ return FALSE;
}
gboolean
Modified: projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-pixbuf.c
===================================================================
--- projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-pixbuf.c 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap-pixbuf.c 2009-02-13 09:25:59 UTC (rev 17412)
@@ -56,306 +56,8 @@
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format)
{
- guint xpos, ypos;
- gint src_bpp;
- gint dst_bpp;
- gboolean swap_bgr;
-
- /* FIXME: we could do some fancy preprocessor magic here so
- * support formats in a much more sensible way?
- *
- * #define RGB888_GREEN(X) (x[1])
- * #define RGB888_SET(X,R,G,B) X[0]=R;X[1]=G;X[2]=B;
- * #define ...
- * #define SWAP(A,B,FMT_FROM,FMT_TO) \
- * for (x...) FMT_TO##_SET(X, FMT_FROM##GREEN, etc.)
- */
-
- swap_bgr = (bmp->format & COGL_BGR_BIT) != (dst_format & COGL_BGR_BIT);
- src_bpp = _cogl_get_format_bpp (bmp->format);
- dst_bpp = _cogl_get_format_bpp (dst_format);
-
- /* special case for 16-bit X canvas that is faster than fallback */
- if ((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGB_565 &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGB_888)
- {
-
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- if (swap_bgr) {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- guchar *dst = (guchar*)dst_bmp->data + ypos * dst_bmp->rowstride;
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- gushort *c = (gushort*)src;
- dst[0] = (((*c >> 8) & 0xf8) | ((*c >> 5) & 0x7));
- dst[1] = (((*c >> 3) & 0xfc) | ((*c >> 9) & 0x3));
- dst[2] = (((*c << 3) & 0xf8) | ((*c >> 2) & 0x7));
- src += 2;
- dst += 3;
- }
- }
- } else {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- guchar *dst = (guchar*)dst_bmp->data + ypos * dst_bmp->rowstride;
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- gushort *c = (gushort*)src;
- dst[0] = (((*c << 3) & 0xf8) | ((*c >> 2) & 0x7));
- dst[1] = (((*c >> 3) & 0xfc) | ((*c >> 9) & 0x3));
- dst[2] = (((*c >> 8) & 0xf8) | ((*c >> 5) & 0x7));
- src += 2;
- dst += 3;
- }
- }
- }
- return TRUE;
- }
- /* to 16 bit conversion without alpha */
- if (((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGB_888 ||
- (bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888) &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGB_565)
- {
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- if (!swap_bgr) {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- *dst = (src[2] >> 3) |
- ((src[1] & 0xFC) << 3) |
- ((src[0] & 0xF8) << 8);
- src += src_bpp;
- dst ++;
- }
- }
- } else {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- *dst = (src[0] >> 3) |
- ((src[1] & 0xFC) << 3) |
- ((src[2] & 0xF8) << 8);
- src += src_bpp;
- dst ++;
- }
- }
- }
- return TRUE;
- }
- /* to 16 bit conversion WITH alpha */
- if ((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888 &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_4444)
- {
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- if (!swap_bgr) {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- *dst = (src[3] >> 4) |
- (src[2] & 0xF0) |
- ((src[1] & 0xF0) << 4) |
- ((src[0] & 0xF0) << 8);
- src += 4;
- dst ++;
- }
- }
- } else {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- *dst = (src[1] >> 4) |
- (src[2] & 0xF0) |
- ((src[3] & 0xF0) << 4) |
- ((src[0] & 0xF0) << 8);
- src += 4;
- dst ++;
- }
- }
- }
- return TRUE;
- }
-/* to 16 bit conversion WITH 1 bit alpha */
- if ((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888 &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_5551)
- {
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- if (!swap_bgr) {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- /* for reversed bit pattern in 5551
- *dst = (src[3] >> 3) |
- ((src[2] & 0xF8) << 2) |
- ((src[1] & 0xF8) << 7) |
- ((src[0] & 0x80) << 8);*/
- *dst = ((src[0] & 0xF8) << 8) |
- ((src[1] & 0xF8) << 3) |
- ((src[2] & 0xF8) >> 2) |
- (src[3] >> 7);
- src += 4;
- dst ++;
- }
- }
- } else {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- gushort *dst = (gushort*)((guchar*)dst_bmp->data + ypos * dst_bmp->rowstride);
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- /*for reversed bit pattern in 5551
- *dst = (src[1] >> 3) |
- ((src[2] & 0xF8) << 2) |
- ((src[3] & 0xF8) << 7) |
- ((src[0] & 0x80) << 8);*/
- *dst = ((src[2] & 0xF8) << 8) |
- ((src[1] & 0xF8) << 3) |
- ((src[0] & 0xF8) >> 2) |
- (src[3] >> 7);
- src += 4;
- dst ++;
- }
- }
- }
- return TRUE;
- }
- /* special case for RGBA -> RGB (used in hildon-desktop at least once) */
- if ((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888 &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGB_888)
- {
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- if (!swap_bgr) {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- guchar *dst = (guchar*)dst_bmp->data + ypos * dst_bmp->rowstride;
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- src += src_bpp;
- dst += dst_bpp;
- }
- }
- } else {
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- guchar *dst = (guchar*)dst_bmp->data + ypos * dst_bmp->rowstride;
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- src += src_bpp;
- dst += dst_bpp;
- }
- }
- }
- return TRUE;
- }
- /* case for RGBA->BGRA swapping */
- if ((bmp->format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888 &&
- (dst_format & COGL_UNORDERED_MASK)==COGL_PIXEL_FORMAT_RGBA_8888 &&
- (bmp->format & COGL_BGR_BIT) != (dst_format & COGL_BGR_BIT))
- {
- /* Initialize destination bitmap */
- *dst_bmp = *bmp;
- dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
- dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
- (dst_format & COGL_UNPREMULT_MASK));
-
- /* Allocate a new buffer to hold converted data */
- dst_bmp->data = g_malloc (sizeof(guchar)
- * dst_bmp->height
- * dst_bmp->rowstride);
-
- for (ypos=0; ypos<bmp->height; ypos++)
- {
- guchar *src = (guchar*)bmp->data + ypos * bmp->rowstride;
- guchar *dst = (guchar*)dst_bmp->data + ypos * dst_bmp->rowstride;
- for (xpos=0; xpos<bmp->width; xpos++)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
- src += src_bpp;
- dst += dst_bpp;
- }
- }
-
- return TRUE;
- }
+ /* Now bitmap-fallback is improved there is no need for all this, errm...
+ * clutter in here */
return FALSE;
}
Modified: projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap.c
===================================================================
--- projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap.c 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/clutter/cogl/common/cogl-bitmap.c 2009-02-13 09:25:59 UTC (rev 17412)
@@ -34,14 +34,14 @@
#include <string.h>
-gint
+inline gint
_cogl_get_format_bpp (CoglPixelFormat format)
{
switch (format & COGL_PIXEL_SIZE_MASK)
{
- case COGL_PIXEL_FORMAT_8 & COGL_UNORDERED_MASK :
- return 1;
- case COGL_PIXEL_FORMAT_16 & COGL_UNORDERED_MASK :
+ case COGL_PIXEL_FORMAT_8 & COGL_UNORDERED_MASK :
+ return 1;
+ case COGL_PIXEL_FORMAT_16 & COGL_UNORDERED_MASK :
return 2;
case COGL_PIXEL_FORMAT_24 & COGL_UNORDERED_MASK :
return 3;
@@ -50,7 +50,7 @@
default:
g_warning("%s: UNKNOWN PIXEL FORMAT %d", G_STRLOC, format);
}
-
+
return 0;
}
@@ -62,7 +62,7 @@
CoglBitmap tmp_bmp = *bmp;
CoglBitmap new_bmp = *bmp;
gboolean new_bmp_owner = FALSE;
-
+
/* Is base format different (not considering premult status)? */
if ((bmp->format & COGL_UNPREMULT_MASK) !=
(dst_format & COGL_UNPREMULT_MASK))
@@ -70,20 +70,20 @@
/* Try converting using imaging library */
if (!_cogl_bitmap_convert (&new_bmp, &tmp_bmp, dst_format))
{
- g_warning("%s: Falling back to slow conversion between pixel formats %d and %d",
- __FUNCTION__, (int)bmp->format, (int)dst_format);
+ /*g_warning("%s: Falling back to slow conversion between pixel formats %d and %d",
+ __FUNCTION__, (int)bmp->format, (int)dst_format);*/
/* ... or try fallback */
- if (!_cogl_bitmap_fallback_convert (&new_bmp, &tmp_bmp, dst_format))
+ if (!_cogl_bitmap_fallback_convert (&new_bmp, &tmp_bmp, dst_format))
{
return FALSE;
}
}
-
+
/* Update bitmap with new data */
new_bmp = tmp_bmp;
new_bmp_owner = TRUE;
}
-
+
/* Do we need to unpremultiply */
if ((bmp->format & COGL_PREMULT_BIT) == 0 &&
(dst_format & COGL_PREMULT_BIT) > 0)
@@ -96,19 +96,19 @@
{
if (new_bmp_owner)
g_free (new_bmp.data);
-
+
return FALSE;
}
}
-
+
/* Update bitmap with new data */
if (new_bmp_owner)
g_free (new_bmp.data);
-
+
new_bmp = tmp_bmp;
new_bmp_owner = TRUE;
}
-
+
/* Do we need to premultiply */
if ((bmp->format & COGL_PREMULT_BIT) > 0 &&
(dst_format & COGL_PREMULT_BIT) == 0)
@@ -116,13 +116,13 @@
/* FIXME: implement premultiplication */
if (new_bmp_owner)
g_free (new_bmp.data);
-
+
return FALSE;
}
-
+
/* Output new bitmap info */
*dst_bmp = new_bmp;
-
+
return TRUE;
}
@@ -140,14 +140,14 @@
guchar *dstdata;
gint bpp;
gint line;
-
+
/* Intended only for fast copies when format is equal! */
g_assert (src->format == dst->format);
bpp = _cogl_get_format_bpp (src->format);
-
+
srcdata = src->data + src_y * src->rowstride + src_x * bpp;
dstdata = dst->data + dst_y * dst->rowstride + dst_x * bpp;
-
+
for (line=0; line<height; ++line)
{
memcpy (dstdata, srcdata, width * bpp);
@@ -166,11 +166,11 @@
const guchar *uncompressed = data;
guchar *rgba = 0;
guint compressed_size = 0;
-
+
if (!has_alpha)
{
- gint i,s;
- guchar *uc;
+ gint i,s;
+ guchar *uc;
/* do conversion to RGBA8888... */
s = width*height;
rgba = g_malloc(4*s);
@@ -184,21 +184,21 @@
uc += 4;
}
}
-
+
compressed = cogl_pvr_texture_compress_pvrtc4(
uncompressed, width, height,
&compressed_size);
- /* free data if we created it above */
+ /* free data if we created it above */
if (rgba)
- g_free(rgba);
-
+ g_free(rgba);
+
if (!compressed)
return FALSE;
-
+
if (!cogl_pvr_texture_save_pvrtc4( filename, compressed, compressed_size,
width, height))
return FALSE;
g_free (compressed);
- return TRUE;
+ return TRUE;
}
Modified: projects/haf/trunk/clutter/clutter/x11/clutter-x11-texture-pixmap.c
===================================================================
--- projects/haf/trunk/clutter/clutter/x11/clutter-x11-texture-pixmap.c 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/clutter/x11/clutter-x11-texture-pixmap.c 2009-02-13 09:25:59 UTC (rev 17412)
@@ -791,7 +791,10 @@
first_pixel = priv->image->data + priv->image->bytes_per_line * y
+ x * priv->image->bits_per_pixel/8;
else
- g_warning ("%s: XGetImage() failed", __FUNCTION__);
+ {
+ g_warning ("%s: XGetImage() failed", __FUNCTION__);
+ return;
+ }
}
else
{
Modified: projects/haf/trunk/clutter/debian/changelog
===================================================================
--- projects/haf/trunk/clutter/debian/changelog 2009-02-13 08:45:36 UTC (rev 17411)
+++ projects/haf/trunk/clutter/debian/changelog 2009-02-13 09:25:59 UTC (rev 17412)
@@ -2,6 +2,9 @@
* Removed needless print for scratchbox
* Fixed RGBA texture pixmaps in X11-texture-pixmap (format conversion hell)
+ * Fixed possible uninitialised pointer in x11-texture
+ * Re-implemented the format conversion code to make it much quicker and
+ tidier using preprocessor
-- Gordon Williams <gordon.williams at collabora.co.uk> Wed, 11 Feb 2009 09:24:53 +0200
- Previous message: [maemo-commits] r17411 - in projects/haf/trunk/ke-recv-extra: debian src
- Next message: [maemo-commits] r17413 - in projects/haf/trunk/libmatchbox2: . matchbox/core
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
