Ejemplo n.º 1
0
        public void JpegFrameEncoderDecoderTest()
        {
            // Encode and decode a basic raster structure.
            var colorModel = new ColorModel();

            colorModel.ColorSpace = ColorSpace.YCbCr;
            colorModel.Opaque     = true;
            byte[][][] originalRaster = GetRaster();
            var        image          = new Image(colorModel, originalRaster);
            var        stream         = new MemoryStream();
            var        ctx            = new JpegFrameContext(50, height, width);
            var        encoder        = new JpegFrameEncoder(image, stream, ctx);

            encoder.Encode();
            stream.Seek(0, SeekOrigin.Begin);
            var decoder = new JpegFrameDecoder(stream, ctx);

            byte[][][] decodedRaster = Image.GetRaster(width, height, 3);
            decoder.Decode(decodedRaster);

            // Check that the returned raster structure looks something like what we passed in.
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    for (int k = 0; k < height; k++)
                    {
                        // Tune this.
                        int diff = Math.Abs(decodedRaster[i][j][k] - originalRaster[i][j][k]);
                        Assert.IsTrue(diff < 5);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Decode()
        {
            // Get the raster image.
            Debug.Assert(JpegQuality > 0 && JpegQuality <= 100);
            EncodedStream.Position = 0;
            var ctx     = contextFactory.GetJpegFrameContext(JpegQuality, BlockType);
            var decoder = new JpegFrameDecoder(EncodedStream, ctx);

            decoder.Decode(rasterBuffer);
            GetUpsampledRgba(rasterBuffer, BlockType == BlockType.Jpeg ? RgbaRaw : RgbaDelta);
        }