use common fileFormatError reporter
authorClaus Gittinger <cg@exept.de>
Tue, 03 Feb 1998 17:54:19 +0100
changeset 809 0d39cb7c21a9
parent 808 495535230e80
child 810 93a9f3c4d8ec
use common fileFormatError reporter
GIFReader.st
--- a/GIFReader.st	Tue Feb 03 17:52:33 1998 +0100
+++ b/GIFReader.st	Tue Feb 03 17:54:19 1998 +0100
@@ -326,7 +326,9 @@
     byteOrder := #lsb.
 
     id := ByteArray new:6.
-    aStream nextBytes:6 into:id startingAt:1.
+    (aStream nextBytes:6 into:id startingAt:1) ~~ 6 ifTrue:[
+        ^ self fileFormatError:'not a gif file (short read)'.
+    ].
     id := id asString.
 
     "all I had for testing where GIF87a files;
@@ -334,13 +336,12 @@
 
     isGif89 := false.
     (id ~= 'GIF87a') ifTrue:[
-	(id startsWith:'GIF') ifFalse:[
-	    'GIFReader [info]: not a gif file' infoPrintCR.
-	    ^ nil
-	].
-	id ~= 'GIF89a' ifTrue:[ 
-	    'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
-	]
+        (id startsWith:'GIF') ifFalse:[
+            ^ self fileFormatError:('not a gif file (id=''' , id , ''')').
+        ].
+        id ~= 'GIF89a' ifTrue:[ 
+            'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
+        ]
     ].
 
     "get screen dimensions (not used)"
@@ -363,11 +364,11 @@
 
     "get colorMap"
     hasColorMap ifTrue:[
-	self readColorMap:colorMapSize.
-	fileColorMap := Colormap 
-			redVector:redMap 
-			greenVector:greenMap 
-			blueVector:blueMap.
+        self readColorMap:colorMapSize.
+        fileColorMap := Colormap 
+                        redVector:redMap 
+                        greenVector:greenMap 
+                        blueVector:blueMap.
     ].
     colorMap := fileColorMap.
 
@@ -377,48 +378,47 @@
 
     atEnd := false.
     [atEnd] whileFalse:[
-	"gif89a extensions"
+        "gif89a extensions"
 
-	byte := aStream nextByte.
-	byte == Extension ifTrue:[
-	    self readExtension:aStream.
-	] ifFalse:[
-	    (byte == Terminator) ifTrue:[
-		atEnd := true
-	    ] ifFalse:[
-		"must be image separator"
-		(byte ~~ ImageSeparator) ifTrue:[
-		    ('GIFReader [info]: corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)) infoPrintCR.
-		    ^ nil
-		].
+        byte := aStream nextByte.
+        byte == Extension ifTrue:[
+            self readExtension:aStream.
+        ] ifFalse:[
+            (byte == Terminator) ifTrue:[
+                atEnd := true
+            ] ifFalse:[
+                "must be image separator"
+                (byte ~~ ImageSeparator) ifTrue:[
+                    ^ self fileFormatError:('corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)).
+                ].
+
+                fileColorMap notNil ifTrue:[
+                    colorMap := fileColorMap.
+                ].
+                self readImage:aStream.
 
-		fileColorMap notNil ifTrue:[
-		    colorMap := fileColorMap.
-		].
-		self readImage:aStream.
+                imageSequence isNil ifTrue:[
+                    imageSequence := OrderedCollection new.
+                ].
+                maskPixel notNil ifTrue:[
+                    "/
+                    "/ ok, there is a maskValue
+                    "/ build a Depth1Image for it.
+                    "/
+                    self buildMaskFromColor:maskPixel
+                ].
 
-		imageSequence isNil ifTrue:[
-		    imageSequence := OrderedCollection new.
-		].
-		maskPixel notNil ifTrue:[
-		    "/
-		    "/ ok, there is a maskValue
-		    "/ build a Depth1Image for it.
-		    "/
-		    self buildMaskFromColor:maskPixel
-		].
+                imageSequence add:(self image).
 
-		imageSequence add:(self image).
-
-		aStream atEnd ifTrue:[
-		    atEnd := true.
-		]
-	    ]
-	].
+                aStream atEnd ifTrue:[
+                    atEnd := true.
+                ]
+            ]
+        ].
     ].
 
     "Modified: / 5.7.1996 / 17:32:01 / stefan"
-    "Modified: / 13.1.1998 / 10:44:26 / cg"
+    "Modified: / 3.2.1998 / 17:53:37 / cg"
 !
 
 makeGreyscale
@@ -939,6 +939,6 @@
 !GIFReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.66 1998-01-16 15:20:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.67 1998-02-03 16:54:19 cg Exp $'
 ! !
 GIFReader initialize!