WindowsIconReader.st
changeset 172 ee7d84977c86
parent 161 c47f1fd6cf5b
child 211 3eb140e89e2e
--- a/WindowsIconReader.st	Tue Mar 05 01:02:09 1996 +0100
+++ b/WindowsIconReader.st	Thu Mar 07 19:28:20 1996 +0100
@@ -11,10 +11,10 @@
 "
 
 ImageReader subclass:#WindowsIconReader
-	 instanceVariableNames:''
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Graphics-Images support'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Graphics-Images support'
 !
 
 !WindowsIconReader class methodsFor:'documentation'!
@@ -33,10 +33,6 @@
 "
 !
 
-version
-    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.21 1996-02-04 21:03:27 cg Exp $'
-!
-
 documentation
 "
     this class provides methods for loading Windows and OS2 icon files.
@@ -64,29 +60,29 @@
     inStream binary.
     ok := false.
     inStream size > 16 ifTrue:[
-	header := ByteArray uninitializedNew:4.
-	inStream nextBytes:4 into:header.
+        header := ByteArray uninitializedNew:4.
+        inStream nextBytes:4 into:header.
 
-	(header startsWith:#(66 77)) ifTrue:[     "BM"
-	    ok := true.
+        (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.
+        ].
+        (header startsWith:#(66 65)) ifTrue:[     "BA"
+            ok := true.
 "/            'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
-	].
-	(header startsWith:#(73 67)) ifTrue:[     "IC"
-	    ok := true.
+        ].
+        (header startsWith:#(73 67)) ifTrue:[     "IC"
+            ok := true.
 "/            'WINREADER: OS/2 IC format' infoPrintNL.
-	].
-	(header startsWith:#(80 84)) ifTrue:[     "PT"
-	    ok := true.
+        ].
+        (header startsWith:#(80 84)) ifTrue:[     "PT"
+            ok := true.
 "/            'WINREADER: OS/2 PT format' infoPrintNL.
-	].
-	(header startsWith:#(0 0 1 0)) ifTrue:[
-	    ok := true.
+        ].
+        (header startsWith:#(0 0 1 0)) ifTrue:[
+            ok := true.
 "/            'WINREADER: Win3.x ICO format' infoPrintNL.
-	].
+        ].
     ].
     inStream close.
     ^ ok
@@ -104,54 +100,54 @@
     |buff idx1 idx2 bytesPerRow|
 
     d == 8 ifTrue:[
-	(self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
-	    'BMP: read/decompression failed' errorPrintNL.
-	    ^ false
-	].
-	^ true
+        (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+            'BMP: read/decompression failed' infoPrintNL.
+            ^ false
+        ].
+        ^ true
     ].
     d == 4 ifTrue:[
-	(self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
-	    'BMP: read/decompression failed' errorPrintNL.
-	    ^ false
-	].
-	^ true
+        (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+            'BMP: read/decompression failed' infoPrintNL.
+            ^ false
+        ].
+        ^ true
     ].
     d == 2 ifTrue:[
-	(self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
-	    'BMP: read failed' errorPrintNL.
-	    ^ false
-	].
-	^ true
+        (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
+            'BMP: read failed' infoPrintNL.
+            ^ false
+        ].
+        ^ true
     ].
     d == 1 ifTrue:[
-	(self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
-	    'BMP: read failed' errorPrintNL.
-	    ^ false
-	].
-	^ true
+        (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
+            'BMP: read failed' infoPrintNL.
+            ^ false
+        ].
+        ^ true
     ].
     d == 24 ifTrue:[
-	bytesPerRow := w * 3.
-	((aStream nextBytes:(h * bytesPerRow) into:data) ~~ (h * bytesPerRow)) ifTrue:[
-	    'BMP: read failed' errorPrintNL.
-	    ^ false
-	].
-	"/ stupid - last row comes first
+        bytesPerRow := w * 3.
+        ((aStream nextBytes:(h * bytesPerRow) into:data) ~~ (h * bytesPerRow)) ifTrue:[
+            'BMP: read failed' infoPrintNL.
+            ^ false
+        ].
+        "/ stupid - last row comes first
 
-	buff := ByteArray uninitializedNew:bytesPerRow.
-	idx1 := 1.
-	idx2 := 1 + (h-1 * bytesPerRow).
-	[idx1 < idx2] whileTrue:[
-	    buff replaceFrom:1 to:bytesPerRow with:data startingAt:idx1.
-	    data replaceFrom:idx1 to:(idx1 + bytesPerRow - 1) with:data startingAt:idx2.
-	    data replaceFrom:idx2 to:(idx2 + bytesPerRow - 1) with:buff startingAt:1.
-	    idx1 := idx1 + bytesPerRow.
-	    idx2 := idx2 - bytesPerRow.
-	].
-	^ true
+        buff := ByteArray uninitializedNew:bytesPerRow.
+        idx1 := 1.
+        idx2 := 1 + (h-1 * bytesPerRow).
+        [idx1 < idx2] whileTrue:[
+            buff replaceFrom:1 to:bytesPerRow with:data startingAt:idx1.
+            data replaceFrom:idx1 to:(idx1 + bytesPerRow - 1) with:data startingAt:idx2.
+            data replaceFrom:idx2 to:(idx2 + bytesPerRow - 1) with:buff startingAt:1.
+            idx1 := idx1 + bytesPerRow.
+            idx2 := idx2 - bytesPerRow.
+        ].
+        ^ true
     ].
-    'BMP: unsupported depth:' errorPrint. d errorPrintNL.
+    'BMP: unsupported depth:' infoPrint. d infoPrintNL.
 
     "Created: 17.9.1995 / 18:48:11 / claus"
     "Modified: 4.2.1996 / 18:04:44 / cg"
@@ -170,6 +166,173 @@
     ^ nil
 !
 
+fromOS2Stream:aStream
+    | header inDepth
+      rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
+      data4 mask tmp bytesPerRow nColors nByte|
+
+    inStream := aStream.
+    aStream binary.
+
+    "read the header"
+
+    header := ByteArray uninitializedNew:8r110.
+    aStream nextBytes:16 into:header.
+
+    (header startsWith:#(73 67)) ifTrue:[
+        "IC format"
+        aStream nextBytes:10 into:header startingAt:17.
+        width := header at:7.
+        height := header at:9.
+        inDepth := 2 "header at:11". "where is it"
+    ] ifFalse:[
+        aStream nextBytes:(8r110-16) into:header startingAt:17.
+        width := header at:8r101.
+        height := header at:8r103.
+        inDepth := header at:8r107.
+    ].
+
+    "read the colormap"
+
+    nColors := 1 bitShift:inDepth.
+
+    rawMap := ByteArray uninitializedNew:(nColors*3).
+    aStream nextBytes:(nColors*3) into:rawMap.
+    rMap := Array new:nColors.
+    gMap := Array new:nColors.
+    bMap := Array new:nColors.
+    srcIndex := 1.
+    1 to:nColors do:[:i |
+        bMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+        gMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+        rMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+    ].
+
+    "read mask"
+
+    nByte := width * height + 7 // 8.
+    mask := ByteArray uninitializedNew:nByte.
+    aStream nextBytes:nByte into:mask.
+
+    "what is this"
+
+    aStream nextBytes:nByte into:mask.
+
+"/    "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.
+    "/ bmp data is always 32bit aligned; if required,
+    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
+
+    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
+    (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
+        ^ nil
+    ].
+    photometric := #palette.
+    samplesPerPixel := 1.
+    bitsPerSample := #(8).
+    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+
+    "
+     |i f|
+     i := Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'.
+     f := i asFormOn:Display.
+     v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
+    "
+
+    "Modified: 17.9.1995 / 18:49:24 / claus"
+!
+
+fromStream:aStream 
+    | fileSize header |
+
+    inStream := aStream.
+
+    aStream binary.
+    fileSize := aStream size.
+
+    fileSize < 16 ifTrue:[
+        'WINREADER: short file' infoPrintNL.
+        ^ nil
+    ].
+
+    header := ByteArray uninitializedNew:4.
+    aStream nextBytes:4 into:header.
+
+    (header startsWith:#(66 77)) ifTrue:[     "BM"
+        aStream position:1.
+        'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
+        ^ self fromWindowsBMPStream:aStream
+    ].
+    (header startsWith:#(66 65)) ifTrue:[     "BA"
+        aStream position:1.
+        'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
+        ^ self fromOS2Stream:aStream
+    ].
+    (header startsWith:#(73 67)) ifTrue:[     "IC"
+        aStream position:1.
+        'WINREADER: OS/2 IC format' infoPrintNL.
+        ^ self fromOS2Stream:aStream
+    ].
+    (header startsWith:#(80 84)) ifTrue:[     "PT"
+        aStream position:1.
+        'WINREADER: OS/2 PT format' infoPrintNL.
+        ^ self fromOS2Stream:aStream
+    ].
+    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
+        'WINREADER: SZ format not supported:' infoPrintNL.
+        ^ nil.
+        aStream position:1.
+        'WINREADER: OS/2 PT format' infoPrintNL.
+        ^ self fromOS2Stream:aStream
+    ].
+    (header startsWith:#(0 0 1 0)) ifTrue:[
+        aStream position:1.
+        'WINREADER: Win3.x ICO format' infoPrintNL.
+        ^ self fromWindowsICOStream:aStream
+    ].
+    'WINREADER: format not supported:' infoPrint.
+    ((header at:1) printStringRadix:16) infoPrint.
+    ' ' infoPrint.
+    ((header at:2) printStringRadix:16) infoPrintNL.
+    ^ nil
+
+    "
+     Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
+    "
+
+    "Modified: 17.9.1995 / 18:59:07 / claus"
+!
+
 fromWindowsBMPFile: aFilename 
     |reader stream|
 
@@ -181,6 +344,158 @@
     ^ nil
 !
 
+fromWindowsBMPStream:aStream 
+    | fileSize header inDepth inPlanes compression
+      imgSize resH resV numColor numImportantColor
+      dataStart
+      rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
+      data4 mask tmp bytesPerRow fourBytesPerColorInfo|
+
+    inStream := aStream.
+    aStream binary.
+
+    fileSize := aStream size.
+    "read the header"
+
+    header := ByteArray uninitializedNew:16r54.
+    aStream nextBytes:18 into:header.
+
+    ((header at:(16r0E + 1)) == 40) ifTrue:[    "header-size"
+        "
+         its an Windows3.x BMP file
+         or OS/2 vsn 2 BMP file
+        "
+        'BMP: Win3.x or OS/2 vsn 2 format' infoPrintNL.
+
+        aStream nextBytes:(40-4) into:header startingAt:19.
+
+        width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
+        height := header wordAt:(16r16 + 1) MSB:false. "(header at:23) + ((header at:24) * 256).   "
+        inPlanes := header wordAt:(16r1A + 1) MSB:false.
+        inDepth := header wordAt:(16r1C + 1) MSB:false.
+        compression := header wordAt:(16r1E + 1) MSB:false.
+        imgSize := header doubleWordAt:(16r22 + 1) MSB:false.
+        resH := header doubleWordAt:(16r26 + 1) MSB:false.
+        resV := header doubleWordAt:(16r2A + 1) MSB:false.
+        numColor := header doubleWordAt:(16r2E + 1) MSB:false.
+        numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
+
+        numColor == 0 ifTrue:[
+            "
+             some bmp-writers seem to leave this as zero (which is wrong)
+            "
+            inDepth <= 8 ifTrue:[
+                numColor := 1 bitShift:inDepth.
+                'BMP: missing nColor in header - assume ' infoPrint. numColor infoPrintNL
+            ]
+        ].
+
+        numColor ~~ 0 ifTrue:[
+            rawMap := ByteArray uninitializedNew:(numColor * 4).
+            aStream nextBytes:(numColor * 4) into:rawMap.
+            fourBytesPerColorInfo := true.
+        ].
+        dataStart := header wordAt:(16r0A + 1) MSB:false
+    ] ifFalse:[
+        ((header at:(16r0E + 1)) == 12) ifTrue:[     "core-info header size"
+            "
+             its an OS/2 (vsn1.2) BMP file
+            "
+           'BMP: OS/2 vsn 1.2 format' infoPrintNL.
+            aStream nextBytes:(12-4) into:header startingAt:19.
+
+            width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
+            height := header wordAt:(16r14 + 1) MSB:false. "(header at:21) + ((header at:22) * 256).   "
+            inPlanes := header wordAt:(16r16 + 1) MSB:false.
+            inDepth := header wordAt:(16r18 + 1) MSB:false.
+            numColor := 1 bitShift:inDepth.
+            rawMap := ByteArray uninitializedNew:(numColor * 3).
+            aStream nextBytes:(numColor * 3) into:rawMap.
+            fourBytesPerColorInfo := false.
+            compression := 0.
+            dataStart := header wordAt:(16r0A + 1) MSB:false
+        ] ifFalse:[
+            'BMP: unknown format' infoPrintNL.
+            ^ nil
+        ].
+    ].
+
+    numColor ~~ 0 ifTrue:[
+        "read the colormap"
+
+        rMap := Array new:numColor.
+        gMap := Array new:numColor.
+        bMap := Array new:numColor.
+        srcIndex := 1.
+        1 to:numColor do:[:i |
+            bMap at:i put:(rawMap at:srcIndex).
+            srcIndex := srcIndex + 1.
+            gMap at:i put:(rawMap at:srcIndex).
+            srcIndex := srcIndex + 1.
+            rMap at:i put:(rawMap at:srcIndex).
+            srcIndex := srcIndex + 1.
+            fourBytesPerColorInfo ifTrue:[
+                srcIndex := srcIndex + 1.
+            ]
+        ].
+    ].
+
+    "/ check for valid compression
+
+    compression ~~ 0 ifTrue:[
+        "/ some compression
+        compression == 1 ifTrue:[
+            "/ RLE8 - must be depth-8
+            inDepth ~~ 8 ifTrue:[
+                'BMP: RLE8 compression only allowed with depth8 images' infoPrintNL.
+                ^ nil
+            ].
+        ].
+        compression == 2 ifTrue:[
+            "/ RLE4 - must be depth-4
+            inDepth ~~ 4 ifTrue:[
+                'BMP: RLE4 compression only allowed with depth4 images' infoPrintNL.
+                ^ nil
+            ].
+        ].
+    ].
+
+    inPlanes ~~ 1 ifTrue:[
+        'BMP: only 1 plane images supported' infoPrintNL.
+        ^ nil
+    ].
+
+    aStream position:(dataStart + 1).
+
+    inDepth == 24 ifTrue:[
+        bytesPerRow := width * 3
+    ] ifFalse:[
+        bytesPerRow := width
+    ].
+    data := ByteArray uninitializedNew:(height * bytesPerRow).
+
+    "/ read & possibly decompress
+
+    (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
+        ^ nil
+    ].
+
+    inDepth == 24 ifTrue:[
+        photometric := #rgb.
+        samplesPerPixel := 3.
+        bitsPerSample := #(8 8 8).
+        ^ self
+    ].
+
+    photometric := #palette.
+    samplesPerPixel := 1.
+    bitsPerSample := #(8).
+    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+
+    "Modified: 17.9.1995 / 18:48:46 / claus"
+    "Modified: 4.2.1996 / 17:57:50 / cg"
+!
+
 fromWindowsICOFile: aFilename 
     |reader stream|
 
@@ -227,13 +542,13 @@
     bMap := Array new:16.
     srcIndex := 1.
     1 to:16 do:[:i |
-	bMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-	gMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-	rMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-	srcIndex := srcIndex + 1.
+        bMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+        gMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+        rMap at:i put:(rawMap at:srcIndex).
+        srcIndex := srcIndex + 1.
+        srcIndex := srcIndex + 1.
     ].
 
     "read the data bits"
@@ -255,10 +570,10 @@
     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.
+        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
+                   with:data4 startingAt:srcIndex.
+        srcIndex := srcIndex + bytesPerRow.
+        dstIndex := dstIndex - bytesPerRow.
     ].
     data4 := tmp.
 
@@ -266,7 +581,7 @@
 
     data := ByteArray new:(width * height).
     data4 expandPixels:inDepth width:width height:height
-		  into:data mapping:nil.
+                  into:data mapping:nil.
 
     photometric := #palette.
     samplesPerPixel := 1.
@@ -276,323 +591,11 @@
     "
      WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
     "
-!
-
-fromWindowsBMPStream:aStream 
-    | fileSize header inDepth inPlanes compression
-      imgSize resH resV numColor numImportantColor
-      dataStart
-      rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
-      data4 mask tmp bytesPerRow fourBytesPerColorInfo|
-
-    inStream := aStream.
-    aStream binary.
-
-    fileSize := aStream size.
-    "read the header"
-
-    header := ByteArray uninitializedNew:16r54.
-    aStream nextBytes:18 into:header.
-
-    ((header at:(16r0E + 1)) == 40) ifTrue:[    "header-size"
-	"
-	 its an Windows3.x BMP file
-	 or OS/2 vsn 2 BMP file
-	"
-	'BMP: Win3.x or OS/2 vsn 2 format' errorPrintNL.
-
-	aStream nextBytes:(40-4) into:header startingAt:19.
-
-	width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
-	height := header wordAt:(16r16 + 1) MSB:false. "(header at:23) + ((header at:24) * 256).   "
-	inPlanes := header wordAt:(16r1A + 1) MSB:false.
-	inDepth := header wordAt:(16r1C + 1) MSB:false.
-	compression := header wordAt:(16r1E + 1) MSB:false.
-	imgSize := header doubleWordAt:(16r22 + 1) MSB:false.
-	resH := header doubleWordAt:(16r26 + 1) MSB:false.
-	resV := header doubleWordAt:(16r2A + 1) MSB:false.
-	numColor := header doubleWordAt:(16r2E + 1) MSB:false.
-	numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
-
-	numColor == 0 ifTrue:[
-	    "
-	     some bmp-writers seem to leave this as zero (which is wrong)
-	    "
-	    inDepth <= 8 ifTrue:[
-		numColor := 1 bitShift:inDepth.
-		'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
-	    ]
-	].
-
-	numColor ~~ 0 ifTrue:[
-	    rawMap := ByteArray uninitializedNew:(numColor * 4).
-	    aStream nextBytes:(numColor * 4) into:rawMap.
-	    fourBytesPerColorInfo := true.
-	].
-	dataStart := header wordAt:(16r0A + 1) MSB:false
-    ] ifFalse:[
-	((header at:(16r0E + 1)) == 12) ifTrue:[     "core-info header size"
-	    "
-	     its an OS/2 (vsn1.2) BMP file
-	    "
-	   'BMP: OS/2 vsn 1.2 format' errorPrintNL.
-	    aStream nextBytes:(12-4) into:header startingAt:19.
-
-	    width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
-	    height := header wordAt:(16r14 + 1) MSB:false. "(header at:21) + ((header at:22) * 256).   "
-	    inPlanes := header wordAt:(16r16 + 1) MSB:false.
-	    inDepth := header wordAt:(16r18 + 1) MSB:false.
-	    numColor := 1 bitShift:inDepth.
-	    rawMap := ByteArray uninitializedNew:(numColor * 3).
-	    aStream nextBytes:(numColor * 3) into:rawMap.
-	    fourBytesPerColorInfo := false.
-	    compression := 0.
-	    dataStart := header wordAt:(16r0A + 1) MSB:false
-	] ifFalse:[
-	    'BMP: unknown format' errorPrintNL.
-	    ^ nil
-	].
-    ].
+! !
 
-    numColor ~~ 0 ifTrue:[
-	"read the colormap"
-
-	rMap := Array new:numColor.
-	gMap := Array new:numColor.
-	bMap := Array new:numColor.
-	srcIndex := 1.
-	1 to:numColor do:[:i |
-	    bMap at:i put:(rawMap at:srcIndex).
-	    srcIndex := srcIndex + 1.
-	    gMap at:i put:(rawMap at:srcIndex).
-	    srcIndex := srcIndex + 1.
-	    rMap at:i put:(rawMap at:srcIndex).
-	    srcIndex := srcIndex + 1.
-	    fourBytesPerColorInfo ifTrue:[
-		srcIndex := srcIndex + 1.
-	    ]
-	].
-    ].
-
-    "/ check for valid compression
-
-    compression ~~ 0 ifTrue:[
-	"/ some compression
-	compression == 1 ifTrue:[
-	    "/ RLE8 - must be depth-8
-	    inDepth ~~ 8 ifTrue:[
-		'BMP: RLE8 compression only allowed with depth8 images' errorPrintNL.
-		^ nil
-	    ].
-	].
-	compression == 2 ifTrue:[
-	    "/ RLE4 - must be depth-4
-	    inDepth ~~ 4 ifTrue:[
-		'BMP: RLE4 compression only allowed with depth4 images' errorPrintNL.
-		^ nil
-	    ].
-	].
-    ].
-
-    inPlanes ~~ 1 ifTrue:[
-	'BMP: only 1 plane images supported' errorPrintNL.
-	^ nil
-    ].
-
-    aStream position:(dataStart + 1).
-
-    inDepth == 24 ifTrue:[
-	bytesPerRow := width * 3
-    ] ifFalse:[
-	bytesPerRow := width
-    ].
-    data := ByteArray uninitializedNew:(height * bytesPerRow).
-
-    "/ read & possibly decompress
-
-    (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
-	^ nil
-    ].
-
-    inDepth == 24 ifTrue:[
-	photometric := #rgb.
-	samplesPerPixel := 3.
-	bitsPerSample := #(8 8 8).
-	^ self
-    ].
-
-    photometric := #palette.
-    samplesPerPixel := 1.
-    bitsPerSample := #(8).
-    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
-
-    "Modified: 17.9.1995 / 18:48:46 / claus"
-    "Modified: 4.2.1996 / 17:57:50 / cg"
-!
-
-fromStream:aStream 
-    | fileSize header |
-
-    inStream := aStream.
+!WindowsIconReader class methodsFor:'documentation'!
 
-    aStream binary.
-    fileSize := aStream size.
-
-    fileSize < 16 ifTrue:[
-	'WINREADER: short file' errorPrintNL.
-	^ nil
-    ].
-
-    header := ByteArray uninitializedNew:4.
-    aStream nextBytes:4 into:header.
-
-    (header startsWith:#(66 77)) ifTrue:[     "BM"
-	aStream position:1.
-	'WINREADER: Win3.x or OS/2 vsn 2 BM format' errorPrintNL.
-	^ self fromWindowsBMPStream:aStream
-    ].
-    (header startsWith:#(66 65)) ifTrue:[     "BA"
-	aStream position:1.
-	'WINREADER: OS/2 vsn 2 BA format' errorPrintNL.
-	^ self fromOS2Stream:aStream
-    ].
-    (header startsWith:#(73 67)) ifTrue:[     "IC"
-	aStream position:1.
-	'WINREADER: OS/2 IC format' errorPrintNL.
-	^ self fromOS2Stream:aStream
-    ].
-    (header startsWith:#(80 84)) ifTrue:[     "PT"
-	aStream position:1.
-	'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:' 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 inBytesPerRow
-      data4 mask tmp bytesPerRow nColors nByte|
-
-    inStream := aStream.
-    aStream binary.
-
-    "read the header"
-
-    header := ByteArray uninitializedNew:8r110.
-    aStream nextBytes:16 into:header.
-
-    (header startsWith:#(73 67)) ifTrue:[
-	"IC format"
-	aStream nextBytes:10 into:header startingAt:17.
-	width := header at:7.
-	height := header at:9.
-	inDepth := 2 "header at:11". "where is it"
-    ] ifFalse:[
-	aStream nextBytes:(8r110-16) into:header startingAt:17.
-	width := header at:8r101.
-	height := header at:8r103.
-	inDepth := header at:8r107.
-    ].
-
-    "read the colormap"
-
-    nColors := 1 bitShift:inDepth.
-
-    rawMap := ByteArray uninitializedNew:(nColors*3).
-    aStream nextBytes:(nColors*3) into:rawMap.
-    rMap := Array new:nColors.
-    gMap := Array new:nColors.
-    bMap := Array new:nColors.
-    srcIndex := 1.
-    1 to:nColors do:[:i |
-	bMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-	gMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-	rMap at:i put:(rawMap at:srcIndex).
-	srcIndex := srcIndex + 1.
-    ].
-
-    "read mask"
-
-    nByte := width * height + 7 // 8.
-    mask := ByteArray uninitializedNew:nByte.
-    aStream nextBytes:nByte into:mask.
-
-    "what is this"
-
-    aStream nextBytes:nByte into:mask.
-
-"/    "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.
-    "/ bmp data is always 32bit aligned; if required,
-    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
-
-    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
-    (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
-	^ nil
-    ].
-    photometric := #palette.
-    samplesPerPixel := 1.
-    bitsPerSample := #(8).
-    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
-
-    "
-     |i f|
-     i := Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'.
-     f := i asFormOn:Display.
-     v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
-    "
-
-    "Modified: 17.9.1995 / 18:49:24 / claus"
+version
+    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.22 1996-03-07 18:28:20 cg Exp $'
 ! !
+WindowsIconReader initialize!