update
[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:
07f8991b 50remove global/static vars
3057fa66 51reduce the time wasted on the mem transfer
3057fa66
A
52unroll stuff if instructions depend too much on the prior one
53we use 8x8 blocks for the horizontal filters, opendivx seems to use 8x4?
54move YScale thing to the end instead of fixing QP
13e00528 55write a faster and higher quality deblocking filter :)
d5a1a995
MN
56make the mainloop more flexible (variable number of blocks at once
57 (the if/else stuff per block is slowing things down)
9f45d04d 58compare the quality & speed of all filters
9f45d04d 59split this huge file
8405b3fd 60optimize c versions
117e45b0 61try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
cc9b0679 62put fastmemcpy back
3057fa66 63...
13e00528
A
64*/
65
a6be8111 66//Changelog: use the CVS log
3057fa66 67
6c426cff 68#include "../config.h"
3057fa66
A
69#include <inttypes.h>
70#include <stdio.h>
d5a1a995 71#include <stdlib.h>
911879d1 72#include <string.h>
cbf5fa71 73#include <errno.h>
dda87e9f
PL
74#ifdef HAVE_MALLOC_H
75#include <malloc.h>
76#endif
3057fa66 77//#undef HAVE_MMX2
13e00528 78//#define HAVE_3DNOW
3057fa66 79//#undef HAVE_MMX
cc9b0679 80//#undef ARCH_X86
7f16f6e6 81//#define DEBUG_BRIGHTNESS
9c9e467d 82#include "../libvo/fastmemcpy.h"
13e00528 83#include "postprocess.h"
cc9b0679 84#include "../cpudetect.h"
9b464428 85#include "../mangle.h"
3057fa66 86
e939e1c3
A
87#define MIN(a,b) ((a) > (b) ? (b) : (a))
88#define MAX(a,b) ((a) < (b) ? (b) : (a))
89#define ABS(a) ((a) > 0 ? (a) : (-(a)))
90#define SIGN(a) ((a) > 0 ? 1 : -1)
91
911879d1
MN
92#define GET_MODE_BUFFER_SIZE 500
93#define OPTIONS_ARRAY_SIZE 10
9c9e467d
MN
94#define BLOCK_SIZE 8
95#define TEMP_STRIDE 8
96//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
911879d1 97
cc9b0679 98#ifdef ARCH_X86
b28daef8
MN
99static uint64_t __attribute__((aligned(8))) w05= 0x0005000500050005LL;
100static uint64_t __attribute__((aligned(8))) w20= 0x0020002000200020LL;
b28daef8
MN
101static uint64_t __attribute__((aligned(8))) b00= 0x0000000000000000LL;
102static uint64_t __attribute__((aligned(8))) b01= 0x0101010101010101LL;
103static uint64_t __attribute__((aligned(8))) b02= 0x0202020202020202LL;
b28daef8 104static uint64_t __attribute__((aligned(8))) b08= 0x0808080808080808LL;
b28daef8 105static uint64_t __attribute__((aligned(8))) b80= 0x8080808080808080LL;
b28daef8 106#endif
3057fa66 107
45b4f285 108extern int divx_quality;
9c9e467d 109static int firstTime2 = 0;
45b4f285
MN
110
111extern int verbose;
112
cd38e322 113int deringThreshold= 20;
3057fa66
A
114
115//amount of "black" u r willing to loose to get a brightness corrected picture
116double maxClippedThreshold= 0.01;
117
9c9e467d
MN
118struct PPFilter{
119 char *shortName;
120 char *longName;
121 int chromDefault; // is chrominance filtering on by default if this filter is manually activated
122 int minLumQuality; // minimum quality to turn luminance filtering on
123 int minChromQuality; // minimum quality to turn chrominance filtering on
124 int mask; // Bitmask to turn this filter on
125};
126
127typedef struct PPContext{
128 uint8_t *tempBlocks; //used for the horizontal code
129
130