care for bad strip size (how can this happen ?)
authorClaus Gittinger <cg@exept.de>
Thu, 11 Jul 1996 21:15:48 +0200
changeset 317 5de89b17ed48
parent 316 d39f3f8f7627
child 318 097d70e8163f
care for bad strip size (how can this happen ?)
TIFFRdr.st
TIFFReader.st
--- a/TIFFRdr.st	Fri Jul 05 23:09:05 1996 +0200
+++ b/TIFFRdr.st	Thu Jul 11 21:15:48 1996 +0200
@@ -20,7 +20,7 @@
 	category:'Graphics-Images-Support'
 !
 
-!TIFFReader class methodsFor:'documentation'!
+!TIFFReader  class methodsFor:'documentation'!
 
 copyright
 "
@@ -67,7 +67,7 @@
 "
 ! !
 
-!TIFFReader class methodsFor:'initialization'!
+!TIFFReader  class methodsFor:'initialization'!
 
 initialize
     "install myself in the Image classes fileFormat table
@@ -80,7 +80,7 @@
     "Modified: 23.4.1996 / 12:28:57 / cg"
 ! !
 
-!TIFFReader class methodsFor:'testing'!
+!TIFFReader  class methodsFor:'testing'!
 
 canRepresent:anImage
     "return true, if anImage can be represented in my file format.
@@ -962,39 +962,39 @@
      or rgb - if non separate planes and no alpha"
 
     (nPlanes == 2) ifTrue:[
-	(planarConfiguration ~~ 2) ifTrue:[
-	    self error:'with alpha, only separate planes supported'.
-	    ^ nil
-	].
-	'TIFFReader: ignoring alpha plane' errorPrintNL.
-	nPlanes := 1.
-	bitsPerPixel := bitsPerSample at:1.
-	bitsPerSample := Array with:bitsPerPixel.
-	samplesPerPixel := 1.
+        (planarConfiguration ~~ 2) ifTrue:[
+            self error:'with alpha, only separate planes supported'.
+            ^ nil
+        ].
+        'TIFFReader: ignoring alpha plane' errorPrintNL.
+        nPlanes := 1.
+        bitsPerPixel := bitsPerSample at:1.
+        bitsPerSample := Array with:bitsPerPixel.
+        samplesPerPixel := 1.
     ] ifFalse:[
-	(nPlanes == 3) ifTrue:[
-	    (planarConfiguration ~~ 1) ifTrue:[
-		self error:'only non separate planes supported'.
-		^ nil
-	    ].
-	    bitsPerSample ~= #(8 8 8) ifTrue:[
-		self error:'only 8/8/8 rgb images supported'.
-		^ nil
-	    ].
-	    bitsPerPixel := 24
-	] ifFalse:[
-	    (nPlanes ~~ 1) ifTrue:[
-		self error:'format not supported'.
-		^ nil
-	    ].
-	    bitsPerPixel := bitsPerSample at:1.
-	]
+        (nPlanes == 3) ifTrue:[
+            (planarConfiguration ~~ 1) ifTrue:[
+                self error:'only non separate planes supported'.
+                ^ nil
+            ].
+            bitsPerSample ~= #(8 8 8) ifTrue:[
+                self error:'only 8/8/8 rgb images supported'.
+                ^ nil
+            ].
+            bitsPerPixel := 24
+        ] ifFalse:[
+            (nPlanes ~~ 1) ifTrue:[
+                self error:'format not supported'.
+                ^ nil
+            ].
+            bitsPerPixel := bitsPerSample at:1.
+        ]
     ].
 
     bitsPerRow := width * bitsPerPixel.
     bytesPerRow := bitsPerRow // 8.
     ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
-	bytesPerRow := bytesPerRow + 1
+        bytesPerRow := bytesPerRow + 1
     ].
 
     overAllBytes := bytesPerRow * height.
@@ -1005,14 +1005,20 @@
 
     row := 1.
     [row <= height] whileTrue:[
-	stripNr := stripNr + 1.
-	nBytes := stripByteCounts at:stripNr.
-	inStream position:((stripOffsets at:stripNr) + 1).
+        stripNr := stripNr + 1.
+        nBytes := stripByteCounts at:stripNr.
+        inStream position:((stripOffsets at:stripNr) + 1).
 
-	inStream nextBytes:nBytes into:data startingAt:offset.
-	offset := offset + nBytes.
-	row := row + rowsPerStrip
+        offset + nBytes > overAllBytes ifTrue:[
+            nBytes := overAllBytes - offset
+        ].
+
+        inStream nextBytes:nBytes into:data startingAt:offset.
+        offset := offset + nBytes.
+        row := row + rowsPerStrip
     ]
+
+    "Modified: 11.7.1996 / 21:10:30 / cg"
 !
 
 writeBitsPerSample
@@ -1644,9 +1650,9 @@
     outStream close
 ! !
 
-!TIFFReader class methodsFor:'documentation'!
+!TIFFReader  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.37 1996-05-10 16:45:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.38 1996-07-11 19:15:48 cg Exp $'
 ! !
 TIFFReader initialize!
--- a/TIFFReader.st	Fri Jul 05 23:09:05 1996 +0200
+++ b/TIFFReader.st	Thu Jul 11 21:15:48 1996 +0200
@@ -20,7 +20,7 @@
 	category:'Graphics-Images-Support'
 !
 
-!TIFFReader class methodsFor:'documentation'!
+!TIFFReader  class methodsFor:'documentation'!
 
 copyright
 "
@@ -67,7 +67,7 @@
 "
 ! !
 
-!TIFFReader class methodsFor:'initialization'!
+!TIFFReader  class methodsFor:'initialization'!
 
 initialize
     "install myself in the Image classes fileFormat table
@@ -80,7 +80,7 @@
     "Modified: 23.4.1996 / 12:28:57 / cg"
 ! !
 
-!TIFFReader class methodsFor:'testing'!
+!TIFFReader  class methodsFor:'testing'!
 
 canRepresent:anImage
     "return true, if anImage can be represented in my file format.
@@ -962,39 +962,39 @@
      or rgb - if non separate planes and no alpha"
 
     (nPlanes == 2) ifTrue:[
-	(planarConfiguration ~~ 2) ifTrue:[
-	    self error:'with alpha, only separate planes supported'.
-	    ^ nil
-	].
-	'TIFFReader: ignoring alpha plane' errorPrintNL.
-	nPlanes := 1.
-	bitsPerPixel := bitsPerSample at:1.
-	bitsPerSample := Array with:bitsPerPixel.
-	samplesPerPixel := 1.
+        (planarConfiguration ~~ 2) ifTrue:[
+            self error:'with alpha, only separate planes supported'.
+            ^ nil
+        ].
+        'TIFFReader: ignoring alpha plane' errorPrintNL.
+        nPlanes := 1.
+        bitsPerPixel := bitsPerSample at:1.
+        bitsPerSample := Array with:bitsPerPixel.
+        samplesPerPixel := 1.
     ] ifFalse:[
-	(nPlanes == 3) ifTrue:[
-	    (planarConfiguration ~~ 1) ifTrue:[
-		self error:'only non separate planes supported'.
-		^ nil
-	    ].
-	    bitsPerSample ~= #(8 8 8) ifTrue:[
-		self error:'only 8/8/8 rgb images supported'.
-		^ nil
-	    ].
-	    bitsPerPixel := 24
-	] ifFalse:[
-	    (nPlanes ~~ 1) ifTrue:[
-		self error:'format not supported'.
-		^ nil
-	    ].
-	    bitsPerPixel := bitsPerSample at:1.
-	]
+        (nPlanes == 3) ifTrue:[
+            (planarConfiguration ~~ 1) ifTrue:[
+                self error:'only non separate planes supported'.
+                ^ nil
+            ].
+            bitsPerSample ~= #(8 8 8) ifTrue:[
+                self error:'only 8/8/8 rgb images supported'.
+                ^ nil
+            ].
+            bitsPerPixel := 24
+        ] ifFalse:[
+            (nPlanes ~~ 1) ifTrue:[
+                self error:'format not supported'.
+                ^ nil
+            ].
+            bitsPerPixel := bitsPerSample at:1.
+        ]
     ].
 
     bitsPerRow := width * bitsPerPixel.
     bytesPerRow := bitsPerRow // 8.
     ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
-	bytesPerRow := bytesPerRow + 1
+        bytesPerRow := bytesPerRow + 1
     ].
 
     overAllBytes := bytesPerRow * height.
@@ -1005,14 +1005,20 @@
 
     row := 1.
     [row <= height] whileTrue:[
-	stripNr := stripNr + 1.
-	nBytes := stripByteCounts at:stripNr.
-	inStream position:((stripOffsets at:stripNr) + 1).
+        stripNr := stripNr + 1.
+        nBytes := stripByteCounts at:stripNr.
+        inStream position:((stripOffsets at:stripNr) + 1).
 
-	inStream nextBytes:nBytes into:data startingAt:offset.
-	offset := offset + nBytes.
-	row := row + rowsPerStrip
+        offset + nBytes > overAllBytes ifTrue:[
+            nBytes := overAllBytes - offset
+        ].
+
+        inStream nextBytes:nBytes into:data startingAt:offset.
+        offset := offset + nBytes.
+        row := row + rowsPerStrip
     ]
+
+    "Modified: 11.7.1996 / 21:10:30 / cg"
 !
 
 writeBitsPerSample
@@ -1644,9 +1650,9 @@
     outStream close
 ! !
 
-!TIFFReader class methodsFor:'documentation'!
+!TIFFReader  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.37 1996-05-10 16:45:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.38 1996-07-11 19:15:48 cg Exp $'
 ! !
 TIFFReader initialize!