diff options
| author | Joakim Verona | 2010-06-17 09:44:04 +0200 |
|---|---|---|
| committer | Joakim Verona | 2010-06-17 09:44:04 +0200 |
| commit | bdf6a35df3d00c5fcf400176eac74fda86b3307a (patch) | |
| tree | e72600b4473cc3521ab9cb4df70342c2dfa8ba71 | |
| parent | f663e78443d5fc1904c63e58df076d1b569499d5 (diff) | |
| download | emacs-bdf6a35df3d00c5fcf400176eac74fda86b3307a.tar.gz emacs-bdf6a35df3d00c5fcf400176eac74fda86b3307a.zip | |
improved lisp interface to scaling, doc changed acordingly
| -rw-r--r-- | README.imagemagick | 56 | ||||
| -rw-r--r-- | src/image.c | 43 |
2 files changed, 81 insertions, 18 deletions
diff --git a/README.imagemagick b/README.imagemagick index a4910d212ee..ff1831e8c8f 100644 --- a/README.imagemagick +++ b/README.imagemagick | |||
| @@ -76,9 +76,41 @@ This means imagemagick will be used also to load jpeg files, if you | |||
| 76 | have both jpeg and imagemagick libraries linked. Add 'JPG to | 76 | have both jpeg and imagemagick libraries linked. Add 'JPG to |
| 77 | imagemagick-types-inhibit if you do not want this. | 77 | imagemagick-types-inhibit if you do not want this. |
| 78 | 78 | ||
| 79 | imagemagick-render-type is a new variable which can be set to choose | ||
| 80 | between screen render methods. | ||
| 81 | |||
| 82 | - 0 is a conservative metod which works with older ImageMagick | ||
| 83 | versions. It is a bit slow, but robust. | ||
| 84 | |||
| 85 | - 1 utilizes a newer ImageMagick method | ||
| 86 | |||
| 87 | |||
| 79 | Images loaded with imagemagick will support a couple of new display | 88 | Images loaded with imagemagick will support a couple of new display |
| 80 | specifications: | 89 | specification behaviours: |
| 90 | |||
| 91 | - if the :width and :height keywords are specified, these values are | ||
| 92 | used for scaling the image. If only one of :width or :height is | ||
| 93 | specified, the other one will be calculated so as to preserve the | ||
| 94 | aspect ratio.If both :width and :height are specified, aspect ratio | ||
| 95 | will not be preserved. | ||
| 96 | |||
| 97 | - :rotation specifies a rotation angle in degrees. | ||
| 98 | |||
| 99 | - :index specifies which image inside an image bundle file format, such | ||
| 100 | as TIFF or DJVM, to view. | ||
| 101 | |||
| 102 | The image-metadata function can be used to retrieve the total number | ||
| 103 | of images in an image bundle. This is simmilar to how GIF files work. | ||
| 104 | |||
| 105 | - :crop is used to specify a croping area: (width height x y). This | ||
| 106 | is similar to the slice image specification, but has a different | ||
| 107 | purpose. :crop removes the croped areas from memory, so its memory | ||
| 108 | efficient if you only need to view a certain part of the image. The | ||
| 109 | slice specification can be used to pick diferent parts of the same | ||
| 110 | image, so its more disk and display efficient. | ||
| 111 | |||
| 81 | 112 | ||
| 113 | * experimental | ||
| 82 | - :geometry takes a geometry string as defined by ImageMagick: | 114 | - :geometry takes a geometry string as defined by ImageMagick: |
| 83 | 115 | ||
| 84 | scale% | 116 | scale% |
| @@ -96,24 +128,12 @@ area@ | |||
| 96 | 128 | ||
| 97 | See the ImageMagick manual for more information. | 129 | See the ImageMagick manual for more information. |
| 98 | 130 | ||
| 99 | Furthermore, if the :width and :height keywords are specified, these | 131 | - :crop is used to specify a croping area, with the "{size}{offset}" syntax. |
| 100 | values are used for scaling the image. | ||
| 101 | |||
| 102 | - :rotation specifies a rotation angle in degrees. | ||
| 103 | |||
| 104 | - :index specifies which image inside an image bundle file format, such | ||
| 105 | as TIFF or DJVM, to view. | ||
| 106 | |||
| 107 | The image-metadata function can be used to retrieve the total number | ||
| 108 | of images in an image bundle. This is simmilar to how GIF files work. | ||
| 109 | |||
| 110 | - :crop is used to specify a croping area, with the {size}{offset} | ||
| 111 | syntax. This is similar to the slice image specification, but has a | ||
| 112 | different purpose. :crop removes the croped areas from memory, so its | ||
| 113 | memory efficient if you only need to view a certain part of the | ||
| 114 | image. :slice can be used to pick diferent parts of the same image, so | ||
| 115 | its more disk and display efficient. | ||
| 116 | 132 | ||
| 133 | :geometry and :crop with a string argument, are both particular to | ||
| 134 | ImageMagick, whereas the lisp interface is more general. Currently it | ||
| 135 | seems like the lisp interface is good enough, so the string argument | ||
| 136 | interface will probably be removed. | ||
| 117 | 137 | ||
| 118 | * Changelog entry | 138 | * Changelog entry |
| 119 | 2010-06-12 Joakim Verona <joakim@verona.se> | 139 | 2010-06-12 Joakim Verona <joakim@verona.se> |
diff --git a/src/image.c b/src/image.c index 4b4eb4e1c2e..7c6f5645097 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -7739,6 +7739,21 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7739 | desired_width = (INTEGERP (value) ? XFASTINT (value) : -1); | 7739 | desired_width = (INTEGERP (value) ? XFASTINT (value) : -1); |
| 7740 | value = image_spec_value (img->spec, QCheight, NULL); | 7740 | value = image_spec_value (img->spec, QCheight, NULL); |
| 7741 | desired_height = (INTEGERP (value) ? XFASTINT (value) : -1); | 7741 | desired_height = (INTEGERP (value) ? XFASTINT (value) : -1); |
| 7742 | /* TODO if h or w is left out, it should be calculated to preserve aspect ratio */ | ||
| 7743 | /* get original w and h, these will be recalculated before final blit*/ | ||
| 7744 | height = MagickGetImageHeight (image_wand); | ||
| 7745 | width = MagickGetImageWidth (image_wand); | ||
| 7746 | |||
| 7747 | if(desired_width != -1 && desired_height == -1) | ||
| 7748 | { | ||
| 7749 | /* w known, calculate h*/ | ||
| 7750 | desired_height = ( (double)desired_width / width ) * height; | ||
| 7751 | } | ||
| 7752 | if(desired_width == -1 && desired_height != -1) | ||
| 7753 | { | ||
| 7754 | /* h known, calculate w*/ | ||
| 7755 | desired_width = ( (double)desired_height / height ) * width; | ||
| 7756 | } | ||
| 7742 | if(desired_width != -1 && desired_height != -1) | 7757 | if(desired_width != -1 && desired_height != -1) |
| 7743 | { | 7758 | { |
| 7744 | printf("MagickScaleImage %d %d\n", desired_width, desired_height); | 7759 | printf("MagickScaleImage %d %d\n", desired_width, desired_height); |
| @@ -7754,6 +7769,33 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7754 | 7769 | ||
| 7755 | crop = image_spec_value (img->spec, QCcrop, NULL); | 7770 | crop = image_spec_value (img->spec, QCcrop, NULL); |
| 7756 | geometry = image_spec_value (img->spec, QCgeometry, NULL); | 7771 | geometry = image_spec_value (img->spec, QCgeometry, NULL); |
| 7772 | |||
| 7773 | if(CONSP (crop)) | ||
| 7774 | { | ||
| 7775 | /* TODO test if MagickCropImage is more efficient than MagickTransformImage | ||
| 7776 | |||
| 7777 | idea: crop can be a list or a string. if its a string, do | ||
| 7778 | "magicktransformimage" as before. if its a list, try MagickCropImage. | ||
| 7779 | args should be somewhat compatible with "slice". | ||
| 7780 | `(slice X Y WIDTH HEIGHT)' | ||
| 7781 | |||
| 7782 | after some testing, it seems cropping is indeed faster this | ||
| 7783 | way, but its early days still. this crop function seems to do | ||
| 7784 | less copying, but it still reads the entire image into memory | ||
| 7785 | before croping, which is aparently difficult to avoid when using imagemagick. | ||
| 7786 | |||
| 7787 | also this interface is better because it is lisp based and not IM specific | ||
| 7788 | */ | ||
| 7789 | |||
| 7790 | int w,h,x,y; | ||
| 7791 | w=XFASTINT(XCAR(crop)); | ||
| 7792 | h=XFASTINT(XCAR(XCDR(crop))); | ||
| 7793 | x=XFASTINT(XCAR(XCDR(XCDR(crop)))); | ||
| 7794 | y=XFASTINT(XCAR(XCDR(XCDR(XCDR(crop))))); | ||
| 7795 | printf("MagickCropImage(image_wand, %d,%d, %d,%d)\n", w, h, x, y); | ||
| 7796 | MagickCropImage(image_wand, w,h, x,y); | ||
| 7797 | } | ||
| 7798 | |||
| 7757 | if (STRINGP (crop) && STRINGP (geometry)) | 7799 | if (STRINGP (crop) && STRINGP (geometry)) |
| 7758 | { | 7800 | { |
| 7759 | printf("MagickTransformImage %s %s\n", SDATA(crop), SDATA(geometry)); | 7801 | printf("MagickTransformImage %s %s\n", SDATA(crop), SDATA(geometry)); |
| @@ -7762,6 +7804,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7762 | /* TODO differ between image_wand and transform_wand. */ | 7804 | /* TODO differ between image_wand and transform_wand. */ |
| 7763 | } | 7805 | } |
| 7764 | 7806 | ||
| 7807 | |||
| 7765 | /* Furthermore :rotation. we need background color and angle for | 7808 | /* Furthermore :rotation. we need background color and angle for |
| 7766 | rotation. */ | 7809 | rotation. */ |
| 7767 | /* | 7810 | /* |