Beispiel #1
0
        private void DecodeCryptedUncompressed()
        {
            var data = ifd.GetIFDsWithTag(TagType.IMAGEWIDTH);

            if (data.Count == 0)
            {
                throw new RawDecoderException("ARW: SRF format, couldn't find width/height");
            }
            var raw = data[0];

            var  size = new Point2D(raw.GetEntry(TagType.IMAGEWIDTH).GetUInt(0), raw.GetEntry(TagType.IMAGELENGTH).GetUInt(0));
            uint len  = (size.Area * 2);

            // Constants taken from dcraw
            uint offtemp  = 862144;
            uint key_off  = 200896;
            uint head_off = 164600;

            // Replicate the dcraw contortions to get the "decryption" key
            base.reader.Position = key_off;;
            int offset = base.reader.ReadByte() * 4;

            base.reader.Position = key_off + offset;
            byte[] d   = base.reader.ReadBytes(4);
            uint   key = (((uint)(d[0]) << 24) | ((uint)(d[1]) << 16) | ((uint)(d[2]) << 8) | d[3]);

            base.reader.Position = head_off;
            byte[] head = base.reader.ReadBytes(40);

            SonyDecrypt(head, 10, key);

            for (int i = 26; i-- > 22;)
            {
                key = key << 8 | head[i];
            }

            // "Decrypt" the whole image buffer in place
            base.reader.Position = offtemp;
            byte[] imageData = base.reader.ReadBytes((int)len);

            SonyDecrypt(imageData, len / 4, key);

            // And now decode as a normal 16bit raw
            rawImage.fullSize.dim = new Point2D(size);
            rawImage.Init(false);
            using (ImageBinaryReader reader = new ImageBinaryReader(imageData, len))
            {
                RawDecompressor.Decode16BitRawUnpacked(reader, size, new Point2D(), rawImage);
            }
        }
Beispiel #2
0
        void DecodeUncompressed(IFD raw)
        {
            uint width  = raw.GetEntry(TagType.IMAGEWIDTH).GetUInt(0);
            uint height = raw.GetEntry(TagType.IMAGELENGTH).GetUInt(0);
            uint off    = raw.GetEntry(TagType.STRIPOFFSETS).GetUInt(0);

            rawImage.fullSize.dim = new Point2D(width, height);
            rawImage.Init(false);
            ImageBinaryReader input = new ImageBinaryReader(reader.BaseStream, off);

            /*
             *  RawDecompressor.Decode14BitRawBEunpacked(input, width, height, rawImage);
             */
            RawDecompressor.Decode16BitRawUnpacked(input, new Point2D(width, height), new Point2D(), rawImage);
        }
Beispiel #3
0
        public override void DecodeRaw()
        {
            List <IFD> data = ifd.GetIFDsWithTag(TagType.FUJI_STRIPOFFSETS);

            if (data.Count <= 0)
            {
                throw new RawDecoderException("Fuji decoder: Unable to locate raw IFD");
            }

            IFD  raw    = data[0];
            uint height = 0;
            uint width  = 0;

            var dim = raw.GetEntry(TagType.FUJI_RAWIMAGEFULLHEIGHT);

            if (dim != null)
            {
                height = dim.GetUInt(0);
                width  = raw.GetEntry(TagType.FUJI_RAWIMAGEFULLWIDTH).GetUInt(0);
            }
            else
            {
                Tag wtag = raw.GetEntryRecursive(TagType.IMAGEWIDTH);
                if (wtag != null)
                {
                    if (wtag.dataCount < 2)
                    {
                        throw new RawDecoderException("Fuji decoder: Size array too small");
                    }
                    height = wtag.GetUShort(0);
                    width  = wtag.GetUShort(1);
                }
            }

            Tag e = raw.GetEntryRecursive(TagType.FUJI_LAYOUT);

            if (e != null)
            {
                if (e.dataCount < 2)
                {
                    throw new RawDecoderException("Fuji decoder: Layout array too small");
                }
                byte[] layout = e.GetByteArray();
                //alt_layout = !(layout[0] >> 7);
            }

            if (width <= 0 || height <= 0)
            {
                throw new RawDecoderException("RAF decoder: Unable to locate image size");
            }

            Tag offsets = raw.GetEntry(TagType.FUJI_STRIPOFFSETS);
            Tag counts  = raw.GetEntry(TagType.FUJI_STRIPBYTECOUNTS);

            if (offsets.dataCount != 1 || counts.dataCount != 1)
            {
                throw new RawDecoderException("RAF Decoder: Multiple Strips found: " + offsets.dataCount + " " + counts.dataCount);
            }

            int off   = offsets.GetInt(0);
            int count = counts.GetInt(0);

            ushort bps    = 12;
            var    bpsTag = raw.GetEntryRecursive(TagType.FUJI_BITSPERSAMPLE) ?? raw.GetEntryRecursive(TagType.BITSPERSAMPLE);

            if (bpsTag != null)
            {
                bps = bpsTag.GetUShort(0);
            }
            else
            {
                rawImage.errors.Add("BPS not found");
            }
            rawImage.fullSize.ColorDepth = bps;

            // x-trans sensors report 14bpp, but data isn't packed so read as 16bpp
            if (bps == 14)
            {
                bps = 16;
            }

            // Some fuji SuperCCD cameras include a second raw image next to the first one
            // that is identical but darker to the first. The two combined can produce
            // a higher dynamic range image. Right now we're ignoring it.
            //bool double_width = hints.ContainsKey("double_width_unpacked");

            rawImage.fullSize.dim = new Point2D(width, height);
            rawImage.Init(false);
            ImageBinaryReader input = new ImageBinaryReader(stream, (uint)(off + raw.RelativeOffset));
            Point2D           pos   = new Point2D(0, 0);

            if (count * 8 / (width * height) < 10)
            {
                throw new RawDecoderException("Don't know how to decode compressed images");
            }
            else if (ifd.endian == Endianness.Big)
            {
                RawDecompressor.Decode16BitRawUnpacked(input, new Point2D(width, height), pos, rawImage);
            }
            else
            {
                //       RawDecompressor.ReadUncompressedRaw(input, rawImage.raw.dim, pos, width * bps / 8, bps, BitOrder.Jpeg32, rawImage);
                RawDecompressor.ReadUncompressedRaw(input, new Point2D(width, height), pos, width * bps / 8, bps, BitOrder.Plain, rawImage);
            }
        }