当前位置: 首页>>代码示例>>C#>>正文


C# TIFF.tif_cleanup方法代码示例

本文整理汇总了C#中Free.Ports.LibTiff.TIFF.tif_cleanup方法的典型用法代码示例。如果您正苦于以下问题:C# TIFF.tif_cleanup方法的具体用法?C# TIFF.tif_cleanup怎么用?C# TIFF.tif_cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Free.Ports.LibTiff.TIFF的用法示例。


在下文中一共展示了TIFF.tif_cleanup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TIFFReadDirectory

        // Read the next TIFF directory from a file
        // and convert it to the internal format.
        // We read directories sequentially.
        public static bool TIFFReadDirectory(TIFF tif)
        {
            string module="TIFFReadDirectory";

            ushort iv;
            uint v;
            TIFFFieldInfo fip;
            bool diroutoforderwarning=false;
            bool haveunknowntags=false;

            tif.tif_diroff=tif.tif_nextdiroff;
            // Check whether we have the last offset or bad offset (IFD looping).
            if(!TIFFCheckDirOffset(tif, tif.tif_nextdiroff)) return false;

            // Cleanup any previous compression state.
            tif.tif_cleanup(tif);
            tif.tif_curdir++;

            List<TIFFDirEntry> dir=null;
            ushort dircount=TIFFFetchDirectory(tif, tif.tif_nextdiroff, ref dir, ref tif.tif_nextdiroff);
            if(dircount==0)
            {
                TIFFErrorExt(tif.tif_clientdata, module, "{0}: Failed to read directory at offset{1}", tif.tif_name, tif.tif_nextdiroff);
                return false;
            }

            tif.tif_flags&=~TIF_FLAGS.TIFF_BEENWRITING; // reset before new dir

            // Setup default value and then make a pass over
            // the fields to check type and tag information,
            // and to extract info required to size data
            // structures. A second pass is made afterwards
            // to read in everthing not taken in the first pass.
            TIFFDirectory td=tif.tif_dir;

            // free any old stuff and reinit
            TIFFFreeDirectory(tif);
            TIFFDefaultDirectory(tif);

            // Electronic Arts writes gray-scale TIFF files
            // without a PlanarConfiguration directory entry.
            // Thus we setup a default value here, even though
            // the TIFF spec says there is no default value.
            TIFFSetField(tif, TIFFTAG.PLANARCONFIG, PLANARCONFIG.CONTIG);

            // Sigh, we must make a separate pass through the
            // directory for the following reason:
            //
            // We must process the Compression tag in the first pass
            // in order to merge in codec-private tag definitions (otherwise
            // we may get complaints about unknown tags). However, the
            // Compression tag may be dependent on the SamplesPerPixel
            // tag value because older TIFF specs permited Compression
            // to be written as a SamplesPerPixel-count tag entry.
            // Thus if we don't first figure out the correct SamplesPerPixel
            // tag value then we may end up ignoring the Compression tag
            // value because it has an incorrect count value (if the
            // true value of SamplesPerPixel is not 1).
            //
            // It sure would have been nice if Aldus had really thought
            // this stuff through carefully.
            foreach(TIFFDirEntry dp in dir)
            {
                if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0)
                {
                    TIFFSwab(ref dp.tdir_tag);
                    TIFFSwab(ref dp.tdir_type);
                    TIFFSwab(ref dp.tdir_count);
                    TIFFSwab(ref dp.tdir_offset);
                }

                if((TIFFTAG)dp.tdir_tag==TIFFTAG.SAMPLESPERPIXEL)
                {
                    if(!TIFFFetchNormalTag(tif, dp)) return false;
                    dp.tdir_tag=IGNORE;
                }
            }

            // First real pass over the directory.
            int fix=0;
            foreach(TIFFDirEntry dp in dir)
            {
                if(dp.tdir_tag==IGNORE) continue;
                if(fix>=tif.tif_fieldinfo.Count) fix=0;

                // Silicon Beach (at least) writes unordered
                // directory tags (violating the spec). Handle
                // it here, but be obnoxious (maybe they'll fix it?).
                if(dp.tdir_tag<(ushort)tif.tif_fieldinfo[fix].field_tag)
                {
                    if(!diroutoforderwarning)
                    {
                        TIFFWarningExt(tif.tif_clientdata, module, "{0}: invalid TIFF directory; tags are not sorted in ascending order", tif.tif_name);
                        diroutoforderwarning=true;
                    }
                    fix=0; // O(n^2)
                }
//.........这里部分代码省略.........
开发者ID:JoshDullen,项目名称:libtiffN,代码行数:101,代码来源:tif_dirread.cs

示例2: TIFFUnlinkDirectory

        // Unlink the specified directory from the directory chain.
        public static bool TIFFUnlinkDirectory(TIFF tif, ushort dirn)
        {
            string module="TIFFUnlinkDirectory";

            if(tif.tif_mode==O.RDONLY)
            {
                TIFFErrorExt(tif.tif_clientdata, module, "Can not unlink directory in read-only file");
                return false;
            }

            // Go to the directory before the one we want
            // to unlink and nab the offset of the link
            // field we'll need to patch.
            uint nextdir=tif.tif_header.tiff_diroff;
            uint off=4;
            uint n;
            for(n=dirn-1u; n>0; n--)
            {
                if(nextdir==0)
                {
                    TIFFErrorExt(tif.tif_clientdata, module, "Directory {0} does not exist", dirn);
                    return false;
                }

                if(!TIFFAdvanceDirectory(tif, ref nextdir, out off)) return false;
            }

            // Advance to the directory to be unlinked and fetch
            // the offset of the directory that follows.
            uint @null;
            if(!TIFFAdvanceDirectory(tif, ref nextdir, out @null)) return false;

            // Go back and patch the link field of the preceding
            // directory to point to the offset of the directory
            // that follows.
            TIFFSeekFile(tif, off, SEEK.SET);

            if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0) TIFFSwab(ref nextdir);

            if(!WriteOK(tif, nextdir))
            {
                TIFFErrorExt(tif.tif_clientdata, module, "Error writing directory link");
                return false;
            }

            // Leave directory state setup safely. We don't have
            // facilities for doing inserting and removing directories,
            // so it's safest to just invalidate everything. This
            // means that the caller can only append to the directory
            // chain.
            tif.tif_cleanup(tif);
            if((tif.tif_flags&TIF_FLAGS.TIFF_MYBUFFER)!=0&&tif.tif_rawdata!=null)
            {
                tif.tif_rawdata=null;
                tif.tif_rawcc=0;
            }

            tif.tif_flags&=~(TIF_FLAGS.TIFF_BEENWRITING|TIF_FLAGS.TIFF_BUFFERSETUP|TIF_FLAGS.TIFF_POSTENCODE);
            TIFFFreeDirectory(tif);
            TIFFDefaultDirectory(tif);
            tif.tif_diroff=0;			// force link on next write
            tif.tif_nextdiroff=0;		// next write must be at end
            tif.tif_curoff=0;
            tif.tif_row=0xffffffff;
            tif.tif_curstrip=0xffffffff;
            return true;
        }
开发者ID:JoshDullen,项目名称:libtiffN,代码行数:68,代码来源:tif_dir.cs

示例3: _TIFFVSetField

        static bool _TIFFVSetField(TIFF tif, TIFFTAG tag, TIFFDataType dt, object[] ap)
        {
            string module="_TIFFVSetField";

            TIFFDirectory td=tif.tif_dir;
            bool status=true;
            uint v;

            switch(tag)
            {
                case TIFFTAG.SUBFILETYPE:
                    td.td_subfiletype=(FILETYPE)__GetAsUint(ap, 0);
                    break;
                case TIFFTAG.IMAGEWIDTH:
                    td.td_imagewidth=__GetAsUint(ap, 0);
                    break;
                case TIFFTAG.IMAGELENGTH:
                    td.td_imagelength=__GetAsUint(ap, 0);
                    break;
                case TIFFTAG.BITSPERSAMPLE:
                    td.td_bitspersample=__GetAsUshort(ap, 0);

                    // If the data require post-decoding processing to byte-swap
                    // samples, set it up here. Note that since tags are required
                    // to be ordered, compression code can override this behaviour
                    // in the setup method if it wants to roll the post decoding
                    // work in with its normal work.
                    if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0)
                    {
                        if(td.td_bitspersample==16) tif.tif_postdecode=TIFFSwab16BitData;
                        else if(td.td_bitspersample==24) tif.tif_postdecode=TIFFSwab24BitData;
                        else if(td.td_bitspersample==32) tif.tif_postdecode=TIFFSwab32BitData;
                        else if(td.td_bitspersample==64) tif.tif_postdecode=TIFFSwab64BitData;
                        else if(td.td_bitspersample==128) tif.tif_postdecode=TIFFSwab64BitData; // two 64's
                    }
                    break;
                case TIFFTAG.COMPRESSION:
                    v=__GetAsUint(ap, 0)&0xffff;

                    // If we're changing the compression scheme, the notify the
                    // previous module so that it can cleanup any state it's setup.
                    if(TIFFFieldSet(tif, FIELD.COMPRESSION))
                    {
                        if(td.td_compression==(COMPRESSION)v) break;
                        tif.tif_cleanup(tif);
                        tif.tif_flags&=~TIF_FLAGS.TIFF_CODERSETUP;
                    }

                    // Setup new compression routine state.
                    if(status=TIFFSetCompressionScheme(tif, (COMPRESSION)v)) td.td_compression=(COMPRESSION)v;
                    else status=false;
                    break;
                case TIFFTAG.PHOTOMETRIC:
                    td.td_photometric=(PHOTOMETRIC)__GetAsUshort(ap, 0);
                    break;
                case TIFFTAG.THRESHHOLDING:
                    td.td_threshholding=(THRESHHOLD)__GetAsUshort(ap, 0);
                    break;
                case TIFFTAG.FILLORDER:
                    v=__GetAsUint(ap, 0);
                    if((FILLORDER)v!=FILLORDER.LSB2MSB&&(FILLORDER)v!=FILLORDER.MSB2LSB) goto badvalue;
                    td.td_fillorder=(FILLORDER)v;
                    break;
                case TIFFTAG.ORIENTATION:
                    v=__GetAsUint(ap, 0);
                    if((ORIENTATION)v<ORIENTATION.TOPLEFT||ORIENTATION.LEFTBOT<(ORIENTATION)v)
                        goto badvalue;
                    td.td_orientation=(ORIENTATION)v;
                    break;
                case TIFFTAG.SAMPLESPERPIXEL:
                    // XXX should cross check -- e.g. if pallette, then 1
                    v=__GetAsUint(ap, 0);
                    if(v==0) goto badvalue;
                    td.td_samplesperpixel=(ushort)v;
                    break;
                case TIFFTAG.ROWSPERSTRIP:
                    v=__GetAsUint(ap, 0);
                    if(v==0) goto badvalue;
                    td.td_rowsperstrip=v;
                    if(!TIFFFieldSet(tif, FIELD.TILEDIMENSIONS))
                    {
                        td.td_tilelength=v;
                        td.td_tilewidth=td.td_imagewidth;
                    }
                    break;
                case TIFFTAG.MINSAMPLEVALUE:
                    td.td_minsamplevalue=__GetAsUshort(ap, 0);
                    break;
                case TIFFTAG.MAXSAMPLEVALUE:
                    td.td_maxsamplevalue=__GetAsUshort(ap, 0);
                    break;
                case TIFFTAG.SMINSAMPLEVALUE:
                    td.td_sminsamplevalue=__GetAsDouble(ap, 0);
                    break;
                case TIFFTAG.SMAXSAMPLEVALUE:
                    td.td_smaxsamplevalue=__GetAsDouble(ap, 0);
                    break;
                case TIFFTAG.XRESOLUTION:
                    td.td_xresolution=__GetAsDouble(ap, 0);
                    break;
//.........这里部分代码省略.........
开发者ID:JoshDullen,项目名称:libtiffN,代码行数:101,代码来源:tif_dir.cs

示例4: TIFFWriteDirectory


//.........这里部分代码省略.........
                        break;
                    case FIELD.INKNAMES:
                        if(!TIFFWriteInkNames(tif, dir)) return false;
                        break;
                    case FIELD.TRANSFERFUNCTION:
                        if(!TIFFWriteTransferFunction(tif, dir)) return false;
                        break;
                    case FIELD.SUBIFD:
                        // XXX: Always write this field using LONG type
                        // for backward compatibility.
                        dir.tdir_tag=(ushort)fip.field_tag;
                        dir.tdir_type=(ushort)TIFFDataType.TIFF_LONG;
                        dir.tdir_count=(uint)td.td_nsubifd;
                        if(!TIFFWriteLongArray(tif, dir, td.td_subifd)) return false;

                        // Total hack: if this directory includes a SubIFD
                        // tag then force the next <n> directories to be
                        // written as "sub directories" of this one. This
                        // is used to write things like thumbnails and
                        // image masks that one wants to keep out of the
                        // normal directory linkage access mechanism.
                        if(dir.tdir_count>0)
                        {
                            tif.tif_flags|=TIF_FLAGS.TIFF_INSUBIFD;
                            tif.tif_nsubifd=(ushort)dir.tdir_count;
                            if(dir.tdir_count>1) tif.tif_subifdoff=dir.tdir_offset;
                            //was else tif.tif_subifdoff=(uint)(tif.tif_diroff+2+((char*)&dir.tdir_offset-data));
                            else tif.tif_subifdoff=(uint)(tif.tif_diroff+2+12*dirsnumber-4);
                        }
                        break;
                    default:
                        // XXX: Should be fixed and removed.
                        if(fip.field_tag==TIFFTAG.DOTRANGE)
                        {
                            if(!TIFFSetupShortPair(tif, fip.field_tag, dir)) return false;
                        }
                        else if(!TIFFWriteNormalTag(tif, dir, fip)) return false;
                        break;
                }
                dirsnumber++;

                if(fip.field_bit!=FIELD.CUSTOM) ResetFieldBit(fields, fip.field_bit);
            }

            // Write directory.
            ushort dircount=(ushort)nfields;
            uint diroff=tif.tif_nextdiroff;
            if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0)
            {
                // The file's byte order is opposite to the
                // native machine architecture. We overwrite
                // the directory information with impunity
                // because it'll be released below after we
                // write it to the file. Note that all the
                // other tag construction routines assume that
                // we do this byte-swapping; i.e. they only
                // byte-swap indirect data.
                foreach(TIFFDirEntry dir in dirs)
                {
                    TIFFSwab(ref dir.tdir_tag);
                    TIFFSwab(ref dir.tdir_type);
                    TIFFSwab(ref dir.tdir_count);
                    TIFFSwab(ref dir.tdir_offset);
                }
                dircount=(ushort)nfields;
                TIFFSwab(ref dircount);
                TIFFSwab(ref diroff);
            }

            TIFFSeekFile(tif, tif.tif_diroff, SEEK.SET);
            if(!WriteOK(tif, dircount))
            {
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Error writing directory count");
                return false;
            }

            if(!WriteOK(tif, dirs, (ushort)dirsize))
            {
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Error writing directory contents");
                return false;
            }

            if(!WriteOK(tif, diroff))
            {
                TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Error writing directory link");
                return false;
            }

            if(done)
            {
                TIFFFreeDirectory(tif);
                tif.tif_flags&=~TIF_FLAGS.TIFF_DIRTYDIRECT;
                tif.tif_cleanup(tif);

                // Reset directory-related state for subsequent directories.
                TIFFCreateDirectory(tif);
            }

            return true;
        }
开发者ID:JoshDullen,项目名称:libtiffN,代码行数:101,代码来源:tif_dirwrite.cs


注:本文中的Free.Ports.LibTiff.TIFF.tif_cleanup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。