mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
vc2enc: add support for Haar wavelet transforms
This commit adds support for the (simple, allowed in the spec, but inferior in quality) Haar wavelet transforms. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
This commit is contained in:
parent
56e2cd9c04
commit
029c069c6d
@ -1153,8 +1153,10 @@ static const AVOption vc2enc_options[] = {
|
||||
{"slice_height", "Slice height", offsetof(VC2EncContext, slice_height), AV_OPT_TYPE_INT, {.i64 = 64}, 8, 1024, VC2ENC_FLAGS, "slice_height"},
|
||||
{"wavelet_depth", "Transform depth", offsetof(VC2EncContext, wavelet_depth), AV_OPT_TYPE_INT, {.i64 = 5}, 1, 5, VC2ENC_FLAGS, "wavelet_depth"},
|
||||
{"wavelet_type", "Transform type", offsetof(VC2EncContext, wavelet_idx), AV_OPT_TYPE_INT, {.i64 = VC2_TRANSFORM_9_7}, 0, VC2_TRANSFORMS_NB, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"9_7", "Deslauriers-Dubuc (9,7)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"5_3", "LeGall (5,3)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"9_7", "Deslauriers-Dubuc (9,7)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"5_3", "LeGall (5,3)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"haar", "Haar (with shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR_S}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"haar_noshift", "Haar (without shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
|
||||
{"qm", "Custom quantization matrix", offsetof(VC2EncContext, quant_matrix), AV_OPT_TYPE_INT, {.i64 = VC2_QM_DEF}, 0, VC2_QM_NB, VC2ENC_FLAGS, "quant_matrix"},
|
||||
{"default", "Default from the specifications", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_DEF}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "quant_matrix"},
|
||||
{"color", "Prevents low bitrate discoloration", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_COL}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "quant_matrix"},
|
||||
|
@ -211,10 +211,56 @@ static void vc2_subband_dwt_53(VC2TransformContext *t, dwtcoef *data,
|
||||
deinterleave(data, stride, width, height, synth);
|
||||
}
|
||||
|
||||
static av_always_inline void dwt_haar(VC2TransformContext *t, dwtcoef *data,
|
||||
ptrdiff_t stride, int width, int height,
|
||||
const int s)
|
||||
{
|
||||
int x, y;
|
||||
dwtcoef *synth = t->buffer, *synthl = synth, *datal = data;
|
||||
const ptrdiff_t synth_width = width << 1;
|
||||
const ptrdiff_t synth_height = height << 1;
|
||||
|
||||
/* Horizontal synthesis. */
|
||||
for (y = 0; y < synth_height; y++) {
|
||||
for (x = 0; x < synth_width; x += 2) {
|
||||
synthl[y*synth_width + x + 1] = (datal[y*stride + x + 1] << s) -
|
||||
(datal[y*stride + x] << s);
|
||||
synthl[y*synth_width + x] = (datal[y*stride + x + 0] << s) +
|
||||
((synthl[y*synth_width + x + 1] + 1) >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Vertical synthesis. */
|
||||
for (x = 0; x < synth_width; x++) {
|
||||
for (y = 0; y < synth_height; y += 2) {
|
||||
synthl[(y + 1)*synth_width + x] = synthl[(y + 1)*synth_width + x] -
|
||||
synthl[y*synth_width + x];
|
||||
synthl[y*synth_width + x] = synthl[y*synth_width + x] +
|
||||
((synthl[(y + 1)*synth_width + x] + 1) >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
deinterleave(data, stride, width, height, synth);
|
||||
}
|
||||
|
||||
static void vc2_subband_dwt_haar(VC2TransformContext *t, dwtcoef *data,
|
||||
ptrdiff_t stride, int width, int height)
|
||||
{
|
||||
dwt_haar(t, data, stride, width, height, 0);
|
||||
}
|
||||
|
||||
static void vc2_subband_dwt_haar_shift(VC2TransformContext *t, dwtcoef *data,
|
||||
ptrdiff_t stride, int width, int height)
|
||||
{
|
||||
dwt_haar(t, data, stride, width, height, 1);
|
||||
}
|
||||
|
||||
av_cold int ff_vc2enc_init_transforms(VC2TransformContext *s, int p_width, int p_height)
|
||||
{
|
||||
s->vc2_subband_dwt[VC2_TRANSFORM_9_7] = vc2_subband_dwt_97;
|
||||
s->vc2_subband_dwt[VC2_TRANSFORM_5_3] = vc2_subband_dwt_53;
|
||||
s->vc2_subband_dwt[VC2_TRANSFORM_HAAR] = vc2_subband_dwt_haar;
|
||||
s->vc2_subband_dwt[VC2_TRANSFORM_HAAR_S] = vc2_subband_dwt_haar_shift;
|
||||
|
||||
s->buffer = av_malloc(2*p_width*p_height*sizeof(dwtcoef));
|
||||
if (!s->buffer)
|
||||
|
Loading…
Reference in New Issue
Block a user