summaryrefslogtreecommitdiff
path: root/libavcodec/vc2enc_dwt.c
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-02-19 14:56:22 +0000
committerRostislav Pehlivanov <atomnuker@gmail.com>2016-02-20 13:49:44 +0000
commit029c069c6d98fd2ff0ab9e615f5445655501175f (patch)
tree3dc4bee8323f492632235072ba51cc3d883f3673 /libavcodec/vc2enc_dwt.c
parent56e2cd9c042e05255aa28487694c29aaec023263 (diff)
downloadffmpeg-029c069c6d98fd2ff0ab9e615f5445655501175f.tar.gz
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>
Diffstat (limited to 'libavcodec/vc2enc_dwt.c')
-rw-r--r--libavcodec/vc2enc_dwt.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libavcodec/vc2enc_dwt.c b/libavcodec/vc2enc_dwt.c
index eb341684cd..c60b003a31 100644
--- a/libavcodec/vc2enc_dwt.c
+++ b/libavcodec/vc2enc_dwt.c
@@ -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)