private int WriteBlock(Block block, QuantIndex index, int prevDc) { FDCT.Transform(block); int dc = Round(block[0], 8 * quant[(int)index][0]); EmitHuffRle((HuffIndex)(2 * (int)index + 0), 0, dc - prevDc); HuffIndex h = (HuffIndex)(2 * (int)index + 1); int runLength = 0; for (int zig = 1; zig < Block.blockSize; zig++) { int ac = Round(block[unzig[zig]], 8 * quant[(int)index][zig]); if (ac == 0) { runLength++; } else { while (runLength > 15) { EmitHuff(h, 0xf0); runLength -= 16; } EmitHuffRle(h, runLength, ac); runLength = 0; } } if (runLength > 0) { EmitHuff(h, 0x00); } return(dc); }
private void EmitHuffRLE(HuffIndex index, int runLength, int value) { int a = value; int b = value; if (a < 0) { a = -value; b = value - 1; } uint bt; if (a < 0x100) { bt = BitCountLut[a]; } else { bt = 8 + (uint)BitCountLut[a >> 8]; } this.EmitHuff(index, (int)((uint)(runLength << 4) | bt)); if (bt > 0) { this.Emit((uint)b & (uint)((1 << ((int)bt)) - 1), bt); } }
/// <summary> /// Writes a block of pixel data using the given quantization table, /// returning the post-quantized DC value of the DCT-transformed block. /// The block is in natural (not zig-zag) order. /// </summary> /// <param name="index">The quantization table index.</param> /// <param name="prevDC">The previous DC value.</param> /// <param name="src">Source block</param> /// <param name="tempDest1">Temporal block to be used as FDCT Destination</param> /// <param name="tempDest2">Temporal block 2</param> /// <param name="quant">Quantization table</param> /// <param name="unzigPtr">The 8x8 Unzig block pointer</param> /// <returns> /// The <see cref="int"/> /// </returns> private int WriteBlock( QuantIndex index, int prevDC, Block8x8F *src, Block8x8F *tempDest1, Block8x8F *tempDest2, Block8x8F *quant, int *unzigPtr) { DCT.TransformFDCT(ref *src, ref *tempDest1, ref *tempDest2); Block8x8F.UnzigDivRound(tempDest1, tempDest2, quant, unzigPtr); float *unziggedDestPtr = (float *)tempDest2; int dc = (int)unziggedDestPtr[0]; // Emit the DC delta. this.EmitHuffRLE((HuffIndex)((2 * (int)index) + 0), 0, dc - prevDC); // Emit the AC components. HuffIndex h = (HuffIndex)((2 * (int)index) + 1); int runLength = 0; for (int zig = 1; zig < Block8x8F.ScalarCount; zig++) { int ac = (int)unziggedDestPtr[zig]; if (ac == 0) { runLength++; } else { while (runLength > 15) { this.EmitHuff(h, 0xf0); runLength -= 16; } this.EmitHuffRLE(h, runLength, ac); runLength = 0; } } if (runLength > 0) { this.EmitHuff(h, 0x00); } return(dc); }
/// <summary> /// Writes a block of pixel data using the given quantization table, /// returning the post-quantized DC value of the DCT-transformed block. /// The block is in natural (not zig-zag) order. /// </summary> /// <param name="block">The block to write.</param> /// <param name="index">The quantization table index.</param> /// <param name="prevDC">The previous DC value.</param> /// <returns>The <see cref="int"/></returns> private int WriteBlock(Block block, QuantIndex index, int prevDC) { FDCT.Transform(block); // Emit the DC delta. int dc = Round(block[0], 8 * this.quant[(int)index][0]); this.EmitHuffRLE((HuffIndex)((2 * (int)index) + 0), 0, dc - prevDC); // Emit the AC components. HuffIndex h = (HuffIndex)((2 * (int)index) + 1); int runLength = 0; for (int zig = 1; zig < Block.BlockSize; zig++) { int ac = Round(block[Unzig[zig]], 8 * this.quant[(int)index][zig]); if (ac == 0) { runLength++; } else { while (runLength > 15) { this.EmitHuff(h, 0xf0); runLength -= 16; } this.EmitHuffRLE(h, runLength, ac); runLength = 0; } } if (runLength > 0) { this.EmitHuff(h, 0x00); } return(dc); }
private void EmitHuffRle(HuffIndex index, int runLength, int value) { int a = value; int b = value; if (a < 0){ a = -value; b = value - 1; } uint bt; if (a < 0x100){ bt = bitCount[a]; } else{ bt = 8 + (uint) bitCount[a >> 8]; } EmitHuff(index, (int) ((uint) (runLength << 4) | bt)); if (bt > 0){ Emit((uint) b & (uint) ((1 << ((int) bt)) - 1), bt); } }
private void EmitHuff(HuffIndex index, int value) { uint x = theHuffmanLut[(int) index].values[value]; Emit(x & ((1 << 24) - 1), x >> 24); }
private void EmitHuff(HuffIndex index, int value) { uint x = HuffmanLut.TheHuffmanLut[(int)index].Values[value]; this.Emit(x & ((1 << 24) - 1), x >> 24); }
private void EmitHuff(HuffIndex index, int value, ref byte emitBufferBase) { uint x = HuffmanLut.TheHuffmanLut[(int)index].Values[value]; this.Emit(x & ((1 << 24) - 1), x >> 24, ref emitBufferBase); }