Changeset 3225
- Timestamp:
- 10/04/07 14:58:50 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/loci/formats/in/OMETiffReader.java
r3221 r3225 103 103 int fileIndex = -1; 104 104 int[] savedCoords = new int[] {-1, -1, -1}; 105 for (int i=0; i<coordinateMap[series].size(); i++) { 106 int[] firstZCT = (int[]) coordinateMap[series].get(new Integer(i)); 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]); 107 110 if (firstZCT[0] <= zct[0] && firstZCT[1] <= zct[1] && 108 111 firstZCT[2] <= zct[2] && firstZCT[0] >= savedCoords[0] && … … 110 113 { 111 114 savedCoords = firstZCT; 112 fileIndex = i;115 fileIndex = keys[i].intValue(); 113 116 } 114 117 } 115 118 in = new RandomAccessStream(used[fileIndex]); 116 119 ifds = TiffTools.getIFDs(in); 117 TiffTools.getSamples(ifds[no % ifds.length], in, buf); 120 int firstIFD = ((int[]) coordinateMap[series].get(keys[fileIndex]))[3]; 121 TiffTools.getSamples(ifds[firstIFD + (no % ifds.length)], in, buf); 118 122 in.close(); 119 123 return swapIfRequired(buf); … … 126 130 super.initStandardMetadata(); 127 131 128 String imageId = (String) getMeta("Comment"); 129 int ndx = imageId.indexOf("<Image"); 130 ndx = imageId.indexOf("ID=\"", ndx); 131 imageId = imageId.substring(ndx + 4, imageId.indexOf("\"", ndx + 5)); 132 133 int[] numIFDs = null; 132 String comment = (String) getMeta("Comment"); 133 boolean lsids = true; 134 135 // find list of Image IDs 136 Vector v = new Vector(); 137 String check = "<Image "; 138 int ndx = comment.indexOf(check); 139 while (ndx >= 0) { 140 int ii = comment.indexOf("ID=\"", ndx); 141 v.add(comment.substring(ii + 4, comment.indexOf("\"", ii + 5))); 142 ndx = comment.indexOf(check, ndx + 1); 143 } 144 String[] imageIds = (String[]) v.toArray(new String[0]); 145 for (int i=0; i<imageIds.length; i++) { 146 if (!imageIds[i].toLowerCase().startsWith("urn:lsid")) { 147 lsids = false; 148 break; 149 } 150 } 151 152 // find list of Pixels IDs 153 v.clear(); 154 check = "<Pixels "; 155 ndx = comment.indexOf(check); 156 while (ndx >= 0) { 157 int ii = comment.indexOf("ID=\"", ndx); 158 v.add(comment.substring(ii + 4, comment.indexOf("\"", ii + 5))); 159 ndx = comment.indexOf(check, ndx + 1); 160 } 161 String[] pixelsIds = (String[]) v.toArray(new String[0]); 162 for (int i=0; i<pixelsIds.length; i++) { 163 if (!pixelsIds[i].toLowerCase().startsWith("urn:lsid")) { 164 lsids = false; 165 break; 166 } 167 } 168 169 int numSeries = pixelsIds.length; 170 171 int[] numIFDs = new int[numSeries]; 134 172 135 173 // only look for files in the same dataset if LSIDs are present 136 if ( imageId.indexOf("urn:lsid") != -1) {174 if (lsids) { 137 175 Vector files = new Vector(); 138 176 Location l = new Location(currentId); 139 177 l = l.getAbsoluteFile().getParentFile(); 140 178 String[] fileList = l.list(); 141 Vector tempComments = new Vector(); 179 coordinateMap = new Hashtable[numSeries]; 180 for (int i=0; i<numSeries; i++) { 181 coordinateMap[i] = new Hashtable(); 182 } 142 183 143 184 for (int i=0; i<fileList.length; i++) { 144 Stringcheck = fileList[i].toLowerCase();185 check = fileList[i].toLowerCase(); 145 186 if (check.endsWith(".tif") || check.endsWith(".tiff")) { 146 187 Hashtable ifd = TiffTools.getFirstIFD(new RandomAccessStream( 147 188 l.getAbsolutePath() + File.separator + fileList[i])); 148 189 if (ifd == null) continue; 149 Stringcomment =190 comment = 150 191 (String) TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 151 tempComments.add(comment); 152 ndx = comment.indexOf("<Image"); 153 ndx = comment.indexOf("ID=\"", ndx); 154 if (ndx > -1) { 155 comment = 156 comment.substring(ndx + 4, comment.indexOf("\"", ndx + 5)); 157 if (comment.equals(imageId)) { 158 files.add(l.getAbsolutePath() + File.separator + fileList[i]); 192 boolean addToList = true; 193 for (int s=0; s<imageIds.length; s++) { 194 if (comment.indexOf(imageIds[s]) == -1) { 195 addToList = false; 196 break; 159 197 } 160 198 } 199 if (addToList) { 200 for (int s=0; s<pixelsIds.length; s++) { 201 if (comment.indexOf(pixelsIds[s]) == -1) { 202 addToList = false; 203 } 204 } 205 } 206 207 if (addToList) { 208 files.add(l.getAbsolutePath() + File.separator + fileList[i]); 209 210 ByteArrayInputStream is = 211 new ByteArrayInputStream(comment.getBytes()); 212 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 213 Document doc = null; 214 try { 215 DocumentBuilder builder = factory.newDocumentBuilder(); 216 doc = builder.parse(is); 217 } 218 catch (ParserConfigurationException exc) { } 219 catch (SAXException exc) { } 220 catch (IOException exc) { } 221 222 if (doc != null) { 223 NodeList pixelsList = doc.getElementsByTagName("Pixels"); 224 for (int j=0; j<numSeries; j++) { 225 NodeList list = ((Element) pixelsList.item(j)).getChildNodes(); 226 Element tiffData = null; 227 for (int q=0; q<list.getLength(); q++) { 228 if (((Node) list.item(q)).getNodeName().equals("TiffData")) { 229 tiffData = (Element) list.item(q); 230 break; 231 } 232 } 233 String firstZ = tiffData.getAttribute("FirstZ"); 234 String firstC = tiffData.getAttribute("FirstC"); 235 String firstT = tiffData.getAttribute("FirstT"); 236 String firstIFD = tiffData.getAttribute("IFD"); 237 if (firstZ == null || firstZ.equals("")) firstZ = "0"; 238 if (firstC == null || firstC.equals("")) firstC = "0"; 239 if (firstT == null || firstT.equals("")) firstT = "0"; 240 if (firstIFD == null || firstIFD.equals("")) firstIFD = "0"; 241 coordinateMap[j].put(new Integer(files.size() - 1), 242 new int[] {Integer.parseInt(firstZ), Integer.parseInt(firstC), 243 Integer.parseInt(firstT), Integer.parseInt(firstIFD)}); 244 numIFDs[j] += TiffTools.getIFDs(new RandomAccessStream( 245 (String) files.get(files.size() - 1))).length; 246 } 247 } 248 } 161 249 } 162 250 } 163 251 164 252 used = (String[]) files.toArray(new String[0]); 165 166 // reorder TIFF files167 for (int i=0; i<files.size(); i++) {168 String comment = (String) tempComments.get(i);169 ByteArrayInputStream is = new ByteArrayInputStream(comment.getBytes());170 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();171 Document doc = null;172 try {173 DocumentBuilder builder = factory.newDocumentBuilder();174 doc = builder.parse(is);175 }176 catch (ParserConfigurationException exc) { }177 catch (SAXException exc) { }178 catch (IOException exc) { }179 180 if (doc != null) {181 int numSeries = doc.getElementsByTagName("Pixels").getLength();182 if (coordinateMap == null) coordinateMap = new Hashtable[numSeries];183 if (numIFDs == null) numIFDs = new int[numSeries];184 Vector v = new Vector();185 NodeList pixelsList = doc.getElementsByTagName("Pixels");186 Element[] tiffData = null;187 for (int j=0; j<numSeries; j++) {188 if (coordinateMap[j] == null) coordinateMap[j] = new Hashtable();189 NodeList list = ((Element) pixelsList.item(j)).getChildNodes();190 int size = list.getLength();191 v.clear();192 for (int k=0; k<size; k++) {193 Node node = list.item(k);194 if ("TiffData".equals(node.getNodeName())) v.add(node);195 }196 tiffData = new Element[v.size()];197 v.copyInto(tiffData);198 199 String firstZ = tiffData[0].getAttribute("FirstZ");200 String firstC = tiffData[0].getAttribute("FirstC");201 String firstT = tiffData[0].getAttribute("FirstT");202 if (firstZ == null || firstZ.equals("")) firstZ = "0";203 if (firstC == null || firstC.equals("")) firstC = "0";204 if (firstT == null || firstT.equals("")) firstT = "0";205 coordinateMap[j].put(new Integer(i),206 new int[] {Integer.parseInt(firstZ),207 Integer.parseInt(firstC), Integer.parseInt(firstT)});208 numIFDs[j] += TiffTools.getIFDs(209 new RandomAccessStream((String) files.get(i))).length;210 }211 }212 }213 253 } 214 254 else { … … 216 256 LogTools.println("Not searching for other files - " + 217 257 "Image LSID not present."); 258 numIFDs[0] = ifds.length; 218 259 } 219 260 220 261 int oldX = core.sizeX[0]; 221 262 int oldY = core.sizeY[0]; 222 Stringcomment = (String) getMeta("Comment");263 comment = (String) getMeta("Comment"); 223 264 224 265 // convert string to DOM … … 239 280 if (doc != null) { 240 281 NodeList pixelsList = doc.getElementsByTagName("Pixels"); 241 int n umSeries = pixelsList.getLength();242 Vectorv = new Vector();243 pixels = new Element[n umSeries];244 tiffData = new Element[n umSeries][];245 for (int i=0; i<n umSeries; i++) {282 int nSeries = pixelsList.getLength(); 283 v = new Vector(); 284 pixels = new Element[nSeries]; 285 tiffData = new Element[nSeries][]; 286 for (int i=0; i<nSeries; i++) { 246 287 pixels[i] = (Element) pixelsList.item(i); 247 288 NodeList list = pixels[i].getChildNodes(); … … 271 312 if (tiffData != null) { 272 313 boolean rgb = isRGB(); 314 boolean indexed = isIndexed(); 315 boolean falseColor = isFalseColor(); 273 316 core = new CoreMetadata(tiffData.length); 274 317 Arrays.fill(core.orderCertain, true); 318 Arrays.fill(core.indexed, indexed); 319 Arrays.fill(core.falseColor, falseColor); 275 320 276 321 for (int i=0; i<tiffData.length; i++) { … … 296 341 if (core.sizeT[i] < 1) core.sizeT[i] = 1; 297 342 343 if (rgb && indexed && core.sizeC[i] == 3) { 344 rgb = false; 345 core.indexed[i] = false; 346 core.falseColor[i] = false; 347 } 348 298 349 int sc = core.sizeC[i]; 299 if (rgb ) sc /= 3;350 if (rgb && sc > 1) sc /= 3; 300 351 core.imageCount[i] = core.sizeZ[i] * sc * core.sizeT[i]; 301 352 core.rgb[i] = rgb; … … 316 367 core.orderCertain[i] = true; 317 368 318 if (numIFDs != null ) {369 if (numIFDs != null && lsids) { 319 370 if (numIFDs[i] < core.imageCount[i]) { 320 371 LogTools.println("Too few IFDs; got " + numIFDs[i] + ", expected " +
Note: See TracChangeset
for help on using the changeset viewer.