Exemplo n.º 1
0
        public static int TIFFReadScanline(TIFF tif, byte[] buf, uint row, ushort sample)
        {
            if (!TIFFCheckRead(tif, false))
            {
                return(-1);
            }

            bool e = TIFFSeek(tif, buf, row, sample);

            if (e)
            {
                // Decompress desired row into user buffer.
                e = tif.tif_decoderow(tif, buf, (int)tif.tif_scanlinesize, sample);

                // we are now poised at the beginning of the next row
                tif.tif_row = row + 1;

                if (e)
                {
                    tif.tif_postdecode(tif, buf, 0, (int)tif.tif_scanlinesize);
                }
            }

            return(e?1:-1);
        }
Exemplo n.º 2
0
        // Seek to a random row+sample in a file.
        static bool TIFFSeek(TIFF tif, byte[] buf, uint row, ushort sample)
        {
            TIFFDirectory td=tif.tif_dir;

            if(row>=td.td_imagelength)
            {	// out of range
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Row out of range, max {1}", row, td.td_imagelength);
                return false;
            }

            uint strip;
            if(td.td_planarconfig==PLANARCONFIG.SEPARATE)
            {
                if(sample>=td.td_samplesperpixel)
                {
                    TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Sample out of range, max {1}", sample, td.td_samplesperpixel);
                    return false;
                }
                strip=sample*td.td_stripsperimage+row/td.td_rowsperstrip;
            }
            else strip=row/td.td_rowsperstrip;

            if(strip!=tif.tif_curstrip)
            {	// different strip, refill
                if(!TIFFFillStrip(tif, strip)) return false;
            }
            else if(row<tif.tif_row)
            {
                // Moving backwards within the same strip: backup
                // to the start and then decode forward (below).
                //
                // NB: If you're planning on lots of random access within a
                // strip, it's better to just read and decode the entire
                // strip, and then access the decoded data in a random fashion.
                if(!TIFFStartStrip(tif, strip)) return false;
            }

            if(row!=tif.tif_row)
            {
                // Seek forward to the desired row.
                if(!tif.tif_seek(tif, row-tif.tif_row))
                {
                    // if not directly seeked to, then the slow way... line by line
                    for(; tif.tif_row<row; tif.tif_row++)
                        tif.tif_decoderow(tif, buf, (int)tif.tif_scanlinesize, sample);
                }
                tif.tif_row=row;
            }

            return true;
        }
Exemplo n.º 3
0
        public static int TIFFReadScanline(TIFF tif, byte[] buf, uint row, ushort sample)
        {
            if(!TIFFCheckRead(tif, false)) return -1;

            bool e=TIFFSeek(tif, buf, row, sample);

            if(e)
            {
                // Decompress desired row into user buffer.
                e=tif.tif_decoderow(tif, buf, (int)tif.tif_scanlinesize, sample);

                // we are now poised at the beginning of the next row
                tif.tif_row=row+1;

                if(e) tif.tif_postdecode(tif, buf, 0, (int)tif.tif_scanlinesize);
            }

            return e?1:-1;
        }
Exemplo n.º 4
0
        const uint NOTILE  = 0xffffffff;        // undefined state

        // Seek to a random row+sample in a file.
        static bool TIFFSeek(TIFF tif, byte[] buf, uint row, ushort sample)
        {
            TIFFDirectory td = tif.tif_dir;

            if (row >= td.td_imagelength)
            {                   // out of range
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Row out of range, max {1}", row, td.td_imagelength);
                return(false);
            }

            uint strip;

            if (td.td_planarconfig == PLANARCONFIG.SEPARATE)
            {
                if (sample >= td.td_samplesperpixel)
                {
                    TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Sample out of range, max {1}", sample, td.td_samplesperpixel);
                    return(false);
                }
                strip = sample * td.td_stripsperimage + row / td.td_rowsperstrip;
            }
            else
            {
                strip = row / td.td_rowsperstrip;
            }

            if (strip != tif.tif_curstrip)
            {                   // different strip, refill
                if (!TIFFFillStrip(tif, strip))
                {
                    return(false);
                }
            }
            else if (row < tif.tif_row)
            {
                // Moving backwards within the same strip: backup
                // to the start and then decode forward (below).
                //
                // NB: If you're planning on lots of random access within a
                // strip, it's better to just read and decode the entire
                // strip, and then access the decoded data in a random fashion.
                if (!TIFFStartStrip(tif, strip))
                {
                    return(false);
                }
            }

            if (row != tif.tif_row)
            {
                // Seek forward to the desired row.
                if (!tif.tif_seek(tif, row - tif.tif_row))
                {
                    // if not directly seeked to, then the slow way... line by line
                    for (; tif.tif_row < row; tif.tif_row++)
                    {
                        tif.tif_decoderow(tif, buf, (int)tif.tif_scanlinesize, sample);
                    }
                }
                tif.tif_row = row;
            }

            return(true);
        }