--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IrisRGBReader.st Mon Apr 14 17:11:16 1997 +0200
@@ -0,0 +1,272 @@
+"
+ COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
+
+ImageReader subclass:#IrisRGBReader
+ instanceVariableNames:'bytesPerPixel'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Graphics-Images-Support'
+!
+
+!IrisRGBReader class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+documentation
+"
+ this class provides methods for loading Iris RGB format images.
+ Only 3-byte/pixel format is supported.
+ Writing is not (yet) supported.
+
+ [author:]
+ Claus Gittinger
+
+ [See also:]
+ Image Form Icon
+ BlitImageReader FaceReader GIFReader JPEGReader PCXReader
+ ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader
+ XBMReader XPMReader XWDReader
+"
+! !
+
+!IrisRGBReader class methodsFor:'initialization'!
+
+initialize
+ "install myself in the Image classes fileFormat table
+ for the `.rgb' extension."
+
+ Image addReader:self suffix:'rgb'.
+
+ "Modified: 14.4.1997 / 15:49:19 / cg"
+! !
+
+!IrisRGBReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+ "return true, if aFileName contains an IRIS_RGB image"
+
+ |inStream magic type bpp dim w h bytesPerPixel|
+
+ inStream := self streamReadingFile:aFileName.
+ inStream isNil ifTrue:[^ false].
+
+ inStream binary.
+
+ magic := inStream nextShortMSB:true.
+ type := inStream nextShortMSB:true.
+ dim := inStream nextShortMSB:true.
+ w := inStream nextShortMSB:true.
+ h := inStream nextShortMSB:true.
+ bytesPerPixel := inStream nextShortMSB:true.
+ inStream close.
+
+ magic ~~ 8r0732 ifTrue:[^ false].
+ bpp := type bitAnd:16r00FF.
+ bpp ~~ 1 ifTrue:[^ false].
+ bytesPerPixel ~~ 3 ifTrue:[^ false].
+
+ ^ true
+
+ "
+ IrisRGBReader isValidImageFile:'/home2/cg/capture.rgb'
+ "
+
+ "Modified: 14.4.1997 / 16:51:58 / cg"
+! !
+
+!IrisRGBReader methodsFor:'reading from file'!
+
+expandRow:rleData to:dataIdx
+ "expand a single RLE-encoded row"
+
+ |srcIdx "{Class: SmallInteger }"
+ dstIdx "{Class: SmallInteger }"
+ pixel "{Class: SmallInteger }"
+ count "{Class: SmallInteger }"|
+
+ srcIdx := 1.
+ dstIdx := dataIdx.
+ [true] whileTrue:[
+ pixel := rleData at:srcIdx.
+ srcIdx := srcIdx + 1.
+ count := pixel bitAnd:16r7F.
+ count == 0 ifTrue:[
+ ^ self
+ ].
+ (pixel bitAnd:16r80) == 0 ifFalse:[
+ "/ verbatim bytes
+ 1 to:count do:[:c |
+ data at:dstIdx put:(rleData at:srcIdx).
+ srcIdx := srcIdx + 1.
+ dstIdx := dstIdx + 3.
+ ]
+ ] ifTrue:[
+ "/ run bytes
+ pixel := rleData at:srcIdx.
+ srcIdx := srcIdx + 1.
+ 1 to:count do:[:c |
+ data at:dstIdx put:pixel.
+ dstIdx := dstIdx + 3.
+ ]
+ ]
+ ].
+
+ "
+ IrisRGBReader fromFile:'/home2/cg/capture.rgb'
+ "
+
+ "Created: 14.4.1997 / 17:05:41 / cg"
+ "Modified: 14.4.1997 / 17:07:32 / cg"
+!
+
+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:[
+ 'IrisRGBReader [warning]: bad magic' errorPrintCR.
+ ^nil
+ ].
+
+ 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:[
+ 'IrisRGBReader [warning]: not 1byte/pixel chan' errorPrintCR.
+ ^nil
+ ].
+ bytesPerPixel ~~ 3 ifTrue:[
+ 'IrisRGBReader [warning]: can only read 3-channel images' errorPrintCR.
+ ^nil
+ ].
+
+ isRLE ifTrue:[
+ self readRLEData
+ ] ifFalse:[
+ 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: 14.4.1997 / 17:06:05 / cg"
+!
+
+readRLEData
+ "read RLE compressed data"
+
+ |rleBufferLen tableLen startTable lengthTable rleData
+ cur badOrder y z pos tblIdx dstIdx|
+
+ rleBufferLen := width * 2 + 10.
+ tableLen := height * bytesPerPixel.
+
+ startTable := Array new:tableLen.
+ lengthTable := Array new:tableLen.
+ rleData := ByteArray uninitializedNew:rleBufferLen.
+
+ "/ read rowStart & length table
+
+ inStream position:512+1.
+ 1 to:tableLen do:[:i |
+ startTable at:i put:(inStream nextLongMSB:true).
+ ].
+ 1 to:tableLen do:[:i |
+ lengthTable at:i put:(inStream nextLongMSB:true).
+ ].
+
+ data := ByteArray uninitializedNew:(width*height*3).
+
+ dstIdx := width * (height-1) * 3 + 1.
+
+ 0 to:(height-1) do:[:y |
+ 0 to:(bytesPerPixel-1) do:[:z |
+ |start length|
+
+ tblIdx := y + (z*height) + 1.
+
+ start := startTable at:tblIdx.
+ length := lengthTable at:tblIdx.
+
+ inStream position:(start + 1).
+ (inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[
+ self halt:'short read'
+ ].
+ (rleData at:length) ~~ 0 ifTrue:[
+ self halt.
+ ].
+ self expandRow:rleData to:dstIdx+z. "/ (3-z).
+ ].
+ dstIdx := dstIdx - (width * 3).
+ ].
+
+ "
+ IrisRGBReader fromFile:'/home2/cg/capture.rgb'
+ "
+
+ "Modified: 14.4.1997 / 17:08:59 / cg"
+! !
+
+!IrisRGBReader methodsFor:'testing '!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Currently only B&W and Depth8 images are supported."
+
+ |depth|
+
+"/ anImage photometric == #rgb ifTrue:[
+"/ ^ false "/ not yet implemented
+"/ ].
+"/ (depth := anImage depth) == 1 ifTrue:[^ true].
+"/ depth == 8 ifTrue:[^ true].
+ ^ false
+
+ "Created: 14.4.1997 / 15:38:51 / cg"
+ "Modified: 14.4.1997 / 15:58:20 / cg"
+! !
+
+!IrisRGBReader class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.1 1997-04-14 15:11:16 cg Exp $'
+! !
+IrisRGBReader initialize!