XPMReader.st
changeset 509 df395b9c70c8
parent 471 350583677b5b
child 550 254480517864
--- a/XPMReader.st	Fri Apr 04 12:47:42 1997 +0200
+++ b/XPMReader.st	Fri Apr 04 15:02:02 1997 +0200
@@ -145,7 +145,7 @@
      dstIndex "{ Class: SmallInteger }"
      colorName monoName greyName grey4Name symbolicName colorMapSize redMap greenMap blueMap
      charsPerPixel xlation s bitsPerPixel char lineDone maskPixelValue
-     state|
+     state key|
 
     inStream := aStream.
 
@@ -184,16 +184,15 @@
     colorMapSize := Integer readFrom:s.
     charsPerPixel := Integer readFrom:s.
     charsPerPixel ~~ 1 ifTrue:[
-        'XPM: can only handle single-character xpm-files' errorPrintNL.
-        ^ nil
+        xlation := Dictionary new:colorMapSize.
+    ] ifFalse:[
+        xlation := Array new:256.
     ].
-    xlation := Array new:256.
 
     redMap := ByteArray new:colorMapSize.
     greenMap := ByteArray new:colorMapSize.
     blueMap := ByteArray new:colorMapSize.
     colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap.
-
     1 to:colorMapSize do:[:colorIndex |
         |index line color t word|
 
@@ -211,8 +210,13 @@
 
         s := ReadStream on:line.
         s next. "skip quote"
-        index := s next asciiValue.
-        xlation at:index put:colorIndex - 1.
+        charsPerPixel ~~ 1 ifTrue:[
+            key := s next:charsPerPixel.
+            xlation at:key put:colorIndex - 1.
+        ] ifFalse:[
+            index := s next asciiValue.
+            xlation at:index put:colorIndex - 1.
+        ].
 
         lineDone := false.
         state := nil.
@@ -345,14 +349,26 @@
             'XPM: format error (expected pixels)' errorPrintNL.
             ^ nil
         ].
-        srcIndex := 2.
-        1 to: width do:[:col |
-            |char|
+        charsPerPixel ~~ 1 ifTrue:[
+            s := line readStream.
+            s next. "/ skip dquote
+            1 to: width do:[:col |
+                |key|
 
-            char := line at:srcIndex.
-            data at:dstIndex put:(xlation at:char asciiValue).
-            srcIndex := srcIndex + 1.
-            dstIndex := dstIndex + 1
+                key := s next:charsPerPixel.
+                data at:dstIndex put:(xlation at:key).
+                dstIndex := dstIndex + 1
+            ]
+        ] ifFalse:[
+            srcIndex := 2.
+            1 to: width do:[:col |
+                |char|
+
+                char := line at:srcIndex.
+                data at:dstIndex put:(xlation at:char asciiValue).
+                srcIndex := srcIndex + 1.
+                dstIndex := dstIndex + 1
+            ]
         ]
     ].
 
@@ -374,7 +390,7 @@
     "Created: 24.9.1995 / 06:20:06 / claus"
     "Modified: 24.9.1995 / 07:07:33 / claus"
     "Modified: 5.7.1996 / 17:27:59 / stefan"
-    "Modified: 1.3.1997 / 23:14:51 / cg"
+    "Modified: 4.4.1997 / 15:01:28 / cg"
 ! !
 
 !XPMReader methodsFor:'writing to a file'!
@@ -490,6 +506,6 @@
 !XPMReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.27 1997-03-01 22:15:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.28 1997-04-04 13:02:02 cg Exp $'
 ! !
 XPMReader initialize!