Example #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);
                    }
                }
            }
        }
Example #2
0
        public void Encode(byte jpegQuality)
        {
            JpegQuality = jpegQuality;
            LoadSubsampledRaster(BlockType == BlockType.Jpeg ? RgbaRaw : RgbaDelta);
            var image = new Image(colorModel, rasterBuffer);

            EncodedStream = new MemoryStream();
            var ctx     = contextFactory.GetJpegFrameContext(JpegQuality, BlockType);
            var encoder = new JpegFrameEncoder(image, EncodedStream, ctx);

            encoder.Encode();
        }