2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-12-23 16:20:10 +01:00
|
|
|
#include "./vpx_config.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_scale/yv12config.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_postproc.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_textblit.h"
|
2012-12-03 23:19:49 +01:00
|
|
|
#include "vpx_scale/vpx_scale.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_systemdependent.h"
|
2012-11-28 19:00:25 +01:00
|
|
|
#include "./vp9_rtcd.h"
|
2012-12-03 21:26:51 +01:00
|
|
|
#include "./vpx_scale_rtcd.h"
|
2012-11-28 19:00:25 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
#define RGB_TO_YUV(t) \
|
|
|
|
( (0.257*(float)(t >> 16)) + (0.504*(float)(t >> 8 & 0xff)) + \
|
|
|
|
(0.098*(float)(t & 0xff)) + 16), \
|
|
|
|
(-(0.148*(float)(t >> 16)) - (0.291*(float)(t >> 8 & 0xff)) + \
|
|
|
|
(0.439*(float)(t & 0xff)) + 128), \
|
|
|
|
( (0.439*(float)(t >> 16)) - (0.368*(float)(t >> 8 & 0xff)) - \
|
|
|
|
(0.071*(float)(t & 0xff)) + 128)
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2010-10-28 01:04:02 +02:00
|
|
|
/* global constants */
|
2012-12-23 16:20:10 +01:00
|
|
|
#if 0 && CONFIG_POSTPROC_VISUALIZER
|
2012-07-14 00:21:29 +02:00
|
|
|
static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] = {
|
|
|
|
{ RGB_TO_YUV(0x98FB98) }, /* PaleGreen */
|
|
|
|
{ RGB_TO_YUV(0x00FF00) }, /* Green */
|
|
|
|
{ RGB_TO_YUV(0xADFF2F) }, /* GreenYellow */
|
|
|
|
{ RGB_TO_YUV(0x8F0000) }, /* Dark Red */
|
|
|
|
{ RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
|
|
|
|
{ RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
|
|
|
|
{ RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
|
|
|
|
{ RGB_TO_YUV(0x8F0000) }, /* Dark Red */
|
|
|
|
{ RGB_TO_YUV(0x8F0000) }, /* Dark Red */
|
|
|
|
{ RGB_TO_YUV(0x228B22) }, /* ForestGreen */
|
|
|
|
{ RGB_TO_YUV(0x006400) }, /* DarkGreen */
|
|
|
|
{ RGB_TO_YUV(0x98F5FF) }, /* Cadet Blue */
|
|
|
|
{ RGB_TO_YUV(0x6CA6CD) }, /* Sky Blue */
|
|
|
|
{ RGB_TO_YUV(0x00008B) }, /* Dark blue */
|
|
|
|
{ RGB_TO_YUV(0x551A8B) }, /* Purple */
|
|
|
|
{ RGB_TO_YUV(0xFF0000) } /* Red */
|
|
|
|
{ RGB_TO_YUV(0xCC33FF) }, /* Magenta */
|
2010-10-26 21:58:51 +02:00
|
|
|
};
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static const unsigned char B_PREDICTION_MODE_colors[B_MODE_COUNT][3] = {
|
|
|
|
{ RGB_TO_YUV(0x6633ff) }, /* Purple */
|
|
|
|
{ RGB_TO_YUV(0xcc33ff) }, /* Magenta */
|
|
|
|
{ RGB_TO_YUV(0xff33cc) }, /* Pink */
|
|
|
|
{ RGB_TO_YUV(0xff3366) }, /* Coral */
|
|
|
|
{ RGB_TO_YUV(0x3366ff) }, /* Blue */
|
|
|
|
{ RGB_TO_YUV(0xed00f5) }, /* Dark Blue */
|
|
|
|
{ RGB_TO_YUV(0x2e00b8) }, /* Dark Purple */
|
|
|
|
{ RGB_TO_YUV(0xff6633) }, /* Orange */
|
|
|
|
{ RGB_TO_YUV(0x33ccff) }, /* Light Blue */
|
|
|
|
{ RGB_TO_YUV(0x8ab800) }, /* Green */
|
|
|
|
{ RGB_TO_YUV(0xffcc33) }, /* Light Orange */
|
|
|
|
{ RGB_TO_YUV(0x33ffcc) }, /* Aqua */
|
|
|
|
{ RGB_TO_YUV(0x66ff33) }, /* Light Green */
|
|
|
|
{ RGB_TO_YUV(0xccff33) }, /* Yellow */
|
2010-11-04 18:35:02 +01:00
|
|
|
};
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static const unsigned char MV_REFERENCE_FRAME_colors[MAX_REF_FRAMES][3] = {
|
|
|
|
{ RGB_TO_YUV(0x00ff00) }, /* Blue */
|
|
|
|
{ RGB_TO_YUV(0x0000ff) }, /* Green */
|
|
|
|
{ RGB_TO_YUV(0xffff00) }, /* Yellow */
|
|
|
|
{ RGB_TO_YUV(0xff0000) }, /* Red */
|
2010-10-26 21:58:51 +02:00
|
|
|
};
|
2010-11-05 00:03:36 +01:00
|
|
|
#endif
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static const short kernel5[] = {
|
|
|
|
1, 1, 4, 1, 1
|
2010-05-18 17:58:33 +02:00
|
|
|
};
|
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
const short vp9_rv[] = {
|
2012-07-14 00:21:29 +02:00
|
|
|
8, 5, 2, 2, 8, 12, 4, 9, 8, 3,
|
|
|
|
0, 3, 9, 0, 0, 0, 8, 3, 14, 4,
|
|
|
|
10, 1, 11, 14, 1, 14, 9, 6, 12, 11,
|
|
|
|
8, 6, 10, 0, 0, 8, 9, 0, 3, 14,
|
|
|
|
8, 11, 13, 4, 2, 9, 0, 3, 9, 6,
|
|
|
|
1, 2, 3, 14, 13, 1, 8, 2, 9, 7,
|
|
|
|
3, 3, 1, 13, 13, 6, 6, 5, 2, 7,
|
|
|
|
11, 9, 11, 8, 7, 3, 2, 0, 13, 13,
|
|
|
|
14, 4, 12, 5, 12, 10, 8, 10, 13, 10,
|
|
|
|
4, 14, 4, 10, 0, 8, 11, 1, 13, 7,
|
|
|
|
7, 14, 6, 14, 13, 2, 13, 5, 4, 4,
|
|
|
|
0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
|
|
|
|
8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
|
|
|
|
3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
|
|
|
|
3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
|
|
|
|
13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
|
|
|
|
5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
|
|
|
|
9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
|
|
|
|
4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
|
|
|
|
3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
|
|
|
|
11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
|
|
|
|
5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
|
|
|
|
0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
|
|
|
|
10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
|
|
|
|
4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
|
|
|
|
0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
|
|
|
|
8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
|
|
|
|
3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
|
|
|
|
3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
|
|
|
|
13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
|
|
|
|
5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
|
|
|
|
9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
|
|
|
|
4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
|
|
|
|
3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
|
|
|
|
11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
|
|
|
|
5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
|
|
|
|
0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
|
|
|
|
10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
|
|
|
|
4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
|
|
|
|
3, 8, 3, 7, 8, 5, 11, 4, 12, 3,
|
|
|
|
11, 9, 14, 8, 14, 13, 4, 3, 1, 2,
|
|
|
|
14, 6, 5, 4, 4, 11, 4, 6, 2, 1,
|
|
|
|
5, 8, 8, 12, 13, 5, 14, 10, 12, 13,
|
|
|
|
0, 9, 5, 5, 11, 10, 13, 9, 10, 13,
|
2010-05-18 17:58:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
/****************************************************************************
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
2013-05-14 20:01:57 +02:00
|
|
|
void vp9_post_proc_down_and_across_c(const uint8_t *src_ptr,
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *dst_ptr,
|
2012-11-01 00:09:17 +01:00
|
|
|
int src_pixels_per_line,
|
|
|
|
int dst_pixels_per_line,
|
|
|
|
int rows,
|
|
|
|
int cols,
|
|
|
|
int flimit) {
|
2013-05-14 20:01:57 +02:00
|
|
|
uint8_t const *p_src;
|
|
|
|
uint8_t *p_dst;
|
2012-07-14 00:21:29 +02:00
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
int i;
|
|
|
|
int v;
|
|
|
|
int pitch = src_pixels_per_line;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t d[8];
|
2012-07-14 00:21:29 +02:00
|
|
|
(void)dst_pixels_per_line;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (row = 0; row < rows; row++) {
|
|
|
|
/* post_proc_down for one row */
|
|
|
|
p_src = src_ptr;
|
|
|
|
p_dst = dst_ptr;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (col = 0; col < cols; col++) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
int kernel = 4;
|
|
|
|
int v = p_src[col];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = -2; i <= 2; i++) {
|
|
|
|
if (abs(v - p_src[col + i * pitch]) > flimit)
|
|
|
|
goto down_skip_convolve;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
kernel += kernel5[2 + i] * p_src[col + i * pitch];
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
v = (kernel >> 3);
|
|
|
|
down_skip_convolve:
|
|
|
|
p_dst[col] = v;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* now post_proc_across */
|
|
|
|
p_src = dst_ptr;
|
|
|
|
p_dst = dst_ptr;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
d[i] = p_src[i];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (col = 0; col < cols; col++) {
|
|
|
|
int kernel = 4;
|
|
|
|
v = p_src[col];
|
|
|
|
|
|
|
|
d[col & 7] = v;
|
|
|
|
|
|
|
|
for (i = -2; i <= 2; i++) {
|
|
|
|
if (abs(v - p_src[col + i]) > flimit)
|
|
|
|
goto across_skip_convolve;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
kernel += kernel5[2 + i] * p_src[col + i];
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
d[col & 7] = (kernel >> 3);
|
|
|
|
across_skip_convolve:
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (col >= 2)
|
|
|
|
p_dst[col - 2] = d[(col - 2) & 7];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* handle the last two pixels */
|
|
|
|
p_dst[col - 2] = d[(col - 2) & 7];
|
|
|
|
p_dst[col - 1] = d[(col - 1) & 7];
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* next row */
|
|
|
|
src_ptr += pitch;
|
|
|
|
dst_ptr += pitch;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static int q2mbl(int x) {
|
|
|
|
if (x < 20) x = 20;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x = 50 + (x - 50) * 10 / 8;
|
|
|
|
return x * x / 3;
|
|
|
|
}
|
2012-11-01 00:09:17 +01:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
void vp9_mbpost_proc_across_ip_c(uint8_t *src, int pitch,
|
2012-11-01 00:09:17 +01:00
|
|
|
int rows, int cols, int flimit) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int r, c, i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *s = src;
|
|
|
|
uint8_t d[16];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (r = 0; r < rows; r++) {
|
|
|
|
int sumsq = 0;
|
|
|
|
int sum = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = -8; i <= 6; i++) {
|
|
|
|
sumsq += s[i] * s[i];
|
|
|
|
sum += s[i];
|
|
|
|
d[i + 8] = 0;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (c = 0; c < cols + 8; c++) {
|
|
|
|
int x = s[c + 7] - s[c - 8];
|
|
|
|
int y = s[c + 7] + s[c - 8];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sum += x;
|
|
|
|
sumsq += x * y;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
d[c & 15] = s[c];
|
|
|
|
|
|
|
|
if (sumsq * 15 - sum * sum < flimit) {
|
|
|
|
d[c & 15] = (8 + sum + s[c]) >> 4;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
s[c - 8] = d[(c - 8) & 15];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
s += pitch;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch,
|
2012-11-01 00:09:17 +01:00
|
|
|
int rows, int cols, int flimit) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int r, c, i;
|
2012-10-31 01:12:12 +01:00
|
|
|
const short *rv3 = &vp9_rv[63 & rand()];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (c = 0; c < cols; c++) {
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *s = &dst[c];
|
2012-07-14 00:21:29 +02:00
|
|
|
int sumsq = 0;
|
|
|
|
int sum = 0;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t d[16];
|
2012-07-14 00:21:29 +02:00
|
|
|
const short *rv2 = rv3 + ((c * 17) & 127);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = -8; i <= 6; i++) {
|
|
|
|
sumsq += s[i * pitch] * s[i * pitch];
|
|
|
|
sum += s[i * pitch];
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (r = 0; r < rows + 8; r++) {
|
|
|
|
sumsq += s[7 * pitch] * s[ 7 * pitch] - s[-8 * pitch] * s[-8 * pitch];
|
|
|
|
sum += s[7 * pitch] - s[-8 * pitch];
|
|
|
|
d[r & 15] = s[0];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (sumsq * 15 - sum * sum < flimit) {
|
|
|
|
d[r & 15] = (rv2[r & 127] + sum + s[0]) >> 4;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
s[-8 * pitch] = d[(r - 8) & 15];
|
|
|
|
s += pitch;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
static void deblock_and_de_macro_block(YV12_BUFFER_CONFIG *source,
|
|
|
|
YV12_BUFFER_CONFIG *post,
|
|
|
|
int q,
|
|
|
|
int low_var_thresh,
|
2012-11-28 19:00:25 +01:00
|
|
|
int flag) {
|
2012-07-14 00:21:29 +02:00
|
|
|
double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
|
|
|
|
int ppl = (int)(level + .5);
|
|
|
|
(void) low_var_thresh;
|
|
|
|
(void) flag;
|
|
|
|
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_post_proc_down_and_across(source->y_buffer, post->y_buffer,
|
|
|
|
source->y_stride, post->y_stride,
|
|
|
|
source->y_height, source->y_width, ppl);
|
|
|
|
|
|
|
|
vp9_mbpost_proc_across_ip(post->y_buffer, post->y_stride, post->y_height,
|
|
|
|
post->y_width, q2mbl(q));
|
|
|
|
|
|
|
|
vp9_mbpost_proc_down(post->y_buffer, post->y_stride, post->y_height,
|
|
|
|
post->y_width, q2mbl(q));
|
|
|
|
|
|
|
|
vp9_post_proc_down_and_across(source->u_buffer, post->u_buffer,
|
|
|
|
source->uv_stride, post->uv_stride,
|
|
|
|
source->uv_height, source->uv_width, ppl);
|
|
|
|
vp9_post_proc_down_and_across(source->v_buffer, post->v_buffer,
|
|
|
|
source->uv_stride, post->uv_stride,
|
|
|
|
source->uv_height, source->uv_width, ppl);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
void vp9_deblock(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
|
|
|
|
int q) {
|
|
|
|
const int ppl = (int)(6.0e-05 * q * q * q - 0.0067 * q * q + 0.306 * q
|
|
|
|
+ 0.0065 + 0.5);
|
|
|
|
int i;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
|
|
|
|
const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
|
|
|
|
const int src_widths[3] = {src->y_width, src->uv_width, src->uv_width};
|
|
|
|
const int src_heights[3] = {src->y_height, src->uv_height, src->uv_height};
|
2012-11-28 19:00:25 +01:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
|
|
|
|
const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
|
2012-11-28 19:00:25 +01:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
for (i = 0; i < MAX_MB_PLANE; ++i)
|
|
|
|
vp9_post_proc_down_and_across(srcs[i], dsts[i],
|
|
|
|
src_strides[i], dst_strides[i],
|
|
|
|
src_heights[i], src_widths[i], ppl);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
void vp9_denoise(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
|
|
|
|
int q) {
|
|
|
|
const int ppl = (int)(6.0e-05 * q * q * q - 0.0067 * q * q + 0.306 * q
|
|
|
|
+ 0.0065 + 0.5);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
|
|
|
|
const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
|
|
|
|
const int src_widths[3] = {src->y_width, src->uv_width, src->uv_width};
|
|
|
|
const int src_heights[3] = {src->y_height, src->uv_height, src->uv_height};
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
|
|
|
|
const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
|
2012-11-28 19:00:25 +01:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
for (i = 0; i < MAX_MB_PLANE; ++i) {
|
|
|
|
const int src_stride = src_strides[i];
|
|
|
|
const uint8_t *const src = srcs[i] + 2 * src_stride + 2;
|
|
|
|
const int src_width = src_widths[i] - 4;
|
|
|
|
const int src_height = src_heights[i] - 4;
|
2012-11-28 19:00:25 +01:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
const int dst_stride = dst_strides[i];
|
|
|
|
uint8_t *const dst = dsts[i] + 2 * dst_stride + 2;
|
|
|
|
|
|
|
|
vp9_post_proc_down_and_across(src, dst, src_stride, dst_stride,
|
|
|
|
src_height, src_width, ppl);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
double vp9_gaussian(double sigma, double mu, double x) {
|
2012-07-14 00:21:29 +02:00
|
|
|
return 1 / (sigma * sqrt(2.0 * 3.14159265)) *
|
|
|
|
(exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)));
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static void fillrd(struct postproc_state *state, int q, int a) {
|
|
|
|
char char_dist[300];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
double sigma;
|
|
|
|
int ai = a, qi = q, i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sigma = ai + .5 + .6 * (63 - qi) / 63.0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* set up a lookup table of 256 entries that matches
|
|
|
|
* a gaussian distribution with sigma determined by q.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
double i;
|
|
|
|
int next, j;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
next = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = -32; i < 32; i++) {
|
2012-10-31 00:25:53 +01:00
|
|
|
int a = (int)(.5 + 256 * vp9_gaussian(sigma, 0, i));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (a) {
|
|
|
|
for (j = 0; j < a; j++) {
|
|
|
|
char_dist[next + j] = (char) i;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
next = next + j;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (next = next; next < 256; next++)
|
|
|
|
char_dist[next] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 3072; i++) {
|
|
|
|
state->noise[i] = char_dist[rand() & 0xff];
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
state->blackclamp[i] = -char_dist[0];
|
|
|
|
state->whiteclamp[i] = -char_dist[0];
|
|
|
|
state->bothclamp[i] = -2 * char_dist[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
state->last_q = q;
|
|
|
|
state->last_noise = a;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ROUTINE : plane_add_noise_c
|
|
|
|
*
|
2012-11-01 00:09:17 +01:00
|
|
|
* INPUTS : unsigned char *Start starting address of buffer to
|
|
|
|
* add gaussian noise to
|
2013-03-21 00:41:30 +01:00
|
|
|
* unsigned int width width of plane
|
|
|
|
* unsigned int height height of plane
|
|
|
|
* int pitch distance between subsequent lines of frame
|
2010-05-18 17:58:33 +02:00
|
|
|
* int q quantizer used to determine amount of noise
|
|
|
|
* to add
|
|
|
|
*
|
|
|
|
* OUTPUTS : None.
|
|
|
|
*
|
|
|
|
* RETURNS : void.
|
|
|
|
*
|
|
|
|
* FUNCTION : adds gaussian noise to a plane of pixels
|
|
|
|
*
|
|
|
|
* SPECIAL NOTES : None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-03-21 00:41:30 +01:00
|
|
|
void vp9_plane_add_noise_c(uint8_t *start, char *noise,
|
2010-05-18 17:58:33 +02:00
|
|
|
char blackclamp[16],
|
|
|
|
char whiteclamp[16],
|
|
|
|
char bothclamp[16],
|
2013-03-21 00:41:30 +01:00
|
|
|
unsigned int width, unsigned int height, int pitch) {
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int i, j;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
uint8_t *pos = start + i * pitch;
|
|
|
|
char *ref = (char *)(noise + (rand() & 0xff)); // NOLINT
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
for (j = 0; j < width; j++) {
|
|
|
|
if (pos[j] < blackclamp[0])
|
|
|
|
pos[j] = blackclamp[0];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
if (pos[j] > 255 + whiteclamp[0])
|
|
|
|
pos[j] = 255 + whiteclamp[0];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
pos[j] += ref[j];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-10-28 01:04:02 +02:00
|
|
|
/* Blend the macro block with a solid colored square. Leave the
|
|
|
|
* edges unblended to give distinction to macro blocks in areas
|
|
|
|
* filled with the same color block.
|
|
|
|
*/
|
2012-12-19 00:31:19 +01:00
|
|
|
void vp9_blend_mb_inner_c(uint8_t *y, uint8_t *u, uint8_t *v,
|
2012-07-14 00:21:29 +02:00
|
|
|
int y1, int u1, int v1, int alpha, int stride) {
|
|
|
|
int i, j;
|
|
|
|
int y1_const = y1 * ((1 << 16) - alpha);
|
|
|
|
int u1_const = u1 * ((1 << 16) - alpha);
|
|
|
|
int v1_const = v1 * ((1 << 16) - alpha);
|
|
|
|
|
|
|
|
y += 2 * stride + 2;
|
|
|
|
for (i = 0; i < 12; i++) {
|
|
|
|
for (j = 0; j < 12; j++) {
|
|
|
|
y[j] = (y[j] * alpha + y1_const) >> 16;
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
y += stride;
|
|
|
|
}
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
stride >>= 1;
|
2010-10-27 21:50:16 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
u += stride + 1;
|
|
|
|
v += stride + 1;
|
2010-10-27 21:50:16 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
for (j = 0; j < 6; j++) {
|
|
|
|
u[j] = (u[j] * alpha + u1_const) >> 16;
|
|
|
|
v[j] = (v[j] * alpha + v1_const) >> 16;
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
u += stride;
|
|
|
|
v += stride;
|
|
|
|
}
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-11-04 18:35:02 +01:00
|
|
|
/* Blend only the edge of the macro block. Leave center
|
|
|
|
* unblended to allow for other visualizations to be layered.
|
|
|
|
*/
|
2012-12-19 00:31:19 +01:00
|
|
|
void vp9_blend_mb_outer_c(uint8_t *y, uint8_t *u, uint8_t *v,
|
2012-07-14 00:21:29 +02:00
|
|
|
int y1, int u1, int v1, int alpha, int stride) {
|
|
|
|
int i, j;
|
|
|
|
int y1_const = y1 * ((1 << 16) - alpha);
|
|
|
|
int u1_const = u1 * ((1 << 16) - alpha);
|
|
|
|
int v1_const = v1 * ((1 << 16) - alpha);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
y[j] = (y[j] * alpha + y1_const) >> 16;
|
|
|
|
}
|
|
|
|
y += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 12; i++) {
|
|
|
|
y[0] = (y[0] * alpha + y1_const) >> 16;
|
|
|
|
y[1] = (y[1] * alpha + y1_const) >> 16;
|
|
|
|
y[14] = (y[14] * alpha + y1_const) >> 16;
|
|
|
|
y[15] = (y[15] * alpha + y1_const) >> 16;
|
|
|
|
y += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
y[j] = (y[j] * alpha + y1_const) >> 16;
|
|
|
|
}
|
|
|
|
y += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
stride >>= 1;
|
|
|
|
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
u[j] = (u[j] * alpha + u1_const) >> 16;
|
|
|
|
v[j] = (v[j] * alpha + v1_const) >> 16;
|
|
|
|
}
|
|
|
|
u += stride;
|
|
|
|
v += stride;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
u[0] = (u[0] * alpha + u1_const) >> 16;
|
|
|
|
v[0] = (v[0] * alpha + v1_const) >> 16;
|
|
|
|
|
|
|
|
u[7] = (u[7] * alpha + u1_const) >> 16;
|
|
|
|
v[7] = (v[7] * alpha + v1_const) >> 16;
|
2010-11-04 18:35:02 +01:00
|
|
|
|
|
|
|
u += stride;
|
|
|
|
v += stride;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-11-04 18:35:02 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
u[j] = (u[j] * alpha + u1_const) >> 16;
|
|
|
|
v[j] = (v[j] * alpha + v1_const) >> 16;
|
|
|
|
}
|
2010-11-04 18:35:02 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
void vp9_blend_b_c(uint8_t *y, uint8_t *u, uint8_t *v,
|
2012-07-14 00:21:29 +02:00
|
|
|
int y1, int u1, int v1, int alpha, int stride) {
|
|
|
|
int i, j;
|
|
|
|
int y1_const = y1 * ((1 << 16) - alpha);
|
|
|
|
int u1_const = u1 * ((1 << 16) - alpha);
|
|
|
|
int v1_const = v1 * ((1 << 16) - alpha);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
y[j] = (y[j] * alpha + y1_const) >> 16;
|
2010-11-04 18:35:02 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
y += stride;
|
|
|
|
}
|
2010-11-04 18:35:02 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
stride >>= 1;
|
2010-11-04 18:35:02 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
u[j] = (u[j] * alpha + u1_const) >> 16;
|
|
|
|
v[j] = (v[j] * alpha + v1_const) >> 16;
|
2010-11-04 18:35:02 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
u += stride;
|
|
|
|
v += stride;
|
|
|
|
}
|
2010-11-04 18:35:02 +01:00
|
|
|
}
|
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
static void constrain_line(int x0, int *x1, int y0, int *y1,
|
|
|
|
int width, int height) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
|
|
|
|
if (*x1 > width) {
|
|
|
|
dx = *x1 - x0;
|
|
|
|
dy = *y1 - y0;
|
|
|
|
|
|
|
|
*x1 = width;
|
|
|
|
if (dx)
|
|
|
|
*y1 = ((width - x0) * dy) / dx + y0;
|
|
|
|
}
|
|
|
|
if (*x1 < 0) {
|
|
|
|
dx = *x1 - x0;
|
|
|
|
dy = *y1 - y0;
|
|
|
|
|
|
|
|
*x1 = 0;
|
|
|
|
if (dx)
|
|
|
|
*y1 = ((0 - x0) * dy) / dx + y0;
|
|
|
|
}
|
|
|
|
if (*y1 > height) {
|
|
|
|
dx = *x1 - x0;
|
|
|
|
dy = *y1 - y0;
|
|
|
|
|
|
|
|
*y1 = height;
|
|
|
|
if (dy)
|
|
|
|
*x1 = ((height - y0) * dx) / dy + x0;
|
|
|
|
}
|
|
|
|
if (*y1 < 0) {
|
|
|
|
dx = *x1 - x0;
|
|
|
|
dy = *y1 - y0;
|
|
|
|
|
|
|
|
*y1 = 0;
|
|
|
|
if (dy)
|
|
|
|
*x1 = ((0 - y0) * dx) / dy + x0;
|
|
|
|
}
|
2010-10-23 00:41:06 +02:00
|
|
|
}
|
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
int vp9_post_proc_frame(VP9_COMMON *oci, YV12_BUFFER_CONFIG *dest,
|
|
|
|
vp9_ppflags_t *ppflags) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int q = oci->filter_level * 10 / 6;
|
|
|
|
int flags = ppflags->post_proc_flag;
|
|
|
|
int deblock_level = ppflags->deblocking_level;
|
|
|
|
int noise_level = ppflags->noise_level;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!oci->frame_to_show)
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (q > 63)
|
|
|
|
q = 63;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!flags) {
|
|
|
|
*dest = *oci->frame_to_show;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if ARCH_X86||ARCH_X86_64
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_reset_mmx_state();
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_DEMACROBLOCK) {
|
|
|
|
deblock_and_de_macro_block(oci->frame_to_show, &oci->post_proc_buffer,
|
2012-11-28 19:00:25 +01:00
|
|
|
q + (deblock_level - 5) * 10, 1, 0);
|
2012-10-31 22:40:53 +01:00
|
|
|
} else if (flags & VP9D_DEBLOCK) {
|
2013-05-14 20:01:57 +02:00
|
|
|
vp9_deblock(oci->frame_to_show, &oci->post_proc_buffer, q);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
2012-11-02 01:53:44 +01:00
|
|
|
vp8_yv12_copy_frame(oci->frame_to_show, &oci->post_proc_buffer);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_ADDNOISE) {
|
2012-07-14 00:21:29 +02:00
|
|
|
if (oci->postproc_state.last_q != q
|
|
|
|
|| oci->postproc_state.last_noise != noise_level) {
|
|
|
|
fillrd(&oci->postproc_state, 63 - q, noise_level);
|
|
|
|
}
|
|
|
|
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_plane_add_noise(oci->post_proc_buffer.y_buffer,
|
|
|
|
oci->postproc_state.noise,
|
|
|
|
oci->postproc_state.blackclamp,
|
|
|
|
oci->postproc_state.whiteclamp,
|
|
|
|
oci->postproc_state.bothclamp,
|
|
|
|
oci->post_proc_buffer.y_width,
|
|
|
|
oci->post_proc_buffer.y_height,
|
|
|
|
oci->post_proc_buffer.y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-23 16:20:10 +01:00
|
|
|
#if 0 && CONFIG_POSTPROC_VISUALIZER
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_DEBUG_TXT_FRAME_INFO) {
|
2012-07-14 00:21:29 +02:00
|
|
|
char message[512];
|
|
|
|
sprintf(message, "F%1dG%1dQ%3dF%3dP%d_s%dx%d",
|
|
|
|
(oci->frame_type == KEY_FRAME),
|
|
|
|
oci->refresh_golden_frame,
|
|
|
|
oci->base_qindex,
|
|
|
|
oci->filter_level,
|
|
|
|
flags,
|
|
|
|
oci->mb_cols, oci->mb_rows);
|
2012-11-01 00:09:17 +01:00
|
|
|
vp9_blit_text(message, oci->post_proc_buffer.y_buffer,
|
|
|
|
oci->post_proc_buffer.y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_DEBUG_TXT_MBLK_MODES) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i, j;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *y_ptr;
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
|
|
|
|
int mb_rows = post->y_height >> 4;
|
|
|
|
int mb_cols = post->y_width >> 4;
|
|
|
|
int mb_index = 0;
|
|
|
|
MODE_INFO *mi = oci->mi;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
y_ptr = post->y_buffer + 4 * post->y_stride + 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
/* vp9_filter each macro block */
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < mb_rows; i++) {
|
|
|
|
for (j = 0; j < mb_cols; j++) {
|
|
|
|
char zz[4];
|
2010-10-26 22:26:17 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sprintf(zz, "%c", mi[mb_index].mbmi.mode + 'a');
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_text(zz, y_ptr, post->y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
mb_index++;
|
|
|
|
y_ptr += 16;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
mb_index++; /* border */
|
|
|
|
y_ptr += post->y_stride * 16 - post->y_width;
|
2010-10-26 22:26:17 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-10-26 22:26:17 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_DEBUG_TXT_DC_DIFF) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i, j;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *y_ptr;
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
|
|
|
|
int mb_rows = post->y_height >> 4;
|
|
|
|
int mb_cols = post->y_width >> 4;
|
|
|
|
int mb_index = 0;
|
|
|
|
MODE_INFO *mi = oci->mi;
|
|
|
|
|
|
|
|
y_ptr = post->y_buffer + 4 * post->y_stride + 4;
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
/* vp9_filter each macro block */
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < mb_rows; i++) {
|
|
|
|
for (j = 0; j < mb_cols; j++) {
|
|
|
|
char zz[4];
|
2013-04-11 21:16:35 +02:00
|
|
|
int dc_diff = !(mi[mb_index].mbmi.mode != I4X4_PRED &&
|
2012-07-14 00:21:29 +02:00
|
|
|
mi[mb_index].mbmi.mode != SPLITMV &&
|
|
|
|
mi[mb_index].mbmi.mb_skip_coeff);
|
|
|
|
|
|
|
|
if (oci->frame_type == KEY_FRAME)
|
|
|
|
sprintf(zz, "a");
|
|
|
|
else
|
|
|
|
sprintf(zz, "%c", dc_diff + '0');
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_text(zz, y_ptr, post->y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
mb_index++;
|
|
|
|
y_ptr += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb_index++; /* border */
|
|
|
|
y_ptr += post->y_stride * 16 - post->y_width;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (flags & VP9D_DEBUG_TXT_RATE_INFO) {
|
2012-07-14 00:21:29 +02:00
|
|
|
char message[512];
|
2012-11-01 00:09:17 +01:00
|
|
|
snprintf(message, sizeof(message),
|
|
|
|
"Bitrate: %10.2f frame_rate: %10.2f ",
|
|
|
|
oci->bitrate, oci->framerate);
|
|
|
|
vp9_blit_text(message, oci->post_proc_buffer.y_buffer,
|
|
|
|
oci->post_proc_buffer.y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw motion vectors */
|
2012-10-31 22:40:53 +01:00
|
|
|
if ((flags & VP9D_DEBUG_DRAW_MV) && ppflags->display_mv_flag) {
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
|
|
|
|
int width = post->y_width;
|
|
|
|
int height = post->y_height;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *y_buffer = oci->post_proc_buffer.y_buffer;
|
2012-07-14 00:21:29 +02:00
|
|
|
int y_stride = oci->post_proc_buffer.y_stride;
|
|
|
|
MODE_INFO *mi = oci->mi;
|
|
|
|
int x0, y0;
|
|
|
|
|
|
|
|
for (y0 = 0; y0 < height; y0 += 16) {
|
|
|
|
for (x0 = 0; x0 < width; x0 += 16) {
|
|
|
|
int x1, y1;
|
|
|
|
|
|
|
|
if (!(ppflags->display_mv_flag & (1 << mi->mbmi.mode))) {
|
|
|
|
mi++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-05 00:03:36 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (mi->mbmi.mode == SPLITMV) {
|
|
|
|
switch (mi->mbmi.partitioning) {
|
2012-10-22 20:25:48 +02:00
|
|
|
case PARTITIONING_16X8 : { /* mv_top_bottom */
|
2012-07-14 00:21:29 +02:00
|
|
|
union b_mode_info *bmi = &mi->bmi[0];
|
|
|
|
MV *mv = &bmi->mv.as_mv;
|
2010-10-30 02:09:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 8 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 4 + (mv->row >> 3);
|
2010-10-30 02:09:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 8, &x1, y0 + 4, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 8, x1, y0 + 4, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi = &mi->bmi[8];
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 8 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 12 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 8, &x1, y0 + 12, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 8, x1, y0 + 12, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-10-22 20:25:48 +02:00
|
|
|
case PARTITIONING_8X16 : { /* mv_left_right */
|
2012-07-14 00:21:29 +02:00
|
|
|
union b_mode_info *bmi = &mi->bmi[0];
|
|
|
|
MV *mv = &bmi->mv.as_mv;
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 4 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 8 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 4, &x1, y0 + 8, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 4, x1, y0 + 8, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi = &mi->bmi[2];
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 12 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 8 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 12, &x1, y0 + 8, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 12, x1, y0 + 8, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-10-22 20:25:48 +02:00
|
|
|
case PARTITIONING_8X8 : { /* mv_quarters */
|
2012-07-14 00:21:29 +02:00
|
|
|
union b_mode_info *bmi = &mi->bmi[0];
|
|
|
|
MV *mv = &bmi->mv.as_mv;
|
2010-10-30 02:09:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 4 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 4 + (mv->row >> 3);
|
2010-10-30 02:09:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 4, &x1, y0 + 4, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 4, x1, y0 + 4, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi = &mi->bmi[2];
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 12 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 4 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 12, &x1, y0 + 4, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 12, x1, y0 + 4, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi = &mi->bmi[8];
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 4 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 12 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 4, &x1, y0 + 12, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 4, x1, y0 + 12, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi = &mi->bmi[10];
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = x0 + 12 + (mv->col >> 3);
|
|
|
|
y1 = y0 + 12 + (mv->row >> 3);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(x0 + 12, &x1, y0 + 12, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(x0 + 12, x1, y0 + 12, y1, y_buffer, y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-10-22 20:25:48 +02:00
|
|
|
case PARTITIONING_4X4:
|
2012-07-14 00:21:29 +02:00
|
|
|
default : {
|
|
|
|
union b_mode_info *bmi = mi->bmi;
|
|
|
|
int bx0, by0;
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (by0 = y0; by0 < (y0 + 16); by0 += 4) {
|
|
|
|
for (bx0 = x0; bx0 < (x0 + 16); bx0 += 4) {
|
|
|
|
MV *mv = &bmi->mv.as_mv;
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
x1 = bx0 + 2 + (mv->col >> 3);
|
|
|
|
y1 = by0 + 2 + (mv->row >> 3);
|
2010-10-30 02:09:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
constrain_line(bx0 + 2, &x1, by0 + 2, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(bx0 + 2, x1, by0 + 2, y1, y_buffer, y_stride);
|
2010-11-02 21:29:13 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
bmi++;
|
2010-10-30 02:09:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-10-23 00:41:06 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
} else if (mi->mbmi.mode >= NEARESTMV) {
|
|
|
|
MV *mv = &mi->mbmi.mv.as_mv;
|
|
|
|
const int lx0 = x0 + 8;
|
|
|
|
const int ly0 = y0 + 8;
|
|
|
|
|
|
|
|
x1 = lx0 + (mv->col >> 3);
|
|
|
|
y1 = ly0 + (mv->row >> 3);
|
|
|
|
|
|
|
|
if (x1 != lx0 && y1 != ly0) {
|
|
|
|
constrain_line(lx0, &x1, ly0 - 1, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(lx0, x1, ly0 - 1, y1, y_buffer, y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
constrain_line(lx0, &x1, ly0 + 1, &y1, width, height);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(lx0, x1, ly0 + 1, y1, y_buffer, y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_blit_line(lx0, x1, ly0, y1, y_buffer, y_stride);
|
2010-10-23 00:41:06 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Color in block modes */
|
2012-10-31 22:40:53 +01:00
|
|
|
if ((flags & VP9D_DEBUG_CLR_BLK_MODES)
|
2012-07-14 00:21:29 +02:00
|
|
|
&& (ppflags->display_mb_modes_flag || ppflags->display_b_modes_flag)) {
|
|
|
|
int y, x;
|
|
|
|
YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
|
|
|
|
int width = post->y_width;
|
|
|
|
int height = post->y_height;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *y_ptr = oci->post_proc_buffer.y_buffer;
|
|
|
|
uint8_t *u_ptr = oci->post_proc_buffer.u_buffer;
|
|
|
|
uint8_t *v_ptr = oci->post_proc_buffer.v_buffer;
|
2012-07-14 00:21:29 +02:00
|
|
|
int y_stride = oci->post_proc_buffer.y_stride;
|
|
|
|
MODE_INFO *mi = oci->mi;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y += 16) {
|
|
|
|
for (x = 0; x < width; x += 16) {
|
|
|
|
int Y = 0, U = 0, V = 0;
|
|
|
|
|
2013-04-11 21:16:35 +02:00
|
|
|
if (mi->mbmi.mode == I4X4_PRED &&
|
|
|
|
((ppflags->display_mb_modes_flag & I4X4_PRED) ||
|
2012-11-01 00:09:17 +01:00
|
|
|
ppflags->display_b_modes_flag)) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int by, bx;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *yl, *ul, *vl;
|
2012-07-14 00:21:29 +02:00
|
|
|
union b_mode_info *bmi = mi->bmi;
|
|
|
|
|
|
|
|
yl = y_ptr + x;
|
|
|
|
ul = u_ptr + (x >> 1);
|
|
|
|
vl = v_ptr + (x >> 1);
|
|
|
|
|
|
|
|
for (by = 0; by < 16; by += 4) {
|
|
|
|
for (bx = 0; bx < 16; bx += 4) {
|
|
|
|
if ((ppflags->display_b_modes_flag & (1 << mi->mbmi.mode))
|
2013-04-11 21:16:35 +02:00
|
|
|
|| (ppflags->display_mb_modes_flag & I4X4_PRED)) {
|
2012-07-14 00:21:29 +02:00
|
|
|
Y = B_PREDICTION_MODE_colors[bmi->as_mode.first][0];
|
|
|
|
U = B_PREDICTION_MODE_colors[bmi->as_mode.first][1];
|
|
|
|
V = B_PREDICTION_MODE_colors[bmi->as_mode.first][2];
|
|
|
|
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_blend_b(yl + bx, ul + (bx >> 1), vl + (bx >> 1), Y, U, V,
|
|
|
|
0xc000, y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
bmi++;
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
yl += y_stride * 4;
|
|
|
|
ul += y_stride * 1;
|
|
|
|
vl += y_stride * 1;
|
|
|
|
}
|
|
|
|
} else if (ppflags->display_mb_modes_flag & (1 << mi->mbmi.mode)) {
|
|
|
|
Y = MB_PREDICTION_MODE_colors[mi->mbmi.mode][0];
|
|
|
|
U = MB_PREDICTION_MODE_colors[mi->mbmi.mode][1];
|
|
|
|
V = MB_PREDICTION_MODE_colors[mi->mbmi.mode][2];
|
|
|
|
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_blend_mb_inner(y_ptr + x, u_ptr + (x >> 1), v_ptr + (x >> 1),
|
|
|
|
Y, U, V, 0xc000, y_stride);
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
y_ptr += y_stride * 16;
|
|
|
|
u_ptr += y_stride * 4;
|
|
|
|
v_ptr += y_stride * 4;
|
|
|
|
|
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Color in frame reference blocks */
|
2012-11-01 00:09:17 +01:00
|
|
|
if ((flags & VP9D_DEBUG_CLR_FRM_REF_BLKS) &&
|
|
|
|
ppflags->display_ref_frame_flag) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int y, x;
|
|
|
|
YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
|
|
|
|
int width = post->y_width;
|
|
|
|
int height = post->y_height;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *y_ptr = oci->post_proc_buffer.y_buffer;
|
|
|
|
uint8_t *u_ptr = oci->post_proc_buffer.u_buffer;
|
|
|
|
uint8_t *v_ptr = oci->post_proc_buffer.v_buffer;
|
2012-07-14 00:21:29 +02:00
|
|
|
int y_stride = oci->post_proc_buffer.y_stride;
|
|
|
|
MODE_INFO *mi = oci->mi;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y += 16) {
|
|
|
|
for (x = 0; x < width; x += 16) {
|
|
|
|
int Y = 0, U = 0, V = 0;
|
|
|
|
|
|
|
|
if (ppflags->display_ref_frame_flag & (1 << mi->mbmi.ref_frame)) {
|
|
|
|
Y = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][0];
|
|
|
|
U = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][1];
|
|
|
|
V = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][2];
|
|
|
|
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_blend_mb_outer(y_ptr + x, u_ptr + (x >> 1), v_ptr + (x >> 1),
|
|
|
|
Y, U, V, 0xc000, y_stride);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
y_ptr += y_stride * 16;
|
|
|
|
u_ptr += y_stride * 4;
|
|
|
|
v_ptr += y_stride * 4;
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
mi++;
|
2010-10-26 21:58:51 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-11-05 00:03:36 +01:00
|
|
|
#endif
|
2010-10-26 21:58:51 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
*dest = oci->post_proc_buffer;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* handle problem with extending borders */
|
2013-03-21 00:41:30 +01:00
|
|
|
dest->y_width = oci->width;
|
|
|
|
dest->y_height = oci->height;
|
2012-07-14 00:21:29 +02:00
|
|
|
dest->uv_height = dest->y_height / 2;
|
2012-11-01 00:09:17 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|