emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r113146: Implement :max-width/:max-height for (Image


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] trunk r113146: Implement :max-width/:max-height for (ImageMagic) images
Date: Sun, 23 Jun 2013 19:24:31 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113146
revision-id: address@hidden
parent: address@hidden
committer: Lars Magne Ingebrigtsen <address@hidden>
branch nick: trunk
timestamp: Sun 2013-06-23 21:24:27 +0200
message:
  Implement :max-width/:max-height for (ImageMagic) images
  
  * doc/lispref/display.texi (ImageMagick Images): Mention :max-width and
  :max-height.
  
  * lisp/net/shr.el (shr-rescale-image): Use the new
  :max-width/:max-height functionality.
  
  * src/image.c (compute_image_size): New function to implement
  :max-width and :max-height.
  (imagemagick_load_image): Use it.
modified:
  doc/lispref/ChangeLog          changelog-20091113204419-o5vbwnq5f7feedwu-6155
  doc/lispref/display.texi       
display.texi-20091113204419-o5vbwnq5f7feedwu-6172
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/net/shr.el                shr.el-20101002102929-yfzewk55rsg0mn93-1
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/image.c                    image.c-20091113204419-o5vbwnq5f7feedwu-2969
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2013-06-20 14:15:42 +0000
+++ b/doc/lispref/ChangeLog     2013-06-23 19:24:27 +0000
@@ -1,3 +1,8 @@
+2013-06-23  Lars Magne Ingebrigtsen  <address@hidden>
+
+       * display.texi (ImageMagick Images): Mention :max-width and
+       :max-height.
+
 2013-06-20  Paul Eggert  <address@hidden>
 
        * numbers.texi (Math Functions): Remove obsolete function log10.

=== modified file 'doc/lispref/display.texi'
--- a/doc/lispref/display.texi  2013-06-19 13:51:47 +0000
+++ b/doc/lispref/display.texi  2013-06-23 19:24:27 +0000
@@ -4653,6 +4653,15 @@
 calculated so as to preserve the aspect ratio.  If both are specified,
 aspect ratio may not be preserved.
 
address@hidden :max-width, :max-height
+The @code{:max-width} and @code{:max-height} keywords are used for
+scaling if the size of the image of the image exceeds these values.
+If @code{:width} is set it will have presedence over @code{max-width},
+and if @code{:height} is set it will have presedence over
address@hidden, but you can otherwise mix these keywords as you
+wish.  @code{:max-width} and @code{:max-height} will always preserve
+the aspec ratio.
+
 @item :rotation
 Specifies a rotation angle in degrees.
 

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-06-20 14:15:42 +0000
+++ b/etc/NEWS  2013-06-23 19:24:27 +0000
@@ -695,6 +695,9 @@
 `imagemagick-filter-types' returns the list of types that will be
 treated as images.
 
+*** ImageMagick images now support the :max-width and :max-height
+keywords.
+
 ** Minibuffer
 
 *** In minibuffer filename prompts, `C-M-f' and `C-M-b' now move to the

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-06-23 18:29:30 +0000
+++ b/lisp/ChangeLog    2013-06-23 19:24:27 +0000
@@ -1,3 +1,8 @@
+2013-06-23  Lars Magne Ingebrigtsen  <address@hidden>
+
+       * net/shr.el (shr-rescale-image): Use the new
+       :max-width/:max-height functionality.
+
 2013-06-23  Ivan Kanis  <address@hidden>
 
        * net/eww.el (eww-search-prefix): New variable.

=== modified file 'lisp/net/shr.el'
--- a/lisp/net/shr.el   2013-06-19 22:28:04 +0000
+++ b/lisp/net/shr.el   2013-06-23 19:24:27 +0000
@@ -741,34 +741,18 @@
 (defun shr-rescale-image (data &optional force)
   "Rescale DATA, if too big, to fit the current buffer.
 If FORCE, rescale the image anyway."
-  (let ((image (create-image data nil t :ascent 100)))
-    (if (or (not (fboundp 'imagemagick-types))
-           (not (get-buffer-window (current-buffer))))
-       image
-      (let* ((size (image-size image t))
-            (width (car size))
-            (height (cdr size))
-            (edges (window-inside-pixel-edges
-                    (get-buffer-window (current-buffer))))
-            (window-width (truncate (* shr-max-image-proportion
-                                       (- (nth 2 edges) (nth 0 edges)))))
-            (window-height (truncate (* shr-max-image-proportion
-                                        (- (nth 3 edges) (nth 1 edges)))))
-            scaled-image)
-       (when (or force
-                 (> height window-height))
-         (setq image (or (create-image data 'imagemagick t
-                                       :height window-height
-                                       :ascent 100)
-                         image))
-         (setq size (image-size image t)))
-       (when (> (car size) window-width)
-         (setq image (or
-                      (create-image data 'imagemagick t
-                                    :width window-width
-                                    :ascent 100)
-                      image)))
-       image))))
+  (if (or (not (fboundp 'imagemagick-types))
+         (not (get-buffer-window (current-buffer))))
+      (create-image data nil t :ascent 100)
+    (let ((edges (window-inside-pixel-edges
+                 (get-buffer-window (current-buffer)))))
+      (create-image
+       data 'imagemagick t
+       :ascent 100
+       :max-width (truncate (* shr-max-image-proportion
+                              (- (nth 2 edges) (nth 0 edges))))
+       :max-height (truncate (* shr-max-image-proportion
+                               (- (nth 3 edges) (nth 1 edges))))))))
 
 ;; url-cache-extract autoloads url-cache.
 (declare-function url-cache-create-filename "url-cache" (url))

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-06-23 18:18:47 +0000
+++ b/src/ChangeLog     2013-06-23 19:24:27 +0000
@@ -1,3 +1,9 @@
+2013-06-23  Lars Magne Ingebrigtsen  <address@hidden>
+
+       * image.c (compute_image_size): New function to implement
+       :max-width and :max-height.
+       (imagemagick_load_image): Use it.
+
 2013-06-23  Paul Eggert  <address@hidden>
 
        Try to avoid malloc SEGVs on Cygwin (Bug#14569).

=== modified file 'src/image.c'
--- a/src/image.c       2013-06-21 20:11:44 +0000
+++ b/src/image.c       2013-06-23 19:24:27 +0000
@@ -132,6 +132,8 @@
 static unsigned long *colors_in_color_table (int *n);
 #endif
 
+Lisp_Object QCmax_width, QCmax_height;
+
 /* Code to deal with bitmaps.  Bitmaps are referenced by their bitmap
    id, which is just an int that this section returns.  Bitmaps are
    reference counted so they can be shared among frames.
@@ -7489,6 +7491,76 @@
 #endif /* HAVE_GIF */
 
 
+static void
+compute_image_size (size_t width, size_t height,
+                   Lisp_Object spec,
+                   int *d_width, int *d_height)
+{
+  Lisp_Object value;
+  int desired_width, desired_height;
+
+  /* If width and/or height is set in the display spec assume we want
+     to scale to those values.  If either h or w is unspecified, the
+     unspecified should be calculated from the specified to preserve
+     aspect ratio.  */
+  value = image_spec_value (spec, QCwidth, NULL);
+  desired_width = (INTEGERP (value)  ? XFASTINT (value) : -1);
+  value = image_spec_value (spec, QCheight, NULL);
+  desired_height = (INTEGERP (value) ? XFASTINT (value) : -1);
+
+  if (desired_width == -1)
+    {
+      value = image_spec_value (spec, QCmax_width, NULL);
+      if (INTEGERP (value) &&
+         width > XFASTINT (value))
+       {
+         /* The image is wider than :max-width. */
+         desired_width = XFASTINT (value);
+         if (desired_height == -1)
+           {
+             value = image_spec_value (spec, QCmax_height, NULL);
+             if (INTEGERP (value))
+               {
+                 /* We have no specified height, but we have a
+                    :max-height value, so check that we satisfy both
+                    conditions. */
+                 desired_height = (double) desired_width / width * height;
+                 if (desired_height > XFASTINT (value))
+                   {
+                     desired_height = XFASTINT (value);
+                     desired_width = (double) desired_height / height * width;
+                   }
+               }
+             else
+               {
+                 /* We have no specified height and no specified
+                    max-height, so just compute the height. */
+                 desired_height = (double) desired_width / width * height;
+               }
+           }
+       }
+    }
+
+  if (desired_height == -1)
+    {
+      value = image_spec_value (spec, QCmax_height, NULL);
+      if (INTEGERP (value) &&
+         height > XFASTINT (value))
+         desired_height = XFASTINT (value);
+    }
+
+  if (desired_width != -1 && desired_height == -1)
+    /* w known, calculate h.  */
+    desired_height = (double) desired_width / width * height;
+
+  if (desired_width == -1 && desired_height != -1)
+    /* h known, calculate w.  */
+    desired_width = (double) desired_height / height * width;
+
+  *d_width = desired_width;
+  *d_height = desired_height;
+}
+
 /***********************************************************************
                                 ImageMagick
 ***********************************************************************/
@@ -7516,6 +7588,8 @@
     IMAGEMAGICK_BACKGROUND,
     IMAGEMAGICK_HEIGHT,
     IMAGEMAGICK_WIDTH,
+    IMAGEMAGICK_MAX_HEIGHT,
+    IMAGEMAGICK_MAX_WIDTH,
     IMAGEMAGICK_ROTATION,
     IMAGEMAGICK_CROP,
     IMAGEMAGICK_LAST
@@ -7538,6 +7612,8 @@
     {":background",    IMAGE_STRING_OR_NIL_VALUE,              0},
     {":height",                IMAGE_INTEGER_VALUE,                    0},
     {":width",         IMAGE_INTEGER_VALUE,                    0},
+    {":max-height",    IMAGE_INTEGER_VALUE,                    0},
+    {":max-width",     IMAGE_INTEGER_VALUE,                    0},
     {":rotation",      IMAGE_NUMBER_VALUE,                     0},
     {":crop",          IMAGE_DONT_CHECK_VALUE_TYPE,            0}
   };
@@ -7726,24 +7802,10 @@
     PixelSetBlue  (bg_wand, (double) bgcolor.blue  / 65535);
   }
 
-  /* If width and/or height is set in the display spec assume we want
-     to scale to those values.  If either h or w is unspecified, the
-     unspecified should be calculated from the specified to preserve
-     aspect ratio.  */
-  value = image_spec_value (img->spec, QCwidth, NULL);
-  desired_width = (INTEGERP (value)  ? XFASTINT (value) : -1);
-  value = image_spec_value (img->spec, QCheight, NULL);
-  desired_height = (INTEGERP (value) ? XFASTINT (value) : -1);
-
-  height = MagickGetImageHeight (image_wand);
-  width = MagickGetImageWidth (image_wand);
-
-  if (desired_width != -1 && desired_height == -1)
-    /* w known, calculate h.  */
-    desired_height = (double) desired_width / width * height;
-  if (desired_width == -1 && desired_height != -1)
-    /* h known, calculate w.  */
-    desired_width = (double) desired_height / height * width;
+  compute_image_size (MagickGetImageWidth (image_wand),
+                     MagickGetImageHeight (image_wand),
+                     img->spec, &desired_width, &desired_height);
+
   if (desired_width != -1 && desired_height != -1)
     {
       status = MagickScaleImage (image_wand, desired_width, desired_height);
@@ -8895,6 +8957,8 @@
   DEFSYM (Qheuristic, "heuristic");
 
   DEFSYM (Qpostscript, "postscript");
+  DEFSYM (QCmax_width, ":max-width");
+  DEFSYM (QCmax_height, ":max-height");
 #ifdef HAVE_GHOSTSCRIPT
   ADD_IMAGE_TYPE (Qpostscript);
   DEFSYM (QCloader, ":loader");


reply via email to

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