95 from->item_idx[0] = 0;
98 for (times = 0; times <= max_length; times++) {
105 if (times < max_length) {
108 while (i < size || j + 1 < from->nitems) {
112 (j + 1 >= from->nitems ||
114 from->probability[j] + from->probability[j + 1])) {
119 for (k = from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
123 from->probability[j] + from->probability[j + 1];
132 min = (size - 1 < from->nitems) ? size - 1 : from->nitems;
133 for (i = 0; i < from->item_idx[
min]; i++) {
134 nbits[from->items[i]]++;
139 for (i = 0; i < 256; i++) {
141 distincts[j].
code = i;
142 distincts[j].
length = nbits[i];
169 for (i = 0; i < 256; i++) {
175 for (i = 0; i < 256; i++) {
177 val_counts[j].
value = i;
182 val_counts[j].
value = 256;
183 val_counts[j].
prob = 0;
187 memset(bits, 0,
sizeof(bits[0]) * 17);
188 for (i = 0; i < nval; i++) {
189 val[i] = distincts[i].
code;
190 bits[distincts[i].
length]++;
const char const char void * val
int prob
number of occurences of this value in input
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int probability[514]
probability of each item 3, 8, 18, 46
void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17], uint8_t val[], int max_nval)
Produces a Huffman encoding with a given input.
int nitems
number of items in the list and probability ex. 4
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
simple assert() macros that are a bit more flexible than ISO C assert().
int length
length of the encoding
int code
code is the input value
Used to store intermediate lists in the package merge algorithm.
void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts, int size, int max_length)
Computes the length of the Huffman encoding for each distinct input value.
Used to store optimal huffman encoding results.
Used to assign a occurrence count or "probability" to an input value.
Huffman table generation for MJPEG encoder.
static int compare_by_prob(const void *a, const void *b)
Comparison function for two PTables by prob.
common internal and external API header
static int compare_by_length(const void *a, const void *b)
Comparison function for two HuffTables by length.
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...