From d30496f52b85f82947bd07b9bd60f8482843ece8 Mon Sep 17 00:00:00 2001
From: jordi <jordi@cb4bfb15-1111-0410-82e2-95233c8f1c7e>
Date: Tue, 5 Jul 2011 09:23:38 +0000
Subject: [PATCH 1/2] When using Poppler 0.17.0, I needed to swap the blue and
 red channels, otherwise the colors (other than black
 and white) looked wierd.

--- ./src/PDFDocument.cxx
+++ ./src/PDFDocument.cxx
@@ -20,6 +20,7 @@
 #include <time.h>
 #include <poppler.h>
 #include <unistd.h>
+#include <algorithm>
 #include "epdfview.h"
 
 using namespace ePDFView;
@@ -33,6 +34,24 @@ static PageLayout convertPageLayout (gint pageLayout);
 static PageMode convertPageMode (gint pageMode);
 static gchar *getAbsoluteFileName (const gchar *fileName);
 
+namespace
+{
+    void
+    convert_bgra_to_rgba (guint8 *data, int width, int height)
+    {
+        using std::swap;
+
+        for (int y = 0; y < height; y++)
+        {
+            for (int x = 0; x < width; x++)
+            {
+                swap(data[0], data[2]);
+                data += 4;
+            }
+        }
+    }
+}
+
 ///
 /// @brief Constructs a new PDFDocument object.
 ///
@@ -650,6 +669,7 @@ PDFDocument::renderPage (gint pageNum)
         poppler_page_render (page, context);
         cairo_destroy(context);
         cairo_surface_destroy (surface);
+        convert_bgra_to_rgba(renderedPage->getData (), width, height);
 #else // !HAVE_POPPLER_0_17_0
         // Create the pixbuf from the data and render to it.
         GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data (renderedPage->getData (),
--- ./src/PDFDocument.cxx
+++ ./src/PDFDocument.cxx
@@ -635,7 +635,7 @@ PDFDocument::renderPage (gint pageNum)
 #if defined (HAVE_POPPLER_0_17_0)
         cairo_surface_t *surface = cairo_image_surface_create_for_data (
                 renderedPage->getData (),
-                CAIRO_FORMAT_RGB24, width, height,
+                CAIRO_FORMAT_ARGB32, width, height,
                 renderedPage->getRowStride ());
         cairo_t *context = cairo_create (surface);
         cairo_save(context);
