IrisRGBReader.st
changeset 2726 de3b045610a0
parent 1848 864ca2cd4e71
child 3097 b067905c1c89
--- a/IrisRGBReader.st	Fri Aug 07 17:31:40 2009 +0200
+++ b/IrisRGBReader.st	Wed Aug 19 20:25:02 2009 +0200
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libview2' }"
 
 ImageReader subclass:#IrisRGBReader
@@ -100,7 +99,7 @@
 !IrisRGBReader methodsFor:'private-reading'!
 
 readRLEData 
-    "read RLE compressed data"
+    "read RLE compressed data."
 
     |rleBufferLen tableLen startTable lengthTable rleData
      tblIdx dstIdx|
@@ -122,9 +121,9 @@
         lengthTable at:i put:(inStream nextLongMSB:true).
     ].
 
-    data := ByteArray uninitializedNew:(width*height*3).
+    data := ByteArray uninitializedNew:(width*height*bytesPerPixel).
 
-    dstIdx := width * (height-1) * 3 + 1.
+    dstIdx := width * (height-1) * bytesPerPixel + 1.
 
     0 to:(height-1) do:[:y |
         0 to:(bytesPerPixel-1) do:[:z |
@@ -145,11 +144,11 @@
 
             self class
                 decompressRLEFrom:rleData at:1 
-                into:data at:dstIdx+z increment:3.
+                into:data at:dstIdx+z increment:bytesPerPixel.
 
 "/            self expandRow:rleData to:dstIdx+z. "/ (3-z).
         ].
-        dstIdx := dstIdx - (width * 3).
+        dstIdx := dstIdx - (width * bytesPerPixel).
     ].
 
     "
@@ -162,9 +161,6 @@
 !IrisRGBReader methodsFor:'reading'!
 
 fromStream:aStream
-    "read a Portable bitmap file format as of Jeff Poskanzers Portable Bitmap Package.
-     supported are IRIS_RGB, PGB and PNM files." 
-
     | magic type dim isRLE bpp|
 
     inStream := aStream.
@@ -186,8 +182,8 @@
     bpp ~~ 1 ifTrue:[
         ^ self fileFormatError:'only 1byte/pixel channel supported'.
     ].
-    bytesPerPixel ~~ 3 ifTrue:[
-        ^ self fileFormatError:'can only read 3-channel images'.
+    (bytesPerPixel ~~ 3 and:[ bytesPerPixel ~~ 4 ]) ifTrue:[
+        ^ self fileFormatError:'can only read 3- and 4-channel images'.
     ].
 
     self reportDimension.
@@ -195,13 +191,13 @@
     isRLE ifTrue:[
         self readRLEData
     ] ifFalse:[
+        "/ self readVerbatimData
         ^ self fileFormatError:'currently, only RLE encoding supported'.
-        "/ self readVerbatimData
     ].
 
-    photometric := #rgb.
-    samplesPerPixel := 3.
-    bitsPerSample := #(8 8 8).
+    photometric := #rgba.
+    samplesPerPixel := 4.
+    bitsPerSample := #(8 8 8 8).
 
     "
      IrisRGBReader fromFile:'/home2/cg/capture.rgb'
@@ -233,7 +229,7 @@
 !IrisRGBReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.12 2003-11-19 15:38:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.13 2009-08-19 18:25:02 cg Exp $'
 ! !
 
 IrisRGBReader initialize!