improved lisp interface to scaling, doc changed acordingly
authorJoakim Verona <joakim@verona.se>
Thu, 17 Jun 2010 07:44:04 +0000 (09:44 +0200)
committerJoakim Verona <joakim@verona.se>
Thu, 17 Jun 2010 07:44:04 +0000 (09:44 +0200)
README.imagemagick
src/image.c

index a4910d2..ff1831e 100644 (file)
@@ -76,9 +76,41 @@ This means imagemagick will be used also to load jpeg files, if you
 have both jpeg and imagemagick libraries linked. Add 'JPG to
 imagemagick-types-inhibit if you do not want this.
 
+imagemagick-render-type is a new variable which can be set to choose
+between screen render methods.
+
+- 0 is a conservative metod which works with older ImageMagick
+  versions. It is a bit slow, but robust.
+
+- 1 utilizes a newer ImageMagick method   
+
+
 Images loaded with imagemagick will support a couple of new display
-specifications:
+specification behaviours:
+
+- if the :width and :height keywords are specified, these values are
+used for scaling the image. If only one of :width or :height is
+specified, the other one will be calculated so as to preserve the
+aspect ratio.If both :width and :height are specified, aspect ratio
+will not be preserved.
+
+- :rotation specifies a rotation angle in degrees.
+
+- :index specifies which image inside an image bundle file format, such
+as TIFF or DJVM, to view.
+
+The image-metadata function can be used to retrieve the total number
+of images in an image bundle. This is simmilar to how GIF files work.
+
+- :crop is used to specify a croping area: (width height x y).  This
+is similar to the slice image specification, but has a different
+purpose. :crop removes the croped areas from memory, so its memory
+efficient if you only need to view a certain part of the image. The
+slice specification can be used to pick diferent parts of the same
+image, so its more disk and display efficient.
+
 
+* experimental
 - :geometry takes a geometry string as defined by ImageMagick:
 
 scale%            
@@ -96,24 +128,12 @@ area@
 
 See the ImageMagick manual for more information.
 
-Furthermore, if the :width and :height keywords are specified, these
-values are used for scaling the image.
-
-- :rotation specifies a rotation angle in degrees.
-
-- :index specifies which image inside an image bundle file format, such
-as TIFF or DJVM, to view.
-
-The image-metadata function can be used to retrieve the total number
-of images in an image bundle. This is simmilar to how GIF files work.
-
-- :crop is used to specify a croping area, with the {size}{offset}
-syntax.  This is similar to the slice image specification, but has a
-different purpose. :crop removes the croped areas from memory, so its
-memory efficient if you only need to view a certain part of the
-image. :slice can be used to pick diferent parts of the same image, so
-its more disk and display efficient.
+- :crop is used to specify a croping area, with the "{size}{offset}" syntax.
 
+:geometry and :crop with a string argument, are both particular to
+ImageMagick, whereas the lisp interface is more general. Currently it
+seems like the lisp interface is good enough, so the string argument
+interface will probably be removed.
 
 * Changelog entry
 2010-06-12 Joakim Verona <joakim@verona.se>
index 4b4eb4e..7c6f564 100644 (file)
@@ -7739,6 +7739,21 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
   desired_width = (INTEGERP (value)  ? XFASTINT (value) : -1);
   value = image_spec_value (img->spec, QCheight, NULL);
   desired_height = (INTEGERP (value) ? XFASTINT (value) : -1);
+  /* TODO if h or w is left out, it should be calculated to preserve aspect ratio */
+  /* get original w and h, these will be recalculated before final blit*/
+  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;
+    }  
   if(desired_width != -1 && desired_height != -1)
     {
       printf("MagickScaleImage %d %d\n", desired_width, desired_height);
@@ -7754,6 +7769,33 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
 
   crop     = image_spec_value (img->spec, QCcrop, NULL);
   geometry = image_spec_value (img->spec, QCgeometry, NULL);
+
+  if(CONSP (crop))
+    {
+      /* TODO test if MagickCropImage is more efficient than MagickTransformImage
+
+         idea: crop can be a list or a string. if its a string, do
+         "magicktransformimage" as before. if its a list, try MagickCropImage.
+         args should be somewhat compatible with "slice".
+         `(slice X Y WIDTH HEIGHT)'
+
+         after some testing, it seems cropping is indeed faster this
+         way, but its early days still. this crop function seems to do
+         less copying, but it still reads the entire image into memory
+         before croping, which is aparently difficult to avoid when using imagemagick.
+
+         also this interface is better because it is lisp based and not IM specific
+      */
+      
+      int w,h,x,y;
+      w=XFASTINT(XCAR(crop));
+      h=XFASTINT(XCAR(XCDR(crop)));
+      x=XFASTINT(XCAR(XCDR(XCDR(crop))));
+      y=XFASTINT(XCAR(XCDR(XCDR(XCDR(crop)))));
+      printf("MagickCropImage(image_wand, %d,%d, %d,%d)\n", w, h, x, y);
+      MagickCropImage(image_wand, w,h, x,y);
+    }
+  
   if (STRINGP (crop) && STRINGP (geometry))
     {
       printf("MagickTransformImage %s %s\n", SDATA(crop), SDATA(geometry));
@@ -7762,6 +7804,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
       /* TODO differ between image_wand and transform_wand. */
     }
 
+  
   /* Furthermore :rotation. we need background color and angle for
      rotation.  */
   /*