FFmpeg
mjpegenc_huffman.h
Go to the documentation of this file.
1 /*
2  * MJPEG encoder
3  * Copyright (c) 2016 William Ma, Ted Ying, Jerry Jiang
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Huffman table generation for MJPEG encoder.
25  */
26 
27 #ifndef AVCODEC_MJPEGENC_HUFFMAN_H
28 #define AVCODEC_MJPEGENC_HUFFMAN_H
29 
30 #include <stdint.h>
31 
32 typedef struct MJpegEncHuffmanContext {
33  int val_count[256];
35 
36 // Uses the package merge algorithm to compute the Huffman table.
39  uint8_t val)
40 {
41  s->val_count[val]++;
42 }
44  uint8_t bits[17], uint8_t val[],
45  int max_nval);
46 
47 
48 /**
49  * Used to assign a occurrence count or "probability" to an input value
50  */
51 typedef struct PTable {
52  int value; ///< input value
53  int prob; ///< number of occurences of this value in input
54 } PTable;
55 
56 /**
57  * Used to store intermediate lists in the package merge algorithm
58  */
59 typedef struct PackageMergerList {
60  int nitems; ///< number of items in the list and probability ex. 4
61  int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
62  int probability[514]; ///< probability of each item 3, 8, 18, 46
63  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
65 
66 /**
67  * Used to store optimal huffman encoding results
68  */
69 typedef struct HuffTable {
70  int code; ///< code is the input value
71  int length; ///< length of the encoding
72 } HuffTable;
73 
74 void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
75  int size, int max_length);
76 #endif /* AVCODEC_MJPEGENC_HUFFMAN_H */
PackageMergerList::item_idx
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
Definition: magicyuvenc.c:281
PTable::prob
int prob
number of occurences of this value in input
Definition: mjpegenc_huffman.h:53
val
static double val(void *priv, double ch)
Definition: aeval.c:77
s
#define s(width, name)
Definition: cbs_vp9.c:256
PackageMergerList::nitems
int nitems
number of items in the list and probability ex. 4
Definition: magicyuvenc.c:280
bits
uint8_t bits
Definition: vp3data.h:141
MJpegEncHuffmanContext
Definition: mjpegenc_huffman.h:32
ff_mjpeg_encode_huffman_close
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.
Definition: mjpegenc_huffman.c:158
PTable
Used to assign a occurrence count or "probability" to an input value.
Definition: magicyuvenc.c:50
HuffTable
Used to store optimal huffman encoding results.
Definition: mjpegenc_huffman.h:69
HuffTable::code
int code
code is the input value
Definition: mjpegenc_huffman.h:70
PackageMergerList
Used to store intermediate lists in the package merge algorithm.
Definition: magicyuvenc.c:279
ff_mjpeg_encode_huffman_increment
static void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, uint8_t val)
Definition: mjpegenc_huffman.h:38
HuffTable::length
int length
length of the encoding
Definition: mjpegenc_huffman.h:71
size
int size
Definition: twinvq_data.h:10344
PTable::value
int value
input value
Definition: magicyuvenc.c:51
ff_mjpeg_encode_huffman_init
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
Definition: mjpegenc_huffman.c:145
PackageMergerList::items
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D,...
Definition: magicyuvenc.c:283
ff_mjpegenc_huffman_compute_bits
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.
Definition: mjpegenc_huffman.c:77
PackageMergerList::probability
int probability[514]
probability of each item 3, 8, 18, 46
Definition: magicyuvenc.c:282
MJpegEncHuffmanContext::val_count
int val_count[256]
Definition: mjpegenc_huffman.h:33