Go to the documentation of this file.
92 from->item_idx[0] = 0;
95 for (times = 0; times <= max_length; times++) {
102 if (times < max_length) {
105 while (
i <
size || j + 1 <
from->nitems) {
107 to->item_idx[
to->nitems] =
to->item_idx[
to->nitems - 1];
109 (j + 1 >=
from->nitems ||
111 from->probability[j] +
from->probability[j + 1])) {
112 to->items[
to->item_idx[
to->nitems]++] = prob_table[
i].
value;
113 to->probability[
to->nitems - 1] = prob_table[
i].
prob;
116 for (k =
from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
117 to->items[
to->item_idx[
to->nitems]++] =
from->items[k];
119 to->probability[
to->nitems - 1] =
120 from->probability[j] +
from->probability[j + 1];
131 nbits[
from->items[
i]]++;
136 for (
i = 0;
i < 256;
i++) {
138 distincts[j].
code =
i;
139 distincts[j].
length = nbits[
i];
147 memset(
s->val_count, 0,
sizeof(
s->val_count));
159 uint8_t
val[],
int max_nval)
166 for (
i = 0;
i < 256;
i++) {
167 if (
s->val_count[
i]) nval++;
172 for (
i = 0;
i < 256;
i++) {
173 if (
s->val_count[
i]) {
175 val_counts[j].
prob =
s->val_count[
i];
179 val_counts[j].
value = 256;
180 val_counts[j].
prob = 0;
184 memset(
bits, 0,
sizeof(
bits[0]) * 17);
185 for (
i = 0;
i < nval;
i++) {
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.
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.
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
static int compare_by_prob(const void *a, const void *b)
Comparison function for two PTables by prob.
static double val(void *priv, double ch)
static int compare_by_length(const void *a, const void *b)
Comparison function for two HuffTables by length.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t prob
number of occurences of this value in input
Used to assign a occurrence count or "probability" to an input value.
Used to store optimal huffman encoding results.
int code
code is the input value
Used to store intermediate lists in the package merge algorithm.
int length
length of the encoding
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define i(width, name, range_min, range_max)
#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...