Changeset 3170
- Timestamp:
- 09/18/07 09:46:23 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/loci/formats/in/DicomReader.java
r3097 r3170 25 25 package loci.formats.in; 26 26 27 import java.awt.image. BufferedImage;27 import java.awt.image.*; 28 28 import java.io.*; 29 29 import java.text.*; … … 91 91 private boolean inSequence; 92 92 private boolean bigEndianTransferSyntax; 93 private boolean indexed = false; 94 private byte[][] lut; 93 95 94 96 // -- Constructor -- … … 112 114 } 113 115 116 /* @see loci.formats.IFormatReader#isIndexed() */ 117 public boolean isIndexed() { 118 FormatTools.assertId(currentId, true, 1); 119 return indexed; 120 } 121 122 /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 123 public byte[][] get8BitLookupTable() { 124 FormatTools.assertId(currentId, true, 1); 125 return lut; 126 } 127 114 128 /* @see loci.formats.IFormatReader#openBytes(int) */ 115 129 public byte[] openBytes(int no) throws FormatException, IOException { 116 130 FormatTools.assertId(currentId, true, 1); 117 byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8)]; 131 int bytes = core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8); 132 if (!indexed) bytes *= core.sizeC[0]; 133 byte[] buf = new byte[bytes]; 118 134 return openBytes(no, buf); 119 135 } … … 129 145 130 146 int bytes = core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8); 147 if (!indexed) bytes *= core.sizeC[0]; 131 148 132 149 if (buf.length < bytes) { … … 142 159 public BufferedImage openImage(int no) throws FormatException, IOException { 143 160 FormatTools.assertId(currentId, true, 1); 144 return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 145 1, false, bitsPerPixel / 8, core.littleEndian[0]); 161 BufferedImage b = ImageTools.makeImage(openBytes(no), core.sizeX[0], 162 core.sizeY[0], indexed ? 1 : core.sizeC[0], core.interleaved[0], 163 bitsPerPixel / 8, core.littleEndian[0]); 164 if (indexed) { 165 byte[][] table = get8BitLookupTable(); 166 IndexedColorModel model = 167 new IndexedColorModel(8, table[0].length, table); 168 WritableRaster raster = Raster.createWritableRaster(b.getSampleModel(), 169 b.getData().getDataBuffer(), null); 170 b = new BufferedImage(model, raster, false, null); 171 } 172 return b; 146 173 } 147 174 … … 270 297 271 298 core.sizeZ[0] = core.imageCount[0]; 272 core.sizeC[0] = 1; 299 if (core.sizeC[0] == 0) core.sizeC[0] = 1; 300 core.rgb[0] = core.sizeC[0] > 1; 273 301 core.sizeT[0] = 1; 274 core.currentOrder[0] = "XYZTC"; 275 core.rgb[0] = false; 276 core.interleaved[0] = false; 302 core.currentOrder[0] = "XYCZT"; 303 core.interleaved[0] = true; 277 304 278 305 // The metadata store we're working with. … … 341 368 342 369 private void addInfo(int tag, String value) throws IOException { 370 long oldFp = in.getFilePointer(); 343 371 String info = getHeaderInfo(tag, value); 344 372 if (inSequence && info != null && vr != SQ) info = ">" + info; … … 346 374 String key = (String) TYPES.get(new Integer(tag)); 347 375 if (key == null) key = "" + tag; 376 if (key.equals("Samples per pixel")) { 377 core.sizeC[0] = Integer.parseInt(info.trim()); 378 if (core.sizeC[0] > 1) core.rgb[0] = true; 379 } 380 else if (key.equals("Photometric Interpretation")) { 381 if (info.trim().equals("PALETTE COLOR")) { 382 indexed = true; 383 core.sizeC[0] = 3; 384 core.rgb[0] = true; 385 lut = new byte[3][]; 386 } 387 } 388 else if (key.indexOf("Palette Color LUT Data") != -1) { 389 String color = key.substring(0, key.indexOf(" ")).trim(); 390 int ndx = color.equals("Red") ? 0 : color.equals("Green") ? 1 : 2; 391 long fp = in.getFilePointer(); 392 in.seek(oldFp + ndx*ndx); 393 lut[ndx] = new byte[elementLength / 2]; 394 for (int i=0; i<lut[ndx].length; i++) { 395 lut[ndx][i] = (byte) (in.read() & 0xff); 396 in.skipBytes(1); 397 } 398 in.seek(fp); 399 } 400 348 401 if (tag != PIXEL_DATA) addMeta(key, info); 349 402 } … … 408 461 value = ""; 409 462 boolean privateTag = ((tag >> 16) & 1) != 0; 410 if (tag == ICON_IMAGE_SEQUENCE || privateTag) skip = true; 411 break; 463 if (tag != ICON_IMAGE_SEQUENCE && !privateTag) break; 412 464 default: 413 465 skip = true; … … 498 550 499 551 int elementWord = in.readShort(); 500 int tag = groupWord << 16 | elementWord;552 int tag = ((groupWord << 16) & 0xffff0000) | (elementWord & 0xffff); 501 553 elementLength = getLength(); 502 554
Note: See TracChangeset
for help on using the changeset viewer.