use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.
the class VectraReader method initStandardMetadata.
// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
super.initStandardMetadata();
ifds = tiffParser.getIFDs();
thumbnailIFDs = null;
for (IFD ifd : ifds) {
tiffParser.fillInIFD(ifd);
}
// count number of channels
CoreMetadata m = core.get(0);
m.sizeC = 1;
if (ifds.get(0).getSamplesPerPixel() == 1) {
long width = ifds.get(0).getImageWidth();
long height = ifds.get(0).getImageLength();
int ifd = 1;
while (ifds.get(ifd).getImageWidth() == width && ifds.get(ifd).getImageLength() == height) {
m.sizeC++;
ifd++;
}
}
for (int start = m.sizeC + 1; start < ifds.size(); start += m.sizeC) {
IFD ifd = ifds.get(start);
if (ifd.getIFDIntValue(IFD.NEW_SUBFILE_TYPE) == 1) {
pyramidDepth++;
} else
break;
}
int coreSize = ifds.size() - (pyramidDepth * (m.sizeC - 1));
// repopulate core metadata
core.clear();
for (int s = 0; s < coreSize; s++) {
CoreMetadata ms = new CoreMetadata(m);
if (s == 0) {
ms.resolutionCount = pyramidDepth;
}
core.add(ms);
}
for (int s = 0; s < core.size(); s++) {
CoreMetadata ms = core.get(s);
int index = getIFDIndex(s, 0);
IFD ifd = ifds.get(index);
PhotoInterp p = ifd.getPhotometricInterpretation();
int samples = ifd.getSamplesPerPixel();
ms.rgb = samples > 1 || p == PhotoInterp.RGB;
ms.sizeX = (int) ifd.getImageWidth();
ms.sizeY = (int) ifd.getImageLength();
ms.sizeZ = 1;
ms.sizeT = 1;
if (ms.rgb) {
ms.sizeC = samples;
}
ms.littleEndian = ifd.isLittleEndian();
ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
ms.imageCount = ms.sizeC / samples;
ms.pixelType = ifd.getPixelType();
ms.metadataComplete = true;
ms.interleaved = false;
ms.falseColor = false;
ms.dimensionOrder = "XYCZT";
ms.thumbnail = s != 0;
}
}
use of loci.formats.tiff.PhotoInterp 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.PhotoInterp in project bioformats by openmicroscopy.
the class PhotoInterpTest method testLookupBlackIsZero.
@Test
public void testLookupBlackIsZero() {
PhotoInterp pi = PhotoInterp.get(1);
assertEquals(PhotoInterp.BLACK_IS_ZERO, pi);
}
use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.
the class MinimalTiffReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id, 16);
initTiffParser();
Boolean littleEndian = tiffParser.checkHeader();
if (littleEndian == null) {
throw new FormatException("Invalid TIFF file: " + id);
}
boolean little = littleEndian.booleanValue();
in.order(little);
LOGGER.info("Reading IFDs");
IFDList allIFDs = tiffParser.getIFDs();
if (allIFDs == null || allIFDs.size() == 0) {
throw new FormatException("No IFDs found");
}
ifds = new IFDList();
thumbnailIFDs = new IFDList();
subResolutionIFDs = new ArrayList<IFDList>();
for (IFD ifd : allIFDs) {
tiffParser.fillInIFD(ifd);
Number subfile = (Number) ifd.getIFDValue(IFD.NEW_SUBFILE_TYPE);
int subfileType = subfile == null ? 0 : subfile.intValue();
if (subfileType != 1 || allIFDs.size() <= 1) {
ifds.add(ifd);
} else if (subfileType == 1) {
thumbnailIFDs.add(ifd);
}
}
LOGGER.info("Populating metadata");
CoreMetadata ms0 = core.get(0);
ms0.imageCount = ifds.size();
tiffParser.setAssumeEqualStrips(equalStrips);
for (IFD ifd : ifds) {
if ((ifd.getCompression() == TiffCompression.JPEG_2000 || ifd.getCompression() == TiffCompression.JPEG_2000_LOSSY) && ifd.getImageWidth() == ifds.get(0).getImageWidth()) {
LOGGER.debug("Found IFD with JPEG 2000 compression");
long[] stripOffsets = ifd.getStripOffsets();
long[] stripByteCounts = ifd.getStripByteCounts();
if (stripOffsets.length > 0) {
long stripOffset = stripOffsets[0];
in.seek(stripOffset);
JPEG2000MetadataParser metadataParser = new JPEG2000MetadataParser(in, stripOffset + stripByteCounts[0]);
resolutionLevels = metadataParser.getResolutionLevels();
if (resolutionLevels != null && !noSubresolutions) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Original resolution IFD Levels %d %dx%d Tile %dx%d", resolutionLevels, ifd.getImageWidth(), ifd.getImageLength(), ifd.getTileWidth(), ifd.getTileLength()));
}
IFDList theseSubResolutionIFDs = new IFDList();
subResolutionIFDs.add(theseSubResolutionIFDs);
for (int level = 1; level <= resolutionLevels; level++) {
IFD newIFD = new IFD(ifd);
long imageWidth = ifd.getImageWidth();
long imageLength = ifd.getImageLength();
long tileWidth = ifd.getTileWidth();
long tileLength = ifd.getTileLength();
long factor = (long) Math.pow(2, level);
long newTileWidth = Math.round((double) tileWidth / factor);
newTileWidth = newTileWidth < 1 ? 1 : newTileWidth;
long newTileLength = Math.round((double) tileLength / factor);
newTileLength = newTileLength < 1 ? 1 : newTileLength;
long evenTilesPerRow = imageWidth / tileWidth;
long evenTilesPerColumn = imageLength / tileLength;
double remainingWidth = ((double) (imageWidth - (evenTilesPerRow * tileWidth))) / factor;
remainingWidth = remainingWidth < 1 ? Math.ceil(remainingWidth) : Math.round(remainingWidth);
double remainingLength = ((double) (imageLength - (evenTilesPerColumn * tileLength))) / factor;
remainingLength = remainingLength < 1 ? Math.ceil(remainingLength) : Math.round(remainingLength);
long newImageWidth = (long) ((evenTilesPerRow * newTileWidth) + remainingWidth);
long newImageLength = (long) ((evenTilesPerColumn * newTileLength) + remainingLength);
int resolutionLevel = Math.abs(level - resolutionLevels);
newIFD.put(IFD.IMAGE_WIDTH, newImageWidth);
newIFD.put(IFD.IMAGE_LENGTH, newImageLength);
newIFD.put(IFD.TILE_WIDTH, newTileWidth);
newIFD.put(IFD.TILE_LENGTH, newTileLength);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Added JPEG 2000 sub-resolution IFD Level %d %dx%d " + "Tile %dx%d", resolutionLevel, newImageWidth, newImageLength, newTileWidth, newTileLength));
}
theseSubResolutionIFDs.add(newIFD);
}
}
} else {
LOGGER.warn("IFD has no strip offsets!");
}
}
}
IFD firstIFD = ifds.get(0);
PhotoInterp photo = firstIFD.getPhotometricInterpretation();
int samples = firstIFD.getSamplesPerPixel();
ms0.rgb = samples > 1 || photo == PhotoInterp.RGB;
ms0.interleaved = false;
ms0.littleEndian = firstIFD.isLittleEndian();
ms0.sizeX = (int) firstIFD.getImageWidth();
ms0.sizeY = (int) firstIFD.getImageLength();
ms0.sizeZ = 1;
ms0.sizeC = isRGB() ? samples : 1;
ms0.sizeT = ifds.size();
ms0.pixelType = firstIFD.getPixelType();
ms0.metadataComplete = true;
ms0.indexed = photo == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
if (isIndexed()) {
ms0.sizeC = 1;
ms0.rgb = false;
for (IFD ifd : ifds) {
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION, PhotoInterp.RGB_PALETTE);
}
}
if (getSizeC() == 1 && !isIndexed())
ms0.rgb = false;
ms0.dimensionOrder = "XYCZT";
ms0.bitsPerPixel = firstIFD.getBitsPerSample()[0];
// New core metadata now that we know how many sub-resolutions we have.
if (resolutionLevels != null && subResolutionIFDs.size() > 0) {
IFDList ifds = subResolutionIFDs.get(0);
int seriesCount = ifds.size() + 1;
if (!hasFlattenedResolutions()) {
ms0.resolutionCount = seriesCount;
}
ms0.sizeT = subResolutionIFDs.size();
ms0.imageCount = ms0.sizeT;
if (ms0.sizeT <= 0) {
ms0.sizeT = 1;
}
if (ms0.imageCount <= 0) {
ms0.imageCount = 1;
}
for (IFD ifd : ifds) {
CoreMetadata ms = new CoreMetadata(this, 0);
core.add(ms);
ms.sizeX = (int) ifd.getImageWidth();
ms.sizeY = (int) ifd.getImageLength();
ms.sizeT = ms0.sizeT;
ms.imageCount = ms0.imageCount;
ms.thumbnail = true;
ms.resolutionCount = 1;
}
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.
the class BaseTiffReader method initStandardMetadata.
/**
* Parses standard metadata.
*
* NOTE: Absolutely <b>no</b> calls to the metadata store should be made in
* this method or methods that override this method. Data <b>will</b> be
* overwritten if you do so.
*/
protected void initStandardMetadata() throws FormatException, IOException {
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
for (int i = 0; i < ifds.size(); i++) {
put("PageName #" + i, ifds.get(i), IFD.PAGE_NAME);
}
IFD firstIFD = ifds.get(0);
put("ImageWidth", firstIFD, IFD.IMAGE_WIDTH);
put("ImageLength", firstIFD, IFD.IMAGE_LENGTH);
put("BitsPerSample", firstIFD, IFD.BITS_PER_SAMPLE);
if (ifds.get(0).containsKey(IFD.EXIF)) {
IFDList exifIFDs = tiffParser.getExifIFDs();
if (exifIFDs.size() > 0) {
IFD exif = exifIFDs.get(0);
tiffParser.fillInIFD(exif);
for (Integer key : exif.keySet()) {
int k = key.intValue();
addGlobalMeta(getExifTagName(k), exif.get(key));
}
}
}
TiffCompression comp = firstIFD.getCompression();
put("Compression", comp.getCodecName());
PhotoInterp photo = firstIFD.getPhotometricInterpretation();
String photoInterp = photo.getName();
String metaDataPhotoInterp = photo.getMetadataType();
put("PhotometricInterpretation", photoInterp);
put("MetaDataPhotometricInterpretation", metaDataPhotoInterp);
putInt("CellWidth", firstIFD, IFD.CELL_WIDTH);
putInt("CellLength", firstIFD, IFD.CELL_LENGTH);
int or = firstIFD.getIFDIntValue(IFD.ORIENTATION);
// adjust the width and height if necessary
if (or == 8) {
put("ImageWidth", firstIFD, IFD.IMAGE_LENGTH);
put("ImageLength", firstIFD, IFD.IMAGE_WIDTH);
}
String orientation = null;
// there is no case 0
switch(or) {
case 1:
orientation = "1st row -> top; 1st column -> left";
break;
case 2:
orientation = "1st row -> top; 1st column -> right";
break;
case 3:
orientation = "1st row -> bottom; 1st column -> right";
break;
case 4:
orientation = "1st row -> bottom; 1st column -> left";
break;
case 5:
orientation = "1st row -> left; 1st column -> top";
break;
case 6:
orientation = "1st row -> right; 1st column -> top";
break;
case 7:
orientation = "1st row -> right; 1st column -> bottom";
break;
case 8:
orientation = "1st row -> left; 1st column -> bottom";
break;
}
put("Orientation", orientation);
putInt("SamplesPerPixel", firstIFD, IFD.SAMPLES_PER_PIXEL);
put("Software", firstIFD, IFD.SOFTWARE);
put("Instrument Make", firstIFD, IFD.MAKE);
put("Instrument Model", firstIFD, IFD.MODEL);
put("Document Name", firstIFD, IFD.DOCUMENT_NAME);
put("DateTime", getImageCreationDate());
put("Artist", firstIFD, IFD.ARTIST);
put("HostComputer", firstIFD, IFD.HOST_COMPUTER);
put("Copyright", firstIFD, IFD.COPYRIGHT);
put("NewSubfileType", firstIFD, IFD.NEW_SUBFILE_TYPE);
int thresh = firstIFD.getIFDIntValue(IFD.THRESHHOLDING);
String threshholding = null;
switch(thresh) {
case 1:
threshholding = "No dithering or halftoning";
break;
case 2:
threshholding = "Ordered dithering or halftoning";
break;
case 3:
threshholding = "Randomized error diffusion";
break;
}
put("Threshholding", threshholding);
int fill = firstIFD.getIFDIntValue(IFD.FILL_ORDER);
String fillOrder = null;
switch(fill) {
case 1:
fillOrder = "Pixels with lower column values are stored " + "in the higher order bits of a byte";
break;
case 2:
fillOrder = "Pixels with lower column values are stored " + "in the lower order bits of a byte";
break;
}
put("FillOrder", fillOrder);
putInt("Make", firstIFD, IFD.MAKE);
putInt("Model", firstIFD, IFD.MODEL);
putInt("MinSampleValue", firstIFD, IFD.MIN_SAMPLE_VALUE);
putInt("MaxSampleValue", firstIFD, IFD.MAX_SAMPLE_VALUE);
TiffRational xResolution = firstIFD.getIFDRationalValue(IFD.X_RESOLUTION);
TiffRational yResolution = firstIFD.getIFDRationalValue(IFD.Y_RESOLUTION);
if (xResolution != null) {
put("XResolution", xResolution.doubleValue());
}
if (yResolution != null) {
put("YResolution", yResolution.doubleValue());
}
int planar = firstIFD.getIFDIntValue(IFD.PLANAR_CONFIGURATION);
String planarConfig = null;
switch(planar) {
case 1:
planarConfig = "Chunky";
break;
case 2:
planarConfig = "Planar";
break;
}
put("PlanarConfiguration", planarConfig);
putInt("XPosition", firstIFD, IFD.X_POSITION);
putInt("YPosition", firstIFD, IFD.Y_POSITION);
putInt("FreeOffsets", firstIFD, IFD.FREE_OFFSETS);
putInt("FreeByteCounts", firstIFD, IFD.FREE_BYTE_COUNTS);
putInt("GrayResponseUnit", firstIFD, IFD.GRAY_RESPONSE_UNIT);
putInt("GrayResponseCurve", firstIFD, IFD.GRAY_RESPONSE_CURVE);
putInt("T4Options", firstIFD, IFD.T4_OPTIONS);
putInt("T6Options", firstIFD, IFD.T6_OPTIONS);
int res = firstIFD.getIFDIntValue(IFD.RESOLUTION_UNIT);
String resUnit = null;
switch(res) {
case 1:
resUnit = "None";
break;
case 2:
resUnit = "Inch";
break;
case 3:
resUnit = "Centimeter";
break;
}
put("ResolutionUnit", resUnit);
putString("PageNumber", firstIFD, IFD.PAGE_NUMBER);
putInt("TransferFunction", firstIFD, IFD.TRANSFER_FUNCTION);
int predict = firstIFD.getIFDIntValue(IFD.PREDICTOR);
String predictor = null;
switch(predict) {
case 1:
predictor = "No prediction scheme";
break;
case 2:
predictor = "Horizontal differencing";
break;
}
put("Predictor", predictor);
putInt("WhitePoint", firstIFD, IFD.WHITE_POINT);
putInt("PrimaryChromacities", firstIFD, IFD.PRIMARY_CHROMATICITIES);
putInt("HalftoneHints", firstIFD, IFD.HALFTONE_HINTS);
putInt("TileWidth", firstIFD, IFD.TILE_WIDTH);
putInt("TileLength", firstIFD, IFD.TILE_LENGTH);
putInt("TileOffsets", firstIFD, IFD.TILE_OFFSETS);
putInt("TileByteCounts", firstIFD, IFD.TILE_BYTE_COUNTS);
int ink = firstIFD.getIFDIntValue(IFD.INK_SET);
String inkSet = null;
switch(ink) {
case 1:
inkSet = "CMYK";
break;
case 2:
inkSet = "Other";
break;
}
put("InkSet", inkSet);
putInt("InkNames", firstIFD, IFD.INK_NAMES);
putInt("NumberOfInks", firstIFD, IFD.NUMBER_OF_INKS);
putInt("DotRange", firstIFD, IFD.DOT_RANGE);
put("TargetPrinter", firstIFD, IFD.TARGET_PRINTER);
putInt("ExtraSamples", firstIFD, IFD.EXTRA_SAMPLES);
int fmt = firstIFD.getIFDIntValue(IFD.SAMPLE_FORMAT);
String sampleFormat = null;
switch(fmt) {
case 1:
sampleFormat = "unsigned integer";
break;
case 2:
sampleFormat = "two's complement signed integer";
break;
case 3:
sampleFormat = "IEEE floating point";
break;
case 4:
sampleFormat = "undefined";
break;
}
put("SampleFormat", sampleFormat);
putInt("SMinSampleValue", firstIFD, IFD.S_MIN_SAMPLE_VALUE);
putInt("SMaxSampleValue", firstIFD, IFD.S_MAX_SAMPLE_VALUE);
putInt("TransferRange", firstIFD, IFD.TRANSFER_RANGE);
int jpeg = firstIFD.getIFDIntValue(IFD.JPEG_PROC);
String jpegProc = null;
switch(jpeg) {
case 1:
jpegProc = "baseline sequential process";
break;
case 14:
jpegProc = "lossless process with Huffman coding";
break;
}
put("JPEGProc", jpegProc);
putInt("JPEGInterchangeFormat", firstIFD, IFD.JPEG_INTERCHANGE_FORMAT);
putInt("JPEGRestartInterval", firstIFD, IFD.JPEG_RESTART_INTERVAL);
putInt("JPEGLosslessPredictors", firstIFD, IFD.JPEG_LOSSLESS_PREDICTORS);
putInt("JPEGPointTransforms", firstIFD, IFD.JPEG_POINT_TRANSFORMS);
putInt("JPEGQTables", firstIFD, IFD.JPEG_Q_TABLES);
putInt("JPEGDCTables", firstIFD, IFD.JPEG_DC_TABLES);
putInt("JPEGACTables", firstIFD, IFD.JPEG_AC_TABLES);
putInt("YCbCrCoefficients", firstIFD, IFD.Y_CB_CR_COEFFICIENTS);
int ycbcr = firstIFD.getIFDIntValue(IFD.Y_CB_CR_SUB_SAMPLING);
String subSampling = null;
switch(ycbcr) {
case 1:
subSampling = "chroma image dimensions = luma image dimensions";
break;
case 2:
subSampling = "chroma image dimensions are " + "half the luma image dimensions";
break;
case 4:
subSampling = "chroma image dimensions are " + "1/4 the luma image dimensions";
break;
}
put("YCbCrSubSampling", subSampling);
putInt("YCbCrPositioning", firstIFD, IFD.Y_CB_CR_POSITIONING);
putInt("ReferenceBlackWhite", firstIFD, IFD.REFERENCE_BLACK_WHITE);
// bits per sample and number of channels
int[] q = firstIFD.getBitsPerSample();
int bps = q[0];
int numC = q.length;
if (photo == PhotoInterp.RGB_PALETTE || photo == PhotoInterp.CFA_ARRAY) {
numC = 3;
}
put("BitsPerSample", bps);
put("NumberOfChannels", numC);
}
Aggregations