本文整理汇总了C#中BitWriter.WriteVarIntUnsigned方法的典型用法代码示例。如果您正苦于以下问题:C# BitWriter.WriteVarIntUnsigned方法的具体用法?C# BitWriter.WriteVarIntUnsigned怎么用?C# BitWriter.WriteVarIntUnsigned使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitWriter
的用法示例。
在下文中一共展示了BitWriter.WriteVarIntUnsigned方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncodePrediction
private unsafe byte[] EncodePrediction(Bitmap Frame)
{
//We'll just look if there are blocks that are 100% the same first
BitmapData d = Frame.LockBits(new Rectangle(0, 0, Frame.Width, Frame.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData prev = PastFrames[1].LockBits(new Rectangle(0, 0, Frame.Width, Frame.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
for (int y = 0; y < Height; y += 16)
{
for (int x = 0; x < Width; x += 16)
{
MacroBlocks[y / 16][x / 16] = new MacroBlock(d, x, y);
bool same = true;
for (int y2 = 0; y2 < 16; y2++)
{
ulong* pA = (ulong*)(((byte*)d.Scan0) + (y + y2) * d.Stride + x * 4);
ulong* pB = (ulong*)(((byte*)prev.Scan0) + (y + y2) * prev.Stride + x * 4);
for (int x2 = 0; x2 < 16; x2+=2)
{
ulong color = *pA++;
ulong color2 = *pB++;
if (color != color2)
{
same = false;
break;
}
}
if (!same) break;
}
if (same) MacroBlocks[y / 16][x / 16].Predict = true;
else
{
Analyzer.ConfigureBlockY(this, MacroBlocks[y / 16][x / 16]);
int blocktype2 = Analyzer.AnalyzeBlockUV(this, MacroBlocks[y / 16][x / 16]);
MacroBlocks[y / 16][x / 16].UVPredictionMode = blocktype2;
MacroBlocks[y / 16][x / 16].UVUseComplex8x8[0] = true;
MacroBlocks[y / 16][x / 16].UVUseComplex8x8[1] = true;
MacroBlocks[y / 16][x / 16].SetupDCTs(this);
}
}
}
Frame.UnlockBits(d);
PastFrames[1].UnlockBits(prev);
BitWriter b = new BitWriter();
b.WriteBits(0, 1);//Interframe
b.WriteVarIntSigned(0);
for (int y = 0; y < Height; y += 16)
{
for (int x = 0; x < Width; x += 16)
{
MacroBlock curblock = MacroBlocks[y / 16][x / 16];
if (curblock.Predict)
{
b.WriteBits(1, 1);
b.WriteVarIntUnsigned(0);
}
else
{
b.WriteBits(0xE >> 1, 5);
EncodeBlockIntra(curblock, b);
}
}
}
b.WriteBits(0, 16);
b.Flush();
byte[] result = b.ToArray();
return result;
}
示例2: EncodeBlockIntra
private void EncodeBlockIntra(MacroBlock Block, BitWriter b)
{
uint dctmask =
(Block.YUseComplex8x8[0] ? 1u : 0) |
((Block.YUseComplex8x8[1] ? 1u : 0) << 1) |
((Block.YUseComplex8x8[2] ? 1u : 0) << 2) |
((Block.YUseComplex8x8[3] ? 1u : 0) << 3) |
((Block.UVUseComplex8x8[0] ? 1u : 0) << 4) |
((Block.UVUseComplex8x8[1] ? 1u : 0) << 5);
b.WriteVarIntUnsigned(REV_byte_115FC4[dctmask]);
b.WriteBits((uint)Block.YPredictionMode, 3);//Block type
for (int y2 = 0; y2 < 2; y2++)
{
for (int x2 = 0; x2 < 2; x2++)
{
if (Block.YUseComplex8x8[x2 + y2 * 2] && !Block.YUse4x4[x2 + y2 * 2])
{
b.WriteBits(1, 1);//Don't use 4x4 blocks
EncodeDCT(Block.YDCT8x8[x2 + y2 * 2], 0, b);
}
else if (Block.YUseComplex8x8[x2 + y2 * 2] && Block.YUse4x4[x2 + y2 * 2])
{
uint dctmask2 =
(Block.YUseDCT4x4[x2 + y2 * 2][0] ? 1u : 0) |
((Block.YUseDCT4x4[x2 + y2 * 2][1] ? 1u : 0) << 1) |
((Block.YUseDCT4x4[x2 + y2 * 2][2] ? 1u : 0) << 2) |
((Block.YUseDCT4x4[x2 + y2 * 2][3] ? 1u : 0) << 3);
b.WriteVarIntUnsigned(REV_byte_1164F4[dctmask2]);
for (int y3 = 0; y3 < 2; y3++)
{
for (int x3 = 0; x3 < 2; x3++)
{
if (Block.YUseDCT4x4[x2 + y2 * 2][x3 + y3 * 2])
EncodeDCT(Block.YDCT4x4[x2 + y2 * 2][x3 + y3 * 2], 0, b);
}
}
}
}
}
b.WriteBits((uint)Block.UVPredictionMode, 3);//Block type
for (int q = 0; q < 2; q++)
{
if (Block.UVUseComplex8x8[q] && !Block.UVUse4x4[q])
{
b.WriteBits(1, 1);//Don't use 4x4 blocks
EncodeDCT(Block.UVDCT8x8[q], 0, b);
}
}
}