forked from locationtech/geotrellis
/
TiffTagsReader.scala
625 lines (550 loc) · 23.3 KB
/
TiffTagsReader.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
package geotrellis.raster.io.geotiff.reader
import geotrellis.raster.io.geotiff.tags._
import geotrellis.raster.io.geotiff.tags.codes._
import TagCodes._
import TiffFieldType._
import geotrellis.raster.io.geotiff.util._
import geotrellis.util.{Filesystem, ByteReader}
import spire.syntax.cfor._
import monocle.syntax.apply._
import scala.language.implicitConversions
import java.nio.{ ByteBuffer, ByteOrder }
object TiffTagsReader {
def read(path: String): TiffTags =
read(Filesystem.toMappedByteBuffer(path))
def read(bytes: Array[Byte]): TiffTags =
read(ByteBuffer.wrap(bytes))
def read(byteBuffer: ByteReader): TiffTags = {
(byteBuffer.get.toChar, byteBuffer.get.toChar) match {
case ('I', 'I') => byteBuffer.order(ByteOrder.LITTLE_ENDIAN)
case ('M', 'M') => byteBuffer.order(ByteOrder.BIG_ENDIAN)
case _ => throw new MalformedGeoTiffException("incorrect byte order")
}
// Validate GeoTiff identification number
val geoTiffIdNumber = byteBuffer.getChar
if ( geoTiffIdNumber != 42)
throw new MalformedGeoTiffException(s"bad identification number (must be 42, was $geoTiffIdNumber)")
val tagsStartPosition = byteBuffer.getInt
read(byteBuffer, tagsStartPosition)
}
def read(byteBuffer: ByteReader, tagsStartPosition: Int): TiffTags = {
byteBuffer.position(tagsStartPosition)
val tagCount = byteBuffer.getShort
// Read the tags.
var tiffTags = TiffTags()
// Need to read geo tags last, relies on other tags already being read in.
var geoTags: Option[TiffTagMetadata] = None
cfor(0)(_ < tagCount, _ + 1) { i =>
val tagMetadata =
TiffTagMetadata(
byteBuffer.getUnsignedShort, // Tag
byteBuffer.getUnsignedShort, // Type
byteBuffer.getInt, // Count
byteBuffer.getInt // Offset
)
if (tagMetadata.tag == codes.TagCodes.GeoKeyDirectoryTag) {
geoTags = Some(tagMetadata)
} else {
tiffTags = readTag(byteBuffer, tiffTags, tagMetadata)
}
}
println(s"the gotags is: $geoTags") //, and the tifftags are: $tiffTags")
geoTags match {
case Some(t) => tiffTags = readTag(byteBuffer, tiffTags, t)
case None =>
}
tiffTags
}
def readTag(byteBuffer: ByteReader, tiffTags: TiffTags, tagMetadata: TiffTagMetadata): TiffTags =
(tagMetadata.tag, tagMetadata.fieldType) match {
case (ModelPixelScaleTag, _) =>
byteBuffer.readModelPixelScaleTag(tiffTags, tagMetadata)
case (ModelTiePointsTag, _) =>
byteBuffer.readModelTiePointsTag(tiffTags, tagMetadata)
case (GeoKeyDirectoryTag, _) =>
byteBuffer.readGeoKeyDirectoryTag(tiffTags, tagMetadata)
case (_, BytesFieldType) =>
byteBuffer.readBytesTag(tiffTags, tagMetadata)
case (_, AsciisFieldType) =>
byteBuffer.readAsciisTag(tiffTags, tagMetadata)
case (_, ShortsFieldType) =>
byteBuffer.readShortsTag(tiffTags, tagMetadata)
case (_, IntsFieldType) =>
byteBuffer.readIntsTag(tiffTags, tagMetadata)
case (_, FractionalsFieldType) =>
byteBuffer.readFractionalsTag(tiffTags, tagMetadata)
case (_, SignedBytesFieldType) =>
byteBuffer.readSignedBytesTag(tiffTags, tagMetadata)
case (_, UndefinedFieldType) =>
byteBuffer.readUndefinedTag(tiffTags, tagMetadata)
case (_, SignedShortsFieldType) =>
byteBuffer.readSignedShortsTag(tiffTags, tagMetadata)
case (_, SignedIntsFieldType) =>
byteBuffer.readSignedIntsTag(tiffTags, tagMetadata)
case (_, SignedFractionalsFieldType) =>
byteBuffer.readSignedFractionalsTag(tiffTags, tagMetadata)
case (_, FloatsFieldType) =>
byteBuffer.readFloatsTag(tiffTags, tagMetadata)
case (_, DoublesFieldType) =>
byteBuffer.readDoublesTag(tiffTags, tagMetadata)
}
implicit class ByteBufferTagReaderWrapper(val byteBuffer: ByteReader) extends AnyVal {
def readModelPixelScaleTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val oldPos = byteBuffer.position
byteBuffer.position(tagMetadata.offset)
val scaleX = byteBuffer.getDouble
val scaleY = byteBuffer.getDouble
val scaleZ = byteBuffer.getDouble
byteBuffer.position(oldPos)
(tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._modelPixelScale set(Some(scaleX, scaleY, scaleZ)))
}
def readModelTiePointsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val oldPos = byteBuffer.position
val numberOfPoints = tagMetadata.length / 6
val points = Array.ofDim[(Pixel3D, Pixel3D)](numberOfPoints)
cfor(0)(_ < numberOfPoints, _ + 1) { i =>
points(i) =
(
Pixel3D(
byteBuffer.getDouble,
byteBuffer.getDouble,
byteBuffer.getDouble
),
Pixel3D(
byteBuffer.getDouble,
byteBuffer.getDouble,
byteBuffer.getDouble
)
)
}
byteBuffer.position(oldPos)
(tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._modelTiePoints set(Some(points)))
}
def readGeoKeyDirectoryTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val oldPos = byteBuffer.position
byteBuffer.position(tagMetadata.offset)
println("ByteBuffer position before reading in keydirectorymetadata is", byteBuffer.getByteBuffer.position)
val o = byteBuffer.getByteBuffer.position
cfor(0)(_ < 25, _ + 1) { i =>
println(byteBuffer.getByteBuffer.get)
}
byteBuffer.position(o)
val version = byteBuffer.getShort
val keyRevision = byteBuffer.getShort
val minorRevision = byteBuffer.getShort
val numberOfKeys = byteBuffer.getShort
//println(byteBuffer.getByteBuffer.position)
//println(version, keyRevision, minorRevision, numberOfKeys)
val keyDirectoryMetadata = GeoKeyDirectoryMetadata(version, keyRevision,
minorRevision, numberOfKeys)
//println(byteBuffer.getByteBuffer.position)
//println(keyDirectoryMetadata)
val geoKeyDirectory = GeoKeyReader.read(byteBuffer,
tiffTags, GeoKeyDirectory(count = numberOfKeys))
//println(byteBuffer.getByteBuffer.position)
byteBuffer.position(oldPos)
(tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._geoKeyDirectory set(Some(geoKeyDirectory)))
}
def readBytesTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val bytes = byteBuffer.getByteArray(tagMetadata.length, tagMetadata.offset)
tagMetadata.tag match {
case DotRangeTag => tiffTags &|->
TiffTags._cmykTags ^|->
CmykTags._dotRange set(Some(bytes.map(_.toInt)))
case ExtraSamplesTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._extraSamples set(Some(bytes.map(_.toInt)))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tag -> bytes.map(_.toLong)))
}
}
def readAsciisTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata): TiffTags = {
// Read string, but don't read in trailing 0
val string =
byteBuffer.getString(tagMetadata.length, tagMetadata.offset).substring(0, tagMetadata.length - 1)
tagMetadata.tag match {
case DateTimeTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._dateTime set(Some(string))
case ImageDescTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._imageDesc set(Some(string))
case MakerTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._maker set(Some(string))
case ModelTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._model set(Some(string))
case SoftwareTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._software set(Some(string))
case ArtistTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._artist set(Some(string))
case HostComputerTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._hostComputer set(Some(string))
case CopyrightTag => tiffTags &|->
TiffTags._metadataTags ^|->
MetadataTags._copyright set(Some(string))
case AsciisTag => tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._asciis set(Some(string))
case MetadataTag => tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._metadata set(Some(string))
case GDALInternalNoDataTag =>
tiffTags.setGDALNoData(string)
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._asciisMap modify(_ + (tag -> string))
}
}
def readShortsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val shorts = byteBuffer.getShortArray(tagMetadata.length,
tagMetadata.offset)
tagMetadata.tag match {
case SubfileTypeTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._subfileType set(Some(shorts(0)))
case ImageWidthTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._imageWidth set(shorts(0))
case ImageLengthTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._imageLength set(shorts(0))
case CompressionTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._compression set(shorts(0))
case PhotometricInterpTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._photometricInterp set(shorts(0))
case ThresholdingTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._thresholding set(shorts(0))
case CellWidthTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._cellWidth set(Some(shorts(0)))
case CellLengthTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._cellLength set(Some(shorts(0)))
case FillOrderTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._fillOrder set((shorts(0)))
case OrientationTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._orientation set(shorts(0))
case SamplesPerPixelTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._samplesPerPixel set(shorts(0))
case RowsPerStripTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._rowsPerStrip set(shorts(0))
case PlanarConfigurationTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._planarConfiguration set(Some(shorts(0)))
case GrayResponseUnitTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._grayResponseUnit set(Some(shorts(0)))
case ResolutionUnitTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._resolutionUnit set(Some(shorts(0)))
case PredictorTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._predictor set(Some(shorts(0)))
case TileWidthTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileWidth set(Some(shorts(0)))
case TileLengthTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileLength set(Some(shorts(0)))
case InkSetTag => tiffTags &|->
TiffTags._cmykTags ^|->
CmykTags._inkSet set(Some(shorts(0)))
case NumberOfInksTag => tiffTags &|->
TiffTags._cmykTags ^|->
CmykTags._numberOfInks set(Some(shorts(0)))
case JpegProcTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegProc set(Some(shorts(0)))
case JpegInterchangeFormatTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegInterchangeFormat set(Some(shorts(0)))
case JpegInterchangeFormatLengthTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegInterchangeFormatLength set(Some(shorts(0)))
case JpegRestartIntervalTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegRestartInterval set(Some(shorts(0)))
case YCbCrPositioningTag => tiffTags &|->
TiffTags._yCbCrTags ^|->
YCbCrTags._yCbCrPositioning set(Some(shorts(0)))
case BitsPerSampleTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._bitsPerSample set(shorts(0))
case StripOffsetsTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._stripOffsets set(Some(shorts))
case StripByteCountsTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._stripByteCounts set(Some(shorts))
case MinSampleValueTag => tiffTags &|->
TiffTags._dataSampleFormatTags ^|->
DataSampleFormatTags._minSampleValue set(Some(shorts.map(_.toLong)))
case MaxSampleValueTag => tiffTags &|->
TiffTags._dataSampleFormatTags ^|->
DataSampleFormatTags._maxSampleValue set(Some(shorts.map(_.toLong)))
case GrayResponseCurveTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._grayResponseCurve set(Some(shorts))
case PageNumberTag => tiffTags &|->
TiffTags._documentationTags ^|->
DocumentationTags._pageNumber set(Some(shorts))
case TransferFunctionTag => tiffTags &|->
TiffTags._colimetryTags ^|->
ColimetryTags._transferFunction set(Some(shorts))
case ColorMapTag => setColorMap(tiffTags, shorts)
case HalftoneHintsTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._halftoneHints set(Some(shorts))
case TileByteCountsTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileByteCounts set(Some(shorts))
case DotRangeTag => tiffTags &|->
TiffTags._cmykTags ^|->
CmykTags._dotRange set(Some(shorts))
case SampleFormatTag => tiffTags &|->
TiffTags._dataSampleFormatTags ^|->
DataSampleFormatTags._sampleFormat set(shorts(0))
case TransferRangeTag => tiffTags &|->
TiffTags._colimetryTags ^|->
ColimetryTags._transferRange set(Some(shorts))
case JpegLosslessPredictorsTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegLosslessPredictors set(Some(shorts))
case JpegPointTransformsTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegPointTransforms set(Some(shorts))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tag -> shorts.map(_.toLong)))
}
}
def setColorMap(tiffTags: TiffTags, shorts: Array[Int]): TiffTags =
if ((tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._photometricInterp get) == 3) {
val divider = shorts.size / 3
val arr = Array.ofDim[(Short, Short, Short)](divider)
cfor(0)(_ < divider, _ + 1) { i =>
arr(i) = (
shorts(i).toShort,
shorts(i + divider).toShort,
shorts(i + 2 * divider).toShort
)
}
(tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._colorMap set arr.toSeq)
} else throw new MalformedGeoTiffException(
"Colormap without Photometric Interpetation = 3."
)
def readIntsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val ints = byteBuffer.getIntArray(tagMetadata.length, tagMetadata.offset)
tagMetadata.tag match {
case NewSubfileTypeTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._newSubfileType set(Some(ints(0)))
case ImageWidthTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._imageWidth set(ints(0).toInt)
case ImageLengthTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._imageLength set(ints(0).toInt)
case T4OptionsTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._t4Options set(ints(0).toInt)
case T6OptionsTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._t6Options set(Some(ints(0).toInt))
case TileWidthTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileWidth set(Some(ints(0)))
case TileLengthTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileLength set(Some(ints(0)))
case JpegInterchangeFormatTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegInterchangeFormat set(Some(ints(0)))
case JpegInterchangeFormatLengthTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegInterchangeFormatLength set(Some(ints(0)))
case RowsPerStripTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._rowsPerStrip set(ints(0))
case StripOffsetsTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._stripOffsets set(Some(ints.map(_.toInt)))
case StripByteCountsTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._stripByteCounts set(Some(ints.map(_.toInt)))
case FreeOffsetsTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._freeOffsets set(Some(ints))
case FreeByteCountsTag => tiffTags &|->
TiffTags._nonBasicTags ^|->
NonBasicTags._freeByteCounts set(Some(ints))
case TileOffsetsTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileOffsets set(Some(ints.map(_.toInt)))
case TileByteCountsTag => tiffTags &|->
TiffTags._tileTags ^|->
TileTags._tileByteCounts set(Some(ints.map(_.toInt)))
case JpegQTablesTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegQTables set(Some(ints))
case JpegDCTablesTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegDCTables set(Some(ints))
case JpegACTablesTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegACTables set(Some(ints))
case ReferenceBlackWhiteTag => tiffTags &|->
TiffTags._colimetryTags ^|->
ColimetryTags._referenceBlackWhite set(Some(ints))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tag -> ints.map(_.toLong)))
}
}
def readFractionalsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val fractionals = byteBuffer.getFractionalArray(tagMetadata.length,
tagMetadata.offset)
tagMetadata.tag match {
case XResolutionTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._xResolution set(Some(fractionals(0)))
case YResolutionTag => tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._yResolution set(Some(fractionals(0)))
case XPositionTag => tiffTags &|->
TiffTags._documentationTags ^|->
DocumentationTags._xPositions set(Some(fractionals))
case YPositionTag => tiffTags &|->
TiffTags._documentationTags ^|->
DocumentationTags._yPositions set(Some(fractionals))
case WhitePointTag => tiffTags &|->
TiffTags._colimetryTags ^|->
ColimetryTags._whitePoints set(Some(fractionals))
case PrimaryChromaticitiesTag => tiffTags &|->
TiffTags._colimetryTags ^|->
ColimetryTags._primaryChromaticities set(Some(fractionals))
case YCbCrCoefficientsTag => tiffTags &|->
TiffTags._yCbCrTags ^|->
YCbCrTags._yCbCrCoefficients set(Some(fractionals))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._fractionalsMap modify(
_ + (tag -> fractionals)
)
}
}
def readSignedBytesTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val bytes = byteBuffer.getSignedByteArray(tagMetadata.length,
tagMetadata.offset)
(tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tagMetadata.tag -> bytes.map(_.toLong))))
}
def readUndefinedTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val bytes = byteBuffer.getSignedByteArray(tagMetadata.length, tagMetadata.offset)
tagMetadata.tag match {
case JpegTablesTag => tiffTags &|->
TiffTags._jpegTags ^|->
JpegTags._jpegTables set(Some(bytes))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._undefinedMap modify(_ + (tag -> bytes))
}
}
def readSignedShortsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val shorts = byteBuffer.getSignedShortArray(tagMetadata.length,
tagMetadata.offset)
(tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tagMetadata.tag -> shorts.map(_.toLong))))
}
def readSignedIntsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val ints = byteBuffer.getSignedIntArray(tagMetadata.length,
tagMetadata.offset)
(tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._longsMap modify(_ + (tagMetadata.tag -> ints.map(_.toLong))))
}
def readSignedFractionalsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val fractionals = byteBuffer.getSignedFractionalArray(tagMetadata.length,
tagMetadata.offset)
(tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._fractionalsMap modify(
_ + (tagMetadata.tag -> fractionals.map(x => (x._1.toLong, x._2.toLong)))
))
}
def readFloatsTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val floats = byteBuffer.getFloatArray(tagMetadata.length,
tagMetadata.offset)
(tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._doublesMap modify(
_ + (tagMetadata.tag -> floats.map(_.toDouble))
))
}
def readDoublesTag(tiffTags: TiffTags,
tagMetadata: TiffTagMetadata) = {
val doubles = byteBuffer.getDoubleArray(tagMetadata.length, tagMetadata.offset)
tagMetadata.tag match {
case ModelTransformationTag =>
if (doubles.size != 16)
throw new MalformedGeoTiffException("bad model tranformations")
else {
val matrix = Array(
Array(doubles(0), doubles(1), doubles(2), doubles(3)),
Array(doubles(4), doubles(5), doubles(6), doubles(7)),
Array(doubles(8), doubles(9), doubles(10), doubles(11)),
Array(doubles(12), doubles(13), doubles(14), doubles(15))
)
(tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._modelTransformation set(Some(matrix)))
}
case DoublesTag => tiffTags &|->
TiffTags._geoTiffTags ^|->
GeoTiffTags._doubles set(Some(doubles))
case tag => tiffTags &|->
TiffTags._nonStandardizedTags ^|->
NonStandardizedTags._doublesMap modify(_ + (tag -> doubles))
}
}
}
}