当前位置: 首页>>代码示例>>C#>>正文


C# BitWriter.ToArray方法代码示例

本文整理汇总了C#中BitWriter.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# BitWriter.ToArray方法的具体用法?C# BitWriter.ToArray怎么用?C# BitWriter.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitWriter的用法示例。


在下文中一共展示了BitWriter.ToArray方法的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;
 }
开发者ID:elfinlazz,项目名称:MobiclipDecoder,代码行数:66,代码来源:MobiEncoder.cs

示例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;
        }
开发者ID:elfinlazz,项目名称:MobiclipDecoder,代码行数:60,代码来源:MobiEncoder.cs


注:本文中的BitWriter.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。