47 |
47 |
48 private long stripOrTileByteCountsPosition = -1; |
48 private long stripOrTileByteCountsPosition = -1; |
49 private long stripOrTileOffsetsPosition = -1; |
49 private long stripOrTileOffsetsPosition = -1; |
50 private long lastPosition = -1; |
50 private long lastPosition = -1; |
51 |
51 |
|
52 |
|
53 /** |
|
54 * Converts a {@code TIFFDirectory} to a {@code TIFFIFD}. |
|
55 */ |
|
56 public static TIFFIFD getDirectoryAsIFD(TIFFDirectory dir) { |
|
57 if(dir instanceof TIFFIFD) { |
|
58 return (TIFFIFD)dir; |
|
59 } |
|
60 |
|
61 TIFFIFD ifd = new TIFFIFD(Arrays.asList(dir.getTagSets()), |
|
62 dir.getParentTag()); |
|
63 TIFFField[] fields = dir.getTIFFFields(); |
|
64 int numFields = fields.length; |
|
65 for(int i = 0; i < numFields; i++) { |
|
66 TIFFField f = fields[i]; |
|
67 TIFFTag tag = f.getTag(); |
|
68 if(tag.isIFDPointer()) { |
|
69 TIFFDirectory subDir = null; |
|
70 if (f.hasDirectory()) { |
|
71 subDir = f.getDirectory(); |
|
72 } else if (f.getData() instanceof TIFFDirectory) { |
|
73 subDir = (TIFFDirectory)f.getData(); |
|
74 } |
|
75 if (subDir != null) { |
|
76 TIFFDirectory subIFD = getDirectoryAsIFD(subDir); |
|
77 f = new TIFFField(tag, f.getType(), (long)f.getCount(), |
|
78 subIFD); |
|
79 } else { |
|
80 f = null; |
|
81 } |
|
82 } |
|
83 if (f != null) { |
|
84 ifd.addTIFFField(f); |
|
85 } |
|
86 } |
|
87 |
|
88 return ifd; |
|
89 } |
|
90 |
52 public static TIFFTag getTag(int tagNumber, List<TIFFTagSet> tagSets) { |
91 public static TIFFTag getTag(int tagNumber, List<TIFFTagSet> tagSets) { |
53 Iterator<TIFFTagSet> iter = tagSets.iterator(); |
92 Iterator<TIFFTagSet> iter = tagSets.iterator(); |
54 while (iter.hasNext()) { |
93 while (iter.hasNext()) { |
55 TIFFTagSet tagSet = iter.next(); |
94 TIFFTagSet tagSet = iter.next(); |
56 TIFFTag tag = tagSet.getTag(tagNumber); |
95 TIFFTag tag = tagSet.getTag(tagNumber); |
702 stream.writeInt((int)nextSpace); |
741 stream.writeInt((int)nextSpace); |
703 stream.seek(nextSpace); |
742 stream.seek(nextSpace); |
704 pos = nextSpace; |
743 pos = nextSpace; |
705 |
744 |
706 if (tag.isIFDPointer() && f.hasDirectory()) { |
745 if (tag.isIFDPointer() && f.hasDirectory()) { |
707 TIFFIFD subIFD = (TIFFIFD)f.getDirectory(); |
746 TIFFIFD subIFD = getDirectoryAsIFD(f.getDirectory()); |
708 subIFD.writeToStream(stream); |
747 subIFD.writeToStream(stream); |
709 nextSpace = subIFD.lastPosition; |
748 nextSpace = subIFD.lastPosition; |
710 } else { |
749 } else { |
711 writeTIFFFieldToStream(f, stream); |
750 writeTIFFFieldToStream(f, stream); |
712 nextSpace = stream.getStreamPosition(); |
751 nextSpace = stream.getStreamPosition(); |