--- a/AVIReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/AVIReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -471,40 +471,7 @@
"Modified: 5.4.1997 / 14:47:41 / cg"
! !
-!AVIReader methodsFor:'reading'!
-
-fromStream:aStream
- "read a AVI-movie from aStream. Return a frame sequence."
-
- inStream := aStream.
-
- riffReader := RIFFReader new.
- riffReader client:self.
- riffReader processStream:inStream.
-
- "/ return the first frame as image
-
- "/ ATTENTION: the following is not true:
-
- colorMap := MappedPalette
- redVector:redPalette
- greenVector:greenPalette
- blueVector:bluePalette.
-
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerSample := #(8).
-
- "
- AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi'.
- AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/hangldm.avi'.
- "
-
- "Created: 4.4.1997 / 22:35:53 / cg"
- "Modified: 24.6.1997 / 15:58:29 / cg"
-! !
-
-!AVIReader methodsFor:'reading-private'!
+!AVIReader methodsFor:'private-reading'!
getChunk_ISBJ:chunkSize
"process (ignore) a ISBJ chunk"
@@ -1299,10 +1266,43 @@
riffReader skipChunk:chunkSize
! !
+!AVIReader methodsFor:'reading'!
+
+fromStream:aStream
+ "read a AVI-movie from aStream. Return a frame sequence."
+
+ inStream := aStream.
+
+ riffReader := RIFFReader new.
+ riffReader client:self.
+ riffReader processStream:inStream.
+
+ "/ return the first frame as image
+
+ "/ ATTENTION: the following is not true:
+
+ colorMap := MappedPalette
+ redVector:redPalette
+ greenVector:greenPalette
+ blueVector:bluePalette.
+
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := #(8).
+
+ "
+ AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi'.
+ AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/hangldm.avi'.
+ "
+
+ "Created: 4.4.1997 / 22:35:53 / cg"
+ "Modified: 24.6.1997 / 15:58:29 / cg"
+! !
+
!AVIReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/AVIReader.st,v 1.13 2003-11-19 15:33:55 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/AVIReader.st,v 1.14 2003-11-19 15:38:28 cg Exp $'
! !
AVIReader initialize!
--- a/IrisRGBReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/IrisRGBReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -97,59 +97,7 @@
"Modified: 14.4.1997 / 16:51:58 / cg"
! !
-!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.
- inStream binary.
-
- magic := inStream nextShortMSB:true.
- magic ~~ 8r0732 ifTrue:[
- ^ self fileFormatError:'bad magic number'.
- ].
-
- type := inStream nextShortMSB:true.
- dim := inStream nextShortMSB:true.
- width := inStream nextShortMSB:true.
- height := inStream nextShortMSB:true.
- bytesPerPixel := inStream nextShortMSB:true.
-
- isRLE := (type bitAnd:16rFF00) == 16r0100.
- bpp := type bitAnd:16r00FF.
- bpp ~~ 1 ifTrue:[
- ^ self fileFormatError:'only 1byte/pixel channel supported'.
- ].
- bytesPerPixel ~~ 3 ifTrue:[
- ^ self fileFormatError:'can only read 3-channel images'.
- ].
-
- self reportDimension.
-
- isRLE ifTrue:[
- self readRLEData
- ] ifFalse:[
- ^ self fileFormatError:'currently, only RLE encoding supported'.
- "/ self readVerbatimData
- ].
-
- photometric := #rgb.
- samplesPerPixel := 3.
- bitsPerSample := #(8 8 8).
-
- "
- IrisRGBReader fromFile:'/home2/cg/capture.rgb'
- "
-
- "Created: / 14.4.1997 / 15:38:51 / cg"
- "Modified: / 1.4.1998 / 14:28:51 / cg"
-! !
-
-!IrisRGBReader methodsFor:'reading-private'!
+!IrisRGBReader methodsFor:'private-reading'!
readRLEData
"read RLE compressed data"
@@ -211,6 +159,58 @@
"Modified: 23.4.1997 / 18:59:11 / cg"
! !
+!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.
+ inStream binary.
+
+ magic := inStream nextShortMSB:true.
+ magic ~~ 8r0732 ifTrue:[
+ ^ self fileFormatError:'bad magic number'.
+ ].
+
+ type := inStream nextShortMSB:true.
+ dim := inStream nextShortMSB:true.
+ width := inStream nextShortMSB:true.
+ height := inStream nextShortMSB:true.
+ bytesPerPixel := inStream nextShortMSB:true.
+
+ isRLE := (type bitAnd:16rFF00) == 16r0100.
+ bpp := type bitAnd:16r00FF.
+ bpp ~~ 1 ifTrue:[
+ ^ self fileFormatError:'only 1byte/pixel channel supported'.
+ ].
+ bytesPerPixel ~~ 3 ifTrue:[
+ ^ self fileFormatError:'can only read 3-channel images'.
+ ].
+
+ self reportDimension.
+
+ isRLE ifTrue:[
+ self readRLEData
+ ] ifFalse:[
+ ^ self fileFormatError:'currently, only RLE encoding supported'.
+ "/ self readVerbatimData
+ ].
+
+ photometric := #rgb.
+ samplesPerPixel := 3.
+ bitsPerSample := #(8 8 8).
+
+ "
+ IrisRGBReader fromFile:'/home2/cg/capture.rgb'
+ "
+
+ "Created: / 14.4.1997 / 15:38:51 / cg"
+ "Modified: / 1.4.1998 / 14:28:51 / cg"
+! !
+
!IrisRGBReader methodsFor:'testing '!
canRepresent:anImage
@@ -233,7 +233,7 @@
!IrisRGBReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.11 2003-11-19 15:27:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.12 2003-11-19 15:38:49 cg Exp $'
! !
IrisRGBReader initialize!
--- a/PBMReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/PBMReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -114,6 +114,82 @@
"Modified: / 7.12.1998 / 14:27:11 / cg"
! !
+!PBMReader methodsFor:'private-reading'!
+
+readMaxVal
+ self skipPBMJunk.
+ maxVal := Integer readFrom:inStream onError:nil.
+ (maxVal isNil or:[maxVal >= 256]) ifTrue: [
+ self fileFormatError:'Invalid format'.
+ ^ false.
+ ].
+ ^ true
+!
+
+readWidthAndHeight
+ self skipPBMJunk.
+ width := Integer readFrom:inStream onError:0.
+ width > 0 ifFalse: [
+ self fileFormatError:'Invalid width'.
+ ^ false
+ ].
+
+ self skipPBMJunk.
+ height := Integer readFrom:inStream onError:0.
+ height > 0 ifFalse: [
+ self fileFormatError:'Invalid height'.
+ ^ false
+ ].
+
+ self reportDimension.
+ ^ true
+!
+
+readWidthAndHeightAndMaxVal
+ (self readWidthAndHeight) ifFalse:[ ^ false ].
+ ^ self readMaxVal
+!
+
+skipPBMJunk
+ "this method removes any superfluous characters from the input stream."
+
+ | char foundNL|
+
+ [
+ char := inStream peek.
+ [char == $#] whileTrue:[
+ "Start of a comment. Skip to end-of-line."
+"/ foundNL := (aStream skipUpTo: Character cr) notNil.
+ foundNL := (inStream skipThrough: Character cr) notNil.
+ foundNL ifFalse: [
+ "Must be EOF"
+ ^self
+ ].
+ char := inStream peek
+ ].
+ inStream atEnd not and: [char isSeparator]
+ ] whileTrue: [inStream next]
+
+ "Created: / 3.2.1998 / 17:20:37 / cg"
+ "Modified: / 7.9.1998 / 15:49:07 / cg"
+! !
+
+!PBMReader methodsFor:'private-writing'!
+
+writeCommonHeader:format on:aStream
+ "common header for P4, P5 and P5 formats"
+
+ aStream nextPutAll:format; cr.
+ aStream nextPutAll:'# From Smalltalk/X on '.
+ aStream nextPutAll:(Date today printString).
+ aStream nextPutAll:' at '; nextPutAll:(Time now printString).
+ aStream cr.
+ aStream nextPutAll:(width printString); space; nextPutAll:(height printString).
+
+ "Created: / 14.10.1997 / 20:01:05 / cg"
+ "Modified: / 1.4.1998 / 14:30:47 / cg"
+! !
+
!PBMReader methodsFor:'reading'!
fromStream:aStream
@@ -326,66 +402,6 @@
"Modified: / 7.9.1998 / 15:50:36 / cg"
! !
-!PBMReader methodsFor:'reading-private'!
-
-readMaxVal
- self skipPBMJunk.
- maxVal := Integer readFrom:inStream onError:nil.
- (maxVal isNil or:[maxVal >= 256]) ifTrue: [
- self fileFormatError:'Invalid format'.
- ^ false.
- ].
- ^ true
-!
-
-readWidthAndHeight
- self skipPBMJunk.
- width := Integer readFrom:inStream onError:0.
- width > 0 ifFalse: [
- self fileFormatError:'Invalid width'.
- ^ false
- ].
-
- self skipPBMJunk.
- height := Integer readFrom:inStream onError:0.
- height > 0 ifFalse: [
- self fileFormatError:'Invalid height'.
- ^ false
- ].
-
- self reportDimension.
- ^ true
-!
-
-readWidthAndHeightAndMaxVal
- (self readWidthAndHeight) ifFalse:[ ^ false ].
- ^ self readMaxVal
-!
-
-skipPBMJunk
- "this method removes any superfluous characters from the input stream."
-
- | char foundNL|
-
- [
- char := inStream peek.
- [char == $#] whileTrue:[
- "Start of a comment. Skip to end-of-line."
-"/ foundNL := (aStream skipUpTo: Character cr) notNil.
- foundNL := (inStream skipThrough: Character cr) notNil.
- foundNL ifFalse: [
- "Must be EOF"
- ^self
- ].
- char := inStream peek
- ].
- inStream atEnd not and: [char isSeparator]
- ] whileTrue: [inStream next]
-
- "Created: / 3.2.1998 / 17:20:37 / cg"
- "Modified: / 7.9.1998 / 15:49:07 / cg"
-! !
-
!PBMReader methodsFor:'writing'!
save:image onStream:aStream
@@ -542,26 +558,10 @@
"Modified: 14.10.1997 / 20:07:08 / cg"
! !
-!PBMReader methodsFor:'writing-private'!
-
-writeCommonHeader:format on:aStream
- "common header for P4, P5 and P5 formats"
-
- aStream nextPutAll:format; cr.
- aStream nextPutAll:'# From Smalltalk/X on '.
- aStream nextPutAll:(Date today printString).
- aStream nextPutAll:' at '; nextPutAll:(Time now printString).
- aStream cr.
- aStream nextPutAll:(width printString); space; nextPutAll:(height printString).
-
- "Created: / 14.10.1997 / 20:01:05 / cg"
- "Modified: / 1.4.1998 / 14:30:47 / cg"
-! !
-
!PBMReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.41 2003-11-19 15:27:07 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.42 2003-11-19 15:38:51 cg Exp $'
! !
PBMReader initialize!
--- a/PCXReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/PCXReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -112,26 +112,7 @@
"Modified: 16.4.1997 / 22:24:32 / cg"
! !
-!PCXReader methodsFor:'reading'!
-
-readImage
- "read an image in pcx format from inStream"
-
- inStream binary.
-
- header := ByteArray uninitializedNew:128.
- (inStream nextBytes:128 into:header) == 128 ifFalse:[
- ^ self fileFormatError:'short file'.
- ].
-
- (self class isValidPCXHeader:header) ifFalse:[
- ^ self fileFormatError:'wrong header'.
- ].
-
- self readRestAfterHeader.
-! !
-
-!PCXReader methodsFor:'reading-private'!
+!PCXReader methodsFor:'private-reading'!
extractColorMap16
"extract the 16-entry colormap from the header"
@@ -359,10 +340,29 @@
nBuffer := 0.
! !
+!PCXReader methodsFor:'reading'!
+
+readImage
+ "read an image in pcx format from inStream"
+
+ inStream binary.
+
+ header := ByteArray uninitializedNew:128.
+ (inStream nextBytes:128 into:header) == 128 ifFalse:[
+ ^ self fileFormatError:'short file'.
+ ].
+
+ (self class isValidPCXHeader:header) ifFalse:[
+ ^ self fileFormatError:'wrong header'.
+ ].
+
+ self readRestAfterHeader.
+! !
+
!PCXReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.32 2003-11-19 15:26:45 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.33 2003-11-19 15:38:20 cg Exp $'
! !
PCXReader initialize!
--- a/PNGReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/PNGReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -319,6 +319,64 @@
"Created: 21.6.1996 / 21:15:58 / cg"
! !
+!PNGReader methodsFor:'private-reading'!
+
+setColorType:colorType
+ colorType == 0 ifTrue:[
+ photometric := #blackIs0.
+ samplesPerPixel := 1.
+ bitsPerSample := Array with:depth.
+ ^ true.
+ ].
+
+ colorType == 2 ifTrue:[
+ depth < 8 ifTrue:[
+ 'PNGReader: invalid colorType/depth combination' infoPrintCR.
+ ^ false.
+ ].
+ photometric := #rgb.
+ samplesPerPixel := 3.
+ bitsPerSample := Array with:depth with:depth with:depth.
+ ^ true.
+ ].
+
+ colorType == 3 ifTrue:[
+ depth == 16 ifTrue:[
+ 'PNGReader: invalid colorType/depth combination' infoPrintCR.
+ ^ false.
+ ].
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := Array with:depth.
+ ^ true.
+ ].
+
+ colorType == 4 ifTrue:[
+ depth < 8 ifTrue:[
+ 'PNGReader: invalid colorType/depth combination' infoPrintCR.
+ ^ false.
+ ].
+ photometric := #blackIs0.
+ samplesPerPixel := 2.
+ bitsPerSample := Array with:depth with:depth.
+ ^ true.
+ ].
+
+ colorType == 6 ifTrue:[
+ depth < 8 ifTrue:[
+ 'PNGReader: invalid colorType/depth combination' infoPrintCR.
+ ^ false.
+ ].
+ photometric := #rgb.
+ samplesPerPixel := 4.
+ bitsPerSample := Array with:depth with:depth with:depth with:depth.
+ ^ true.
+ ].
+
+ ('PNGReader: invalid colorType: ' , colorType printString , '.') infoPrintCR.
+ ^ false
+! !
+
!PNGReader methodsFor:'reading'!
fromStream:aStream
@@ -383,68 +441,10 @@
"Modified: 21.6.1996 / 21:44:34 / cg"
! !
-!PNGReader methodsFor:'reading-private'!
-
-setColorType:colorType
- colorType == 0 ifTrue:[
- photometric := #blackIs0.
- samplesPerPixel := 1.
- bitsPerSample := Array with:depth.
- ^ true.
- ].
-
- colorType == 2 ifTrue:[
- depth < 8 ifTrue:[
- 'PNGReader: invalid colorType/depth combination' infoPrintCR.
- ^ false.
- ].
- photometric := #rgb.
- samplesPerPixel := 3.
- bitsPerSample := Array with:depth with:depth with:depth.
- ^ true.
- ].
-
- colorType == 3 ifTrue:[
- depth == 16 ifTrue:[
- 'PNGReader: invalid colorType/depth combination' infoPrintCR.
- ^ false.
- ].
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerSample := Array with:depth.
- ^ true.
- ].
-
- colorType == 4 ifTrue:[
- depth < 8 ifTrue:[
- 'PNGReader: invalid colorType/depth combination' infoPrintCR.
- ^ false.
- ].
- photometric := #blackIs0.
- samplesPerPixel := 2.
- bitsPerSample := Array with:depth with:depth.
- ^ true.
- ].
-
- colorType == 6 ifTrue:[
- depth < 8 ifTrue:[
- 'PNGReader: invalid colorType/depth combination' infoPrintCR.
- ^ false.
- ].
- photometric := #rgb.
- samplesPerPixel := 4.
- bitsPerSample := Array with:depth with:depth with:depth with:depth.
- ^ true.
- ].
-
- ('PNGReader: invalid colorType: ' , colorType printString , '.') infoPrintCR.
- ^ false
-! !
-
!PNGReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.9 2003-11-19 15:26:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.10 2003-11-19 15:38:33 cg Exp $'
! !
PNGReader initialize!
--- a/TargaReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/TargaReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -159,146 +159,7 @@
"Modified: 21.4.1997 / 20:46:52 / cg"
! !
-!TargaReader methodsFor:'reading'!
-
-readImage
- "read a targa-image from aFileName. return the receiver (with all
- relevant instance variables set for the image) or nil on error"
-
- |depth flags lenID hasColorMap imageType
- cmapOffset cmapLength cmapEntrySize xOrg yOrg rle|
-
- inStream binary.
-
- lenID := inStream next.
- hasColorMap := inStream next.
- imageType := inStream next.
- cmapOffset := inStream nextShortMSB:false.
- cmapLength := inStream nextShortMSB:false.
- cmapEntrySize := inStream next.
- xOrg := inStream nextShortMSB:false.
- yOrg := inStream nextShortMSB:false.
-
- width := inStream nextShortMSB:false.
- height := inStream nextShortMSB:false.
- depth := inStream next.
- (#(8 "16" 24 32) includes:depth) ifFalse:[
- ^ self fileFormatError:('unsupported depth: ', depth printString).
- ].
- depth == 32 ifTrue:[
- 'TargaReader [info]: alpha channel ignored' infoPrintCR.
- ] ifFalse:[
- 'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
- ].
-
- "/ MapRGB == 1
- "/ RawRGB == 2
- "/ RawMono == 3
- "/ MapEnCode == 9
- "/ RawEnCode == 10
-
- (#(1 2 9 10) includes:imageType) ifFalse:[
- "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
- ^ self fileFormatError:('unsupported imageType: ', imageType printString).
- ].
- 'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
-
- self reportDimension.
-
- "/ flags:
- "/ 0000 xxxx attribute-bits-per-pixel
- "/ 0000 0001 greysc
- "/ 0000 0010 colour
- "/ 0000 0011 mapped
- "/ 0000 0100 rleEncoded
- "/ 0000 1000 interlaced
- "/ 00xx 0000 origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
- "/ xx00 0000 interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
- "/
- flags := inStream next.
-
- (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
- ^ self fileFormatError:('unsupported interlace: ' , flags printString).
- ].
-
- rle := flags bitTest:2r000001000.
- flags := flags bitAnd:2r111110111.
-
- (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
- ^ self fileFormatError:('unsupported flags: ' , flags printString).
- ].
-
- (flags bitAnd:2r00110000) == 16r20 ifTrue:[
- orientation := #topLeft
- ] ifFalse:[
- (flags bitAnd:2r00110000) == 16r30 ifTrue:[
- orientation := #topRight
- ] ifFalse:[
- (flags bitAnd:2r00110000) == 16r10 ifTrue:[
- orientation := #bottomRight
- ] ifFalse:[
- (flags bitAnd:2r00110000) == 0 ifTrue:[
- orientation := #bottomLeft
- ]
- ]
- ]
- ].
-
- lenID ~~ 0 ifTrue:[
- inStream skip:lenID
- ].
-
- hasColorMap ~~ 0 ifTrue:[
- "/ read the colorMap
- colorMap := self readColorMap:cmapLength.
- 'TargaReader [info]: has colorMap' infoPrintCR.
- ].
-
- depth == 32 ifTrue:[
- imageType == 2 ifTrue:[
-"/ rle ifTrue:[self halt:'oops - should not happen'].
- self read32.
- ] ifFalse:[
-"/ rle ifFalse:[self halt:'oops - should not happen'].
- self read32RLE.
- ].
- bytesPerRow := width*3.
- bytesPerPixel := 3.
- ].
- depth == 24 ifTrue:[
- imageType == 2 ifTrue:[
-"/ rle ifTrue:[self halt:'oops - should not happen'].
- self read24.
- ] ifFalse:[
-"/ rle ifFalse:[self halt:'oops - should not happen'].
- self read24RLE.
- ].
- bytesPerRow := width*3.
- bytesPerPixel := 3.
- ].
- depth == 8 ifTrue:[
- imageType == 1 ifTrue:[
-"/ rle ifTrue:[self halt:'oops - should not happen'].
- self read8.
- ] ifFalse:[
-"/ rle ifFalse:[self halt:'oops - should not happen'].
- self read8RLE
- ].
- bytesPerRow := width.
- bytesPerPixel := 1.
- ].
-
- self handleImageOrientation.
-
- "
- TargaReader fromFile:'bitmaps/test.tga'
- "
-
- "Modified: / 7.9.1998 / 21:12:12 / cg"
- "Modified: / 13.10.1998 / 19:50:48 / ps"
-! !
-
-!TargaReader methodsFor:'reading-private'!
+!TargaReader methodsFor:'private-reading'!
handleImageOrientation
|rowIdx startIdx endIdx t|
@@ -549,10 +410,149 @@
^ colorMap
! !
+!TargaReader methodsFor:'reading'!
+
+readImage
+ "read a targa-image from aFileName. return the receiver (with all
+ relevant instance variables set for the image) or nil on error"
+
+ |depth flags lenID hasColorMap imageType
+ cmapOffset cmapLength cmapEntrySize xOrg yOrg rle|
+
+ inStream binary.
+
+ lenID := inStream next.
+ hasColorMap := inStream next.
+ imageType := inStream next.
+ cmapOffset := inStream nextShortMSB:false.
+ cmapLength := inStream nextShortMSB:false.
+ cmapEntrySize := inStream next.
+ xOrg := inStream nextShortMSB:false.
+ yOrg := inStream nextShortMSB:false.
+
+ width := inStream nextShortMSB:false.
+ height := inStream nextShortMSB:false.
+ depth := inStream next.
+ (#(8 "16" 24 32) includes:depth) ifFalse:[
+ ^ self fileFormatError:('unsupported depth: ', depth printString).
+ ].
+ depth == 32 ifTrue:[
+ 'TargaReader [info]: alpha channel ignored' infoPrintCR.
+ ] ifFalse:[
+ 'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
+ ].
+
+ "/ MapRGB == 1
+ "/ RawRGB == 2
+ "/ RawMono == 3
+ "/ MapEnCode == 9
+ "/ RawEnCode == 10
+
+ (#(1 2 9 10) includes:imageType) ifFalse:[
+ "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
+ ^ self fileFormatError:('unsupported imageType: ', imageType printString).
+ ].
+ 'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
+
+ self reportDimension.
+
+ "/ flags:
+ "/ 0000 xxxx attribute-bits-per-pixel
+ "/ 0000 0001 greysc
+ "/ 0000 0010 colour
+ "/ 0000 0011 mapped
+ "/ 0000 0100 rleEncoded
+ "/ 0000 1000 interlaced
+ "/ 00xx 0000 origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
+ "/ xx00 0000 interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
+ "/
+ flags := inStream next.
+
+ (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
+ ^ self fileFormatError:('unsupported interlace: ' , flags printString).
+ ].
+
+ rle := flags bitTest:2r000001000.
+ flags := flags bitAnd:2r111110111.
+
+ (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
+ ^ self fileFormatError:('unsupported flags: ' , flags printString).
+ ].
+
+ (flags bitAnd:2r00110000) == 16r20 ifTrue:[
+ orientation := #topLeft
+ ] ifFalse:[
+ (flags bitAnd:2r00110000) == 16r30 ifTrue:[
+ orientation := #topRight
+ ] ifFalse:[
+ (flags bitAnd:2r00110000) == 16r10 ifTrue:[
+ orientation := #bottomRight
+ ] ifFalse:[
+ (flags bitAnd:2r00110000) == 0 ifTrue:[
+ orientation := #bottomLeft
+ ]
+ ]
+ ]
+ ].
+
+ lenID ~~ 0 ifTrue:[
+ inStream skip:lenID
+ ].
+
+ hasColorMap ~~ 0 ifTrue:[
+ "/ read the colorMap
+ colorMap := self readColorMap:cmapLength.
+ 'TargaReader [info]: has colorMap' infoPrintCR.
+ ].
+
+ depth == 32 ifTrue:[
+ imageType == 2 ifTrue:[
+"/ rle ifTrue:[self halt:'oops - should not happen'].
+ self read32.
+ ] ifFalse:[
+"/ rle ifFalse:[self halt:'oops - should not happen'].
+ self read32RLE.
+ ].
+ bytesPerRow := width*3.
+ bytesPerPixel := 3.
+ ].
+ depth == 24 ifTrue:[
+ imageType == 2 ifTrue:[
+"/ rle ifTrue:[self halt:'oops - should not happen'].
+ self read24.
+ ] ifFalse:[
+"/ rle ifFalse:[self halt:'oops - should not happen'].
+ self read24RLE.
+ ].
+ bytesPerRow := width*3.
+ bytesPerPixel := 3.
+ ].
+ depth == 8 ifTrue:[
+ imageType == 1 ifTrue:[
+"/ rle ifTrue:[self halt:'oops - should not happen'].
+ self read8.
+ ] ifFalse:[
+"/ rle ifFalse:[self halt:'oops - should not happen'].
+ self read8RLE
+ ].
+ bytesPerRow := width.
+ bytesPerPixel := 1.
+ ].
+
+ self handleImageOrientation.
+
+ "
+ TargaReader fromFile:'bitmaps/test.tga'
+ "
+
+ "Modified: / 7.9.1998 / 21:12:12 / cg"
+ "Modified: / 13.10.1998 / 19:50:48 / ps"
+! !
+
!TargaReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.24 2003-11-19 15:25:29 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.25 2003-11-19 15:38:53 cg Exp $'
! !
TargaReader initialize!
--- a/WindowsIconReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/WindowsIconReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -356,6 +356,42 @@
"Modified: / 3.2.1998 / 20:21:16 / cg"
! !
+!WindowsIconReader methodsFor:'private-reading'!
+
+readColorMap:nColors numBytesPerColor:nRawBytesPerColor from:aStream
+ "read the colormap; notice: its in BGR order (sigh)."
+
+ |rawMap rMap gMap bMap
+ srcIndex "{ Class: SmallInteger }"
+ skipDelta "{ Class: SmallInteger }"|
+
+ rawMap := ByteArray uninitializedNew:(nColors*nRawBytesPerColor).
+ aStream nextBytes:(nColors*nRawBytesPerColor) into:rawMap.
+
+ rMap := ByteArray new:nColors.
+ gMap := ByteArray new:nColors.
+ bMap := ByteArray new:nColors.
+ srcIndex := 1.
+ skipDelta := nRawBytesPerColor - 3.
+
+ "/ stupid: this is a BGR-ordered map (otherwise, could use #rgbBytesVector:-message)
+ "/ also, there might be a fourth byte (alpha ?) which is (currently) skipped.
+ 1 to:nColors do:[:i |
+ bMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ gMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ rMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ srcIndex := srcIndex + skipDelta.
+ ].
+
+ ^ MappedPalette
+ redVector:rMap
+ greenVector:gMap
+ blueVector:bMap.
+! !
+
!WindowsIconReader methodsFor:'reading'!
fromOS2File:aFilename
@@ -829,42 +865,6 @@
"Modified: / 18.5.1999 / 15:40:00 / cg"
! !
-!WindowsIconReader methodsFor:'reading-private'!
-
-readColorMap:nColors numBytesPerColor:nRawBytesPerColor from:aStream
- "read the colormap; notice: its in BGR order (sigh)."
-
- |rawMap rMap gMap bMap
- srcIndex "{ Class: SmallInteger }"
- skipDelta "{ Class: SmallInteger }"|
-
- rawMap := ByteArray uninitializedNew:(nColors*nRawBytesPerColor).
- aStream nextBytes:(nColors*nRawBytesPerColor) into:rawMap.
-
- rMap := ByteArray new:nColors.
- gMap := ByteArray new:nColors.
- bMap := ByteArray new:nColors.
- srcIndex := 1.
- skipDelta := nRawBytesPerColor - 3.
-
- "/ stupid: this is a BGR-ordered map (otherwise, could use #rgbBytesVector:-message)
- "/ also, there might be a fourth byte (alpha ?) which is (currently) skipped.
- 1 to:nColors do:[:i |
- bMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- gMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- rMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- srcIndex := srcIndex + skipDelta.
- ].
-
- ^ MappedPalette
- redVector:rMap
- greenVector:gMap
- blueVector:bMap.
-! !
-
!WindowsIconReader methodsFor:'writing'!
save:image onFile:aFileName
@@ -1111,7 +1111,7 @@
!WindowsIconReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.57 2003-11-19 15:25:15 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.58 2003-11-19 15:38:30 cg Exp $'
! !
WindowsIconReader initialize!
--- a/XPMReader.st Wed Nov 19 16:33:55 2003 +0100
+++ b/XPMReader.st Wed Nov 19 16:38:53 2003 +0100
@@ -173,168 +173,7 @@
"Modified: 24.4.1997 / 20:29:40 / cg"
! !
-!XPMReader methodsFor:'reading'!
-
-readImage
- "read an XPM-image from my inStream. Return the receiver
- (with all relevant instance variables set for the image)
- or nil on error"
-
- |line
- srcIndex "{ Class: SmallInteger }"
- dstIndex "{ Class: SmallInteger }"
- colorMapSize
- s bitsPerPixel key lastKey lastChar1 lastChar2 c1 c2 lastXLation|
-
- line := inStream nextLine.
- (line notNil and:[line startsWith:'/* XPM']) ifFalse:[
- ^ self fileFormatError:'format error (expected XPM)'.
- ].
-
- line := inStream nextLine.
- [line notNil and:[(line startsWith:'/*') or:[line isBlank or:[(line startsWith:' *')]]]] whileTrue:[
- line := inStream nextLine.
- ].
- (line notNil and:[line startsWith:'static char']) ifFalse:[
- ^ self fileFormatError:'format error (expected static char)'.
- ].
- line := inStream nextLine.
- (line notNil and:[line startsWith:'/*']) ifTrue:[
- [line notNil
- and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[
- line := inStream nextLine.
- ].
- ].
- line notNil ifTrue:[
- line := line withoutSeparators
- ].
- (line notNil and:[line startsWith:'"']) ifFalse:[
- ^ self fileFormatError:'format error (expected "ww hh nn mm)'.
- ].
- s := ReadStream on:line.
- s next. "skip quote"
- width := Integer readFrom:s.
- height := Integer readFrom:s.
- colorMapSize := Integer readFrom:s.
- charsPerPixel := Integer readFrom:s.
-
- self reportDimension.
-
- charsPerPixel ~~ 1 ifTrue:[
- characterTranslation := Dictionary new:colorMapSize.
- ] ifFalse:[
- characterTranslation := Array new:256.
- ].
-
- self readColorMap:colorMapSize.
-
- "actually, could make it an image with less depth most of the time ..."
-
-"
- bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1.
-"
- 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 |
- line := inStream nextLine withoutSpaces.
- [line notNil and:[line startsWith:'/*']] whileTrue:[
- line := inStream nextLine withoutSpaces.
- ].
- line notNil ifTrue:[
- line := line withoutSeparators
- ].
- (line notNil and:[line startsWith:'"']) ifFalse:[
- ^ self fileFormatError:'format error (expected pixels)'.
- ].
- charsPerPixel == 1 ifTrue:[
- srcIndex := 2. "skip dquote"
- 1 to:width do:[:col |
- key := line at:srcIndex.
- key ~~ lastKey ifTrue:[
- lastXLation := characterTranslation at:key asciiValue.
- lastKey := key
- ].
- data at:dstIndex put:lastXLation.
- srcIndex := srcIndex + 1.
- dstIndex := dstIndex + 1
- ]
- ] ifFalse:[
- charsPerPixel == 2 ifTrue:[
- "/ sorry, but this ugly code does a lot for speed,
- "/ when reading big Xpm files (factor=5 for banner8.xpm) ...
- srcIndex := 2."skip dquote"
- lastChar1 := lastChar2 := nil.
- key := String new:2.
- 1 to:width do:[:col |
- c1 := line at:srcIndex.
- c2 := line at:srcIndex+1.
- (c1 ~~ lastChar1 or:[c2 ~~ lastChar2]) ifTrue:[
- key at:1 put:c1.
- key at:2 put:c2.
- lastXLation := characterTranslation at:key.
- 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:[
- data at:dstIndex put:lastXLation.
- dstIndex := dstIndex + 1.
- ].
- srcIndex := srcIndex + 2.
- ]
- ] ifFalse:[
- s := line readStream.
- s next. "/ skip dquote
- 1 to:width do:[:col |
- key := s next:charsPerPixel.
-"/ data at:dstIndex put:(characterTranslation at:key).
- key ~= lastKey ifTrue:[
- lastXLation := characterTranslation at:key.
- lastKey := key
- ].
- data at:dstIndex put:lastXLation.
- dstIndex := dstIndex + 1
- ]
- ]
- ]
- ].
-
- 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
- ].
-
- "
- XPMReader fromStream:('../../goodies/bitmaps/xpmBitmaps/FATAL.xpm' asFilename readStream)
- "
-
- "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: / 27.7.1998 / 20:01:56 / cg"
-! !
-
-!XPMReader methodsFor:'reading-private'!
+!XPMReader methodsFor:'private-reading'!
colorNameFrom:aStream
"read either a color-name or value specified in X-notation
@@ -499,6 +338,188 @@
colorMap := MappedPalette redVector:redMap greenVector:greenMap blueVector:blueMap.
! !
+!XPMReader methodsFor:'private-writing'!
+
+colorNameOf:aColor
+ "generate a name for a color. If its a standard color,
+ return its name; otherwise return the hex representation."
+
+ #(white black red green blue
+ yellow magenta cyan orange) do:[:aStandardColorName |
+ aColor = (Color name:aStandardColorName) ifTrue:[
+ ^ aStandardColorName.
+ ]
+ ].
+ ^ '#'
+ , (aColor redByte hexPrintString:2)
+ , (aColor greenByte hexPrintString:2)
+ , (aColor blueByte hexPrintString:2)
+
+ "Created: / 27.2.1997 / 11:48:40 / cg"
+ "Modified: / 6.6.1998 / 20:58:49 / cg"
+! !
+
+!XPMReader methodsFor:'reading'!
+
+readImage
+ "read an XPM-image from my inStream. Return the receiver
+ (with all relevant instance variables set for the image)
+ or nil on error"
+
+ |line
+ srcIndex "{ Class: SmallInteger }"
+ dstIndex "{ Class: SmallInteger }"
+ colorMapSize
+ s bitsPerPixel key lastKey lastChar1 lastChar2 c1 c2 lastXLation|
+
+ line := inStream nextLine.
+ (line notNil and:[line startsWith:'/* XPM']) ifFalse:[
+ ^ self fileFormatError:'format error (expected XPM)'.
+ ].
+
+ line := inStream nextLine.
+ [line notNil and:[(line startsWith:'/*') or:[line isBlank or:[(line startsWith:' *')]]]] whileTrue:[
+ line := inStream nextLine.
+ ].
+ (line notNil and:[line startsWith:'static char']) ifFalse:[
+ ^ self fileFormatError:'format error (expected static char)'.
+ ].
+ line := inStream nextLine.
+ (line notNil and:[line startsWith:'/*']) ifTrue:[
+ [line notNil
+ and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[
+ line := inStream nextLine.
+ ].
+ ].
+ line notNil ifTrue:[
+ line := line withoutSeparators
+ ].
+ (line notNil and:[line startsWith:'"']) ifFalse:[
+ ^ self fileFormatError:'format error (expected "ww hh nn mm)'.
+ ].
+ s := ReadStream on:line.
+ s next. "skip quote"
+ width := Integer readFrom:s.
+ height := Integer readFrom:s.
+ colorMapSize := Integer readFrom:s.
+ charsPerPixel := Integer readFrom:s.
+
+ self reportDimension.
+
+ charsPerPixel ~~ 1 ifTrue:[
+ characterTranslation := Dictionary new:colorMapSize.
+ ] ifFalse:[
+ characterTranslation := Array new:256.
+ ].
+
+ self readColorMap:colorMapSize.
+
+ "actually, could make it an image with less depth most of the time ..."
+
+"
+ bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1.
+"
+ 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 |
+ line := inStream nextLine withoutSpaces.
+ [line notNil and:[line startsWith:'/*']] whileTrue:[
+ line := inStream nextLine withoutSpaces.
+ ].
+ line notNil ifTrue:[
+ line := line withoutSeparators
+ ].
+ (line notNil and:[line startsWith:'"']) ifFalse:[
+ ^ self fileFormatError:'format error (expected pixels)'.
+ ].
+ charsPerPixel == 1 ifTrue:[
+ srcIndex := 2. "skip dquote"
+ 1 to:width do:[:col |
+ key := line at:srcIndex.
+ key ~~ lastKey ifTrue:[
+ lastXLation := characterTranslation at:key asciiValue.
+ lastKey := key
+ ].
+ data at:dstIndex put:lastXLation.
+ srcIndex := srcIndex + 1.
+ dstIndex := dstIndex + 1
+ ]
+ ] ifFalse:[
+ charsPerPixel == 2 ifTrue:[
+ "/ sorry, but this ugly code does a lot for speed,
+ "/ when reading big Xpm files (factor=5 for banner8.xpm) ...
+ srcIndex := 2."skip dquote"
+ lastChar1 := lastChar2 := nil.
+ key := String new:2.
+ 1 to:width do:[:col |
+ c1 := line at:srcIndex.
+ c2 := line at:srcIndex+1.
+ (c1 ~~ lastChar1 or:[c2 ~~ lastChar2]) ifTrue:[
+ key at:1 put:c1.
+ key at:2 put:c2.
+ lastXLation := characterTranslation at:key.
+ 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:[
+ data at:dstIndex put:lastXLation.
+ dstIndex := dstIndex + 1.
+ ].
+ srcIndex := srcIndex + 2.
+ ]
+ ] ifFalse:[
+ s := line readStream.
+ s next. "/ skip dquote
+ 1 to:width do:[:col |
+ key := s next:charsPerPixel.
+"/ data at:dstIndex put:(characterTranslation at:key).
+ key ~= lastKey ifTrue:[
+ lastXLation := characterTranslation at:key.
+ lastKey := key
+ ].
+ data at:dstIndex put:lastXLation.
+ dstIndex := dstIndex + 1
+ ]
+ ]
+ ]
+ ].
+
+ 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
+ ].
+
+ "
+ XPMReader fromStream:('../../goodies/bitmaps/xpmBitmaps/FATAL.xpm' asFilename readStream)
+ "
+
+ "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: / 27.7.1998 / 20:01:56 / cg"
+! !
+
!XPMReader methodsFor:'writing'!
save:image onFile:aFileName
@@ -600,31 +621,10 @@
"Modified: / 28.7.1998 / 21:52:13 / cg"
! !
-!XPMReader methodsFor:'writing-private'!
-
-colorNameOf:aColor
- "generate a name for a color. If its a standard color,
- return its name; otherwise return the hex representation."
-
- #(white black red green blue
- yellow magenta cyan orange) do:[:aStandardColorName |
- aColor = (Color name:aStandardColorName) ifTrue:[
- ^ aStandardColorName.
- ]
- ].
- ^ '#'
- , (aColor redByte hexPrintString:2)
- , (aColor greenByte hexPrintString:2)
- , (aColor blueByte hexPrintString:2)
-
- "Created: / 27.2.1997 / 11:48:40 / cg"
- "Modified: / 6.6.1998 / 20:58:49 / cg"
-! !
-
!XPMReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.57 2003-11-19 15:24:31 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.58 2003-11-19 15:38:24 cg Exp $'
! !
XPMReader initialize!