public TiffDecoder(InputStream in, String name) { directory = ""; this.name = name; url = ""; this.in = new RandomAccessStream(in); }
void error(String message) throws IOException { if (in!=null) in.close(); throw new IOException(message); }
byte[] getString(int count, long offset) throws IOException { count--; // skip null byte at end of string if (count<=3) return null; byte[] bytes = new byte[count]; long saveLoc = in.getLongFilePointer(); in.seek(offset); in.readFully(bytes); in.seek(saveLoc); return bytes; }
void decodeNIHImageHeader(int offset, FileInfo fi) throws IOException { long saveLoc = in.getLongFilePointer(); in.seek(offset+12); int version = in.readShort(); in.seek(offset+160); double scale = in.readDouble(); if (version>106 && scale!=0.0) { fi.pixelWidth = 1.0/scale; in.seek(offset+172); int units = in.readShort(); if (version<=153) units += 5; switch (units) { in.seek(offset+182); int fitType = in.read(); int unused = in.read(); int nCoefficients = in.readShort(); if (fitType==11) { fi.calibrationFunction = 21; //Calibration.UNCALIBRATED_OD fi.coefficients[i] = in.readDouble(); in.seek(offset+234); int size = in.read(); StringBuffer sb = new StringBuffer(); if (size>=1 && size<=16) { for (int i=0; i<size; i++)
ArrayList list = new ArrayList(); if (in==null) in = new RandomAccessStream(new RandomAccessFile(new File(directory, name), "r")); ifdOffset = OpenImageFileHeader(); if (ifdOffset<0L) { in.close(); return null; in.seek(ifdOffset); FileInfo fi = OpenIFD(); if (fi!=null) { in.close(); return null; } else { if (debugMode) info[0].debugInfo = dInfo; if (url!=null) { in.seek(0); info[0].inputStream = in; } else in.close(); if (info[0].info==null) info[0].info = tiffMetadata;
void getOverlay(int first, int last, FileInfo fi) throws IOException { fi.overlay = new byte[last-first+1][]; int index = 0; for (int i=first; i<=last; i++) { int len = metaDataCounts[i]; fi.overlay[index] = new byte[len]; in.readFully(fi.overlay[index], len); index++; } }
double getRational(long loc) throws IOException { long saveLoc = in.getLongFilePointer(); in.seek(loc); double numerator = getUnsignedInt(); double denominator = getUnsignedInt(); in.seek(saveLoc); if (denominator!=0.0) return numerator/denominator; else return 0.0; }
public final void readFully(byte[] bytes, int len) throws IOException { int read = 0; do { int l = read(bytes, read, len - read); if(l < 0) break; read += l; } while (read<len); }
long OpenImageFileHeader() throws IOException { // Open 8-byte Image File Header at start of file. // Returns the offset in bytes to the first IFD or -1 // if this is not a valid tiff file. int byteOrder = in.readShort(); if (byteOrder==0x4949) // "II" littleEndian = true; else if (byteOrder==0x4d4d) // "MM" littleEndian = false; else { in.close(); return -1; } int magicNumber = getShort(); // 42 long offset = ((long)getInt())&0xffffffffL; return offset; }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
void decodeNIHImageHeader(int offset, FileInfo fi) throws IOException { long saveLoc = in.getLongFilePointer(); in.seek(offset+12); int version = in.readShort(); in.seek(offset+160); double scale = in.readDouble(); if (version>106 && scale!=0.0) { fi.pixelWidth = 1.0/scale; in.seek(offset+172); int units = in.readShort(); if (version<=153) units += 5; switch (units) { in.seek(offset+182); int fitType = in.read(); int unused = in.read(); int nCoefficients = in.readShort(); if (fitType==11) { fi.calibrationFunction = 21; //Calibration.UNCALIBRATED_OD fi.coefficients[i] = in.readDouble(); in.seek(offset+234); int size = in.read(); StringBuffer sb = new StringBuffer(); if (size>=1 && size<=16) { for (int i=0; i<size; i++)
ArrayList list = new ArrayList(); if (in==null) in = new RandomAccessStream(new RandomAccessFile(new File(directory, name), "r")); ifdOffset = OpenImageFileHeader(); if (ifdOffset<0L) { in.close(); return null; in.seek(ifdOffset); FileInfo fi = OpenIFD(); if (fi!=null) { in.close(); return null; } else { if (debugMode) info[0].debugInfo = dInfo; if (url!=null) { in.seek(0); info[0].inputStream = in; } else in.close(); if (info[0].info==null) info[0].info = tiffMetadata;
void skipUnknownType(int first, int last) throws IOException { byte[] buffer = new byte[metaDataCounts[first]]; for (int i=first; i<=last; i++) { int len = metaDataCounts[i]; if (len>buffer.length) buffer = new byte[len]; in.readFully(buffer, len); } }
double getRational(long loc) throws IOException { long saveLoc = in.getLongFilePointer(); in.seek(loc); double numerator = getUnsignedInt(); double denominator = getUnsignedInt(); in.seek(saveLoc); if (denominator!=0.0) return numerator/denominator; else return 0.0; }
long OpenImageFileHeader() throws IOException { // Open 8-byte Image File Header at start of file. // Returns the offset in bytes to the first IFD or -1 // if this is not a valid tiff file. int byteOrder = in.readShort(); if (byteOrder==0x4949) // "II" littleEndian = true; else if (byteOrder==0x4d4d) // "MM" littleEndian = false; else { in.close(); return -1; } int magicNumber = getShort(); // 42 long offset = ((long)getInt())&0xffffffffL; return offset; }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
byte[] getString(int count, long offset) throws IOException { count--; // skip null byte at end of string if (count<=3) return null; byte[] bytes = new byte[count]; long saveLoc = in.getLongFilePointer(); in.seek(offset); in.readFully(bytes); in.seek(saveLoc); return bytes; }