--- a/m3g/m3gcore11/src/m3g_image.c Tue Apr 27 17:59:32 2010 +0300
+++ b/m3g/m3gcore11/src/m3g_image.c Tue May 11 17:25:23 2010 +0300
@@ -835,22 +835,33 @@
M3Gsizei count)
{
M3Guint temp[SPAN_BUFFER_SIZE];
+ const char endianTest[4] = { 1, 0, 0, 0 };
M3Guint srcBpp = m3gBytesPerPixel(srcFormat);
M3Guint dstBpp = m3gBytesPerPixel(dstFormat);
M3G_ASSERT(srcBpp > 0 && dstBpp > 0);
while (count > 0) {
- M3Gsizei n = (count < SPAN_BUFFER_SIZE) ? count : SPAN_BUFFER_SIZE;
- if (srcFormat == M3G_ARGB8 && dstFormat != M3G_ARGB8) {
+ M3Gsizei n = count;
+
+ /* Check the source and destination formats to avoid
+ the intermediate ARGB format conversion. */
+ if (((srcFormat == M3G_RGBA8 && (dstFormat == M3G_BGRA8 || dstFormat == M3G_BGR8_32))
+ || (dstFormat == M3G_RGBA8 && (srcFormat == M3G_BGRA8 || srcFormat == M3G_BGR8_32)))
+ && (n > 2) && ((*(const int *)endianTest) == 1)) {
+ /* use fast path for RGBA<->BGRA conversion */
+ fastConvertBGRAToRGBA(src, n * srcBpp, n, 1, dst);
+ } else if (srcFormat == M3G_ARGB8 && dstFormat != M3G_ARGB8) {
convertFromARGB((M3Guint*)src, n, dstFormat, dst);
} else if (srcFormat != M3G_ARGB8 && dstFormat == M3G_ARGB8) {
convertToARGB(srcFormat, src, n, (M3Guint*)dst);
} else {
+ /* no luck, do the conversion via ARGB (source format -> ARGB -> destination format) */
+ n = (count < SPAN_BUFFER_SIZE) ? count : SPAN_BUFFER_SIZE;
convertToARGB(srcFormat, src, n, temp);
convertFromARGB(temp, n, dstFormat, dst);
}
- count -= SPAN_BUFFER_SIZE; /* \note may go negative */
+ count -= n;
src += n * srcBpp;
dst += n * dstBpp;
}
@@ -1374,7 +1385,7 @@
image->flags = flags;
-#ifdef M3G_ENABLE_GLES_RESOURCE_HANDLING
+#ifndef M3G_ENABLE_GLES_RESOURCE_HANDLING
/* If the image format has no alpha information, we can discard
* the image data under suitable conditions */