1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avocdec/mjpegenc_huffman: Avoid redundant loop

There is no point in iterating over the list twice.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-02 12:54:07 +02:00
parent 7ad16a4410
commit 31d5686c39

View File

@ -185,31 +185,27 @@ void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17], void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
uint8_t val[], int max_nval) uint8_t val[], int max_nval)
{ {
int i, j;
int nval = 0;
PTable val_counts[257]; PTable val_counts[257];
HuffTable distincts[256]; HuffTable distincts[256];
for (i = 0; i < 256; i++) { av_assert1(max_nval <= FF_ARRAY_ELEMS(val_counts) - 1);
if (s->val_count[i]) nval++;
}
av_assert0 (nval <= max_nval);
j = 0; int nval = 0;
for (i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
if (s->val_count[i]) { if (s->val_count[i]) {
val_counts[j].value = i; val_counts[nval].value = i;
val_counts[j].prob = s->val_count[i]; val_counts[nval].prob = s->val_count[i];
j++; nval++;
av_assert2(nval <= max_nval);
} }
} }
val_counts[j].value = 256; val_counts[nval].value = 256;
val_counts[j].prob = 0; val_counts[nval].prob = 0;
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); AV_QSORT(distincts, nval, HuffTable, compare_by_length);
memset(bits, 0, sizeof(bits[0]) * 17); memset(bits, 0, sizeof(bits[0]) * 17);
for (i = 0; i < nval; i++) { for (int i = 0; i < nval; i++) {
val[i] = distincts[i].code; val[i] = distincts[i].code;
bits[distincts[i].length]++; bits[distincts[i].length]++;
} }