2002-10-11 23:01:16 +00:00
|
|
|
/*
|
|
|
|
* Simple IDCT (Alpha optimized)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
2007-07-05 10:37:29 +00:00
|
|
|
* based upon some outcommented C code from mpeg2dec (idct_mmx.c
|
|
|
|
* written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
|
|
|
|
*
|
2007-07-05 20:08:51 +00:00
|
|
|
* Alpha optimizations by Måns Rullgård <mans@mansr.com>
|
2007-07-05 10:37:29 +00:00
|
|
|
* and Falk Hueffner <falk@debian.org>
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2006-10-07 15:30:46 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2002-10-11 23:01:16 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-10-11 23:01:16 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2002-10-11 23:01:16 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-10-11 23:01:16 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-09 11:56:36 +00:00
|
|
|
#include "libavcodec/dsputil.h"
|
2010-03-08 02:36:03 +00:00
|
|
|
#include "dsputil_alpha.h"
|
2002-10-11 23:01:16 +00:00
|
|
|
#include "asm.h"
|
|
|
|
|
|
|
|
// cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
|
|
|
|
// W4 is actually exactly 16384, but using 16383 works around
|
|
|
|
// accumulating rounding errors for some encoders
|
2011-04-27 13:36:21 +00:00
|
|
|
#define W1 22725
|
|
|
|
#define W2 21407
|
|
|
|
#define W3 19266
|
|
|
|
#define W4 16383
|
|
|
|
#define W5 12873
|
|
|
|
#define W6 8867
|
|
|
|
#define W7 4520
|
2002-10-11 23:01:16 +00:00
|
|
|
#define ROW_SHIFT 11
|
|
|
|
#define COL_SHIFT 20
|
|
|
|
|
|
|
|
/* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
|
|
|
|
static inline int idct_row(DCTELEM *row)
|
|
|
|
{
|
2011-04-29 18:15:00 +00:00
|
|
|
int a0, a1, a2, a3, b0, b1, b2, b3, t;
|
2003-02-22 13:44:16 +00:00
|
|
|
uint64_t l, r, t2;
|
2002-10-11 23:01:16 +00:00
|
|
|
l = ldq(row);
|
|
|
|
r = ldq(row + 4);
|
|
|
|
|
|
|
|
if (l == 0 && r == 0)
|
|
|
|
return 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2002-10-11 23:01:16 +00:00
|
|
|
a0 = W4 * sextw(l) + (1 << (ROW_SHIFT - 1));
|
|
|
|
|
|
|
|
if (((l & ~0xffffUL) | r) == 0) {
|
|
|
|
a0 >>= ROW_SHIFT;
|
2003-02-22 13:44:16 +00:00
|
|
|
t2 = (uint16_t) a0;
|
|
|
|
t2 |= t2 << 16;
|
|
|
|
t2 |= t2 << 32;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2003-02-22 13:44:16 +00:00
|
|
|
stq(t2, row);
|
|
|
|
stq(t2, row + 4);
|
2002-10-11 23:01:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
a1 = a0;
|
|
|
|
a2 = a0;
|
|
|
|
a3 = a0;
|
|
|
|
|
|
|
|
t = extwl(l, 4); /* row[2] */
|
|
|
|
if (t != 0) {
|
|
|
|
t = sextw(t);
|
|
|
|
a0 += W2 * t;
|
|
|
|
a1 += W6 * t;
|
|
|
|
a2 -= W6 * t;
|
|
|
|
a3 -= W2 * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = extwl(r, 0); /* row[4] */
|
|
|
|
if (t != 0) {
|
|
|
|
t = sextw(t);
|
|
|
|
a0 += W4 * t;
|
|
|
|
a1 -= W4 * t;
|
|
|
|
a2 -= W4 * t;
|
|
|
|
a3 += W4 * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = extwl(r, 4); /* row[6] */
|
|
|
|
if (t != 0) {
|
|
|
|
t = sextw(t);
|
|
|
|
a0 += W6 * t;
|
|
|
|
a1 -= W2 * t;
|
|
|
|
a2 += W2 * t;
|
|
|
|
a3 -= W6 * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = extwl(l, 2); /* row[1] */
|
|
|
|
if (t != 0) {
|
|
|
|
t = sextw(t);
|
|
|
|
b0 = W1 * t;
|
|
|
|
b1 = W3 * t;
|
|
|
|
b2 = W5 * t;
|
|
|
|
b3 = W7 * t;
|
|
|
|
} else {
|
|
|
|
b0 = 0;
|
|
|
|
b1 = 0;
|
|
|
|
b2 = 0;
|
|
|
|
b3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = extwl(l, 6); /* row[3] */
|
|
|
|
if (t) {
|
|
|
|
t = sextw(t);
|
|
|
|
b0 += W3 * t;
|
|
|
|
b1 -= W7 * t;
|
|
|
|
b2 -= W1 * t;
|
|
|
|
b3 -= W5 * t;
|
|
|
|
}
|
|
|
|
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2002-10-11 23:01:16 +00:00
|
|
|
t = extwl(r, 2); /* row[5] */
|
|
|
|
if (t) {
|
|
|
|
t = sextw(t);
|
|
|
|
b0 += W5 * t;
|
|
|
|
b1 -= W1 * t;
|
|
|
|
b2 += W7 * t;
|
|
|
|
b3 += W3 * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = extwl(r, 6); /* row[7] */
|
|
|
|
if (t) {
|
|
|
|
t = sextw(t);
|
|
|
|
b0 += W7 * t;
|
|
|
|
b1 -= W5 * t;
|
|
|
|
b2 += W3 * t;
|
|
|
|
b3 -= W1 * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
row[0] = (a0 + b0) >> ROW_SHIFT;
|
|
|
|
row[1] = (a1 + b1) >> ROW_SHIFT;
|
|
|
|
row[2] = (a2 + b2) >> ROW_SHIFT;
|
|
|
|
row[3] = (a3 + b3) >> ROW_SHIFT;
|
|
|
|
row[4] = (a3 - b3) >> ROW_SHIFT;
|
|
|
|
row[5] = (a2 - b2) >> ROW_SHIFT;
|
|
|
|
row[6] = (a1 - b1) >> ROW_SHIFT;
|
|
|
|
row[7] = (a0 - b0) >> ROW_SHIFT;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void idct_col(DCTELEM *col)
|
|
|
|
{
|
2011-04-29 18:15:00 +00:00
|
|
|
int a0, a1, a2, a3, b0, b1, b2, b3;
|
2002-10-11 23:01:16 +00:00
|
|
|
|
|
|
|
col[0] += (1 << (COL_SHIFT - 1)) / W4;
|
|
|
|
|
|
|
|
a0 = W4 * col[8 * 0];
|
|
|
|
a1 = W4 * col[8 * 0];
|
|
|
|
a2 = W4 * col[8 * 0];
|
|
|
|
a3 = W4 * col[8 * 0];
|
|
|
|
|
|
|
|
if (col[8 * 2]) {
|
|
|
|
a0 += W2 * col[8 * 2];
|
|
|
|
a1 += W6 * col[8 * 2];
|
|
|
|
a2 -= W6 * col[8 * 2];
|
|
|
|
a3 -= W2 * col[8 * 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 4]) {
|
|
|
|
a0 += W4 * col[8 * 4];
|
|
|
|
a1 -= W4 * col[8 * 4];
|
|
|
|
a2 -= W4 * col[8 * 4];
|
|
|
|
a3 += W4 * col[8 * 4];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 6]) {
|
|
|
|
a0 += W6 * col[8 * 6];
|
|
|
|
a1 -= W2 * col[8 * 6];
|
|
|
|
a2 += W2 * col[8 * 6];
|
|
|
|
a3 -= W6 * col[8 * 6];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 1]) {
|
|
|
|
b0 = W1 * col[8 * 1];
|
|
|
|
b1 = W3 * col[8 * 1];
|
|
|
|
b2 = W5 * col[8 * 1];
|
|
|
|
b3 = W7 * col[8 * 1];
|
|
|
|
} else {
|
|
|
|
b0 = 0;
|
|
|
|
b1 = 0;
|
|
|
|
b2 = 0;
|
|
|
|
b3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 3]) {
|
|
|
|
b0 += W3 * col[8 * 3];
|
|
|
|
b1 -= W7 * col[8 * 3];
|
|
|
|
b2 -= W1 * col[8 * 3];
|
|
|
|
b3 -= W5 * col[8 * 3];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 5]) {
|
|
|
|
b0 += W5 * col[8 * 5];
|
|
|
|
b1 -= W1 * col[8 * 5];
|
|
|
|
b2 += W7 * col[8 * 5];
|
|
|
|
b3 += W3 * col[8 * 5];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col[8 * 7]) {
|
|
|
|
b0 += W7 * col[8 * 7];
|
|
|
|
b1 -= W5 * col[8 * 7];
|
|
|
|
b2 += W3 * col[8 * 7];
|
|
|
|
b3 -= W1 * col[8 * 7];
|
|
|
|
}
|
|
|
|
|
|
|
|
col[8 * 0] = (a0 + b0) >> COL_SHIFT;
|
|
|
|
col[8 * 7] = (a0 - b0) >> COL_SHIFT;
|
|
|
|
col[8 * 1] = (a1 + b1) >> COL_SHIFT;
|
|
|
|
col[8 * 6] = (a1 - b1) >> COL_SHIFT;
|
|
|
|
col[8 * 2] = (a2 + b2) >> COL_SHIFT;
|
|
|
|
col[8 * 5] = (a2 - b2) >> COL_SHIFT;
|
|
|
|
col[8 * 3] = (a3 + b3) >> COL_SHIFT;
|
|
|
|
col[8 * 4] = (a3 - b3) >> COL_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all rows but the first one are zero after row transformation,
|
|
|
|
all rows will be identical after column transformation. */
|
|
|
|
static inline void idct_col2(DCTELEM *col)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint64_t l, r;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; ++i) {
|
2011-04-29 18:15:00 +00:00
|
|
|
int a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4;
|
2002-10-11 23:01:16 +00:00
|
|
|
|
|
|
|
a0 *= W4;
|
2005-06-19 21:46:14 +00:00
|
|
|
col[i] = a0 >> COL_SHIFT;
|
2002-10-11 23:01:16 +00:00
|
|
|
}
|
|
|
|
|
2005-06-19 21:46:14 +00:00
|
|
|
l = ldq(col + 0 * 4); r = ldq(col + 1 * 4);
|
|
|
|
stq(l, col + 2 * 4); stq(r, col + 3 * 4);
|
|
|
|
stq(l, col + 4 * 4); stq(r, col + 5 * 4);
|
|
|
|
stq(l, col + 6 * 4); stq(r, col + 7 * 4);
|
|
|
|
stq(l, col + 8 * 4); stq(r, col + 9 * 4);
|
|
|
|
stq(l, col + 10 * 4); stq(r, col + 11 * 4);
|
|
|
|
stq(l, col + 12 * 4); stq(r, col + 13 * 4);
|
|
|
|
stq(l, col + 14 * 4); stq(r, col + 15 * 4);
|
2002-10-11 23:01:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 05:52:17 +00:00
|
|
|
void ff_simple_idct_axp(DCTELEM *block)
|
2002-10-11 23:01:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int rowsZero = 1; /* all rows except row 0 zero */
|
|
|
|
int rowsConstant = 1; /* all rows consist of a constant value */
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
int sparseness = idct_row(block + 8 * i);
|
|
|
|
|
|
|
|
if (i > 0 && sparseness > 0)
|
|
|
|
rowsZero = 0;
|
|
|
|
if (sparseness == 2)
|
|
|
|
rowsConstant = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rowsZero) {
|
|
|
|
idct_col2(block);
|
|
|
|
} else if (rowsConstant) {
|
|
|
|
idct_col(block);
|
|
|
|
for (i = 0; i < 8; i += 2) {
|
2005-06-19 21:46:14 +00:00
|
|
|
uint64_t v = (uint16_t) block[0];
|
|
|
|
uint64_t w = (uint16_t) block[8];
|
2002-10-11 23:01:16 +00:00
|
|
|
|
|
|
|
v |= v << 16;
|
|
|
|
w |= w << 16;
|
|
|
|
v |= v << 32;
|
|
|
|
w |= w << 32;
|
2005-06-19 21:46:14 +00:00
|
|
|
stq(v, block + 0 * 4);
|
|
|
|
stq(v, block + 1 * 4);
|
|
|
|
stq(w, block + 2 * 4);
|
|
|
|
stq(w, block + 3 * 4);
|
2005-12-22 01:10:11 +00:00
|
|
|
block += 4 * 4;
|
2002-10-11 23:01:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
idct_col(block + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 05:52:17 +00:00
|
|
|
void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
|
2002-10-11 23:01:16 +00:00
|
|
|
{
|
2009-01-18 05:52:17 +00:00
|
|
|
ff_simple_idct_axp(block);
|
2002-11-27 01:20:42 +00:00
|
|
|
put_pixels_clamped_axp_p(block, dest, line_size);
|
2002-10-11 23:01:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 05:52:17 +00:00
|
|
|
void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
|
2002-10-11 23:01:16 +00:00
|
|
|
{
|
2009-01-18 05:52:17 +00:00
|
|
|
ff_simple_idct_axp(block);
|
2002-11-27 01:20:42 +00:00
|
|
|
add_pixels_clamped_axp_p(block, dest, line_size);
|
2002-10-11 23:01:16 +00:00
|
|
|
}
|