summaryrefslogtreecommitdiff
path: root/vp8/common/idctllm.c
diff options
context:
space:
mode:
authorHui Su <huisu@google.com>2012-06-13 19:03:31 -0700
committerHui Su <huisu@google.com>2012-06-28 17:09:47 -0700
commite44ee38aef85e48601e54a13939f2a299bb583e0 (patch)
tree9a4b27e1b2a663fb4c852f4768c6fef91d785018 /vp8/common/idctllm.c
parent0e734a63e87c9f87a5ed3dc8c2c698f0cdb1dad7 (diff)
downloadlibvpx-e44ee38aef85e48601e54a13939f2a299bb583e0.tar
libvpx-e44ee38aef85e48601e54a13939f2a299bb583e0.tar.gz
libvpx-e44ee38aef85e48601e54a13939f2a299bb583e0.tar.bz2
libvpx-e44ee38aef85e48601e54a13939f2a299bb583e0.zip
Add lossless compression mode.
This commit adds lossless compression capability to the experimental branch. The lossless experiment can be enabled using --enable-lossless in configure. When the experiment is enabled, the encoder will use lossless compression mode by command line option --lossless, and the decoder automatically recognizes a losslessly encoded clip and decodes accordingly. To achieve the lossless coding, this commit has changed the following: 1. To encode at lossless mode, encoder forces the use of unit quantizer, i.e, Q 0, where effective quantization is 1. Encoder also disables the usage of 8x8 transform and allows only 4x4 transform; 2. At Q 0, the first order 4x4 DCT/IDCT have been switched over to a pair of forward and inverse Walsh-Hadamard Transform (http://goo.gl/EIsfy), with proper scaling applied to match the range of the original 4x4 DCT/IDCT pair; 3. At Q 0, the second order remains to use the previous walsh-hadamard transform pair. However, to maintain the reversibility in second order transform at Q 0, scaling down is applied to first order DC coefficients prior to forward transform, and scaling up is applied to the second order output prior to quantization. Symmetric upscaling and downscaling are added around inverse second order transform; 4. At lossless mode, encoder also disables a number of minor features to ensure no loss is introduced, these features includes: a. Trellis quantization optimization b. Loop filtering c. Aggressive zero-binning, rounding and zero-bin boosting d. Mode based zero-bin boosting Lossless coding test was performed on all clips within the derf set, to verify that the commit has achieved lossless compression for all clips. The average compression ratio is around 2.57 to 1. (http://goo.gl/dEShs) Change-Id: Ia3aba7dd09df40dd590f93b9aba134defbc64e34
Diffstat (limited to 'vp8/common/idctllm.c')
-rw-r--r--vp8/common/idctllm.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/vp8/common/idctllm.c b/vp8/common/idctllm.c
index 75ce8d44d..acb856d53 100644
--- a/vp8/common/idctllm.c
+++ b/vp8/common/idctllm.c
@@ -23,6 +23,7 @@
* x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
**************************************************************************/
#include "vpx_ports/config.h"
+#include "vp8/common/idct.h"
#include <math.h>
@@ -195,6 +196,163 @@ void vp8_short_inv_walsh4x4_1_c(short *in, short *out)
}
}
+#if CONFIG_LOSSLESS
+void vp8_short_inv_walsh4x4_lossless_c(short *input, short *output)
+{
+ int i;
+ int a1, b1, c1, d1;
+ short *ip = input;
+ short *op = output;
+
+ for (i = 0; i < 4; i++)
+ {
+ a1 = ((ip[0] + ip[3]))>>Y2_WHT_UPSCALE_FACTOR;
+ b1 = ((ip[1] + ip[2]))>>Y2_WHT_UPSCALE_FACTOR;
+ c1 = ((ip[1] - ip[2]))>>Y2_WHT_UPSCALE_FACTOR;
+ d1 = ((ip[0] - ip[3]))>>Y2_WHT_UPSCALE_FACTOR;
+
+ op[0] = (a1 + b1 + 1)>>1;
+ op[1] = (c1 + d1)>>1;
+ op[2] = (a1 - b1)>>1;
+ op[3] = (d1 - c1)>>1;
+
+ ip += 4;
+ op += 4;
+ }
+
+ ip = output;
+ op = output;
+ for (i = 0; i < 4; i++)
+ {
+ a1 = ip[0] + ip[12];
+ b1 = ip[4] + ip[8];
+ c1 = ip[4] - ip[8];
+ d1 = ip[0] - ip[12];
+
+
+ op[0] = ((a1 + b1 + 1)>>1)<<Y2_WHT_UPSCALE_FACTOR;
+ op[4] = ((c1 + d1)>>1)<<Y2_WHT_UPSCALE_FACTOR;
+ op[8] = ((a1 - b1)>>1)<<Y2_WHT_UPSCALE_FACTOR;
+ op[12]= ((d1 - c1)>>1)<<Y2_WHT_UPSCALE_FACTOR;
+
+ ip++;
+ op++;
+ }
+}
+
+void vp8_short_inv_walsh4x4_1_lossless_c(short *in, short *out)
+{
+ int i;
+ short tmp[4];
+ short *ip = in;
+ short *op = tmp;
+
+ op[0] =((ip[0]>>Y2_WHT_UPSCALE_FACTOR)+ 1)>>1;
+ op[1] = op[2] = op[3] = ((ip[0]>>Y2_WHT_UPSCALE_FACTOR)>>1);
+
+ ip = tmp;
+ op = out;
+ for(i = 0; i<4; i++)
+ {
+ op[0] =((ip[0]+ 1)>>1)<<Y2_WHT_UPSCALE_FACTOR;
+ op[4] = op[8] = op[12] = ((ip[0]>>1))<<Y2_WHT_UPSCALE_FACTOR;
+ ip ++;
+ op ++;
+ }
+}
+
+void vp8_short_inv_walsh4x4_x8_c(short *input, short *output, int pitch)
+{
+ int i;
+ int a1, b1, c1, d1;
+ short *ip = input;
+ short *op = output;
+ int shortpitch = pitch >> 1;
+
+ for (i = 0; i < 4; i++)
+ {
+ a1 = ((ip[0] + ip[3]))>>WHT_UPSCALE_FACTOR;
+ b1 = ((ip[1] + ip[2]))>>WHT_UPSCALE_FACTOR;
+ c1 = ((ip[1] - ip[2]))>>WHT_UPSCALE_FACTOR;
+ d1 = ((ip[0] - ip[3]))>>WHT_UPSCALE_FACTOR;
+
+ op[0] = (a1 + b1 + 1)>>1;
+ op[1] = (c1 + d1)>>1;
+ op[2] = (a1 - b1)>>1;
+ op[3] = (d1 - c1)>>1;
+
+ ip += 4;
+ op += shortpitch;
+ }
+
+ ip = output;
+ op = output;
+ for (i = 0; i < 4; i++)
+ {
+ a1 = ip[shortpitch*0] + ip[shortpitch*3];
+ b1 = ip[shortpitch*1] + ip[shortpitch*2];
+ c1 = ip[shortpitch*1] - ip[shortpitch*2];
+ d1 = ip[shortpitch*0] - ip[shortpitch*3];
+
+
+ op[shortpitch*0] = (a1 + b1 + 1)>>1;
+ op[shortpitch*1] = (c1 + d1)>>1;
+ op[shortpitch*2] = (a1 - b1)>>1;
+ op[shortpitch*3] = (d1 - c1)>>1;
+
+ ip++;
+ op++;
+ }
+}
+
+void vp8_short_inv_walsh4x4_1_x8_c(short *in, short *out, int pitch)
+{
+ int i;
+ short tmp[4];
+ short *ip = in;
+ short *op = tmp;
+ int shortpitch = pitch >> 1;
+
+ op[0] =((ip[0]>>WHT_UPSCALE_FACTOR) + 1)>>1;
+ op[1] = op[2] = op[3] = ((ip[0]>>WHT_UPSCALE_FACTOR)>>1);
+
+
+ ip = tmp;
+ op = out;
+ for(i = 0; i<4; i++)
+ {
+ op[shortpitch*0] =(ip[0]+ 1)>>1;
+ op[shortpitch*1] = op[shortpitch*2] = op[shortpitch*3] = ip[0]>>1;
+ ip ++;
+ op ++;
+ }
+}
+
+void vp8_dc_only_inv_walsh_add_c(short input_dc, unsigned char *pred_ptr, unsigned char *dst_ptr, int pitch, int stride)
+{
+ int r, c;
+ short tmp[16];
+ vp8_short_inv_walsh4x4_1_x8_c( &input_dc, tmp, 4<<1);
+
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+ int a = tmp[r*4 + c] + pred_ptr[c] ;
+ if (a < 0)
+ a = 0;
+
+ if (a > 255)
+ a = 255;
+
+ dst_ptr[c] = (unsigned char) a ;
+ }
+
+ dst_ptr += stride;
+ pred_ptr += pitch;
+ }
+}
+#endif
void vp8_dc_only_idct_add_8x8_c(short input_dc,
unsigned char *pred_ptr,