XPMReader.st
changeset 316 d39f3f8f7627
parent 259 62b1bbafd9ba
child 384 f139a7fc423b
--- a/XPMReader.st	Fri Jul 05 23:07:28 1996 +0200
+++ b/XPMReader.st	Fri Jul 05 23:09:05 1996 +0200
@@ -17,7 +17,7 @@
 	category:'Graphics-Images-Support'
 !
 
-!XPMReader class methodsFor:'documentation'!
+!XPMReader  class methodsFor:'documentation'!
 
 copyright
 "
@@ -48,8 +48,6 @@
 
         Can only handle single-character index.
 
-        Does not (currently) handle none-colors (i.e. for image-masks).
-
         Only understands single-word color names (i.e. names with spaces 
         are not supported)
 
@@ -66,7 +64,7 @@
 "
 ! !
 
-!XPMReader class methodsFor:'initialization'!
+!XPMReader  class methodsFor:'initialization'!
 
 initialize
     "tell Image-class, that a new fileReader is present
@@ -75,7 +73,7 @@
     Image fileFormats at:'.xpm'  put:self.
 ! !
 
-!XPMReader class methodsFor:'testing'!
+!XPMReader  class methodsFor:'testing'!
 
 isValidImageFile:aFileName
     "return true, if aFileName contains an x-bitmap-file image"
@@ -127,34 +125,34 @@
      srcIndex "{ Class: SmallInteger }"
      dstIndex "{ Class: SmallInteger }"
      colorName colorMapSize redMap greenMap blueMap
-     charsPerPixel xlation s bitsPerPixel char lineDone|
+     charsPerPixel xlation s bitsPerPixel char lineDone maskPixelValue|
 
     inStream := aStream.
 
     line := aStream nextLine.
     (line notNil and:[line startsWith:'/* XPM']) ifFalse:[
-	'XPM: format error (expected XPM)' errorPrintNL.
-	^ nil
+        'XPM: format error (expected XPM)' errorPrintNL.
+        ^ nil
     ].
 
     line := aStream nextLine.
     [line notNil and:[(line startsWith:'/*') or:[line isBlank]]] whileTrue:[
-	line := aStream nextLine.
+        line := aStream nextLine.
     ].
     (line notNil and:[line startsWith:'static char']) ifFalse:[
-	'XPM: format error (expected static char)' errorPrintNL.
-	^ nil
+        'XPM: format error (expected static char)' errorPrintNL.
+        ^ nil
     ].
     line := aStream nextLine.
     (line notNil and:[line startsWith:'/*']) ifTrue:[
-	[line notNil 
-	 and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[
-	    line := aStream nextLine.
-	].
+        [line notNil 
+         and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[
+            line := aStream nextLine.
+        ].
     ].
     (line notNil and:[line startsWith:'"']) ifFalse:[
-	'XPM: format error (expected "ww hh nn mm)' errorPrintNL.
-	^ nil
+        'XPM: format error (expected "ww hh nn mm)' errorPrintNL.
+        ^ nil
     ].
     s := ReadStream on:line.
     s next.  "skip quote"
@@ -163,8 +161,8 @@
     colorMapSize := Integer readFrom:s.
     charsPerPixel := Integer readFrom:s.
     charsPerPixel ~~ 1 ifTrue:[
-	'XPM: can only handle single-character xpm-files' errorPrintNL.
-	^ nil
+        'XPM: can only handle single-character xpm-files' errorPrintNL.
+        ^ nil
     ].
     xlation := Array new:256.
 
@@ -174,89 +172,89 @@
     colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap.
 
     1 to:colorMapSize do:[:colorIndex |
-	|index line color t|
+        |index line color t|
 
-	line := aStream nextLine.
-	[line notNil and:[line startsWith:'/*']] whileTrue:[
-	    line := aStream nextLine.
-	].
-	(line notNil and:[line startsWith:'"']) ifFalse:[
-	    'XPM: format error (expected color spec)' errorPrintNL.
-	    ^ nil
-	].
+        line := aStream nextLine.
+        [line notNil and:[line startsWith:'/*']] whileTrue:[
+            line := aStream nextLine.
+        ].
+        (line notNil and:[line startsWith:'"']) ifFalse:[
+            'XPM: format error (expected color spec)' errorPrintNL.
+            ^ nil
+        ].
 
-	s := ReadStream on:line.
-	s next. "skip quote"
-	index := s next asciiValue.
-	xlation at:index put:colorIndex - 1.
+        s := ReadStream on:line.
+        s next. "skip quote"
+        index := s next asciiValue.
+        xlation at:index put:colorIndex - 1.
 
-	lineDone := false.
-	[lineDone] whileFalse:[
-	    s skipSeparators.
-	    char := s peek.
-	    char == $" ifTrue:[
-		lineDone := true
-	    ] ifFalse:[
-		char == $s ifTrue:[
-		    "
-		     symbolic name
-		    "
-		    s next.
-		    s skipSeparators.
-		    self colorNameFrom:s.  
-		    s skipSeparators.
-		] ifFalse:[
-		    char == $m ifTrue:[
-			"
-			 monochrome data
-			"
-			s next.
-			s skipSeparators.
-			self colorNameFrom:s.
-			s skipSeparators.
-		    ] ifFalse:[
-			(char == $g) ifTrue:[
-			    "
-			     greyscale data
-			    "
-			    s next.
-			    s peek == 4 ifTrue:[s next].
-			    s skipSeparators.
-			    self colorNameFrom:s.
-			    s skipSeparators.
-			] ifFalse:[
-			    (char == $c) ifTrue:[
-				"
-				 color data
-				"
-				s next.
-				s skipSeparators.
-				colorName := self colorNameFrom:s.
-				s skipSeparators.
-			    ] ifFalse:[
-				'XPM: format error got: ' errorPrint.
+        lineDone := false.
+        [lineDone] whileFalse:[
+            s skipSeparators.
+            char := s peek.
+            char == $" ifTrue:[
+                lineDone := true
+            ] ifFalse:[
+                char == $s ifTrue:[
+                    "
+                     symbolic name
+                    "
+                    s next.
+                    s skipSeparators.
+                    self colorNameFrom:s.  
+                    s skipSeparators.
+                ] ifFalse:[
+                    char == $m ifTrue:[
+                        "
+                         monochrome data
+                        "
+                        s next.
+                        s skipSeparators.
+                        self colorNameFrom:s.
+                        s skipSeparators.
+                    ] ifFalse:[
+                        (char == $g) ifTrue:[
+                            "
+                             greyscale data
+                            "
+                            s next.
+                            s peek == 4 ifTrue:[s next].
+                            s skipSeparators.
+                            self colorNameFrom:s.
+                            s skipSeparators.
+                        ] ifFalse:[
+                            (char == $c) ifTrue:[
+                                "
+                                 color data
+                                "
+                                s next.
+                                s skipSeparators.
+                                colorName := self colorNameFrom:s.
+                                s skipSeparators.
+                            ] ifFalse:[
+                                'XPM: format error got: ' errorPrint.
 "/                                char errorPrint. '(' errorPrint. char asciiValue printString errorPrint.
 "/                                '); ' errorPrint.
-				 '(expected ''c'',''m'',''g'' or ''s'')' errorPrintNL.
-				^ nil
-			    ].
-			]
-		    ]
-		]
-	    ].
-	].
-	((colorName = 'none') or:[colorName = 'None']) ifTrue:[
-	    "mhmh must add mask to Image-instances soon ..."
-	    color := Color noColor. "/ white
-	    redMap at:colorIndex put:0.
-	    greenMap at:colorIndex put:0.
-	    blueMap at:colorIndex put:0.
-	] ifFalse:[
-	    color := Color name:colorName.
-	    redMap at:colorIndex put:(color red asFloat * 255.0 // 100).
-	    greenMap at:colorIndex put:(color green asFloat * 255.0 // 100).
-	    blueMap at:colorIndex put:(color blue asFloat * 255.0 // 100).
-	].
+                                 '(expected ''c'',''m'',''g'' or ''s'')' errorPrintNL.
+                                ^ nil
+                            ].
+                        ]
+                    ]
+                ]
+            ].
+        ].
+        ((colorName = 'none') or:[colorName = 'None']) ifTrue:[
+            color := Color noColor. "/ white
+            redMap at:colorIndex put:0.
+            greenMap at:colorIndex put:0.
+            blueMap at:colorIndex put:0.
+            maskPixelValue := colorIndex-1.
+        ] ifFalse:[
+            color := Color name:colorName.
+            redMap at:colorIndex put:(color red asFloat * 255.0 // 100).
+            greenMap at:colorIndex put:(color green asFloat * 255.0 // 100).
+            blueMap at:colorIndex put:(color blue asFloat * 255.0 // 100).
+        ].
     ].
 
     "actually, could make it an image with less depth most of the time ..."
@@ -269,29 +267,33 @@
 
     dstIndex := 1.
     1 to:height do:[:row |
-	line := aStream nextLine withoutSpaces.
-	[line notNil and:[line startsWith:'/*']] whileTrue:[
-	    line := aStream nextLine withoutSpaces.
-	].
-	(line notNil and:[line startsWith:'"']) ifFalse:[
-	    'XPM: format error (expected pixels)' errorPrintNL.
-	    ^ nil
-	].
-	srcIndex := 2.
-	1 to: width do:[:col |
-	    |char|
+        line := aStream nextLine withoutSpaces.
+        [line notNil and:[line startsWith:'/*']] whileTrue:[
+            line := aStream nextLine withoutSpaces.
+        ].
+        (line notNil and:[line startsWith:'"']) ifFalse:[
+            'XPM: format error (expected pixels)' errorPrintNL.
+            ^ nil
+        ].
+        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
-	]
+            char := line at:srcIndex.
+            data at:dstIndex put:(xlation at:char asciiValue).
+            srcIndex := srcIndex + 1.
+            dstIndex := dstIndex + 1
+        ]
     ].
 
     photometric := #palette.
     samplesPerPixel := 1.
     bitsPerSample := Array with:bitsPerPixel.
 
+    maskPixelValue notNil ifTrue:[
+        self buildMaskFromColor:maskPixelValue
+    ].
+
     "
      XPMReader fromStream:('bitmaps/ljet.xpm' asFilename readStream)
      XPMReader fromStream:('bitmaps/magtape.xpm' asFilename readStream)
@@ -301,11 +303,12 @@
 
     "Created: 24.9.1995 / 06:20:06 / claus"
     "Modified: 24.9.1995 / 07:07:33 / claus"
+    "Modified: 5.7.1996 / 17:27:59 / stefan"
 ! !
 
-!XPMReader class methodsFor:'documentation'!
+!XPMReader  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.17 1996-05-10 16:46:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.18 1996-07-05 21:09:05 stefan Exp $'
 ! !
 XPMReader initialize!