Go to the documentation of this file.
83 int size,
int max_length)
98 from->item_idx[0] = 0;
101 for (times = 0; times <= max_length; times++) {
108 if (times < max_length) {
111 while (
i <
size || j + 1 <
from->nitems) {
113 to->item_idx[
to->nitems] =
to->item_idx[
to->nitems - 1];
115 (j + 1 >=
from->nitems ||
117 from->probability[j] +
from->probability[j + 1])) {
118 to->items[
to->item_idx[
to->nitems]++] = prob_table[
i].
value;
119 to->probability[
to->nitems - 1] = prob_table[
i].
prob;
122 for (k =
from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
123 to->items[
to->item_idx[
to->nitems]++] =
from->items[k];
125 to->probability[
to->nitems - 1] =
126 from->probability[j] +
from->probability[j + 1];
137 nbits[
from->items[
i]]++;
141 memset(counts, 0,
sizeof(counts[0]) * (max_length + 1));
142 for (
int i = 0;
i < 256; ++
i)
148 memset(
s->val_count, 0,
sizeof(
s->val_count));
160 uint8_t
val[],
int max_nval)
167 for (
int i = 0;
i < 256;
i++) {
168 if (
s->val_count[
i]) {
169 val_counts[nval].
value =
i;
170 val_counts[nval].
prob =
s->val_count[
i];
175 val_counts[nval].
value = 256;
176 val_counts[nval].
prob = 0;
184 for (
int 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.
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
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.
int prob
number of occurences of this value in input
static double val(void *priv, double ch)
#define FF_ARRAY_ELEMS(a)
int nitems
number of items in the list and probability ex. 4
#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 intermediate lists in the package merge algorithm.
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 av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#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...
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D,...
#define prob(name, subs,...)
int probability[514]
probability of each item 3, 8, 18, 46
static void mjpegenc_huffman_compute_bits(PTable *prob_table, uint8_t counts[], int size, int max_length)
Computes the length of the Huffman encoding for each distinct input value.