/// <summary> /// Performs the IPTC data extraction, adding found values to the specified instance of /// <see cref="Com.Drew.Metadata.Metadata"/> /// . /// </summary> public virtual void Extract(SequentialReader reader, Com.Drew.Metadata.Metadata metadata, long length) { IptcDirectory directory = metadata.GetOrCreateDirectory <IptcDirectory>(); int offset = 0; // for each tag while (offset < length) { // identifies start of a tag short startByte; try { startByte = reader.GetUInt8(); offset++; } catch (IOException) { directory.AddError("Unable to read starting byte of IPTC tag"); return; } if (startByte != unchecked ((int)(0x1c))) { directory.AddError("Invalid start to IPTC tag"); return; } // we need at least five bytes left to read a tag if (offset + 5 >= length) { directory.AddError("Too few bytes remain for a valid IPTC tag"); return; } int directoryType; int tagType; int tagByteCount; try { directoryType = reader.GetUInt8(); tagType = reader.GetUInt8(); tagByteCount = reader.GetUInt16(); offset += 4; } catch (IOException) { directory.AddError("IPTC data segment ended mid-way through tag descriptor"); return; } if (offset + tagByteCount > length) { directory.AddError("Data for tag extends beyond end of IPTC segment"); return; } try { ProcessTag(reader, directory, directoryType, tagType, tagByteCount); } catch (IOException) { directory.AddError("Error processing IPTC tag"); return; } offset += tagByteCount; } }
/// <summary> /// Performs the IPTC data extraction, adding found values to the specified instance of /// <see cref="Com.Drew.Metadata.Metadata"/> /// . /// </summary> public virtual void Extract([NotNull] SequentialReader reader, [NotNull] Com.Drew.Metadata.Metadata metadata, long length) { IptcDirectory directory = new IptcDirectory(); metadata.AddDirectory(directory); int offset = 0; // for each tag while (offset < length) { // identifies start of a tag short startByte; try { startByte = reader.GetUInt8(); offset++; } catch (IOException) { directory.AddError("Unable to read starting byte of IPTC tag"); return; } if (startByte != unchecked ((int)(0x1c))) { // NOTE have seen images where there was one extra byte at the end, giving // offset==length at this point, which is not worth logging as an error. if (offset != length) { directory.AddError("Invalid IPTC tag marker at offset " + (offset - 1) + ". Expected '0x1c' but got '0x" + Sharpen.Extensions.ToHexString(startByte) + "'."); } return; } // we need at least five bytes left to read a tag if (offset + 5 >= length) { directory.AddError("Too few bytes remain for a valid IPTC tag"); return; } int directoryType; int tagType; int tagByteCount; try { directoryType = reader.GetUInt8(); tagType = reader.GetUInt8(); // TODO support Extended DataSet Tag (see 1.5(c), p14, IPTC-IIMV4.2.pdf) tagByteCount = reader.GetUInt16(); offset += 4; } catch (IOException) { directory.AddError("IPTC data segment ended mid-way through tag descriptor"); return; } if (offset + tagByteCount > length) { directory.AddError("Data for tag extends beyond end of IPTC segment"); return; } try { ProcessTag(reader, directory, directoryType, tagType, tagByteCount); } catch (IOException) { directory.AddError("Error processing IPTC tag"); return; } offset += tagByteCount; } }
/// <summary> /// Performs the IPTC data extraction, adding found values to the specified instance of /// <see cref="Com.Drew.Metadata.Metadata"/> /// . /// </summary> public virtual void Extract([NotNull] SequentialReader reader, [NotNull] Com.Drew.Metadata.Metadata metadata, long length) { IptcDirectory directory = new IptcDirectory(); metadata.AddDirectory(directory); int offset = 0; // for each tag while (offset < length) { // identifies start of a tag short startByte; try { startByte = reader.GetUInt8(); offset++; } catch (IOException) { directory.AddError("Unable to read starting byte of IPTC tag"); return; } if (startByte != unchecked((int)(0x1c))) { // NOTE have seen images where there was one extra byte at the end, giving // offset==length at this point, which is not worth logging as an error. if (offset != length) { directory.AddError("Invalid IPTC tag marker at offset " + (offset - 1) + ". Expected '0x1c' but got '0x" + Sharpen.Extensions.ToHexString(startByte) + "'."); } return; } // we need at least five bytes left to read a tag if (offset + 5 >= length) { directory.AddError("Too few bytes remain for a valid IPTC tag"); return; } int directoryType; int tagType; int tagByteCount; try { directoryType = reader.GetUInt8(); tagType = reader.GetUInt8(); // TODO support Extended DataSet Tag (see 1.5(c), p14, IPTC-IIMV4.2.pdf) tagByteCount = reader.GetUInt16(); offset += 4; } catch (IOException) { directory.AddError("IPTC data segment ended mid-way through tag descriptor"); return; } if (offset + tagByteCount > length) { directory.AddError("Data for tag extends beyond end of IPTC segment"); return; } try { ProcessTag(reader, directory, directoryType, tagType, tagByteCount); } catch (IOException) { directory.AddError("Error processing IPTC tag"); return; } offset += tagByteCount; } }