Beispiel #1
0
        // Read a strip of data and decompress the specified
        // amount into the user-supplied buffer.
        public static int TIFFReadEncodedStrip(TIFF tif, int strip, byte[] buf, int size)
        {
            if (!TIFFCheckRead(tif, false))
            {
                return(-1);
            }

            TIFFDirectory td = tif.tif_dir;

            if (strip >= td.td_nstrips)
            {
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Strip out of range, max {1}", strip, td.td_nstrips);
                return(-1);
            }

            // Calculate the strip size according to the number of
            // rows in the strip (check for truncated last strip on any
            // of the separations).
            uint strips_per_sep;

            if (td.td_rowsperstrip >= td.td_imagelength)
            {
                strips_per_sep = 1;
            }
            else
            {
                strips_per_sep = (td.td_imagelength + td.td_rowsperstrip - 1) / td.td_rowsperstrip;
            }

            uint sep_strip = (uint)strip % strips_per_sep;

            uint nrows = td.td_imagelength % td.td_rowsperstrip;

            if (sep_strip != strips_per_sep - 1 || nrows == 0)
            {
                nrows = td.td_rowsperstrip;
            }

            int stripsize = TIFFVStripSize(tif, nrows);

            if (size == -1)
            {
                size = stripsize;
            }
            else if (size > stripsize)
            {
                size = stripsize;
            }

            if (TIFFFillStrip(tif, (uint)strip) && tif.tif_decodestrip(tif, buf, size, (ushort)(strip / td.td_stripsperimage)))
            {
                tif.tif_postdecode(tif, buf, 0, size);
                return(size);
            }

            return(-1);
        }
Beispiel #2
0
        // Read a strip of data and decompress the specified
        // amount into the user-supplied buffer.
        public static int TIFFReadEncodedStrip(TIFF tif, int strip, byte[] buf, int size)
        {
            if(!TIFFCheckRead(tif, false)) return -1;

            TIFFDirectory td=tif.tif_dir;

            if(strip>=td.td_nstrips)
            {
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Strip out of range, max {1}", strip, td.td_nstrips);
                return -1;
            }

            // Calculate the strip size according to the number of
            // rows in the strip (check for truncated last strip on any
            // of the separations).
            uint strips_per_sep;
            if(td.td_rowsperstrip>=td.td_imagelength) strips_per_sep=1;
            else strips_per_sep=(td.td_imagelength+td.td_rowsperstrip-1)/td.td_rowsperstrip;

            uint sep_strip=(uint)strip%strips_per_sep;

            uint nrows=td.td_imagelength%td.td_rowsperstrip;

            if(sep_strip!=strips_per_sep-1||nrows==0) nrows=td.td_rowsperstrip;

            int stripsize=TIFFVStripSize(tif, nrows);
            if(size==-1) size=stripsize;
            else if(size>stripsize) size=stripsize;

            if(TIFFFillStrip(tif, (uint)strip)&&tif.tif_decodestrip(tif, buf, size, (ushort)(strip/td.td_stripsperimage)))
            {
                tif.tif_postdecode(tif, buf, 0, size);
                return (size);
            }

            return -1;
        }