XPMReader.st
changeset 1529 0c9e38ea3261
parent 1521 3c54279a418c
child 1650 916067641a59
--- a/XPMReader.st	Thu Nov 15 11:31:42 2001 +0100
+++ b/XPMReader.st	Thu Nov 15 12:09:54 2001 +0100
@@ -345,8 +345,13 @@
 "
     bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1.
 "
-    bitsPerPixel := 8.
-    data := ByteArray new:(width * height).
+    colorMapSize > 256 ifTrue:[
+        bitsPerPixel := 24.
+        data := ByteArray new:(width * height * 3).
+    ] ifFalse:[
+        bitsPerPixel := 8.
+        data := ByteArray new:(width * height).
+    ].
 
     dstIndex := 1.
     1 to:height do:[:row |
@@ -389,9 +394,16 @@
                         lastChar1 := c1.
                         lastChar2 := c2.
                     ].
-                    data at:dstIndex put:lastXLation.
+                    bitsPerPixel == 24 ifTrue:[
+                        data at:dstIndex   put:(colorMap at:lastXLation+1) redByte.
+                        data at:dstIndex+1 put:(colorMap at:lastXLation+1) greenByte.
+                        data at:dstIndex+2 put:(colorMap at:lastXLation+1) blueByte.
+                        dstIndex := dstIndex + 3.
+                    ] ifFalse:[
+                        data at:dstIndex put:lastXLation.
+                        dstIndex := dstIndex + 1.
+                    ].
                     srcIndex := srcIndex + 2.
-                    dstIndex := dstIndex + 1
                 ]
             ] ifFalse:[
                 s := line readStream.
@@ -410,9 +422,15 @@
         ]
     ].
 
-    photometric := #palette.
-    samplesPerPixel := 1.
-    bitsPerSample := Array with:bitsPerPixel.
+    bitsPerPixel == 24 ifTrue:[
+        photometric := #rgb.
+        samplesPerPixel := 3.
+        bitsPerSample := #(8 8 8).
+    ] ifFalse:[
+        photometric := #palette.
+        samplesPerPixel := 1.
+        bitsPerSample := Array with:bitsPerPixel.
+    ].
 
     maskPixelValue notNil ifTrue:[
         self buildMaskFromColor:maskPixelValue
@@ -554,6 +572,6 @@
 !XPMReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.46 2001-10-16 11:25:45 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.47 2001-11-15 11:09:54 penk Exp $'
 ! !
 XPMReader initialize!