Changeset 2922
- Timestamp:
- 06/29/07 13:03:59 (12 years ago)
- Location:
- trunk/loci/formats
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/loci/formats/in/AliconaReader.java
r2842 r2922 75 75 } 76 76 77 long offset = textureOffset;78 79 77 for (int i=0; i<numBytes; i++) { 80 in.seek( offset + (no * (core.sizeX[0] + pad)*core.sizeY[0]*(i+1)));78 in.seek(textureOffset + (no * (core.sizeX[0] + pad)*core.sizeY[0]*(i+1))); 81 79 for (int j=0; j<core.sizeX[0] * core.sizeY[0]; j++) { 82 buf[j*numBytes + i] = (byte) in.read();80 buf[j*numBytes + i] = (byte) (in.read() & 0xff); 83 81 if (j % core.sizeX[0] == core.sizeX[0] - 1) in.skipBytes(pad); 84 82 } … … 105 103 // check that this is a valid AL3D file 106 104 status("Verifying Alicona format"); 107 byte[] check = new byte[17]; 108 in.read(check); 109 String magicString = new String(check); 105 String magicString = in.readString(17); 110 106 if (!magicString.trim().equals("AliconaImaging")) { 111 107 throw new FormatException("Invalid magic string : " + … … 118 114 status("Reading tags"); 119 115 120 byte[] keyBytes = new byte[20];121 byte[] valueBytes = new byte[30];122 123 116 int count = 2; 124 117 … … 128 121 129 122 for (int i=0; i<count; i++) { 130 in.read(keyBytes); 131 in.read(valueBytes); 132 in.skipBytes(2); 133 134 String key = new String(keyBytes); 135 String value = new String(valueBytes); 123 String key = in.readString(20); 124 String value = in.readString(30); 136 125 key = key.trim(); 137 126 value = value.trim(); 138 127 139 128 addMeta(key, value); 129 in.skipBytes(2); 140 130 141 131 if (key.equals("TagCount")) count += Integer.parseInt(value); -
trunk/loci/formats/in/BMPReader.java
r2876 r2922 121 121 for (int y=core.sizeY[0]-1; y>=0; y--) { 122 122 for (int x=0; x<core.sizeX[0]; x++) { 123 buf[y*core.sizeX[0] + x] = (byte) in.read();123 buf[y*core.sizeX[0] + x] = (byte) (in.read() & 0xff); 124 124 } 125 125 } … … 129 129 for (int x=0; x<core.sizeX[0]; x++) { 130 130 int off = y*core.sizeX[0] + x; 131 buf[2*core.sizeX[0]*core.sizeY[0] + off] = (byte) in.read();132 buf[core.sizeX[0]*core.sizeY[0] + off] = (byte) in.read();133 buf[off] = (byte) in.read();131 buf[2*core.sizeX[0]*core.sizeY[0] + off] = (byte)(in.read() & 0xff); 132 buf[core.sizeX[0]*core.sizeY[0] + off] = (byte) (in.read() & 0xff); 133 buf[off] = (byte) (in.read() & 0xff); 134 134 } 135 in.skipBytes(2);136 135 } 137 136 } … … 161 160 // read the first header - 14 bytes 162 161 163 byte[] two = new byte[2]; 164 in.read(two); 165 addMeta("Magic identifier", new String(two)); 162 addMeta("Magic identifier", in.readString(2)); 166 163 167 164 addMeta("File size (in bytes)", "" + in.readInt()); … … 226 223 for (int i=0; i<nColors; i++) { 227 224 for (int j=palette.length; j>0; j--) { 228 palette[j][i] = (byte) in.read();225 palette[j][i] = (byte) (in.read() & 0xff); 229 226 } 230 227 in.read(); -
trunk/loci/formats/in/BaseTiffReader.java
r2857 r2922 492 492 core.rgb[0] = samples > 1 || p == TiffTools.RGB_PALETTE || 493 493 p == TiffTools.CFA_ARRAY || p == TiffTools.RGB; 494 //core.interleaved[0] = TiffTools.getSamplesPerPixel(ifds[0]) > 1;495 494 core.interleaved[0] = true; 496 495 core.littleEndian[0] = TiffTools.isLittleEndian(ifds[0]); … … 513 512 else if (bitFormat == 2) { 514 513 switch (bps) { 515 case 8:516 core.pixelType[0] = FormatTools.UINT8;517 break;518 514 case 16: 519 515 core.pixelType[0] = FormatTools.INT16; … … 528 524 else { 529 525 switch (bps) { 530 case 8:531 core.pixelType[0] = FormatTools.UINT8;532 break;533 526 case 16: 534 527 core.pixelType[0] = FormatTools.UINT16; -
trunk/loci/formats/in/BioRadReader.java
r2802 r2922 146 146 byteFormat = in.readShort() != 0; 147 147 int imageNumber = in.readShort(); 148 byte[] s = new byte[32]; 149 in.read(s); 150 String name = new String(s); 148 String name = in.readString(32); 151 149 int merged = in.readShort(); 152 150 int color1 = in.readShort(); … … 220 218 int x = in.readShort(); 221 219 int y = in.readShort(); 222 s = new byte[80]; 223 in.read(s); 224 String text = new String(s); 220 String text = in.readString(80); 225 221 226 222 // be sure to remove binary data from the note text … … 765 761 for (int i=0; i<core.sizeC[0]; i++) { 766 762 store.setLogicalChannel(i, null, null, null, null, null, null, null); 767 768 double white = ramp1max; 769 double black = ramp1min; 770 771 store.setDisplayChannel(new Integer(i), new Double(black), 772 new Double(white), null, null); 763 store.setDisplayChannel(new Integer(i), new Double(ramp1max), 764 new Double(ramp1min), null, null); 773 765 } 774 766 store.setDisplayOptions(zoom == null ? null : new Float(zoom), -
trunk/loci/formats/in/DeltavisionReader.java
r2762 r2922 51 51 private int bytesPerPixel; 52 52 53 /** Offset where the ExtHdr starts. */54 protected int initExtHdrOffset = 1024;55 56 53 /** Size of one wave in the extended header. */ 57 54 protected int wSize; … … 64 61 65 62 /** 66 * the Number of ints in each extended header section. These fields appear63 * The number of ints in each extended header section. These fields appear 67 64 * to be all blank but need to be skipped to get to the floats afterwards 68 65 */ … … 84 81 /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 85 82 public boolean isThisType(byte[] block) { 86 return (DataTools.bytesToShort(block, 0, 2, core.littleEndian[0]) == 87 LITTLE_ENDIAN); 83 return false; 88 84 } 89 85 … … 347 343 new DVExtHdrFields[core.sizeZ[0]][core.sizeC[0]][core.sizeT[0]]; 348 344 345 hstream.close(); 346 349 347 store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]), 350 348 new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]), … … 361 359 // Run through every timeslice, for each wavelength, for each z section 362 360 // and fill in the Extended Header information array for that image 363 for (int z = 0; z <core.sizeZ[0]; z++) {364 for (int t = 0; t <core.sizeT[0]; t++) {365 for (int w = 0; w <core.sizeC[0]; w++) {361 for (int z=0; z<core.sizeZ[0]; z++) { 362 for (int t=0; t<core.sizeT[0]; t++) { 363 for (int w=0; w<core.sizeC[0]; w++) { 366 364 extHdrFields[z][w][t] = new DVExtHdrFields(getTotalOffset(z, w, t), 367 365 numIntsPerSection, extHeader, core.littleEndian[0]); … … 572 570 byte[] extHeader, boolean little) 573 571 { 574 // skip over the int values that have nothing in them 575 offsetWithInts = startingOffset + (numIntsPerSection * 4); 576 577 // DV files store the ND (neuatral density) Filter (normally expressed as 578 // a %T (transmittance)) as an OD (optical density) rating. 579 // To convert from one to the other the formula is %T = 10^(-OD) X 100. 580 oDFilter = Float.intBitsToFloat( 581 DataTools.bytesToInt(extHeader, offsetWithInts + 36, 4, little)); 582 583 // fill in the extended header information for the floats 584 photosensorReading = 585 Float.intBitsToFloat( 586 DataTools.bytesToInt(extHeader, offsetWithInts, 4, little)); 587 timeStampSeconds = 588 Float.intBitsToFloat( 589 DataTools.bytesToInt(extHeader, offsetWithInts + 4, 4, little)); 590 stageXCoord = 591 Float.intBitsToFloat( 592 DataTools.bytesToInt(extHeader, offsetWithInts + 8, 4, little)); 593 stageYCoord = 594 Float.intBitsToFloat( 595 DataTools.bytesToInt(extHeader, offsetWithInts + 12, 4, little)); 596 stageZCoord = 597 Float.intBitsToFloat( 598 DataTools.bytesToInt(extHeader, offsetWithInts + 16, 4, little)); 599 minInten = 600 Float.intBitsToFloat( 601 DataTools.bytesToInt(extHeader, offsetWithInts + 20, 4, little)); 602 maxInten = 603 Float.intBitsToFloat( 604 DataTools.bytesToInt(extHeader, offsetWithInts + 24, 4, little)); 605 meanInten = 606 Float.intBitsToFloat( 607 DataTools.bytesToInt(extHeader, offsetWithInts + 28, 4, little)); 608 expTime = 609 Float.intBitsToFloat( 610 DataTools.bytesToInt(extHeader, offsetWithInts + 32, 4, little)); 611 ndFilter = (float) Math.pow(10.0, -oDFilter); 612 exFilter = 613 Float.intBitsToFloat( 614 DataTools.bytesToInt(extHeader, offsetWithInts + 40, 4, little)); 615 emFilter = 616 Float.intBitsToFloat( 617 DataTools.bytesToInt(extHeader, offsetWithInts + 44, 4, little)); 618 exWavelen = 619 Float.intBitsToFloat( 620 DataTools.bytesToInt(extHeader, offsetWithInts + 48, 4, little)); 621 emWavelen = 622 Float.intBitsToFloat( 623 DataTools.bytesToInt(extHeader, offsetWithInts + 52, 4, little)); 624 intenScaling = 625 Float.intBitsToFloat( 626 DataTools.bytesToInt(extHeader, offsetWithInts + 56, 4, little)); 627 energyConvFactor = 628 Float.intBitsToFloat( 629 DataTools.bytesToInt(extHeader, offsetWithInts + 60, 4, little)); 572 try { 573 RandomAccessStream ext = new RandomAccessStream(extHeader); 574 ext.order(little); 575 576 // skip over the int values that have nothing in them 577 offsetWithInts = startingOffset + (numIntsPerSection * 4); 578 579 // DV files store the ND (neuatral density) Filter 580 // (normally expressed as a %T (transmittance)) as an OD 581 // (optical density) rating. 582 // To convert from one to the other the formula is %T = 10^(-OD) X 100. 583 ext.seek(offsetWithInts + 36); 584 oDFilter = ext.readFloat(); 585 586 // fill in the extended header information for the floats 587 ext.seek(offsetWithInts); 588 photosensorReading = ext.readFloat(); 589 timeStampSeconds = ext.readFloat(); 590 stageXCoord = ext.readFloat(); 591 stageYCoord = ext.readFloat(); 592 stageZCoord = ext.readFloat(); 593 minInten = ext.readFloat(); 594 maxInten = ext.readFloat(); 595 meanInten = ext.readFloat(); 596 expTime = ext.readFloat(); 597 ndFilter = (float) Math.pow(10.0, -oDFilter); 598 ext.skipBytes(4); 599 600 exFilter = ext.readFloat(); 601 emFilter = ext.readFloat(); 602 exWavelen = ext.readFloat(); 603 emWavelen = ext.readFloat(); 604 intenScaling = ext.readFloat(); 605 energyConvFactor = ext.readFloat(); 606 } 607 catch (IOException e) { 608 LogTools.trace(e); 609 } 630 610 } 631 611 -
trunk/loci/formats/in/DicomReader.java
r2905 r2922 93 93 // "Digital Imaging and Communications in Medicine" is nasty long. 94 94 public DicomReader() { 95 super("Digital Img. & Comm. in Med.", 96 new String[] {"dcm", "dicom"}); 95 super("Digital Img. & Comm. in Med.", new String[] {"dcm", "dicom"}); 97 96 } 98 97 … … 154 153 status("Verifying DICOM format"); 155 154 156 byte[] four = new byte[4];157 long pos = 0;158 155 in.seek(128); 159 in.read(four); 160 if ((new String(four)).equals("DICM")) { 156 if (in.readString(4).equals("DICM")) { 161 157 // header exists, so we'll read it 162 in.seek(pos); 163 byte[] header = new byte[128]; 164 in.read(header); 165 addMeta("Header information", new String(header)); 158 in.seek(0); 159 addMeta("Header information", in.readString(128)); 166 160 in.readInt(); 167 161 location = 128; 168 162 } 169 else in.seek( pos);163 else in.seek(0); 170 164 171 165 status("Reading tags"); … … 188 182 switch (tag) { 189 183 case TRANSFER_SYNTAX_UID: 190 byte[] st = new byte[elementLength]; 191 in.read(st); 192 s = new String(st); 184 s = in.readString(elementLength); 193 185 addInfo(tag, s); 194 186 if (s.indexOf("1.2.4") > -1 || s.indexOf("1.2.5") > -1) { … … 201 193 break; 202 194 case NUMBER_OF_FRAMES: 203 st = new byte[elementLength]; 204 in.read(st); 205 s = new String(st); 195 s = in.readString(elementLength); 206 196 addInfo(tag, s); 207 197 double frames = Double.parseDouble(s); … … 213 203 break; 214 204 case PHOTOMETRIC_INTERPRETATION: 215 st = new byte[elementLength]; 216 in.read(st); 217 String photoInterpretation = new String(st); 218 addInfo(tag, photoInterpretation); 205 addInfo(tag, in.readString(elementLength)); 219 206 break; 220 207 case PLANAR_CONFIGURATION: 221 int planarConfiguration = in.readShort(); 222 addInfo(tag, planarConfiguration); 208 addInfo(tag, in.readShort()); 223 209 break; 224 210 case ROWS: … … 231 217 break; 232 218 case PIXEL_SPACING: 233 st = new byte[elementLength]; 234 in.read(st); 235 String scale = new String(st); 236 addInfo(tag, scale); 219 addInfo(tag, in.readString(elementLength)); 237 220 break; 238 221 case SLICE_SPACING: 239 st = new byte[elementLength]; 240 in.read(st); 241 String spacing = new String(st); 242 addInfo(tag, spacing); 222 addInfo(tag, in.readString(elementLength)); 243 223 break; 244 224 case BITS_ALLOCATED: … … 247 227 break; 248 228 case PIXEL_REPRESENTATION: 249 int pixelRepresentation = in.readShort(); 250 addInfo(tag, pixelRepresentation); 229 addInfo(tag, in.readShort()); 251 230 break; 252 231 case WINDOW_CENTER: … … 254 233 case RESCALE_INTERCEPT: 255 234 case RESCALE_SLOPE: 256 st = new byte[elementLength]; 257 in.read(st); 258 String c = new String(st); 259 addInfo(tag, c); 235 addInfo(tag, in.readString(elementLength)); 260 236 break; 261 237 case PIXEL_DATA: … … 403 379 case TM: 404 380 case UI: 405 byte[] s = new byte[elementLength]; 406 in.read(s); 407 value = new String(s); 381 value = in.readString(elementLength); 408 382 break; 409 383 case US: … … 418 392 break; 419 393 case IMPLICIT_VR: 420 s = new byte[elementLength]; 421 in.read(s); 422 value = new String(s); 394 value = in.readString(elementLength); 423 395 if (elementLength <= 4 || elementLength > 44) value = null; 424 396 break; -
trunk/loci/formats/in/EPSReader.java
r2857 r2922 83 83 throw new FormatException("Invalid image number: " + no); 84 84 } 85 if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)) { 85 if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)) 86 { 86 87 throw new FormatException("Buffer too small."); 87 88 } -
trunk/loci/formats/in/FitsReader.java
r2805 r2922 99 99 count = 1; 100 100 101 byte[] b = new byte[80]; 102 in.read(b); 103 String line = new String(b); 101 String line = in.readString(80); 104 102 if (!line.startsWith("SIMPLE")) { 105 103 throw new FormatException("Unsupported FITS file."); … … 108 106 while (true) { 109 107 count++; 110 in.read(b); 111 line = new String(b); 112 108 line = in.readString(80); 109 113 110 // parse key/value pair 114 111 int ndx = line.indexOf("="); -
trunk/loci/formats/in/FluoviewReader.java
r2687 r2922 25 25 package loci.formats.in; 26 26 27 import java.awt.image.BufferedImage; 27 28 import java.io.*; 28 29 import java.util.*; … … 59 60 private float voxelX = 0f, voxelY = 0f, voxelZ = 0f, voxelC = 0f, voxelT = 0f; 60 61 62 /** First image. */ 63 private BufferedImage zeroImage = null; 64 61 65 // -- Constructor -- 62 66 63 67 /** Constructs a new Fluoview TIFF reader. */ 64 68 public FluoviewReader() { 65 super("Olympus Fluoview/Andor Bio-imaging TIFF", 66 new String[] {"tif", "tiff"}); 69 super("Olympus Fluoview/ABD TIFF", new String[] {"tif", "tiff"}); 67 70 } 68 71 … … 98 101 } 99 102 103 /* @see loci.formats.IFormatReader#openBytes(int) */ 104 public byte[] openBytes(int no) throws FormatException, IOException { 105 if (core.sizeY[0] == TiffTools.getImageLength(ifds[0])) { 106 return super.openBytes(no); 107 } 108 return openBytes(no, new byte[core.sizeX[0] * 109 FormatTools.getBytesPerPixel(core.pixelType[0])]); 110 } 111 112 /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 113 public byte[] openBytes(int no, byte[] buf) 114 throws FormatException, IOException 115 { 116 if (core.sizeY[0] == TiffTools.getImageLength(ifds[0])) { 117 return super.openBytes(no, buf); 118 } 119 FormatTools.assertId(currentId, false, 1); 120 if (no < 0 || no >= core.imageCount[0]) { 121 throw new FormatException("Invalid image number: " + no); 122 } 123 if (buf.length < core.sizeX[0] * 124 FormatTools.getBytesPerPixel(core.pixelType[0])) 125 { 126 throw new FormatException("Buffer too small."); 127 } 128 129 byte[] b = super.openBytes(0); 130 System.arraycopy(b, 0, buf, 0, buf.length); 131 return buf; 132 } 133 134 /* @see loci.formats.IFormatReader#openImage(int) */ 135 public BufferedImage openImage(int no) throws FormatException, IOException { 136 if (core.sizeY[0] == TiffTools.getImageLength(ifds[0])) { 137 return super.openImage(no); 138 } 139 140 if (zeroImage == null) zeroImage = super.openImage(0); 141 return zeroImage.getSubimage(0, no, core.sizeX[0], 1); 142 } 143 144 /* @see loci.formats.IFormatReader#close() */ 145 public void close() throws IOException { 146 super.close(); 147 zeroImage = null; 148 } 149 100 150 // -- IFormatHandler API methods -- 101 151 … … 138 188 put("Image Type", (char) ras.read()); 139 189 140 byte[] nameBytes = new byte[257]; 141 ras.read(nameBytes); 142 put("Image name", new String(nameBytes)); 190 put("Image name", ras.readString(257)); 143 191 144 192 ras.skipBytes(4); // skip pointer to data field … … 152 200 153 201 // read dimension information 154 byte[] dimNameBytes = new byte[16];155 byte[] dimCalibrationUnits = new byte[64];156 202 String[] names = new String[10]; 157 203 int[] sizes = new int[10]; 158 204 double[] resolutions = new double[10]; 159 205 for (int i=0; i<10; i++) { 160 ras.read(dimNameBytes); 161 names[i] = new String(dimNameBytes); 206 names[i] = ras.readString(16); 162 207 sizes[i] = ras.readInt(); 163 208 double origin = ras.readDouble(); 164 209 resolutions[i] = ras.readDouble(); 165 ras.read(dimCalibrationUnits);166 210 167 211 put("Dimension " + (i+1) + " Name", names[i]); … … 169 213 put("Dimension " + (i+1) + " Origin", origin); 170 214 put("Dimension " + (i+1) + " Resolution", resolutions[i]); 171 put("Dimension " + (i+1) + " Units", new String(dimCalibrationUnits));215 put("Dimension " + (i+1) + " Units", ras.readString(64)); 172 216 } 173 217 … … 186 230 187 231 // read gray channel data 188 ras.read(dimNameBytes); 189 put("Gray Channel Name", new String(dimNameBytes)); 232 put("Gray Channel Name", ras.readString(16)); 190 233 put("Gray Channel Size", ras.readInt()); 191 234 put("Gray Channel Origin", ras.readDouble()); 192 235 put("Gray Channel Resolution", ras.readDouble()); 193 ras.read(dimCalibrationUnits); 194 put("Gray Channel Units", new String(dimCalibrationUnits)); 236 put("Gray Channel Units", ras.readString(64)); 195 237 196 238 ras.skipBytes(4); // skip pointer to thumbnail data … … 267 309 core.imageCount[0] = ifds.length; 268 310 311 if (core.imageCount[0] == 1 && (core.sizeT[0] == core.sizeY[0] || 312 core.sizeZ[0] == core.sizeY[0]) && (core.sizeT[0] > core.imageCount[0] || 313 core.sizeZ[0] > core.imageCount[0])) 314 { 315 core.sizeY[0] = 1; 316 core.imageCount[0] = core.sizeZ[0] * core.sizeT[0] * core.sizeC[0]; 317 } 318 269 319 // cut up the comment, if necessary 270 320 String comment = (String) getMeta("Comment"); -
trunk/loci/formats/in/GIFReader.java
r2701 r2922 25 25 package loci.formats.in; 26 26 27 import java.awt.Rectangle;28 27 import java.awt.image.BufferedImage; 29 28 import java.io.*; … … 40 39 // -- Constants -- 41 40 42 /** Status codes. */43 private static final int STATUS_OK = 0;44 private static final int STATUS_FORMAT_ERROR = 1;45 private static final int STATUS_OPEN_ERROR = 2;46 47 41 /** Maximum buffer size. */ 48 42 private static final int MAX_STACK_SIZE = 4096; … … 50 44 // -- Fields -- 51 45 52 private int status;53 54 46 /** Global color table used. */ 55 47 private boolean gctFlag; … … 58 50 private int gctSize; 59 51 60 /** Iterations; 0 = repeat forever. */61 private int loopCount;62 63 52 /** Global color table. */ 64 53 private int[] gct; … … 76 65 private int bgColor; 77 66 78 /** Previous bg color. */79 private int lastBgColor;80 81 /** Pixel aspect ratio. */82 private int pixelAspect;83 84 67 /** Local color table flag. */ 85 68 private boolean lctFlag; … … 94 77 private int ix, iy, iw, ih; 95 78 96 /** Last image rectangle. */97 private Rectangle lastRect;98 99 79 /** Current data block. */ 100 80 private byte[] dBlock = new byte[256]; … … 108 88 /** Use transparent color. */ 109 89 private boolean transparency = false; 110 111 /** Delay in ms. */112 private int delay = 0;113 90 114 91 /** Transparent color index. */ … … 127 104 /** Constructs a new GIF reader. */ 128 105 public GIFReader() { 129 super("Graphics Interchange Format (GIF)", "gif");106 super("Graphics Interchange Format", "gif"); 130 107 } 131 108 … … 155 132 156 133 int[] ints = (int[]) images.get(no); 134 if (no > 0) { 135 int[] prev = (int[]) images.get(no - 1); 136 for (int i=0; i<ints.length; i++) { 137 if ((ints[i] & 0x00ffffff) == 0) { 138 ints[i] = prev[i]; 139 } 140 } 141 images.setElementAt(ints, no); 142 } 157 143 158 144 for (int i=0; i<ints.length; i++) { … … 183 169 status("Verifying GIF format"); 184 170 185 status = STATUS_OK;186 171 in = new RandomAccessStream(id); 172 in.order(true); 187 173 images = new Vector(); 188 174 189 byte[] buf = new byte[6]; 190 in.read(buf); 191 String ident = new String(buf); 175 String ident = in.readString(6); 192 176 193 177 if (!ident.startsWith("GIF")) { … … 197 181 status("Reading dimensions"); 198 182 199 core.sizeX[0] = DataTools.read2UnsignedBytes(in, true);200 core.sizeY[0] = DataTools.read2UnsignedBytes(in, true);201 202 int packed = DataTools.readUnsignedByte(in);183 core.sizeX[0] = in.readShort(); 184 core.sizeY[0] = in.readShort(); 185 186 int packed = in.read() & 0xff; 203 187 gctFlag = (packed & 0x80) != 0; 204 188 gctSize = 2 << (packed & 7); 205 bgIndex = DataTools.readUnsignedByte(in);206 pixelAspect = DataTools.readUnsignedByte(in);189 bgIndex = in.read() & 0xff; 190 in.skipBytes(1); 207 191 208 192 if (gctFlag) { 209 193 int nbytes = 3 * gctSize; 210 194 byte[] c = new byte[nbytes]; 211 in t n = in.read(c);195 in.read(c); 212 196 213 197 gct = new int[256]; … … 229 213 boolean done = false; 230 214 while (!done) { 231 int code = DataTools.readUnsignedByte(in);215 int code = in.read() & 0xff; 232 216 switch (code) { 233 217 case 0x2c: // image separator: 234 ix = DataTools.read2UnsignedBytes(in, true);235 iy = DataTools.read2UnsignedBytes(in, true);236 iw = DataTools.read2UnsignedBytes(in, true);237 ih = DataTools.read2UnsignedBytes(in, true);238 239 packed = DataTools.readUnsignedByte(in);218 ix = in.readShort(); 219 iy = in.readShort(); 220 iw = in.readShort(); 221 ih = in.readShort(); 222 223 packed = in.read(); 240 224 lctFlag = (packed & 0x80) != 0; 241 225 interlace = (packed & 0x40) != 0; … … 290 274 291 275 lastDispose = dispose; 292 lastRect = new Rectangle(ix, iy, iw, ih);293 lastBgColor = bgColor;294 276 lct = null; 295 277 296 278 break; 297 279 case 0x21: // extension 298 code = DataTools.readUnsignedByte(in);280 code = in.read() & 0xff; 299 281 switch (code) { 300 282 case 0xf9: // graphics control extension 301 in. read();302 packed = DataTools.readUnsignedByte(in);283 in.skipBytes(1); 284 packed = in.read() & 0xff; 303 285 dispose = (packed & 0x1c) >> 1; 304 286 transparency = (packed & 1) != 0; 305 delay = DataTools.read2UnsignedBytes(in, true) * 10;306 transIndex = DataTools.readUnsignedByte(in);307 in. read();287 in.skipBytes(2); 288 transIndex = in.read() & 0xff; 289 in.skipBytes(1); 308 290 break; 309 291 case 0xff: // application extension … … 320 302 int b1 = ((int) dBlock[1]) & 0xff; 321 303 int b2 = ((int) dBlock[2]) & 0xff; 322 loopCount = (b2 << 8) | b1;323 304 } 324 305 } … … 381 362 private int readBlock() throws IOException { 382 363 if (in.getFilePointer() == in.length()) return -1; 383 blockSize = DataTools.readUnsignedByte(in);364 blockSize = in.read() & 0xff; 384 365 int n = 0; 385 366 int count; … … 413 394 414 395 // initialize GIF data stream decoder 415 416 dataSize = DataTools.readUnsignedByte(in);396 397 dataSize = in.read() & 0xff; 417 398 418 399 clear = 1 << dataSize; … … 422 403 codeSize = dataSize + 1; 423 404 codeMask = (1 << codeSize) - 1; 424 for (code=0; code <clear; code++) {405 for (code=0; code<clear; code++) { 425 406 prefix[code] = 0; 426 407 suffix[code] = (byte) code; -
trunk/loci/formats/in/GatanReader.java
r2701 r2922 37 37 public class GatanReader extends FormatReader { 38 38 39 // -- Constants --40 41 private static final byte[] GATAN_MAGIC_BLOCK_1 = {0, 0, 0, 3};42 43 39 // -- Fields -- 44 40 … … 63 59 /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 64 60 public boolean isThisType(byte[] block) { 65 if (block == null) return false; 66 if (block.length != GATAN_MAGIC_BLOCK_1.length) return false; 67 for (int i=0; i<block.length; i++) { 68 if (block[i] != GATAN_MAGIC_BLOCK_1[i]) return false; 69 } 70 return true; 61 if (block == null || block.length < 4) return false; 62 return DataTools.bytesToInt(block, false) == 3; 71 63 } 72 64 … … 97 89 /* @see loci.formats.IFormatReader#openImage(int) */ 98 90 public BufferedImage openImage(int no) throws FormatException, IOException { 99 FormatTools.assertId(currentId, true, 1);100 if (no < 0 || no >= getImageCount()) {101 throw new FormatException("Invalid image number: " + no);102 }103 104 91 return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 105 92 1, false, bytesPerPixel, core.littleEndian[0]); … … 120 107 pixelSizes = new Vector(); 121 108 122 byte[] tmp = new byte[4];123 in.read(tmp); 109 in.order(false); 110 124 111 // only support version 3 125 if ( !isThisType(tmp)) {112 if (in.readInt() != 3) { 126 113 throw new FormatException("invalid header"); 127 114 } … … 130 117 131 118 in.skipBytes(4); 132 in.read(tmp); 133 core.littleEndian[0] = DataTools.bytesToInt(tmp, core.littleEndian[0]) == 1; 119 core.littleEndian[0] = in.readInt() == 1; 134 120 135 121 // TagGroup instance 136 122 137 123 in.skipBytes(2); 138 in. read(tmp);139 parseTags( DataTools.bytesToInt(tmp, !core.littleEndian[0]), "initFile");124 in.order(!core.littleEndian[0]); 125 parseTags(in.readInt(), "initFile"); 140 126 141 127 status("Populating metadata"); … … 143 129 switch (datatype) { 144 130 case 1: 131 case 10: 145 132 core.pixelType[0] = FormatTools.UINT16; 146 133 break; 147 134 case 2: 148 core.pixelType[0] = FormatTools.FLOAT;149 break;150 135 case 3: 151 core.pixelType[0] = FormatTools.FLOAT;152 break;153 // there is no case 4154 136 case 5: 155 core.pixelType[0] = FormatTools.FLOAT;156 break;157 case 6:158 core.pixelType[0] = FormatTools.UINT8;159 break;160 case 7:161 core.pixelType[0] = FormatTools.INT32;162 break;163 case 8:164 core.pixelType[0] = FormatTools.UINT32;165 break;166 case 9:167 core.pixelType[0] = FormatTools.INT8;168 break;169 case 10:170 core.pixelType[0] = FormatTools.UINT16;171 break;172 case 11:173 core.pixelType[0] = FormatTools.UINT32;174 break;175 137 case 12: 176 core.pixelType[0] = FormatTools.FLOAT;177 break;178 138 case 13: 179 139 core.pixelType[0] = FormatTools.FLOAT; 180 140 break; 181 case 14:182 core.pixelType[0] = FormatTools.UINT8;183 break;141 case 7: 142 case 8: 143 case 11: 184 144 case 23: 185 core.pixelType[0] = FormatTools. INT32;145 core.pixelType[0] = FormatTools.UINT32; 186 146 break; 187 147 default: 188 core.pixelType[0] = FormatTools. INT8;148 core.pixelType[0] = FormatTools.UINT8; 189 149 } 190 150 … … 212 172 null); // Use pixels index 0 213 173 214 Float pixX = n ull;215 Float pixY = n ull;216 Float pixZ = n ull;174 Float pixX = new Float(1); 175 Float pixY = new Float(1); 176 Float pixZ = new Float(1); 217 177 218 178 if (pixelSizes.size() > 0) { 219 179 pixX = new Float((String) pixelSizes.get(0)); 220 180 } 221 else pixX = new Float(1);222 181 223 182 if (pixelSizes.size() > 1) { 224 183 pixY = new Float((String) pixelSizes.get(1)); 225 184 } 226 else pixY = new Float(1);227 185 228 186 if (pixelSizes.size() > 2) { 229 187 pixZ = new Float((String) pixelSizes.get(2)); 230 188 } 231 else pixZ = new Float(1);232 189 233 190 store.setDimensions(pixX, pixY, pixZ, null, null, null); … … 254 211 */ 255 212 private void parseTags(int numTags, String parent) throws IOException { 256 byte[] temp = new byte[4];257 213 for (int i=0; i<numTags; i++) { 258 214 byte type = in.readByte(); // can be 21 (data) or 20 (tag group) 259 byte[] twobytes = new byte[2]; 260 in.read(twobytes); 261 int length = DataTools.bytesToInt(twobytes, !core.littleEndian[0]); 262 byte[] label = new byte[length]; 263 in.read(label); 264 String labelString = new String(label); 215 int length = in.readShort(); 216 String labelString = in.readString(length); 265 217 266 218 // image data is in tag with type 21 and label 'Data' … … 270 222 if (type == 21) { 271 223 in.skipBytes(4); // equal to '%%%%' 272 in.read(temp); 273 int n = DataTools.bytesToInt(temp, !core.littleEndian[0]); 224 int n = in.readInt(); 274 225 int dataType = 0; 275 226 if (n == 1) { 276 in.read(temp); 277 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 227 dataType = in.readInt(); 278 228 String data; 229 in.order(core.littleEndian[0]); 279 230 switch (dataType) { 280 231 case 2: 281 data = "" + DataTools.read2SignedBytes(in, core.littleEndian[0]); 232 case 4: 233 data = "" + in.readShort(); 282 234 break; 283 235 case 3: 284 data = "" + DataTools.read4SignedBytes(in, core.littleEndian[0]); 285 break; 286 case 4: 287 data = 288 "" + DataTools.read2UnsignedBytes(in, core.littleEndian[0]); 289 break; 290 case 5: 291 data = 292 "" + DataTools.read4UnsignedBytes(in, core.littleEndian[0]); 236 case 5: 237 data = "" + in.readInt(); 293 238 break; 294 239 case 6: 295 data = "" + DataTools.readFloat(in, core.littleEndian[0]);240 data = "" + in.readFloat(); 296 241 break; 297 242 case 7: 298 data = "" + DataTools.readFloat(in, core.littleEndian[0]);243 data = "" + in.readFloat(); 299 244 in.skipBytes(4); 300 245 break; 301 246 case 8: 302 data = "" + DataTools.readSignedByte(in);303 break;304 247 case 9: 305 data = "" + DataTools.readSignedByte(in);306 break;307 248 case 10: 308 data = "" + DataTools.readSignedByte(in);249 data = "" + in.read(); 309 250 break; 310 251 default: … … 325 266 addMeta(labelString, data); 326 267 if (labelString.equals("DataType")) datatype = Integer.parseInt(data); 268 in.order(!core.littleEndian[0]); 327 269 } 328 270 else if (n == 2) { 329 in. read(temp);330 dataType = DataTools.bytesToInt(temp, core.littleEndian[0]);271 in.order(core.littleEndian[0]); 272 dataType = in.readInt(); 331 273 if (dataType == 18) { // this should always be true 332 in.read(temp); 333 length = DataTools.bytesToInt(temp, core.littleEndian[0]); 334 } 335 byte[] data = new byte[length]; 336 in.read(data); 337 addMeta(labelString, new String(label)); 274 length = in.readInt(); 275 } 276 addMeta(labelString, in.readString(length)); 277 in.order(!core.littleEndian[0]); 338 278 } 339 279 else if (n == 3) { 340 in.read(temp); 341 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 280 dataType = in.readInt(); 342 281 if (dataType == 20) { // this should always be true 343 in.read(temp); 344 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 345 in.read(temp); 346 length = DataTools.bytesToInt(temp, !core.littleEndian[0]); 282 dataType = in.readInt(); 283 length = in.readInt(); 347 284 348 285 if ("Data".equals(labelString)) pixelDataNum++; … … 365 302 check = in.readByte(); 366 303 } 367 in.seek(( int) (pos + bpp * length));304 in.seek((long) (pos + bpp * length)); 368 305 } 369 306 else { … … 371 308 for (int j=0; j<length; j++) { 372 309 if (dataType == 2 || dataType == 4) { 373 byte[] two = new byte[2]; 374 in.read(two); 375 data[j] = (int) DataTools.bytesToShort(two, 376 !core.littleEndian[0]); 310 data[j] = in.readShort(); 377 311 } 378 312 else if (dataType == 7) in.skipBytes(8); 379 313 else if (dataType == 8 || dataType == 9) in.skipBytes(1); 380 314 else { 381 in.read(temp); 382 data[j] = DataTools.bytesToInt(temp, !core.littleEndian[0]); 315 data[j] = in.readInt(); 383 316 } 384 317 } … … 387 320 } 388 321 else { 389 in.read(temp); 390 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 322 dataType = in.readInt(); 391 323 // this is a normal struct of simple types 392 324 if (dataType == 15) { 393 int skip = 0; 394 in.read(temp); 395 skip += DataTools.bytesToInt(temp, !core.littleEndian[0]); 396 in.read(temp); 397 int numFields = DataTools.bytesToInt(temp, !core.littleEndian[0]); 325 int skip = in.readInt(); 326 int numFields = in.readInt(); 398 327 for (int j=0; j<numFields; j++) { 399 in.read(temp); 400 skip += DataTools.bytesToInt(temp, !core.littleEndian[0]); 401 in.read(temp); 402 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 328 skip += in.readInt(); 329 dataType = in.readInt(); 403 330 404 331 switch (dataType) { 405 332 case 2: 333 case 4: 406 334 skip += 2; 407 335 break; 408 336 case 3: 409 skip += 4;410 break;411 case 4:412 skip += 2;413 break;414 337 case 5: 415 skip += 4;416 break;417 338 case 6: 418 339 skip += 4; … … 422 343 break; 423 344 case 8: 424 skip += 1;425 break;426 345 case 9: 427 346 skip += 1; … … 434 353 // this is an array of structs 435 354 int skip = 0; 436 in.read(temp); 437 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 355 dataType = in.readInt(); 438 356 if (dataType == 15) { // should always be true 439 in.read(temp); 440 skip += DataTools.bytesToInt(temp, !core.littleEndian[0]); 441 in.read(temp); 442 int numFields = DataTools.bytesToInt(temp, !core.littleEndian[0]); 357 skip += in.readInt(); 358 int numFields = in.readInt(); 443 359 for (int j=0; j<numFields; j++) { 444 in.read(temp); 445 skip += DataTools.bytesToInt(temp, !core.littleEndian[0]); 446 in.read(temp); 447 dataType = DataTools.bytesToInt(temp, !core.littleEndian[0]); 360 skip += in.readInt(); 361 dataType = in.readInt(); 448 362 449 363 switch (dataType) { 450 364 case 2: 365 case 4: 451 366 skip += 2; 452 367 break; 453 368 case 3: 454 skip += 4;455 break;456 case 4:457 skip += 2;458 break;459 369 case 5: 460 skip += 4;461 break;462 370 case 6: 463 371 skip += 4; … … 467 375 break; 468 376 case 8: 469 skip += 1;470 break;471 377 case 9: 472 378 skip += 1; … … 475 381 } 476 382 } 477 in.read(temp); 478 skip *= DataTools.bytesToInt(temp, !core.littleEndian[0]); 383 skip *= in.readInt(); 479 384 in.skipBytes(skip); 480 385 } … … 483 388 else if (type == 20) { 484 389 in.skipBytes(2); 485 in.read(temp); 486 parseTags(DataTools.bytesToInt(temp, !core.littleEndian[0]), 487 labelString); 390 parseTags(in.readInt(), labelString); 488 391 } 489 392 } -
trunk/loci/formats/in/ICSReader.java
r2800 r2922 159 159 if (bytes == 4) { 160 160 float[] f = new float[core.sizeX[0] * core.sizeY[0] * channels]; 161 int pt = 0;162 161 for (int i=0; i<f.length; i++) { 163 162 int p = DataTools.bytesToInt(plane, i*4, 4, core.littleEndian[0]); … … 256 255 StringTokenizer t; 257 256 String token; 258 b = new byte[(int) reader.length()]; 259 reader.read(b); 257 String s = reader.readString((int) reader.length()); 260 258 reader.close(); 261 String s = new String(b);262 259 StringTokenizer st = new StringTokenizer(s, "\n"); 263 260 String line = st.nextToken(); -
trunk/loci/formats/in/IPLabReader.java
r2701 r2922 68 68 /* @see loci.formats.IFormatReader#openBytes(int) */ 69 69 public byte[] openBytes(int no) throws FormatException, IOException { 70 FormatTools.assertId(currentId, true, 1);71 70 byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bps * core.sizeC[0]]; 72 71 return openBytes(no, buf); … … 94 93 /* @see loci.formats.IFormatReader#openImage(int) */ 95 94 public BufferedImage openImage(int no) throws FormatException, IOException { 96 FormatTools.assertId(currentId, true, 1);97 95 return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 98 96 core.rgb[0] ? core.sizeC[0] : 1, false, bps, core.littleEndian[0]); … … 109 107 status("Populating metadata"); 110 108 111 byte[] fourBytes = new byte[4]; 112 in.read(fourBytes); 113 core.littleEndian[0] = new String(fourBytes).equals("iiii"); 109 core.littleEndian[0] = in.readString(4).equals("iiii"); 114 110 115 111 in.order(core.littleEndian[0]); … … 144 140 case 1: 145 141 ptype = "16 bit signed short"; 146 core.pixelType[0] = FormatTools. INT16;142 core.pixelType[0] = FormatTools.UINT16; 147 143 bps = 2; 148 144 break; … … 154 150 case 3: 155 151 ptype = "32 bit signed long"; 156 core.pixelType[0] = FormatTools. INT32;152 core.pixelType[0] = FormatTools.UINT32; 157 153 bps = 4; 158 154 break; … … 164 160 case 5: 165 161 ptype = "Color24"; 166 core.pixelType[0] = FormatTools. INT32;162 core.pixelType[0] = FormatTools.UINT32; 167 163 bps = 1; 168 164 break; 169 165 case 6: 170 166 ptype = "Color48"; 171 core.pixelType[0] = FormatTools. INT32;167 core.pixelType[0] = FormatTools.UINT32; 172 168 bps = 2; 173 169 break; … … 212 208 status("Reading tags"); 213 209 214 in.read(fourBytes); 215 String tag = new String(fourBytes); 210 String tag = in.readString(4); 216 211 while (!tag.equals("fini") && in.getFilePointer() < in.length() - 4) { 217 212 if (tag.equals("clut")) { … … 220 215 if (size == 8) { 221 216 // indexed lookup table 222 in. readInt();217 in.skipBytes(4); 223 218 int type = in.readInt(); 224 219 225 String clutType = "unknown"; 226 switch ((int) type) { 227 case 0: 228 clutType = "monochrome"; 229 break; 230 case 1: 231 clutType = "reverse monochrome"; 232 break; 233 case 2: 234 clutType = "BGR"; 235 break; 236 case 3: 237 clutType = "classify"; 238 break; 239 case 4: 240 clutType = "rainbow"; 241 break; 242 case 5: 243 clutType = "red"; 244 break; 245 case 6: 246 clutType = "green"; 247 break; 248 case 7: 249 clutType = "blue"; 250 break; 251 case 8: 252 clutType = "cyan"; 253 break; 254 case 9: 255 clutType = "magenta"; 256 break; 257 case 10: 258 clutType = "yellow"; 259 break; 260 case 11: 261 clutType = "saturated pixels"; 262 break; 263 } 220 String[] types = new String[] { 221 "monochrome", "reverse monochrome", "BGR", "classify", "rainbow", 222 "red", "green", "blue", "cyan", "magenta", "yellow", 223 "saturated pixels" 224 }; 225 String clutType = (type >= 0 && type < types.length) ? types[type] : 226 "unknown"; 264 227 addMeta("LUT type", clutType); 265 228 } … … 267 230 // explicitly defined lookup table 268 231 // length is 772 269 in.readInt(); 270 byte[] colorTable = new byte[256*3]; 271 in.read(colorTable); 232 in.skipBytes(4 + 256 * 3); 272 233 } 273 234 } … … 283 244 284 245 for (int i=0; i<core.sizeC[0]; i++) { 285 long source = in.readInt(); 286 287 String sourceType; 288 switch ((int) source) { 289 case 0: 290 sourceType = "user"; 291 break; 292 case 1: 293 sourceType = "plane"; 294 break; 295 case 2: 296 sourceType = "sequence"; 297 break; 298 case 3: 299 sourceType = "saturated plane"; 300 break; 301 case 4: 302 sourceType = "saturated sequence"; 303 break; 304 case 5: 305 sourceType = "ROI"; 306 break; 307 default: 308 sourceType = "user"; 309 } 246 int source = in.readInt(); 247 String[] types = new String[] { 248 "user", "plane", "sequence", "saturated plane", 249 "saturated sequence", "ROI" 250 }; 251 252 String sourceType = (source >= 0 && source < types.length) ? 253 types[source] : "user"; 310 254 addMeta("NormalizationSource" + i, sourceType); 311 255 … … 335 279 int size = in.readInt(); 336 280 337 byte[] headerString = new byte[20]; 338 for (int i=0; i<size / (headerString.length + 2); i++) { 281 for (int i=0; i<size / 22; i++) { 339 282 int num = in.readShort(); 340 in.read(headerString); 341 String name = new String(fourBytes); 283 String name = in.readString(20); 342 284 addMeta("Header" + num, name); 343 285 } … … 356 298 int numRoiPts = in.readInt(); 357 299 358 Integer x0 = new Integer( (int)roiLeft);359 Integer x1 = new Integer( (int)roiRight);360 Integer y0 = new Integer( (int)roiBottom);361 Integer y1 = new Integer( (int)roiTop);300 Integer x0 = new Integer(roiLeft); 301 Integer x1 = new Integer(roiRight); 302 Integer y0 = new Integer(roiBottom); 303 Integer y1 = new Integer(roiTop); 362 304 store.setDisplayROI( 363 305 x0, y0, null, x1, y1, null, null, null, null, null); … … 367 309 else if (tag.equals("mask")) { 368 310 // read in Segmentation Mask 369 int size = in.readInt(); 370 in.skipBytes(size); 311 in.skipBytes(in.readInt()); 371 312 } 372 313 else if (tag.equals("unit")) { 373 314 // read in units 374 in. readInt(); // size is 48315 in.skipBytes(4); 375 316 376 317 for (int i=0; i<4; i++) { … … 402 343 // read in notes (image info) 403 344 in.readInt(); // size is 576 404 byte[] temp = new byte[64]; 405 in.read(temp); 406 String descriptor = new String(temp); 407 temp = new byte[512]; 408 in.read(temp); 409 String notes = new String(temp); 345 String descriptor = in.readString(64); 346 String notes = in.readString(512); 410 347 addMeta("Descriptor", descriptor); 411 348 addMeta("Notes", notes); … … 415 352 416 353 if (in.getFilePointer() + 4 <= in.length()) { 417 in.read(fourBytes); 418 tag = new String(fourBytes); 354 tag = in.readString(4); 419 355 } 420 356 else { -
trunk/loci/formats/in/IPWReader.java
r2857 r2922 144 144 /* @see loci.formats.IFormatReader#openImage(int) */ 145 145 public BufferedImage openImage(int no) throws FormatException, IOException { 146 FormatTools.assertId(currentId, true, 1);147 if (no < 0 || no >= getImageCount()) {148 throw new FormatException("Invalid image number: " + no);149 }150 151 146 byte[] b = openBytes(no); 152 147 int bytes = b.length / (core.sizeX[0] * core.sizeY[0]); … … 291 286 } 292 287 293 // TODO : look into removing this logic, as it appears to be copied directly294 // from BaseTiffReader295 296 288 int bitsPerSample = TiffTools.getIFDIntValue(ifds[0], 297 289 TiffTools.BITS_PER_SAMPLE); … … 374 366 if (debug) trace(t); 375 367 } 368 369 core.interleaved[0] = true; 376 370 } 377 371 … … 408 402 r.exec("dis.read(data)"); 409 403 404 RandomAccessStream ds = new RandomAccessStream(data); 405 ds.order(true); 406 410 407 String entryName = (String) r.getVar("entryName"); 411 408 String dirName = (String) r.getVar("dirName"); … … 420 417 // should always be exactly 4 bytes 421 418 // only exists if the file has more than one image 422 addMeta("Frame Rate", new Long( DataTools.bytesToInt(data, true)));419 addMeta("Frame Rate", new Long(ds.readInt())); 423 420 } 424 421 else if (entryName.equals("FrameInfo")) { 425 422 // should always be 16 bytes (if present) 426 423 for(int i=0; i<data.length/2; i++) { 427 addMeta("FrameInfo "+i, 428 new Short(DataTools.bytesToShort(data, i*2, true))); 424 addMeta("FrameInfo "+i, new Short(ds.readShort())); 429 425 } 430 426 } … … 449 445 core.imageCount[0]++; 450 446 } 447 ds.close(); 451 448 r.exec("dis.close()"); 452 449 if (debug) { 453 print(depth + 1, ((byte[]) 454 r.getVar("data")).length + " bytes read."); 450 print(depth + 1, data.length + " bytes read."); 455 451 } 456 452 } -
trunk/loci/formats/in/ImarisReader.java
r2802 r2922 93 93 /* @see loci.formats.IFormatReader#openImage(int) */ 94 94 public BufferedImage openImage(int no) throws FormatException, IOException { 95 FormatTools.assertId(currentId, true, 1);96 95 return ImageTools.makeImage(openBytes(no), core.sizeX[0], 97 96 core.sizeY[0], 1, false); … … 137 136 in.readInt(); 138 137 139 byte[] name = new byte[128]; 140 in.read(name); 141 String iName = new String(name); 142 addMeta("Image name", iName); 138 addMeta("Image name", in.readString(128)); 143 139 144 140 core.sizeX[0] = in.readShort(); … … 151 147 in.skipBytes(2); 152 148 153 byte[] date = new byte[32]; 154 in.read(date); 155 String origDate = new String(date); 156 addMeta("Original date", origDate); 149 addMeta("Original date", in.readString(32)); 157 150 158 151 float dx = in.readFloat(); … … 161 154 int mag = in.readShort(); 162 155 163 byte[] com = new byte[128]; 164 in.read(com); 165 String comment = new String(com); 166 addMeta("Image comment", comment); 156 addMeta("Image comment", in.readString(128)); 167 157 int isSurvey = in.readInt(); 168 158 addMeta("Survey performed", isSurvey == 0 ? "true" : "false"); -
trunk/loci/formats/in/ImarisTiffReader.java
r2687 r2922 145 145 int bitFormat = TiffTools.getIFDIntValue(ifds[0], TiffTools.SAMPLE_FORMAT); 146 146 147 // TODO : look into removing this logic, since it's copied directly from148 // BaseTiffReader149 150 147 while (bitsPerSample % 8 != 0) bitsPerSample++; 151 148 if (bitsPerSample == 24 || bitsPerSample == 48) bitsPerSample /= 3; -
trunk/loci/formats/in/KhorosReader.java
r2898 r2922 127 127 int dependency = in.readInt(); 128 128 129 byte[] comment = new byte[512]; 130 in.read(comment); 131 addMeta("Comment", new String(comment)); 129 addMeta("Comment", in.readString(512)); 132 130 133 131 in.order(dependency == 4 || dependency == 8); … … 144 142 switch (type) { 145 143 case 0: 146 core.pixelType[0] = FormatTools.UINT8;147 break;148 144 case 1: 149 145 core.pixelType[0] = FormatTools.UINT8; -
trunk/loci/formats/in/LIFReader.java
r2839 r2922 58 58 private int[] extraDimensions; 59 59 60 /** Number of valid bits per pixel */61 private int[][] validBits;62 63 60 private int bpp; 64 61 private Vector xcal; … … 66 63 private Vector zcal; 67 64 private Vector seriesNames; 68 69 private Vector channelMins;70 private Vector channelMaxs;71 65 72 66 // -- Constructor -- … … 119 113 /* @see loci.formats.IFormatReader#openImage(int) */ 120 114 public BufferedImage openImage(int no) throws FormatException, IOException { 121 FormatTools.assertId(currentId, true, 1);122 115 return ImageTools.makeImage(openBytes(no), core.sizeX[series], 123 core.sizeY[series], isRGB() ? core.sizeC[series] : 1, false, bpp / 8,124 core.littleEndian[series] , validBits[series]);116 core.sizeY[series], getRGBChannelCount(), false, bpp / 8, 117 core.littleEndian[series]); 125 118 } 126 119 … … 135 128 136 129 core.littleEndian[0] = true; 130 in.order(core.littleEndian[0]); 137 131 138 132 xcal = new Vector(); 139 133 ycal = new Vector(); 140 134 zcal = new Vector(); 141 channelMins = new Vector();142 channelMaxs = new Vector();143 135 144 136 // read the header … … 163 155 // number of Unicode characters in the XML block 164 156 165 int nc = DataTools.read4SignedBytes(in, core.littleEndian[0]); 166 byte[] s = new byte[nc * 2]; 167 in.read(s); 168 String xml = DataTools.stripString(new String(s)); 157 int nc = in.readInt(); 158 String xml = DataTools.stripString(in.readString(nc * 2)); 169 159 170 160 status("Finding image offsets"); 171 161 172 162 while (in.getFilePointer() < in.length()) { 173 if ( DataTools.read4SignedBytes(in, core.littleEndian[0]) != 0x70) {163 if (in.readInt() != 0x70) { 174 164 throw new FormatException("Invalid Memory Block"); 175 165 } … … 180 170 } 181 171 182 int blockLength = DataTools.read4SignedBytes(in, core.littleEndian[0]);172 int blockLength = in.readInt(); 183 173 if (in.read() != 0x2a) { 184 174 throw new FormatException("Invalid Memory Description"); 185 175 } 186 176 187 int descrLength = DataTools.read4SignedBytes(in, core.littleEndian[0]); 188 byte[] memDescr = new byte[2*descrLength]; 189 in.read(memDescr); 177 int descrLength = in.readInt(); 178 in.skipBytes(descrLength * 2); 190 179 191 180 if (blockLength > 0) { … … 359 348 if (numChannels == 1) { 360 349 bps.add(new Integer((String) tmp.get("Resolution"))); 361 String sMin = (String) tmp.get("Min");362 String sMax = (String) tmp.get("Max");363 if (sMin != null && sMax != null) {364 double min = Double.parseDouble(sMin);365 double max = Double.parseDouble(sMax);366 channelMins.add(new Integer((int) min));367 channelMaxs.add(new Integer((int) max));368 }369 350 } 370 351 } … … 433 414 core = new CoreMetadata(numDatasets); 434 415 Arrays.fill(core.orderCertain, true); 435 validBits = new int[numDatasets][];436 416 437 417 for (int i=0; i<numDatasets; i++) { … … 458 438 core.imageCount[i] = core.sizeZ[i] * core.sizeT[i]; 459 439 if (!core.rgb[i]) core.imageCount[i] *= core.sizeC[i]; 460 461 validBits[i] = new int[core.sizeC[i] != 2 ? core.sizeC[i] : 3];462 for (int j=0; j<validBits[i].length; j++) {463 validBits[i][j] = bitsPerPixel[i];464 }465 440 466 441 while (bitsPerPixel[i] % 8 != 0) bitsPerPixel[i]++; -
trunk/loci/formats/in/LegacyPictReader.java
r2701 r2922 54 54 /* @see loci.formats.IFormatReader#openBytes(int) */ 55 55 public byte[] openBytes(int no) throws FormatException, IOException { 56 FormatTools.assertId(currentId, true, 1);57 56 return ImageTools.getBytes(openImage(no), false, 3); 58 57 } -
trunk/loci/formats/in/LegacyZVIReader.java
r2857 r2922 135 135 super.initFile(id); 136 136 in = new RandomAccessStream(id); 137 in.order(true); 137 138 138 139 // Highly questionable decoding strategy: … … 226 227 227 228 // read potential header information 228 int theZ = (int) DataTools.read4UnsignedBytes(in, true);229 int theC = (int) DataTools.read4UnsignedBytes(in, true);230 int theT = (int) DataTools.read4UnsignedBytes(in, true);229 int theZ = in.readInt(); 230 int theC = in.readInt(); 231 int theT = in.readInt(); 231 232 pos += 12; 232 233 … … 287 288 288 289 // read more header information 289 core.sizeX[0] = (int) DataTools.read4UnsignedBytes(in, true);290 core.sizeY[0] = (int) DataTools.read4UnsignedBytes(in, true);290 core.sizeX[0] = in.readInt(); 291 core.sizeY[0] = in.readInt(); 291 292 // don't know what this is for 292 int alwaysOne = (int) DataTools.read4UnsignedBytes(in, true);293 bytesPerPixel = (int) DataTools.read4UnsignedBytes(in, true);293 int alwaysOne = in.readInt(); 294 bytesPerPixel = in.readInt(); 294 295 // not clear what this value signifies 295 int pixType = (int) DataTools.read4UnsignedBytes(in, true);296 int pixType = in.readInt(); 296 297 // doesn't always equal bytesPerPixel * 8 297 int bitDepth = (int) DataTools.read4UnsignedBytes(in, true);298 int bitDepth = in.readInt(); 298 299 pos += 24; 299 300 … … 302 303 case 1: 303 304 type = "8 bit rgb tuple, 24 bpp"; 304 core.pixelType[0] = FormatTools. INT8;305 core.pixelType[0] = FormatTools.UINT8; 305 306 break; 306 307 case 2: 307 308 type = "8 bit rgb quad, 32 bpp"; 308 core.pixelType[0] = FormatTools. INT8;309 core.pixelType[0] = FormatTools.UINT8; 309 310 break; 310 311 case 3: 311 312 type = "8 bit grayscale"; 312 core.pixelType[0] = FormatTools. INT8;313 core.pixelType[0] = FormatTools.UINT8; 313 314 break; 314 315 case 4: 315 316 type = "16 bit signed int, 16 bpp"; 316 core.pixelType[0] = FormatTools. INT16;317 core.pixelType[0] = FormatTools.UINT16; 317 318 break; 318 319 case 5: 319 320 type = "32 bit int, 32 bpp"; 320 core.pixelType[0] = FormatTools. INT32;321 core.pixelType[0] = FormatTools.UINT32; 321 322 break; 322 323 case 6: … … 330 331 case 8: 331 332 type = "16 bit unsigned short triple, 48 bpp"; 332 core.pixelType[0] = FormatTools. INT16;333 core.pixelType[0] = FormatTools.UINT16; 333 334 break; 334 335 case 9: 335 336 type = "32 bit int triple, 96 bpp"; 336 core.pixelType[0] = FormatTools. INT32;337 core.pixelType[0] = FormatTools.UINT32; 337 338 break; 338 339 default: … … 357 358 // sorry not a very clever way to find dimension order 358 359 359 if ((numI == 2) && (cSet.size() == 2)) 360 if ((numI == 2) && (zSet.size() == 2)) 361 if ((numI == 2) && (tSet.size() == 2)) 360 if ((numI == 2) && (cSet.size() == 2)) cFlag = 1; 361 if ((numI == 2) && (zSet.size() == 2)) zFlag = 1; 362 if ((numI == 2) && (tSet.size() == 2)) tFlag = 1; 362 363 363 364 if ((numI % 3 == 0) && (zSet.size() > 1) && (cFlag == 1)) { -
trunk/loci/formats/in/MNGReader.java
r2701 r2922 48 48 49 49 /** Constructs a new MNG reader. */ 50 public MNGReader() { super("Multiple Network Graphics (MNG)", "mng"); }50 public MNGReader() { super("Multiple Network Graphics", "mng"); } 51 51 52 52 // -- IFormatReader API methods -- … … 62 62 /* @see loci.formats.IFormatReader#openBytes(int) */ 63 63 public byte[] openBytes(int no) throws FormatException, IOException { 64 FormatTools.assertId(currentId, true, 1);65 64 return ImageTools.getBytes(openImage(no), true, core.sizeC[0]); 66 65 } … … 97 96 super.initFile(id); 98 97 in = new RandomAccessStream(id); 98 in.order(false); 99 99 100 100 status("Verifying MNG format"); … … 114 114 status("Reading dimensions"); 115 115 116 core.sizeX[0] = (int) DataTools.read4UnsignedBytes(in, false);117 core.sizeY[0] = (int) DataTools.read4UnsignedBytes(in, false);118 long fps = DataTools.read4UnsignedBytes(in, false);119 long layerCounter = DataTools.read4UnsignedBytes(in, false);116 core.sizeX[0] = in.readInt(); 117 core.sizeY[0] = in.readInt(); 118 int fps = in.readInt(); 119 int layerCounter = in.readInt(); 120 120 in.skipBytes(4); 121 121 122 long playTime = DataTools.read4UnsignedBytes(in, false);123 long profile = DataTools.read4UnsignedBytes(in, false);122 int playTime = in.readInt(); 123 int profile = in.readInt(); 124 124 125 125 in.skipBytes(4); // skip the CRC … … 132 132 133 133 while (in.getFilePointer() < in.length()) { 134 long len = DataTools.read4UnsignedBytes(in, false);134 int len = in.readInt(); 135 135 in.read(b); 136 136 String code = new String(b); … … 148 148 stack.add(new Long(in.getFilePointer() + len + 4)); 149 149 in.skipBytes(1); 150 maxIterations = DataTools.read4SignedBytes(in, false);150 maxIterations = in.readInt(); 151 151 } 152 152 else if (code.equals("ENDL")) { … … 163 163 } 164 164 165 in.seek(fp + (int)len + 4);165 in.seek(fp + len + 4); 166 166 } 167 167 -
trunk/loci/formats/in/MRCReader.java
r2701 r2922 63 63 /* @see loci.formats.IFormatReader#openBytes(int) */ 64 64 public byte[] openBytes(int no) throws FormatException, IOException { 65 FormatTools.assertId(currentId, true, 1);66 65 byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bpp]; 67 66 return openBytes(no, buf); … … 86 85 /* @see loci.formats.IFormatReader#openImage(int) */ 87 86 public BufferedImage openImage(int no) throws FormatException, IOException { 88 FormatTools.assertId(currentId, true, 1);89 87 return ImageTools.makeImage(openBytes(no), core.sizeX[0], 90 88 core.sizeY[0], 1, true, bpp, core.littleEndian[0]); … … 124 122 break; 125 123 case 1: 124 case 6: 126 125 bpp = 2; 127 126 core.pixelType[0] = FormatTools.UINT16; … … 141 140 core.pixelType[0] = FormatTools.DOUBLE; 142 141 break; 143 case 6:144 bpp = 2;145 core.pixelType[0] = FormatTools.UINT16;146 break;147 142 case 16: 148 143 bpp = 2; … … 170 165 addMeta("Pixel size (Z)", "" + (zlen / mz)); 171 166 172 float alpha = in.readFloat(); 173 float beta = in.readFloat(); 174 float gamma = in.readFloat(); 175 176 addMeta("Alpha angle", "" + alpha); 177 addMeta("Beta angle", "" + beta); 178 addMeta("Gamma angle", "" + gamma); 167 addMeta("Alpha angle", "" + in.readFloat()); 168 addMeta("Beta angle", "" + in.readFloat()); 169 addMeta("Gamma angle", "" + in.readFloat()); 179 170 180 171 in.skipBytes(12); … … 182 173 // min, max and mean pixel values 183 174 184 float min = in.readFloat(); 185 float max = in.readFloat(); 186 float mean = in.readFloat(); 187 188 addMeta("Minimum pixel value", "" + min); 189 addMeta("Maximum pixel value", "" + max); 190 addMeta("Mean pixel value", "" + mean); 175 addMeta("Minimum pixel value", "" + in.readFloat()); 176 addMeta("Maximum pixel value", "" + in.readFloat()); 177 addMeta("Mean pixel value", "" + in.readFloat()); 191 178 192 179 in.skipBytes(4); 193 180 194 181 extHeaderSize = in.readInt(); 195 int creator = in.readShort(); 196 197 in.skipBytes(30); 198 199 int nint = in.readShort(); 200 int nreal = in.readShort(); 201 202 in.skipBytes(28); 182 183 in.skipBytes(64); 203 184 204 185 int idtype = in.readShort(); 205 int lens = in.readShort(); 206 int nd1 = in.readShort(); 207 int nd2 = in.readShort(); 208 int vd1 = in.readShort(); 209 int vd2 = in.readShort(); 210 211 String type = ""; 212 switch (idtype) { 213 case 0: 214 type = "mono"; 215 break; 216 case 1: 217 type = "tilt"; 218 break; 219 case 2: 220 type = "tilts"; 221 break; 222 case 3: 223 type = "lina"; 224 break; 225 case 4: 226 type = "lins"; 227 break; 228 default: 229 type = "unknown"; 230 } 186 187 String[] types = new String[] {"mono", "tilt", "tilts", "lina", "lins"}; 188 String type = (idtype >= 0 && idtype < types.length) ? types[idtype] : 189 "unknown"; 231 190 232 191 addMeta("Series type", type); 233 addMeta("Lens", "" + lens);234 addMeta("ND1", "" + nd1);235 addMeta("ND2", "" + nd2);236 addMeta("VD1", "" + vd1);237 addMeta("VD2", "" + vd2);192 addMeta("Lens", "" + in.readShort()); 193 addMeta("ND1", "" + in.readShort()); 194 addMeta("ND2", "" + in.readShort()); 195 addMeta("VD1", "" + in.readShort()); 196 addMeta("VD2", "" + in.readShort()); 238 197 239 198 float[] angles = new float[6]; … … 248 207 addMeta("Number of useful labels", "" + nUsefulLabels); 249 208 250 byte[] b = new byte[80];251 209 for (int i=0; i<10; i++) { 252 in.read(b); 253 addMeta("Label " + (i+1), new String(b)); 210 addMeta("Label " + (i+1), in.readString(80)); 254 211 } 255 212 -
trunk/loci/formats/in/ND2Reader.java
r2879 r2922 122 122 /** Array of image offsets. */ 123 123 private long[] offsets; 124 125 /** Number of valid bits per pixel */126 private int[] validBits;127 124 128 125 /** Whether or not the pixel data is compressed using JPEG 2000. */ … … 176 173 pixels[i].length); 177 174 } 175 pixels = null; 178 176 } 179 177 else { … … 328 326 pos = in.getFilePointer(); 329 327 length = in.readInt(); 330 if (pos + length >= in.length() ) lastBoxFound = true;328 if (pos + length >= in.length() || length == 0) lastBoxFound = true; 331 329 box = in.readInt(); 332 330 pos = in.getFilePointer(); … … 343 341 offsets[i] = ((Long) vs.get(i)).longValue(); 344 342 } 343 vs.clear(); 344 vs = null; 345 345 346 346 status("Finding XML metadata"); … … 377 377 } 378 378 } 379 380 buf = null; 379 381 380 382 status("Parsing XML"); … … 476 478 } 477 479 } 480 b = null; 481 xml = null; 482 st = null; 478 483 } 479 484 … … 483 488 core.sizeX[0] = img.getWidth(); 484 489 core.sizeY[0] = img.getHeight(); 490 core.sizeC[0] = img.getRaster().getNumBands(); 491 core.rgb[0] = core.sizeC[0] > 1; 485 492 486 493 int numInvalid = 0; … … 527 534 } 528 535 529 if (core.sizeC[0] == 0) {530 core.sizeC[0] = openImage(0).getRaster().getNumBands();531 }532 536 if (core.sizeC[0] == 2) core.sizeC[0] = 1; 533 537 … … 543 547 // we calculate this directly (instead of calling getEffectiveSizeC) because 544 548 // sizeZ and sizeT have not been accurately set yet 545 int effectiveC = ( core.sizeC[0]/ 3) + 1;549 int effectiveC = ((core.sizeC[0] - 1) / 3) + 1; 546 550 547 551 if (core.imageCount[0] < core.sizeZ[0] * core.sizeT[0]) { … … 593 597 } 594 598 595 if (bits != 0) { 596 validBits = new int[core.sizeC[0] == 2 ? 3 : core.sizeC[0]]; 597 for (int i=0; i<validBits.length; i++) validBits[i] = bits; 598 } 599 else validBits = null; 600 601 if (validBits == null) core.pixelType[0] = FormatTools.UINT8; 599 if (bits == 0) core.pixelType[0] = FormatTools.UINT8; 602 600 else { 603 int bpp = validBits[0];601 int bpp = bits; 604 602 while (bpp % 8 != 0) bpp++; 605 603 switch (bpp) { … … 628 626 629 627 if (core.sizeZ[0] * core.sizeT[0] * core.sizeC[0] < core.imageCount[0]) { 630 core.sizeC[0] = 1;631 628 core.sizeT[0] = 1; 632 629 core.sizeZ[0] = core.imageCount[0]; -
trunk/loci/formats/in/NRRDReader.java
r2762 r2922 60 60 public boolean isThisType(byte[] block) { 61 61 if (block.length < 4) return false; 62 return block[0] == 'N' && block[1] == 'R' && block[2] == 'R' && 63 block[3] == 'D'; 62 return new String(block).startsWith("NRRD"); 64 63 } 65 64 -
trunk/loci/formats/in/OIBReader.java
r2857 r2922 112 112 private Vector[] tIndices; 113 113 114 /** Number of valid bits per pixel. */115 private int[][] validBits;116 117 114 private Vector rgb; 118 115 … … 148 145 149 146 return ImageTools.makeImage(b, core.sizeX[series], core.sizeY[series], 150 getRGBChannelCount(), false, bytes, core.littleEndian[series], 151 validBits[series]); 147 getRGBChannelCount(), false, bytes, core.littleEndian[series]); 152 148 } 153 149 … … 318 314 core = new CoreMetadata(numSeries); 319 315 320 validBits = new int[numSeries][];321 322 316 for (int i=0; i<numSeries; i++) { 323 317 core.sizeX[i] = ((Integer) width.get(i)).intValue(); … … 393 387 nImages.setElementAt(new Integer(core.imageCount[i]), i); 394 388 setSeries(oldSeries); 395 396 validBits[i] = new int[core.sizeC[i] == 2 ? 3 : core.sizeC[i]];397 int vb = 0;398 Enumeration k = metadata.keys();399 while (k.hasMoreElements()) {400 String key = k.nextElement().toString();401 if (key.indexOf("ValidBitCounts") != -1) {402 vb = Integer.parseInt((String) getMeta(key));403 }404 }405 if (vb > 0) {406 for (int j=0; j<validBits[i].length; j++) validBits[i][j] = vb;407 }408 else validBits[i] = null;409 389 410 390 core.rgb[i] = ((Boolean) rgb.get(i)).booleanValue(); … … 457 437 for (int i=0; i<width.size(); i++) { 458 438 switch (((Integer) bpp.get(0)).intValue() % 3) { 459 case 0:460 case 1:461 core.pixelType[i] = FormatTools.UINT8;462 break;463 439 case 2: 464 440 core.pixelType[i] = FormatTools.UINT16; 465 441 break; 466 case 4: 467 core.pixelType[i] = FormatTools.UINT32; 468 break; 469 default: 470 throw new RuntimeException( 471 "Unknown matching for pixel byte width of: " + bpp); 442 default: core.pixelType[i] = FormatTools.UINT8; 472 443 } 473 444 -
trunk/loci/formats/in/OIFReader.java
r2859 r2922 48 48 /** Helper reader to open the thumbnail. */ 49 49 protected BMPReader thumbReader; 50 51 /** Number of valid bits per pixel. */52 protected int[] validBits;53 50 54 51 /** List of files in the current OIF dataset. */ … … 109 106 BufferedImage b = tiffReader[no].openImage(0); 110 107 ColorModel cm = ImageTools.makeColorModel(b.getRaster().getNumBands(), 111 b.getRaster().getTransferType(), validBits);108 b.getRaster().getTransferType(), null); 112 109 b = ImageTools.makeBuffered(b, cm); 113 110 tiffReader[no].close(); … … 334 331 335 332 for (int i=0; i<9; i++) { 336 if (code[i].equals("\"X\"")) core.sizeX[0] = Integer.parseInt(size[i]); 337 else if (code[i].equals("\"Y\"")) { 338 core.sizeY[0] = Integer.parseInt(size[i]); 339 } 340 else if (code[i].equals("\"C\"")) { 341 core.sizeC[0] = Integer.parseInt(size[i]); 342 } 343 else if (code[i].equals("\"T\"")) { 344 core.sizeT[0] = Integer.parseInt(size[i]); 345 } 346 else if (code[i].equals("\"Z\"")) { 347 core.sizeZ[0] = Integer.parseInt(size[i]); 348 } 333 int ss = Integer.parseInt(size[i]); 334 if (code[i].equals("\"X\"")) core.sizeX[0] = ss; 335 else if (code[i].equals("\"Y\"")) core.sizeY[0] = ss; 336 else if (code[i].equals("\"C\"")) core.sizeC[0] = ss; 337 else if (code[i].equals("\"T\"")) core.sizeT[0] = ss; 338 else if (code[i].equals("\"Z\"")) core.sizeZ[0] = ss; 349 339 } 350 340 … … 396 386 } 397 387 398 validBits = new int[core.sizeC[0]];399 if (validBits.length == 2) validBits = new int[3];400 for (int i=0; i<validBits.length; i++) {401 s = (String) getMeta("[Reference Image Parameter] - ValidBitCounts");402 if (s != null) {403 validBits[i] = Integer.parseInt(s);404 }405 else {406 i = validBits.length;407 }408 }409 410 int len = validBits.length;411 for (int i=0; i<len; i++) {412 if (validBits[i] == 0) {413 validBits = null;414 break;415 }416 }417 418 388 core.rgb[0] = tiffReader[0].isRGB(); 419 389 core.littleEndian[0] = true; -
trunk/loci/formats/in/OMEXMLReader.java
r2857 r2922 114 114 data = null; 115 115 116 //byte[] pixels = Compression.base64Decode(pix);117 116 Base64Codec e = new Base64Codec(); 118 117 byte[] pixels = e.base64Decode(pix); … … 198 197 if (ndx != -1) { 199 198 found = true; 200 String endian = test.substring(ndx + 11); 199 String endian = test.substring(ndx + 11).trim(); 200 if (endian.startsWith("\"")) endian = endian.substring(1); 201 201 endianness.add(new Boolean(!endian.toLowerCase().startsWith("t"))); 202 202 bigEndianPos.add(new Long(in.getFilePointer() - read - 9 + ndx)); -
trunk/loci/formats/in/OpenlabRawReader.java
r2701 r2922 95 95 /* @see loci.formats.IFormatReader#openImage(int) */ 96 96 public BufferedImage openImage(int no) throws FormatException, IOException { 97 FormatTools.assertId(currentId, true, 1);98 97 return ImageTools.makeImage(openBytes(no), core.sizeX[0], 99 98 core.sizeY[0], core.sizeC[0], false, bytesPerPixel, false); … … 150 149 addMeta("Bytes per pixel", new Integer(bytesPerPixel)); 151 150 151 int plane = core.sizeX[0] * core.sizeY[0] * bytesPerPixel; 152 152 for (int i=1; i<core.imageCount[0]; i++) { 153 offsets[i] = 154 offsets[i-1] + 288 + core.sizeX[0] * core.sizeY[0] * bytesPerPixel; 153 offsets[i] = offsets[i - 1] + 288 + plane; 155 154 } 156 155 … … 167 166 switch (bytesPerPixel) { 168 167 case 1: 168 case 3: 169 169 core.pixelType[0] = FormatTools.UINT8; 170 170 break; 171 171 case 2: 172 172 core.pixelType[0] = FormatTools.UINT16; 173 break;174 case 3:175 core.pixelType[0] = FormatTools.INT8;176 173 break; 177 174 default: -
trunk/loci/formats/in/OpenlabReader.java
r2857 r2922 103 103 104 104 in.skipBytes(24); 105 int volumeType = DataTools.read2SignedBytes(in, false);105 int volumeType = in.readShort(); 106 106 in.skipBytes(272); 107 107 … … 110 110 if (version == 2) { 111 111 in.skipBytes(2); 112 top = DataTools.read2SignedBytes(in, false);113 left = DataTools.read2SignedBytes(in, false);114 bottom = DataTools.read2SignedBytes(in, false);115 right = DataTools.read2SignedBytes(in, false);112 top = in.readShort(); 113 left = in.readShort(); 114 bottom = in.readShort(); 115 right = in.readShort(); 116 116 117 117 if (core.sizeX[series] == 0) core.sizeX[series] = right - left; … … 119 119 } 120 120 else { 121 core.sizeX[series] = DataTools.read4SignedBytes(in, false);122 core.sizeY[series] = DataTools.read4SignedBytes(in, false);121 core.sizeX[series] = in.readInt(); 122 core.sizeY[series] = in.readInt(); 123 123 } 124 124 … … 226 226 227 227 in.skipBytes(24); 228 volumeType = DataTools.read2SignedBytes(in, false);228 volumeType = in.readShort(); 229 229 230 230 in.skipBytes(280); 231 int size = DataTools.read4SignedBytes(in, false);232 int compressedSize = DataTools.read4SignedBytes(in, false);231 int size = in.readInt(); 232 int compressedSize = in.readInt(); 233 233 b = new byte[size]; 234 234 byte[] c = new byte[compressedSize]; … … 352 352 status("Verifying Openlab LIFF format"); 353 353 354 in.order(false); 354 355 in.skipBytes(4); 355 byte[] b = new byte[4]; 356 in.read(b); 357 String s = new String(b); 358 if (!s.equals("impr")) throw new FormatException("Invalid LIFF file."); 359 360 version = DataTools.read4SignedBytes(in, false); 356 if (!in.readString(4).equals("impr")) { 357 throw new FormatException("Invalid LIFF file."); 358 } 359 360 version = in.readInt(); 361 361 362 362 if (version != 2 && version != 5) { … … 368 368 369 369 // read offset to first plane 370 int offset = DataTools.read4SignedBytes(in, false);370 int offset = in.readInt(); 371 371 in.seek(offset); 372 372 … … 404 404 405 405 in.skipBytes(24); 406 int volumeType = DataTools.read2SignedBytes(in, false);406 int volumeType = in.readShort(); 407 407 408 408 if (volumeType == MAC_1_BIT || volumeType == MAC_256_GREYS || … … 411 411 { 412 412 in.skipBytes(16); 413 b = new byte[128]; 414 in.read(b); 415 info.layerName = new String(b); 413 info.layerName = in.readString(128); 416 414 417 415 if (!info.layerName.trim().equals("Original Image")) { 418 info.timestamp = DataTools.read8SignedBytes(in, false);416 info.timestamp = in.readLong(); 419 417 layerInfoList[0].add(info); 420 418 } … … 424 422 else if (tag == 69) { 425 423 in.skipBytes(4); 426 int units = DataTools.read2SignedBytes(in, false);424 int units = in.readShort(); 427 425 in.skipBytes(12); 428 426 429 xCal = Float.intBitsToFloat(DataTools.read4SignedBytes(in, false));430 yCal = Float.intBitsToFloat(DataTools.read4SignedBytes(in, false));427 xCal = in.readFloat(); 428 yCal = in.readFloat(); 431 429 } 432 430 else if (tag == 72 || fmt.equals("USER")) { … … 444 442 445 443 if (aChar == 1) { 446 int numVars = DataTools.read2SignedBytes(in, false);444 int numVars = in.readShort(); 447 445 while (numVars > 0) { 448 446 aChar = (char) in.read(); … … 466 464 467 465 if (className.equals("CStringVariable")) { 468 int strSize = DataTools.read4SignedBytes(in, false); 469 b = new byte[strSize]; 470 in.read(b); 471 varStringValue = new String(b); 466 int strSize = in.readInt(); 467 varStringValue = in.readString(strSize); 472 468 varNumValue = Float.parseFloat(varStringValue); 473 469 … … 475 471 } 476 472 else if (className.equals("CFloatVariable")) { 477 varNumValue = Double.longBitsToDouble( 478 DataTools.read8SignedBytes(in, false)); 473 varNumValue = in.readDouble(); 479 474 varStringValue = "" + varNumValue; 480 475 } … … 482 477 int baseClassVersion = in.read(); 483 478 if (baseClassVersion == 1 || baseClassVersion == 2) { 484 int strSize = DataTools.read4SignedBytes(in, false); 485 b = new byte[strSize]; 486 in.read(b); 487 varName = new String(b); 479 int strSize = in.readInt(); 480 varName = in.readString(strSize); 488 481 in.skipBytes(baseClassVersion == 1 ? 3 : 2); 489 482 } … … 532 525 if (fmt.equals("PICT")) { 533 526 in.skipBytes(24); 534 int volumeType = DataTools.read2SignedBytes(in, false);527 int volumeType = in.readShort(); 535 528 in.skipBytes(272); 536 529 … … 539 532 if (version == 2) { 540 533 in.skipBytes(2); 541 top = DataTools.read2SignedBytes(in, false);542 left = DataTools.read2SignedBytes(in, false);543 bottom = DataTools.read2SignedBytes(in, false);544 right = DataTools.read2SignedBytes(in, false);534 top = in.readShort(); 535 left = in.readShort(); 536 bottom = in.readShort(); 537 right = in.readShort(); 545 538 546 539 if (core.sizeX[series] == 0) core.sizeX[series] = right - left; … … 548 541 } 549 542 else { 550 core.sizeX[series] = DataTools.read4SignedBytes(in, false);551 core.sizeY[series] = DataTools.read4SignedBytes(in, false);543 core.sizeX[series] = in.readInt(); 544 core.sizeY[series] = in.readInt(); 552 545 } 553 546 554 547 in.seek(layer.layerStart); 555 556 b = new byte[0];557 548 558 549 if (version == 2) { … … 566 557 // open image using pict reader 567 558 try { 568 b = new byte[(int) (nextTag - in.getFilePointer())];559 byte[] b = new byte[(int) (nextTag - in.getFilePointer())]; 569 560 in.read(b); 570 561 BufferedImage img = pict.open(b); … … 672 663 switch (bpp[i]) { 673 664 case 1: 674 core.pixelType[i] = FormatTools.INT8;675 break;676 case 2:677 core.pixelType[i] = FormatTools.UINT16;678 break;679 665 case 3: 680 666 core.pixelType[i] = FormatTools.UINT8; 681 667 break; 668 case 2: 669 case 6: 670 core.pixelType[i] = FormatTools.UINT16; 671 break; 682 672 case 4: 683 core.pixelType[i] = FormatTools.INT32; 684 break; 685 case 6: 686 core.pixelType[i] = FormatTools.INT16; 673 core.pixelType[i] = FormatTools.UINT32; 687 674 break; 688 675 } … … 715 702 throws IOException 716 703 { 717 tag = DataTools.read2SignedBytes(in, false); 718 subTag = DataTools.read2SignedBytes(in, false); 719 720 long nextTag = (version == 2 ? DataTools.read4SignedBytes(in, false) : 721 DataTools.read8SignedBytes(in, false)); 704 tag = in.readShort(); 705 subTag = in.readShort(); 706 707 long nextTag = (version == 2 ? in.readInt() : in.readLong()); 722 708 723 709 byte[] b = new byte[4]; -
trunk/loci/formats/in/PGMReader.java
r2804 r2922 31 31 32 32 /** 33 * PGMReader is the file format reader for 34 * Portable Gray Map (PGM) images. 33 * PGMReader is the file format reader for Portable Gray Map (PGM) images. 35 34 * 36 35 * Much of this code was adapted from ImageJ (http://rsb.info.nih.gov/ij). … … 124 123 boolean isBlackAndWhite = false; 125 124 126 if (magic.equals("P1") || magic.equals("P2")) { 127 rawBits = false; 128 core.sizeC[0] = 1; 129 isBlackAndWhite = magic.equals("P1"); 130 } 131 else if (magic.equals("P3")) { 132 rawBits = false; 133 core.sizeC[0] = 3; 134 } 135 else if (magic.equals("P4") || magic.equals("P5")) { 136 rawBits = true; 137 core.sizeC[0] = 1; 138 isBlackAndWhite = magic.equals("P4"); 139 } 140 else if (magic.equals("P6")) { 141 rawBits = true; 142 core.sizeC[0] = 3; 143 } 144 else throw new FormatException("Unsupported magic number: " + magic); 145 125 rawBits = magic.equals("P4") || magic.equals("P5") || magic.equals("P6"); 126 core.sizeC[0] = (magic.equals("P3") || magic.equals("P6")) ? 3 : 1; 127 isBlackAndWhite = magic.equals("P1") || magic.equals("P4"); 128 146 129 String line = in.readLine().trim(); 147 130 while (line.startsWith("#") || line.length() == 0) line = in.readLine(); -
trunk/loci/formats/in/PNGReader.java
r2842 r2922 36 36 37 37 /** Constructs a new PNGReader. */ 38 public PNGReader() { super("Portable Network Graphics", new String[] {"png", "pnm"}); } 39 38 public PNGReader() { 39 super("Portable Network Graphics", new String[] {"png", "pnm"}); 40 } 40 41 } -
trunk/loci/formats/in/PerkinElmerReader.java
r2857 r2922 213 213 ((prefix != null) && (s.startsWith(prefix)))) 214 214 { 215 if (cfgPos == -1) { 216 if (filename.endsWith(".cfg")) { 217 cfgPos = i; 218 prefix = ls[i].substring(0, d); 219 } 220 } 221 222 if (anoPos == -1) { 223 if (filename.endsWith(".ano")) { 224 anoPos = i; 225 prefix = ls[i].substring(0, d); 226 } 227 } 228 229 if (recPos == -1) { 230 if (filename.endsWith(".rec")) { 231 recPos = i; 232 prefix = ls[i].substring(0, d); 233 } 234 } 235 236 if (timPos == -1) { 237 if (filename.endsWith(".tim")) { 238 timPos = i; 239 prefix = ls[i].substring(0, d); 240 } 241 } 242 if (csvPos == -1) { 243 if (filename.endsWith(".csv")) { 244 csvPos = i; 245 prefix = ls[i].substring(0, d); 246 } 247 } 248 if (zpoPos == -1) { 249 if (filename.endsWith(".zpo")) { 250 zpoPos = i; 251 prefix = ls[i].substring(0, d); 252 } 253 } 254 if (htmPos == -1) { 255 if (filename.endsWith(".htm")) { 256 htmPos = i; 257 prefix = ls[i].substring(0, d); 258 } 215 if (cfgPos == -1 && filename.endsWith(".cfg")) { 216 cfgPos = i; 217 prefix = ls[i].substring(0, d); 218 } 219 if (anoPos == -1 && filename.endsWith(".ano")) { 220 anoPos = i; 221 prefix = ls[i].substring(0, d); 222 } 223 if (recPos == -1 && filename.endsWith(".rec")) { 224 recPos = i; 225 prefix = ls[i].substring(0, d); 226 } 227 if (timPos == -1 && filename.endsWith(".tim")) { 228 timPos = i; 229 prefix = ls[i].substring(0, d); 230 } 231 if (csvPos == -1 && filename.endsWith(".csv")) { 232 csvPos = i; 233 prefix = ls[i].substring(0, d); 234 } 235 if (zpoPos == -1 && filename.endsWith(".zpo")) { 236 zpoPos = i; 237 prefix = ls[i].substring(0, d); 238 } 239 if (htmPos == -1 && filename.endsWith(".htm")) { 240 htmPos = i; 241 prefix = ls[i].substring(0, d); 259 242 } 260 243 … … 345 328 tiff[i] = new TiffReader(); 346 329 if (i > 0) tiff[i].setMetadataCollected(false); 347 //tiff[i].setId(files[i]); 348 } 349 350 // highly questionable metadata parsing 330 } 351 331 352 332 // we always parse the .tim and .htm files if they exist, along with … … 562 542 switch (bpp) { 563 543 case 1: 564 core.pixelType[0] = FormatTools.INT8; 544 case 3: 545 core.pixelType[0] = FormatTools.UINT8; 565 546 break; 566 547 case 2: 567 548 core.pixelType[0] = FormatTools.UINT16; 568 549 break; 569 case 3:570 core.pixelType[0] = FormatTools.INT8;571 break;572 550 case 4: 573 core.pixelType[0] = FormatTools. INT32;551 core.pixelType[0] = FormatTools.UINT32; 574 552 break; 575 553 } … … 631 609 new Integer(core.sizeT[0]), // SizeT 632 610 new Integer(core.pixelType[0]), // PixelType 633 new Boolean(! isLittleEndian()), // BigEndian611 new Boolean(!core.littleEndian[0]), // BigEndian 634 612 core.currentOrder[0], // DimensionOrder 635 613 null, // Use image index 0 -
trunk/loci/formats/in/PictReader.java
r2857 r2922 65 65 static { 66 66 int index = 0; 67 for (int i = 0; i <256; i++) {67 for (int i=0; i<256; i++) { 68 68 EXPANSION_TABLE[index++] = (i & 128) == 0 ? (byte) 0 : (byte) 1; 69 69 EXPANSION_TABLE[index++] = (i & 64) == 0 ? (byte) 0 : (byte) 1; … … 79 79 // -- Fields -- 80 80 81 /** Stream for reading pixel data. */ 82 protected RandomAccessStream ras; 83 81 84 /** Pixel bytes. */ 82 85 protected byte[] bytes; … … 90 93 /** Image state. */ 91 94 protected int pictState; 92 93 /** Pointer into the array of bytes representing the file. */94 protected int pt;95 95 96 96 /** Vector of byte arrays representing individual rows. */ … … 125 125 126 126 /** Open a PICT image from an array of bytes (used by OpenlabReader). */ 127 public BufferedImage open(byte[] pix) throws FormatException {127 public BufferedImage open(byte[] pix) throws FormatException, IOException { 128 128 // handles case when we call this method directly, instead of 129 129 // through initFile(String) … … 137 137 pictState = INITIAL; 138 138 bytes = pix; 139 pt = 0; 139 ras = new RandomAccessStream(bytes); 140 ras.order(false); 140 141 141 142 try { … … 340 341 341 342 /** Loop through the remainder of the file and find relevant opcodes. */ 342 private boolean driveDecoder() throws FormatException {343 private boolean driveDecoder() throws FormatException, IOException { 343 344 if (debug) debug("driveDecoder"); 344 345 int opcode; … … 346 347 switch (pictState) { 347 348 case INITIAL: 348 pt += 2; 349 // skip over frame 350 pt += 8; 351 int verOpcode = 352 DataTools.bytesToInt(bytes, pt, 1, core.littleEndian[0]); 353 pt++; 354 int verNumber = 355 DataTools.bytesToInt(bytes, pt, 1, core.littleEndian[0]); 356 pt++; 349 ras.skipBytes(10); 350 int verOpcode = ras.read(); 351 int verNumber = ras.read(); 357 352 358 353 if (verOpcode == 0x11 && verNumber == 0x01) versionOne = true; 359 354 else if (verOpcode == 0x00 && verNumber == 0x11) { 360 355 versionOne = false; 361 int verNumber2 = 362 DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 363 pt += 2; 356 int verNumber2 = ras.readShort(); 364 357 365 358 if (verNumber2 != 0x02ff) { … … 368 361 369 362 // skip over v2 header -- don't need it here 370 pt += 26;363 ras.skipBytes(26); 371 364 } 372 365 else throw new FormatException("Invalid PICT file"); … … 377 370 378 371 case STATE2: 379 if (versionOne) { 380 opcode = DataTools.bytesToInt(bytes, pt, 1, core.littleEndian[0]); 381 pt++; 382 } 372 if (versionOne) opcode = ras.read(); 383 373 else { 384 374 // if at odd boundary skip a byte for opcode in PICT v2 385 375 386 if (( pt& 0x1L) != 0) {387 pt++;376 if ((ras.getFilePointer() & 0x1L) != 0) { 377 ras.skipBytes(1); 388 378 } 389 opcode = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 390 pt += 2; 379 opcode = ras.readShort(); 391 380 } 392 381 return drivePictDecoder(opcode); … … 396 385 397 386 /** Handles the opcodes in the PICT file. */ 398 private boolean drivePictDecoder(int opcode) throws FormatException { 387 private boolean drivePictDecoder(int opcode) 388 throws FormatException, IOException 389 { 399 390 if (debug) debug("drivePictDecoder"); 400 391 … … 408 399 break; 409 400 case PICT_CLIP_RGN: 410 int x = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]);411 pt += x;401 int x = ras.readShort(); 402 ras.skipBytes(x - 2); 412 403 break; 413 404 case PICT_LONGCOMMENT: 414 pt += 2;415 x = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]);416 pt += x + 2;405 ras.skipBytes(2); 406 x = ras.readShort(); 407 ras.skipBytes(x); 417 408 break; 418 409 case PICT_END: // end of PICT … … 421 412 } 422 413 423 return (pt < bytes.length);414 return ras.getFilePointer() < ras.length(); 424 415 } 425 416 426 417 /** Handles bitmap and pixmap opcodes of PICT format. */ 427 private void handlePackBits(int opcode) throws FormatException { 418 private void handlePackBits(int opcode) 419 throws FormatException, IOException 420 { 428 421 if (debug) debug("handlePackBits(" + opcode + ")"); 429 422 if (opcode == PICT_9A) { … … 432 425 } 433 426 else { 434 rowBytes = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 435 pt += 2; 427 rowBytes = ras.readShort(); 436 428 if (versionOne || (rowBytes & 0x8000) == 0) handleBitmap(opcode); 437 429 else handlePixmap(opcode); … … 440 432 441 433 /** Extract the image data in a PICT bitmap structure. */ 442 private void handleBitmap(int opcode) throws FormatException { 434 private void handleBitmap(int opcode) 435 throws FormatException, IOException 436 { 443 437 if (debug) debug("handleBitmap(" + opcode + ")"); 444 438 int row; … … 451 445 // read the bitmap data -- 3 rectangles + mode 452 446 453 int tlY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 454 pt += 2; 455 int tlX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 456 pt += 2; 457 int brY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 458 pt += 2; 459 int brX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 460 pt += 2; 447 int tlY = ras.readShort(); 448 int tlX = ras.readShort(); 449 int brY = ras.readShort(); 450 int brX = ras.readShort(); 461 451 462 452 // skip next two rectangles 463 pt += 18;453 ras.skipBytes(18); 464 454 465 455 core.sizeX[0] = brX - tlX; … … 479 469 for (row=0; row < core.sizeY[0]; ++row) { 480 470 if (rowBytes < 8) { // data is not compressed 481 System.arraycopy(bytes, pt, buf, 0, rowBytes);471 ras.read(buf, 0, rowBytes); 482 472 483 473 for (int j=buf.length; --j >= 0;) { … … 488 478 else { 489 479 int rawLen; 490 if (rowBytes > 250) { 491 rawLen = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 492 pt += 2; 493 } 494 else { 495 rawLen = DataTools.bytesToInt(bytes, pt, 1, core.littleEndian[0]); 496 pt++; 497 } 480 if (rowBytes > 250) rawLen = ras.readShort(); 481 else rawLen = ras.read(); 498 482 499 483 try { 500 System.arraycopy(bytes, pt, buf, 0, rawLen); 501 pt += rawLen; 484 ras.read(buf, 0, rawLen); 502 485 } 503 486 catch (ArrayIndexOutOfBoundsException e) { … … 519 502 520 503 /** Extracts the image data in a PICT pixmap structure. */ 521 private void handlePixmap(int opcode) throws FormatException { 504 private void handlePixmap(int opcode) 505 throws FormatException, IOException 506 { 522 507 if (debug) debug("handlePixmap(" + opcode + ")"); 523 508 int pixelSize; … … 530 515 // read the pixmap (9A) 531 516 532 pt += 4; // skip fake length and fake EOF 533 534 pt += 2; 517 ras.skipBytes(6); 535 518 536 519 // read the bounding box 537 int tlY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 538 pt += 2; 539 int tlX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 540 pt += 2; 541 int brY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 542 pt += 2; 543 int brX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 544 pt += 2; 545 546 pt += 2; // undocumented extra short in the data structure 547 548 pt += 16; 549 550 pixelSize = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 551 pt += 2; 552 compCount = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 553 pt += 16; // reserved 520 int tlY = ras.readShort(); 521 int tlX = ras.readShort(); 522 int brY = ras.readShort(); 523 int brX = ras.readShort(); 524 525 ras.skipBytes(18); 526 527 pixelSize = ras.readShort(); 528 compCount = ras.readShort(); 529 ras.skipBytes(14); 554 530 555 531 core.sizeX[0] = brX - tlX; … … 570 546 else { 571 547 rowBytes &= 0x3fff; // mask off flags 572 573 int tlY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 574 pt += 2; 575 int tlX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 576 pt += 2; 577 int brY = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 578 pt += 2; 579 int brX = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 580 pt += 2; 581 582 // unnecessary data 583 pt += 18; 584 585 pixelSize = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 586 pt += 2; 587 compCount = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 588 pt += 2; 589 590 // unnecessary data 591 pt += 14; 548 549 int tlY = ras.readShort(); 550 int tlX = ras.readShort(); 551 int brY = ras.readShort(); 552 int brX = ras.readShort(); 553 554 ras.skipBytes(18); 555 556 pixelSize = ras.readShort(); 557 compCount = ras.readShort(); 558 559 ras.skipBytes(14); 592 560 593 561 // read the lookup table 594 562 595 pt += 4; 596 int flags = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 597 pt += 2; 598 int count = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 599 pt += 2; 563 ras.skipBytes(4); 564 int flags = ras.readShort(); 565 int count = ras.readShort(); 600 566 601 567 count++; … … 603 569 604 570 for (int i=0; i<count; i++) { 605 int index = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 606 pt += 2; 571 int index = ras.readShort(); 607 572 if ((flags & 0x8000) != 0) index = i; 608 lookup[0][index] = 609 DataTools.bytesToShort(bytes, pt, 2, core.littleEndian[0]); 610 pt += 2; 611 lookup[1][index] = 612 DataTools.bytesToShort(bytes, pt, 2, core.littleEndian[0]); 613 pt += 2; 614 lookup[2][index] = 615 DataTools.bytesToShort(bytes, pt, 2, core.littleEndian[0]); 616 pt += 2; 573 lookup[0][index] = ras.readShort(); 574 lookup[1][index] = ras.readShort(); 575 lookup[2][index] = ras.readShort(); 617 576 } 618 577 … … 622 581 623 582 // skip over two rectangles 624 pt += 18;625 626 if (opcode == PICT_BITSRGN || opcode == PICT_PACKBITSRGN) pt += 2;583 ras.skipBytes(18); 584 585 if (opcode == PICT_BITSRGN || opcode == PICT_PACKBITSRGN) ras.skipBytes(2); 627 586 628 587 handlePixmap(rowBytes, pixelSize, compCount); … … 631 590 /** Handles the unpacking of the image data. */ 632 591 private void handlePixmap(int rBytes, int pixelSize, int compCount) 633 throws FormatException 592 throws FormatException, IOException 634 593 { 635 594 if (debug) { … … 676 635 buf = new byte[bufSize]; 677 636 for (int row=0; row<core.sizeY[0]; row++) { 678 System.arraycopy(bytes, pt,buf, 0, rBytes);637 ras.read(buf, 0, rBytes); 679 638 680 639 switch (pixelSize) { … … 701 660 buf = new byte[bufSize + 1 + bufSize / 128]; 702 661 for (int row=0; row<core.sizeY[0]; row++) { 703 if (rBytes > 250) { 704 rawLen = DataTools.bytesToInt(bytes, pt, 2, core.littleEndian[0]); 705 pt += 2; 706 } 707 else { 708 rawLen = DataTools.bytesToInt(bytes, pt, 1, core.littleEndian[0]); 709 pt++; 710 } 662 if (rBytes > 250) rawLen = ras.readShort(); 663 else rawLen = ras.read(); 711 664 712 665 if (rawLen > buf.length) rawLen = buf.length; 713 666 714 if (( bytes.length - pt) <= rawLen) {715 rawLen = bytes.length - pt - 1;667 if ((ras.length() - ras.getFilePointer()) <= rawLen) { 668 rawLen = (int) (ras.length() - ras.getFilePointer() - 1); 716 669 } 717 670 718 671 if (rawLen < 0) { 719 672 rawLen = 0; 720 pt = bytes.length - 1; 721 } 722 723 System.arraycopy(bytes, pt, buf, 0, rawLen); 724 pt += rawLen; 673 ras.seek(ras.length() - 1); 674 } 675 676 ras.read(buf, 0, rawLen); 725 677 726 678 if (pixelSize == 16) { … … 806 758 int t; 807 759 byte v; 808 int count = 0; // number of pixels in a byte809 int maskshift = 1; // num bits to shift mask810 int pixelshift = 0; // num bits to shift pixel760 int count = 8 / bitSize; // number of pixels in a byte 761 int maskshift = bitSize; // num bits to shift mask 762 int pixelshift = 8 - bitSize; // num bits to shift pixel 811 763 int tpixelshift = 0; 812 int pixelshiftdelta = 0;764 int pixelshiftdelta = bitSize; 813 765 int mask = 0; 814 766 int tmask; // temp mask … … 821 773 case 1: 822 774 mask = 0x80; 823 maskshift = 1;824 count = 8;825 pixelshift = 7;826 pixelshiftdelta = 1;827 775 break; 828 776 case 2: 829 777 mask = 0xC0; 830 maskshift = 2;831 count = 4;832 pixelshift = 6;833 pixelshiftdelta = 2;834 778 break; 835 779 case 4: 836 780 mask = 0xF0; 837 maskshift = 4;838 count = 2;839 pixelshift = 4;840 pixelshiftdelta = 4;841 781 break; 842 782 } -
trunk/loci/formats/in/QTReader.java
r2914 r2922 331 331 case 0: 332 332 case 1: 333 case 3: 333 334 core.pixelType[0] = FormatTools.UINT8; 334 335 break; 335 336 case 2: 336 core.pixelType[0] = FormatTools. INT16;337 core.pixelType[0] = FormatTools.UINT16; 337 338 break; 338 case 3: 339 core.pixelType[0] = FormatTools.UINT8; 340 break; 341 } 342 343 /* 344 if (flip) { 345 int tmp = core.sizeX[0]; 346 core.sizeX[0] = core.sizeY[0]; 347 core.sizeY[0] = tmp; 348 } 349 */ 339 } 350 340 351 341 core.rgb[0] = bitsPerPixel < 40; … … 484 474 485 475 // read the atom type 486 byte[] four = new byte[4]; 487 in.read(four); 488 String atomType = new String(four); 476 String atomType = in.readString(4); 489 477 490 478 // if atomSize is 1, then there is an 8 byte extended size … … 609 597 610 598 for (int i=0; i<numEntries; i++) { 611 byte[] b = new byte[4];612 in.read(b);613 599 if (i == 0) { 614 codec = new String(b);600 codec = in.readString(4); 615 601 in.skipBytes(74); 616 602 … … 627 613 } 628 614 else { 629 altCodec = new String(b);615 altCodec = in.readString(4); 630 616 addMeta("Second codec", altCodec); 631 617 } … … 738 724 String test = null; 739 725 boolean found = false; 740 byte[] b = new byte[4];741 726 while (!found && in.getFilePointer() < (in.length() - 4)) { 742 in.read(b); 743 test = new String(b); 727 test = in.readString(4); 744 728 if (test.equals("moov")) { 745 729 found = true; -
trunk/loci/formats/in/SlidebookReader.java
r2916 r2922 102 102 super.initFile(id); 103 103 in = new RandomAccessStream(id); 104 in.order(true); 104 105 105 106 status("Finding offsets to pixel data"); … … 216 217 if (n == 'i') { 217 218 in.skipBytes(79); 218 core.sizeX[0] = DataTools.read2UnsignedBytes(in, true);219 core.sizeY[0] = DataTools.read2UnsignedBytes(in, true);219 core.sizeX[0] = in.readShort(); 220 core.sizeY[0] = in.readShort(); 220 221 iCount++; 221 222 } -
trunk/loci/formats/in/ZeissLSMReader.java
r2857 r2922 159 159 160 160 RandomAccessStream ras = new RandomAccessStream(cz); 161 162 put("MagicNumber", DataTools.read4UnsignedBytes(ras, little)); 163 put("StructureSize", DataTools.read4SignedBytes(ras, little)); 164 put("DimensionX", DataTools.read4SignedBytes(ras, little)); 165 put("DimensionY", DataTools.read4SignedBytes(ras, little)); 166 167 core.sizeZ[0] = DataTools.read4SignedBytes(ras, little); 168 int c = DataTools.read4SignedBytes(ras, little); 169 core.sizeT[0] = DataTools.read4SignedBytes(ras, little); 161 ras.order(little); 162 163 put("MagicNumber", ras.readInt()); 164 put("StructureSize", ras.readInt()); 165 put("DimensionX", ras.readInt()); 166 put("DimensionY", ras.readInt()); 167 168 core.sizeZ[0] = ras.readInt(); 169 int c = ras.readInt(); 170 core.sizeT[0] = ras.readInt(); 170 171 171 172 if (c > core.sizeC[0] || c != 1) core.sizeC[0] = c; … … 188 189 put("DimensionTime", core.sizeT[0]); 189 190 190 int dataType = DataTools.read4SignedBytes(ras, little);191 int dataType = ras.readInt(); 191 192 switch (dataType) { 192 193 case 1: … … 214 215 int[] bps = TiffTools.getBitsPerSample(ifd); 215 216 switch (bps[0]) { 216 case 8:217 core.pixelType[0] = FormatTools.UINT8;218 break;219 217 case 16: 220 218 core.pixelType[0] = FormatTools.UINT16; … … 228 226 } 229 227 230 put("ThumbnailX", DataTools.read4SignedBytes(ras, little));231 put("ThumbnailY", DataTools.read4SignedBytes(ras, little));232 233 put("VoxelSizeX", DataTools.readDouble(ras, little));234 put("VoxelSizeY", DataTools.readDouble(ras, little));235 put("VoxelSizeZ", DataTools.readDouble(ras, little));236 237 put("OriginX", DataTools.readDouble(ras, little));238 put("OriginY", DataTools.readDouble(ras, little));239 put("OriginZ", DataTools.readDouble(ras, little));240 241 int scanType = DataTools.read2UnsignedBytes(ras, little);228 put("ThumbnailX", ras.readInt()); 229 put("ThumbnailY", ras.readInt()); 230 231 put("VoxelSizeX", ras.readDouble()); 232 put("VoxelSizeY", ras.readDouble()); 233 put("VoxelSizeZ", ras.readDouble()); 234 235 put("OriginX", ras.readDouble()); 236 put("OriginY", ras.readDouble()); 237 put("OriginZ", ras.readDouble()); 238 239 int scanType = ras.readShort(); 242 240 switch (scanType) { 243 241 case 0: … … 307 305 } 308 306 309 int spectralScan = DataTools.read2UnsignedBytes(ras, little);307 int spectralScan = ras.readShort(); 310 308 switch (spectralScan) { 311 309 case 0: … … 319 317 } 320 318 321 long type = DataTools.read4UnsignedBytes(ras, little);319 long type = ras.readInt(); 322 320 switch ((int) type) { 323 321 case 0: … … 334 332 } 335 333 336 long overlayOffset = DataTools.read4UnsignedBytes(ras, little);337 long inputLUTOffset = DataTools.read4UnsignedBytes(ras, little);338 long outputLUTOffset = DataTools.read4UnsignedBytes(ras, little);339 long channelColorsOffset = DataTools.read4UnsignedBytes(ras, little);340 341 put("TimeInterval", DataTools.readDouble(ras, little));342 343 long channelDataTypesOffset = DataTools.read4UnsignedBytes(ras, little);344 long scanInformationOffset = DataTools.read4UnsignedBytes(ras, little);345 long ksDataOffset = DataTools.read4UnsignedBytes(ras, little);346 long timeStampOffset = DataTools.read4UnsignedBytes(ras, little);347 long eventListOffset = DataTools.read4UnsignedBytes(ras, little);348 long roiOffset = DataTools.read4UnsignedBytes(ras, little);349 long bleachRoiOffset = DataTools.read4UnsignedBytes(ras, little);350 long nextRecordingOffset = DataTools.read4UnsignedBytes(ras, little);351 352 put("DisplayAspectX", DataTools.readDouble(ras, little));353 put("DisplayAspectY", DataTools.readDouble(ras, little));354 put("DisplayAspectZ", DataTools.readDouble(ras, little));355 put("DisplayAspectTime", DataTools.readDouble(ras, little));356 357 long meanOfRoisOverlayOffset = DataTools.read4UnsignedBytes(ras, little);358 long topoIsolineOverlayOffset = DataTools.read4UnsignedBytes(ras, little);359 long topoProfileOverlayOffset = DataTools.read4UnsignedBytes(ras, little);360 long linescanOverlayOffset = DataTools.read4UnsignedBytes(ras, little);361 362 put("ToolbarFlags", DataTools.read4UnsignedBytes(ras, little));363 long channelWavelengthOffset = DataTools.read4UnsignedBytes(ras, little);364 long channelFactorsOffset = DataTools.read4UnsignedBytes(ras, little);365 366 double objectiveSphereCorrection = DataTools.readDouble(ras, little);367 long unmixParamsOffset = DataTools.read4UnsignedBytes(ras, little);334 long overlayOffset = ras.readInt(); 335 long inputLUTOffset = ras.readInt(); 336 long outputLUTOffset = ras.readInt(); 337 long channelColorsOffset = ras.readInt(); 338 339 put("TimeInterval", ras.readDouble()); 340 341 long channelDataTypesOffset = ras.readInt(); 342 long scanInformationOffset = ras.readInt(); 343 long ksDataOffset = ras.readInt(); 344 long timeStampOffset = ras.readInt(); 345 long eventListOffset = ras.readInt(); 346 long roiOffset = ras.readInt(); 347 long bleachRoiOffset = ras.readInt(); 348 long nextRecordingOffset = ras.readInt(); 349 350 put("DisplayAspectX", ras.readDouble()); 351 put("DisplayAspectY", ras.readDouble()); 352 put("DisplayAspectZ", ras.readDouble()); 353 put("DisplayAspectTime", ras.readDouble()); 354 355 long meanOfRoisOverlayOffset = ras.readInt(); 356 long topoIsolineOverlayOffset = ras.readInt(); 357 long topoProfileOverlayOffset = ras.readInt(); 358 long linescanOverlayOffset = ras.readInt(); 359 360 put("ToolbarFlags", ras.readInt()); 361 long channelWavelengthOffset = ras.readInt(); 362 long channelFactorsOffset = ras.readInt(); 363 364 double objectiveSphereCorrection = ras.readDouble(); 365 long unmixParamsOffset = ras.readInt(); 368 366 369 367 // read referenced structures … … 420 418 if (timeStampOffset != 0) { 421 419 in.seek(timeStampOffset); 422 int blockSize = DataTools.read4SignedBytes(in, little);423 int numberOfStamps = DataTools.read4SignedBytes(in, little);420 int blockSize = in.readInt(); 421 int numberOfStamps = in.readInt(); 424 422 for (int i=0; i<numberOfStamps; i++) { 425 put("TimeStamp" + i, DataTools.readDouble(in, little));423 put("TimeStamp" + i, in.readDouble()); 426 424 } 427 425 } -
trunk/loci/formats/ome/OMEXMLMetadataStore.java
r2857 r2922 29 29 import java.io.IOException; 30 30 import java.lang.reflect.Constructor; 31 import java.util.Arrays; 32 import java.util.Vector; 31 import java.util.*; 33 32 import javax.xml.parsers.ParserConfigurationException; 34 33 import javax.xml.transform.TransformerException; … … 96 95 } 97 96 98 /** Creates a new key/value pair. */ 99 public void setOriginalMetadata(String key, String value) { 100 if (firstImageCA == null) { 101 ImageNode image = (ImageNode) getChild(root, "Image", 0); 102 CustomAttributesNode ca = 103 (CustomAttributesNode) getChild(image, "CustomAttributes", 0); 104 firstImageCA = ca.getDOMElement(); 105 106 Vector original = DOMUtil.getChildElements("OriginalMetadata", 107 ca.getDOMElement()); 108 if (original.size() == 0) { 109 Element el = DOMUtil.createChild(root.getDOMElement(), 110 "SemanticTypeDefinitions"); 111 OMEXMLNode node = OMEXMLNode.createNode(el); 112 node.setAttribute("xmlns", 113 "http://www.openmicroscopy.org/XMLschemas/STD/RC2/STD.xsd"); 114 el = DOMUtil.createChild(el, "SemanticType"); 115 node = OMEXMLNode.createNode(el); 116 node.setAttribute("Name", "OriginalMetadata"); 117 node.setAttribute("AppliesTo", "I"); 118 119 Element nameElement = DOMUtil.createChild(el, "Element"); 120 OMEXMLNode nameNode = OMEXMLNode.createNode(nameElement); 121 nameNode.setAttribute("Name", "name"); 122 nameNode.setAttribute("DBLocation", "ORIGINAL_METADATA.NAME"); 123 nameNode.setAttribute("DataType", "string"); 124 125 Element valueElement = DOMUtil.createChild(el, "Element"); 126 OMEXMLNode valueNode = OMEXMLNode.createNode(valueElement); 127 valueElement.setAttribute("Name", "value"); 128 valueElement.setAttribute("DBLocation", "ORIGINAL_METADATA.VALUE"); 129 valueElement.setAttribute("DataType", "string"); 130 } 131 } 132 133 Element el = DOMUtil.createChild(firstImageCA, "OriginalMetadata"); 134 OMEXMLNode node = new AttributeNode(el); 135 node.setAttribute("name", key); 136 node.setAttribute("value", value); 97 /** 98 * Add each of the key/value pairs in the hashtable as a new 99 * OriginalMetadata node. 100 */ 101 public void populateOriginalMetadata(Hashtable h) { 102 ImageNode image = (ImageNode) getChild(root, "Image", 0); 103 CustomAttributesNode ca = 104 (CustomAttributesNode) getChild(image, "CustomAttributes", 0); 105 firstImageCA = ca.getDOMElement(); 106 107 Vector original = DOMUtil.getChildElements("OriginalMetadata", 108 ca.getDOMElement()); 109 if (original.size() == 0) { 110 Element el = DOMUtil.createChild(root.getDOMElement(), 111 "SemanticTypeDefinitions"); 112 OMEXMLNode node = OMEXMLNode.createNode(el); 113 node.setAttribute("xmlns", 114 "http://www.openmicroscopy.org/XMLschemas/STD/RC2/STD.xsd"); 115 el = DOMUtil.createChild(el, "SemanticType"); 116 node = OMEXMLNode.createNode(el); 117 node.setAttribute("Name", "OriginalMetadata"); 118 node.setAttribute("AppliesTo", "I"); 119 120 Element nameElement = DOMUtil.createChild(el, "Element"); 121 OMEXMLNode nameNode = OMEXMLNode.createNode(nameElement); 122 nameNode.setAttribute("Name", "name"); 123 nameNode.setAttribute("DBLocation", "ORIGINAL_METADATA.NAME"); 124 nameNode.setAttribute("DataType", "string"); 125 126 Element valueElement = DOMUtil.createChild(el, "Element"); 127 OMEXMLNode valueNode = OMEXMLNode.createNode(valueElement); 128 valueElement.setAttribute("Name", "value"); 129 valueElement.setAttribute("DBLocation", "ORIGINAL_METADATA.VALUE"); 130 valueElement.setAttribute("DataType", "string"); 131 } 132 133 Object[] keys = h.keySet().toArray(); 134 for (int i=0; i<h.size(); i++) { 135 Element el = DOMUtil.createChild(firstImageCA, "OriginalMetadata"); 136 OMEXMLNode node = new AttributeNode(el); 137 node.setAttribute("name", keys[i].toString()); 138 node.setAttribute("value", h.get(keys[i]).toString()); 139 } 137 140 } 138 141 -
trunk/loci/formats/test/ConfigurationFiles.java
r2880 r2922 141 141 s.substring(ndx, s.indexOf(" ", ndx))); 142 142 ndx = s.indexOf("little") + 7; 143 entry.littleEndian[i] = s.substring(ndx).equals("true"); 143 entry.littleEndian[i] = 144 s.substring(ndx, s.indexOf(" ", ndx)).equals("true"); 144 145 ndx = s.indexOf("md5") + 4; 145 entry.md5[i] = s.substring(ndx , s.indexOf(" ", ndx));146 entry.md5[i] = s.substring(ndx); 146 147 } 147 148
Note: See TracChangeset
for help on using the changeset viewer.