Changeset 3238
- Timestamp:
- 10/08/07 11:53:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/loci/formats/in/OMETiffReader.java
r3230 r3238 48 48 private String[] used; 49 49 50 private Hashtable[] coordinateMap; 50 private int[][] ifdMap; 51 private int[][] fileMap; 51 52 52 53 // -- Constructor -- … … 95 96 FormatTools.checkBufferSize(this, buf.length); 96 97 97 if (used.length == 1 && series == 0) { 98 TiffTools.getSamples(ifds[no], in, buf); 99 return swapIfRequired(buf); 100 } 101 102 int[] zct = getZCTCoords(no); 103 int fileIndex = -1; 104 int[] savedCoords = new int[] {-1, -1, -1}; 105 Integer[] keys = 106 (Integer[]) coordinateMap[series].keySet().toArray(new Integer[0]); 107 108 for (int i=0; i<keys.length; i++) { 109 int[] firstZCT = (int[]) coordinateMap[series].get(keys[i]); 110 if (firstZCT[0] <= zct[0] && firstZCT[1] <= zct[1] && 111 firstZCT[2] <= zct[2] && firstZCT[0] >= savedCoords[0] && 112 firstZCT[1] >= savedCoords[1] && firstZCT[2] >= savedCoords[2]) 113 { 114 savedCoords = firstZCT; 115 fileIndex = keys[i].intValue(); 116 } 117 } 98 int ifd = ifdMap[series][no]; 99 int fileIndex = fileMap[series][no]; 100 118 101 in = new RandomAccessStream(used[fileIndex]); 119 102 ifds = TiffTools.getIFDs(in); 120 int firstIFD = ((int[]) coordinateMap[series].get(keys[fileIndex]))[3]; 121 TiffTools.getSamples(ifds[firstIFD + (no % ifds.length)], in, buf); 103 TiffTools.getSamples(ifds[ifd], in, buf); 122 104 in.close(); 123 105 return swapIfRequired(buf); … … 176 158 l = l.getAbsoluteFile().getParentFile(); 177 159 String[] fileList = l.list(); 178 coordinateMap = new Hashtable[numSeries]; 179 for (int i=0; i<numSeries; i++) { 180 coordinateMap[i] = new Hashtable(); 181 } 160 ifdMap = new int[numSeries][]; 161 fileMap = new int[numSeries][]; 162 182 163 if (!lsids) { 183 164 fileList = new String[] {currentId}; … … 186 167 } 187 168 169 Vector comments = new Vector(); 170 188 171 for (int i=0; i<fileList.length; i++) { 189 172 check = fileList[i].toLowerCase(); 190 173 if (check.endsWith(".tif") || check.endsWith(".tiff")) { 191 Hashtable ifd = TiffTools.getFirstIFD(new RandomAccessStream( 192 l.getAbsolutePath() + File.separator + fileList[i])); 193 if (ifd == null) continue; 174 ifds = TiffTools.getIFDs(new RandomAccessStream(l.getAbsolutePath() + 175 File.separator + fileList[i])); 176 // TODO - need accurate IFD count 177 for (int j=0; j<numSeries; j++) { 178 numIFDs[j] += ifds.length; 179 } 180 if (ifds[0] == null) continue; 194 181 comment = 195 (String) TiffTools.getIFDValue(ifd , TiffTools.IMAGE_DESCRIPTION);182 (String) TiffTools.getIFDValue(ifds[0], TiffTools.IMAGE_DESCRIPTION); 196 183 boolean addToList = true; 197 184 for (int s=0; s<imageIds.length; s++) { … … 211 198 if (addToList) { 212 199 files.add(l.getAbsolutePath() + File.separator + fileList[i]); 213 214 ByteArrayInputStream is = 215 new ByteArrayInputStream(comment.getBytes()); 216 DocumentBuilderFactory factory = 217 DocumentBuilderFactory.newInstance(); 218 Document doc = null; 219 try { 220 DocumentBuilder builder = factory.newDocumentBuilder(); 221 doc = builder.parse(is); 222 } 223 catch (ParserConfigurationException exc) { } 224 catch (SAXException exc) { } 225 catch (IOException exc) { } 226 227 if (doc != null) { 228 NodeList pixelsList = doc.getElementsByTagName("Pixels"); 229 for (int j=0; j<numSeries; j++) { 230 NodeList list = ((Element) pixelsList.item(j)).getChildNodes(); 231 // if there are multiple TiffData elements, find the one with 232 // the smallest ZCT coordinates 233 234 v = new Vector(); 235 for (int q=0; q<list.getLength(); q++) { 236 if (((Node) list.item(q)).getNodeName().equals("TiffData")) { 237 v.add(list.item(q)); 238 } 239 } 240 Element[] tiffData = (Element[]) v.toArray(new Element[0]); 241 int[] smallestCoords = new int[4]; 242 Arrays.fill(smallestCoords, Integer.MAX_VALUE); 243 for (int q=0; q<tiffData.length; q++) { 244 String firstZ = tiffData[q].getAttribute("FirstZ"); 245 String firstC = tiffData[q].getAttribute("FirstC"); 246 String firstT = tiffData[q].getAttribute("FirstT"); 247 String firstIFD = tiffData[q].getAttribute("IFD"); 248 if (firstZ == null || firstZ.equals("")) firstZ = "0"; 249 if (firstC == null || firstC.equals("")) firstC = "0"; 250 if (firstT == null || firstT.equals("")) firstT = "0"; 251 if (firstIFD == null || firstIFD.equals("")) firstIFD = "0"; 252 int z = Integer.parseInt(firstZ); 253 int c = Integer.parseInt(firstC); 254 int t = Integer.parseInt(firstT); 255 if (z <= smallestCoords[0] && c <= smallestCoords[1] && 256 t <= smallestCoords[2]) 257 { 258 smallestCoords[0] = z; 259 smallestCoords[1] = c; 260 smallestCoords[2] = t; 261 smallestCoords[3] = Integer.parseInt(firstIFD); 262 } 263 } 264 coordinateMap[j].put(new Integer(files.size() - 1), 265 smallestCoords); 266 numIFDs[j] += TiffTools.getIFDs(new RandomAccessStream( 267 (String) files.get(files.size() - 1))).length; 200 comments.add(comment); 201 } 202 } 203 } 204 205 used = (String[]) files.toArray(new String[0]); 206 207 for (int i=0; i<numSeries; i++) { 208 ifdMap[i] = new int[numIFDs[i]]; 209 fileMap[i] = new int[numIFDs[i]]; 210 } 211 212 // set ifdMap and fileMap based on TiffData elements 213 for (int i=0; i<used.length; i++) { 214 String com = (String) comments.get(i); 215 ByteArrayInputStream is = new ByteArrayInputStream(com.getBytes()); 216 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 217 Document doc = null; 218 try { 219 DocumentBuilder builder = factory.newDocumentBuilder(); 220 doc = builder.parse(is); 221 } 222 catch (ParserConfigurationException exc) { } 223 catch (SAXException exc) { } 224 catch (IOException exc) { } 225 226 Element[] pixels = null; 227 if (doc != null) { 228 NodeList pixelsList = doc.getElementsByTagName("Pixels"); 229 pixels = new Element[pixelsList.getLength()]; 230 for (int j=0; j<pixels.length; j++) { 231 pixels[j] = (Element) pixelsList.item(j); 232 233 String order = pixels[j].getAttribute("DimensionOrder"); 234 int z = Integer.parseInt(pixels[j].getAttribute("SizeZ")); 235 int c = Integer.parseInt(pixels[j].getAttribute("SizeC")); 236 int t = Integer.parseInt(pixels[j].getAttribute("SizeT")); 237 238 NodeList list = pixels[j].getChildNodes(); 239 int size = list.getLength(); 240 v.clear(); 241 for (int k=0; k<size; k++) { 242 Node node = list.item(k); 243 if (!(node instanceof Element)) continue; 244 if ("TiffData".equals(node.getNodeName())) { 245 v.add(node); 268 246 } 269 247 } 270 } 271 } 272 } 273 274 used = (String[]) files.toArray(new String[0]); 248 Element[] tiffData = new Element[v.size()]; 249 v.copyInto(tiffData); 250 251 int ifdCount = 252 TiffTools.getIFDs(new RandomAccessStream(used[i])).length; 253 254 for (int k=0; k<tiffData.length; k++) { 255 String ifd = tiffData[k].getAttribute("IFD"); 256 String numPlanes = tiffData[k].getAttribute("NumPlanes"); 257 String firstZ = tiffData[k].getAttribute("FirstZ"); 258 String firstC = tiffData[k].getAttribute("FirstC"); 259 String firstT = tiffData[k].getAttribute("FirstT"); 260 if (ifd == null || ifd.equals("")) ifd = "0"; 261 if (numPlanes == null || numPlanes.equals("")) { 262 numPlanes = "" + ifdCount; 263 } 264 if (firstZ == null || firstZ.equals("")) firstZ = "0"; 265 if (firstC == null || firstC.equals("")) firstC = "0"; 266 if (firstT == null || firstT.equals("")) firstT = "0"; 267 268 int idx = FormatTools.getIndex(order, z, c, t, z * c * t, 269 Integer.parseInt(firstZ), Integer.parseInt(firstC), 270 Integer.parseInt(firstT)); 271 272 ifdMap[j][idx] = Integer.parseInt(ifd) % ifdCount; 273 fileMap[j][idx] = i; 274 for (int q=0; q<Integer.parseInt(numPlanes); q++) { 275 ifdMap[j][idx + q] = ifdMap[j][idx] + q; 276 fileMap[j][idx + q] = i; 277 } 278 } 279 } 280 } 281 } 275 282 276 283 comment = (String) getMeta("Comment");
Note: See TracChangeset
for help on using the changeset viewer.