[FFmpeg-devel] [PATCH 3/3] avcodec/sheervideo: Avoid code duplication when creating VLC tables
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sat Oct 10 22:58:29 EEST 2020
Paul B Mahol:
> On Sat, Oct 10, 2020 at 08:59:56PM +0200, Andreas Rheinhardt wrote:
>> The SheerVideo decoder uses two VLC tables and these are in turn created
>> from structures (called SheerTable) that are naturally paired. This
>> commit unifies these pairs of SheerTables to arrays and unifies creating
>> the VLC tables.
>
> patch-set should be fine if all variant of files are still decoded fine
> after this set applied.
>
I tested all files from
https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket492/ which
unfortunately don't cover all variants and they decode the same. Given
that the new tables have been created automatically* I am confident that
I made no errors.
- Andreas
*: using this small program:
#include <stdio.h>
#include <stdint.h>
#include "sheervideodata.h"
void test(const char *name, const uint8_t *table, int size)
{
int last = 0;
int descending = 0;
int counts[2][16] = { { 0 } }, count = 0;
for (int i = 0; i < size; i++) {
int cur = table[i];
if (descending) {
if (last < cur) {
printf("Table %s not according to expectations at index
%d.\n",
name, i);
return;
}
} else if (last > cur)
descending = 1;
if (cur > 16 || cur <= 0) {
printf("Element %d of table %s out of range.\n", i, name);
return;
}
counts[descending][cur - 1]++;
last = cur;
}
if (!descending) {
printf("Still ascending.\n");
return;
}
if (counts[1][15]) {
printf("Strange");
return;
}
for (int i = 0; i < 16; i++)
count += counts[0][i] + counts[1][i];
if (count != size) {
printf("Strange2");
return;
}
if (counts[0][15] > UINT16_MAX) {
printf("Strange3");
return;
}
printf("static const SheerTable %s = {\n {", name);
for (int i = 0; i < 15; i++)
printf("%3d,", counts[0][i]);
printf("\n ");
for (int i = 0; i < 14; i++)
printf("%3d,", counts[1][14 - i]);
printf("%3d }, %d\n };\n\n", counts[1][0], counts[0][15]);
}
#define test(table, size) test(#table, table, size)
int main()
{
test(l_r_rgb, 256);
test(l_g_rgb, 256);
test(l_r_rgbi, 256);
test(l_g_rgbi, 256);
test(l_y_ybr, 256);
test(l_u_ybr, 256);
test(l_y_ybyr, 256);
test(l_u_ybyr, 256);
test(l_y_byry, 256);
test(l_u_byry, 256);
test(l_y_ybr10i, 1024);
test(l_y_ybr10, 1024);
test(l_u_ybr10i, 1024);
test(l_u_ybr10, 1024);
test(l_r_rgbx, 1024);
test(l_g_rgbx, 1024);
test(l_y_yry10, 1024);
test(l_u_yry10, 1024);
test(l_y_yry10i, 1024);
test(l_u_yry10i, 1024);
test(l_y_ybri, 256);
test(l_u_ybri, 256);
test(l_y_byryi, 256);
test(l_u_byryi, 256);
test(l_r_rgbxi, 1024);
test(l_g_rgbxi, 1024);
return 0;
}
More information about the ffmpeg-devel
mailing list