You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mjpegenc_huffman: Make ff_mjpegenc_huffman_compute_bits() static
Only used here and in a test tool. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -25,6 +25,32 @@
|
||||
#include "libavutil/qsort.h"
|
||||
#include "mjpegenc_huffman.h"
|
||||
|
||||
/**
|
||||
* Used to assign a occurrence count or "probability" to an input value
|
||||
*/
|
||||
typedef struct PTable {
|
||||
int value; ///< input value
|
||||
int prob; ///< number of occurences of this value in input
|
||||
} PTable;
|
||||
|
||||
/**
|
||||
* Used to store intermediate lists in the package merge algorithm
|
||||
*/
|
||||
typedef struct PackageMergerList {
|
||||
int nitems; ///< number of items in the list and probability ex. 4
|
||||
int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
|
||||
int probability[514]; ///< probability of each item 3, 8, 18, 46
|
||||
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
|
||||
} PackageMergerList;
|
||||
|
||||
/**
|
||||
* Used to store optimal huffman encoding results
|
||||
*/
|
||||
typedef struct HuffTable {
|
||||
int code; ///< code is the input value
|
||||
int length; ///< length of the encoding
|
||||
} HuffTable;
|
||||
|
||||
/**
|
||||
* Comparison function for two PTables by prob
|
||||
*
|
||||
@ -74,7 +100,8 @@ static int compare_by_length(const void *a, const void *b)
|
||||
* @param size size of the prob_table array
|
||||
* @param max_length max length of an encoding
|
||||
*/
|
||||
void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts, int size, int max_length)
|
||||
static void mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
|
||||
int size, int max_length)
|
||||
{
|
||||
PackageMergerList list_a, list_b, *to = &list_a, *from = &list_b, *temp;
|
||||
|
||||
@ -178,7 +205,7 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
|
||||
}
|
||||
val_counts[j].value = 256;
|
||||
val_counts[j].prob = 0;
|
||||
ff_mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
|
||||
mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
|
||||
AV_QSORT(distincts, nval, HuffTable, compare_by_length);
|
||||
|
||||
memset(bits, 0, sizeof(bits[0]) * 17);
|
||||
|
@ -44,33 +44,4 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
|
||||
uint8_t bits[17], uint8_t val[],
|
||||
int max_nval);
|
||||
|
||||
|
||||
/**
|
||||
* Used to assign a occurrence count or "probability" to an input value
|
||||
*/
|
||||
typedef struct PTable {
|
||||
int value; ///< input value
|
||||
int prob; ///< number of occurences of this value in input
|
||||
} PTable;
|
||||
|
||||
/**
|
||||
* Used to store intermediate lists in the package merge algorithm
|
||||
*/
|
||||
typedef struct PackageMergerList {
|
||||
int nitems; ///< number of items in the list and probability ex. 4
|
||||
int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
|
||||
int probability[514]; ///< probability of each item 3, 8, 18, 46
|
||||
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
|
||||
} PackageMergerList;
|
||||
|
||||
/**
|
||||
* Used to store optimal huffman encoding results
|
||||
*/
|
||||
typedef struct HuffTable {
|
||||
int code; ///< code is the input value
|
||||
int length; ///< length of the encoding
|
||||
} HuffTable;
|
||||
|
||||
void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
|
||||
int size, int max_length);
|
||||
#endif /* AVCODEC_MJPEGENC_HUFFMAN_H */
|
||||
|
@ -23,12 +23,12 @@
|
||||
* Optimal Huffman Encoding tests.
|
||||
*/
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include <stdlib.h>
|
||||
#include "libavcodec/mjpegenc.h"
|
||||
#include "libavcodec/mjpegenc_huffman.h"
|
||||
#include "libavcodec/mjpegenc_common.h"
|
||||
#include "libavcodec/mpegvideo.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/macros.h"
|
||||
|
||||
#include "libavcodec/mjpegenc_huffman.c"
|
||||
|
||||
// Validate the computed lengths satisfy the JPEG restrictions and is optimal.
|
||||
static int check_lengths(int L, int expected_length,
|
||||
@ -45,7 +45,7 @@ static int check_lengths(int L, int expected_length,
|
||||
val_counts[i] = (PTable){.value = i, .prob = probs[i]};
|
||||
}
|
||||
|
||||
ff_mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
|
||||
mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
|
||||
|
||||
for (i = 0; i < nprobs; i++) {
|
||||
// Find the value's prob and length
|
||||
@ -137,8 +137,8 @@ int main(int argc, char **argv)
|
||||
|
||||
// Build optimal huffman tree using an internal function, to allow for
|
||||
// smaller-than-normal test cases. This mutates val_counts by sorting.
|
||||
ff_mjpegenc_huffman_compute_bits(val_counts, distincts,
|
||||
FF_ARRAY_ELEMS(distincts), 3);
|
||||
mjpegenc_huffman_compute_bits(val_counts, distincts,
|
||||
FF_ARRAY_ELEMS(distincts), 3);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(distincts); i++) {
|
||||
if (distincts[i].code != expected[i].code ||
|
||||
|
Reference in New Issue
Block a user