aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-04-09 16:28:01 -0400
committerChong Yidong2011-04-09 16:28:01 -0400
commita32d40405d31edd2ce4349b95277306554fb54a4 (patch)
tree7b94ea7a28ae8eff395c6953d94bc86f14593ff1
parent8546720e6f25eb988e8215de6678798053031440 (diff)
downloademacs-a32d40405d31edd2ce4349b95277306554fb54a4.tar.gz
emacs-a32d40405d31edd2ce4349b95277306554fb54a4.zip
Cleanups to the ImageMagick code and docstrings.
* lisp/image-mode.el (image-toggle-display-image): Signal an error if not in Image mode. (image-transform-mode, image-transform-resize) (image-transform-set-rotation): Doc fix. (image-transform-set-resize): Deleted. (image-transform-set-scale, image-transform-fit-to-height) (image-transform-fit-to-width): Handle image-toggle-display-image and image-transform-resize directly. * src/image.c (Fimagemagick_types): Doc fix, and comment cleanup.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/image-mode.el113
-rw-r--r--src/ChangeLog4
-rw-r--r--src/image.c64
4 files changed, 102 insertions, 90 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8d705cdaed6..402b078be7b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12011-04-09 Chong Yidong <cyd@stupidchicken.com>
2
3 * image-mode.el (image-toggle-display-image): Signal an error if
4 not in Image mode.
5 (image-transform-mode, image-transform-resize)
6 (image-transform-set-rotation): Doc fix.
7 (image-transform-set-resize): Deleted.
8 (image-transform-set-scale, image-transform-fit-to-height)
9 (image-transform-fit-to-width): Handle image-toggle-display-image
10 and image-transform-resize directly.
11
12011-04-08 Sho Nakatani <lay.sakura@gmail.com> 122011-04-08 Sho Nakatani <lay.sakura@gmail.com>
2 13
3 * doc-view.el (doc-view-fit-width-to-window) 14 * doc-view.el (doc-view-fit-width-to-window)
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 64dcf9076ae..96d874dbec6 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -469,6 +469,8 @@ Remove text properties that display the image."
469 "Show the image of the image file. 469 "Show the image of the image file.
470Turn the image data into a real image, but only if the whole file 470Turn the image data into a real image, but only if the whole file
471was inserted." 471was inserted."
472 (unless (derived-mode-p 'image-mode major-mode)
473 (error "The buffer is not in Image mode"))
472 (let* ((filename (buffer-file-name)) 474 (let* ((filename (buffer-file-name))
473 (data-p (not (and filename 475 (data-p (not (and filename
474 (file-readable-p filename) 476 (file-readable-p filename)
@@ -485,8 +487,7 @@ was inserted."
485 (type (image-type file-or-data nil data-p)) 487 (type (image-type file-or-data nil data-p))
486 (image0 (create-animated-image file-or-data type data-p)) 488 (image0 (create-animated-image file-or-data type data-p))
487 (image (append image0 489 (image (append image0
488 (image-transform-properties image0) 490 (image-transform-properties image0)))
489 ))
490 (props 491 (props
491 `(display ,image 492 `(display ,image
492 intangible ,image 493 intangible ,image
@@ -557,80 +558,86 @@ the image file and `image-mode' showing the image as an image."
557 558
558(defvar image-transform-minor-mode-map 559(defvar image-transform-minor-mode-map
559 (let ((map (make-sparse-keymap))) 560 (let ((map (make-sparse-keymap)))
560; (define-key map [(control ?+)] 'image-scale-in) 561 ;; (define-key map [(control ?+)] 'image-scale-in)
561; (define-key map [(control ?-)] 'image-scale-out) 562 ;; (define-key map [(control ?-)] 'image-scale-out)
562; (define-key map [(control ?=)] 'image-scale-none) 563 ;; (define-key map [(control ?=)] 'image-scale-none)
563;; (define-key map "c f h" 'image-scale-fit-height) 564 ;; (define-key map "c f h" 'image-scale-fit-height)
564;; (define-key map "c ]" 'image-rotate-right) 565 ;; (define-key map "c ]" 'image-rotate-right)
565 map) 566 map)
566 "Minor mode keymap for transforming the view of images Image mode.") 567 "Minor mode keymap `image-transform-mode'.")
567 568
568(define-minor-mode image-transform-mode 569(define-minor-mode image-transform-mode
569 "minor mode for scaleing and rotation" 570 "Minor mode for scaling and rotating images.
570 nil "image-transform" 571This minor mode has no effect unless Emacs is compiled with
571 image-transform-minor-mode-map) 572ImageMagick support."
572 573 nil "image-transform" image-transform-minor-mode-map)
573(defvar image-transform-resize nil 574
574 "The image resize operation. See the command 575(defvar image-transform-resize nil
575 `image-transform-set-scale' for more information." ) 576 "The image resize operation.
577Its value should be one of the following:
578 - nil, meaning no resizing.
579 - `fit-height', meaning to fit the image to the window height.
580 - `fit-width', meaning to fit the image to the window width.
581 - A number, which is a scale factor (the default size is 100).")
576 582
577(defvar image-transform-rotation 0.0) 583(defvar image-transform-rotation 0.0)
578 584
579
580(defun image-transform-properties (display) 585(defun image-transform-properties (display)
581 "Calculate the display properties for transformations; scaling 586 "Rescale and/or rotate the current image.
582and rotation. " 587The scale factor and rotation angle are given by the variables
583 (let* 588`image-transform-resize' and `image-transform-rotation'. This
584 ((size (image-size display t)) 589takes effect only if Emacs is compiled with ImageMagick support."
585 (height 590 (let* ((size (image-size display t))
586 (cond 591 (height
587 ((and (numberp image-transform-resize) (eq 100 image-transform-resize)) 592 (cond
588 nil) 593 ((numberp image-transform-resize)
589 ((numberp image-transform-resize) 594 (unless (= image-transform-resize 100)
590 (* image-transform-resize (cdr size))) 595 (* image-transform-resize (cdr size))))
591 ((eq image-transform-resize 'fit-height) 596 ((eq image-transform-resize 'fit-height)
592 (- (nth 3 (window-inside-pixel-edges)) (nth 1 (window-inside-pixel-edges)))) 597 (- (nth 3 (window-inside-pixel-edges))
593 (t nil))) 598 (nth 1 (window-inside-pixel-edges))))))
594 (width (if (eq image-transform-resize 'fit-width) 599 (width (if (eq image-transform-resize 'fit-width)
595 (- (nth 2 (window-inside-pixel-edges)) (nth 0 (window-inside-pixel-edges)))))) 600 (- (nth 2 (window-inside-pixel-edges))
596 601 (nth 0 (window-inside-pixel-edges))))))
602 ;;TODO fit-to-* should consider the rotation angle
597 `(,@(if height (list :height height)) 603 `(,@(if height (list :height height))
598 ,@(if width (list :width width)) 604 ,@(if width (list :width width))
599 ,@(if (not (equal 0.0 image-transform-rotation)) 605 ,@(if (not (equal 0.0 image-transform-rotation))
600 (list :rotation image-transform-rotation)) 606 (list :rotation image-transform-rotation)))))
601 ;;TODO fit-to-* should consider the rotation angle
602 )))
603 607
604(defun image-transform-set-scale (scale) 608(defun image-transform-set-scale (scale)
605 "SCALE sets the scaling for images. " 609 "Prompt for a number, and resize the current image by that amount.
606 (interactive "nscale:") 610This command has no effect unless Emacs is compiled with
607 (image-transform-set-resize (float scale))) 611ImageMagick support."
612 (interactive "nScale: ")
613 (setq image-transform-resize resize)
614 (image-toggle-display-image))
608 615
609(defun image-transform-fit-to-height () 616(defun image-transform-fit-to-height ()
610 "Fit image height to window height. " 617 "Fit the current image to the height of the current window.
618This command has no effect unless Emacs is compiled with
619ImageMagick support."
611 (interactive) 620 (interactive)
612 (image-transform-set-resize 'fit-height)) 621 (setq image-transform-resize 'fit-height)
622 (image-toggle-display-image))
613 623
614(defun image-transform-fit-to-width () 624(defun image-transform-fit-to-width ()
615 "Fit image width to window width. " 625 "Fit the current image to the width of the current window.
626This command has no effect unless Emacs is compiled with
627ImageMagick support."
616 (interactive) 628 (interactive)
617 (image-transform-set-resize 'fit-width)) 629 (setq image-transform-resize 'fit-width)
618 630 (image-toggle-display-image))
619(defun image-transform-set-resize (resize)
620 "Set the resize mode for images. The RESIZE value can be the
621symbol fit-height which fits the image to the window height. The
622symbol fit-width fits the image to the window width. A number
623indicates a scaling factor. nil indicates scale to 100%. "
624 (setq image-transform-resize resize)
625 (if (eq 'image-mode major-mode) (image-toggle-display-image)))
626 631
627(defun image-transform-set-rotation (rotation) 632(defun image-transform-set-rotation (rotation)
628 "Set the image ROTATION angle. " 633 "Prompt for an angle ROTATION, and rotate the image by that amount.
629 (interactive "nrotation:") 634ROTATION should be in degrees. This command has no effect unless
635Emacs is compiled with ImageMagick support."
636 (interactive "nRotation angle (in degrees): ")
630 ;;TODO 0 90 180 270 degrees are the only reasonable angles here 637 ;;TODO 0 90 180 270 degrees are the only reasonable angles here
631 ;;otherwise combining with rescaling will get very awkward 638 ;;otherwise combining with rescaling will get very awkward
632 (setq image-transform-rotation (float rotation)) 639 (setq image-transform-rotation (float rotation))
633 (if (eq major-mode 'image-mode) (image-toggle-display-image))) 640 (image-toggle-display-image))
634 641
635(provide 'image-mode) 642(provide 'image-mode)
636 643
diff --git a/src/ChangeLog b/src/ChangeLog
index e7ea07705af..a1a5abe87c3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
12011-04-09 Chong Yidong <cyd@stupidchicken.com> 12011-04-09 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * image.c (Fimagemagick_types): Doc fix, and comment cleanup.
4
52011-04-09 Chong Yidong <cyd@stupidchicken.com>
6
3 * ftfont.c (get_adstyle_property, ftfont_pattern_entity): Use 7 * ftfont.c (get_adstyle_property, ftfont_pattern_entity): Use
4 unsigned char, to match FcChar8 type definition. 8 unsigned char, to match FcChar8 type definition.
5 9
diff --git a/src/image.c b/src/image.c
index 260bc6eb260..b3d2be88b96 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7370,14 +7370,13 @@ gif_load (struct frame *f, struct image *img)
7370 7370
7371 7371
7372/*********************************************************************** 7372/***********************************************************************
7373 imagemagick 7373 ImageMagick
7374***********************************************************************/ 7374***********************************************************************/
7375#if defined (HAVE_IMAGEMAGICK) 7375#if defined (HAVE_IMAGEMAGICK)
7376 7376
7377/* The symbol `imagemagick' identifying images of this type. */
7378
7379Lisp_Object Qimagemagick; 7377Lisp_Object Qimagemagick;
7380/* Indices of image specification fields in imagemagick_format, below. */ 7378
7379/* Indices of image specification fields in imagemagick_format. */
7381 7380
7382enum imagemagick_keyword_index 7381enum imagemagick_keyword_index
7383 { 7382 {
@@ -7418,6 +7417,7 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7418 {":rotation", IMAGE_NUMBER_VALUE, 0}, 7417 {":rotation", IMAGE_NUMBER_VALUE, 0},
7419 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} 7418 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
7420 }; 7419 };
7420
7421/* Free X resources of imagemagick image IMG which is used on frame F. */ 7421/* Free X resources of imagemagick image IMG which is used on frame F. */
7422 7422
7423static void 7423static void
@@ -7427,8 +7427,6 @@ imagemagick_clear_image (struct frame *f,
7427 x_clear_image (f, img); 7427 x_clear_image (f, img);
7428} 7428}
7429 7429
7430
7431
7432/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do 7430/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do
7433 this by calling parse_image_spec and supplying the keywords that 7431 this by calling parse_image_spec and supplying the keywords that
7434 identify the IMAGEMAGICK format. */ 7432 identify the IMAGEMAGICK format. */
@@ -7457,7 +7455,7 @@ imagemagick_image_p (Lisp_Object object)
7457 7455
7458 Uses librimagemagick to do most of the image processing. 7456 Uses librimagemagick to do most of the image processing.
7459 7457
7460 non-zero when successful. 7458 Return non-zero if successful.
7461*/ 7459*/
7462 7460
7463static int 7461static int
@@ -7504,12 +7502,12 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
7504 Image * im_image; 7502 Image * im_image;
7505 7503
7506 7504
7507 /* Handle image index for image types who can contain more than one 7505 /* Handle image index for image types who can contain more than one image.
7508 image. Interface :index is same as for GIF. First we "ping" the 7506 Interface :index is same as for GIF. First we "ping" the image to see how
7509 image to see how many sub-images it contains. Pinging is faster 7507 many sub-images it contains. Pinging is faster than loading the image to
7510 than loading the image to find out things about it. */ 7508 find out things about it. */
7511 7509
7512 /* `MagickWandGenesis' initializes the imagemagick environment. */ 7510 /* Initialize the imagemagick environment. */
7513 MagickWandGenesis (); 7511 MagickWandGenesis ();
7514 image = image_spec_value (img->spec, QCindex, NULL); 7512 image = image_spec_value (img->spec, QCindex, NULL);
7515 ino = INTEGERP (image) ? XFASTINT (image) : 0; 7513 ino = INTEGERP (image) ? XFASTINT (image) : 0;
@@ -7541,7 +7539,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
7541 DestroyMagickWand (ping_wand); 7539 DestroyMagickWand (ping_wand);
7542 7540
7543 /* Now, after pinging, we know how many images are inside the 7541 /* Now, after pinging, we know how many images are inside the
7544 file. If its not a bundle, just one. */ 7542 file. If it's not a bundle, the number is one. */
7545 7543
7546 if (filename != NULL) 7544 if (filename != NULL)
7547 { 7545 {
@@ -7572,7 +7570,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
7572 if (status == MagickFalse) goto imagemagick_error; 7570 if (status == MagickFalse) goto imagemagick_error;
7573 7571
7574 /* If width and/or height is set in the display spec assume we want 7572 /* If width and/or height is set in the display spec assume we want
7575 to scale to those values. if either h or w is unspecified, the 7573 to scale to those values. If either h or w is unspecified, the
7576 unspecified should be calculated from the specified to preserve 7574 unspecified should be calculated from the specified to preserve
7577 aspect ratio. */ 7575 aspect ratio. */
7578 7576
@@ -7584,17 +7582,13 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
7584 height = MagickGetImageHeight (image_wand); 7582 height = MagickGetImageHeight (image_wand);
7585 width = MagickGetImageWidth (image_wand); 7583 width = MagickGetImageWidth (image_wand);
7586 7584
7587 if(desired_width != -1 && desired_height == -1) 7585 if (desired_width != -1 && desired_height == -1)
7588 { 7586 /* w known, calculate h. */
7589 /* w known, calculate h. */ 7587 desired_height = (double) desired_width / width * height;
7590 desired_height = (double) desired_width / width * height; 7588 if (desired_width == -1 && desired_height != -1)
7591 } 7589 /* h known, calculate w. */
7592 if(desired_width == -1 && desired_height != -1) 7590 desired_width = (double) desired_height / height * width;
7593 { 7591 if (desired_width != -1 && desired_height != -1)
7594 /* h known, calculate w. */
7595 desired_width = (double) desired_height / height * width;
7596 }
7597 if(desired_width != -1 && desired_height != -1)
7598 { 7592 {
7599 status = MagickScaleImage (image_wand, desired_width, desired_height); 7593 status = MagickScaleImage (image_wand, desired_width, desired_height);
7600 if (status == MagickFalse) 7594 if (status == MagickFalse)
@@ -7604,19 +7598,17 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
7604 } 7598 }
7605 } 7599 }
7606 7600
7607
7608 /* crop behaves similar to image slicing in Emacs but is more memory 7601 /* crop behaves similar to image slicing in Emacs but is more memory
7609 efficient. */ 7602 efficient. */
7610 crop = image_spec_value (img->spec, QCcrop, NULL); 7603 crop = image_spec_value (img->spec, QCcrop, NULL);
7611 7604
7612 if (CONSP (crop) && INTEGERP (XCAR (crop))) 7605 if (CONSP (crop) && INTEGERP (XCAR (crop)))
7613 { 7606 {
7614 /* After some testing, it seems MagickCropImage is the fastest 7607 /* After some testing, it seems MagickCropImage is the fastest crop
7615 crop function in ImageMagick. This crop function seems to do 7608 function in ImageMagick. This crop function seems to do less copying
7616 less copying than the alternatives, but it still reads the 7609 than the alternatives, but it still reads the entire image into memory
7617 entire image into memory before croping, which is aparently 7610 before croping, which is aparently difficult to avoid when using
7618 difficult to avoid when using imagemagick. */ 7611 imagemagick. */
7619
7620 int w, h, x, y; 7612 int w, h, x, y;
7621 w = XFASTINT (XCAR (crop)); 7613 w = XFASTINT (XCAR (crop));
7622 crop = XCDR (crop); 7614 crop = XCDR (crop);
@@ -7877,12 +7869,10 @@ static struct image_type imagemagick_type =
7877 }; 7869 };
7878 7870
7879 7871
7880
7881
7882DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, 7872DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0,
7883 doc: /* Return image file types supported by ImageMagick. 7873 doc: /* Return the image types supported by ImageMagick.
7884Since ImageMagick recognizes a lot of file-types that clash with Emacs, 7874Note that ImageMagick recognizes many file-types that Emacs does not recognize
7885such as .c, we want to be able to alter the list at the lisp level. */) 7875as images, such as .c. */)
7886 (void) 7876 (void)
7887{ 7877{
7888 Lisp_Object typelist = Qnil; 7878 Lisp_Object typelist = Qnil;