vpx/vp9/common/vp9_recon.c
Ronald S. Bultje c456b35fdf 32x32 transform for superblocks.
This adds Debargha's DCT/DWT hybrid and a regular 32x32 DCT, and adds
code all over the place to wrap that in the bitstream/encoder/decoder/RD.

Some implementation notes (these probably need careful review):
- token range is extended by 1 bit, since the value range out of this
  transform is [-16384,16383].
- the coefficients coming out of the FDCT are manually scaled back by
  1 bit, or else they won't fit in int16_t (they are 17 bits). Because
  of this, the RD error scoring does not right-shift the MSE score by
  two (unlike for 4x4/8x8/16x16).
- to compensate for this loss in precision, the quantizer is halved
  also. This is currently a little hacky.
- FDCT and IDCT is double-only right now. Needs a fixed-point impl.
- There are no default probabilities for the 32x32 transform yet; I'm
  simply using the 16x16 luma ones. A future commit will add newly
  generated probabilities for all transforms.
- No ADST version. I don't think we'll add one for this level; if an
  ADST is desired, transform-size selection can scale back to 16x16
  or lower, and use an ADST at that level.

Additional notes specific to Debargha's DWT/DCT hybrid:
- coefficient scale is different for the top/left 16x16 (DCT-over-DWT)
  block than for the rest (DWT pixel differences) of the block. Therefore,
  RD error scoring isn't easily scalable between coefficient and pixel
  domain. Thus, unfortunately, we need to compute the RD distortion in
  the pixel domain until we figure out how to scale these appropriately.

Change-Id: I00386f20f35d7fabb19aba94c8162f8aee64ef2b
2012-12-07 14:45:05 -08:00

245 lines
4.5 KiB
C

/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vpx_ports/config.h"
#include "vp9_rtcd.h"
#include "vp9/common/vp9_blockd.h"
void vp9_recon_b_c
(
unsigned char *pred_ptr,
short *diff_ptr,
unsigned char *dst_ptr,
int stride
) {
int r, c;
for (r = 0; r < 4; r++) {
for (c = 0; c < 4; c++) {
int a = diff_ptr[c] + pred_ptr[c];
if (a < 0)
a = 0;
if (a > 255)
a = 255;
dst_ptr[c] = (unsigned char) a;
}
dst_ptr += stride;
diff_ptr += 16;
pred_ptr += 16;
}
}
void vp9_recon_uv_b_c
(
unsigned char *pred_ptr,
short *diff_ptr,
unsigned char *dst_ptr,
int stride
) {
int r, c;
for (r = 0; r < 4; r++) {
for (c = 0; c < 4; c++) {
int a = diff_ptr[c] + pred_ptr[c];
if (a < 0)
a = 0;
if (a > 255)
a = 255;
dst_ptr[c] = (unsigned char) a;
}
dst_ptr += stride;
diff_ptr += 8;
pred_ptr += 8;
}
}
void vp9_recon4b_c
(
unsigned char *pred_ptr,
short *diff_ptr,
unsigned char *dst_ptr,
int stride
) {
int r, c;
for (r = 0; r < 4; r++) {
for (c = 0; c < 16; c++) {
int a = diff_ptr[c] + pred_ptr[c];
if (a < 0)
a = 0;
if (a > 255)
a = 255;
dst_ptr[c] = (unsigned char) a;
}
dst_ptr += stride;
diff_ptr += 16;
pred_ptr += 16;
}
}
void vp9_recon2b_c
(
unsigned char *pred_ptr,
short *diff_ptr,
unsigned char *dst_ptr,
int stride
) {
int r, c;
for (r = 0; r < 4; r++) {
for (c = 0; c < 8; c++) {
int a = diff_ptr[c] + pred_ptr[c];
if (a < 0)
a = 0;
if (a > 255)
a = 255;
dst_ptr[c] = (unsigned char) a;
}
dst_ptr += stride;
diff_ptr += 8;
pred_ptr += 8;
}
}
#if CONFIG_SUPERBLOCKS
void vp9_recon_mby_s_c(MACROBLOCKD *xd, uint8_t *dst) {
int x, y;
BLOCKD *b = &xd->block[0];
int stride = b->dst_stride;
short *diff = b->diff;
for (y = 0; y < 16; y++) {
for (x = 0; x < 16; x++) {
int a = dst[x] + diff[x];
if (a < 0)
a = 0;
else if (a > 255)
a = 255;
dst[x] = a;
}
dst += stride;
diff += 16;
}
}
void vp9_recon_mbuv_s_c(MACROBLOCKD *xd, uint8_t *udst, uint8_t *vdst) {
int x, y, i;
uint8_t *dst = udst;
for (i = 0; i < 2; i++, dst = vdst) {
BLOCKD *b = &xd->block[16 + 4 * i];
int stride = b->dst_stride;
short *diff = b->diff;
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
int a = dst[x] + diff[x];
if (a < 0)
a = 0;
else if (a > 255)
a = 255;
dst[x] = a;
}
dst += stride;
diff += 8;
}
}
}
#if CONFIG_TX32X32
void vp9_recon_sby_s_c(MACROBLOCKD *xd, uint8_t *dst) {
int x, y, stride = xd->block[0].dst_stride;
short *diff = xd->sb_coeff_data.diff;
for (y = 0; y < 32; y++) {
for (x = 0; x < 32; x++) {
int a = dst[x] + diff[x];
if (a < 0)
a = 0;
else if (a > 255)
a = 255;
dst[x] = a;
}
dst += stride;
diff += 32;
}
}
void vp9_recon_sbuv_s_c(MACROBLOCKD *xd, uint8_t *udst, uint8_t *vdst) {
int x, y, stride = xd->block[16].dst_stride;
short *udiff = xd->sb_coeff_data.diff + 1024;
short *vdiff = xd->sb_coeff_data.diff + 1280;
for (y = 0; y < 16; y++) {
for (x = 0; x < 16; x++) {
int u = udst[x] + udiff[x];
int v = vdst[x] + vdiff[x];
if (u < 0)
u = 0;
else if (u > 255)
u = 255;
if (v < 0)
v = 0;
else if (v > 255)
v = 255;
udst[x] = u;
vdst[x] = v;
}
udst += stride;
vdst += stride;
udiff += 16;
vdiff += 16;
}
}
#endif
#endif
void vp9_recon_mby_c(MACROBLOCKD *xd) {
int i;
for (i = 0; i < 16; i += 4) {
BLOCKD *b = &xd->block[i];
vp9_recon4b(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
}
}
void vp9_recon_mb_c(MACROBLOCKD *xd) {
int i;
for (i = 0; i < 16; i += 4) {
BLOCKD *b = &xd->block[i];
vp9_recon4b(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
}
for (i = 16; i < 24; i += 2) {
BLOCKD *b = &xd->block[i];
vp9_recon2b(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
}
}