/// <exception cref="System.IO.IOException"/> private void SetInt32(Com.Drew.Metadata.Directory directory, int tagType, RandomAccessReader reader) { int i = reader.GetInt32(tagType); if (i != 0) { directory.SetInt(tagType, i); } }
private static void ProcessTag(Com.Drew.Metadata.Directory directory, int tagType, int tagValueOffset, int componentCount, int formatCode, RandomAccessReader reader) { switch (formatCode) { case FmtUndefined: { // Directory simply stores raw values // The display side uses a Descriptor class per directory to turn the raw values into 'pretty' descriptions // this includes exif user comments directory.SetByteArray(tagType, reader.GetBytes(tagValueOffset, componentCount)); break; } case FmtString: { string @string = reader.GetNullTerminatedString(tagValueOffset, componentCount); directory.SetString(tagType, @string); break; } case FmtSrational: { if (componentCount == 1) { directory.SetRational(tagType, new Rational(reader.GetInt32(tagValueOffset), reader.GetInt32(tagValueOffset + 4))); } else { if (componentCount > 1) { Rational[] rationals = new Rational[componentCount]; for (int i = 0; i < componentCount; i++) { rationals[i] = new Rational(reader.GetInt32(tagValueOffset + (8 * i)), reader.GetInt32(tagValueOffset + 4 + (8 * i))); } directory.SetRationalArray(tagType, rationals); } } break; } case FmtUrational: { if (componentCount == 1) { directory.SetRational(tagType, new Rational(reader.GetUInt32(tagValueOffset), reader.GetUInt32(tagValueOffset + 4))); } else { if (componentCount > 1) { Rational[] rationals = new Rational[componentCount]; for (int i = 0; i < componentCount; i++) { rationals[i] = new Rational(reader.GetUInt32(tagValueOffset + (8 * i)), reader.GetUInt32(tagValueOffset + 4 + (8 * i))); } directory.SetRationalArray(tagType, rationals); } } break; } case FmtSingle: { if (componentCount == 1) { directory.SetFloat(tagType, reader.GetFloat32(tagValueOffset)); } else { float[] floats = new float[componentCount]; for (int i = 0; i < componentCount; i++) { floats[i] = reader.GetFloat32(tagValueOffset + (i * 4)); } directory.SetFloatArray(tagType, floats); } break; } case FmtDouble: { if (componentCount == 1) { directory.SetDouble(tagType, reader.GetDouble64(tagValueOffset)); } else { double[] doubles = new double[componentCount]; for (int i = 0; i < componentCount; i++) { doubles[i] = reader.GetDouble64(tagValueOffset + (i * 4)); } directory.SetDoubleArray(tagType, doubles); } break; } case FmtSbyte: { // // Note that all integral types are stored as int32 internally (the largest supported by TIFF) // if (componentCount == 1) { directory.SetInt(tagType, reader.GetInt8(tagValueOffset)); } else { int[] bytes = new int[componentCount]; for (int i = 0; i < componentCount; i++) { bytes[i] = reader.GetInt8(tagValueOffset + i); } directory.SetIntArray(tagType, bytes); } break; } case FmtByte: { if (componentCount == 1) { directory.SetInt(tagType, reader.GetUInt8(tagValueOffset)); } else { int[] bytes = new int[componentCount]; for (int i = 0; i < componentCount; i++) { bytes[i] = reader.GetUInt8(tagValueOffset + i); } directory.SetIntArray(tagType, bytes); } break; } case FmtUshort: { if (componentCount == 1) { int i = reader.GetUInt16(tagValueOffset); directory.SetInt(tagType, i); } else { int[] ints = new int[componentCount]; for (int i = 0; i < componentCount; i++) { ints[i] = reader.GetUInt16(tagValueOffset + (i * 2)); } directory.SetIntArray(tagType, ints); } break; } case FmtSshort: { if (componentCount == 1) { int i = reader.GetInt16(tagValueOffset); directory.SetInt(tagType, i); } else { int[] ints = new int[componentCount]; for (int i = 0; i < componentCount; i++) { ints[i] = reader.GetInt16(tagValueOffset + (i * 2)); } directory.SetIntArray(tagType, ints); } break; } case FmtSlong: case FmtUlong: { // NOTE 'long' in this case means 32 bit, not 64 if (componentCount == 1) { int i = reader.GetInt32(tagValueOffset); directory.SetInt(tagType, i); } else { int[] ints = new int[componentCount]; for (int i = 0; i < componentCount; i++) { ints[i] = reader.GetInt32(tagValueOffset + (i * 4)); } directory.SetIntArray(tagType, ints); } break; } default: { directory.AddError("Unknown format code " + formatCode + " for tag " + tagType); break; } } }
/// <exception cref="System.IO.IOException"/> private void ProcessTag(SequentialReader reader, Com.Drew.Metadata.Directory directory, int directoryType, int tagType, int tagByteCount) { int tagIdentifier = tagType | (directoryType << 8); string @string = null; switch (tagIdentifier) { case IptcDirectory.TagApplicationRecordVersion: { // short int shortValue = reader.GetUInt16(); reader.Skip(tagByteCount - 2); directory.SetInt(tagIdentifier, shortValue); return; } case IptcDirectory.TagUrgency: { // byte directory.SetInt(tagIdentifier, reader.GetUInt8()); reader.Skip(tagByteCount - 1); return; } case IptcDirectory.TagReleaseDate: case IptcDirectory.TagDateCreated: { // Date object if (tagByteCount >= 8) { @string = reader.GetString(tagByteCount); try { int year = System.Convert.ToInt32(Sharpen.Runtime.Substring(@string, 0, 4)); int month = System.Convert.ToInt32(Sharpen.Runtime.Substring(@string, 4, 6)) - 1; int day = System.Convert.ToInt32(Sharpen.Runtime.Substring(@string, 6, 8)); DateTime date = new Sharpen.GregorianCalendar(year, month, day).GetTime(); directory.SetDate(tagIdentifier, date); return; } catch (FormatException) { } } else { // fall through and we'll process the 'string' value below reader.Skip(tagByteCount); } goto case IptcDirectory.TagReleaseTime; } case IptcDirectory.TagReleaseTime: case IptcDirectory.TagTimeCreated: default: { break; } } // time... // fall through // If we haven't returned yet, treat it as a string // NOTE that there's a chance we've already loaded the value as a string above, but failed to parse the value if (@string == null) { @string = reader.GetString(tagByteCount, Runtime.GetProperty("file.encoding")); } // "ISO-8859-1" if (directory.ContainsTag(tagIdentifier)) { // this fancy string[] business avoids using an ArrayList for performance reasons string[] oldStrings = directory.GetStringArray(tagIdentifier); string[] newStrings; if (oldStrings == null) { newStrings = new string[1]; } else { newStrings = new string[oldStrings.Length + 1]; System.Array.Copy(oldStrings, 0, newStrings, 0, oldStrings.Length); } newStrings[newStrings.Length - 1] = @string; directory.SetStringArray(tagIdentifier, newStrings); } else { directory.SetString(tagIdentifier, @string); } }