]> git.eshelyaron.com Git - emacs.git/commitdiff
Support RSVG and cairo.
authorJan D <jan.h.d@swipnet.se>
Sun, 5 Apr 2015 16:34:07 +0000 (18:34 +0200)
committerJan D <jan.h.d@swipnet.se>
Sun, 5 Apr 2015 16:34:07 +0000 (18:34 +0200)
* configure.ac: Allow rsvg with cairo.  Move back HAVE_RSVG.

* src/dispextern.h (struct image): add cr_data2 if cairo.

* src/image.c: #undef COLOR_TABLE_SUPPORT when USE_CAIRO.
(x_clear_image): Free cr_data and cr_data2 if set.
(xpm_load): Assign data to cr_data2.
(svg_load_image): Convert from GdkPixbuf to CAIRO_FORMAT_ARGB32.

ChangeLog
configure.ac
src/ChangeLog
src/dispextern.h
src/image.c

index 6e8cadebb15858350faffe0e7f5102da16b8023d..b456cc46a5457198d187760809bf731df3309a85 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-04-05  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * configure.ac: Allow rsvg with cairo.  Move back HAVE_RSVG.
+
 2015-04-03  Jan Djärv  <jan.h.d@swipnet.se>
 
        * configure.ac (HAVE_RSVG): Move after cairo.
index 9d4e3758fda0df656377c56d8b23cde7f88fd5d0..79619c74117e5422c226587d27775e13071641f7 100644 (file)
@@ -2361,6 +2361,28 @@ fail;
 fi
 
 
+### Use -lrsvg-2 if available, unless `--with-rsvg=no' is specified.
+HAVE_RSVG=no
+if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" || test "${opsys}" = "mingw32"; then
+  if test "${with_rsvg}" != "no"; then
+    RSVG_REQUIRED=2.11.0
+    RSVG_MODULE="librsvg-2.0 >= $RSVG_REQUIRED"
+
+    EMACS_CHECK_MODULES([RSVG], [$RSVG_MODULE])
+    AC_SUBST(RSVG_CFLAGS)
+    AC_SUBST(RSVG_LIBS)
+
+    if test $HAVE_RSVG = yes; then
+      AC_DEFINE(HAVE_RSVG, 1, [Define to 1 if using librsvg.])
+      CFLAGS="$CFLAGS $RSVG_CFLAGS"
+      # Windows loads librsvg dynamically
+      if test "${opsys}" = "mingw32"; then
+        RSVG_LIBS=
+      fi
+    fi
+  fi
+fi
+
 HAVE_IMAGEMAGICK=no
 if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" || test "${HAVE_W32}" = "yes"; then
   if test "${with_imagemagick}" != "no"; then
@@ -3092,7 +3114,6 @@ if test "${HAVE_X11}" = "yes"; then
     with_jpeg=no
     with_gif=no
     with_tiff=no
-    with_rsvg=no
 
     CFLAGS="$CFLAGS $CAIRO_CFLAGS"
     LIBS="$LIBS $CAIRO_LIBS"
@@ -3101,29 +3122,6 @@ if test "${HAVE_X11}" = "yes"; then
   fi
 fi
 
-### Use -lrsvg-2 if available, unless `--with-rsvg=no' is specified.
-HAVE_RSVG=no
-if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" || test "${opsys}" = "mingw32"; then
-  if test "${with_rsvg}" != "no"; then
-    RSVG_REQUIRED=2.11.0
-    RSVG_MODULE="librsvg-2.0 >= $RSVG_REQUIRED"
-
-    EMACS_CHECK_MODULES([RSVG], [$RSVG_MODULE])
-    AC_SUBST(RSVG_CFLAGS)
-    AC_SUBST(RSVG_LIBS)
-
-    if test $HAVE_RSVG = yes; then
-      AC_DEFINE(HAVE_RSVG, 1, [Define to 1 if using librsvg.])
-      CFLAGS="$CFLAGS $RSVG_CFLAGS"
-      # Windows loads librsvg dynamically
-      if test "${opsys}" = "mingw32"; then
-        RSVG_LIBS=
-      fi
-    fi
-  fi
-fi
-
-
 ### Use -lXpm if available, unless `--with-xpm=no'.
 ### mingw32 doesn't use -lXpm, since it loads the library dynamically.
 ### In the Cygwin-w32 build, we need to use /usr/include/noX/X11/xpm.h
index 1a473e653866f9ba0b85c67f63a845f64042550e..18e4b343fb7f4fc387d6be5c2c9babe091289772 100644 (file)
@@ -1,3 +1,12 @@
+2015-04-05  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * image.c: #undef COLOR_TABLE_SUPPORT when USE_CAIRO.
+       (x_clear_image): Free cr_data and cr_data2 if set.
+       (xpm_load): Assign data to cr_data2.
+       (svg_load_image): Convert from GdkPixbuf to CAIRO_FORMAT_ARGB32.
+
+       * dispextern.h (struct image): add cr_data2 if cairo.
+
 2015-04-03  Jan Djärv  <jan.h.d@swipnet.se>
 
        * image.c (prepare_image_for_display): Don't load if USE_CAIRO.
index addb43275bcc8231ce35362c76d3e3f8978a2534..d9d4d2300fa9286ab3361a85401d479b2bac0813 100644 (file)
@@ -2943,6 +2943,7 @@ struct image
 
 #ifdef USE_CAIRO
   void *cr_data;
+  void *cr_data2;
 #endif
 #ifdef HAVE_X_WINDOWS
   /* X images of the image, corresponding to the above Pixmaps.
index e24bc589ef0f9724ad6d45b9e1e60077e47662f7..895021c4b41fd994011b5e4afe5d66a526192591 100644 (file)
@@ -88,6 +88,10 @@ typedef struct w32_bitmap_record Bitmap_Record;
 
 #endif /* HAVE_NTGUI */
 
+#ifdef USE_CAIRO
+#undef COLOR_TABLE_SUPPORT
+#endif
+
 #ifdef HAVE_NS
 #undef COLOR_TABLE_SUPPORT
 
@@ -1303,10 +1307,8 @@ x_clear_image (struct frame *f, struct image *img)
   block_input ();
 #ifdef USE_CAIRO
   if (img->cr_data)
-    {
-      cairo_surface_destroy ((cairo_surface_t *)img->cr_data);
-      if (img->ximg && img->ximg->obdata) xfree (img->ximg->obdata);
-    }
+    cairo_surface_destroy ((cairo_surface_t *)img->cr_data);
+  if (img->cr_data2) xfree (img->cr_data2);
 #endif
   x_clear_image_1 (f, img,
                   CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_MASK | CLEAR_IMAGE_COLORS);
@@ -3670,7 +3672,7 @@ xpm_load (struct frame *f, struct image *img)
       img->height = cairo_image_surface_get_height (surface);
       img->cr_data = surface;
       img->pixmap = 0;
-      img->ximg->obdata = (char *)data;
+      img->cr_data2 = data;
     }
   else
     {
@@ -8993,6 +8995,45 @@ svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  *
   eassert (gdk_pixbuf_get_has_alpha (pixbuf));
   eassert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
 
+#ifdef USE_CAIRO
+  {
+    cairo_surface_t *surface;
+    cairo_format_t format = CAIRO_FORMAT_ARGB32;
+    int stride = cairo_format_stride_for_width (format, width);
+    unsigned char *data = (unsigned char *) xmalloc (width*height*4);
+    int y;
+
+    for (y = 0; y < height; ++y)
+      {
+        const guchar *iconptr = pixels + y * rowstride;
+        uint32_t *dataptr = (uint32_t *) (data + y * rowstride);
+        int x;
+
+        for (x = 0; x < width; ++x)
+          {
+            *dataptr = (iconptr[0] << 16)
+              | (iconptr[1] << 8)
+              | iconptr[2]
+              | (iconptr[3] << 24);
+            iconptr += 4;
+            ++dataptr;
+          }
+      }
+
+    surface = cairo_image_surface_create_for_data (data,
+                                                   format,
+                                                   width,
+                                                   height,
+                                                   stride);
+
+    g_object_unref (pixbuf);
+    img->width  = width;
+    img->height = height;
+    img->cr_data = surface;
+    img->cr_data2 = data;
+    img->pixmap = 0;
+  }
+#else
   /* Try to create a x pixmap to hold the svg pixmap.  */
   if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
     {
@@ -9064,6 +9105,7 @@ svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  *
 
   /* Put ximg into the image.  */
   image_put_x_image (f, img, ximg, 0);
+#endif /* ! USE_CAIRO */
 
   return 1;
 
@@ -9331,15 +9373,16 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
          /* For each pixel of the image, look its color up in the
             color table.  After having done so, the color table will
             contain an entry for each color used by the image.  */
+#ifdef COLOR_TABLE_SUPPORT
          for (y = 0; y < img->height; ++y)
            for (x = 0; x < img->width; ++x)
              {
                unsigned long pixel = XGetPixel (ximg, x, y);
+
                lookup_pixel_color (f, pixel);
              }
 
          /* Record colors in the image.  Free color table and XImage.  */
-#ifdef COLOR_TABLE_SUPPORT
          img->colors = colors_in_color_table (&img->ncolors);
          free_color_table ();
 #endif