.
--- a/WinIconRdr.st Sun Sep 17 20:01:10 1995 +0200
+++ b/WinIconRdr.st Mon Sep 18 00:52:44 1995 +0200
@@ -35,7 +35,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/Attic/WinIconRdr.st,v 1.16 1995-09-17 18:01:10 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/WinIconRdr.st,v 1.17 1995-09-17 22:52:44 claus Exp $
"
!
@@ -102,6 +102,44 @@
"Created: 17.9.1995 / 17:14:20 / claus"
! !
+!WindowsIconReader methodsFor:'private'!
+
+loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
+ d == 8 ifTrue:[
+ (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+ 'BMP: read/decompression failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 4 ifTrue:[
+ (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+ 'BMP: read/decompression failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 2 ifTrue:[
+ (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 1 ifTrue:[
+ (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ 'BMP: unsupported depth:' errorPrint. d errorPrintNL.
+ ^ false
+ ]
+ ]
+ ]
+ ].
+ ^ true
+
+ "Created: 17.9.1995 / 18:48:11 / claus"
+! !
+
!WindowsIconReader methodsFor:'reading from file'!
fromOS2File: aFilename
@@ -227,7 +265,7 @@
| fileSize header inDepth inPlanes compression
imgSize resH resV numColor numImportantColor
dataStart
- rawMap rMap gMap bMap srcIndex dstIndex
+ rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
data4 mask tmp bytesPerRow fourBytesPerColorInfo|
inStream := aStream.
@@ -353,6 +391,10 @@
"/ dstIndex := dstIndex - bytesPerRow.
"/ ].
"/ data4 := tmp.
+"/ data := ByteArray new:(width * height).
+"/ data4 expandPixels:inDepth width:width height:height
+"/ into:data mapping:nil.
+"/
compression ~~ 0 ifTrue:[
"/ some compression
@@ -383,39 +425,17 @@
aStream position:(dataStart + 1).
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
- ]
- ]
+ (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
+ ^ nil
].
"expand into bytes"
- data := ByteArray new:(width * height).
- data4 expandPixels:inDepth width:width height:height
- into:data mapping:nil.
-
photometric := #palette.
samplesPerPixel := 1.
bitsPerSample := #(8).
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+
+ "Modified: 17.9.1995 / 18:48:46 / claus"
!
fromStream:aStream
@@ -454,22 +474,34 @@
'WINREADER: OS/2 PT format' errorPrintNL.
^ self fromOS2Stream:aStream
].
+ (header startsWith:#(16r53 16r5A)) ifTrue:[ "SZ"
+ 'WINREADER: SZ format not supported:' errorPrintNL.
+ ^ nil.
+ aStream position:1.
+ 'WINREADER: OS/2 PT format' errorPrintNL.
+ ^ self fromOS2Stream:aStream
+ ].
(header startsWith:#(0 0 1 0)) ifTrue:[
aStream position:1.
'WINREADER: Win3.x ICO format' errorPrintNL.
^ self fromWindowsICOStream:aStream
].
- 'WINREADER: format not supported' errorPrintNL.
+ 'WINREADER: format not supported:' errorPrint.
+ ((header at:1) printStringRadix:16) errorPrint.
+ ' ' errorPrint.
+ ((header at:2) printStringRadix:16) errorPrintNL.
^ nil
"
Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
"
+
+ "Modified: 17.9.1995 / 18:59:07 / claus"
!
fromOS2Stream:aStream
| header inDepth
- rawMap rMap gMap bMap srcIndex dstIndex
+ rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
data4 mask tmp bytesPerRow nColors nByte|
inStream := aStream.
@@ -522,31 +554,42 @@
aStream nextBytes:nByte into:mask.
- "read the data bits"
+"/ "read the data bits"
+"/
+"/ bytesPerRow := width * inDepth + 7 // 8.
+"/ data4 := ByteArray uninitializedNew:(height * bytesPerRow).
+"/ inDepth == 8 ifTrue:[
+"/ ].
+"/ aStream nextBytes:(height * bytesPerRow) into:data4.
+"/
+"/ "stupid: last row first"
+"/
+"/ tmp := ByteArray new:(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.
+"/
+"/ "expand into bytes"
+"/
+"/ data := ByteArray new:(width * height).
+"/ data4 expandPixels:inDepth width:width height:height
+"/ into:data mapping:nil.
+"/
bytesPerRow := width * inDepth + 7 // 8.
- data4 := ByteArray uninitializedNew:(height * bytesPerRow).
- aStream nextBytes:(height * bytesPerRow) into:data4.
-
- "stupid: last row first"
+ "/ bmp data is always 32bit aligned; if required,
+ inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
- tmp := ByteArray new:(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").
+ (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
+ ^ nil
].
- data4 := tmp.
-
- "expand into bytes"
-
- data := ByteArray new:(width * height).
- data4 expandPixels:inDepth width:width height:height
- into:data mapping:nil.
-
photometric := #palette.
samplesPerPixel := 1.
bitsPerSample := #(8).
@@ -558,4 +601,6 @@
f := i asFormOn:Display.
v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
"
+
+ "Modified: 17.9.1995 / 18:49:24 / claus"
! !
--- a/WindowsIconReader.st Sun Sep 17 20:01:10 1995 +0200
+++ b/WindowsIconReader.st Mon Sep 18 00:52:44 1995 +0200
@@ -35,7 +35,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.16 1995-09-17 18:01:10 claus Exp $
+$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.17 1995-09-17 22:52:44 claus Exp $
"
!
@@ -102,6 +102,44 @@
"Created: 17.9.1995 / 17:14:20 / claus"
! !
+!WindowsIconReader methodsFor:'private'!
+
+loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
+ d == 8 ifTrue:[
+ (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+ 'BMP: read/decompression failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 4 ifTrue:[
+ (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+ 'BMP: read/decompression failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 2 ifTrue:[
+ (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ d == 1 ifTrue:[
+ (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ]
+ ] ifFalse:[
+ 'BMP: unsupported depth:' errorPrint. d errorPrintNL.
+ ^ false
+ ]
+ ]
+ ]
+ ].
+ ^ true
+
+ "Created: 17.9.1995 / 18:48:11 / claus"
+! !
+
!WindowsIconReader methodsFor:'reading from file'!
fromOS2File: aFilename
@@ -227,7 +265,7 @@
| fileSize header inDepth inPlanes compression
imgSize resH resV numColor numImportantColor
dataStart
- rawMap rMap gMap bMap srcIndex dstIndex
+ rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
data4 mask tmp bytesPerRow fourBytesPerColorInfo|
inStream := aStream.
@@ -353,6 +391,10 @@
"/ dstIndex := dstIndex - bytesPerRow.
"/ ].
"/ data4 := tmp.
+"/ data := ByteArray new:(width * height).
+"/ data4 expandPixels:inDepth width:width height:height
+"/ into:data mapping:nil.
+"/
compression ~~ 0 ifTrue:[
"/ some compression
@@ -383,39 +425,17 @@
aStream position:(dataStart + 1).
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
- ]
- ]
+ (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
+ ^ nil
].
"expand into bytes"
- data := ByteArray new:(width * height).
- data4 expandPixels:inDepth width:width height:height
- into:data mapping:nil.
-
photometric := #palette.
samplesPerPixel := 1.
bitsPerSample := #(8).
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+
+ "Modified: 17.9.1995 / 18:48:46 / claus"
!
fromStream:aStream
@@ -454,22 +474,34 @@
'WINREADER: OS/2 PT format' errorPrintNL.
^ self fromOS2Stream:aStream
].
+ (header startsWith:#(16r53 16r5A)) ifTrue:[ "SZ"
+ 'WINREADER: SZ format not supported:' errorPrintNL.
+ ^ nil.
+ aStream position:1.
+ 'WINREADER: OS/2 PT format' errorPrintNL.
+ ^ self fromOS2Stream:aStream
+ ].
(header startsWith:#(0 0 1 0)) ifTrue:[
aStream position:1.
'WINREADER: Win3.x ICO format' errorPrintNL.
^ self fromWindowsICOStream:aStream
].
- 'WINREADER: format not supported' errorPrintNL.
+ 'WINREADER: format not supported:' errorPrint.
+ ((header at:1) printStringRadix:16) errorPrint.
+ ' ' errorPrint.
+ ((header at:2) printStringRadix:16) errorPrintNL.
^ nil
"
Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
"
+
+ "Modified: 17.9.1995 / 18:59:07 / claus"
!
fromOS2Stream:aStream
| header inDepth
- rawMap rMap gMap bMap srcIndex dstIndex
+ rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
data4 mask tmp bytesPerRow nColors nByte|
inStream := aStream.
@@ -522,31 +554,42 @@
aStream nextBytes:nByte into:mask.
- "read the data bits"
+"/ "read the data bits"
+"/
+"/ bytesPerRow := width * inDepth + 7 // 8.
+"/ data4 := ByteArray uninitializedNew:(height * bytesPerRow).
+"/ inDepth == 8 ifTrue:[
+"/ ].
+"/ aStream nextBytes:(height * bytesPerRow) into:data4.
+"/
+"/ "stupid: last row first"
+"/
+"/ tmp := ByteArray new:(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.
+"/
+"/ "expand into bytes"
+"/
+"/ data := ByteArray new:(width * height).
+"/ data4 expandPixels:inDepth width:width height:height
+"/ into:data mapping:nil.
+"/
bytesPerRow := width * inDepth + 7 // 8.
- data4 := ByteArray uninitializedNew:(height * bytesPerRow).
- aStream nextBytes:(height * bytesPerRow) into:data4.
-
- "stupid: last row first"
+ "/ bmp data is always 32bit aligned; if required,
+ inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
- tmp := ByteArray new:(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").
+ (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
+ ^ nil
].
- data4 := tmp.
-
- "expand into bytes"
-
- data := ByteArray new:(width * height).
- data4 expandPixels:inDepth width:width height:height
- into:data mapping:nil.
-
photometric := #palette.
samplesPerPixel := 1.
bitsPerSample := #(8).
@@ -558,4 +601,6 @@
f := i asFormOn:Display.
v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
"
+
+ "Modified: 17.9.1995 / 18:49:24 / claus"
! !