TIFFReader.st
changeset 1571 cffaf89a0c6e
parent 1230 993aaef8a28a
child 1702 75a595a70c86
equal deleted inserted replaced
1570:5ef90b35b7d6 1571:cffaf89a0c6e
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
       
    12 
       
    13 "{ Package: 'stx:libview2' }"
    12 
    14 
    13 ImageReader subclass:#TIFFReader
    15 ImageReader subclass:#TIFFReader
    14 	instanceVariableNames:'planarConfiguration subFileType stripOffsets rowsPerStrip
    16 	instanceVariableNames:'planarConfiguration subFileType stripOffsets rowsPerStrip
    15 		fillOrder compression group3options predictor stripByteCounts
    17 		fillOrder compression group3options predictor stripByteCounts
    16 		currentOffset stripOffsetsPos stripByteCountsPos bitsPerSamplePos
    18 		currentOffset stripOffsetsPos stripByteCountsPos bitsPerSamplePos
  2106 !TIFFReader methodsFor:'writing to file'!
  2108 !TIFFReader methodsFor:'writing to file'!
  2107 
  2109 
  2108 save:image onFile:aFileName
  2110 save:image onFile:aFileName
  2109     "save image as (uncompressed) TIFF file on aFileName"
  2111     "save image as (uncompressed) TIFF file on aFileName"
  2110 
  2112 
  2111     |pos1 pos|
       
  2112 
       
  2113     image mask notNil ifTrue:[
       
  2114         Image informationLostQuerySignal
       
  2115             raiseWith:image
       
  2116             errorString:('TIFF writer does not (yet) support an imageMask').
       
  2117     ].
       
  2118 
       
  2119     outStream := FileStream newFileNamed:aFileName.
  2113     outStream := FileStream newFileNamed:aFileName.
  2120     outStream isNil ifTrue:[
  2114     outStream isNil ifTrue:[
  2121         ^ Image fileCreationErrorSignal 
  2115         ^ Image fileCreationErrorSignal 
  2122             raiseWith:image
  2116             raiseWith:image
  2123             errorString:('file creation error: ' , aFileName asString).
  2117             errorString:('file creation error: ' , aFileName asString).
  2124     ].
  2118     ].
       
  2119     [
       
  2120         self save:image onStream:outStream.
       
  2121     ] ensure:[
       
  2122         outStream close.
       
  2123     ].
       
  2124 !
       
  2125 
       
  2126 save:image onStream:aStream
       
  2127     "save image as (uncompressed) TIFF file on aFileName"
       
  2128 
       
  2129     |pos1 pos indicator|
       
  2130 
       
  2131     image mask notNil ifTrue:[
       
  2132         Image informationLostQuerySignal
       
  2133             raiseWith:image
       
  2134             errorString:('TIFF writer does not (yet) support an imageMask').
       
  2135     ].
       
  2136 
       
  2137     outStream := aStream.
       
  2138     outStream binary.
  2125 
  2139 
  2126     "save as msb"
  2140     "save as msb"
  2127 
  2141 
  2128     byteOrder := #msb.
  2142     byteOrder := #msb.
  2129 "
  2143 "
  2141     data := image bits.
  2155     data := image bits.
  2142 
  2156 
  2143     currentOffset := 0.
  2157     currentOffset := 0.
  2144 
  2158 
  2145     (byteOrder == #msb) ifTrue:[
  2159     (byteOrder == #msb) ifTrue:[
  2146         outStream nextPut:$M. outStream nextPut:$M.
  2160         indicator := $M asciiValue.
  2147     ] ifFalse:[
  2161     ] ifFalse:[
  2148         outStream nextPut:$I. outStream nextPut:$I.
  2162         indicator := $I asciiValue.
  2149     ].
  2163     ].
       
  2164     outStream nextPut:indicator; nextPut:indicator.
  2150     currentOffset := currentOffset + 2.
  2165     currentOffset := currentOffset + 2.
  2151 
       
  2152     outStream binary.
       
  2153 
  2166 
  2154     self writeShort:42.
  2167     self writeShort:42.
  2155     currentOffset := currentOffset + 2.
  2168     currentOffset := currentOffset + 2.
  2156 
  2169 
  2157     pos1 := outStream position.
  2170     pos1 := outStream position.
  2195     self writeTag:284.               "planarconfig"
  2208     self writeTag:284.               "planarconfig"
  2196     photometric == #palette ifTrue:[
  2209     photometric == #palette ifTrue:[
  2197         self writeTag:320            "colorMap"
  2210         self writeTag:320            "colorMap"
  2198     ].
  2211     ].
  2199     self writeLong:0.                "end of tags mark"
  2212     self writeLong:0.                "end of tags mark"
  2200     outStream close
       
  2201 
       
  2202     "Modified: / 30.9.1998 / 23:30:18 / cg"
       
  2203 ! !
  2213 ! !
  2204 
  2214 
  2205 !TIFFReader class methodsFor:'documentation'!
  2215 !TIFFReader class methodsFor:'documentation'!
  2206 
  2216 
  2207 version
  2217 version
  2208     ^ '$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.64 1999-09-08 16:30:21 cg Exp $'
  2218     ^ '$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.65 2002-06-09 14:47:23 stefan Exp $'
  2209 ! !
  2219 ! !
  2210 TIFFReader initialize!
  2220 TIFFReader initialize!