TIFFReader.st
changeset 14 20638e830834
parent 11 1d0df18a7049
child 19 8527f194f903
--- a/TIFFReader.st	Sat Dec 11 02:38:34 1993 +0100
+++ b/TIFFReader.st	Sat Jan 08 18:10:32 1994 +0100
@@ -28,7 +28,7 @@
 COPYRIGHT (c) 1991 by Claus Gittinger
               All Rights Reserved
 
-$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.5 1993-12-11 01:33:46 claus Exp $
+$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.6 1994-01-08 17:10:32 claus Exp $
 written Summer 91 by claus
 '!
 
@@ -36,18 +36,20 @@
 
 documentation
 "
-    This class knows how to read TIFF files and how to
-    write uncompressed TIFF files.
-    Only single image files are supported.
-    Currently, not all formats are implemented, and of
-    those that are not all are tested.
-    It should work with most rgb, mono and 2-plane greyscale
-    images, since this is what I have as test material on
-    the NeXT.
-    It supports reading of uncompressed, LZW and G3 compressed 
-    images; JPEG and pacbits are currently not implemented.
-    Only writing of uncompressed images is currently implemented.
-    More formats will come ...
+This class knows how to read TIFF files and how to
+write uncompressed TIFF files.
+
+Only single image files are supported.
+Currently, not all formats are implemented, and of those that are not 
+all are tested.
+It should work with most rgb, mono and 2-plane greyscale
+images, since this is what I have as test material on
+the NeXT.
+It supports reading of uncompressed, LZW and G3 compressed 
+images; JPEG and packbits are currently not implemented.
+
+Only writing of uncompressed images is currently implemented.
+More formats will come ...
 "
 ! !
 
@@ -273,7 +275,7 @@
 
     "output strips"
 
-    self writeBits.             "this outputs bits as strips, sets stripOffsets and stripByteCounts"
+    self writeUncompressedBits. "this outputs bits as strips, sets stripOffsets and stripByteCounts"
     self writeStripOffsets.     "this outputs strip offsets, sets stripOffsetsPos"
     self writeStripByteCounts.  "this outputs strip bytecounts, sets stripByteCountPos"
     self writeBitsPerSample.    "this outputs bitsPerSample, sets bitsPerSamplePos"
@@ -292,9 +294,9 @@
     "output tag data"
 
     photometric == #palette ifTrue:[
-        self writeShort:9.  "9 tags"
+        self writeShort:10.  "10 tags"
     ] ifFalse:[
-        self writeShort:8.  "8 tags"
+        self writeShort:9.   "9 tags"
     ].
     self writeTag:256.               "image width"
     self writeTag:257.               "image height"
@@ -304,10 +306,12 @@
     self writeTag:273.               "strip offsets"
     self writeTag:279.               "strip byte counts"
     self writeTag:284.               "planarconfig"
+    self writeTag:278.               "rowsPerStrip"
     photometric == #palette ifTrue:[
         self writeTag:320            "colorMap"
     ].
     self writeLong:0.                "end of tags mark"
+    outStream close
 ! !
 
 !TIFFReader methodsFor:'private'!
@@ -424,37 +428,49 @@
     (tagType == 254) ifTrue:[
         "NewSubfileType"
         "newSubFileType := value."
+"
         'newSubfiletype ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 255) ifTrue:[
         "SubfileType"
         subFileType := value.
+"
         'subfiletype ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 256) ifTrue:[
         "ImageWidth"
         width := value.
         'width ' print. width printNewline.
+"
         ^ self
+"
     ].
     (tagType == 257) ifTrue:[
         "ImageHeight"
         height := value.
+"
         'height ' print. height  printNewline.
+"
         ^ self
     ].
     (tagType == 258) ifTrue:[
         "bitspersample"
          bitsPerSample := valueArray.
+"
         'bitspersample ' print. bitsPerSample printNewline.
+"
         ^ self
     ].
     (tagType == 259) ifTrue:[
         "compression"
         compression := value.
+"
         'compression ' print. compression printNewline.
+"
         ^ self
     ].
     (tagType == 262) ifTrue:[
@@ -480,25 +496,33 @@
             ]
           ]
         ].
+"
         'photometric ' print. photometric printNewline.
+"
         ^ self
     ].
     (tagType == 263) ifTrue:[
         "Treshholding"
         "threshholding := value."
+"
         'treshholding ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 264) ifTrue:[
         "CellWidth"
         "cellWidth:= value."
+"
         'cellWidth ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 265) ifTrue:[
         "CellLength"
         "cellLength:= value."
+"
         'cellLength ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 266) ifTrue:[
@@ -512,81 +536,109 @@
             fillOrder := nil
           ]
         ].
+"
         'fillorder ' print. fillOrder printNewline.
+"
         ^ self
     ].
     (tagType == 269) ifTrue:[
         "documentName"
+"
         'documentName ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 270) ifTrue:[
         "imageDescription"
+"
         'imageDescription ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 271) ifTrue:[
         "make"
+"
         'make ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 272) ifTrue:[
         "model"
+"
         'model ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 273) ifTrue:[
         "stripoffsets"
         stripOffsets := valueArray.
+"
         'stripOffsets Array(' print. stripOffsets size print. ')' printNewline.
+"
         ^ self
     ].
     (tagType == 274) ifTrue:[
         "Orientation"
         "orientation:= value."
+"
         'orientation ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 277) ifTrue:[
         "samplesPerPixel"
         samplesPerPixel := value.
+"
         'samplesperpixel ' print. samplesPerPixel printNewline.
+"
         ^ self
     ].
     (tagType == 278) ifTrue:[
         "rowsperstrip"
         rowsPerStrip := value.
+"
         'rowsperstrip ' print. rowsPerStrip printNewline.
+"
         ^ self
     ].
     (tagType == 279) ifTrue:[
         "stripbytecount"
         stripByteCounts := valueArray.
+"
         'stripByteCounts Array(' print. 
         stripByteCounts size print.
         ')' printNewline.
+"
         ^ self
     ].
     (tagType == 280) ifTrue:[
         "MinSampleValue"
         "minSampleValue:= value."
+"
         'minSampleValue ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 281) ifTrue:[
         "MaxSampleValue"
         "maxSampleValue:= value."
+"
         'maxSampleValue ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 282) ifTrue:[
         "xResolution"
+"
         'xres ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 283) ifTrue:[
         "yResolution"
+"
         'yres ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 284) ifTrue:[
@@ -600,58 +652,79 @@
             planarConfiguration := nil
           ]
         ].
+"
         'planarconfig ' print. planarConfiguration printNewline.
+"
         ^ self
     ].
     (tagType == 285) ifTrue:[
         "pageName"
+"
         'pageName ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 286) ifTrue:[
         "xPosition"
+"
         'xPos ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 287) ifTrue:[
         "yPosition"
+"
         'yPos ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 288) ifTrue:[
         "freeOffsets"
+"
         'freeOffsets ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 289) ifTrue:[
         "freeByteCounts"
+"
         'freeByteCounts ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 290) ifTrue:[
         "grayResponceUnit"
+"
         'grayResponceUnit' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 291) ifTrue:[
         "grayResponceCurve"
+"
         'grayResponceCurve' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 292) ifTrue:[
         "group3options"
         group3options := value.
+"
         'group3options ' print. group3options printNewline.
+"
         ^ self
     ].
     (tagType == 293) ifTrue:[
         "group4options"
         "group4options := value."
+"
         'group4options ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 296) ifTrue:[
         "resolutionunit"
+"
         (value == 1) ifTrue:[
             'res-unit pixel' printNewline
         ] ifFalse:[
@@ -665,44 +738,59 @@
                 ]
             ]
         ].
+"
         "resolutionUnit := value."
         ^ self
     ].
     (tagType == 297) ifTrue:[
         "pageNumber"
         "pageNumber := value."
+"
         'pageNumber ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 300) ifTrue:[
         "colorResponceUnit"
+"
         'colorResponceUnit' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 301) ifTrue:[
         "colorResponceCurve"
+"
         'colorResponceCurve' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 306) ifTrue:[
         "dateTime"
+"
         'dateTime ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 315) ifTrue:[
         "artist"
+"
         'artist ' print. value printNewline.
+"
         ^ self
     ].
     (tagType == 317) ifTrue:[
         "predictor"
         predictor := value.
+"
         'predictor ' print. predictor printNewline.
+"
         ^ self
     ].
     (tagType == 320) ifTrue:[
         "colorMap"
+"
         'colorMap (size=' print. valueArray size print. ')' printNewline.
+"
         n := valueArray size // 3.
         colorMap := Array new:3.
         colorMap at:1 put:(valueArray copyFrom:1 to:n).
@@ -725,20 +813,21 @@
     'unknown type ' print. tagType printNewline
 !
 
-writeBits
-    "write bits as one strip"
+writeUncompressedBits
+    "write bits as one or multiple strips"
 
-    |offs bytesPerRow|
+    |offs bytesPerRow nBytes|
 
-    data size < 16rFFFF ifTrue:[
+    nBytes := data size.
+    nBytes < 16rFFFF ifTrue:[
         stripOffsets := Array with:(outStream position - 1).
-        stripByteCounts := Array with:(data size).
-        outStream nextPutBytes:data size from:data.
+        stripByteCounts := Array with:nBytes.
+        outStream nextPutBytes:nBytes from:data.
         rowsPerStrip := height
     ] ifFalse:[
         stripOffsets := Array new:height.
-        bytesPerRow := data size // height.
-        stripByteCounts := (Array new:height) atAllPut:bytesPerRow.
+        bytesPerRow := nBytes // height.
+        stripByteCounts := Array new:height withAll:bytesPerRow.
 
         offs := 1.
         1 to:height do:[:row |
@@ -748,8 +837,10 @@
         ].
         rowsPerStrip := 1
     ].
+"
     'stripOffsets: ' print. stripOffsets printNewline.
     'stripByteCounts: ' print. stripByteCounts printNewline.
+"
 !
 
 writeColorMap
@@ -999,9 +1090,11 @@
         ^ self
     ].
 
+"
 'tag:' print. tagType print. ' typ:' print. numberType print.
 ' len:' print. count print.
 ' val:' print. value printNewline.  
+"
 
     self writeShort:tagType.
     numberType == #short ifTrue:[
@@ -1135,9 +1228,7 @@
         nBytes := stripByteCounts at:stripNr.
         inStream position:((stripOffsets at:stripNr) + 1).
 
-            inStream nextBytes:nBytes 
-                          into:data
-                    startingAt:offset.
+        inStream nextBytes:nBytes into:data startingAt:offset.
         offset := offset + nBytes.
         row := row + rowsPerStrip
     ]