public byte[] insertHeaders(Stream stream, List<Dictionary<string, object>> headers = null) { long idx; BinaryReader br = new BinaryReader(stream); if (headers == null || headers.Count == 0) { headers = _headers; } // Check if data is jpeg if (br.SHORT(0) != 0xFFD8) { throw new ImageError(ImageError.WRONG_FORMAT); } if (headers.Count != 0) { idx = br.SHORT(2) == 0xFFE0 ? 4 + br.SHORT(4) : 2; for (int i = 0, max = headers.Count; i < max; i++) { br.SEGMENT((int)idx, 0, (byte[])headers[i]["segment"]); idx += Convert.ToInt32(headers[i]["length"]); } } return br.SEGMENT(); }
public bool init(Stream segment) { // Reset internal data offsets = new Dictionary<string, long>() { { "tiffHeader", 10 } }; if (segment == null || segment.Length == 0) { return false; } data = new BinaryReader(segment); // Check if that"s APP1 and that it has EXIF if (data.SHORT(0) == 0xFFE1 && data.STRING(4, 4).ToUpper() == "EXIF") { return getIFDOffsets(); } return false; }
public override Dictionary<string, int> info(BinaryReader br = null) { long idx = 0; int marker, length; if (br == null) { br = _br; } // examine all through the end, since some images might have very large APP segments while (idx <= br.Length) { marker = br.SHORT(idx += 2); if (marker >= 0xFFC0 && marker <= 0xFFC3) { // SOFn idx += 5; // marker (2 bytes) + length (2 bytes) + Sample precision (1 byte) return new Dictionary<string, int>() { { "height", br.SHORT(idx) }, { "width", br.SHORT(idx += 2) } }; } length = br.SHORT(idx += 2); idx += length - 2; } return null; }