Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
[libav.git] / postproc / postprocess.c
CommitLineData
3057fa66 1/*
8aaac435 2 Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
3057fa66
A
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19/*
3b58b885 20 C MMX MMX2 3DNow
3057fa66
A
21isVertDC Ec Ec
22isVertMinMaxOk Ec Ec
3b58b885 23doVertLowPass E e e
7f16f6e6 24doVertDefFilter Ec Ec e e
3057fa66 25isHorizDC Ec Ec
4e4dcbc5
MN
26isHorizMinMaxOk a E
27doHorizLowPass E e e
7f16f6e6 28doHorizDefFilter Ec Ec e e
2e212618 29deRing E e e*
3b58b885 30Vertical RKAlgo1 E a a
e5c30e06 31Horizontal RKAlgo1 a a
117e45b0
MN
32Vertical X1# a E E
33Horizontal X1# a E E
acced553
MN
34LinIpolDeinterlace e E E*
35CubicIpolDeinterlace a e e*
36LinBlendDeinterlace e E E*
117e45b0 37MedianDeinterlace# Ec Ec
be44a4d7 38TempDeNoiser# E e e
d5a1a995 39
117e45b0
MN
40* i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work
41# more or less selfinvented filters so the exactness isnt too meaningfull
3057fa66 42E = Exact implementation
acced553 43e = allmost exact implementation (slightly different rounding,...)
3057fa66
A
44a = alternative / approximate impl
45c = checked against the other implementations (-vo md5)
46*/
47
48/*
49TODO:
3057fa66 50reduce the time wasted on the mem transfer
3057fa66 51unroll stuff if instructions depend too much on the prior one
3057fa66 52move YScale thing to the end instead of fixing QP
13e00528 53write a faster and higher quality deblocking filter :)
d5a1a995
MN
54make the mainloop more flexible (variable number of blocks at once
55 (the if/else stuff per block is slowing things down)
9f45d04d 56compare the quality & speed of all filters
9f45d04d 57split this huge file
8405b3fd 58optimize c versions
117e45b0 59try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
3057fa66 60...
13e00528
A
61*/
62
a6be8111 63//Changelog: use the CVS log
3057fa66 64
6c426cff 65#include "../config.h"
3057fa66
A
66#include <inttypes.h>
67#include <stdio.h>
d5a1a995 68#include <stdlib.h>
911879d1 69#include <string.h>
dda87e9f
PL
70#ifdef HAVE_MALLOC_H
71#include <malloc.h>
72#endif
3057fa66 73//#undef HAVE_MMX2
13e00528 74//#define HAVE_3DNOW
3057fa66 75//#undef HAVE_MMX
cc9b0679 76//#undef ARCH_X86
7f16f6e6 77//#define DEBUG_BRIGHTNESS
9c9e467d 78#include "../libvo/fastmemcpy.h"
13e00528 79#include "postprocess.h"
9b464428 80#include "../mangle.h"
3057fa66 81
e939e1c3
A
82#define MIN(a,b) ((a) > (b) ? (b) : (a))
83#define MAX(a,b) ((a) < (b) ? (b) : (a))
84#define ABS(a) ((a) > 0 ? (a) : (-(a)))
85#define SIGN(a) ((a) > 0 ? 1 : -1)
86
911879d1
MN
87#define GET_MODE_BUFFER_SIZE 500
88#define OPTIONS_ARRAY_SIZE 10
9c9e467d
MN
89#define BLOCK_SIZE 8
90#define TEMP_STRIDE 8
91//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
911879d1 92
cc9b0679 93#ifdef ARCH_X86
b28daef8
MN
94static uint64_t __attribute__((aligned(8))) w05= 0x0005000500050005LL;
95static uint64_t __attribute__((aligned(8))) w20= 0x0020002000200020LL;
b28daef8
MN
96static uint64_t __attribute__((aligned(8))) b00= 0x0000000000000000LL;
97static uint64_t __attribute__((aligned(8))) b01= 0x0101010101010101LL;
98static uint64_t __attribute__((aligned(8))) b02= 0x0202020202020202LL;
b28daef8 99static uint64_t __attribute__((aligned(8))) b08= 0x0808080808080808LL;
b28daef8 100static uint64_t __attribute__((aligned(8))) b80= 0x8080808080808080LL;
b28daef8 101#endif
3057fa66 102
df8d4d0e 103static int verbose= 0;
45b4f285 104
df8d4d0e 105static const int deringThreshold= 20;
3057fa66 106
9c9e467d
MN
107struct PPFilter{
108 char *shortName;
109 char *longName;
110 int chromDefault; // is chrominance filtering on by default if this filter is manually activated
111 int minLumQuality; // minimum quality to turn luminance filtering on
112 int minChromQuality; // minimum quality to turn chrominance filtering on
113 int mask; // Bitmask to turn this filter on
114};
115
116typedef struct PPContext{
117 uint8_t *tempBlocks; //used for the horizontal code
118
119