public bool WriteCheck(bool tiles, string method)
{
if (m_mode == O_RDONLY)
{
ErrorExt(this, m_clientdata, method, "{0}: File not open for writing", m_name);
return false;
}
if (tiles ^ IsTiled())
{
ErrorExt(this, m_clientdata, m_name,
tiles ? "Can not write tiles to a stripped image" : "Can not write scanlines to a tiled image");
return false;
}
// On the first write verify all the required information has been setup and
// initialize any data structures that had to wait until directory information was set.
// Note that a lot of our work is assumed to remain valid because we disallow any of
// the important parameters from changing after we start writing (i.e. once
// BEENWRITING is set, SetField will only allow the image's length to be changed).
if (!fieldSet(FieldBit.ImageDimensions))
{
ErrorExt(this, m_clientdata, method, "{0}: Must set \"ImageWidth\" before writing data", m_name);
return false;
}
if (m_dir.td_samplesperpixel == 1)
{
// PlanarConfiguration is irrelevant in case of single band images and need not
// be included. We will set it anyway, because this field is used in other parts
// of library even in the single band case.
if (!fieldSet(FieldBit.PlanarConfig))
m_dir.td_planarconfig = PlanarConfig.CONTIG;
}
else
{
if (!fieldSet(FieldBit.PlanarConfig))
{
ErrorExt(this, m_clientdata, method,
"{0}: Must set \"PlanarConfiguration\" before writing data", m_name);
return false;
}
}
if (m_dir.td_stripoffset == null && !SetupStrips())
{
m_dir.td_nstrips = 0;
ErrorExt(this, m_clientdata, method,
"{0}: No space for {1} arrays", m_name, IsTiled() ? "tile" : "strip");
return false;
}
m_tilesize = IsTiled() ? TileSize() : -1;
m_scanlinesize = ScanlineSize();
m_flags |= TiffFlags.BEENWRITING;
return true;
}