亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? huffman.cpp

?? 非常好用的五子棋游戲源碼
?? CPP
字號:
// Created:09-24-98
// By Jeff Connelly

// Huffman compression.

// Original code: ORIGSRC\CODHUFF.C and ORIGSRC\DCODHUFF.C written by
// David Bourgin

// Note: The compiler must have been configured for a stack size of at
//       minimum 20K.

#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"
#include "huffman.h"

#include <string.h>
#include <stdlib.h>

static unsigned char bit_counter_to_write = 0;
static unsigned int val_to_write = 0;

#define dfunc(n)   static int DEBUG_COUNTER = 0; printf ("%s(): %d\n", n, DEBUG_COUNTER++);
#define dend(n)    printf ("End %s()\n", n);

// Writes the value binary-coded into 'bin_val'
static void write_bin_val(t_bin_val bin_val)
{
    dfunc("write_bin_val");
    unsigned char bin_pos, byte_pos;

    byte_pos = (BITS_NB_BIN_VAL(bin_val) + 7) >> 3;
    bin_pos = BITS_NB_BIN_VAL(bin_val) & 7;
    if (bin_pos)
    {
        --byte_pos;
        val_to_write = (val_to_write << bin_pos) | BITS_BIN_VAL(bin_val)
                        [byte_pos];
        bit_counter_to_write += bin_pos;
        if (bit_counter_to_write >= 8)
        {
            bit_counter_to_write -= 8;
            write_byte((unsigned char)
                       (val_to_write >> bit_counter_to_write));
            val_to_write &= ((1 << bit_counter_to_write) - 1);
        }
     }
     while (byte_pos)
     {
         --byte_pos;
         val_to_write = (val_to_write << 8) | BITS_BIN_VAL(bin_val)[byte_pos];
         write_byte((unsigned char)(val_to_write >> bit_counter_to_write));
         val_to_write &= ((1 << bit_counter_to_write) - 1);
     }
     dend("write_bin_val");
}

// Fills the last byte to write with zero values
static void fill_encoding()
{
    dfunc("fill_encoding");
    if (bit_counter_to_write)
        write_byte(val_to_write << (8 - bit_counter_to_write));
    dend("fill_encoding");
}

// Writes the header in the stream of codes
static void write_header (t_bin_val codes_table[257])
{
    dfunc("write_header");
    register unsigned int i, j;

    // Used to send in binary mode via write_bin_val
    t_bin_val bin_val_to_0, bin_val_to_1, bin_val;

    *BITS_BIN_VAL(bin_val_to_0) = 0;
    BITS_NB_BIN_VAL(bin_val_to_0) = 1;
    *BITS_BIN_VAL(bin_val_to_1) = 1;
    BITS_NB_BIN_VAL(bin_val_to_1) = 1;

    for (i = 0, j = 0; j <= 0xFF; j++)
        if (BITS_NB_BIN_VAL(codes_table[j]))
            ++i;

    // From there, 'i' contains the number of bytes of the several non-null
    // occurences to encode.  First part of header specifies the bytes that
    // appear in the source of encoding

    if (i < 32)
    {
        write_bin_val(bin_val_to_0);
        BITS_NB_BIN_VAL(bin_val) = 5;
        *BITS_BIN_VAL(bin_val) = (unsigned char)(i - 1);
        write_bin_val(bin_val);
        BITS_NB_BIN_VAL(bin_val) = 8;
        for (j = 0; j <= 0xFF; j++)
            if BITS_NB_BIN_VAL(codes_table[j])
            {
                *BITS_BIN_VAL(bin_val) = (unsigned char)j;
                write_bin_val(bin_val);
            }
    } else {
        write_bin_val(bin_val_to_1);
        for (j = 0; j <= 0xFF; j++)
            if BITS_NB_BIN_VAL(codes_table[j])
                write_bin_val(bin_val_to_1);
            else
                write_bin_val(bin_val_to_0);
    };
    // Second part of header specifies the encoding of the bytes
    // (fictive or not) that appear in the source of encoding

    for (i = 0; i <= 0x100; i++)
    {
        if (j = BITS_NB_BIN_VAL(codes_table[i]))
            if (j < 33)
            {
                write_bin_val(bin_val_to_0);
                BITS_NB_BIN_VAL(bin_val) = 5;
            } else {
                write_bin_val(bin_val_to_1);
                BITS_NB_BIN_VAL(bin_val) = 8;
            }
            *BITS_BIN_VAL(bin_val) = (unsigned char)(j - 1);
            write_bin_val(bin_val);
            write_bin_val(codes_table[i]);
    }
    dend ("write_header");
}

// Returns a negative, zero or positive integer depending on the weight
// of 'tree2' is less than, equal to, or greater than the weight of 'tree1',
// respectivly.
// static int weight_tree_comp (p_tree* tree1, p_tree* tree2)
static int weight_tree_comp (const void* ptree1, const void* ptree2)
{
	p_tree* tree1 = (p_tree*)ptree1;
	p_tree* tree2 = (p_tree*)ptree2;
    dfunc ("weight_tree_comp");
    return (WEIGHT_OF_TREE(*tree2) ^ WEIGHT_OF_TREE(*tree1)) ?
            ((WEIGHT_OF_TREE(*tree2) < WEIGHT_OF_TREE(*tree1))
             ? -1 : +1) : 0;
    dend ("weight_tree_comp");
}

// supresses the allocation memory for 'tree'
static void suppress_tree (p_tree tree)
{
    dfunc ("suppress_tree");
    if (tree != NULL)
    {
        suppress_tree (LEFTPTR_OF_TREE(tree));
        suppress_tree (RIGHTPTR_OF_TREE(tree));
        free (tree);
    }
    dend ("suppress_tree");
}

// Creates a Huffman encoding tree based on the data from the input stream
static p_tree build_tree_encoding()
{
    dfunc ("build_tree_encoding()");
    register unsigned int i;
    p_tree occurrences_table[257], ptr_fictive_tree;

    // Set up the occurrences number of all bytes to zero
    for (i = 0; i <= 0x100; i++)
    {
        if ((occurrences_table[i] = (p_tree)malloc(sizeof(t_tree))) == NULL)
        {
            for (; i; i--)
                free(occurrences_table[i - 1]);
            EXCEPTION (ERR_MEMORY, "Failed to allocate memory for"
                                   "occurrences table to build tree",
                                   "build_tree_encoding()");
        }
        BYTE_OF_TREE(occurrences_table[i]) = i;
        WEIGHT_OF_TREE(occurrences_table[i]) = 0;
        LEFTPTR_OF_TREE(occurrences_table[i]) = NULL;
        RIGHTPTR_OF_TREE(occurrences_table[i]) = NULL;
    }

    if (!end_of_data())
    {
        while (!end_of_data())
        {
            i = read_byte();
            WEIGHT_OF_TREE(occurrences_table[i])++;
        }
        WEIGHT_OF_TREE(occurrences_table[0x100]) = 1;
        // Sort the occurrences table depending on the weight of each
        // byte.
        (void)qsort(
			(void*)(const void*)occurrences_table,
			257, sizeof(p_tree),
			weight_tree_comp);
			//((int)(*weight_tree_comp)(const void*, const void*)));
        for (i = 0x100; (i != 0) && (!WEIGHT_OF_TREE(occurrences_table[i]));
             i--);
            free(occurrences_table[i]);
        ++i;
        // From here, 'i' gives the number of different bytes with a null
        // occurrence in the input stream.  Look up (i + 1) / 2 times
        // the occurrences table to link the nodes in a unique tree
        while (i > 0)
        {
            if((ptr_fictive_tree = (p_tree)malloc(sizeof(t_tree))) == NULL)
            {
                for (i = 0; i <= 0x100; i++)
                    suppress_tree (occurrences_table[i]);
                EXCEPTION (ERR_MEMORY, "Failed to allocate memory to build"
                                       "fictive tree",
                                       "build_tree_encoding()");
            }
            BYTE_OF_TREE(ptr_fictive_tree) = 257;
            WEIGHT_OF_TREE(ptr_fictive_tree) =
                        WEIGHT_OF_TREE(occurrences_table[--i]);
            LEFTPTR_OF_TREE(ptr_fictive_tree) = occurrences_table[i];
            if (i)
            {
                --i;
                WEIGHT_OF_TREE(ptr_fictive_tree) +=
                            WEIGHT_OF_TREE(occurrences_table[i]);
                RIGHTPTR_OF_TREE(ptr_fictive_tree) = occurrences_table[i];
            } else
                RIGHTPTR_OF_TREE(ptr_fictive_tree) = NULL;
            occurrences_table[i] = ptr_fictive_tree;
            (void)qsort(occurrences_table, i + 1, sizeof(p_tree),
                    weight_tree_comp);
            // Is there another node in the occurrences table? 
            if (i)
                ++i;  // Yes, then takes care to the fictive node
        }
    }
    dend ("build_tree_encoding");
    return (*occurrences_table);
}

static void encode_codes_table (p_tree tree, t_bin_val codes_table[257],
                                t_bin_val* code_val)
{
    dfunc ("encode_codes_table");
    register unsigned int i;
    t_bin_val tmp_code_val;

    if (BYTE_OF_TREE(tree) == 257)
    {
        if (LEFTPTR_OF_TREE(tree) != NULL)
        {
            // The sub-trees on left begin with a bit with value 1
            tmp_code_val = *code_val;
            for (i = 31; i > 0; i--)
                BITS_BIN_VAL(*code_val)[i] =
                    (BITS_BIN_VAL(*code_val)[i] << 1) |
                    (BITS_BIN_VAL(*code_val)[i - 1] >> 7);
            *BITS_BIN_VAL(*code_val) = (*BITS_BIN_VAL(*code_val) << 1) | 1;
            BITS_NB_BIN_VAL(*code_val)++;
            encode_codes_table (LEFTPTR_OF_TREE(tree), codes_table,
                                code_val);
            *code_val = tmp_code_val;
        };

        if (RIGHTPTR_OF_TREE(tree) != NULL)
        {
            tmp_code_val = *code_val;
            for (i = 31; i > 0; i--)
                BITS_BIN_VAL(*code_val)[i] = (BITS_BIN_VAL(*code_val)[i]
                    << 1) | (BITS_BIN_VAL(*code_val)[i - 1] >> 7);
            *BITS_BIN_VAL(*code_val) <<= 1;
            BITS_NB_BIN_VAL(*code_val)++;
            encode_codes_table(RIGHTPTR_OF_TREE(tree), codes_table, code_val);
            *code_val = tmp_code_val;
        };
    } else
        codes_table[BYTE_OF_TREE(tree)] = *code_val;
    dend ("encode_codes_table");
}

// Stores the encoding tree as a binary encoding table to speed up the
// access by caling encode_codes_table
static void create_codes_table(p_tree tree, t_bin_val codes_table[257])
{
    dfunc ("create_codes_table");
    t_bin_val code_val;

    (void)memset((char*)&code_val, 0, sizeof(code_val));
    (void)memset((char*)codes_table, 0, 257 * sizeof(*codes_table));
    encode_codes_table(tree, codes_table, &code_val);
    dend ("create_codes_table");
}

// Finally, the main encoding function!
void EXPORT  huffman_encode ()
{
    dfunc ("huffman_encode");
    p_tree tree;
    t_bin_val encoding_table[257];
    unsigned char byte_read;

    if (!end_of_data())         // Only output data if there is input data
    {
        // Build the tree
        tree = build_tree_encoding();
        create_codes_table(tree, encoding_table);   
        suppress_tree (tree);
        write_header(encoding_table);       // Write definition of encoding
        beginning_of_data();                // Actual compression begins
        while (!end_of_data())
        {
            byte_read = read_byte();
            write_bin_val(encoding_table[byte_read]);
        }
        write_bin_val(encoding_table[256]);     // Code of end of encoding
        fill_encoding();                        // Fill last byte, if any
    }
    dend ("huffman_encode");
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美性猛片xxxx免费看久爱| 久久99精品国产麻豆不卡| 99视频超级精品| 国产精品传媒视频| caoporen国产精品视频| 中文字幕一区av| 欧美日韩一区小说| 久久精品国产亚洲高清剧情介绍| 久久综合久久综合九色| 不卡av免费在线观看| 亚洲成人免费视频| 欧美zozozo| 99在线热播精品免费| 亚洲国产成人91porn| 日韩视频123| 国产在线播放一区二区三区| 中文字幕一区二区不卡| 56国语精品自产拍在线观看| 久久电影网电视剧免费观看| 国产精品不卡在线| 欧美视频三区在线播放| 久久国产欧美日韩精品| 中日韩av电影| 欧美精品自拍偷拍| 国产91对白在线观看九色| 亚洲精品成人a在线观看| 日韩精品专区在线| fc2成人免费人成在线观看播放| 亚洲一二三区视频在线观看| 久久综合一区二区| 精品污污网站免费看| 国产剧情一区在线| 一级做a爱片久久| 久久久久久亚洲综合| 色狠狠桃花综合| 国产剧情一区二区| 日韩精品亚洲专区| 综合亚洲深深色噜噜狠狠网站| 3d动漫精品啪啪一区二区竹菊| 岛国av在线一区| 日韩国产高清在线| 亚洲图片你懂的| 精品国产免费一区二区三区香蕉| 色婷婷综合久久久| 成人午夜短视频| 日本成人在线视频网站| 一区二区三区不卡视频| 中文字幕精品三区| 欧美一区二区三区不卡| 欧美怡红院视频| 99国产精品国产精品毛片| 国产乱码精品一区二区三区五月婷| 亚洲精品国产一区二区三区四区在线| 国产欧美日韩在线| 精品理论电影在线| 91精品国产一区二区人妖| 91久久精品国产91性色tv| 成人av高清在线| 黄色小说综合网站| 青娱乐精品视频| 丝袜亚洲另类欧美综合| 亚洲综合在线免费观看| 日韩一区在线看| 国产精品丝袜在线| 日本一区二区免费在线观看视频 | 欧美日本一区二区| 91久久人澡人人添人人爽欧美 | 亚洲欧美综合色| 国产欧美日本一区视频| 国产午夜精品福利| 久久精品水蜜桃av综合天堂| 2023国产精品| 久久久久久久久免费| 日韩欧美色综合| 欧美不卡一区二区三区四区| 欧美一级片在线看| 日韩免费观看高清完整版| 欧美一区永久视频免费观看| 欧美一区二区三区免费观看视频| 日韩一区二区视频| 精品国产乱子伦一区| 精品久久久久久久久久久久包黑料 | 在线电影欧美成精品| 欧美午夜电影网| 欧美群妇大交群的观看方式| 欧美久久久久久久久中文字幕| 337p亚洲精品色噜噜噜| 欧美不卡激情三级在线观看| 久久久综合视频| 国产精品私人自拍| 亚洲欧美国产高清| 亚洲mv在线观看| 精品午夜一区二区三区在线观看| 国产麻豆精品久久一二三| 风间由美一区二区av101| 豆国产96在线|亚洲| 91久久精品一区二区三区| 欧美肥大bbwbbw高潮| 精品欧美乱码久久久久久1区2区| 久久久影视传媒| 亚洲靠逼com| 日韩av在线播放中文字幕| 国产一区二区看久久| 91视频.com| 91精品国产免费| 国产亚洲一区二区三区在线观看| 国产精品欧美久久久久一区二区| 欧美激情一区二区三区不卡| 亚洲国产精品ⅴa在线观看| 国产区在线观看成人精品| 自拍偷自拍亚洲精品播放| 丝袜诱惑亚洲看片| 国产精品一区二区x88av| 色激情天天射综合网| 日韩视频免费观看高清完整版| 国产精品久久久久婷婷| 视频一区国产视频| 国产精品亚洲一区二区三区妖精| 日本高清不卡在线观看| 日韩欧美国产1| 日韩电影在线观看电影| 国产精品一二三在| 在线不卡一区二区| 亚洲欧洲av在线| 国内一区二区视频| 欧美日韩你懂的| 国产精品久久免费看| 蜜乳av一区二区| 在线亚洲人成电影网站色www| 欧美mv和日韩mv国产网站| 欧美日韩视频在线一区二区 | 亚洲欧洲性图库| 婷婷中文字幕综合| 成人精品高清在线| 日韩欧美一卡二卡| 亚洲国产精品久久人人爱| 成人中文字幕电影| 亚洲精品一区二区三区在线观看| 亚洲资源在线观看| av一区二区三区| 亚洲精品一区二区三区四区高清| 亚洲成人黄色影院| 色噜噜夜夜夜综合网| 国产午夜亚洲精品不卡| 蜜桃精品视频在线观看| 欧美美女一区二区三区| 亚洲日本青草视频在线怡红院| 国产一区亚洲一区| 91精品国产综合久久久久久漫画 | 欧美电影免费提供在线观看| 亚洲一区二区精品久久av| 91在线观看视频| 国产精品视频第一区| 国产一区二区三区国产| 精品国产乱码91久久久久久网站| 亚洲国产欧美在线| 色猫猫国产区一区二在线视频| 中文字幕中文乱码欧美一区二区| 六月婷婷色综合| 欧美精品123区| 日韩精品1区2区3区| 91麻豆精品国产91久久久久久 | 久久久久久久久久久99999| 日本不卡不码高清免费观看| 欧美日韩成人一区二区| 午夜精品久久久久久久99水蜜桃| 欧美亚洲尤物久久| 亚洲成人免费观看| 欧美日韩极品在线观看一区| 热久久国产精品| 欧美精品aⅴ在线视频| 日本视频一区二区三区| 精品女同一区二区| 国产毛片精品国产一区二区三区| 精品国产污网站| 国产精品一区二区久激情瑜伽| 国产香蕉久久精品综合网| 国产成人在线看| 18成人在线视频| 欧美专区在线观看一区| 亚洲成人av一区二区| 在线综合+亚洲+欧美中文字幕| 裸体一区二区三区| 国产亚洲欧美激情| 成人av片在线观看| 悠悠色在线精品| 欧美精品vⅰdeose4hd| 精品亚洲国内自在自线福利| 欧美精彩视频一区二区三区| 91亚洲午夜精品久久久久久| 亚洲一区二区综合| 日韩片之四级片| 国产91精品一区二区| 亚洲精品福利视频网站| 56国语精品自产拍在线观看| 国产精品1024久久| 洋洋成人永久网站入口| 欧美一区二区三区不卡| 成人综合婷婷国产精品久久蜜臀 | 亚洲色图一区二区三区|