# HG changeset patch # User Joakim # Date 1276760644 -7200 # Node ID 458fda2a5cffd9cddaffb2e2a00ad338d35c00cb # Parent d68f30f3aba2473ddceec0eb898c7dae2449c2e9 improved lisp interface to scaling, doc changed acordingly diff -r d68f30f3aba2 -r 458fda2a5cff README.imagemagick --- a/README.imagemagick Tue Jun 15 15:06:47 2010 +0200 +++ b/README.imagemagick Thu Jun 17 09:44:04 2010 +0200 @@ -76,9 +76,41 @@ 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 @@ 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. +- :crop is used to specify a croping area, with the "{size}{offset}" syntax. -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. - +: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 diff -r d68f30f3aba2 -r 458fda2a5cff src/image.c --- a/src/image.c Tue Jun 15 15:06:47 2010 +0200 +++ b/src/image.c Thu Jun 17 09:44:04 2010 +0200 @@ -7739,6 +7739,21 @@ 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 @@ 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 @@ /* TODO differ between image_wand and transform_wand. */ } + /* Furthermore :rotation. we need background color and angle for rotation. */ /*