public static bool _TIFFMergeFieldInfo(TIFF tif, List <TIFFFieldInfo> info) { string module = "_TIFFMergeFieldInfo"; tif.tif_foundfield = null; try { foreach (TIFFFieldInfo fi in info) { TIFFFieldInfo fip = TIFFFindFieldInfo(tif, fi.field_tag, fi.field_type); if (fip == null) { tif.tif_fieldinfo.Add(fi); } } } catch { TIFFErrorExt(tif.tif_clientdata, module, "Failed to allocate field info array"); return(false); } // Sort the field info by tag number tif.tif_fieldinfo.Sort(tagCompare); return(true); }
public static void TIFFMergeFieldInfo(TIFF tif, TIFFFieldInfo info) { if (!_TIFFMergeFieldInfo(tif, info)) { TIFFErrorExt(tif.tif_clientdata, "TIFFMergeFieldInfo", "Merging block of 1 fields failed"); } }
static int tagCompare(TIFFFieldInfo ta, TIFFFieldInfo tb) { if (ta.field_tag != tb.field_tag) { return((int)ta.field_tag - (int)tb.field_tag); } return((int)tb.field_type - (int)ta.field_type); }
public static void TIFFSetupFieldInfo(TIFF tif, TIFFFieldInfo info) { tif.tif_fieldinfo.Clear(); if (!_TIFFMergeFieldInfo(tif, info)) { TIFFErrorExt(tif.tif_clientdata, "TIFFSetupFieldInfo", "Setting up field info failed"); } }
static int tagNameCompare(TIFFFieldInfo ta, TIFFFieldInfo tb) { int ret = ta.field_name.CompareTo(tb.field_name); if (ret != 0) { return(ret); } return((ta.field_type == TIFFDataType.TIFF_ANY)?0:((int)tb.field_type - (int)ta.field_type)); }
static TIFFFieldInfo TIFFCreateAnonFieldInfo(TIFF tif, TIFFTAG tag, TIFFDataType field_type) { try { // ??? TIFFFieldInfo fld=new TIFFFieldInfo(tag, TIFF_VARIABLE2, TIFF_VARIABLE2, field_type, FIELD.CUSTOM, true, true, "Tag "+tag); TIFFFieldInfo fld = new TIFFFieldInfo(tag, TIFF_VARIABLE, TIFF_VARIABLE, field_type, FIELD.CUSTOM, true, true, "Tag " + tag); return(fld); } catch { return(null); } }
static TIFFFieldInfo TIFFFieldWithTag(TIFF tif, TIFFTAG tag) { TIFFFieldInfo fip = TIFFFindFieldInfo(tif, tag, TIFFDataType.TIFF_ANY); if (fip == null) { TIFFErrorExt(tif.tif_clientdata, "TIFFFieldWithTag", "Internal error, unknown tag 0x{0:X}", tag); #if DEBUG throw new Exception("fip==null"); #endif // NOTREACHED } return(fip); }
static TIFFFieldInfo TIFFFieldWithName(TIFF tif, string field_name) { TIFFFieldInfo fip = TIFFFindFieldInfoByName(tif, field_name, TIFFDataType.TIFF_ANY); if (fip == null) { TIFFErrorExt(tif.tif_clientdata, "TIFFFieldWithName", "Internal error, unknown tag {0}", field_name); #if DEBUG throw new Exception("fip==null"); #endif // NOTREACHED } return(fip); }
static TIFFFieldInfo TIFFFindOrRegisterFieldInfo(TIFF tif, TIFFTAG tag, TIFFDataType dt) { TIFFFieldInfo fld = TIFFFindFieldInfo(tif, tag, dt); if (fld == null) { fld = TIFFCreateAnonFieldInfo(tif, tag, dt); if (!_TIFFMergeFieldInfo(tif, fld)) { return(null); } } return(fld); }
public static void TIFFMergeFieldInfo(TIFF tif, TIFFFieldInfo info) { if(!_TIFFMergeFieldInfo(tif, info)) { TIFFErrorExt(tif.tif_clientdata, "TIFFMergeFieldInfo", "Merging block of 1 fields failed"); } }
static int tagNameCompare(TIFFFieldInfo ta, TIFFFieldInfo tb) { int ret=ta.field_name.CompareTo(tb.field_name); if(ret!=0) return ret; return (ta.field_type==TIFFDataType.TIFF_ANY)?0:((int)tb.field_type-(int)ta.field_type); }
static int tagCompare(TIFFFieldInfo ta, TIFFFieldInfo tb) { if(ta.field_tag!=tb.field_tag) return (int)ta.field_tag-(int)tb.field_tag; return (int)tb.field_type-(int)ta.field_type; }
public static void TIFFSetupFieldInfo(TIFF tif, TIFFFieldInfo info) { tif.tif_fieldinfo.Clear(); if(!_TIFFMergeFieldInfo(tif, info)) TIFFErrorExt(tif.tif_clientdata, "TIFFSetupFieldInfo", "Setting up field info failed"); }
static void TIFFPrintField(TextWriter fd, TIFFFieldInfo fip, uint value_count, object raw_data) { fd.Write(" {0}: ", fip.field_name); for(uint j=0; j<value_count; j++) { if(fip.field_type==TIFFDataType.TIFF_BYTE) fd.Write("{0}", ((byte[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_UNDEFINED) fd.Write("0x{0:x}", (uint)((byte[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_SBYTE) fd.Write("{0}", ((sbyte[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_SHORT) fd.Write("{0}", ((ushort[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_SSHORT) fd.Write("{0}", ((short[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_LONG) fd.Write("{0}", ((uint[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_SLONG) fd.Write("{0}", (long)((int[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_FLOAT) fd.Write("{0}", ((float[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_IFD) fd.Write("0x{0:x}", ((uint[])raw_data)[j]); else if(fip.field_type==TIFFDataType.TIFF_ASCII) { fd.Write("{0}", (string)raw_data); break; } else if(fip.field_type==TIFFDataType.TIFF_RATIONAL||fip.field_type==TIFFDataType.TIFF_SRATIONAL||fip.field_type==TIFFDataType.TIFF_DOUBLE) fd.Write("{0}", ((double[])raw_data)[j]); else { fd.Write("<unsupported data type in TIFFPrint>"); break; } if(j<value_count-1) fd.Write(","); } fd.WriteLine(); }
static void TIFFPrintField(TextWriter fd, TIFFFieldInfo fip, uint value_count, object raw_data) { fd.Write(" {0}: ", fip.field_name); for (uint j = 0; j < value_count; j++) { if (fip.field_type == TIFFDataType.TIFF_BYTE) { fd.Write("{0}", ((byte[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_UNDEFINED) { fd.Write("0x{0:x}", (uint)((byte[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_SBYTE) { fd.Write("{0}", ((sbyte[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_SHORT) { fd.Write("{0}", ((ushort[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_SSHORT) { fd.Write("{0}", ((short[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_LONG) { fd.Write("{0}", ((uint[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_SLONG) { fd.Write("{0}", (long)((int[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_FLOAT) { fd.Write("{0}", ((float[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_IFD) { fd.Write("0x{0:x}", ((uint[])raw_data)[j]); } else if (fip.field_type == TIFFDataType.TIFF_ASCII) { fd.Write("{0}", (string)raw_data); break; } else if (fip.field_type == TIFFDataType.TIFF_RATIONAL || fip.field_type == TIFFDataType.TIFF_SRATIONAL || fip.field_type == TIFFDataType.TIFF_DOUBLE) { fd.Write("{0}", ((double[])raw_data)[j]); } else { fd.Write("<unsupported data type in TIFFPrint>"); break; } if (j < value_count - 1) { fd.Write(","); } } fd.WriteLine(); }
// Print the contents of the current directory // to the specified stdio file stream. public static void TIFFPrintDirectory(TIFF tif, TextWriter fd, TIFFPRINT flags) { TIFFDirectory td = tif.tif_dir; fd.WriteLine("TIFF Directory at offset 0x{0:X} ({0})", tif.tif_diroff); if (TIFFFieldSet(tif, FIELD.SUBFILETYPE)) { fd.Write(" Subfile Type:"); string sep = " "; if ((td.td_subfiletype & FILETYPE.REDUCEDIMAGE) != 0) { fd.Write("{0}reduced-resolution image", sep); sep = "/"; } if ((td.td_subfiletype & FILETYPE.PAGE) != 0) { fd.Write("{0}multi-page document", sep); sep = "/"; } if ((td.td_subfiletype & FILETYPE.MASK) != 0) { fd.Write("{0}transparency mask", sep); } fd.WriteLine(" ({0} = 0x{0:X})", td.td_subfiletype); } if (TIFFFieldSet(tif, FIELD.IMAGEDIMENSIONS)) { fd.Write(" Image Width: {0} Image Length: {1}", td.td_imagewidth, td.td_imagelength); if (TIFFFieldSet(tif, FIELD.IMAGEDEPTH)) { fd.Write(" Image Depth: {0}", td.td_imagedepth); } fd.WriteLine(); } if (TIFFFieldSet(tif, FIELD.TILEDIMENSIONS)) { fd.Write(" Tile Width: {0} Tile Length: {1}", td.td_tilewidth, td.td_tilelength); if (TIFFFieldSet(tif, FIELD.TILEDEPTH)) { fd.Write(" Tile Depth: {0}", td.td_tiledepth); } fd.WriteLine(); } if (TIFFFieldSet(tif, FIELD.RESOLUTION)) { fd.Write(" Resolution: {0}, {1}", td.td_xresolution, td.td_yresolution); if (TIFFFieldSet(tif, FIELD.RESOLUTIONUNIT)) { switch (td.td_resolutionunit) { case RESUNIT.NONE: fd.Write(" (unitless)"); break; case RESUNIT.INCH: fd.Write(" pixels/inch"); break; case RESUNIT.CENTIMETER: fd.Write(" pixels/cm"); break; default: fd.Write(" (unit {0} = 0x{0:X})", td.td_resolutionunit); break; } } fd.WriteLine(); } if (TIFFFieldSet(tif, FIELD.POSITION)) { fd.WriteLine(" Position: {0}, {1}", td.td_xposition, td.td_yposition); } if (TIFFFieldSet(tif, FIELD.BITSPERSAMPLE)) { fd.WriteLine(" Bits/Sample: {0}", td.td_bitspersample); } if (TIFFFieldSet(tif, FIELD.SAMPLEFORMAT)) { fd.Write(" Sample Format: "); switch (td.td_sampleformat) { case SAMPLEFORMAT.VOID: fd.WriteLine("void"); break; case SAMPLEFORMAT.INT: fd.WriteLine("signed integer"); break; case SAMPLEFORMAT.UINT: fd.WriteLine("unsigned integer"); break; case SAMPLEFORMAT.IEEEFP: fd.WriteLine("IEEE floating point"); break; case SAMPLEFORMAT.COMPLEXINT: fd.WriteLine("complex signed integer"); break; case SAMPLEFORMAT.COMPLEXIEEEFP: fd.WriteLine("complex IEEE floating point"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_sampleformat); break; } } if (TIFFFieldSet(tif, FIELD.COMPRESSION)) { TIFFCodec c = TIFFFindCODEC(td.td_compression); fd.Write(" Compression Scheme: "); if (c != null) { fd.WriteLine(c.name); } else { fd.WriteLine("{0} (0x{0:X})", td.td_compression); } } if (TIFFFieldSet(tif, FIELD.PHOTOMETRIC)) { fd.Write(" Photometric Interpretation: "); if ((int)td.td_photometric < photoNames.Length) { fd.WriteLine(photoNames[(int)td.td_photometric]); } else { switch (td.td_photometric) { case PHOTOMETRIC.LOGL: fd.WriteLine("CIE Log2(L)"); break; case PHOTOMETRIC.LOGLUV: fd.WriteLine("CIE Log2(L) (u',v')"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_photometric); break; } } } if (TIFFFieldSet(tif, FIELD.EXTRASAMPLES) && td.td_extrasamples != 0) { fd.Write(" Extra Samples: {0}<", td.td_extrasamples); string sep = ""; for (int i = 0; i < td.td_extrasamples; i++) { switch ((EXTRASAMPLE)td.td_sampleinfo[i]) { case EXTRASAMPLE.UNSPECIFIED: fd.Write("{0}unspecified", sep); break; case EXTRASAMPLE.ASSOCALPHA: fd.Write("{0}assoc-alpha", sep); break; case EXTRASAMPLE.UNASSALPHA: fd.Write("{0}unassoc-alpha", sep); break; default: fd.Write("{0}{1} (0x{1:X})", sep, td.td_sampleinfo[i]); break; } sep = ", "; } fd.WriteLine(">"); } if (TIFFFieldSet(tif, FIELD.INKNAMES)) { string[] names = td.td_inknames.Split('\0'); fd.Write(" Ink Names: "); string sep = ""; for (int i = 0; i < td.td_samplesperpixel && i < names.Length; i++) { fd.Write(sep); TIFFprintAscii(fd, names[i]); sep = ", "; } fd.WriteLine(); } if (TIFFFieldSet(tif, FIELD.THRESHHOLDING)) { fd.Write(" Thresholding: "); switch (td.td_threshholding) { case THRESHHOLD.BILEVEL: fd.WriteLine("bilevel art scan"); break; case THRESHHOLD.HALFTONE: fd.WriteLine("halftone or dithered scan"); break; case THRESHHOLD.ERRORDIFFUSE: fd.WriteLine("error diffused"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_threshholding); break; } } if (TIFFFieldSet(tif, FIELD.FILLORDER)) { fd.Write(" FillOrder: "); switch (td.td_fillorder) { case FILLORDER.MSB2LSB: fd.WriteLine("msb-to-lsb"); break; case FILLORDER.LSB2MSB: fd.WriteLine("lsb-to-msb"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_fillorder); break; } } if (TIFFFieldSet(tif, FIELD.YCBCRSUBSAMPLING)) { // For hacky reasons (see tif_jpeg.cs - JPEGFixupTestSubsampling), // we need to fetch this rather than trust what is in our structures. object[] ap = new object[2]; TIFFGetField(tif, TIFFTAG.YCBCRSUBSAMPLING, ap); fd.WriteLine(" YCbCr Subsampling: {0}, {1}", __GetAsUshort(ap, 0), __GetAsUshort(ap, 1)); } if (TIFFFieldSet(tif, FIELD.YCBCRPOSITIONING)) { fd.Write(" YCbCr Positioning: "); switch (td.td_ycbcrpositioning) { case YCBCRPOSITION.CENTERED: fd.WriteLine("centered"); break; case YCBCRPOSITION.COSITED: fd.WriteLine("cosited"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_ycbcrpositioning); break; } } if (TIFFFieldSet(tif, FIELD.HALFTONEHINTS)) { fd.WriteLine(" Halftone Hints: light {0} dark {1}", td.td_halftonehints[0], td.td_halftonehints[1]); } if (TIFFFieldSet(tif, FIELD.ORIENTATION)) { fd.Write(" Orientation: "); if ((int)td.td_orientation < orientNames.Length) { fd.WriteLine(orientNames[(int)td.td_orientation]); } else { fd.WriteLine("{0} (0x{0:X})", td.td_orientation); } } if (TIFFFieldSet(tif, FIELD.SAMPLESPERPIXEL)) { fd.WriteLine(" Samples/Pixel: {0}", td.td_samplesperpixel); } if (TIFFFieldSet(tif, FIELD.ROWSPERSTRIP)) { fd.Write(" Rows/Strip: "); if (td.td_rowsperstrip == uint.MaxValue) { fd.WriteLine("(infinite)"); } else { fd.WriteLine(td.td_rowsperstrip); } } if (TIFFFieldSet(tif, FIELD.MINSAMPLEVALUE)) { fd.WriteLine(" Min Sample Value: {0}", td.td_minsamplevalue); } if (TIFFFieldSet(tif, FIELD.MAXSAMPLEVALUE)) { fd.WriteLine(" Max Sample Value: {0}", td.td_maxsamplevalue); } if (TIFFFieldSet(tif, FIELD.SMINSAMPLEVALUE)) { fd.WriteLine(" SMin Sample Value: {0}", td.td_sminsamplevalue); } if (TIFFFieldSet(tif, FIELD.SMAXSAMPLEVALUE)) { fd.WriteLine(" SMax Sample Value: {0}", td.td_smaxsamplevalue); } if (TIFFFieldSet(tif, FIELD.PLANARCONFIG)) { fd.Write(" Planar Configuration: "); switch (td.td_planarconfig) { case PLANARCONFIG.CONTIG: fd.WriteLine("single image plane"); break; case PLANARCONFIG.SEPARATE: fd.WriteLine("separate image planes"); break; default: fd.WriteLine("{0} (0x{0:X})", td.td_planarconfig); break; } } if (TIFFFieldSet(tif, FIELD.PAGENUMBER)) { fd.WriteLine(" Page Number: {0}-{1}", td.td_pagenumber[0], td.td_pagenumber[1]); } if (TIFFFieldSet(tif, FIELD.COLORMAP)) { fd.Write(" Color Map: "); if ((flags & TIFFPRINT.COLORMAP) != 0) { fd.WriteLine(); uint n = 1u << td.td_bitspersample; for (uint l = 0; l < n; l++) { fd.WriteLine("\t{0}: {1} {2} {3}", l, td.td_colormap[0][l], td.td_colormap[1][l], td.td_colormap[2][l]); } } else { fd.WriteLine("(present)"); } } if (TIFFFieldSet(tif, FIELD.TRANSFERFUNCTION)) { fd.Write(" Transfer Function: "); if ((flags & TIFFPRINT.CURVES) != 0) { fd.WriteLine(); uint n = 1u << td.td_bitspersample; for (uint l = 0; l < n; l++) { fd.Write("\t{0}: {1}", l, td.td_transferfunction[0][l]); for (int i = 1; i < td.td_samplesperpixel; i++) { fd.Write(" {0}", td.td_transferfunction[i][l]); } fd.WriteLine(); } } else { fd.WriteLine("(present)"); } } if (TIFFFieldSet(tif, FIELD.SUBIFD) && td.td_subifd != null && td.td_subifd.Length != 0) { fd.Write(" SubIFD Offsets:"); for (int i = 0; i < td.td_nsubifd; i++) { fd.Write(" {0}", td.td_subifd[i]); } fd.WriteLine(); } // Custom tag support. short count = (short)TIFFGetTagListCount(tif); for (int i = 0; i < count; i++) { TIFFTAG tag = TIFFGetTagListEntry(tif, i); TIFFFieldInfo fip = TIFFFieldWithTag(tif, tag); if (fip == null) { continue; } uint value_count; object raw_data = null; if (fip.field_passcount) { object[] ap = new object[2]; if (!TIFFGetField(tif, tag, ap)) { continue; } value_count = __GetAsUshort(ap, 0); raw_data = ap[1]; } else { if (fip.field_readcount == TIFF_VARIABLE) { value_count = 1; } else if (fip.field_readcount == TIFF_SPP) { value_count = td.td_samplesperpixel; } else { value_count = (ushort)fip.field_readcount; } if (fip.field_type == TIFFDataType.TIFF_ASCII || fip.field_readcount == TIFF_VARIABLE || fip.field_readcount == TIFF_SPP || value_count > 1) { object[] ap = new object[2]; if (!TIFFGetField(tif, tag, ap)) { continue; } raw_data = ap[0]; } else { object[] ap = new object[value_count]; if (!TIFFGetField(tif, tag, ap)) { continue; } switch (fip.field_type) { case TIFFDataType.TIFF_UNDEFINED: case TIFFDataType.TIFF_BYTE: { byte[] raw_data1 = new byte[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsByte(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_DOUBLE: case TIFFDataType.TIFF_RATIONAL: case TIFFDataType.TIFF_SRATIONAL: { double[] raw_data1 = new double[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsDouble(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_SBYTE: { sbyte[] raw_data1 = new sbyte[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsSbyte(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_SHORT: { ushort[] raw_data1 = new ushort[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsUshort(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_SSHORT: { short[] raw_data1 = new short[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsShort(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_IFD: case TIFFDataType.TIFF_LONG: { uint[] raw_data1 = new uint[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsUint(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_SLONG: { int[] raw_data1 = new int[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsInt(ap, a); } raw_data = raw_data1; } break; case TIFFDataType.TIFF_FLOAT: { float[] raw_data1 = new float[value_count]; for (int a = 0; a < value_count; a++) { raw_data1[a] = __GetAsFloat(ap, a); } raw_data = raw_data1; } break; } } } // Catch the tags which needs to be specially handled and // pretty print them. If tag not handled in // _TIFFPrettyPrintField() fall down and print it as any other tag. if (TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data)) { continue; } else { TIFFPrintField(fd, fip, value_count, raw_data); } } if (tif.tif_tagmethods.printdir != null) { tif.tif_tagmethods.printdir(tif, fd, flags); } if ((flags & TIFFPRINT.STRIPS) != 0 && TIFFFieldSet(tif, FIELD.STRIPOFFSETS)) { fd.WriteLine(" {0} {1}:", td.td_nstrips, isTiled(tif)?"Tiles":"Strips"); for (uint s = 0; s < td.td_nstrips; s++) { fd.WriteLine("\t{0}: [{1}, {2}]", s, td.td_stripoffset[s], td.td_stripbytecount[s]); } } }
public static bool _TIFFMergeFieldInfo(TIFF tif, TIFFFieldInfo info) { string module="_TIFFMergeFieldInfo"; tif.tif_foundfield=null; try { TIFFFieldInfo fip=TIFFFindFieldInfo(tif, info.field_tag, info.field_type); if(fip==null) tif.tif_fieldinfo.Add(info); } catch { TIFFErrorExt(tif.tif_clientdata, module, "Failed to allocate field info array"); return false; } // Sort the field info by tag number tif.tif_fieldinfo.Sort(tagCompare); return true; }
static TIFFFieldInfo TIFFFindFieldInfoSearch(TIFF tif, TIFFTAG tag, TIFFDataType dt, int min, int num) { if (num == 0) { return(null); } TIFFFieldInfo fip = tif.tif_fieldinfo[min + num / 2]; if (fip.field_tag == tag) { int pos = min + num / 2; if (dt == TIFFDataType.TIFF_ANY) { for (; ;) // Find first { if (pos == 0) { break; } if (tif.tif_fieldinfo[pos - 1].field_tag != tag) { break; } pos--; fip = tif.tif_fieldinfo[pos]; } return(tif.tif_foundfield = fip); } if (fip.field_type == dt) { return(tif.tif_foundfield = fip); } //if(fip.field_type>dt) return TIFFFindFieldInfoSearch(tif, tag, dt, min, num/2); //return TIFFFindFieldInfoSearch(tif, tag, dt, min+num/2+1, num-(num/2+1)); for (; ;) // preceding fieldinfos and exit if found DataType { if (pos == 0) { break; } if (tif.tif_fieldinfo[pos - 1].field_tag != tag) { break; } pos--; fip = tif.tif_fieldinfo[pos]; if (fip.field_type == dt) { return(tif.tif_foundfield = fip); } } pos = min + num / 2; for (; ;) // succeding fieldinfos first and exit if found DataType { if (pos == (tif.tif_fieldinfo.Count - 1)) { break; } if (tif.tif_fieldinfo[pos + 1].field_tag != tag) { break; } pos++; fip = tif.tif_fieldinfo[pos]; if (fip.field_type == dt) { return(tif.tif_foundfield = fip); } } return(null); } if (fip.field_tag > tag) { return(TIFFFindFieldInfoSearch(tif, tag, dt, min, num / 2)); } return(TIFFFindFieldInfoSearch(tif, tag, dt, min + num / 2 + 1, num - (num / 2 + 1))); }
static TIFFFieldInfo TIFFCreateAnonFieldInfo(TIFF tif, TIFFTAG tag, TIFFDataType field_type) { try { // ??? TIFFFieldInfo fld=new TIFFFieldInfo(tag, TIFF_VARIABLE2, TIFF_VARIABLE2, field_type, FIELD.CUSTOM, true, true, "Tag "+tag); TIFFFieldInfo fld=new TIFFFieldInfo(tag, TIFF_VARIABLE, TIFF_VARIABLE, field_type, FIELD.CUSTOM, true, true, "Tag "+tag); return fld; } catch { return null; } }
// Process tags that are not special cased. static bool TIFFWriteNormalTag(TIFF tif, TIFFDirEntry dir, TIFFFieldInfo fip) { uint wc=(uint)fip.field_writecount; dir.tdir_tag=(ushort)fip.field_tag; dir.tdir_type=(ushort)fip.field_type; dir.tdir_count=wc; switch(fip.field_type) { case TIFFDataType.TIFF_SHORT: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); ushort[] wp=ap[1] as ushort[]; if(wp==null) return false; if(!TIFFWriteShortArray(tif, dir, wp)) return false; } else { if(wc==1) { ushort sv=__GetAsUshort(ap, 0); //was dir.tdir_offset=TIFFInsertData(tif, dir.tdir_type, sv); dir.tdir_offset=((uint)(tif.tif_header.tiff_magic==TIFF_BIGENDIAN?(sv&tif_typemask[dir.tdir_type])<<tif_typeshift[dir.tdir_type]:sv&tif_typemask[dir.tdir_type])); } else { ushort[] wp=ap[0] as ushort[]; if(wp==null) return false; if(!TIFFWriteShortArray(tif, dir, wp)) return false; } } } break; case TIFFDataType.TIFF_SSHORT: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); short[] wp=ap[1] as short[]; if(wp==null) return false; if(!TIFFWriteShortArray(tif, dir, wp)) return false; } else { if(wc==1) { short sv=__GetAsShort(ap, 0); //was dir.tdir_offset=TIFFInsertData(tif, dir.tdir_type, sv); dir.tdir_offset=((uint)(tif.tif_header.tiff_magic==TIFF_BIGENDIAN?(sv&tif_typemask[dir.tdir_type])<<tif_typeshift[dir.tdir_type]:sv&tif_typemask[dir.tdir_type])); } else { short[] wp=ap[0] as short[]; if(wp==null) return false; if(!TIFFWriteShortArray(tif, dir, wp)) return false; } } } break; case TIFFDataType.TIFF_SLONG: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); int[] lp=ap[1] as int[]; if(lp==null) return false; if(!TIFFWriteLongArray(tif, dir, lp)) return false; } else { if(wc==1) { // XXX handle LONG=>SHORT conversion dir.tdir_offset=__GetAsUint(ap, 0); } else { int[] lp=ap[0] as int[]; if(lp==null) return false; if(!TIFFWriteLongArray(tif, dir, lp)) return false; } } } break; case TIFFDataType.TIFF_LONG: case TIFFDataType.TIFF_IFD: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); uint[] lp=ap[1] as uint[]; if(lp==null) return false; if(!TIFFWriteLongArray(tif, dir, lp)) return false; } else { if(wc==1) { // XXX handle LONG=>SHORT conversion dir.tdir_offset=__GetAsUint(ap, 0); } else { uint[] lp=ap[0] as uint[]; if(lp==null) return false; if(!TIFFWriteLongArray(tif, dir, lp)) return false; } } } break; case TIFFDataType.TIFF_RATIONAL: case TIFFDataType.TIFF_SRATIONAL: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); double[] fp=ap[1] as double[]; if(fp==null) return false; if(!TIFFWriteRationalArray(tif, dir, fp)) return false; } else { if(wc==1) { double fv=__GetAsDouble(ap, 0); if(!TIFFWriteRational(tif, fip.field_type, fip.field_tag, dir, fv)) return false; } else { double[] fp=ap[0] as double[]; if(fp==null) return false; if(!TIFFWriteRationalArray(tif, dir, fp)) return false; } } } break; case TIFFDataType.TIFF_FLOAT: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); float[] fp=ap[1] as float[]; if(fp==null) return false; if(!TIFFWriteFloatArray(tif, dir, fp)) return false; } else { if(wc==1) { float[] fv=new float[1]; fv[0]=__GetAsFloat(ap, 0); if(!TIFFWriteFloatArray(tif, dir, fv)) return false; } else { float[] fp=ap[0] as float[]; if(fp==null) return false; if(!TIFFWriteFloatArray(tif, dir, fp)) return false; } } } break; case TIFFDataType.TIFF_DOUBLE: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); double[] dp=ap[1] as double[]; if(dp==null) return false; if(!TIFFWriteDoubleArray(tif, dir, dp)) return false; } else { if(wc==1) { double[] dv=new double[1]; dv[0]=__GetAsDouble(ap, 0); if(!TIFFWriteDoubleArray(tif, dir, dv)) return false; } else { double[] dp=ap[0] as double[]; if(dp==null) return false; if(!TIFFWriteDoubleArray(tif, dir, dp)) return false; } } } break; case TIFFDataType.TIFF_ASCII: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); string cp; if(fip.field_passcount) { // Assume TIFF_VARIABLE wc=__GetAsUint(ap, 0); cp=ap[1] as string; if(cp==null) return false; } else { cp=ap[0] as string; if(cp==null) return false; } cp=cp.TrimEnd('\0'); cp+='\0'; dir.tdir_count=(uint)cp.Length; if(!TIFFWriteByteArray(tif, dir, Encoding.ASCII.GetBytes(cp))) return false; } break; case TIFFDataType.TIFF_BYTE: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); byte[] cp=ap[1] as byte[]; if(cp==null) return false; if(!TIFFWriteByteArray(tif, dir, cp)) return false; } else { if(wc==1) { byte[] cv=new byte[1]; cv[0]=__GetAsByte(ap, 0); if(!TIFFWriteByteArray(tif, dir, cv)) return false; } else { byte[] cp=ap[0] as byte[]; if(cp==null) return false; if(!TIFFWriteByteArray(tif, dir, cp)) return false; } } } break; case TIFFDataType.TIFF_SBYTE: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); if(fip.field_passcount) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); sbyte[] cp=ap[1] as sbyte[]; if(cp==null) return false; if(!TIFFWriteByteArray(tif, dir, cp)) return false; } else { if(wc==1) { sbyte[] cv=new sbyte[1]; cv[0]=__GetAsSbyte(ap, 0); if(!TIFFWriteByteArray(tif, dir, cv)) return false; } else { sbyte[] cp=ap[0] as sbyte[]; if(cp==null) return false; if(!TIFFWriteByteArray(tif, dir, cp)) return false; } } } break; case TIFFDataType.TIFF_UNDEFINED: { object[] ap=new object[2]; TIFFGetField(tif, fip.field_tag, ap); byte[] cp; if((int)wc==TIFF_VARIABLE) { // Assume TIFF_VARIABLE dir.tdir_count=wc=__GetAsUint(ap, 0); cp=ap[1] as byte[]; if(cp==null) return false; } else { cp=ap[0] as byte[]; if(cp==null) return false; } if(!TIFFWriteByteArray(tif, dir, cp)) return false; } break; case TIFFDataType.TIFF_NOTYPE: break; } return true; }