History

avcodec/ffv1: Implement jeromes idea of making remap flip optional

This also makes remap optional (which is a good idea even if we decide to keep flip fixed) Effect on compression (using 2 rawlsb, golomb rice, large context model with ACES_OT_VWG_SampleFrames -rw-r----- 1 michael michael 499101306 Mär 11 14:58 float-303503-try3d-m2.nut -rw-r----- 1 michael michael 503700199 Mär 11 14:57 float-303503-try3d-m1.nut -rw-r----- 1 michael michael 518150578 Mär 11 14:57 float-303503-try3d-m0.nut (the test above used the rawlsb patch, which is not applied yet)

Michael Niedermayer committed 1 year ago

Commit 437cbd21 parent dcf61423 files · +23 −7Browse files

Unified · Split

3 files
  1. libavcodec/ffv1.h +1 −0
  2. libavcodec/ffv1dec.c +5 −4
  3. libavcodec/ffv1enc.c +17 −3
libavcodec/ffv1.h+1−0
@@ -137,6 +137,7 @@ typedef struct FFV1Context { · 136 unmodified lines
137 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];137 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
138 int colorspace;138 int colorspace;
139 int flt;139 int flt;
140 int remap_mode;
140 141
141 142
142 int use32bit;143 int use32bit;
libavcodec/ffv1dec.c+5−4
@@ -222,8 +222,8 @@ static int decode_slice_header(const FFV1Context *f, · 221 unmodified lines
222 }222 }
223 if (f->combined_version >= 0x40004) {223 if (f->combined_version >= 0x40004) {
224 sc->remap = ff_ffv1_get_symbol(c, state, 0);224 sc->remap = ff_ffv1_get_symbol(c, state, 0);
225 if (sc->remap > 1U ||225 if (sc->remap > 2U ||
226 sc->remap == 1 && !f->flt) {226 sc->remap && !f->flt) {
227 av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", sc->remap);227 av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", sc->remap);
228 return AVERROR_INVALIDDATA;228 return AVERROR_INVALIDDATA;
229 }229 }
@@ -246,6 +246,7 @@ static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc) · 16 unmodified lines
246static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)246static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
247{247{
248 int transparency = f->transparency;248 int transparency = f->transparency;
249 int flip = sc->remap == 2 ? 0x7FFF : 0;
249 250
250 for (int p= 0; p<3 + transparency; p++) {251 for (int p= 0; p<3 + transparency; p++) {
251 int j = 0;252 int j = 0;
@@ -260,13 +261,13 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) · 8 unmodified lines
260 if (lu) {261 if (lu) {
261 lu ^= !run;262 lu ^= !run;
262 while (run--) {263 while (run--) {
263 sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF);264 sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
264 i++;265 i++;
265 }266 }
266 } else {267 } else {
267 i += run;268 i += run;
268 if (i != 65536)269 if (i != 65536)
269 sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF);270 sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
270 lu ^= !run;271 lu ^= !run;
271 }272 }
272 }273 }
libavcodec/ffv1enc.c+17−3
@@ -903,6 +903,9 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, · 902 unmodified lines
903 }903 }
904 av_assert0(s->bits_per_raw_sample >= 8);904 av_assert0(s->bits_per_raw_sample >= 8);
905 905
906 if (s->remap_mode < 0)
907 s->remap_mode = s->flt ? 2 : 0;
908
906 return av_pix_fmt_get_chroma_sub_sample(pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);909 return av_pix_fmt_get_chroma_sub_sample(pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
907}910}
908 911
@@ -958,7 +961,7 @@ static int encode_init_internal(AVCodecContext *avctx) · 49 unmodified lines
958 961
959 ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8);962 ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8);
960 963
961 s->slices[j].remap = s->flt;964 s->slices[j].remap = s->remap_mode;
962 }965 }
963 966
964 if ((ret = ff_ffv1_init_slices_state(s)) < 0)967 if ((ret = ff_ffv1_init_slices_state(s)) < 0)
@@ -1115,6 +1118,7 @@ static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, · 150 unmodified lines
1115static void encode_remap(FFV1Context *f, FFV1SliceContext *sc)1118static void encode_remap(FFV1Context *f, FFV1SliceContext *sc)
1116{1119{
1117 int transparency = f->transparency;1120 int transparency = f->transparency;
1121 int flip = sc->remap == 2 ? 0x7FFF : 0;
1118 1122
1119 for (int p= 0; p<3 + transparency; p++) {1123 for (int p= 0; p<3 + transparency; p++) {
1120 int j = 0;1124 int j = 0;
@@ -1123,7 +1127,7 @@ static void encode_remap(FFV1Context *f, FFV1SliceContext *sc) · 2 unmodified lines
1123 int run = 0;1127 int run = 0;
1124 memset(state, 128, sizeof(state));1128 memset(state, 128, sizeof(state));
1125 for (int i= 0; i<65536; i++) {1129 for (int i= 0; i<65536; i++) {
1126 int ri = i ^ ((i&0x8000) ? 0 : 0x7FFF);1130 int ri = i ^ ((i&0x8000) ? 0 : flip);
1127 int u = sc->fltmap[p][ri];1131 int u = sc->fltmap[p][ri];
1128 sc->fltmap[p][ri] = j;1132 sc->fltmap[p][ri] = j;
1129 j+= u;1133 j+= u;
@@ -1249,7 +1253,7 @@ size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx) · 119 unmodified lines
1249 maxsize += f->slice_count * 800; //for slice header1253 maxsize += f->slice_count * 800; //for slice header
1250 if (f->version > 3) {1254 if (f->version > 3) {
1251 maxsize *= f->bits_per_raw_sample + 1;1255 maxsize *= f->bits_per_raw_sample + 1;
1252 if (f->flt) //remap table1256 if (f->remap_mode)
1253 maxsize += f->slice_count * 70000 * (1 + 2*f->chroma_planes + f->transparency);1257 maxsize += f->slice_count * 70000 * (1 + 2*f->chroma_planes + f->transparency);
1254 } else {1258 } else {
1255 maxsize += f->slice_count * 2 * (avctx->width + avctx->height); //for bug with slices that code some pixels more than once1259 maxsize += f->slice_count * 2 * (avctx->width + avctx->height); //for bug with slices that code some pixels more than once
@@ -1432,6 +1436,16 @@ static const AVOption options[] = { · 176 unmodified lines
1432 { .i64 = QTABLE_8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },1436 { .i64 = QTABLE_8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1433 { "greater8bit", NULL, 0, AV_OPT_TYPE_CONST,1437 { "greater8bit", NULL, 0, AV_OPT_TYPE_CONST,
1434 { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },1438 { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1439 { "remap_mode", "Remap Mode", OFFSET(remap_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE, .unit = "remap_mode" },
1440 { "auto", "Automatic", 0, AV_OPT_TYPE_CONST,
1441 { .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1442 { "off", "Disabled", 0, AV_OPT_TYPE_CONST,
1443 { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1444 { "dualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
1445 { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1446 { "flipdualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
1447 { .i64 = 2 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1448
1435 1449
1436 { NULL }1450 { NULL }
1437};1451};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t