public VStripSize ( int rowCount ) : int | ||
rowCount | int | The number of rows in a strip. |
return | int |
public int VStripSize(int rowCount)
{
if (rowCount == -1)
rowCount = m_dir.td_imagelength;
if (m_dir.td_planarconfig == PlanarConfig.CONTIG &&
m_dir.td_photometric == Photometric.YCBCR && !IsUpSampled())
{
// Packed YCbCr data contain one Cb+Cr for every
// HorizontalSampling * VerticalSampling Y values.
// Must also roundup width and height when calculating since images that are not
// a multiple of the horizontal/vertical subsampling area include YCbCr data for
// the extended image.
FieldValue[] result = GetFieldDefaulted(TiffTag.YCBCRSUBSAMPLING);
short ycbcrsubsampling0 = result[0].ToShort();
short ycbcrsubsampling1 = result[1].ToShort();
int samplingarea = ycbcrsubsampling0 * ycbcrsubsampling1;
if (samplingarea == 0)
{
ErrorExt(this, m_clientdata, m_name, "Invalid YCbCr subsampling");
return 0;
}
int w = roundUp(m_dir.td_imagewidth, ycbcrsubsampling0);
int scanline = howMany8(multiply(w, m_dir.td_bitspersample, "VStripSize"));
rowCount = roundUp(rowCount, ycbcrsubsampling1);
// NB: don't need howMany here 'cuz everything is rounded
scanline = multiply(rowCount, scanline, "VStripSize");
return summarize(scanline, multiply(2, scanline / samplingarea, "VStripSize"), "VStripSize");
}
return multiply(rowCount, ScanlineSize(), "VStripSize");
}
static bool writeBufferToSeparateStrips(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp) { byte[] obuf = new byte[outImage.StripSize()]; FieldValue[] result = outImage.GetFieldDefaulted(TiffTag.ROWSPERSTRIP); int rowsperstrip = result[0].ToInt(); int rowsize = imagewidth * spp; int strip = 0; for (short s = 0; s < spp; s++) { for (int row = 0; row < imagelength; row += rowsperstrip) { int nrows = (row + rowsperstrip > imagelength) ? imagelength - row : rowsperstrip; int stripsize = outImage.VStripSize(nrows); cpContigBufToSeparateBuf(obuf, buf, row * rowsize + s, nrows, imagewidth, 0, 0, spp, 1); if (outImage.WriteEncodedStrip(strip++, obuf, stripsize) < 0) { Tiff.Error(outImage.FileName(), "Error, can't write strip {0}", strip - 1); return false; } } } return true; }