--- a/TIFFReader.st Thu Jun 02 19:14:54 2016 +0200
+++ b/TIFFReader.st Thu Jun 02 19:46:30 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
@@ -23,6 +25,13 @@
category:'Graphics-Images-Readers'
!
+Dictionary subclass:#TIFFMetaData
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:TIFFReader
+!
+
!TIFFReader class methodsFor:'documentation'!
copyright
@@ -186,7 +195,7 @@
"/ MASK -> 4
"newSubFileType := value."
- "/ 'newSubfiletype ' print. value printNewline.
+ "/ 'newSubfiletype ' print. value printNewline.
^ self
].
@@ -197,7 +206,7 @@
"/ PAGE -> 3
subFileType := value.
- "/ 'subfiletype ' print. value printNewline.
+ "/ 'subfiletype ' print. value printNewline.
^ self
].
@@ -205,7 +214,7 @@
"ImageWidth"
width := value.
- "/ 'width ' print. width printNewline.
+ "/ 'width ' print. width printNewline.
^ self
].
@@ -213,7 +222,7 @@
"ImageHeight"
height := value.
- "/ 'height ' print. height printNewline.
+ "/ 'height ' print. height printNewline.
^ self
].
@@ -221,7 +230,7 @@
"bitspersample"
bitsPerSample := valueArray.
- "/ 'bitspersample ' print. bitsPerSample printNewline.
+ "/ 'bitspersample ' print. bitsPerSample printNewline.
^ self
].
@@ -246,7 +255,7 @@
compression := value.
- "/ 'compression ' print. compression printNewline.
+ "/ 'compression ' print. compression printNewline.
^ self
].
@@ -287,7 +296,7 @@
]
].
- "/ 'photometric ' print. photometric printNewline.
+ "/ 'photometric ' print. photometric printNewline.
^ self
].
@@ -299,24 +308,21 @@
"threshholding := value."
- "/ 'treshholding ' print. value printNewline.
+ "/ 'treshholding ' print. value printNewline.
^ self
].
(tagType == 264) ifTrue:[
"CellWidth"
- "cellWidth:= value."
-
- "/ 'cellWidth ' print. value printNewline.
+ "/ 'cellWidth ' print. value printNewline.
+ metaData at:#CellWidth put:value.
^ self
].
(tagType == 265) ifTrue:[
"CellLength"
- "cellLength:= value."
-
- "/ 'cellLength ' print. value printNewline.
-
+ "/ 'cellLength ' print. value printNewline.
+ metaData at:#CellLength put:value.
^ self
].
(tagType == 266) ifTrue:[
@@ -331,44 +337,38 @@
]
].
- "/ 'fillorder ' print. fillOrder printNewline.
+ "/ 'fillorder ' print. fillOrder printNewline.
^ self
].
(tagType == 269) ifTrue:[
"documentName - info only"
-
- "/ 'documentName ' print. value printNewline.
-
+ "/ 'documentName ' print. value printNewline.
+ metaData at:#DocumentName put:value.
^ self
].
(tagType == 270) ifTrue:[
"imageDescription - info only"
-
- "/ 'imageDescription ' print. value printNewline.
-
+ "/ 'imageDescription ' print. value printNewline.
+ metaData at:#ImageDescription put:value.
^ self
].
(tagType == 271) ifTrue:[
"make - info only"
-
- "/ 'make ' print. value printNewline.
-
+ "/ 'make ' print. value printNewline.
+ metaData at:#Make put:value.
^ self
].
(tagType == 272) ifTrue:[
"model - info only"
-
- "/ 'model ' print. value printNewline.
-
+ "/ 'model ' print. value printNewline.
+ metaData at:#Model put:value.
^ self
].
(tagType == 273) ifTrue:[
"stripoffsets"
stripOffsets := valueArray.
-
- "/ 'stripOffsets Array(' print. stripOffsets size print. ')' printNewline.
-
+ "/ 'stripOffsets Array(' print. stripOffsets size print. ')' printNewline.
^ self
].
(tagType == 274) ifTrue:[
@@ -384,65 +384,52 @@
unsupported "/ 7 rot 90' & flip
unsupported "/ 8 rot 90' ccw & flip
) at:value ifAbsent:#unsupported.
-
- "/ 'orientation ' print. value printNewline.
-
+ metaData at:#Orientation put:value.
+ "/ 'orientation ' print. value printNewline.
^ self
].
(tagType == 277) ifTrue:[
"samplesPerPixel"
samplesPerPixel := value.
-
- "/ 'samplesperpixel ' print. samplesPerPixel printNewline.
-
+ "/ 'samplesperpixel ' print. samplesPerPixel printNewline.
^ self
].
(tagType == 278) ifTrue:[
"rowsperstrip"
rowsPerStrip := value.
-
- "/ 'rowsperstrip ' print. rowsPerStrip printNewline.
-
+ "/ 'rowsperstrip ' print. rowsPerStrip printNewline.
^ self
].
(tagType == 279) ifTrue:[
"stripbytecount"
stripByteCounts := valueArray.
-
- "/ 'stripByteCounts Array(' print.
- "/ stripByteCounts size print.
- "/ ')' printNewline.
-
+ "/ 'stripByteCounts Array(' print.
+ "/ stripByteCounts size print.
+ "/ ')' printNewline.
^ self
].
(tagType == 280) ifTrue:[
"MinSampleValue"
- "minSampleValue:= value."
-
- "/ 'minSampleValue ' print. value printNewline.
-
+ "/ 'minSampleValue ' print. value printNewline.
+ metaData at:#MinSampleValue put:value.
^ self
].
(tagType == 281) ifTrue:[
"MaxSampleValue"
- "maxSampleValue:= value."
-
- "/ 'maxSampleValue ' print. value printNewline.
-
+ "/ 'maxSampleValue ' print. value printNewline.
+ metaData at:#MaxSampleValue put:value.
^ self
].
(tagType == 282) ifTrue:[
"xResolution"
-
- "/ 'xres ' print. value printNewline.
-
+ "/ 'xres ' print. value printNewline.
+ metaData at:#ResolutionX put:value.
^ self
].
(tagType == 283) ifTrue:[
"yResolution"
-
- "/ 'yres ' print. value printNewline.
-
+ "/ 'yres ' print. value printNewline.
+ metaData at:#ResolutionY put:value.
^ self
].
(tagType == 284) ifTrue:[
@@ -456,58 +443,47 @@
planarConfiguration := nil
]
].
-
- "/ 'planarconfig ' print. planarConfiguration printNewline.
-
+ "/ 'planarconfig ' print. planarConfiguration printNewline.
^ self
].
(tagType == 285) ifTrue:[
"pageName"
-
- "/ 'pageName ' print. value printNewline.
-
+ "/ 'pageName ' print. value printNewline.
+ metaData at:#PageName put:value.
^ self
].
(tagType == 286) ifTrue:[
"xPosition"
-
- "/ 'xPos ' print. value printNewline.
-
+ "/ 'xPos ' print. value printNewline.
+ metaData at:#PositionX put:value.
^ self
].
(tagType == 287) ifTrue:[
"yPosition"
-
- "/ 'yPos ' print. value printNewline.
-
+ "/ 'yPos ' print. value printNewline.
+ metaData at:#PositionY put:value.
^ self
].
(tagType == 288) ifTrue:[
"freeOffsets"
-
- "/ 'freeOffsets ' print. value printNewline.
-
+ "/ 'freeOffsets ' print. value printNewline.
^ self
].
(tagType == 289) ifTrue:[
"freeByteCounts"
-
- "/ 'freeByteCounts ' print. value printNewline.
-
+ "/ 'freeByteCounts ' print. value printNewline.
^ self
].
(tagType == 290) ifTrue:[
"grayResponceUnit"
-
- "/ 'grayResponceUnit' print. value printNewline.
-
+ "/ 'grayResponceUnit' print. value printNewline.
+ metaData at:#GrayResponceUnit put:value.
^ self
].
(tagType == 291) ifTrue:[
"grayResponceCurve"
-
- "/ 'grayResponceCurve' print. value printNewline.
-
+ "/ 'grayResponceCurve' print. value printNewline.
+ metaData at:#GrayResponceCurve put:value.
^ self
].
(tagType == 292) ifTrue:[
@@ -517,9 +493,7 @@
"/ FILLBITS -> 4
group3options := value.
-
- "/ 'group3options ' print. group3options printNewline.
-
+ "/ 'group3options ' print. group3options printNewline.
^ self
].
(tagType == 293) ifTrue:[
@@ -527,9 +501,7 @@
"/ UNCOMPRESSED -> 2
"group4options := value."
-
- "/ 'group4options ' print. value printNewline.
-
+ "/ 'group4options ' print. value printNewline.
^ self
].
(tagType == 296) ifTrue:[
@@ -548,16 +520,13 @@
"/ ]
"/ ]
"/ ].
-
- "resolutionUnit := value."
+ metaData at:#ResolutionUnit put:value.
^ self
].
(tagType == 297) ifTrue:[
"pageNumber"
- "pageNumber := value."
-
- "/ 'pageNumber ' print. value printNewline.
-
+ "/ 'pageNumber ' print. value printNewline.
+ metaData at:#PageNumber put:value.
^ self
].
].
@@ -565,72 +534,62 @@
(tagType < 400) ifTrue:[
(tagType == 300) ifTrue:[
"colorResponceUnit"
-
- "/ 'colorResponceUnit' print. value printNewline.
-
+ "/ 'colorResponceUnit' print. value printNewline.
+ metaData at:#ColorResponceUnit put:value.
^ self
].
(tagType == 301) ifTrue:[
"colorResponceCurve"
-
- "/ 'colorResponceCurve' print. value printNewline.
-
+ "/ 'colorResponceCurve' print. value printNewline.
+ metaData at:#ColorResponceCurve put:value.
^ self
].
(tagType == 305) ifTrue:[
"software - info only"
-
- "/ 'software' print. value printNewline.
-
+ "/ 'software' print. value printNewline.
+ metaData at:#Software put:value.
^ self
].
(tagType == 306) ifTrue:[
"dateTime - info only"
-
- "/ 'dateTime ' print. value printNewline.
-
+ "/ 'dateTime ' print. value printNewline.
+ metaData at:#DateTime put:value.
^ self
].
(tagType == 315) ifTrue:[
"artist - info only"
-
- "/ 'artist ' print. value printNewline.
-
+ "/ 'artist ' print. value printNewline.
+ metaData at:#Artist put:value.
^ self
].
(tagType == 316) ifTrue:[
"host computer - info only"
-
- "/ 'host ' print. value printNewline.
-
+ "/ 'host ' print. value printNewline.
+ metaData at:#HostComputer put:value.
^ self
].
(tagType == 317) ifTrue:[
"predictor"
predictor := value.
-
- "/ 'predictor ' print. predictor printNewline.
-
+ "/ 'predictor ' print. predictor printNewline.
^ self
].
(tagType == 318) ifTrue:[
"whitePoint"
-
- "/ 'whitePoint ' print. value printNewline.
-
+ "/ 'whitePoint ' print. value printNewline.
+ metaData at:#WhitePoint put:value.
^ self
].
(tagType == 319) ifTrue:[
"primaryChromatics"
-
- "/ 'primaryChromatics ' print. value printNewline.
-
+ "/ 'primaryChromatics ' print. value printNewline.
+ metaData at:#PrimaryChromatics put:value.
^ self
].
(tagType == 320) ifTrue:[
"ColorMap"
- "/ 'colorMap (size=' print. valueArray size print. ')' printNewline.
+ "/ 'colorMap (size=' print. valueArray size print. ')' printNewline.
"
the tiff colormap contains 16bit values;
@@ -659,44 +618,37 @@
].
(tagType == 321) ifTrue:[
"halftonehints"
-
- "/ 'halftonehints' print. value printNewline.
-
+ "/ 'halftonehints' print. value printNewline.
+ metaData at:#HalftoneHints put:value.
^ self
].
(tagType == 322) ifTrue:[
"tilewidth"
-
- "/ 'tilewidth' print. value printNewline.
-
+ "/ 'tilewidth' print. value printNewline.
+ metaData at:#TileWidth put:value.
^ self
].
(tagType == 323) ifTrue:[
"tilelength"
-
- "/ 'tilelength' print. value printNewline.
-
+ "/ 'tilelength' print. value printNewline.
+ metaData at:#TileLength put:value.
^ self
].
(tagType == 324) ifTrue:[
"tileoffsets"
-
- "/ 'tileoffsets' print. value printNewline.
-
+ "/ 'tileoffsets' print. value printNewline.
+ metaData at:#TileOffsets put:value.
^ self
].
(tagType == 325) ifTrue:[
"tilebytecounts"
-
- "/ 'tilebytecounts' print. value printNewline.
-
+ "/ 'tilebytecounts' print. value printNewline.
+ metaData at:#TileByteCounts put:value.
^ self
].
(tagType == 326) ifTrue:[
"BadFaxLines"
-
- "/ 'badFaxLines' print. value printNewline.
-
+ "/ 'badFaxLines' print. value printNewline.
^ self
].
(tagType == 327) ifTrue:[
@@ -743,35 +695,33 @@
(tagType == 333) ifTrue:[
"ink names"
- "/ 'ink names' print. value printNewline.
-
+ "/ 'ink names' print. value printNewline.
+ metaData at:#IncNames put:value.
^ self
].
(tagType == 336) ifTrue:[
"dot range"
- "/ 'dot range' print. value printNewline.
-
+ "/ 'dot range' print. value printNewline.
^ self
].
(tagType == 337) ifTrue:[
"target printer"
- "/ 'target printer' print. value printNewline.
-
+ "/ 'target printer' print. value printNewline.
^ self
].
(tagType == 338) ifTrue:[
"extrasamples"
- "/ 'extrasamples' print. value printNewline.
+ "/ 'extrasamples' print. value printNewline.
^ self
].
(tagType == 339) ifTrue:[
"sample format"
- "/ 'sample format' print. value printNewline.
+ "/ 'sample format' print. value printNewline.
^ self
].
@@ -2127,7 +2077,8 @@
].
"setup default values"
-
+ metaData := TIFFMetaData new.
+
compression := 1. "none"
fillOrder := #msb.
planarConfiguration := 1.
@@ -2206,7 +2157,7 @@
tmp := ByteArray new:bytesPerRow.
offset1 := 1.
offset2 := (height-1)*bytesPerRow + 1.
- 0 to:(height-1//2) do:[:row |
+ 0 to:((height-1)//2) do:[:row |
tmp replaceFrom:1 to:bytesPerRow
with:data startingAt:offset1.
data replaceFrom:offset1 to:offset1+bytesPerRow-1