WindowsIconReader.st
changeset 28 8daff0234d2e
parent 24 6bc436eb4c4a
child 32 6bdcb6da4d4f
--- a/WindowsIconReader.st	Mon Oct 10 03:32:51 1994 +0100
+++ b/WindowsIconReader.st	Mon Oct 10 03:34:22 1994 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -11,17 +11,17 @@
 "
 
 ImageReader subclass:#WindowsIconReader
-         instanceVariableNames:''
-         classVariableNames:''
-         poolDictionaries:''
-         category:'Graphics-Support'
+	 instanceVariableNames:''
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Graphics-Support'
 !
 
 WindowsIconReader comment:'
 COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.7 1994-08-05 01:16:24 claus Exp $
+$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.8 1994-10-10 02:34:13 claus Exp $
 '!
 
 !WindowsIconReader class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
 copyright
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.7 1994-08-05 01:16:24 claus Exp $
+$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.8 1994-10-10 02:34:13 claus Exp $
 "
 !
 
@@ -52,6 +52,13 @@
 "
 ! !
 
+!WindowsIconReader class methodsFor:'initialization'!
+
+initialize
+    Image fileFormats at:'.bmp'  put:self.
+    Image fileFormats at:'.ico'  put:self.
+! !
+
 !WindowsIconReader methodsFor:'reading from file'!
 
 fromOS2File: aFilename 
@@ -108,13 +115,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"
@@ -136,10 +143,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.
 
@@ -147,7 +154,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.
@@ -174,59 +181,59 @@
     inStream 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.
+	"
+	 its an Windows3.x BMP file
+	 or OS/2 vsn 2 BMP file
+	"
+	'BMP: Win3.x or OS/2 vsn 2 format' errorPrintNL.
 
-        inStream nextBytes:(40-4) into:header startingAt:19.
+	inStream nextBytes:(40-4) into:header startingAt:19.
 
-        width := header wordAt:(16r12 + 1).  "(header at:19) + ((header at:20) * 256).   "
-        height := header wordAt:(16r16 + 1). "(header at:23) + ((header at:24) * 256).   "
-        inPlanes := header wordAt:(16r1A + 1).
-        inDepth := header wordAt:(16r1C + 1).
-        compression := header wordAt:(16r1E + 1).
-        imgSize := header doubleWordAt:(16r22 + 1).
-        resH := header doubleWordAt:(16r26 + 1).
-        resV := header doubleWordAt:(16r2A + 1).
-        numColor := header doubleWordAt:(16r2E + 1).
-        numImportantColor := header doubleWordAt:(16r32 + 1).
+	width := header wordAt:(16r12 + 1).  "(header at:19) + ((header at:20) * 256).   "
+	height := header wordAt:(16r16 + 1). "(header at:23) + ((header at:24) * 256).   "
+	inPlanes := header wordAt:(16r1A + 1).
+	inDepth := header wordAt:(16r1C + 1).
+	compression := header wordAt:(16r1E + 1).
+	imgSize := header doubleWordAt:(16r22 + 1).
+	resH := header doubleWordAt:(16r26 + 1).
+	resV := header doubleWordAt:(16r2A + 1).
+	numColor := header doubleWordAt:(16r2E + 1).
+	numImportantColor := header doubleWordAt:(16r32 + 1).
 
-        numColor == 0 ifTrue:[
-            "
-             some bmp-writers seem to leave this as zero (which is wrong)
-            "
-            numColor := 1 bitShift:inDepth.
-            'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
-        ].
-        rawMap := ByteArray uninitializedNew:(numColor * 4).
-        inStream nextBytes:(numColor * 4) into:rawMap.
-        fourBytesPerColorInfo := true.
-        dataStart := header wordAt:(16r0A + 1)
+	numColor == 0 ifTrue:[
+	    "
+	     some bmp-writers seem to leave this as zero (which is wrong)
+	    "
+	    numColor := 1 bitShift:inDepth.
+	    'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
+	].
+	rawMap := ByteArray uninitializedNew:(numColor * 4).
+	inStream nextBytes:(numColor * 4) into:rawMap.
+	fourBytesPerColorInfo := true.
+	dataStart := header wordAt:(16r0A + 1)
     ] 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.
-            inStream nextBytes:(12-4) into:header startingAt:19.
+	((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.
+	    inStream nextBytes:(12-4) into:header startingAt:19.
 
-            width := header wordAt:(16r12 + 1).  "(header at:19) + ((header at:20) * 256).   "
-            height := header wordAt:(16r14 + 1). "(header at:21) + ((header at:22) * 256).   "
-            inPlanes := header wordAt:(16r16 + 1).
-            inDepth := header wordAt:(16r18 + 1).
-            numColor := 1 bitShift:inDepth.
-            rawMap := ByteArray uninitializedNew:(numColor * 3).
-            inStream nextBytes:(numColor * 3) into:rawMap.
-            fourBytesPerColorInfo := false.
-            compression := 0.
-            dataStart := header wordAt:(16r0A + 1)
-        ] ifFalse:[
-            'BMP: unknown format' errorPrintNL.
-            inStream close.
-            ^ nil
-        ].
+	    width := header wordAt:(16r12 + 1).  "(header at:19) + ((header at:20) * 256).   "
+	    height := header wordAt:(16r14 + 1). "(header at:21) + ((header at:22) * 256).   "
+	    inPlanes := header wordAt:(16r16 + 1).
+	    inDepth := header wordAt:(16r18 + 1).
+	    numColor := 1 bitShift:inDepth.
+	    rawMap := ByteArray uninitializedNew:(numColor * 3).
+	    inStream nextBytes:(numColor * 3) into:rawMap.
+	    fourBytesPerColorInfo := false.
+	    compression := 0.
+	    dataStart := header wordAt:(16r0A + 1)
+	] ifFalse:[
+	    'BMP: unknown format' errorPrintNL.
+	    inStream close.
+	    ^ nil
+	].
     ].
 
     "read the colormap"
@@ -236,15 +243,15 @@
     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.
-        ]
+	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.
+	]
     ].
 
     "
@@ -252,15 +259,15 @@
      supported
     "
     compression ~~ 0 ifTrue:[
-        'BMP compression type ' errorPrint. compression errorPrint.
-        'not supported' errorPrintNL.
-        inStream close.
-        ^ nil
+	'BMP compression type ' errorPrint. compression errorPrint.
+	'not supported' errorPrintNL.
+	inStream close.
+	^ nil
     ].
     inPlanes ~~ 1 ifTrue:[
-        'BMP only 1 plane images supported' errorPrintNL.
-        inStream close.
-        ^ nil
+	'BMP only 1 plane images supported' errorPrintNL.
+	inStream close.
+	^ nil
     ].
 
     "read the data bits"
@@ -284,10 +291,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.
 
@@ -295,7 +302,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.
@@ -314,38 +321,38 @@
     fileSize := inStream size.
 
     fileSize < 16 ifTrue:[
-        inStream close.
-        self error:'WINREADER: short file'.
-        ^ nil
+	inStream close.
+	self error:'WINREADER: short file'.
+	^ nil
     ].
 
     header := ByteArray uninitializedNew:4.
     inStream nextBytes:4 into:header.
 
     (header startsWith:#(66 77)) ifTrue:[     "BM"
-        inStream position:1.
-        'WINREADER: Win3.x or OS/2 vsn 2 BM format' errorPrintNL.
-        ^ self fromWindowsBMPStream
+	inStream position:1.
+	'WINREADER: Win3.x or OS/2 vsn 2 BM format' errorPrintNL.
+	^ self fromWindowsBMPStream
     ].
     (header startsWith:#(66 65)) ifTrue:[     "BA"
-        inStream position:1.
-        'WINREADER: OS/2 vsn 2 BA format' errorPrintNL.
-        ^ self fromOS2Stream
+	inStream position:1.
+	'WINREADER: OS/2 vsn 2 BA format' errorPrintNL.
+	^ self fromOS2Stream
     ].
     (header startsWith:#(73 67)) ifTrue:[     "IC"
-        inStream position:1.
-        'WINREADER: OS/2 IC format' errorPrintNL.
-        ^ self fromOS2Stream
+	inStream position:1.
+	'WINREADER: OS/2 IC format' errorPrintNL.
+	^ self fromOS2Stream
     ].
     (header startsWith:#(80 84)) ifTrue:[     "PT"
-        inStream position:1.
-        'WINREADER: OS/2 PT format' errorPrintNL.
-        ^ self fromOS2Stream
+	inStream position:1.
+	'WINREADER: OS/2 PT format' errorPrintNL.
+	^ self fromOS2Stream
     ].
     (header startsWith:#(0 0 1 0)) ifTrue:[
-        inStream position:1.
-        'WINREADER: Win3.x ICO format' errorPrintNL.
-        ^ self fromWindowsICOStream
+	inStream position:1.
+	'WINREADER: Win3.x ICO format' errorPrintNL.
+	^ self fromWindowsICOStream
     ].
     self error:'WINREADER: format not supported'.
     inStream close.
@@ -369,16 +376,16 @@
     inStream nextBytes:16 into:header.
 
     (header startsWith:#(73 67)) ifTrue:[
-        "IC format"
-        inStream nextBytes:10 into:header startingAt:17.
-        width := header at:7.
-        height := header at:9.
-        inDepth := 2 "header at:11". "where is it"
+	"IC format"
+	inStream nextBytes:10 into:header startingAt:17.
+	width := header at:7.
+	height := header at:9.
+	inDepth := 2 "header at:11". "where is it"
     ] ifFalse:[
-        inStream nextBytes:(8r110-16) into:header startingAt:17.
-        width := header at:8r101.
-        height := header at:8r103.
-        inDepth := header at:8r107.
+	inStream nextBytes:(8r110-16) into:header startingAt:17.
+	width := header at:8r101.
+	height := header at:8r103.
+	inDepth := header at:8r107.
     ].
 
     "read the colormap"
@@ -392,12 +399,12 @@
     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.
+	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"
@@ -422,10 +429,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.
 
@@ -433,7 +440,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.