TargaReader.st
changeset 1805 93f557cbe600
parent 1745 4fa0fad2a463
child 1846 d29322944b05
--- a/TargaReader.st	Mon Sep 01 11:52:06 2003 +0200
+++ b/TargaReader.st	Mon Sep 01 16:47:57 2003 +0200
@@ -159,7 +159,144 @@
     "Modified: 21.4.1997 / 20:46:52 / cg"
 ! !
 
-!TargaReader methodsFor:'reading from file'!
+!TargaReader methodsFor:'reading'!
+
+readImage
+    "read a targa-image from aFileName. return the receiver (with all
+     relevant instance variables set for the image) or nil on error"
+
+    |depth flags lenID hasColorMap imageType 
+     cmapOffset cmapLength cmapEntrySize xOrg yOrg rle|
+
+    inStream binary.
+
+    lenID := inStream next.
+    hasColorMap := inStream next.
+    imageType := inStream next.
+    cmapOffset := inStream nextShortMSB:false.
+    cmapLength := inStream nextShortMSB:false.
+    cmapEntrySize := inStream next.
+    xOrg := inStream nextShortMSB:false.
+    yOrg := inStream nextShortMSB:false.
+
+    width := inStream nextShortMSB:false.
+    height := inStream nextShortMSB:false.
+    depth := inStream next.
+    (#(8 "16" 24 32) includes:depth) ifFalse:[
+        ^ self fileFormatError:('unsupported depth: ', depth printString).
+    ].
+    depth == 32 ifTrue:[
+        'TargaReader [info]: alpha channel ignored' infoPrintCR.
+    ] ifFalse:[
+        'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
+    ].
+
+    "/ MapRGB == 1
+    "/ RawRGB == 2
+    "/ RawMono == 3
+    "/ MapEnCode == 9
+    "/ RawEnCode == 10
+
+    (#(1 2 9 10) includes:imageType) ifFalse:[
+        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
+        ^ self fileFormatError:('unsupported imageType: ', imageType printString).
+    ].
+    'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
+
+    "/ flags:
+    "/    0000 xxxx  attribute-bits-per-pixel
+    "/    0000 0001  greysc
+    "/    0000 0010  colour
+    "/    0000 0011  mapped
+    "/    0000 0100  rleEncoded
+    "/    0000 1000  interlaced
+    "/    00xx 0000  origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
+    "/    xx00 0000  interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
+    "/
+    flags := inStream next.
+
+    (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
+        ^ self fileFormatError:('unsupported interlace: ' , flags printString).
+    ].
+
+    rle := flags bitTest:2r000001000.
+    flags := flags bitAnd:2r111110111.
+
+    (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
+        ^ self fileFormatError:('unsupported flags: ' , flags printString).
+    ].
+
+    (flags bitAnd:2r00110000) == 16r20 ifTrue:[
+        orientation := #topLeft
+    ] ifFalse:[
+        (flags bitAnd:2r00110000) == 16r30 ifTrue:[
+            orientation := #topRight
+        ] ifFalse:[
+            (flags bitAnd:2r00110000) == 16r10 ifTrue:[
+                orientation := #bottomRight
+            ] ifFalse:[
+                (flags bitAnd:2r00110000) == 0 ifTrue:[
+                    orientation := #bottomLeft
+                ]
+            ]
+        ]
+    ].
+
+    lenID ~~ 0 ifTrue:[
+        inStream skip:lenID
+    ].
+
+    hasColorMap ~~ 0 ifTrue:[
+        "/ read the colorMap
+        colorMap := self readColorMap:cmapLength.
+        'TargaReader [info]: has colorMap' infoPrintCR.
+    ].
+
+    depth == 32 ifTrue:[
+        imageType == 2 ifTrue:[
+"/            rle ifTrue:[self halt:'oops - should not happen'].
+            self read32.
+        ] ifFalse:[
+"/            rle ifFalse:[self halt:'oops - should not happen'].
+            self read32RLE.
+        ].
+        bytesPerRow := width*3.
+        bytesPerPixel := 3.
+    ].
+    depth == 24 ifTrue:[
+        imageType == 2 ifTrue:[
+"/            rle ifTrue:[self halt:'oops - should not happen'].
+            self read24.
+        ] ifFalse:[
+"/            rle ifFalse:[self halt:'oops - should not happen'].
+            self read24RLE.
+        ].
+        bytesPerRow := width*3.
+        bytesPerPixel := 3.
+    ].
+    depth == 8 ifTrue:[
+        imageType == 1 ifTrue:[
+"/            rle ifTrue:[self halt:'oops - should not happen'].
+            self read8.
+        ] ifFalse:[
+"/            rle ifFalse:[self halt:'oops - should not happen'].
+            self read8RLE
+        ].
+        bytesPerRow := width.
+        bytesPerPixel := 1.
+    ].
+
+    self handleImageOrientation.
+
+    "
+     TargaReader fromFile:'bitmaps/test.tga' 
+    "
+
+    "Modified: / 7.9.1998 / 21:12:12 / cg"
+    "Modified: / 13.10.1998 / 19:50:48 / ps"
+! !
+
+!TargaReader methodsFor:'reading-private'!
 
 handleImageOrientation
     |rowIdx startIdx endIdx t|
@@ -408,147 +545,12 @@
         colorMap at:index put:(Color redByte:r greenByte:g blueByte:b).
     ].
     ^ colorMap
-!
-
-readImage
-    "read a targa-image from aFileName. return the receiver (with all
-     relevant instance variables set for the image) or nil on error"
-
-    |depth flags lenID hasColorMap imageType 
-     cmapOffset cmapLength cmapEntrySize xOrg yOrg rle|
-
-    inStream binary.
-
-    lenID := inStream next.
-    hasColorMap := inStream next.
-    imageType := inStream next.
-    cmapOffset := inStream nextShortMSB:false.
-    cmapLength := inStream nextShortMSB:false.
-    cmapEntrySize := inStream next.
-    xOrg := inStream nextShortMSB:false.
-    yOrg := inStream nextShortMSB:false.
-
-    width := inStream nextShortMSB:false.
-    height := inStream nextShortMSB:false.
-    depth := inStream next.
-    (#(8 "16" 24 32) includes:depth) ifFalse:[
-        ^ self fileFormatError:('unsupported depth: ', depth printString).
-    ].
-    depth == 32 ifTrue:[
-        'TargaReader [info]: alpha channel ignored' infoPrintCR.
-    ] ifFalse:[
-        'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
-    ].
-
-    "/ MapRGB == 1
-    "/ RawRGB == 2
-    "/ RawMono == 3
-    "/ MapEnCode == 9
-    "/ RawEnCode == 10
-
-    (#(1 2 9 10) includes:imageType) ifFalse:[
-        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
-        ^ self fileFormatError:('unsupported imageType: ', imageType printString).
-    ].
-    'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
-
-    "/ flags:
-    "/    0000 xxxx  attribute-bits-per-pixel
-    "/    0000 0001  greysc
-    "/    0000 0010  colour
-    "/    0000 0011  mapped
-    "/    0000 0100  rleEncoded
-    "/    0000 1000  interlaced
-    "/    00xx 0000  origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
-    "/    xx00 0000  interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
-    "/
-    flags := inStream next.
-
-    (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
-        ^ self fileFormatError:('unsupported interlace: ' , flags printString).
-    ].
-
-    rle := flags bitTest:2r000001000.
-    flags := flags bitAnd:2r111110111.
-
-    (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
-        ^ self fileFormatError:('unsupported flags: ' , flags printString).
-    ].
-
-    (flags bitAnd:2r00110000) == 16r20 ifTrue:[
-        orientation := #topLeft
-    ] ifFalse:[
-        (flags bitAnd:2r00110000) == 16r30 ifTrue:[
-            orientation := #topRight
-        ] ifFalse:[
-            (flags bitAnd:2r00110000) == 16r10 ifTrue:[
-                orientation := #bottomRight
-            ] ifFalse:[
-                (flags bitAnd:2r00110000) == 0 ifTrue:[
-                    orientation := #bottomLeft
-                ]
-            ]
-        ]
-    ].
-
-    lenID ~~ 0 ifTrue:[
-        inStream skip:lenID
-    ].
-
-    hasColorMap ~~ 0 ifTrue:[
-        "/ read the colorMap
-        colorMap := self readColorMap:cmapLength.
-        'TargaReader [info]: has colorMap' infoPrintCR.
-    ].
-
-    depth == 32 ifTrue:[
-        imageType == 2 ifTrue:[
-"/            rle ifTrue:[self halt:'oops - should not happen'].
-            self read32.
-        ] ifFalse:[
-"/            rle ifFalse:[self halt:'oops - should not happen'].
-            self read32RLE.
-        ].
-        bytesPerRow := width*3.
-        bytesPerPixel := 3.
-    ].
-    depth == 24 ifTrue:[
-        imageType == 2 ifTrue:[
-"/            rle ifTrue:[self halt:'oops - should not happen'].
-            self read24.
-        ] ifFalse:[
-"/            rle ifFalse:[self halt:'oops - should not happen'].
-            self read24RLE.
-        ].
-        bytesPerRow := width*3.
-        bytesPerPixel := 3.
-    ].
-    depth == 8 ifTrue:[
-        imageType == 1 ifTrue:[
-"/            rle ifTrue:[self halt:'oops - should not happen'].
-            self read8.
-        ] ifFalse:[
-"/            rle ifFalse:[self halt:'oops - should not happen'].
-            self read8RLE
-        ].
-        bytesPerRow := width.
-        bytesPerPixel := 1.
-    ].
-
-    self handleImageOrientation.
-
-    "
-     TargaReader fromFile:'bitmaps/test.tga' 
-    "
-
-    "Modified: / 7.9.1998 / 21:12:12 / cg"
-    "Modified: / 13.10.1998 / 19:50:48 / ps"
 ! !
 
 !TargaReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.22 2003-04-10 14:25:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.23 2003-09-01 14:47:27 cg Exp $'
 ! !
 
 TargaReader initialize!