本文整理汇总了C#中Free.Ports.LibTiff.TIFF类的典型用法代码示例。如果您正苦于以下问题:C# TIFF类的具体用法?C# TIFF怎么用?C# TIFF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TIFF类属于Free.Ports.LibTiff命名空间,在下文中一共展示了TIFF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: alloc_downsampled_buffers
// Allocate downsampled-data buffers needed for downsampled I/O.
// We use values computed in jpeg_start_compress or jpeg_start_decompress.
// We use libjpeg's allocator so that buffers will be released automatically
// when done with strip/tile.
// This is also a handy place to compute samplesperclump, bytesperline.
static bool alloc_downsampled_buffers(TIFF tif, jpeg_component_info[] comp_info, int num_components)
{
JPEGState sp=tif.tif_data as JPEGState;
byte[][] buf;
int samples_per_clump=0;
for(int ci=0; ci<num_components; ci++)
{
jpeg_component_info compptr=comp_info[ci];
samples_per_clump+=compptr.h_samp_factor*compptr.v_samp_factor;
try
{
buf=TIFFjpeg_alloc_sarray(sp, compptr.width_in_blocks*libjpeg.DCTSIZE, (uint)compptr.v_samp_factor*libjpeg.DCTSIZE);
}
catch
{
return false;
}
sp.ds_buffer[ci]=buf;
}
sp.samplesperclump=samples_per_clump;
return true;
}
示例2: TIFFSetupStrips
public static bool TIFFSetupStrips(TIFF tif)
{
TIFFDirectory td=tif.tif_dir;
if(isTiled(tif)) td.td_stripsperimage=isUnspecified(tif, FIELD.TILEDIMENSIONS)?td.td_samplesperpixel:TIFFNumberOfTiles(tif);
else td.td_stripsperimage=isUnspecified(tif, FIELD.ROWSPERSTRIP)?td.td_samplesperpixel:(uint)TIFFNumberOfStrips(tif);
td.td_nstrips=td.td_stripsperimage;
if(td.td_planarconfig==PLANARCONFIG.SEPARATE) td.td_stripsperimage/=td.td_samplesperpixel;
try
{
td.td_stripoffset=new uint[td.td_nstrips];
td.td_stripbytecount=new uint[td.td_nstrips];
}
catch
{
return false;
}
// Place data at the end-of-file
// (by setting offsets to zero).
TIFFSetFieldBit(tif, FIELD.STRIPOFFSETS);
TIFFSetFieldBit(tif, FIELD.STRIPBYTECOUNTS);
// FIX: Some tools don't like images without ROWSPERSTRIP set.
if(!TIFFFieldSet(tif, FIELD.ROWSPERSTRIP))
{
td.td_rowsperstrip=td.td_imagelength;
TIFFSetFieldBit(tif, FIELD.ROWSPERSTRIP);
}
return true;
}
示例3: TIFFCheckTile
// Check an (x,y,z,s) coordinate against the image bounds.
public static bool TIFFCheckTile(TIFF tif, uint x, uint y, uint z, ushort s)
{
TIFFDirectory td=tif.tif_dir;
if(x>=td.td_imagewidth)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Col out of range, max {1}", x, td.td_imagewidth-1);
return false;
}
if(y>=td.td_imagelength)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Row out of range, max {1}", y, td.td_imagelength-1);
return false;
}
if(z>=td.td_imagedepth)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Depth out of range, max {1}", z, td.td_imagedepth-1);
return false;
}
if(td.td_planarconfig==PLANARCONFIG.SEPARATE&&s>=td.td_samplesperpixel)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Sample out of range, max {1}", s, td.td_samplesperpixel-1);
return false;
}
return true;
}
示例4: TIFFComputeTile
// Compute which tile an (x,y,z,s) value is in.
public static uint TIFFComputeTile(TIFF tif, uint x, uint y, uint z, ushort s)
{
TIFFDirectory td=tif.tif_dir;
uint dx=td.td_tilewidth;
uint dy=td.td_tilelength;
uint dz=td.td_tiledepth;
if(td.td_imagedepth==1) z=0;
if(dx==0xffffffff) dx=td.td_imagewidth;
if(dy==0xffffffff) dy=td.td_imagelength;
if(dz==0xffffffff) dz=td.td_imagedepth;
if(dx!=0&&dy!=0&&dz!=0)
{
uint xpt=TIFFhowmany(td.td_imagewidth, dx);
uint ypt=TIFFhowmany(td.td_imagelength, dy);
uint zpt=TIFFhowmany(td.td_imagedepth, dz);
if(td.td_planarconfig==PLANARCONFIG.SEPARATE)
return xpt*ypt*zpt*s+xpt*ypt*(z/dz)+xpt*(y/dy)+x/dx;
return xpt*ypt*(z/dz)+xpt*(y/dy)+x/dx;
}
return 1;
}
示例5: TIFFGetTagListEntry
public static TIFFTAG TIFFGetTagListEntry(TIFF tif, int tag_index)
{
TIFFDirectory td=tif.tif_dir;
if(tag_index<0||tag_index>=td.td_customValueCount) return (TIFFTAG)(-1);
else return td.td_customValues[tag_index].info.field_tag;
}
示例6: TIFFRewriteDirectory
// Similar to TIFFWriteDirectory(), but if the directory has already
// been written once, it is relocated to the end of the file, in case it
// has changed in size. Note that this will result in the loss of the
// previously used directory space.
public static bool TIFFRewriteDirectory(TIFF tif)
{
string module="TIFFRewriteDirectory";
// We don't need to do anything special if it hasn't been written.
if(tif.tif_diroff==0) return TIFFWriteDirectory(tif);
// Find and zero the pointer to this directory, so that TIFFLinkDirectory
// will cause it to be added after this directories current pre-link.
// Is it the first directory in the file?
if(tif.tif_header.tiff_diroff==tif.tif_diroff)
{
tif.tif_header.tiff_diroff=0;
tif.tif_diroff=0;
TIFFSeekFile(tif, (uint)(TIFF_MAGIC_SIZE+TIFF_VERSION_SIZE), SEEK.SET);
if(!WriteOK(tif, tif.tif_header.tiff_diroff))
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Error updating TIFF header");
return true;
}
}
else
{
uint nextdir=tif.tif_header.tiff_diroff;
do
{
ushort dircount;
if(!SeekOK(tif, nextdir)||!ReadOK(tif, out dircount))
{
TIFFErrorExt(tif.tif_clientdata, module, "Error fetching directory count");
return false;
}
if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0) TIFFSwab(ref dircount);
TIFFSeekFile(tif, (uint)dircount*12, SEEK.CUR);
if(!ReadOK(tif, out nextdir))
{
TIFFErrorExt(tif.tif_clientdata, module, "Error fetching directory link");
return false;
}
if((tif.tif_flags&TIF_FLAGS.TIFF_SWAB)!=0) TIFFSwab(ref nextdir);
} while(nextdir!=tif.tif_diroff&&nextdir!=0);
uint off=TIFFSeekFile(tif, 0, SEEK.CUR); // get current offset
TIFFSeekFile(tif, off-4, SEEK.SET);
tif.tif_diroff=0;
if(!WriteOK(tif, tif.tif_diroff))
{
TIFFErrorExt(tif.tif_clientdata, module, "Error writing directory link");
return false;
}
}
// Now use TIFFWriteDirectory() normally.
return TIFFWriteDirectory(tif);
}
示例7: TIFFNewScanlineSize
// Return the number of bytes to read/write in a call to
// one of the scanline-oriented i/o routines. Note that
// this number may be 1/samples-per-pixel if data is
// stored as separate planes.
// The ScanlineSize in case of YCbCrSubsampling is defined as the
// strip size divided by the strip height, i.e. the size of a pack of vertical
// subsampling lines divided by vertical subsampling. It should thus make
// sense when multiplied by a multiple of vertical subsampling.
// Some stuff depends on this newer version of TIFFScanlineSize
// TODO: resolve this
public static int TIFFNewScanlineSize(TIFF tif)
{
TIFFDirectory td=tif.tif_dir;
uint scanline;
if(td.td_planarconfig==PLANARCONFIG.CONTIG)
{
if(td.td_photometric==PHOTOMETRIC.YCBCR&&!isUpSampled(tif))
{
object[] ap=new object[2];
TIFFGetField(tif, TIFFTAG.YCBCRSUBSAMPLING, ap);
ushort[] ycbcrsubsampling=new ushort[2];
ycbcrsubsampling[0]=__GetAsUshort(ap, 0);
ycbcrsubsampling[1]=__GetAsUshort(ap, 1);
if(ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "Invalid YCbCr subsampling");
return 0;
}
return (int)(((((td.td_imagewidth+ycbcrsubsampling[0]-1)/ycbcrsubsampling[0])*(ycbcrsubsampling[0]*ycbcrsubsampling[1]+2)*td.td_bitspersample+7)/8)/ycbcrsubsampling[1]);
}
else scanline=multiply(tif, td.td_imagewidth, td.td_samplesperpixel, "TIFFScanlineSize");
}
else scanline=td.td_imagewidth;
return (int)TIFFhowmany8(multiply(tif, scanline, td.td_bitspersample, "TIFFScanlineSize"));
}
示例8: GTIFNew
//*********************************************************************
//
// Public Routines
//
//*********************************************************************
// Given an open TIFF file, look for GTIF keys and values and return GTIF structure.
//
// This function creates a GeoTIFF information interpretation handle
// (GTIF) based on a passed in TIFF handle originally from
// XTIFFOpen().
//
// The returned GTIF handle can be used to read or write GeoTIFF tags
// using the various GTIF functions. The handle should be destroyed using
// GTIFFree() before the file is closed with TIFFClose().
//
// If the file accessed has no GeoTIFF keys, an valid (but empty) GTIF is
// still returned. GTIFNew() is used both for existing files being read, and
// for new TIFF files that will have GeoTIFF tags written to them.
public static GTIF GTIFNew(TIFF tif)
{
TIFFMethod default_methods=new TIFFMethod();
_GTIFSetDefaultTIFF(default_methods);
return GTIFNewWithMethods(tif, default_methods);
}
示例9: TIFFGetClientInfo
public static object TIFFGetClientInfo(TIFF tif, string name)
{
foreach(TIFFClientInfoLink link in tif.tif_clientinfo)
{
if(link.name==name) return link.data;
}
return null;
}
示例10: TIFFCheckpointDirectory
// Similar to TIFFWriteDirectory(), writes the directory out
// but leaves all data structures in memory so that it can be
// written again. This will make a partially written TIFF file
// readable before it is successfully completed/closed.
public static bool TIFFCheckpointDirectory(TIFF tif)
{
// Setup the strips arrays, if they haven't already been.
if(tif.tif_dir.td_stripoffset==null) TIFFSetupStrips(tif);
bool rc=TIFFWriteDirectory(tif, false);
TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK.END));
return rc;
}
示例11: TIFFInitZIP
static bool TIFFInitZIP(TIFF tif, COMPRESSION scheme)
{
string module="TIFFInitZIP";
#if DEBUG
if(scheme!=COMPRESSION.DEFLATE&&scheme!=COMPRESSION.ADOBE_DEFLATE) throw new Exception("scheme!=COMPRESSION.DEFLATE&&scheme!=COMPRESSION.ADOBE_DEFLATE");
#endif
// Merge codec-specific tag information.
if(!_TIFFMergeFieldInfo(tif, zipFieldInfo))
{
TIFFErrorExt(tif.tif_clientdata, module, "Merging Deflate codec-specific tags failed");
return false;
}
// Allocate state block so tag methods have storage to record values.
ZIPState sp=null;
try
{
tif.tif_data=sp=new ZIPState();
sp.stream=new zlib.z_stream();
}
catch
{
TIFFErrorExt(tif.tif_clientdata, module, "No space for ZIP state block");
return false;
}
// Override parent get/set field methods.
sp.vgetparent=tif.tif_tagmethods.vgetfield;
tif.tif_tagmethods.vgetfield=ZIPVGetField; // hook for codec tags
sp.vsetparent=tif.tif_tagmethods.vsetfield;
tif.tif_tagmethods.vsetfield=ZIPVSetField; // hook for codec tags
// Default values for codec-specific fields
sp.zipquality=zlib.Z_DEFAULT_COMPRESSION; // default comp. level
sp.state=ZSTATE.None;
// Install codec methods.
tif.tif_setupdecode=ZIPSetupDecode;
tif.tif_predecode=ZIPPreDecode;
tif.tif_decoderow=ZIPDecode;
tif.tif_decodestrip=ZIPDecode;
tif.tif_decodetile=ZIPDecode;
tif.tif_setupencode=ZIPSetupEncode;
tif.tif_preencode=ZIPPreEncode;
tif.tif_postencode=ZIPPostEncode;
tif.tif_encoderow=ZIPEncode;
tif.tif_encodestrip=ZIPEncode;
tif.tif_encodetile=ZIPEncode;
tif.tif_cleanup=ZIPCleanup;
// Setup predictor setup.
TIFFPredictorInit(tif);
return true;
}
示例12: TIFFComputeStrip
// Compute which strip a (row, sample) value is in.
public static int TIFFComputeStrip(TIFF tif, uint row, ushort sample)
{
TIFFDirectory td=tif.tif_dir;
uint strip;
strip=row/td.td_rowsperstrip;
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 0;
}
strip+=sample*td.td_stripsperimage;
}
return (int)strip;
}
示例13: fpAcc
// Floating point predictor accumulation routine.
static unsafe void fpAcc(TIFF tif, byte[] cp0, int cp0_offset, int cc)
{
int stride=((TIFFPredictorState)tif.tif_data).stride;
int bps=tif.tif_dir.td_bitspersample/8;
int wc=cc/bps;
int count=cc;
byte[] tmp=null;
try
{
tmp=new byte[cc];
}
catch
{
return;
}
fixed(byte* cp0_=cp0)
{
byte* cp=cp0_+cp0_offset;
while(count>stride)
{
//was REPEAT4(stride, cp[stride]+=*(cp++));
switch(stride)
{
default: for(int i=stride-4; i>0; i--) cp[stride]+=*(cp++); goto case 4;
case 4: cp[stride]+=*(cp++); goto case 3;
case 3: cp[stride]+=*(cp++); goto case 2;
case 2: cp[stride]+=*(cp++); goto case 1;
case 1: cp[stride]+=*(cp++); break;
case 0: break;
}
count-=stride;
}
Array.Copy(cp0, cp0_offset, tmp, 0, cc);
cp=cp0_+cp0_offset;
for(count=0; count<wc; count++)
{
for(uint b=0; b<bps; b++) cp[bps*count+b]=tmp[(bps-b-1)*wc+count];
}
}
}
示例14: TIFFSetClientInfo
public static void TIFFSetClientInfo(TIFF tif, object data, string name)
{
// Do we have an existing link with this name? If so, just
// set it.
foreach(TIFFClientInfoLink link in tif.tif_clientinfo)
{
if(link.name==name)
{
link.data=data;
return;
}
}
// Create a new link.
TIFFClientInfoLink newlink=new TIFFClientInfoLink();
newlink.name=name;
newlink.data=data;
tif.tif_clientinfo.Add(newlink);
}
示例15: TIFFFillStrip
const uint NOTILE = 0xffffffff; // undefined state
#endregion Fields
#region Methods
// Read the specified strip and setup for decoding.
// The data buffer is expanded, as necessary, to
// hold the strip's data.
public static bool TIFFFillStrip(TIFF tif, uint strip)
{
string module="TIFFFillStrip";
TIFFDirectory td=tif.tif_dir;
if((tif.tif_flags&TIF_FLAGS.TIFF_NOREADRAW)==0)
{
// FIXME: butecount should have tsize_t type, but for now
// libtiff defines tsize_t as a signed 32-bit integer and we
// are losing ability to read arrays larger than 2^31 bytes.
// So we are using uint32 instead of tsize_t here.
uint bytecount=td.td_stripbytecount[strip];
if(bytecount<=0)
{
TIFFErrorExt(tif.tif_clientdata, tif.tif_name, "{0}: Invalid strip byte count, strip {1}", bytecount, strip);
return false;
}
// Expand raw data buffer, if needed, to
// hold data strip coming from file
// (perhaps should set upper bound on
// the size of a buffer we'll use?).
if(bytecount>tif.tif_rawdatasize)
{
tif.tif_curstrip=NOSTRIP;
if((tif.tif_flags&TIF_FLAGS.TIFF_MYBUFFER)==0)
{
TIFFErrorExt(tif.tif_clientdata, module, "{0}: Data buffer too small to hold strip {1}", tif.tif_name, strip);
return false;
}
if(!TIFFReadBufferSetup(tif, null, (int)TIFFroundup(bytecount, 1024))) return false;
}
if((uint)TIFFReadRawStrip1(tif, strip, tif.tif_rawdata, (int)bytecount, module)!=bytecount) return false;
if(!isFillOrder(tif, td.td_fillorder)&&(tif.tif_flags&TIF_FLAGS.TIFF_NOBITREV)==0)
TIFFReverseBits(tif.tif_rawdata, (uint)bytecount);
}
return TIFFStartStrip(tif, strip);
}