--- a/XPMReader.st Wed Feb 06 17:05:30 2013 +0100
+++ b/XPMReader.st Fri Feb 08 13:49:41 2013 +0100
@@ -369,7 +369,9 @@
srcIndex "{ Class: SmallInteger }"
dstIndex "{ Class: SmallInteger }"
colorMapSize
- s bitsPerPixel key lastKey lastChar1 lastChar2 c1 c2 lastXLation|
+ s bitsPerPixel bytesPerPixel
+ key lastKey lastChar1 lastChar2
+ c1 c2 lastXLation clr|
line := inStream nextLine.
(line notNil and:[line startsWith:'/* XPM']) ifFalse:[
@@ -421,13 +423,19 @@
"
bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1.
"
- colorMapSize > 256 ifTrue:[
- bitsPerPixel := 24.
- data := ByteArray new:(width * height * 3).
+ colorMapSize > 16r100 ifTrue:[
+ colorMapSize > 16r10000 ifTrue:[
+ bitsPerPixel := 24.
+ bytesPerPixel := 3.
+ ] ifFalse:[
+ bitsPerPixel := 16.
+ bytesPerPixel := 2.
+ ].
] ifFalse:[
bitsPerPixel := 8.
- data := ByteArray new:(width * height).
+ bytesPerPixel := 1.
].
+ data := ByteArray new:(width * bytesPerPixel * height).
dstIndex := 1.
1 to:height do:[:row |
@@ -470,14 +478,21 @@
lastChar1 := c1.
lastChar2 := c2.
].
- 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:[
+ bitsPerPixel == 8 ifTrue:[
data at:dstIndex put:lastXLation.
dstIndex := dstIndex + 1.
+ ] ifFalse:[
+ bitsPerPixel == 16 ifTrue:[
+ data at:dstIndex put:(lastXLation bitAnd:16rFF).
+ data at:dstIndex+1 put:((lastXLation bitShift:-8) bitAnd:16rFF).
+ dstIndex := dstIndex + 2.
+ ] ifFalse:[
+ clr := colorMap at:lastXLation+1.
+ data at:dstIndex put:clr redByte.
+ data at:dstIndex+1 put:clr greenByte.
+ data at:dstIndex+2 put:clr blueByte.
+ dstIndex := dstIndex + 3.
+ ]
].
srcIndex := srcIndex + 2.
]
@@ -633,11 +648,11 @@
!XPMReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.64 2009-11-19 15:22:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.65 2013-02-08 12:49:41 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.64 2009-11-19 15:22:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.65 2013-02-08 12:49:41 cg Exp $'
! !
XPMReader initialize!