Esempio n. 1
0
        // Encode the supplied data and write it to the
        // specified strip.
        //
        // NB: Image length must be setup before writing.
        public static int TIFFWriteEncodedStrip(TIFF tif, uint strip, byte[] data, int cc)
        {
            string module="TIFFWriteEncodedStrip";
            TIFFDirectory td=tif.tif_dir;
            ushort sample;

            if(!((tif.tif_flags&TIF_FLAGS.TIFF_BEENWRITING)!=0||TIFFWriteCheck(tif, false, module))) return -1;

            // Check strip array to make sure there's space.
            // We don't support dynamically growing files that
            // have data organized in separate bitplanes because
            // it's too painful. In that case we require that
            // the imagelength be set properly before the first
            // write (so that the strips array will be fully
            // allocated above).
            ///
            if(strip>=td.td_nstrips)
            {
                if(td.td_planarconfig==PLANARCONFIG.SEPARATE)
                {
                    TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Can not grow image by strips when using separate planes");
                    return -1;
                }

                if(!TIFFGrowStrips(tif, 1, module)) return -1;
                td.td_stripsperimage=TIFFhowmany(td.td_imagelength, td.td_rowsperstrip);
            }

            // Handle delayed allocation of data buffer. This
            // permits it to be sized according to the directory
            // info.
            if(!BUFFERCHECK(tif)) return -1;

            tif.tif_curstrip=strip;
            tif.tif_row=(strip%td.td_stripsperimage)*td.td_rowsperstrip;
            if((tif.tif_flags&TIF_FLAGS.TIFF_CODERSETUP)==0)
            {
                if(!tif.tif_setupencode(tif)) return -1;
                tif.tif_flags|=TIF_FLAGS.TIFF_CODERSETUP;
            }

            tif.tif_rawcc=0;
            tif.tif_rawcp=0;

            if(td.td_stripbytecount[strip]>0)
            {
                // Force TIFFAppendToStrip() to consider placing data at end of file.
                tif.tif_curoff=0;
            }

            tif.tif_flags&=~TIF_FLAGS.TIFF_POSTENCODE;
            sample=(ushort)(strip/td.td_stripsperimage);
            if(!tif.tif_preencode(tif, sample)) return -1;

            // swab if needed - note that source buffer will be altered
            tif.tif_postdecode(tif, data, 0, cc);

            if(!tif.tif_encodestrip(tif, data, cc, sample)) return 0;
            if(!tif.tif_postencode(tif)) return -1;
            if(!isFillOrder(tif, td.td_fillorder)&&(tif.tif_flags&TIF_FLAGS.TIFF_NOBITREV)==0) TIFFReverseBits(tif.tif_rawdata, tif.tif_rawcc);
            if(tif.tif_rawcc>0&&!TIFFAppendToStrip(tif, strip, tif.tif_rawdata, tif.tif_rawcc)) return -1;

            tif.tif_rawcc=0;
            tif.tif_rawcp=0;

            return cc;
        }
Esempio n. 2
0
        // Encode the supplied data and write it to the
        // specified strip.
        //
        // NB: Image length must be setup before writing.
        public static int TIFFWriteEncodedStrip(TIFF tif, uint strip, byte[] data, int cc)
        {
            string        module = "TIFFWriteEncodedStrip";
            TIFFDirectory td     = tif.tif_dir;
            ushort        sample;

            if (!((tif.tif_flags & TIF_FLAGS.TIFF_BEENWRITING) != 0 || TIFFWriteCheck(tif, false, module)))
            {
                return(-1);
            }

            // Check strip array to make sure there's space.
            // We don't support dynamically growing files that
            // have data organized in separate bitplanes because
            // it's too painful. In that case we require that
            // the imagelength be set properly before the first
            // write (so that the strips array will be fully
            // allocated above).
            ///
            if (strip >= td.td_nstrips)
            {
                if (td.td_planarconfig == PLANARCONFIG.SEPARATE)
                {
                    TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Can not grow image by strips when using separate planes");
                    return(-1);
                }

                if (!TIFFGrowStrips(tif, 1, module))
                {
                    return(-1);
                }
                td.td_stripsperimage = TIFFhowmany(td.td_imagelength, td.td_rowsperstrip);
            }

            // Handle delayed allocation of data buffer. This
            // permits it to be sized according to the directory
            // info.
            if (!BUFFERCHECK(tif))
            {
                return(-1);
            }

            tif.tif_curstrip = strip;
            tif.tif_row      = (strip % td.td_stripsperimage) * td.td_rowsperstrip;
            if ((tif.tif_flags & TIF_FLAGS.TIFF_CODERSETUP) == 0)
            {
                if (!tif.tif_setupencode(tif))
                {
                    return(-1);
                }
                tif.tif_flags |= TIF_FLAGS.TIFF_CODERSETUP;
            }

            tif.tif_rawcc = 0;
            tif.tif_rawcp = 0;

            if (td.td_stripbytecount[strip] > 0)
            {
                // Force TIFFAppendToStrip() to consider placing data at end of file.
                tif.tif_curoff = 0;
            }

            tif.tif_flags &= ~TIF_FLAGS.TIFF_POSTENCODE;
            sample         = (ushort)(strip / td.td_stripsperimage);
            if (!tif.tif_preencode(tif, sample))
            {
                return(-1);
            }

            // swab if needed - note that source buffer will be altered
            tif.tif_postdecode(tif, data, 0, cc);

            if (!tif.tif_encodestrip(tif, data, cc, sample))
            {
                return(0);
            }
            if (!tif.tif_postencode(tif))
            {
                return(-1);
            }
            if (!isFillOrder(tif, td.td_fillorder) && (tif.tif_flags & TIF_FLAGS.TIFF_NOBITREV) == 0)
            {
                TIFFReverseBits(tif.tif_rawdata, tif.tif_rawcc);
            }
            if (tif.tif_rawcc > 0 && !TIFFAppendToStrip(tif, strip, tif.tif_rawdata, tif.tif_rawcc))
            {
                return(-1);
            }

            tif.tif_rawcc = 0;
            tif.tif_rawcp = 0;

            return(cc);
        }