예제 #1
0
        public JpegFrameContext(byte quality, ushort height, ushort width,
                                JpegQuantizationTable luminance = null, JpegQuantizationTable chrominance = null, byte[] hSampFactor = null, byte[] vSampFactor = null)
        {
            Quality = quality;
            Height  = height;
            Width   = width;

            HSampFactor = hSampFactor ?? FrameDefaults.HSampFactor;
            VSampFactor = vSampFactor ?? FrameDefaults.VSampFactor;
            Luminance   = luminance ?? JpegQuantizationTable.K1Luminance;
            Chrominance = chrominance ?? JpegQuantizationTable.K2Chrominance;

            DCT          = new DCT(Quality, Luminance, Chrominance);
            HuffmanTable = HuffmanTable.GetHuffmanTable(null);

            JpegFrame                = new JpegFrame();
            JpegFrame.ScanLines      = height;
            JpegFrame.SamplesPerLine = width;
            JpegFrame.Precision      = 8;                                // Number of bits per sample
            JpegFrame.ComponentCount = FrameDefaults.NumberOfComponents; // Number of components (Y, Cb, Cr)

            var qTables = new JpegQuantizationTable[2];

            qTables[0] = JpegQuantizationTable.GetJpegQuantizationTable(DCT.quantum[0]);
            qTables[1] = JpegQuantizationTable.GetJpegQuantizationTable(DCT.quantum[1]);

            for (byte i = 0; i < FrameDefaults.NumberOfComponents; i++)
            {
                JpegFrame.AddComponent(FrameDefaults.CompId[i], HSampFactor[i], VSampFactor[i], qTables[FrameDefaults.QtableNumber[i]]);
                JpegFrame.SetHuffmanTables(FrameDefaults.CompId[i], JpegFrame.AcTables[FrameDefaults.ACtableNumber[i]], JpegFrame.DcTables[FrameDefaults.DCtableNumber[i]]);
            }
        }
예제 #2
0
        /// <summary>
        /// Encodes a JPEG, preserving the colorspace and metadata of the input JPEG.
        /// </summary>
        /// <param name="decodedJpeg">Decoded Jpeg to start with.</param>
        /// <param name="quality">Quality of the image from 0 to 100.  (Compression from max to min.)</param>
        /// <param name="outStream">Stream where the result will be placed.</param>
        public JpegEncoder(DecodedJpeg decodedJpeg, short quality, Stream outStream)
        {
            input = decodedJpeg;

            /* This encoder requires YCbCr */
            input.Image.ChangeColorSpace(ColorSpace.YCbCr);

            this.quality = quality;

            height         = input.Image.Height;
            width          = input.Image.Width;
            this.outStream = outStream;
            dct            = new DCT(quality);
            huf            = HuffmanTable.GetHuffmanTable(null);
        }