public ReadScanline ( byte buffer, int row ) : bool | ||
buffer | byte | The buffer to place read and decoded image data to. |
row | int | The zero-based index of scanline (row) to read. |
return | bool |
/* * Separate -> contig by row. */ bool cpSeparate2ContigByRow(Tiff inImage, Tiff outImage, int imagelength, int imagewidth, short spp) { byte[] inbuf = new byte[inImage.ScanlineSize()]; byte[] outbuf = new byte[outImage.ScanlineSize()]; for (int row = 0; row < imagelength; row++) { /* merge channels */ for (short s = 0; s < spp; s++) { if (!inImage.ReadScanline(inbuf, row, s) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row); return false; } int inp = 0; int outp = s; for (int n = imagewidth; n-- > 0; ) { outbuf[outp] = inbuf[inp]; inp++; outp += spp; } } if (!outImage.WriteScanline(outbuf, row, 0)) { Tiff.Error(outImage.FileName(), "Error, can't write scanline {0}", row); return false; } } return true; }
/* * Separate -> separate by row for rows/strip change. */ bool cpSeparate2SeparateByRow(Tiff inImage, Tiff outImage, int imagelength, int imagewidth, short spp) { byte[] buf = new byte[inImage.ScanlineSize()]; for (short s = 0; s < spp; s++) { for (int row = 0; row < imagelength; row++) { if (!inImage.ReadScanline(buf, row, s) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row); return false; } if (!outImage.WriteScanline(buf, row, s)) { Tiff.Error(outImage.FileName(), "Error, can't write scanline {0}", row); return false; } } } return true; }
/* * Contig -> contig by scanline while subtracting a bias image. */ bool cpBiasedContig2Contig(Tiff inImage, Tiff outImage, int imagelength, int imagewidth, short spp) { if (spp == 1) { int biasSize = m_bias.ScanlineSize(); int bufSize = inImage.ScanlineSize(); FieldValue[] result = m_bias.GetField(TiffTag.IMAGEWIDTH); int biasWidth = result[0].ToInt(); result = m_bias.GetField(TiffTag.IMAGELENGTH); int biasLength = result[0].ToInt(); if (biasSize == bufSize && imagelength == biasLength && imagewidth == biasWidth) { result = inImage.GetField(TiffTag.BITSPERSAMPLE); short sampleBits = result[0].ToShort(); if (sampleBits == 8 || sampleBits == 16 || sampleBits == 32) { byte[] buf = new byte[bufSize]; byte[] biasBuf = new byte[bufSize]; for (int row = 0; row < imagelength; row++) { if (!inImage.ReadScanline(buf, row, 0) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row); return false; } if (!m_bias.ReadScanline(biasBuf, row, 0) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read biased scanline {0}", row); return false; } if (sampleBits == 8) subtract8(buf, biasBuf, imagewidth); else if (sampleBits == 16) subtract16(buf, biasBuf, imagewidth); else if (sampleBits == 32) subtract32(buf, biasBuf, imagewidth); if (!outImage.WriteScanline(buf, row, 0)) { Tiff.Error(outImage.FileName(), "Error, can't write scanline {0}", row); return false; } } m_bias.SetDirectory(m_bias.CurrentDirectory()); /* rewind */ return true; } else { Tiff.Error(inImage.FileName(), "No support for biasing {0} bit pixels\n", sampleBits); return false; } } Tiff.Error(inImage.FileName(), "Bias image {0},{1}\nis not the same size as {2},{3}\n", m_bias.FileName(), m_bias.CurrentDirectory(), inImage.FileName(), inImage.CurrentDirectory()); return false; } else { Tiff.Error(inImage.FileName(), "Can't bias {0},{1} as it has >1 Sample/Pixel\n", inImage.FileName(), inImage.CurrentDirectory()); return false; } }
bool readSeparateStripsIntoBuffer(Tiff inImage, byte[] buf, int imagelength, int imagewidth, short spp) { int scanlinesize = inImage.ScanlineSize(); if (scanlinesize == 0) return false; byte[] scanline = new byte[scanlinesize]; int bufp = 0; for (int row = 0; row < imagelength; row++) { /* merge channels */ for (short s = 0; s < spp; s++) { if (!inImage.ReadScanline(scanline, row, s) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row); return false; } int n = scanlinesize; int bp = s; int sbuf = 0; while (n-- > 0) { buf[bufp + bp] = scanline[sbuf]; sbuf++; bp += spp; } } bufp += scanlinesize * spp; } return true; }
bool readContigStripsIntoBuffer(Tiff inImage, byte[] buffer, int imagelength, int imagewidth, short spp) { int scanlinesize = inImage.ScanlineSize(); int offset = 0; for (int row = 0; row < imagelength; row++) { if (!inImage.ReadScanline(buffer, offset, row, 0) && !m_ignore) { Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row); return false; } offset += scanlinesize; } return true; }
// convert tiff image to 2d byte array public static byte[,] Tiff2Array(Tiff image, int height, int width) { // store the image information in 2d byte array // reserve memory for storing the size of 1 line byte[] scanline = new byte[image.ScanlineSize()]; // reserve memory for the size of image byte[,] im = new byte[height, width]; for (int i = 0; i < height; i++) { image.ReadScanline(scanline, i); { for (int j = 0; j < width; j++) im[i, j] = scanline[j]; } } // end grabbing intensity values return im; }