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; } } }