private void GetQuantizeds(QuantizeMethod quantizeMethod, int quantizeParameter, out double[,] quantizedY, out double[,] quantizedCb, out double[,] quantizedCr) { quantizedY = new double[256, 256]; quantizedCb = new double[128, 128]; quantizedCr = new double[128, 128]; if (quantizeMethod == QuantizeMethod.ZigZag) { quantizedY = DctY.GetQuantizeUsingZigZagMethod(quantizeParameter); quantizedCb = DctCb.GetQuantizeUsingZigZagMethod(quantizeParameter); quantizedCr = DctCr.GetQuantizeUsingZigZagMethod(quantizeParameter); } if (quantizeMethod == QuantizeMethod.Method2) { quantizedY = DctY.GetQuantizeUsingMethod2(quantizeParameter); quantizedCb = DctCb.GetQuantizeUsingMethod2(quantizeParameter); quantizedCr = DctCr.GetQuantizeUsingMethod2(quantizeParameter); } if (quantizeMethod == QuantizeMethod.JpegQuality) { quantizedY = DctY.GetQuantizeUsingJpegQualityMethod(quantizeParameter); quantizedCb = DctCb.GetQuantizeUsingJpegQualityMethod(quantizeParameter); quantizedCr = DctCr.GetQuantizeUsingJpegQualityMethod(quantizeParameter); } }
public void DecodeImage(IDownSampler downSampler, QuantizeMethod quantizeMethod, int quantizeParameter) { GetQuantizeds(quantizeMethod, quantizeParameter, out var quantizedY, out var quantizedCb, out var quantizedCr); var iQuantizedY = new double[256, 256]; var iQuantizedCb = new double[128, 128]; var iQuantizedCr = new double[128, 128]; if (quantizeMethod == QuantizeMethod.ZigZag) { iQuantizedY = quantizedY.GetIQuantizeUsingZigZagMethod(quantizeParameter); iQuantizedCb = quantizedCb.GetIQuantizeUsingZigZagMethod(quantizeParameter); iQuantizedCr = quantizedCr.GetIQuantizeUsingZigZagMethod(quantizeParameter); } if (quantizeMethod == QuantizeMethod.Method2) { iQuantizedY = quantizedY.GetIQuantizeUsingMethod2(quantizeParameter); iQuantizedCb = quantizedCb.GetIQuantizeUsingMethod2(quantizeParameter); iQuantizedCr = quantizedCr.GetIQuantizeUsingMethod2(quantizeParameter); } if (quantizeMethod == QuantizeMethod.JpegQuality) { iQuantizedY = quantizedY.GetIQuantizeUsingJpegQualityMethod(quantizeParameter); iQuantizedCb = quantizedCb.GetIQuantizeUsingJpegQualityMethod(quantizeParameter); iQuantizedCr = quantizedCr.GetIQuantizeUsingJpegQualityMethod(quantizeParameter); } var iDctY = dct.GetIDiscreteCosineTransform(iQuantizedY); var iDctCb = dct.GetIDiscreteCosineTransform(iQuantizedCb); var iDctCr = dct.GetIDiscreteCosineTransform(iQuantizedCr); var upSampledCb = downSampler.GetUpSampledMatrix(iDctCb); var upSampledCr = downSampler.GetUpSampledMatrix(iDctCr); var yCbCrPixels = new YCbCrPixel[256, 256]; for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { yCbCrPixels[i, j] = new YCbCrPixel { Y = (byte)iDctY[i, j], Cb = (byte)upSampledCb[i, j], Cr = (byte)upSampledCr[i, j] }; } } ReconstructedImage = GetBitmapFromYCbCrPixels(yCbCrPixels); }
private void buttonLast4Steps_Click(object sender, EventArgs e) { QuantizeMethod quantizeMethod = QuantizeMethod.Method2; int quantizeParameter = 0; if (radioButtonMethod2.Checked) { quantizeMethod = QuantizeMethod.Method2; quantizeParameter = (int)numericUpDownR.Value; } if (radioButtonJpegQ.Checked) { quantizeMethod = QuantizeMethod.JpegQuality; quantizeParameter = (int)numericUpDownJpeg.Value; } jpegEncoder.DecodeImage(new DownSampler411(), quantizeMethod, quantizeParameter); pictureBoxDecodedImage.Image = jpegEncoder.ReconstructedImage; }