/* Parse FUJI information */ /* It is a simpler form of Tiff IFD, so we add them as TiffEntries */ void ParseFuji(uint offset) { try { IFD tempIFD = new IFD(ifd.endian, ifd.Depth); ImageBinaryReaderBigEndian bytes = new ImageBinaryReaderBigEndian(stream, offset); uint entries = bytes.ReadUInt32(); if (entries > 255) { throw new RawDecoderException("Too many entries"); } for (int i = 0; i < entries; i++) { UInt16 tag = bytes.ReadUInt16(); uint length = bytes.ReadUInt16(); Tag t; // Set types of known tags switch (tag) { case 0x100: case 0x121: case 0x2ff0: t = new Tag((TagType)tag, TiffDataType.SHORT, length / 2); for (int k = 0; k < t.dataCount; k++) { t.data[k] = bytes.ReadUInt16(); } break; case 0xc000: // This entry seem to have swapped endianness: t = new Tag((TagType)tag, TiffDataType.LONG, length / 4); for (int k = 0; k < t.dataCount; k++) { t.data[k] = bytes.ReadUInt32(); } break; default: t = new Tag((TagType)tag, TiffDataType.UNDEFINED, length); for (int k = 0; k < t.dataCount; k++) { t.data[k] = bytes.ReadByte(); } break; } tempIFD.tags.Add(t.TagId, t); //bytes.ReadBytes((int)length); } ifd.subIFD.Add(tempIFD); } catch (IOException) { throw new RawDecoderException("IO error occurred during parsing. Skipping the rest"); } }
public RAFDecoder(Stream file) : base(file, true) { //alt_layout = false; // FUJI has pointers to IFD's at fixed byte offsets // So if camera is FUJI, we cannot use ordinary TIFF parser //get first 8 char and see if equal fuji file.Position = 0; var data = new byte[110]; file.Read(data, 0, 8); string dataAsString = System.Text.Encoding.UTF8.GetString(data.Take(8).ToArray()); if (dataAsString != "FUJIFILM") { throw new RawDecoderException("Header is wrong"); } //Fuji is indexer reverse endian reader = new ImageBinaryReaderBigEndian(file); reader.BaseStream.Position = 8; //read next 8 byte dataAsString = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(8).ToArray()).Trim(); //4 byte version var version = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(4).ToArray()); //8 bytes unknow ?? var unknow = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(8).ToArray()).Trim(); //32 byte a string (camera model) dataAsString = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(32).ToArray()).Trim(); //Directory //4 bytes version version = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(4).ToArray()); //20 bytes unkown ?? dataAsString = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(20).ToArray()).Trim(); //parse the ifd uint first_ifd = reader.ReadUInt32(); relativeOffset = first_ifd + 12; reader.ReadInt32(); //raw header // RAW information IFD on older uint third_ifd = reader.ReadUInt32(); reader.ReadUInt32(); uint secondIFD = reader.ReadUInt32(); uint count = reader.ReadUInt32(); try { Parse(secondIFD); } catch (Exception) { //old format ifd = new IFD(Endianness.Big, 0); //raw image var entry = new Tag(TagType.FUJI_STRIPOFFSETS, TiffDataType.LONG, 1); entry.data[0] = secondIFD; ifd.tags.Add(entry.TagId, entry); entry = new Tag(TagType.FUJI_STRIPBYTECOUNTS, TiffDataType.LONG, 1); entry.data[0] = count; ifd.tags.Add(entry.TagId, entry); } Parse(first_ifd + 12); ParseFuji(third_ifd); }