ReadScanline() public method

Reads and decodes a scanline of data from an open TIFF file/stream.

ReadScanline reads the data for the specified row into the user supplied data buffer buffer. The data are returned decompressed and, in the native byte- and bit-ordering, but are otherwise packed (see further below). The buffer must be large enough to hold an entire scanline of data. Applications should call the ScanlineSize to find out the size (in bytes) of a scanline buffer. Applications should use ReadScanline(byte[], int, short) or ReadScanline(byte[], int, int, short) and specify correct sample plane if image data are organized in separate planes (TiffTag.PLANARCONFIG = PlanarConfig.SEPARATE).

The library attempts to hide bit- and byte-ordering differences between the image and the native machine by converting data to the native machine order. Bit reversal is done if the value of TiffTag.FILLORDER tag is opposite to the native machine bit order. 16- and 32-bit samples are automatically byte-swapped if the file was written with a byte order opposite to the native machine byte order.

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
示例#1
0
        /*
         * 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;
        }
示例#2
0
        /*
         * 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;
        }
示例#3
0
        /*
         * 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;
            }
        }
示例#4
0
        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;
        }
示例#5
0
        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;
        }
示例#6
0
 // 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;
 }