Exemplo n.º 1
0
        public static void Decode12BitRawBEInterlaced(ImageBinaryReader input, Point2D size, Point2D off, Image <ushort> rawImage)
        {
            long half = (size.height + 1) >> 1;
            long y    = 0;

            for (int row = 0; row < size.height; row++)
            {
                y = row % half * 2 + row / half;
                var skip = (y + off.height) * rawImage.fullSize.dim.width + off.width;
                if (y == 1)
                {
                    // The second field starts at a 2048 byte aligment
                    long offset = ((half * size.width * 3 / 2 >> 11) + 1) << 11;
                    if (offset > input.RemainingSize)
                    {
                        throw new IOException("Decode12BitSplitRaw: Trying to jump to invalid offset " + offset);
                    }
                    input.Position = offset;
                }
                for (int x = 0; x < size.width; x += 2)
                {
                    uint g1 = input.ReadByte();
                    uint g2 = input.ReadByte();
                    rawImage.fullSize.rawView[skip + x] = (ushort)((g1 << 4) | (g2 >> 4));
                    uint g3 = input.ReadByte();
                    rawImage.fullSize.rawView[skip + x + 1] = (ushort)(((g2 & 0x0f) << 8) | g3);
                }
            }
        }
Exemplo n.º 2
0
 public static void Decode12BitRawUnpacked(ImageBinaryReader input, Point2D size, Point2D offset, Image <ushort> rawImage)
 {
     for (int y = 0; y < size.height; y++)
     {
         var pos = (y + offset.height) * rawImage.fullSize.dim.width + offset.width;
         for (int x = 0; x < size.width; x += 1)
         {
             uint g1 = input.ReadByte();
             uint g2 = input.ReadByte();
             rawImage.fullSize.rawView[pos + x] = (ushort)(((g2 << 8) | g1) >> 4);
         }
     }
 }
Exemplo n.º 3
0
 public static void Decode14BitRawBEunpacked(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)
         {
             uint g1 = input.ReadByte();
             uint g2 = input.ReadByte();
             rawImage.fullSize.rawView[skip + x] = (ushort)(((g1 & 0x3f) << 8) | g2);
         }
     }
 }
Exemplo n.º 4
0
 public static void Decode12BitRawBE(ImageBinaryReader input, Point2D size, Point2D offset, Image <ushort> rawImage)
 {
     for (int y = 0; y < size.height; y++)
     {
         var pos = (y + offset.height) * rawImage.fullSize.dim.width + offset.width;
         for (int x = 0; x < size.width; x += 2)
         {
             uint g1 = input.ReadByte();
             uint g2 = input.ReadByte();
             rawImage.fullSize.rawView[pos + x] = (ushort)((g1 << 4) | (g2 >> 4));
             uint g3 = input.ReadByte();
             rawImage.fullSize.rawView[pos + x + 1] = (ushort)(((g2 & 0x0f) << 8) | g3);
         }
     }
 }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }