From xemacs-m  Thu Sep 25 19:07:06 1997
Received: from altair.xemacs.org (steve@xemacs.miranova.com [206.190.83.19])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id TAA06039
	for <xemacs-beta@xemacs.org>; Thu, 25 Sep 1997 19:07:04 -0500 (CDT)
Received: (from steve@localhost)
	by altair.xemacs.org (8.8.7/8.8.7) id RAA02758;
	Thu, 25 Sep 1997 17:13:09 -0700
Mail-Copies-To: never
To: xemacs-beta@xemacs.org
Subject: [PATCH] Re: Are jpegs in 19.16 working for anyone?
References: <m2lo0lrqdz.fsf@altair.xemacs.org> <QQdipa07848.199709252338@crystal.WonderWorks.COM>
X-Face: (:YAD@JS'&Kz'M}n7eX7gEvPR6U1mJ-kt;asEc2qAv;h{Yw7ckz<7+X_SYeTNAaPui:e~x$
 ,A=gkt*>UPL/}\a/#C~v2%ETiAY_sx;xve0yL??JWTtX_-NUzXyP38UdW#cmN1\4(X!c3m#%IbtB-3
 Z-!xpZi!`E.s{(;aP=b11"!3wQu]1j@^V|;n=B|{l<bZV1.AI`zWV%kPCnUhcgEe\(}/_kNd6,*3ZJ
 Q3o<YQ3^u;7jS=:p0--u3msQO
X-Attribution: sb
From: SL Baur <steve@xemacs.org>
In-Reply-To: Kyle Jones's message of "Thu, 25 Sep 1997 19:38:44 -0400 (EDT)"
Mime-Version: 1.0 (generated by tm-edit 7.108)
Content-Type: multipart/mixed;
 boundary="Multipart_Thu_Sep_25_17:13:08_1997-1"
Content-Transfer-Encoding: 7bit
Date: 25 Sep 1997 17:13:09 -0700
Message-ID: <m2yb4lq6ei.fsf_-_@altair.xemacs.org>
Lines: 151
X-Mailer: Quassia Gnus v0.10/XEmacs 20.3(beta24) - "Ljubljana"

--Multipart_Thu_Sep_25_17:13:08_1997-1
Content-Type: text/plain; charset=US-ASCII

Kyle Jones <kyle_jones@wonderworks.com> writes:

> SL Baur writes:
>> I've had some reports of problems with jpeg images in 19.16 and they
>> don't appear to work very well on my test build.

> JPEGs seem to have type bits in them.  I've seen XV recognize a
> JPEG but then claim there is an unsupported something-or-the-other
> in it and not be able to display it.  Maybe this is what is causing
> our display code to fail.  I am not an image guru.

I've found some bad code in the jpeg autodetection (the wrong magic
number was being specified for jpeg).  If you are loading an image
into a buffer and expecting the XEmacs glyph code to correctly
recognize it as a jpeg, you will lose.  Presumably this is what VM is
doing.

Everything was O.K. in the code Darryl posted because he was bypassing 
the jpeg autodetection and specifying the image type.

Here is some simple test code, and the patch to XEmacs 19.16 to make
it work.  Load the attachment into XEmacs after extraction `(load
"/tmp/glyph-utils.el")' in *scratch*.  Then do `M-x insert-glyph-at-point'
and supply the name of a convenient jpeg file.

This code fails for me in stock 20.2 and 19.16, but *not 20.3* even
though 20.3 contains the same bogus jpeg magic number.


--Multipart_Thu_Sep_25_17:13:08_1997-1
Content-Type: application/octet-stream; type=emacs-lisp
Content-Disposition: attachment; filename="glyph-utils.el"
Content-Transfer-Encoding: 7bit

(defun show-glyphs ()
  "List glyphs in the current buffer."
  (interactive)
  (with-output-to-temp-buffer "*Show Glyphs*"
    (map-extents
     (lambda (e dummy)
       (let ((gl))
	 (when (setq gl (extent-begin-glyph e))
	   (pp gl))
	 (when (setq gl (extent-end-glyph e))
	   (pp gl)))))))

(defun insert-glyph-at-point (file)
  "Insert a glyph at (point)."
  (interactive "*fGraphic Image: ")
  (save-excursion
    (save-restriction
      (let ((file-coding-system-for-read  'binary)
	    gl e)
	(narrow-to-region (point) (point))
	(insert-file-contents file)
	(setq gl (make-glyph (buffer-substring (point-min) (point-max))))
	(delete-region (point-min) (point-max))
	(setq e (make-extent (point) (point)))
	(set-extent-end-glyph e gl)))))

(defun showgif (file)
  "Display a GIF in a buffer."
  (interactive "f")
  (let ((gl))
    (save-excursion
      (set-buffer (get-buffer-create "*showgif*"))
      (erase-buffer)
      (insert-file-contents file)
      (setq gl (make-glyph (buffer-substring (point-min) (point-max))))
      (delete-region (point-min) (point-max))
      (reveal-annotation (make-annotation gl (point-min))))))

(defun showgif (file)
  "Display a GIF in a buffer."
  (interactive "f")
  (let ((gl))
    (save-excursion
      (set-buffer (get-buffer-create "*showgif*"))
      (erase-buffer)
      (insert-file-contents file)
      (setq gl (make-glyph (buffer-substring (point-min) (point-max))))
      (erase-buffer)
      (make-annotation gl (point-min)))))

--Multipart_Thu_Sep_25_17:13:08_1997-1
Content-Type: text/plain; charset=US-ASCII

This patch does the following.  It corrects the error handling when
loading a corrupted jpeg file (fixes many coredumps when mime decoding 
attachments in netnews).  The image detection logic is synched with
20.3 and the correct JPEG magic number is specified.

Index: src/glyphs-x.c
===================================================================
RCS file: /usr/local/xemacs/xemacs-19/src/glyphs-x.c,v
retrieving revision 1.13
diff -u -r1.13 glyphs-x.c
--- src/glyphs-x.c	1997/09/20 05:45:10	1.13
+++ src/glyphs-x.c	1997/09/25 22:17:29
@@ -1213,7 +1213,8 @@
   if (!src) {
     return;
   } else if (num_bytes > src->bytes_in_buffer) {
-    num_bytes = (long)src->bytes_in_buffer;
+    ERREXIT(cinfo, JERR_INPUT_EOF);
+    /*NOTREACHED*/
   }
 
   src->bytes_in_buffer -= num_bytes;
Index: lisp/prim/glyphs.el
===================================================================
RCS file: /usr/local/xemacs/xemacs-19/lisp/prim/glyphs.el,v
retrieving revision 1.5
diff -u -r1.5 glyphs.el
--- lisp/prim/glyphs.el	1997/03/19 06:11:35	1.5
+++ lisp/prim/glyphs.el	1997/09/25 22:44:54
@@ -596,19 +596,19 @@
   ;; initialize default image types
   (if (featurep 'x)
     (set-console-type-image-conversion-list 'x
-     `(,@(if (featurep 'xpm) '(("\.xpm$" [xpm :file nil] 2)))
-       ,@(if (featurep 'xpm) '(("^/\\* XPM \\*/" [xpm :data nil] 2)))
-       ,@(if (featurep 'xface) '(("^X-Face:" [xface :data nil] 2)))
-       ,@(if (featurep 'gif) '(("\.gif$" [gif :file nil] 2)))
-       ,@(if (featurep 'gif) '(("^GIF8[79]" [gif :data nil] 2)))
-       ,@(if (featurep 'jpeg) '(("\.jpeg$" [jpeg :file nil] 2)))
-       ,@(if (featurep 'jpeg) '(("\.jpg$" [jpeg :file nil] 2)))
+     `(,@(if (featurep 'xpm) '(("\\.xpm$\\'" [xpm :file nil] 2)))
+	 ("\\.xbm\\'" [xbm :file nil] 2)
+       ,@(if (featurep 'xpm) '(("\\`/\\* XPM \\*/" [xpm :data nil] 2)))
+       ,@(if (featurep 'xface) '(("\\`X-Face:" [xface :data nil] 2)))
+       ,@(if (featurep 'gif) '(("\\.gif\\'" [gif :file nil] 2)))
+       ,@(if (featurep 'gif) '(("\\`GIF8[79]" [gif :data nil] 2)))
+       ,@(if (featurep 'jpeg) '(("\\.jpe?g\\'" [jpeg :file nil] 2)))
        ;; all of the JFIF-format JPEG's that I've seen begin with
        ;; the following.  I have no idea if this is standard.
-       ,@(if (featurep 'jpeg) '(("^\377\330\340\000\020JFIF"
+       ,@(if (featurep 'jpeg) '(("\\`\377\330\377\340\000\020JFIF"
 				 [jpeg :data nil] 2)))
-       ,@(if (featurep 'png) '(("\.png$" [png :file nil] 2)))
-       ,@(if (featurep 'png) '(("^\211PNG" [png :data nil] 2)))
+       ,@(if (featurep 'png) '(("\\.png\\'" [png :file nil] 2)))
+       ,@(if (featurep 'png) '(("\\`\211PNG" [png :data nil] 2)))
        ("" [autodetect :data nil] 2))))
   ;; #### this should really be formatted-string, not string but we
   ;; don't have it implemented yet

--Multipart_Thu_Sep_25_17:13:08_1997-1--

