[niepce] Make the cairo surface to BABL code endian safe, theorically.



commit e95a06b3ca648f127bec0cc8320273b3a4fe919e
Author: Hubert Figuiere <hub figuiere net>
Date:   Sun May 17 02:06:36 2009 -0400

    Make the cairo surface to BABL code endian safe, theorically.
---
 ChangeLog         |    6 ++++++
 src/ncr/image.cpp |   41 ++++++++++++++++++++++++++++++++---------
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0a3ec83..ab5641d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-17  Hubert Figuiere  <hub figuiere net>
+
+	* src/ncr/image.cpp
+	Make the cairo surface to BABL code endian
+	safe, theorically.
+
 2009-05-15  Hubert Figuiere  <hub figuiere net>
 
 	* src/ncr/image.cpp
diff --git a/src/ncr/image.cpp b/src/ncr/image.cpp
index a4722fc..03bb956 100644
--- a/src/ncr/image.cpp
+++ b/src/ncr/image.cpp
@@ -34,6 +34,32 @@ extern "C" {
 
 namespace ncr {
 
+namespace {
+
+const Babl * format_for_cairo_argb32()
+{
+    // TODO not endian neutral
+    return babl_format_new(babl_model("R'G'B'A"),
+                           babl_type ("u8"),
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+                           babl_component ("B'"),
+                           babl_component ("G'"),
+                           babl_component ("R'"),
+                           babl_component ("A"),
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+                           babl_component ("A"),
+                           babl_component ("R'"),
+                           babl_component ("G'"),
+                           babl_component ("B'"),
+#else
+#error unknown endian
+#endif
+                           NULL);
+}
+
+
+}
+
 struct Image::Private {
     Private()
         : m_width(0),
@@ -198,19 +224,14 @@ Cairo::RefPtr<Cairo::Surface> Image::cairo_surface_for_display()
     int w, h;
     w = roi.gobj()->width;
     h = roi.gobj()->height;
-    // TODO not endian neutral
-    const Babl * format = babl_format_new(babl_model("R'G'B'A"),
-                                          babl_type ("u8"),
-                                          babl_component ("B'"),
-                                          babl_component ("G'"),
-                                          babl_component ("R'"),
-                                          babl_component ("A"),
-                                          NULL);
+
+    const Babl * format = format_for_cairo_argb32();
+
     Cairo::RefPtr<Cairo::ImageSurface> surface 
         = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, w, h);
     priv->m_output->blit(1.0, roi, format,
                          (void*)surface->get_data(), surface->get_stride(),
-                         (Gegl::BlitFlags)(GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY));
+                         (Gegl::BLIT_CACHE | Gegl::BLIT_DIRTY));
     return surface;
 }
 
@@ -240,6 +261,8 @@ int Image::get_output_height() const
 }
 
 
+
+
 }
 
 /*



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]