--- a/XWDReader.st Tue Jan 28 12:32:02 1997 +0100
+++ b/XWDReader.st Wed Jan 29 23:09:59 1997 +0100
@@ -16,14 +16,14 @@
who placed it into the public domain.
"
-ImageReader subclass:#XWDReader
+ImageReader subclass:#RGBReader
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Graphics-Images-Support'
!
-!XWDReader class methodsFor:'documentation'!
+!RGBReader class methodsFor:'documentation'!
copyright
"
@@ -58,98 +58,129 @@
"
! !
-!XWDReader class methodsFor:'queries'!
+!RGBReader class methodsFor:'queries'!
canRepresent:anImage
- "return true, if anImage can be represented in my file format.
- Only depth8 palette images are supported."
+ "return true, if anImage can be represented in my file format."
- anImage depth ~~ 8 ifTrue:[^ false].
- anImage photometric ~~ #palette ifTrue:[^ false].
- ^ true
+ ^ false
+
+ "Modified: 29.1.1997 / 22:38:08 / cg"
! !
-!XWDReader methodsFor:'image reading'!
+!RGBReader methodsFor:'image reading'!
fromStream:aStream
- "read an image in XWD (X Window Dump) format from aStream."
+ "read an image in RGB (IRIS image format) format from aStream."
- |header nColors pad
- srcRowByteSize bytesPerRow bitsPerPixel colormapSize depth
- dstIndex|
+ |magic type t dim width height min max
+ wasteBytes buffer name clrMap header nColors pad
+ srcRowByteSize bytesPerRow bytesPerPixel colormapSize depth
+ dstIndex tableSize rowStartTable rowSizeTable|
aStream binary.
- header := (1 to: 25) collect: [:i | aStream nextLong].
-
- "skip ..."
- 101 to:(header at: 1) do: [:i | aStream next].
-
- depth := header at: 4.
- width := header at: 5.
- height := header at: 6.
- pad := header at: 11.
-
- bitsPerPixel := header at: 12.
- bitsPerPixel == 24 ifTrue:[
- bitsPerSample := #(8 8 8).
- samplesPerPixel := 3.
- photometric := #rgb
+ magic := aStream nextUnsignedShortMSB:true.
+ magic ~~ 8r732 ifTrue:[
+ 'RGBReader [warning]: bad magic' errorPrintCR.
+ ^ nil
+ ].
+ type := aStream nextUnsignedShortMSB:true.
+ bytesPerPixel := type bitAnd: 16r00FF.
+ t := type bitAnd: 16rFF00.
+ t == 16r0000 ifTrue:[
+ "/ verbatim
+ type := #verbatim.
] ifFalse:[
- bitsPerSample := Array with:bitsPerPixel.
- samplesPerPixel := 1.
- photometric := #palette
+ t == 16r0100 ifTrue:[
+ "/ rle
+ type := #rle
+ ] ifFalse:[
+ 'RGBReader [warning]: bad type' errorPrintCR.
+ ^ nil
+ ].
].
-"/ depth ~~ bitsPerPixel ifTrue:[self halt].
-
- colormapSize := header at: 19.
- nColors := header at: 20.
+'type: ' print. type printCR.
+'bpp: ' print. bytesPerPixel printCR.
- colorMap := Array new:colormapSize.
-
- 1 to:nColors do:[:i |
- |clr r g b|
+ dim := aStream nextUnsignedShortMSB:true.
+'dim: ' print. dim printCR.
+ width := aStream nextUnsignedShortMSB:true.
+'w: ' print. width printCR.
+ height := aStream nextUnsignedShortMSB:true.
+'h: ' print. height printCR.
+ samplesPerPixel := aStream nextUnsignedShortMSB:true.
+'z: ' print. samplesPerPixel printCR.
- aStream nextLong.
- r := aStream nextUnsignedShortMSB:true.
- g := aStream nextUnsignedShortMSB:true.
- b := aStream nextUnsignedShortMSB:true.
- clr := ColorValue scaledRed: (r bitShift: -3)
- scaledGreen: (g bitShift: -3)
- scaledBlue: (b bitShift: -3).
- colorMap at:i put:clr.
- aStream nextWord.
+ min := aStream nextUnsignedLongMSB:true.
+'min: ' print. min printCR.
+ max := aStream nextUnsignedLongMSB:true.
+'max: ' print. max printCR.
+ wasteBytes := aStream nextUnsignedLongMSB:true.
+'waste: ' print. wasteBytes printCR.
+ name := aStream nextBytes:80 into:(buffer := ByteArray new:80).
+ name := buffer asString.
+name printCR.
+ clrMap := aStream nextUnsignedLongMSB:true.
+'clrmap: ' print. clrMap printCR.
+ clrMap == 0 ifTrue:[
+ "/ cm_normal
+ ] ifFalse:[
+ clrMap == 1 ifTrue:[
+ "/ cm_dithered
+ ] ifFalse:[
+ clrMap == 2 ifTrue:[
+ "/ cm_screen
+ ] ifFalse:[
+ clrMap == 3 ifTrue:[
+ "/ cm_colormap
+ ] ifFalse:[
+ 'RGBReader [warning]: bad colormap' errorPrintCR.
+ ^ nil
+ ]
+ ]
+ ]
].
- nColors+1 to:colormapSize do: [:i | colorMap at:i put:Color black].
-
- bytesPerRow := width * bitsPerPixel // 8.
- ((width * bitsPerPixel \\ 8) ~~ 0) ifTrue:[
- bytesPerRow := bytesPerRow + 1
+ bytesPerPixel ~~ 1 ifTrue:[
+ 'RGBReader [warning]: unhandeld bpp' errorPrintCR.
+ ^ nil
].
- srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8).
- data := ByteArray uninitializedNew: srcRowByteSize * height.
- srcRowByteSize == bytesPerRow ifTrue:[
- aStream nextBytes:srcRowByteSize * height into:data.
+ type == #rle ifTrue:[
+ aStream position:513.
+ tableSize := height * samplesPerPixel * 4.
+ rowStartTable := ByteArray new:tableSize.
+ rowSizeTable := ByteArray new:tableSize.
+ (aStream nextBytes:tableSize into:rowStartTable) ~~ tableSize ifTrue:[
+ 'RGBReader [warning]: short read' errorPrintCR.
+ ^ nil
+ ].
+ (aStream nextBytes:tableSize into:rowSizeTable) ~~ tableSize ifTrue:[
+ 'RGBReader [warning]: short read' errorPrintCR.
+ ^ nil
+ ].
] ifFalse:[
- dstIndex := 1.
- 1 to:height do:[:y |
- aStream nextBytes:bytesPerRow into:data startingAt:dstIndex.
- aStream next:(srcRowByteSize - bytesPerRow).
- dstIndex := dstIndex + bytesPerRow.
+ 'RGBReader [warning]: only rle is handled' errorPrintCR.
+ ^ nil
+ ].
+
+ type == #rle ifTrue:[
+ 0 to:height-1 do:[:y |
].
- ]
- "
- XWDReader fromFile:'testfile.xwd'
+ ].
+
+ self halt.
+
"
+ RGBReader fromFile:'/home/cg/capture.rgb'
+
"
- XWDReader save:(Image fromUser) onFile: '/tmp/st.xwd'
- (Image fromFile: '/tmp/st.xwd') inspect
- "
+
+ "Modified: 29.1.1997 / 23:09:50 / cg"
! !
-!XWDReader methodsFor:'image writing'!
+!RGBReader methodsFor:'image writing'!
save:image onFile:fileName
"Save as a version 7 color X11 window dump file (xwd) to the file fileName.
@@ -265,10 +296,12 @@
XWDReader save:(Image fromUser) onFile: '/tmp/st.xwd'
(Image fromFile: '/tmp/st.xwd') inspect
"
+
+ "Created: 29.1.1997 / 22:37:48 / cg"
! !
-!XWDReader class methodsFor:'documentation'!
+!RGBReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.15 1996-05-10 16:46:20 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.16 1997-01-29 22:09:59 cg Exp $'
! !