833 static void m3gConvertPixels(M3GPixelFormat srcFormat, const M3Gubyte *src, |
833 static void m3gConvertPixels(M3GPixelFormat srcFormat, const M3Gubyte *src, |
834 M3GPixelFormat dstFormat, M3Gubyte *dst, |
834 M3GPixelFormat dstFormat, M3Gubyte *dst, |
835 M3Gsizei count) |
835 M3Gsizei count) |
836 { |
836 { |
837 M3Guint temp[SPAN_BUFFER_SIZE]; |
837 M3Guint temp[SPAN_BUFFER_SIZE]; |
|
838 const char endianTest[4] = { 1, 0, 0, 0 }; |
838 |
839 |
839 M3Guint srcBpp = m3gBytesPerPixel(srcFormat); |
840 M3Guint srcBpp = m3gBytesPerPixel(srcFormat); |
840 M3Guint dstBpp = m3gBytesPerPixel(dstFormat); |
841 M3Guint dstBpp = m3gBytesPerPixel(dstFormat); |
841 M3G_ASSERT(srcBpp > 0 && dstBpp > 0); |
842 M3G_ASSERT(srcBpp > 0 && dstBpp > 0); |
842 |
843 |
843 while (count > 0) { |
844 while (count > 0) { |
844 M3Gsizei n = (count < SPAN_BUFFER_SIZE) ? count : SPAN_BUFFER_SIZE; |
845 M3Gsizei n = count; |
845 if (srcFormat == M3G_ARGB8 && dstFormat != M3G_ARGB8) { |
846 |
|
847 /* Check the source and destination formats to avoid |
|
848 the intermediate ARGB format conversion. */ |
|
849 if (((srcFormat == M3G_RGBA8 && (dstFormat == M3G_BGRA8 || dstFormat == M3G_BGR8_32)) |
|
850 || (dstFormat == M3G_RGBA8 && (srcFormat == M3G_BGRA8 || srcFormat == M3G_BGR8_32))) |
|
851 && (n > 2) && ((*(const int *)endianTest) == 1)) { |
|
852 /* use fast path for RGBA<->BGRA conversion */ |
|
853 fastConvertBGRAToRGBA(src, n * srcBpp, n, 1, dst); |
|
854 } else if (srcFormat == M3G_ARGB8 && dstFormat != M3G_ARGB8) { |
846 convertFromARGB((M3Guint*)src, n, dstFormat, dst); |
855 convertFromARGB((M3Guint*)src, n, dstFormat, dst); |
847 } else if (srcFormat != M3G_ARGB8 && dstFormat == M3G_ARGB8) { |
856 } else if (srcFormat != M3G_ARGB8 && dstFormat == M3G_ARGB8) { |
848 convertToARGB(srcFormat, src, n, (M3Guint*)dst); |
857 convertToARGB(srcFormat, src, n, (M3Guint*)dst); |
849 } else { |
858 } else { |
|
859 /* no luck, do the conversion via ARGB (source format -> ARGB -> destination format) */ |
|
860 n = (count < SPAN_BUFFER_SIZE) ? count : SPAN_BUFFER_SIZE; |
850 convertToARGB(srcFormat, src, n, temp); |
861 convertToARGB(srcFormat, src, n, temp); |
851 convertFromARGB(temp, n, dstFormat, dst); |
862 convertFromARGB(temp, n, dstFormat, dst); |
852 } |
863 } |
853 count -= SPAN_BUFFER_SIZE; /* \note may go negative */ |
864 count -= n; |
854 src += n * srcBpp; |
865 src += n * srcBpp; |
855 dst += n * dstBpp; |
866 dst += n * dstBpp; |
856 } |
867 } |
857 } |
868 } |
858 |
869 |
1372 flags &= ~(M3G_DYNAMIC|M3G_RENDERING_TARGET); |
1383 flags &= ~(M3G_DYNAMIC|M3G_RENDERING_TARGET); |
1373 flags |= M3G_STATIC; |
1384 flags |= M3G_STATIC; |
1374 |
1385 |
1375 image->flags = flags; |
1386 image->flags = flags; |
1376 |
1387 |
1377 #ifdef M3G_ENABLE_GLES_RESOURCE_HANDLING |
1388 #ifndef M3G_ENABLE_GLES_RESOURCE_HANDLING |
1378 /* If the image format has no alpha information, we can discard |
1389 /* If the image format has no alpha information, we can discard |
1379 * the image data under suitable conditions */ |
1390 * the image data under suitable conditions */ |
1380 |
1391 |
1381 if (image->format == M3G_RGB || image->format == M3G_LUMINANCE) { |
1392 if (image->format == M3G_RGB || image->format == M3G_LUMINANCE) { |
1382 image->pinned = M3G_FALSE; |
1393 image->pinned = M3G_FALSE; |