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 Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc> --- libavcodec/ffv1.h | 1 + libavcodec/ffv1dec.c | 9 +++++---- libavcodec/ffv1enc.c | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 189004f7981..6c7ef4872a1 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -140,6 +140,7 @@ typedef struct FFV1Context { uint8_t (*initial_states[MAX_QUANT_TABLES])[32]; int colorspace; int flt; + int remap_mode; int use32bit; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 72c93fcf0cd..e534583d8d6 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -228,8 +228,8 @@ static int decode_slice_header(const FFV1Context *f, } if (f->combined_version >= 0x40004) { sc->remap = ff_ffv1_get_symbol(c, state, 0); - if (sc->remap > 1U || - sc->remap == 1 && !f->flt) { + if (sc->remap > 2U || + sc->remap && !f->flt) { av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", sc->remap); return AVERROR_INVALIDDATA; } @@ -253,6 +253,7 @@ static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc) static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) { int transparency = f->transparency; + int flip = sc->remap == 2 ? 0x7FFF : 0; for (int p= 0; p<3 + transparency; p++) { int j = 0; @@ -267,13 +268,13 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) if (lu) { lu ^= !run; while (run--) { - sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF); + sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip); i++; } } else { i += run; if (i != 65536) - sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF); + sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip); lu ^= !run; } } diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 4c9d247bcf1..bd3f989e849 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -939,6 +939,9 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, } av_assert0(s->bits_per_raw_sample >= 8); + if (s->remap_mode < 0) + s->remap_mode = s->flt ? 2 : 0; + return av_pix_fmt_get_chroma_sub_sample(pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); } @@ -999,7 +1002,7 @@ static int encode_init_internal(AVCodecContext *avctx) ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8); - s->slices[j].remap = s->flt; + s->slices[j].remap = s->remap_mode; } if ((ret = ff_ffv1_init_slices_state(s)) < 0) @@ -1157,6 +1160,7 @@ static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, static void encode_remap(FFV1Context *f, FFV1SliceContext *sc) { int transparency = f->transparency; + int flip = sc->remap == 2 ? 0x7FFF : 0; for (int p= 0; p<3 + transparency; p++) { int j = 0; @@ -1165,7 +1169,7 @@ static void encode_remap(FFV1Context *f, FFV1SliceContext *sc) int run = 0; memset(state, 128, sizeof(state)); for (int i= 0; i<65536; i++) { - int ri = i ^ ((i&0x8000) ? 0 : 0x7FFF); + int ri = i ^ ((i&0x8000) ? 0 : flip); int u = sc->fltmap[p][ri]; sc->fltmap[p][ri] = j; j+= u; @@ -1316,7 +1320,7 @@ size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx) maxsize += f->slice_count * 800; //for slice header and if (f->version > 3) { maxsize *= f->bits_per_raw_sample + 1; - if (f->flt) //remap table + if (f->remap_mode) maxsize += f->slice_count * 70000 * (1 + 2*f->chroma_planes + f->transparency); } else { maxsize += f->slice_count * 2 * (avctx->width + avctx->height); //for bug with slices that code some pixels more than once @@ -1507,6 +1511,16 @@ static const AVOption options[] = { { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" }, { "rawlsb", "number of LSBs stored RAW", OFFSET(rawlsb), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, VE }, + { "remap_mode", "Remap Mode", OFFSET(remap_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE, .unit = "remap_mode" }, + { "auto", "Automatic", 0, AV_OPT_TYPE_CONST, + { .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" }, + { "off", "Disabled", 0, AV_OPT_TYPE_CONST, + { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" }, + { "dualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST, + { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" }, + { "flipdualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST, + { .i64 = 2 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" }, + { NULL } }; -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".