putIfNotNull(map, MD_Z, plane.getTheZ().toString());
final NonNegativeInteger c = plane.getTheC();
if (c != null) {
final int cidx = c.getValue().intValue();
if (pixels.sizeOfChannelList() > cidx) {
Channel channel = pixels.getChannel(cidx);
if (channel != null) {
putIfNotNull(map, MD_CHANNEL_NAME, channel.getName());
final PositiveInteger samplesPerPixel = channel.getSamplesPerPixel();
if (samplesPerPixel != null) {
final int nSamplesPerPixel = samplesPerPixel.getValue().intValue();
map.put(MD_COLOR_FORMAT, (nSamplesPerPixel == 1)?MD_MONOCHROME:MD_RGB);
}
}
}
}
} else {
if (pixels != null){
if (pixels.getSizeC().getValue().intValue() == 1) {
map.put(MD_COLOR_FORMAT, MD_MONOCHROME);
Channel channel = pixels.getChannel(0);
if (channel != null) {
putIfNotNull(map, MD_CHANNEL_NAME, channel.getName());
}
} else if (pixels.sizeOfChannelList() == 1) {
map.put(MD_COLOR_FORMAT, MD_RGB);
} else {
map.put(MD_COLOR_FORMAT, MD_MONOCHROME);
Channel channel = pixels.getChannel(source.theC());
if (channel != null) {
putIfNotNull(map, MD_CHANNEL_NAME, channel.getName());
}
}
} else {
/*
* Use the channel within the plane to guess at the format.