bool pickFuncAndCopy(Tiff inImage, Tiff outImage, short bitspersample, short samplesperpixel, int length, int width)
{
using (TextWriter stderr = Console.Error)
{
FieldValue[] result = inImage.GetField(TiffTag.PLANARCONFIG);
PlanarConfig shortv = (PlanarConfig)result[0].ToShort();
if (shortv != m_config && bitspersample != 8 && samplesperpixel > 1)
{
stderr.Write("{0}: Cannot handle different planar configuration w/ bits/sample != 8\n", inImage.FileName());
return false;
}
result = inImage.GetField(TiffTag.IMAGEWIDTH);
int w = result[0].ToInt();
result = inImage.GetField(TiffTag.IMAGELENGTH);
int l = result[0].ToInt();
bool bychunk;
if (!(outImage.IsTiled() || inImage.IsTiled()))
{
result = inImage.GetField(TiffTag.ROWSPERSTRIP);
if (result != null)
{
int irps = result[0].ToInt();
/* if biased, force decoded copying to allow image subtraction */
bychunk = (m_bias == null) && (m_rowsperstrip == irps);
}
else
bychunk = false;
}
else
{
/* either inImage or outImage is tiled */
if (m_bias != null)
{
stderr.Write("{0}: Cannot handle tiled configuration w/bias image\n", inImage.FileName());
return false;
}
if (outImage.IsTiled())
{
int tw;
result = inImage.GetField(TiffTag.TILEWIDTH);
if (result == null)
tw = w;
else
tw = result[0].ToInt();
int tl;
result = inImage.GetField(TiffTag.TILELENGTH);
if (result == null)
tl = l;
else
tl = result[0].ToInt();
bychunk = (tw == m_tilewidth && tl == m_tilelength);
}
else
{
/* outImage's not, so inImage must be tiled */
result = inImage.GetField(TiffTag.TILEWIDTH);
int tw = result[0].ToInt();
result = inImage.GetField(TiffTag.TILELENGTH);
int tl = result[0].ToInt();
bychunk = (tw == w && tl == m_rowsperstrip);
}
}
if (inImage.IsTiled())
{
if (outImage.IsTiled())
{
/* Tiles -> Tiles */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
return cpContigTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContigTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparateTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
return cpSeparateTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
}
else
{
/* Tiles -> Strips */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
return cpContigTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContigTiles2SeparateStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparateTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
return cpSeparateTiles2SeparateStrips(inImage, outImage, length, width, samplesperpixel);
}
}
else
{
if (outImage.IsTiled())
{
/* Strips -> Tiles */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
return cpContigStrips2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContigStrips2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparateStrips2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
return cpSeparateStrips2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
}
else
{
/* Strips -> Strips */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG && !bychunk)
{
if (m_bias != null)
return cpBiasedContig2Contig(inImage, outImage, length, width, samplesperpixel);
return cpContig2ContigByRow(inImage, outImage, length, width, samplesperpixel);
}
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG && bychunk)
return cpDecodedStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContig2SeparateByRow(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparate2ContigByRow(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
return cpSeparate2SeparateByRow(inImage, outImage, length, width, samplesperpixel);
}
}
stderr.Write("tiffcp: {0}: Don't know how to copy/convert image.\n", inImage.FileName());
}
return false;
}