Exemple #1
0
        public void StartDecoder(uint offset, uint size)
        {
            if (!input.IsValid(offset, size))
            {
                throw new RawDecoderException("Start offset plus size is longer than file. Truncated file.");
            }
            if ((int)offX >= raw.fullSize.dim.width)
            {
                throw new RawDecoderException("X offset outside of image");
            }
            if ((int)offY >= raw.fullSize.dim.height)
            {
                throw new RawDecoderException("Y offset outside of image");
            }

            // JPEG is big endian
            if (Common.GetHostEndianness() == Endianness.Big)
            {
                input = new ImageBinaryReader(input.BaseStream, offset);
            }
            else
            {
                input = new ImageBinaryReaderBigEndian(input.BaseStream, offset);
            }

            if (GetNextMarker(false) != JpegMarker.SOI)
            {
                throw new RawDecoderException("Image did not start with SOI. Probably not an LJPEG");
            }

            bool moreImage = true;

            while (moreImage)
            {
                JpegMarker m = GetNextMarker(true);
                switch (m)
                {
                case JpegMarker.DQT:
                    throw new RawDecoderException("Not a valid RAW file.");

                case JpegMarker.DHT:
                    //          _RPT0(0,"Found DHT marker\n");
                    ParseDHT();
                    break;

                case JpegMarker.SOS:
                    //          _RPT0(0,"Found SOS marker\n");
                    ParseSOS();
                    break;

                case JpegMarker.Sof3:
                    //          _RPT0(0,"Found SOF 3 marker:\n");
                    ParseSOF(frame);
                    break;

                case JpegMarker.EOI:
                    //          _RPT0(0,"Found EOI marker\n");
                    moreImage = false;
                    break;

                case JpegMarker.DRI:  //          _RPT0(0,"Found DRI marker\n");
                case JpegMarker.App0: //          _RPT0(0,"Found APP0 marker\n");
                default:              // _RPT1(0, "Found marker:0x%x. Skipping\n", m);
                                      // Just let it skip to next marker
                    break;
                }
            }
        }