checkin from browser
authorClaus Gittinger <cg@exept.de>
Fri, 11 Apr 1997 16:44:54 +0200
changeset 522 93a9f3a8caae
parent 521 2937b6c596b3
child 523 f26a8b493514
checkin from browser
JPEGReader.st
--- a/JPEGReader.st	Fri Apr 11 12:48:20 1997 +0200
+++ b/JPEGReader.st	Fri Apr 11 16:44:54 1997 +0200
@@ -17,6 +17,20 @@
 	category:'Graphics-Images-Support'
 !
 
+!JPEGReader primitiveDefinitions!
+%{
+
+/*
+ * includes, defines, structure definitions
+ * and typedefs come here.
+ */
+
+#include <jpeglib.h>
+#include <jerror.h>
+
+%}
+! !
+
 !JPEGReader class methodsFor:'documentation'!
 
 copyright
@@ -38,7 +52,7 @@
     Reader for JPEG images.
 
     This is a quick&dirty hack, using the PD djpeg tool to convert 
-    the JPG image to GIF first, then reads the GIF image using GIFReader.
+    the JPG image to PNM first, then reads the PNM image using PBMReader.
 
     Of course, this is slower than it should be. If lots of JPG reading
     is done, this class should be rewritten, to directly call the (C) JPG
@@ -79,27 +93,45 @@
     |tempFileName reader|
 
     tempFileName := '/tmp/img' , (OperatingSystem getProcessId printString).
-    'JPEGREADER: converting to gif ..' errorPrintCR.
-    (OperatingSystem executeCommand:'djpeg -gif ' , aFileName , ' > ' , tempFileName)
-    ifTrue:[
-        reader := GIFReader fromFile:tempFileName.
-        OperatingSystem executeCommand:'rm ' , tempFileName.
-        ^ reader
+
+    'JPEGREADER [info]: converting to ppm ..' infoPrintCR.
+    (OperatingSystem executeCommand:'djpeg -pnm ' , aFileName , ' > ' , tempFileName)
+    ifFalse:[
+        (OperatingSystem executeCommand:'../../support/libjpeg/djpeg -pnm ' , aFileName , ' > ' , tempFileName)    
+        ifFalse:[
+            'JPEGREADER [warning]: conversion failed ..' errorPrintCR.
+            'JPEGREADER [warning]: .. cannot execute converter: djpeg' errorPrintCR.
+            ^ nil
+        ].
     ].
-    'JPEGREADER: conversion failed ..' errorPrintCR.
-    'JPEGREADER: .. cannot execute jpeg converter: djpeg' errorPrintCR.
-    ^ nil
+
+    reader := PBMReader fromFile:tempFileName.
+    OperatingSystem executeCommand:'rm ' , tempFileName.
+    ^ reader
 
     "
      JPEGReader fromFile:'bitmaps/testimg.jpg'
     "
 
-    "Modified: 23.4.1996 / 12:30:12 / cg"
+    "Modified: 11.4.1997 / 16:39:59 / cg"
+! !
+
+!JPEGReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains a JPG image.
+     Only look at the files name here ..."
+
+    (aFileName asLowercase endsWith:'.jpg') ifTrue:[^ true].
+    (aFileName asLowercase endsWith:'.jpeg') ifTrue:[^ true].
+    ^ false
+
+    "Created: 11.4.1997 / 16:26:25 / cg"
 ! !
 
 !JPEGReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.18 1997-02-01 14:06:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.19 1997-04-11 14:44:54 cg Exp $'
 ! !
 JPEGReader initialize!