private void GetData(ImageBinaryReader fileStream) { data = new Object[dataCount]; for (int j = 0; j < dataCount; j++) { switch (dataType) { case TiffDataType.BYTE: case TiffDataType.UNDEFINED: case TiffDataType.ASCII: data[j] = fileStream.ReadByte(); break; case TiffDataType.SHORT: data[j] = fileStream.ReadUInt16(); break; case TiffDataType.LONG: case TiffDataType.OFFSET: data[j] = fileStream.ReadUInt32(); break; case TiffDataType.SBYTE: data[j] = fileStream.ReadSByte(); break; case TiffDataType.SSHORT: data[j] = fileStream.ReadInt16(); //if ( dataOffset == 0 && dataCount == 1) fileStream.ReadInt16(); break; case TiffDataType.SLONG: data[j] = fileStream.ReadInt32(); break; case TiffDataType.SRATIONAL: case TiffDataType.RATIONAL: //Because the nikonmakernote is broken with the tag 0x19 wich is double but offset of zero. if (dataOffset == 0) { data[j] = .0; } else { data[j] = fileStream.ReadRational(); } break; case TiffDataType.FLOAT: data[j] = fileStream.ReadSingle(); break; case TiffDataType.DOUBLE: data[j] = fileStream.ReadDouble(); break; } } }
public static void Decode16BitRawUnpacked(ImageBinaryReader input, Point2D size, Point2D offset, Image <ushort> rawImage) { for (int y = 0; y < size.height; y++) { var skip = (y + offset.height) * rawImage.fullSize.dim.width + offset.width; for (int x = 0; x < size.width; x += 1) { rawImage.fullSize.rawView[skip + x] = input.ReadUInt16(); } } }
public void ParseSOF(SOFInfo sof) { uint headerLength = input.ReadUInt16(); sof.precision = input.ReadByte(); sof.height = input.ReadUInt16(); sof.width = input.ReadUInt16(); sof.numComponents = input.ReadByte(); if (sof.precision > 16) { throw new RawDecoderException("More than 16 bits per channel is not supported."); } if (sof.numComponents > 4 || sof.numComponents < 1) { throw new RawDecoderException("Only from 1 to 4 components are supported."); } if (headerLength != 8 + sof.numComponents * 3) { throw new RawDecoderException("Header size mismatch."); } for (int i = 0; i < sof.numComponents; i++) { sof.ComponentInfo[i].componentId = input.ReadByte(); uint subs = input.ReadByte(); frame.ComponentInfo[i].superV = subs & 0xf; frame.ComponentInfo[i].superH = subs >> 4; uint Tq = input.ReadByte(); if (Tq != 0) { throw new RawDecoderException("Quantized components not supported."); } } sof.Initialized = true; }
public Tag(ImageBinaryReader fileStream, int baseOffset) { parent_offset = baseOffset; TagId = (TagType)fileStream.ReadUInt16(); dataType = (TiffDataType)fileStream.ReadUInt16(); if (TagId == TagType.FUJI_RAW_IFD) { if (dataType == TiffDataType.OFFSET) // FUJI - correct type { dataType = TiffDataType.LONG; } } dataCount = fileStream.ReadUInt32(); dataOffset = 0; if (((dataCount * dataType.GetTypeSize() > 4))) { dataOffset = fileStream.ReadUInt32(); } else { GetData(fileStream); int k = (int)dataCount * dataType.GetTypeSize(); if (k < 4) { fileStream.ReadBytes(4 - k); } } /* if (dataOffset < fileStream.BaseStream.Length && dataOffset > 1) * { * long firstPosition = fileStream.Position; * fileStream.Position = dataOffset + parent_offset; * GetData(fileStream); * fileStream.BaseStream.Position = firstPosition; * ¨*/ }
protected void Parse(ImageBinaryReader fileStream) { tagNumber = fileStream.ReadUInt16(); Debug.Assert(tagNumber < UInt16.MaxValue); for (int i = 0; i < tagNumber; i++) { Tag temp = new Tag(fileStream, RelativeOffset); if (!tags.ContainsKey(temp.TagId)) { tags.Add(temp.TagId, temp); } } NextOffset = fileStream.ReadUInt32(); foreach (Tag tag in tags.Values) { if (tag.TagId != TagType.MAKERNOTE && tag.TagId != TagType.MAKERNOTE_ALT) { tag.ReadData(fileStream); } } foreach (Tag tag in tags.Values) { try { //Special tag switch (tag.TagId) { case TagType.DNGPRIVATEDATA: IFD maker_ifd = ParseDngPrivateData(tag); if (maker_ifd != null) { subIFD.Add(maker_ifd); tag.data = null; } break; case TagType.MAKERNOTE: case TagType.MAKERNOTE_ALT: case (TagType)288: Makernote makernote = ParseMakerNote(fileStream, tag, endian); if (makernote != null) { subIFD.Add(makernote); } break; case TagType.OLYMPUSIMAGEPROCESSING: case TagType.FUJI_RAW_IFD: case TagType.NIKONTHUMB: case TagType.SUBIFDS: case TagType.EXIFIFDPOINTER: for (Int32 k = 0; k < tag.dataCount; k++) { subIFD.Add(new IFD(IFDType.Plain, fileStream, tag.GetUInt(k), endian, Depth, RelativeOffset)); } break; case TagType.GPSINFOIFDPOINTER: subIFD.Add(new IFD(IFDType.GPS, fileStream, tag.GetUInt(0), endian, Depth)); break; } } catch (Exception) { } } }
public void Decompress(ImageBinaryReader metadata, uint offset, uint size) { metadata.Position = 0; byte v0 = metadata.ReadByte(); byte v1 = metadata.ReadByte(); int huffSelect = 0; uint split = 0; var pUp1 = new int[2]; var pUp2 = new int[2]; huff[0].UseBigTable = true; if (v0 == 73 || v1 == 88) { metadata.ReadBytes(2110); } if (v0 == 70) { huffSelect = 2; } if (raw.fullSize.ColorDepth == 14) { huffSelect += 3; } pUp1[0] = metadata.ReadInt16(); pUp1[1] = metadata.ReadInt16(); pUp2[0] = metadata.ReadInt16(); pUp2[1] = metadata.ReadInt16(); int max = 1 << raw.fullSize.ColorDepth & 0x7fff; int step = 0, csize = metadata.ReadUInt16(); if (csize > 1) { step = max / (csize - 1); } if (v0 == 68 && v1 == 32 && step > 0) { for (int i = 0; i < csize; i++) { curve[i * step] = metadata.ReadUInt16(); } for (int i = 0; i < max; i++) { curve[i] = (ushort)((curve[i - i % step] * (step - i % step) + curve[i - i % step + step] * (i % step)) / step); } metadata.Position = (562); split = metadata.ReadUInt16(); } else if (v0 != 70 && csize <= 0x4001) { for (int i = 0; i < csize; i++) { curve[i] = metadata.ReadUInt16(); } max = csize; } huff[0].Create(huffSelect); raw.whitePoint = curve[max - 1]; raw.black = curve[0]; raw.table = new TableLookUp(curve, max, true); huff[0].bitPump = new BitPumpMSB(input, offset, size); int pLeft1 = 0, pLeft2 = 0; uint random = huff[0].bitPump.PeekBits(24); for (int y = 0; y < raw.fullSize.dim.height; y++) { if (split != 0 && (y == split)) { huff[0].Create(huffSelect + 1); } pUp1[y & 1] += huff[0].Decode(); pUp2[y & 1] += huff[0].Decode(); pLeft1 = pUp1[y & 1]; pLeft2 = pUp2[y & 1]; long dest = y * raw.fullSize.dim.width; raw.SetWithLookUp((ushort)pLeft1, raw.fullSize.rawView, dest++, ref random); raw.SetWithLookUp((ushort)pLeft2, raw.fullSize.rawView, dest++, ref random); for (int x = 1; x < raw.fullSize.dim.width / 2; x++) { pLeft1 += huff[0].Decode(); pLeft2 += huff[0].Decode(); raw.SetWithLookUp((ushort)pLeft1, raw.fullSize.rawView, dest++, ref random); raw.SetWithLookUp((ushort)pLeft2, raw.fullSize.rawView, dest++, ref random); } } raw.table = null; }