.
authorclaus
Sun, 17 Sep 1995 20:01:10 +0200
changeset 102 b634afc009a4
parent 101 44a6c9a92c00
child 103 8efb0016ad8c
.
PCXReader.st
TIFFRdr.st
TIFFReader.st
WinIconRdr.st
WindowsIconReader.st
--- a/PCXReader.st	Sat Sep 16 01:50:04 1995 +0200
+++ b/PCXReader.st	Sun Sep 17 20:01:10 1995 +0200
@@ -37,16 +37,17 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.8 1995-08-30 17:54:10 claus Exp $
+$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.9 1995-09-17 18:00:43 claus Exp $
 "
 !
 
 documentation
 "
-    this class provides methods for loading PCX bitmap files.
+    this class provides methods for loading 8-plane PCX bitmap files.
     Due to not having too many examples for testing, this could fail
     to read some files. (especially, I have no uncompressed files
     for testing).
+    Also, only 8-bit (i.e. 256 color) PCX images are supported.
 "
 ! !
 
@@ -83,7 +84,6 @@
 
     inStream := self streamReadingFile:aFilename.
     inStream isNil ifTrue:[^ false].
-
     inStream binary.
 
     header := ByteArray uninitializedNew:128.
@@ -94,6 +94,8 @@
 	^ false
     ].
     ^ true
+
+    "Modified: 17.9.1995 / 17:32:07 / claus"
 ! !
 
 !PCXReader methodsFor:'reading from file'!
@@ -138,6 +140,8 @@
      So its not (yet) implemented
     "
     ((inDepth ~~ 8) or:[nPlanes ~~ 1]) ifTrue:[
+	'PCXReader: depth: ' errorPrint. inDepth errorPrint. 
+	' planes:' errorPrint. nPlanes errorPrintNL.
 	'PCXReader: can only handle 1-plane 256 color images' errorPrintNL.
 	^ nil
     ].
--- a/TIFFRdr.st	Sat Sep 16 01:50:04 1995 +0200
+++ b/TIFFRdr.st	Sun Sep 17 20:01:10 1995 +0200
@@ -41,7 +41,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.22 1995-08-30 17:54:23 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.23 1995-09-17 18:00:56 claus Exp $
 "
 !
 
@@ -1024,7 +1024,7 @@
     ] ifFalse:[
 	stripOffsets := Array basicNew:height.
 	bytesPerRow := nBytes // height.
-	stripByteCounts := Array basicNew:height withAll:bytesPerRow.
+	stripByteCounts := (Array basicNew:height) atAllPut:bytesPerRow.
 
 	offs := 1.
 	h := height.
--- a/TIFFReader.st	Sat Sep 16 01:50:04 1995 +0200
+++ b/TIFFReader.st	Sun Sep 17 20:01:10 1995 +0200
@@ -41,7 +41,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.22 1995-08-30 17:54:23 claus Exp $
+$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.23 1995-09-17 18:00:56 claus Exp $
 "
 !
 
@@ -1024,7 +1024,7 @@
     ] ifFalse:[
 	stripOffsets := Array basicNew:height.
 	bytesPerRow := nBytes // height.
-	stripByteCounts := Array basicNew:height withAll:bytesPerRow.
+	stripByteCounts := (Array basicNew:height) atAllPut:bytesPerRow.
 
 	offs := 1.
 	h := height.
--- a/WinIconRdr.st	Sat Sep 16 01:50:04 1995 +0200
+++ b/WinIconRdr.st	Sun Sep 17 20:01:10 1995 +0200
@@ -35,7 +35,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/Attic/WinIconRdr.st,v 1.15 1995-08-30 17:54:33 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/WinIconRdr.st,v 1.16 1995-09-17 18:01:10 claus Exp $
 "
 !
 
@@ -53,6 +53,55 @@
     Image fileFormats at:'.ico'  put:self.
 ! !
 
+!WindowsIconReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains a valid windows bitmap-file image"
+
+    |inStream header ok|
+
+    inStream := self streamReadingFile:aFileName.
+    inStream isNil ifTrue:[^ false].
+
+    inStream binary.
+    inStream size < 16 ifTrue:[
+	^ false
+    ].
+
+    header := ByteArray uninitializedNew:4.
+    inStream nextBytes:4 into:header.
+
+    ok := false.
+    (header startsWith:#(66 77)) ifTrue:[     "BM"
+	ok := true.
+"/        'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
+    ].
+    (header startsWith:#(66 65)) ifTrue:[     "BA"
+	ok := true.
+"/        'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
+    ].
+    (header startsWith:#(73 67)) ifTrue:[     "IC"
+	ok := true.
+"/        'WINREADER: OS/2 IC format' infoPrintNL.
+    ].
+    (header startsWith:#(80 84)) ifTrue:[     "PT"
+	ok := true.
+"/        'WINREADER: OS/2 PT format' infoPrintNL.
+    ].
+    (header startsWith:#(0 0 1 0)) ifTrue:[
+	ok := true.
+"/        'WINREADER: Win3.x ICO format' infoPrintNL.
+    ].
+    ok ifFalse:[^ false].
+    ^ true
+
+    "
+     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
+    "
+
+    "Created: 17.9.1995 / 17:14:20 / claus"
+! !
+
 !WindowsIconReader methodsFor:'reading from file'!
 
 fromOS2File: aFilename 
@@ -263,48 +312,100 @@
 	]
     ].
 
-    "
-     currently only normal (non-rle) bitmaps
-     supported
-    "
+"/    "
+"/     currently only normal (non-rle) bitmaps
+"/     supported
+"/    "
+"/    compression ~~ 0 ifTrue:[
+"/        'BMP compression type ' errorPrint. compression errorPrint.
+"/        'not supported' errorPrintNL.
+"/        ^ nil
+"/    ].
+"/    inPlanes ~~ 1 ifTrue:[
+"/        'BMP only 1 plane images supported' errorPrintNL.
+"/        ^ nil
+"/    ].
+"/
+"/    "read the data bits"
+"/
+"/    bytesPerRow := width * inDepth + 7 // 8.
+"/    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
+"/
+"/    aStream position:(dataStart + 1).
+"/    aStream nextBytes:(height * bytesPerRow) into:data4.
+"/
+"/    "read mask"
+"/
+"/"
+"/    mask := ByteArray new:(width * height / 8).
+"/    aStream nextBytes:(width * height / 8) into:mask.
+"/"
+"/
+"/    "stupid: last row first"
+"/
+"/    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
+"/    srcIndex := 1.
+"/    dstIndex := (height - 1) * bytesPerRow + 1.
+"/    1 to:height do:[:row |
+"/        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
+"/                   with:data4 startingAt:srcIndex.
+"/        srcIndex := srcIndex + bytesPerRow.
+"/        dstIndex := dstIndex - bytesPerRow.
+"/    ].
+"/    data4 := tmp.
+
     compression ~~ 0 ifTrue:[
-	'BMP compression type ' errorPrint. compression errorPrint.
-	'not supported' errorPrintNL.
-	^ nil
+	"/ some compression
+	compression == 1 ifTrue:[
+	    "/ RLE8 - must be depth-8
+	    inDepth == 8 ifFalse:[
+		'BMP: RLE8 compression only allowed with depth8 images' errorPrintNL.
+		^ nil
+	    ].
+	].
+	compression == 2 ifTrue:[
+	    "/ RLE4 - must be depth-4
+	    inDepth == 4 ifFalse:[
+		'BMP: RLE4 compression only allowed with depth4 images' errorPrintNL.
+		^ nil
+	    ].
+	].
     ].
+
     inPlanes ~~ 1 ifTrue:[
-	'BMP only 1 plane images supported' errorPrintNL.
+	'BMP: only 1 plane images supported' errorPrintNL.
 	^ nil
     ].
 
-    "read the data bits"
-
     bytesPerRow := width * inDepth + 7 // 8.
-    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
-
+    "/ bmp data is always 32bit aligned; if required,
+    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
     aStream position:(dataStart + 1).
-    aStream nextBytes:(height * bytesPerRow) into:data4.
-
-    "read mask"
 
-"
-    mask := ByteArray new:(width * height / 8).
-    aStream nextBytes:(width * height / 8) into:mask.
-"
-
-    "stupid: last row first"
-
-    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
-    srcIndex := 1.
-    dstIndex := (height - 1) * bytesPerRow + 1.
-    1 to:height do:[:row |
-	tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
-		   with:data4 startingAt:srcIndex.
-	srcIndex := srcIndex + bytesPerRow.
-	dstIndex := dstIndex - bytesPerRow.
+    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
+    inDepth == 8 ifTrue:[
+	(self class loadBMP8Width:width height:height compression:compression from:aStream into:data) ifFalse:[
+	    'BMP: read/decompression failed' errorPrintNL.
+	    ^ nil
+	]
+    ] ifFalse:[
+	inDepth == 4 ifTrue:[
+	    (self class loadBMP4to8Width:width height:height compression:compression from:aStream into:data) ifFalse:[
+		'BMP: read/decompression failed' errorPrintNL.
+		^ nil
+	    ]
+	] ifFalse:[
+	    inDepth == 1 ifTrue:[
+		(self class loadBMP1to8Width:width height:height from:aStream into:data) ifFalse:[
+		    'BMP: read failed' errorPrintNL.
+		    ^ nil
+		]
+	    ] ifFalse:[
+		'BMP: unsupported depth:' errorPrint. inDepth errorPrintNL.
+		^ nil
+	    ]
+	]
     ].
-    data4 := tmp.
-
     "expand into bytes"
 
     data := ByteArray new:(width * height).
--- a/WindowsIconReader.st	Sat Sep 16 01:50:04 1995 +0200
+++ b/WindowsIconReader.st	Sun Sep 17 20:01:10 1995 +0200
@@ -35,7 +35,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.15 1995-08-30 17:54:33 claus Exp $
+$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.16 1995-09-17 18:01:10 claus Exp $
 "
 !
 
@@ -53,6 +53,55 @@
     Image fileFormats at:'.ico'  put:self.
 ! !
 
+!WindowsIconReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains a valid windows bitmap-file image"
+
+    |inStream header ok|
+
+    inStream := self streamReadingFile:aFileName.
+    inStream isNil ifTrue:[^ false].
+
+    inStream binary.
+    inStream size < 16 ifTrue:[
+	^ false
+    ].
+
+    header := ByteArray uninitializedNew:4.
+    inStream nextBytes:4 into:header.
+
+    ok := false.
+    (header startsWith:#(66 77)) ifTrue:[     "BM"
+	ok := true.
+"/        'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
+    ].
+    (header startsWith:#(66 65)) ifTrue:[     "BA"
+	ok := true.
+"/        'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
+    ].
+    (header startsWith:#(73 67)) ifTrue:[     "IC"
+	ok := true.
+"/        'WINREADER: OS/2 IC format' infoPrintNL.
+    ].
+    (header startsWith:#(80 84)) ifTrue:[     "PT"
+	ok := true.
+"/        'WINREADER: OS/2 PT format' infoPrintNL.
+    ].
+    (header startsWith:#(0 0 1 0)) ifTrue:[
+	ok := true.
+"/        'WINREADER: Win3.x ICO format' infoPrintNL.
+    ].
+    ok ifFalse:[^ false].
+    ^ true
+
+    "
+     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
+    "
+
+    "Created: 17.9.1995 / 17:14:20 / claus"
+! !
+
 !WindowsIconReader methodsFor:'reading from file'!
 
 fromOS2File: aFilename 
@@ -263,48 +312,100 @@
 	]
     ].
 
-    "
-     currently only normal (non-rle) bitmaps
-     supported
-    "
+"/    "
+"/     currently only normal (non-rle) bitmaps
+"/     supported
+"/    "
+"/    compression ~~ 0 ifTrue:[
+"/        'BMP compression type ' errorPrint. compression errorPrint.
+"/        'not supported' errorPrintNL.
+"/        ^ nil
+"/    ].
+"/    inPlanes ~~ 1 ifTrue:[
+"/        'BMP only 1 plane images supported' errorPrintNL.
+"/        ^ nil
+"/    ].
+"/
+"/    "read the data bits"
+"/
+"/    bytesPerRow := width * inDepth + 7 // 8.
+"/    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
+"/
+"/    aStream position:(dataStart + 1).
+"/    aStream nextBytes:(height * bytesPerRow) into:data4.
+"/
+"/    "read mask"
+"/
+"/"
+"/    mask := ByteArray new:(width * height / 8).
+"/    aStream nextBytes:(width * height / 8) into:mask.
+"/"
+"/
+"/    "stupid: last row first"
+"/
+"/    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
+"/    srcIndex := 1.
+"/    dstIndex := (height - 1) * bytesPerRow + 1.
+"/    1 to:height do:[:row |
+"/        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
+"/                   with:data4 startingAt:srcIndex.
+"/        srcIndex := srcIndex + bytesPerRow.
+"/        dstIndex := dstIndex - bytesPerRow.
+"/    ].
+"/    data4 := tmp.
+
     compression ~~ 0 ifTrue:[
-	'BMP compression type ' errorPrint. compression errorPrint.
-	'not supported' errorPrintNL.
-	^ nil
+	"/ some compression
+	compression == 1 ifTrue:[
+	    "/ RLE8 - must be depth-8
+	    inDepth == 8 ifFalse:[
+		'BMP: RLE8 compression only allowed with depth8 images' errorPrintNL.
+		^ nil
+	    ].
+	].
+	compression == 2 ifTrue:[
+	    "/ RLE4 - must be depth-4
+	    inDepth == 4 ifFalse:[
+		'BMP: RLE4 compression only allowed with depth4 images' errorPrintNL.
+		^ nil
+	    ].
+	].
     ].
+
     inPlanes ~~ 1 ifTrue:[
-	'BMP only 1 plane images supported' errorPrintNL.
+	'BMP: only 1 plane images supported' errorPrintNL.
 	^ nil
     ].
 
-    "read the data bits"
-
     bytesPerRow := width * inDepth + 7 // 8.
-    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
-
+    "/ bmp data is always 32bit aligned; if required,
+    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
     aStream position:(dataStart + 1).
-    aStream nextBytes:(height * bytesPerRow) into:data4.
-
-    "read mask"
 
-"
-    mask := ByteArray new:(width * height / 8).
-    aStream nextBytes:(width * height / 8) into:mask.
-"
-
-    "stupid: last row first"
-
-    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
-    srcIndex := 1.
-    dstIndex := (height - 1) * bytesPerRow + 1.
-    1 to:height do:[:row |
-	tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
-		   with:data4 startingAt:srcIndex.
-	srcIndex := srcIndex + bytesPerRow.
-	dstIndex := dstIndex - bytesPerRow.
+    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
+    inDepth == 8 ifTrue:[
+	(self class loadBMP8Width:width height:height compression:compression from:aStream into:data) ifFalse:[
+	    'BMP: read/decompression failed' errorPrintNL.
+	    ^ nil
+	]
+    ] ifFalse:[
+	inDepth == 4 ifTrue:[
+	    (self class loadBMP4to8Width:width height:height compression:compression from:aStream into:data) ifFalse:[
+		'BMP: read/decompression failed' errorPrintNL.
+		^ nil
+	    ]
+	] ifFalse:[
+	    inDepth == 1 ifTrue:[
+		(self class loadBMP1to8Width:width height:height from:aStream into:data) ifFalse:[
+		    'BMP: read failed' errorPrintNL.
+		    ^ nil
+		]
+	    ] ifFalse:[
+		'BMP: unsupported depth:' errorPrint. inDepth errorPrintNL.
+		^ nil
+	    ]
+	]
     ].
-    data4 := tmp.
-
     "expand into bytes"
 
     data := ByteArray new:(width * height).