本文整理汇总了C#中BitWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# BitWriter.Flush方法的具体用法?C# BitWriter.Flush怎么用?C# BitWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitWriter
的用法示例。
在下文中一共展示了BitWriter.Flush方法的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: EncodeIntra
private byte[] EncodeIntra(Bitmap Frame)
{
BitmapData d = Frame.LockBits(new Rectangle(0, 0, Frame.Width, Frame.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
//Setup the macroblocks
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);
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);
BitWriter b = new BitWriter();
b.WriteBits(1, 1);//Interframe
b.WriteBits(1, 1);//YUV format
//TODO: determine table (when we actually use it...)
b.WriteBits(0, 1);//Table
b.WriteBits((uint)Quantizer, 6);//Quantizer
for (int y = 0; y < Height; y += 16)
{
for (int x = 0; x < Width; x += 16)
{
MacroBlock curblock = MacroBlocks[y / 16][x / 16];
//Todo use predicted prediction mode
/*if (x > 0 && y > 0)
{
int r12 = MacroBlocks[y / 16 - 1][x / 16].YPredictionMode;
int r6 = MacroBlocks[y / 16][x / 16 - 1].YPredictionMode;
if (r12 > r6) r12 = r6;
if (r12 == 9) r12 = 3;
r6 = r3 >> 28;
if (r6 >= r12) r6++;
int r7;
if (r6 < 9)
{
r12 = r6;
r7 = 4;
}
else r7 = 1;
r3 <<= r7;
nrBitsRemaining -= r7;
}*/
b.WriteBits(0, 1);//Func
EncodeBlockIntra(curblock, b);
}
}
b.WriteBits(0, 16);
b.Flush();
byte[] result = b.ToArray();
return result;
}