Пример #1
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (CbgMetaData)info as CbgMetaData;

            using (var reader = new CbgReader(stream.AsStream, meta))
            {
                reader.Unpack();
                return(ImageData.Create(meta, reader.Format, null, reader.Data, reader.Stride));
            }
        }
Пример #2
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as CbgMetaData;

            if (null == meta)
            {
                throw new ArgumentException("CompressedBGFormat.Read should be supplied with CbgMetaData", "info");
            }
            using (var reader = new CbgReader(stream, meta))
            {
                reader.Unpack();
                return(ImageData.Create(meta, reader.Format, null, reader.Data, reader.Stride));
            }
        }
Пример #3
0
        public void UnpackBlock(int offset, int length, int dst)
        {
            using (var input = new MemoryStream(this.Input, offset, length))
                using (var reader = new MsbBitStream(input))
                {
                    int block_size = CbgReader.ReadInteger(input);
                    if (-1 == block_size)
                    {
                        return;
                    }
                    var color_data = new short[block_size];
                    int acc        = 0;
                    for (int i = 0; i < block_size && input.Position < input.Length; i += 64)
                    {
                        int count = Tree1.DecodeToken(reader);
                        if (count != 0)
                        {
                            int v = reader.GetBits(count);
                            if (0 == (v >> (count - 1)))
                            {
                                v = (-1 << count | v) + 1;
                            }
                            acc += v;
                        }
                        color_data[i] = (short)acc;
                    }

                    if (0 != (reader.CacheSize & 7))
                    {
                        reader.GetBits(reader.CacheSize & 7);
                    }

                    for (int i = 0; i < block_size && input.Position < input.Length; i += 64)
                    {
                        int index = 1;
                        while (index < 64 && input.Position < input.Length)
                        {
                            int code = Tree2.DecodeToken(reader);
                            if (0 == code)
                            {
                                break;
                            }
                            if (0xF == code)
                            {
                                index += 0x10;
                                continue;
                            }
                            index += code & 0xF;
                            if (index >= block_fill_order.Length)
                            {
                                break;
                            }
                            code >>= 4;
                            int v = reader.GetBits(code);
                            if (code != 0 && 0 == (v >> (code - 1)))
                            {
                                v = (-1 << code | v) + 1;
                            }
                            color_data[i + block_fill_order[index]] = (short)v;
                            ++index;
                        }
                    }
                    if (8 == BPP)
                    {
                        DecodeGrayscale(color_data, dst);
                    }
                    else
                    {
                        DecodeRGB(color_data, dst);
                    }
                }
        }
Пример #4
0
 public override ImageData Read(Stream stream, ImageMetaData info)
 {
     var meta = info as CbgMetaData;
     if (null == meta)
         throw new ArgumentException ("CompressedBGFormat.Read should be supplied with CbgMetaData", "info");
     using (var reader = new CbgReader (stream, meta))
     {
         reader.Unpack();
         return ImageData.Create (meta, reader.Format, null, reader.Data, reader.Stride);
     }
 }