private void _initializeQuantizationTableComponent(out QuantizationTableComponent quantizationTableComponent, QuantizationTable settingsQuantizationTable, QuantizationTable defaultQuantizationTable) { if (settingsQuantizationTable != null) { quantizationTableComponent = new QuantizationTableComponent(settingsQuantizationTable); } else { quantizationTableComponent = new QuantizationTableComponent(defaultQuantizationTable); } pnlQuantization.Controls.Add(quantizationTableComponent); quantizationTableComponent.Location = new Point(4, 18); quantizationTableComponent.BringToFront(); }
/// <summary> /// /// </summary> /// <param name="coverImage"></param> /// <param name="quality"></param> /// <param name="m"></param> /// <param name="yTable"></param> /// <param name="chrTable"></param> public JpegImage(Bitmap coverImage, int quality, int m, QuantizationTable yTable, QuantizationTable chrTable) : this(coverImage, quality, m, yTable, chrTable, HuffmanTable.JpegHuffmanTableYDC, HuffmanTable.JpegHuffmanTableYAC, HuffmanTable.JpegHuffmanTableChrDC, HuffmanTable.JpegHuffmanTableChrAC) { }
private int[,] _quantization(double[,] values, QuantizationTable qTable) { int[,] quantizedValues = new int[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { quantizedValues[i, j] = (int)(values[i, j] / qTable.Entries[j * 8 + i]); } } return quantizedValues; }
private void _encodeBlocksSubMethod(double[,] blocks, HuffmanTable DC, HuffmanTable AC, int index, QuantizationTable table) { blocks = _discreteCosineTransform(blocks); int[,] quantiziedBlock = _quantization(blocks, table); _quantizedBlocks.Add(new Tuple<int[,], HuffmanTable, HuffmanTable, int>(quantiziedBlock, DC, AC, index)); }
private void _writeQuantizationSegment(QuantizationTable quantizationTable, byte id) { _jw.WriteBytes(0xff, 0xdb); //DQT header _jw.WriteBytes(0x00, 0x43); //Length of segment id = (byte)(id & 0x07); _jw.WriteBytes(id); //will output 0000 0xxx where the first nipple defines precission, and the second defines id _jw.WriteBytes(quantizationTable.ZigzagEntries); }
/// <summary> /// /// </summary> /// <param name="coverImage"></param> /// <param name="quality"></param> /// <param name="m"></param> /// <param name="yTable"></param> /// <param name="chrTable"></param> /// <param name="huffmanYDC"></param> /// <param name="huffmanYAC"></param> /// <param name="huffmanChrDC"></param> /// <param name="huffmanChrAC"></param> public JpegImage(Bitmap coverImage, int quality, int m, QuantizationTable yTable, QuantizationTable chrTable, HuffmanTable huffmanYDC, HuffmanTable huffmanYAC, HuffmanTable huffmanChrDC, HuffmanTable huffmanChrAC) { if (coverImage == null) { throw new ArgumentNullException(); } CoverImage = coverImage; YQuantizationTable = yTable.Scale(quality); ChrQuantizationTable = chrTable.Scale(quality); M = m; YDCHuffman = huffmanYDC; YACHuffman = huffmanYAC; ChrDCHuffman = huffmanChrDC; ChrACHuffman = huffmanChrAC; _calculateCosineCoefficients(); }
public static void ResetSettingsToDefault() { Quality = DefaultQuality; MValue = DefaultMValue; QualityLocked = false; LSBMethodSelected = false; HuffmanTableYAC = HuffmanTable.JpegHuffmanTableYAC; HuffmanTableYDC = HuffmanTable.JpegHuffmanTableYDC; HuffmanTableChrAC = HuffmanTable.JpegHuffmanTableChrAC; HuffmanTableChrDC = HuffmanTable.JpegHuffmanTableChrDC; QuantizationTableY = QuantizationTable.JpegDefaultYTable; QuantizationTableChr = QuantizationTable.JpegDefaultChrTable; }
//Returns default table if the table made from the tablecomponent is the same as defaultTable, custom table if they are different. //Doing this prevents an error from ocuring when changing quality while using a 'default' non-default table private static QuantizationTable _defaultOrCustomQuantizationTable(QuantizationTable customQuantizationTable, QuantizationTable defaultTable) { QuantizationTable q; if (customQuantizationTable.Equals(defaultTable)) { q = defaultTable; } else { q = customQuantizationTable; } return q; }
private void _saveSettingsInternally() { Quality = tbarQualitySlider.Value; if (_mValue != 0) { MValue = _mValue; } else { MValue = 4; } if (rdioGTMethod.Checked) { LSBMethodSelected = false; } else { LSBMethodSelected = true; } HuffmanTableYAC = _defaultOrCustomHuffmanTable(HuffmanTableComponentYAC.SaveTable(), HuffmanTable.JpegHuffmanTableYAC); HuffmanTableYDC = _defaultOrCustomHuffmanTable(HuffmanTableComponentYDC.SaveTable(), HuffmanTable.JpegHuffmanTableYDC); HuffmanTableChrAC = _defaultOrCustomHuffmanTable(HuffmanTableComponentChrAC.SaveTable(), HuffmanTable.JpegHuffmanTableChrAC); HuffmanTableChrDC = _defaultOrCustomHuffmanTable(HuffmanTableComponentChrDC.SaveTable(), HuffmanTable.JpegHuffmanTableChrDC); QuantizationTableY = _defaultOrCustomQuantizationTable(QuantizationTableComponentY.SaveTable(), QuantizationTable.JpegDefaultYTable); QuantizationTableChr = _defaultOrCustomQuantizationTable(QuantizationTableComponentChr.SaveTable(), QuantizationTable.JpegDefaultChrTable); }
private static void _saveQuantizationTableToFile(QuantizationTable quantizationTable, string filePath) { if (quantizationTable != null) { File.WriteAllText(filePath, quantizationTable.ToString()); } }
//Uses the QuantizationTable.Fromstring() method to create a quantization table from a string optained from a file. private static void _loadQuantizationTableFromFile(out QuantizationTable quantizationTable, string filePath) { if (File.Exists(filePath)) { string input = File.ReadAllText(filePath); quantizationTable = QuantizationTable.FromString(input); } else { quantizationTable = null; } }
private static short[,] _quantization(float[,] values, QuantizationTable qTable) { short[,] quantizedValues = new short[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { quantizedValues[i, j] = (short)(values[i, j] / qTable.Entries[j * 8 + i]); } } return quantizedValues; }
private static short[,] _encodeBlocksSubMethod(float[,] blocks, QuantizationTable table) { blocks = _discreteCosineTransform(blocks); return _quantization(blocks, table); }
private void _writeQuantizationSegment(QuantizationTable quantizationTable, byte id) { //DQT header _jw.WriteBytes(0xff, 0xdb); //Length of segment _jw.WriteBytes(0x00, 0x43); //0000 0xxx where the first nipple defines precision and the second defines ID id = (byte)(id & 0x07); _jw.WriteBytes(id); //The QTable itself. In zig-zag format _jw.WriteBytes(quantizationTable.ZigzagEntries); }
/// <summary> /// /// </summary> /// <param name="coverImage"></param> /// <param name="quality"></param> /// <param name="m"></param> /// <param name="yTable"></param> /// <param name="chrTable"></param> /// <param name="huffmanYDC"></param> /// <param name="huffmanYAC"></param> /// <param name="huffmanChrDC"></param> /// <param name="huffmanChrAC"></param> public JpegImage(Bitmap coverImage, int quality, byte m, QuantizationTable yTable, QuantizationTable chrTable, HuffmanTable huffmanYDC, HuffmanTable huffmanYAC, HuffmanTable huffmanChrDC, HuffmanTable huffmanChrAC) { if (coverImage == null) { throw new ArgumentNullException(); } CoverImage = coverImage; YQuantizationTable = yTable.Scale(quality); ChrQuantizationTable = chrTable.Scale(quality); M = m; YDCHuffman = huffmanYDC; YACHuffman = huffmanYAC; ChrDCHuffman = huffmanChrDC; ChrACHuffman = huffmanChrAC; _originalCoverWidth = coverImage.Width; _originalCoverHeight = coverImage.Height; // Calculate coefficients that are used in DCT _calculateCosineCoefficients(); }