internal static short[] GetCoefficients(BitReader bReader, ImgInfo imgInfo, int compIndex, int numCoefs) { var coefZig = new short[numCoefs]; int acIndex = imgInfo.components[compIndex].acHuffmanTable; int dcIndex = imgInfo.components[compIndex].dcHuffmanTable; // DC coefficient uint runAmplitude = Huffman.ReadRunAmplitude(bReader, imgInfo.huffmanTables[0, dcIndex]); uint run; // = runAmplitude >> 4; // Upper nybble uint amplitude = runAmplitude & 0xf; // Lower nybble coefZig[0] = (short)(Huffman.ReadCoefValue(bReader, amplitude) + imgInfo.deltaDc[compIndex]); imgInfo.deltaDc[compIndex] = coefZig[0]; // AC coefficients uint pos = 0; while (pos < blkSize * blkSize - 1) { runAmplitude = Huffman.ReadRunAmplitude(bReader, imgInfo.huffmanTables[1, acIndex]); // 0x00 is End of Block if (runAmplitude == 0x00) { break; } run = runAmplitude >> 4; amplitude = runAmplitude & 0xf; pos += run + 1; if (pos >= blkSize * blkSize) { break; } coefZig[pos] = Huffman.ReadCoefValue(bReader, amplitude); } return(coefZig); }
static string ToBinary(Huffman.CodeInfo number) { string numStr = string.Empty; while (number.length > 0) { numStr = (number.code & 1) + numStr; number.code >>= 1; number.length--; } return numStr; }