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


C# BitArray.GetNumeral方法代码示例

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


在下文中一共展示了BitArray.GetNumeral方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DecodeGifLZW

    /// <summary>
    /// GIF LZW decode
    /// </summary>
    /// <param name="compData">LZW compressed data</param>
    /// <param name="lzwMinimumCodeSize">LZW minimum code size</param>
    /// <param name="needDataSize">Need decoded data size</param>
    /// <returns>Decoded data array</returns>
    static byte[] DecodeGifLZW (List<byte> compData, int lzwMinimumCodeSize, int needDataSize)
    {
        int clearCode = 0;
        int finishCode = 0;

        // Initialize dictionary
        Dictionary<int, string> dic = new Dictionary<int, string> ();
        int lzwCodeSize = 0;
        InitDictionary (dic, lzwMinimumCodeSize, out lzwCodeSize, out clearCode, out finishCode);

        // Convert to bit array
        byte[] compDataArr = compData.ToArray ();
        var bitData = new BitArray (compDataArr);

        byte[] output = new byte[needDataSize];
        int outputAddIndex = 0;

        string prevEntry = null;

        bool dicInitFlag = false;

        int bitDataIndex = 0;

        // LZW decode loop
        while (bitDataIndex < bitData.Length) {
            if (dicInitFlag) {
                InitDictionary (dic, lzwMinimumCodeSize, out lzwCodeSize, out clearCode, out finishCode);
                dicInitFlag = false;
            }

            int key = bitData.GetNumeral (bitDataIndex, lzwCodeSize);

            string entry = null;

            if (key == clearCode) {
                // Clear (Initialize dictionary)
                dicInitFlag = true;
                bitDataIndex += lzwCodeSize;
                prevEntry = null;
                continue;

            } else if (key == finishCode) {
                // Exit
                Debug.LogWarning ("early stop code. bitDataIndex:" + bitDataIndex + " lzwCodeSize:" + lzwCodeSize + " key:" + key + " dic.Count:" + dic.Count);
                break;

            } else if (dic.ContainsKey (key)) {
                // Output from dictionary
                entry = dic[key];

            } else if (key >= dic.Count) {
                if (prevEntry != null) {
                    // Output from estimation
                    entry = prevEntry + prevEntry[0];

                } else {
                    Debug.LogWarning ("It is strange that come here. bitDataIndex:" + bitDataIndex + " lzwCodeSize:" + lzwCodeSize + " key:" + key + " dic.Count:" + dic.Count);
                    bitDataIndex += lzwCodeSize;
                    continue;
                }

            } else {
                Debug.LogWarning ("It is strange that come here. bitDataIndex:" + bitDataIndex + " lzwCodeSize:" + lzwCodeSize + " key:" + key + " dic.Count:" + dic.Count);
                bitDataIndex += lzwCodeSize;
                continue;
            }

            // Output
            // Take out 8 bits from the string.
            var temp = Encoding.Unicode.GetBytes (entry);
            for (int i = 0; i < temp.Length; i++) {
                if (i % 2 == 0) {
                    output[outputAddIndex] = temp[i];
                    outputAddIndex++;
                }
            }

            if (outputAddIndex >= needDataSize) {
                // Exit
                break;
            }

            if (prevEntry != null) {
                // Add to dictionary
                dic.Add (dic.Count, prevEntry + entry[0]);
            }

            prevEntry = entry;

            bitDataIndex += lzwCodeSize;

            if (lzwCodeSize == 3 && dic.Count >= 8) {
                lzwCodeSize = 4;
//.........这里部分代码省略.........
开发者ID:cuidonghuan,项目名称:MiniWeChat-Client,代码行数:101,代码来源:UniGifDecoder.cs


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