Skip to content

Commit 7ad16a4

Browse files
committed
avcodec/mjpegenc_huffman: Make ff_mjpegenc_huffman_compute_bits() static
Only used here and in a test tool. Signed-off-by: Andreas Rheinhardt <[email protected]>
1 parent a2136d5 commit 7ad16a4

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

libavcodec/mjpegenc_huffman.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@
2525
#include "libavutil/qsort.h"
2626
#include "mjpegenc_huffman.h"
2727

28+
/**
29+
* Used to assign a occurrence count or "probability" to an input value
30+
*/
31+
typedef struct PTable {
32+
int value; ///< input value
33+
int prob; ///< number of occurences of this value in input
34+
} PTable;
35+
36+
/**
37+
* Used to store intermediate lists in the package merge algorithm
38+
*/
39+
typedef struct PackageMergerList {
40+
int nitems; ///< number of items in the list and probability ex. 4
41+
int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
42+
int probability[514]; ///< probability of each item 3, 8, 18, 46
43+
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
44+
} PackageMergerList;
45+
46+
/**
47+
* Used to store optimal huffman encoding results
48+
*/
49+
typedef struct HuffTable {
50+
int code; ///< code is the input value
51+
int length; ///< length of the encoding
52+
} HuffTable;
53+
2854
/**
2955
* Comparison function for two PTables by prob
3056
*
@@ -74,7 +100,8 @@ static int compare_by_length(const void *a, const void *b)
74100
* @param size size of the prob_table array
75101
* @param max_length max length of an encoding
76102
*/
77-
void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts, int size, int max_length)
103+
static void mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
104+
int size, int max_length)
78105
{
79106
PackageMergerList list_a, list_b, *to = &list_a, *from = &list_b, *temp;
80107

@@ -178,7 +205,7 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
178205
}
179206
val_counts[j].value = 256;
180207
val_counts[j].prob = 0;
181-
ff_mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
208+
mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
182209
AV_QSORT(distincts, nval, HuffTable, compare_by_length);
183210

184211
memset(bits, 0, sizeof(bits[0]) * 17);

libavcodec/mjpegenc_huffman.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,4 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
4444
uint8_t bits[17], uint8_t val[],
4545
int max_nval);
4646

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
64-
} PackageMergerList;
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);
7647
#endif /* AVCODEC_MJPEGENC_HUFFMAN_H */

libavcodec/tests/mjpegenc_huffman.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
* Optimal Huffman Encoding tests.
2424
*/
2525

26-
#include "libavcodec/avcodec.h"
27-
#include <stdlib.h>
28-
#include "libavcodec/mjpegenc.h"
29-
#include "libavcodec/mjpegenc_huffman.h"
30-
#include "libavcodec/mjpegenc_common.h"
31-
#include "libavcodec/mpegvideo.h"
26+
#include <stdio.h>
27+
28+
#include "libavutil/avassert.h"
29+
#include "libavutil/macros.h"
30+
31+
#include "libavcodec/mjpegenc_huffman.c"
3232

3333
// Validate the computed lengths satisfy the JPEG restrictions and is optimal.
3434
static int check_lengths(int L, int expected_length,
@@ -45,7 +45,7 @@ static int check_lengths(int L, int expected_length,
4545
val_counts[i] = (PTable){.value = i, .prob = probs[i]};
4646
}
4747

48-
ff_mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
48+
mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
4949

5050
for (i = 0; i < nprobs; i++) {
5151
// Find the value's prob and length
@@ -137,8 +137,8 @@ int main(int argc, char **argv)
137137

138138
// Build optimal huffman tree using an internal function, to allow for
139139
// smaller-than-normal test cases. This mutates val_counts by sorting.
140-
ff_mjpegenc_huffman_compute_bits(val_counts, distincts,
141-
FF_ARRAY_ELEMS(distincts), 3);
140+
mjpegenc_huffman_compute_bits(val_counts, distincts,
141+
FF_ARRAY_ELEMS(distincts), 3);
142142

143143
for (i = 0; i < FF_ARRAY_ELEMS(distincts); i++) {
144144
if (distincts[i].code != expected[i].code ||

0 commit comments

Comments
 (0)