use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class DNGReader method initStandardMetadata.
// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
super.initStandardMetadata();
// reset image dimensions
// the actual image data is stored in IFDs referenced by the SubIFD tag
// in the 'real' IFD
CoreMetadata m = core.get(0);
m.imageCount = ifds.size();
IFD firstIFD = ifds.get(0);
PhotoInterp photo = firstIFD.getPhotometricInterpretation();
int samples = firstIFD.getSamplesPerPixel();
m.rgb = samples > 1 || photo == PhotoInterp.RGB || photo == PhotoInterp.CFA_ARRAY;
if (photo == PhotoInterp.CFA_ARRAY)
samples = 3;
m.sizeX = (int) firstIFD.getImageWidth();
m.sizeY = (int) firstIFD.getImageLength();
m.sizeZ = 1;
m.sizeC = isRGB() ? samples : 1;
m.sizeT = ifds.size();
m.pixelType = FormatTools.UINT16;
m.indexed = false;
// now look for the EXIF IFD pointer
IFDList exifIFDs = tiffParser.getExifIFDs();
if (exifIFDs.size() > 0) {
IFD exifIFD = exifIFDs.get(0);
tiffParser.fillInIFD(exifIFD);
for (Integer key : exifIFD.keySet()) {
int tag = key.intValue();
String name = IFD.getIFDTagName(tag);
if (tag == IFD.CFA_PATTERN) {
byte[] cfa = (byte[]) exifIFD.get(key);
int[] colorMap = new int[cfa.length];
for (int i = 0; i < cfa.length; i++) colorMap[i] = (int) cfa[i];
addGlobalMeta(name, colorMap);
cfaPattern = colorMap;
} else {
addGlobalMeta(name, exifIFD.get(key));
if (name.equals("MAKER_NOTE")) {
byte[] b = (byte[]) exifIFD.get(key);
int offset = DataTools.bytesToInt(b, b.length - 4, isLittleEndian());
byte[] buf = new byte[b.length + offset - 8];
System.arraycopy(b, b.length - 8, buf, 0, 8);
System.arraycopy(b, 0, buf, offset, b.length - 8);
RandomAccessInputStream makerNote = new RandomAccessInputStream(buf);
TiffParser tp = new TiffParser(makerNote);
IFD note = null;
try {
note = tp.getFirstIFD();
} catch (Exception e) {
LOGGER.debug("Failed to parse first IFD", e);
}
if (note != null) {
for (Integer nextKey : note.keySet()) {
int nextTag = nextKey.intValue();
addGlobalMeta(name, note.get(nextKey));
if (nextTag == WHITE_BALANCE_RGB_COEFFS) {
if (note.get(nextTag) instanceof TiffRational[]) {
TiffRational[] wb = (TiffRational[]) note.get(nextTag);
whiteBalance = new double[wb.length];
for (int i = 0; i < wb.length; i++) {
whiteBalance[i] = wb[i].doubleValue();
}
} else {
// use a default white balance table
whiteBalance = new double[3];
whiteBalance[0] = 2.391381;
whiteBalance[1] = 0.929156;
whiteBalance[2] = 1.298254;
}
}
}
}
makerNote.close();
}
}
}
}
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class CellSensReader method reopenFile.
/* @see loci.formats.IFormatReader#reopenFile() */
public void reopenFile() throws IOException {
super.reopenFile();
parser = new TiffParser(currentId);
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class APLReader method openBytes.
/**
* @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
*/
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
if (parser == null) {
parser = new TiffParser[getSeriesCount()];
}
if (parser[getSeries()] == null) {
parser[getSeries()] = new TiffParser(tiffFiles[getSeries()]);
parser[getSeries()].setDoCaching(false);
}
IFD ifd = ifds[getSeries()].get(no);
return parser[getSeries()].getSamples(ifd, buf, x, y, w, h);
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class BDReader method getTimestamp.
private long getTimestamp(String file) throws FormatException, IOException {
RandomAccessInputStream s = new RandomAccessInputStream(file, 16);
TiffParser parser = new TiffParser(s);
parser.setDoCaching(false);
IFD firstIFD = parser.getFirstIFD();
if (firstIFD != null) {
TiffIFDEntry timestamp = (TiffIFDEntry) firstIFD.get(IFD.DATE_TIME);
if (timestamp != null) {
String stamp = parser.getIFDValue(timestamp).toString();
s.close();
stamp = DateTools.formatDate(stamp, BaseTiffReader.DATE_FORMATS, ".");
Timestamp t = Timestamp.valueOf(stamp);
// NPE if invalid input.
return t.asInstant().getMillis();
}
}
s.close();
return new Location(file).lastModified();
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class TiffPixelsTest method readSavedPlane.
// -- Helper method --
private byte[] readSavedPlane() throws FormatException, IOException {
ByteArrayHandle savedData = new ByteArrayHandle();
RandomAccessOutputStream out = new RandomAccessOutputStream(savedData);
RandomAccessInputStream in = new RandomAccessInputStream(savedData);
TiffSaver saver = new TiffSaver(out, savedData);
// saver.setInputStream(in);
saver.writeImage(data, ifd, 0, FormatTools.UINT16, false);
out.close();
TiffParser parser = new TiffParser(in);
byte[] plane = new byte[data.length];
parser.getSamples(ifd, plane);
in.close();
return plane;
}
Aggregations