LOGGER.info("Populating metadata");
/*
* The first IFD contains file-scope metadata
*/
final IFD ifd0 = tiffParser.getFirstIFD();
tiffParser.fillInIFD(ifd0);
final int channelCount = ifd0.getIFDIntValue(CHANNEL_COUNT_TAG);
final String channelNamesString = ifd0.getIFDStringValue(CHANNEL_NAMES_TAG);
channelNames = channelNamesString.split("\\|");
if (channelNames.length != channelCount) {
throw new FormatException(String.format(
"Channel count (%d) does not match number of channel names (%d) in string \"%s\"",
channelCount, channelNames.length, channelNamesString));
}
LOGGER.debug(String.format(
"Found %d channels: %s",
channelCount, channelNamesString.replace('|', ',')));
final String channelDescsString = ifd0.getIFDStringValue(CHANNEL_DESCS_TAG);
channelDescs = channelDescsString.split("\\|");
if (channelDescs.length != channelCount) {
throw new FormatException(String.format(
"Channel count (%d) does not match number of channel descriptions (%d) in string \"%s\"",
channelCount, channelDescs.length, channelDescsString));
}
/*
* Scan the remaining IFDs
*
* Unfortunately, each image can have a different width and height
* and the images and masks have a different bit depth, so in the
* OME scheme of things, we get one series per plane.
*/
for (int idxOff=1; idxOff<ifdOffsets.length;idxOff++) {
// TODO: Record the channel names
final long offset = ifdOffsets[idxOff];
final boolean first=(idxOff == 1);
final IFD ifd = tiffParser.getIFD(offset);
tiffParser.fillInIFD(ifd);
CoreMetadata ms = first?core.get(0):new CoreMetadata();
ms.rgb = false;
ms.interleaved = false;
ms.littleEndian = ifd0.isLittleEndian();
ms.sizeX = (int) ifd.getImageWidth() / channelCount;
ms.sizeY = (int) ifd.getImageLength();
ms.sizeZ = 1;
ms.sizeC = channelCount;
ms.sizeT = 1;
ms.indexed = false;
ms.dimensionOrder = "XYCZT";
ms.bitsPerPixel = ifd.getIFDIntValue(IFD.BITS_PER_SAMPLE);
ms.pixelType = (ms.bitsPerPixel == 8)?FormatTools.UINT8:FormatTools.UINT16;
ms.imageCount = channelCount;
ms.resolutionCount = 1;
ms.thumbnail = false;
ms.metadataComplete = true;