From 62cd380b8bff78bdcecce7fe6e68cb7a39bb1b33 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 24 Sep 2010 21:42:15 +0000 Subject: [PATCH] add big-endian BGRA (Cairo) pixel buffer to RGBA (GdkPixbuf) pixel buffer conversion - restores text to the editor canvas on big-endian machines git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@7841 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/utils.cc | 51 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index d59ae3bb93..3c58a27e60 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -861,6 +861,7 @@ convert_color_channel (guint8 src, return alpha ? ((guint (src) << 8) - src) / alpha : 0; } + void convert_bgra_to_rgba (guint8 const* src, guint8* dst, @@ -870,20 +871,42 @@ convert_bgra_to_rgba (guint8 const* src, guint8 const* src_pixel = src; guint8* dst_pixel = dst; - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) - { - dst_pixel[0] = convert_color_channel (src_pixel[2], - src_pixel[3]); - dst_pixel[1] = convert_color_channel (src_pixel[1], - src_pixel[3]); - dst_pixel[2] = convert_color_channel (src_pixel[0], - src_pixel[3]); - dst_pixel[3] = src_pixel[3]; - - dst_pixel += 4; - src_pixel += 4; - } + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + /* Cairo [ B G R A ] is actually [ B G R A ] in memory SOURCE + 0 1 2 3 + Pixbuf [ R G B A ] is actually [ R G B A ] in memory DEST + */ + dst_pixel[0] = convert_color_channel (src_pixel[2], + src_pixel[3]); // R [0] <= [ 2 ] + dst_pixel[1] = convert_color_channel (src_pixel[1], + src_pixel[3]); // G [1] <= [ 1 ] + dst_pixel[2] = convert_color_channel (src_pixel[0], + src_pixel[3]); // B [2] <= [ 0 ] + dst_pixel[3] = src_pixel[3]; // alpha + +#elif G_BYTE_ORDER == G_BIG_ENDIAN + /* Cairo [ B G R A ] is actually [ A R G B ] in memory SOURCE + 0 1 2 3 + Pixbuf [ R G B A ] is actually [ R G B A ] in memory DEST + */ + dst_pixel[0] = convert_color_channel (src_pixel[1], + src_pixel[0]); // R [0] <= [ 1 ] + dst_pixel[1] = convert_color_channel (src_pixel[2], + src_pixel[0]); // G [1] <= [ 2 ] + dst_pixel[2] = convert_color_channel (src_pixel[3], + src_pixel[0]); // B [2] <= [ 3 ] + dst_pixel[3] = src_pixel[0]; // alpha + +#else +#error ardour does not currently support PDP-endianess +#endif + + dst_pixel += 4; + src_pixel += 4; + } + } } Glib::RefPtr