public bool RGBAImageOK(out string errorMsg)
{
errorMsg = null;
if (!m_decodestatus)
{
errorMsg = "Sorry, requested compression method is not configured";
return false;
}
switch (m_dir.td_bitspersample)
{
case 1:
case 2:
case 4:
case 8:
case 16:
break;
default:
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle images with {0}-bit samples", m_dir.td_bitspersample);
return false;
}
int colorchannels = m_dir.td_samplesperpixel - m_dir.td_extrasamples;
Photometric photometric = Photometric.RGB;
FieldValue[] result = GetField(TiffTag.PHOTOMETRIC);
if (result == null)
{
switch (colorchannels)
{
case 1:
photometric = Photometric.MINISBLACK;
break;
case 3:
photometric = Photometric.RGB;
break;
default:
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Missing needed {0} tag", TiffRgbaImage.photoTag);
return false;
}
}
else
{
// San Chen <[email protected]>
photometric = (Photometric)result[0].Value;
}
switch (photometric)
{
case Photometric.MINISWHITE:
case Photometric.MINISBLACK:
case Photometric.PALETTE:
if (m_dir.td_planarconfig == PlanarConfig.CONTIG &&
m_dir.td_samplesperpixel != 1 && m_dir.td_bitspersample < 8)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle contiguous data with {0}={1}, and {2}={3} and Bits/Sample={4}",
TiffRgbaImage.photoTag, photometric, "Samples/pixel", m_dir.td_samplesperpixel,
m_dir.td_bitspersample);
return false;
}
// We should likely validate that any extra samples are either to be ignored,
// or are alpha, and if alpha we should try to use them. But for now we won't
// bother with this.
break;
case Photometric.YCBCR:
// TODO: if at all meaningful and useful, make more complete support check
// here, or better still, refactor to let supporting code decide whether there
// is support and what meaningfull error to return
break;
case Photometric.RGB:
if (colorchannels < 3)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle RGB image with {0}={1}",
"Color channels", colorchannels);
return false;
}
break;
case Photometric.SEPARATED:
result = GetFieldDefaulted(TiffTag.INKSET);
InkSet inkset = (InkSet)result[0].ToByte();
if (inkset != InkSet.CMYK)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle separated image with {0}={1}", "InkSet", inkset);
return false;
}
if (m_dir.td_samplesperpixel < 4)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle separated image with {0}={1}",
"Samples/pixel", m_dir.td_samplesperpixel);
return false;
}
break;
case Photometric.LOGL:
if (m_dir.td_compression != Compression.SGILOG)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, LogL data must have {0}={1}",
"Compression", Compression.SGILOG);
return false;
}
break;
case Photometric.LOGLUV:
if (m_dir.td_compression != Compression.SGILOG &&
m_dir.td_compression != Compression.SGILOG24)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, LogLuv data must have {0}={1} or {2}",
"Compression", Compression.SGILOG, Compression.SGILOG24);
return false;
}
if (m_dir.td_planarconfig != PlanarConfig.CONTIG)
{
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle LogLuv images with {0}={1}",
"Planarconfiguration", m_dir.td_planarconfig);
return false;
}
break;
case Photometric.CIELAB:
break;
default:
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle image with {0}={1}",
TiffRgbaImage.photoTag, photometric);
return false;
}
return true;
}