X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=deps%2Flibchdr%2Fsrc%2Flibchdr_huffman.c;fp=deps%2Flibchdr%2Fhuffman.c;h=6a50f1344cf3e62ab80ceae002fd4490d89620cb;hb=2ff0b5124f2e17a290121e1eeecf45db1d9e2c85;hp=a58b6be8248659b8ff32a0b2eac37f4de29e5fa8;hpb=e3e1b865f7c06f57918b97f7293b5b2959fb7b7d;p=pcsx_rearmed.git diff --git a/deps/libchdr/huffman.c b/deps/libchdr/src/libchdr_huffman.c similarity index 96% rename from deps/libchdr/huffman.c rename to deps/libchdr/src/libchdr_huffman.c index a58b6be8..6a50f134 100644 --- a/deps/libchdr/huffman.c +++ b/deps/libchdr/src/libchdr_huffman.c @@ -101,7 +101,7 @@ #include #include -#include "huffman.h" +#include #define MAX(x,y) ((x) > (y) ? (x) : (y)) @@ -142,6 +142,18 @@ struct huffman_decoder* create_huffman_decoder(int numcodes, int maxbits) return decoder; } +void delete_huffman_decoder(struct huffman_decoder* decoder) +{ + if (decoder != NULL) + { + if (decoder->lookup != NULL) + free(decoder->lookup); + if (decoder->huffnode != NULL) + free(decoder->huffnode); + free(decoder); + } +} + /*------------------------------------------------- * decode_one - decode a single code from the * huffman stream @@ -411,6 +423,7 @@ int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint nextalloc = decoder->numcodes; while (listitems > 1) { + int curitem; /* remove lowest two items */ struct node_t* node1 = &(*list[--listitems]); struct node_t* node0 = &(*list[--listitems]); @@ -422,7 +435,6 @@ int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint newnode->weight = node0->weight + node1->weight; /* insert into list at appropriate location */ - int curitem; for (curitem = 0; curitem < listitems; curitem++) if (newnode->weight > list[curitem]->weight) { @@ -436,6 +448,7 @@ int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint /* compute the number of bits in each code, and fill in another histogram */ for (curcode = 0; curcode < decoder->numcodes; curcode++) { + struct node_t *curnode; struct node_t* node = &decoder->huffnode[curcode]; node->numbits = 0; node->bits = 0; @@ -444,7 +457,7 @@ int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint if (node->weight > 0) { /* determine the number of bits for this node */ - for (struct node_t *curnode = node; curnode->parent != NULL; curnode = curnode->parent) + for (curnode = node; curnode->parent != NULL; curnode = curnode->parent) node->numbits++; if (node->numbits == 0) node->numbits = 1; @@ -514,13 +527,16 @@ void huffman_build_lookup_table(struct huffman_decoder* decoder) struct node_t* node = &decoder->huffnode[curcode]; if (node->numbits > 0) { + int shift; + lookup_value *dest; + lookup_value *destend; /* set up the entry */ lookup_value value = MAKE_LOOKUP(curcode, node->numbits); /* fill all matching entries */ - int shift = decoder->maxbits - node->numbits; - lookup_value *dest = &decoder->lookup[node->bits << shift]; - lookup_value *destend = &decoder->lookup[((node->bits + 1) << shift) - 1]; + shift = decoder->maxbits - node->numbits; + dest = &decoder->lookup[node->bits << shift]; + destend = &decoder->lookup[((node->bits + 1) << shift) - 1]; while (dest <= destend) *dest++ = value; }