本文整理汇总了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;
//.........这里部分代码省略.........