[poppler] glib/demo glib/poppler-annot.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Wed May 6 07:05:37 PDT 2009


 glib/demo/annots.c    |   25 +++++++++++--------------
 glib/poppler-annot.cc |   36 +++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 29 deletions(-)

New commits:
commit c21b08a254f42f53d4b59ad4fb308c7c68c32d15
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Wed May 6 15:56:21 2009 +0200

    [glib] Several fixes in poppler_annot_get_color()
    
    PopplerColor is compatible with GdkColor where every component is in the
    range of 0 to 65535, we were returning values between 0 and 1 but
    converted to guint16.
    We were also showing a warning when AnnotColor::colorTransparent is
    used, but we decided to return a PopplerColor * to be able to represent
    transparent color returning NULL, so it's actually supported.

diff --git a/glib/demo/annots.c b/glib/demo/annots.c
index 338f5dd..a4428db 100644
--- a/glib/demo/annots.c
+++ b/glib/demo/annots.c
@@ -152,28 +152,25 @@ get_annot_color (PopplerAnnot *poppler_annot)
 
     if ((poppler_color = poppler_annot_get_color (poppler_annot))) {
         GdkPixbuf *pixbuf;
+	gint rowstride, num, x;
+	guchar *pixels;
 
         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
                                  FALSE, 8,
                                  64, 16);
 
-        if (pixbuf) {
-            gint rowstride, num, x;
-            guchar *pixels;
-
-            rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-            pixels = gdk_pixbuf_get_pixels (pixbuf);
+	rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+	pixels = gdk_pixbuf_get_pixels (pixbuf);
             
-            num = gdk_pixbuf_get_width (pixbuf) *
+	num = gdk_pixbuf_get_width (pixbuf) *
                 gdk_pixbuf_get_height (pixbuf);
 
-            for (x = 0; x < num; x++) {
-                pixels[0] = poppler_color->red * 255;
-                pixels[1] = poppler_color->green * 255;
-                pixels[2] = poppler_color->blue * 255;
-                pixels += 3;
-            }
-        }
+	for (x = 0; x < num; x++) {
+          pixels[0] = poppler_color->red;
+	  pixels[1] = poppler_color->green;
+	  pixels[2] = poppler_color->blue;
+	  pixels += 3;
+	}
 
         g_free (poppler_color);
 
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index e97f705..7746d48 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -345,41 +345,47 @@ poppler_annot_get_flags (PopplerAnnot *poppler_annot)
  * Retrieves the color of @poppler_annot.
  *
  * Return value: a new allocated #PopplerColor with the color values of
- *               @poppler_annot. It must be freed with g_free() when done.
+ *               @poppler_annot, or %NULL. It must be freed with g_free() when done.
  **/
 PopplerColor *
 poppler_annot_get_color (PopplerAnnot *poppler_annot)
 {
   AnnotColor *color;
+  PopplerColor *poppler_color = NULL;
 
   g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
 
-  if ((color = poppler_annot->annot->getColor ())) {
-    PopplerColor *poppler_color;
+  color = poppler_annot->annot->getColor ();
+
+  if (color) {
     double *values = color->getValues ();
 
     switch (color->getSpace ())
       {
       case AnnotColor::colorGray:
         poppler_color = g_new (PopplerColor, 1);
-        poppler_color->red = (guint16) values[0];
-        poppler_color->green = (guint16) values[0];
-        poppler_color->blue = (guint16) values[0];
-        return poppler_color;
+	
+        poppler_color->red = (guint16) (values[0] * 65535);
+        poppler_color->green = poppler_color->red;
+        poppler_color->blue = poppler_color->red;
+
+	break;
       case AnnotColor::colorRGB:
         poppler_color = g_new (PopplerColor, 1);
-        poppler_color->red = (guint16) values[0];
-        poppler_color->green = (guint16) values[1];
-        poppler_color->blue = (guint16) values[2];
-        return poppler_color;
-      case AnnotColor::colorTransparent:
+	
+        poppler_color->red = (guint16) (values[0] * 65535);
+        poppler_color->green = (guint16) (values[1] * 65535);
+        poppler_color->blue = (guint16) (values[2] * 65535);
+
+	break;
       case AnnotColor::colorCMYK:
-      default:
-        g_warning ("Unsupported Annot Color");
+        g_warning ("Unsupported Annot Color: colorCMYK");
+      case AnnotColor::colorTransparent:
+        break;
       }
   }
 
-  return NULL;
+  return poppler_color;
 }
 
 /* PopplerAnnotMarkup */


More information about the poppler mailing list