emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117068: * image.c: Do not use libpng if HAVE_NS, as


From: Paul Eggert
Subject: [Emacs-diffs] trunk r117068: * image.c: Do not use libpng if HAVE_NS, as NS does its own thing.
Date: Tue, 06 May 2014 21:13:40 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117068
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2014-05-06 14:13:37 -0700
message:
  * image.c: Do not use libpng if HAVE_NS, as NS does its own thing.
  
  [HAVE_NS]: Do not include png.h.
  (x_query_frame_background_color): New function.
  (png_load_body, imagemagick_load_image, svg_load_image): Use it.
  (png_load_body): Coalesce duplicate code.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/image.c                    image.c-20091113204419-o5vbwnq5f7feedwu-2969
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-05-04 21:28:08 +0000
+++ b/src/ChangeLog     2014-05-06 21:13:37 +0000
@@ -1,3 +1,11 @@
+2014-05-06  Paul Eggert  <address@hidden>
+
+       * image.c: Do not use libpng if HAVE_NS, as NS does its own thing.
+       [HAVE_NS]: Do not include png.h.
+       (x_query_frame_background_color): New function.
+       (png_load_body, imagemagick_load_image, svg_load_image): Use it.
+       (png_load_body): Coalesce duplicate code.
+
 2014-05-04  Paul Eggert  <address@hidden>
 
        Consult libpng-config more consistently (Bug#17339).

=== modified file 'src/image.c'
--- a/src/image.c       2014-05-04 21:28:08 +0000
+++ b/src/image.c       2014-05-06 21:13:37 +0000
@@ -21,10 +21,6 @@
 #include "sysstdio.h"
 #include <unistd.h>
 
-#ifdef HAVE_PNG
-# include <png.h>
-#endif
-
 #include <setjmp.h>
 #include <c-ctype.h>
 
@@ -1229,6 +1225,18 @@
   return img->background_transparent;
 }
 
+/* Store F's background color into *BGCOLOR.  */
+static void
+x_query_frame_background_color (struct frame *f, XColor *bgcolor)
+{
+#ifndef HAVE_NS
+  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
+  x_query_color (f, bgcolor);
+#else
+  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
+#endif
+}
+
 
 /***********************************************************************
                  Helper functions for X image types
@@ -5502,7 +5510,9 @@
 #endif /* HAVE_PNG || HAVE_NS */
 
 
-#ifdef HAVE_PNG
+#if defined HAVE_PNG && !defined HAVE_NS
+
+#include <png.h>
 
 #ifdef WINDOWSNT
 /* PNG library details.  */
@@ -5880,43 +5890,23 @@
       /* png_color_16 *image_bg; */
       Lisp_Object specified_bg
        = image_spec_value (img->spec, QCbackground, NULL);
-      int shift = (bit_depth == 16) ? 0 : 8;
+      XColor color;
 
-      if (STRINGP (specified_bg))
+      /* If the user specified a color, try to use it; if not, use the
+        current frame background, ignoring any default background
+        color set by the image.  */
+      if (STRINGP (specified_bg)
+         ? x_defined_color (f, SSDATA (specified_bg), &color, false)
+         : (x_query_frame_background_color (f, &color), true))
        /* The user specified `:background', use that.  */
        {
-         XColor color;
-         if (x_defined_color (f, SSDATA (specified_bg), &color, 0))
-           {
-             png_color_16 user_bg;
-
-             memset (&user_bg, 0, sizeof user_bg);
-             user_bg.red = color.red >> shift;
-             user_bg.green = color.green >> shift;
-             user_bg.blue = color.blue >> shift;
-
-             fn_png_set_background (png_ptr, &user_bg,
-                                    PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
-           }
-       }
-      else
-       {
-         /* We use the current frame background, ignoring any default
-            background color set by the image.  */
-#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
-         XColor color;
-         png_color_16 frame_background;
-
-         color.pixel = FRAME_BACKGROUND_PIXEL (f);
-         x_query_color (f, &color);
-
-         memset (&frame_background, 0, sizeof frame_background);
-         frame_background.red = color.red >> shift;
-         frame_background.green = color.green >> shift;
-         frame_background.blue = color.blue >> shift;
-#endif /* HAVE_X_WINDOWS */
-
-         fn_png_set_background (png_ptr, &frame_background,
+         int shift = bit_depth == 16 ? 0 : 8;
+         png_color_16 bg = { 0 };
+         bg.red = color.red >> shift;
+         bg.green = color.green >> shift;
+         bg.blue = color.blue >> shift;
+
+         fn_png_set_background (png_ptr, &bg,
                                 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
        }
     }
@@ -6058,9 +6048,8 @@
   return png_load_body (f, img, &c);
 }
 
-#else /* HAVE_PNG */
+#elif defined HAVE_NS
 
-#ifdef HAVE_NS
 static bool
 png_load (struct frame *f, struct image *img)
 {
@@ -6068,10 +6057,8 @@
                         image_spec_value (img->spec, QCfile, NULL),
                         image_spec_value (img->spec, QCdata, NULL));
 }
-#endif  /* HAVE_NS */
-
-
-#endif /* !HAVE_PNG */
+
+#endif /* HAVE_NS */
 
 
 
@@ -8225,14 +8212,7 @@
     specified_bg = image_spec_value (img->spec, QCbackground, NULL);
     if (!STRINGP (specified_bg)
        || !x_defined_color (f, SSDATA (specified_bg), &bgcolor, 0))
-      {
-#ifndef HAVE_NS
-       bgcolor.pixel = FRAME_BACKGROUND_PIXEL (f);
-       x_query_color (f, &bgcolor);
-#else
-       ns_query_color (FRAME_BACKGROUND_COLOR (f), &bgcolor, 1);
-#endif
-      }
+      x_query_frame_background_color (f, &bgcolor);
 
     bg_wand = NewPixelWand ();
     PixelSetRed   (bg_wand, (double) bgcolor.red   / 65535);
@@ -8868,14 +8848,7 @@
   specified_bg = image_spec_value (img->spec, QCbackground, NULL);
   if (!STRINGP (specified_bg)
       || !x_defined_color (f, SSDATA (specified_bg), &background, 0))
-    {
-#ifndef HAVE_NS
-      background.pixel = FRAME_BACKGROUND_PIXEL (f);
-      x_query_color (f, &background);
-#else
-      ns_query_color (FRAME_BACKGROUND_COLOR (f), &background, 1);
-#endif
-    }
+    x_query_frame_background_color (f, &background);
 
   /* SVG pixmaps specify transparency in the last byte, so right
      shift 8 bits to get rid of it, since emacs doesn't support


reply via email to

[Prev in Thread] Current Thread [Next in Thread]