[mew-dist 27223] Re: 大きな写真

Tetsuya Toda toda at example.com
2006年 8月 17日 (木) 23:52:25 JST


From: Kazu Yamamoto (山本和彦) <kazu at example.com>
Date: Thu, 17 Aug 2006 13:58:45 +0900 (JST)

> > > フレームの高さは取れますが、メッセージバッファの高さは取れません。
> 
> default 文字の縦と横を計算し、ウインドウの文字数を掛けるという算出
> 方法があります。
> 
> Goby の goby-width-height 関数を見て頂くと分かると思います。
> とっても、複雑で、全ての環境を網羅できているか自信がありません。
....(略)....
> それでも、これを導入しますか?

  直感的に難しそうに感じますので,現時点では各自が各自の環
境にあわせて設定するので良いと思います.emacs 側で関数が提
供されると良いですね.

> 実装方法ですが、width と height の関数を分けるのではなく、
> (width height) というリストを返すようにすべきだと思います。
> そうすれば、コードを共通にできます。
> 関数名は、適当に変えて頂いて構いません。

  適当にしてみました(添付パッチ).

#先のものは GIF のバイトオーダー間違えていたり,png のオフ
#セット間違えていたりしていたので,これらの修正もしています.

戸田哲也 =^^=
-------------- next part --------------
*** mew-gemacs.el.orig	Thu Aug 16 16:42:04 2006
--- mew-gemacs.el	Thu Aug 17 23:38:28 2006
***************
*** 138,145 ****
    ;; display-graphic-p
    (and window-system (image-type-available-p format)))
  
! (defun mew-jpeg-width ()
!   (let (c size width)
      (save-excursion
        (catch 'loop
  	(while t
--- 138,145 ----
    ;; display-graphic-p
    (and window-system (image-type-available-p format)))
  
! (defun mew-jpeg-size ()
!   (let (c size width height)
      (save-excursion
        (catch 'loop
  	(while t
***************
*** 150,178 ****
  	  (setq c (char-after))
  	  (forward-char)
  	  (cond
! 	   ((eq c #xd8)
  	    )
! 	   ((eq c #xe0)
! 	    (forward-char 16))
! 	   ((or (eq c #xdb) (eq c #xc4)
! 		(and (>= c #xe0) (<= c #xed)))
! 	    (setq size (char-after))
  	    (forward-char)
! 	    (setq size (+ (* size 256) (char-after)))
  	    (forward-char)
- 	    (forward-char (- size 2)))
- 	   ((eq c #xc0)
- 	    (forward-char 5)
  	    (setq width (char-after))
  	    (forward-char)
  	    (setq width (+ (* width 256) (char-after)))
  	    (throw 'loop nil))
  	   (t
  	    (throw 'loop nil))))))
!     width))
  
! (defun mew-png-width ()
!   (let (width)
      (save-excursion
        (forward-char 18)
        ;; length is four bytes
--- 150,181 ----
  	  (setq c (char-after))
  	  (forward-char)
  	  (cond
! 	   ((or (eq c #xd8)                    ;SOI
! 		(eq c #xd9)                    ;EOI
! 		(and (>= c #xd0) (<= c #xd7))) ;RSTm
  	    )
! 	   ((eq c #xc0)
! 	    (forward-char 3)
! 	    (setq height (char-after))
  	    (forward-char)
! 	    (setq height (+ (* height 256) (char-after)))
  	    (forward-char)
  	    (setq width (char-after))
  	    (forward-char)
  	    (setq width (+ (* width 256) (char-after)))
  	    (throw 'loop nil))
+ 	   ((and (>= c #xc1) (<= c #xfe))
+ 	    (setq size (char-after))
+ 	    (forward-char)
+ 	    (setq size (+ (* size 256) (char-after)))
+ 	    (forward-char)
+ 	    (forward-char (- size 2)))
  	   (t
  	    (throw 'loop nil))))))
!     (cons width height)))
  
! (defun mew-png-size ()
!   (let (width height)
      (save-excursion
        (forward-char 18)
        ;; length is four bytes
***************
*** 180,192 ****
        (setq width (char-after))
        (forward-char)
        (setq width (+ (* width 256) (char-after)))
!       width)))
  
  (defvar mew-image-width-margin 45)
  
  (defvar mew-image-alist
!   '((jpeg "jpegtopnm" mew-jpeg-width)
!     (png  "pngtopnm"  mew-png-width)))
  
  (defun mew-image-format-ent (format)
    (assoc format mew-image-alist))
--- 183,214 ----
        (setq width (char-after))
        (forward-char)
        (setq width (+ (* width 256) (char-after)))
!       (forward-char 3)
!       (setq height (char-after))
!       (forward-char)
!       (setq height (+ (* height 256) (char-after)))
!       (cons width height))))
! 
! (defun mew-gif-size ()
!   (let (width height)
!     (save-excursion
!       (forward-char 6)
!       (setq width (char-after))
!       (forward-char)
!       (setq width (+ width (* (char-after) 256)))
!       (forward-char)
!       (setq height (char-after))
!       (forward-char)
!       (setq height (+ height (* (char-after) 256)))
!       (cons width height))))
  
  (defvar mew-image-width-margin 45)
+ (defvar mew-image-height-margin 200)
  
  (defvar mew-image-alist
!   '((jpeg "jpegtopnm" mew-jpeg-size)
!     (png  "pngtopnm"  mew-png-size)
!     (gif  "giftopnm"  mew-gif-size)))
  
  (defun mew-image-format-ent (format)
    (assoc format mew-image-alist))
***************
*** 194,216 ****
  (defun mew-image-get-prog (ent)
    (nth 1 ent))
  
! (defun mew-image-get-func (ent)
    (nth 2 ent))
  
  (defun mew-mime-image (cache begin end format)
    (message "Loading image...")
    (set-buffer (mew-buffer-message))
    (let* ((width (- (frame-pixel-width (selected-frame)) mew-image-width-margin))
  	 (ent (mew-image-format-ent format))
  	 (prog (mew-image-get-prog ent))
! 	 (func (mew-image-get-func ent))
! 	 image-width image)
!     (when (and func (fboundp func))
        (save-excursion
  	(set-buffer cache)
  	(goto-char begin)
! 	(setq image-width (funcall func))))
!     (if (and image-width (< width image-width) (mew-which-exec prog))
  	(with-temp-buffer
  	  (message "Resizing image...")
  	  (insert-buffer-substring cache begin end)
--- 216,242 ----
  (defun mew-image-get-prog (ent)
    (nth 1 ent))
  
! (defun mew-image-get-func-size (ent)
    (nth 2 ent))
  
  (defun mew-mime-image (cache begin end format)
    (message "Loading image...")
    (set-buffer (mew-buffer-message))
    (let* ((width (- (frame-pixel-width (selected-frame)) mew-image-width-margin))
+ 	 (height (- (frame-pixel-height (selected-frame)) mew-image-height-margin))
  	 (ent (mew-image-format-ent format))
  	 (prog (mew-image-get-prog ent))
! 	 (func-size (mew-image-get-func-size ent))
! 	 image-width image-height image)
!     (when (or (and func-size (fboundp func-size)))
        (save-excursion
  	(set-buffer cache)
  	(goto-char begin)
! 	(setq image-width (car (funcall func-size)))
! 	(setq image-height (cdr (funcall func-size)))))
!     (if (and image-width image-height
! 	     (or (< width image-width) (< height image-height))
! 	     (mew-which-exec prog))
  	(with-temp-buffer
  	  (message "Resizing image...")
  	  (insert-buffer-substring cache begin end)
***************
*** 219,225 ****
  			       t '(t nil) nil)
  	  (call-process-region (point-min) (point-max) "pnmscale"
  			       t '(t nil) nil
! 			       "-xsize" (format "%d" width))
  	  (setq format 'pbm)
  	  (setq image (mew-buffer-substring (point-min) (point-max)))
  	  (message "Resizing image...done"))
--- 245,253 ----
  			       t '(t nil) nil)
  	  (call-process-region (point-min) (point-max) "pnmscale"
  			       t '(t nil) nil
! 			       "-xysize"
! 				(format "%d" width)
! 				(format "%d" height))
  	  (setq format 'pbm)
  	  (setq image (mew-buffer-substring (point-min) (point-max)))
  	  (message "Resizing image...done"))


Mew-dist メーリングリストの案内