Beispiel #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);
                    }
                }
            }
        }
        public JpegFrameContext GetJpegFrameContext(byte quality, BlockType blockType)
        {
            JpegFrameContext ctx = null;

            switch (blockType)
            {
            case BlockType.Jpeg:
                ctx = normalContexts[quality];
                if (ctx == null)
                {
                    ctx = new JpegFrameContext(quality, Height, Width, JpegQuantizationTable.K1Luminance, JpegQuantizationTable.K2Chrominance);
                    normalContexts[quality] = ctx;
                }
                break;

            case BlockType.JpegDiff:
                ctx = deltaContexts[quality];
                if (ctx == null)
                {
                    ctx = new JpegFrameContext(quality, Height, Width, JpegQuantizationTable.Delta, JpegQuantizationTable.Delta);
                    deltaContexts[quality] = ctx;
                }
                break;
            }
            return(ctx);
        }
 public JpegFrameEncoder(Image image, Stream outStream, JpegFrameContext context)
     : this(new DecodedJpeg(image), outStream, context) /* see overload */ }
 public JpegFrameDecoder(Stream input, JpegFrameContext context)
 {
     this.input   = input;
     this.context = context;
 }