Browse code

auto brightness/ contrast bugfix getPPModeByNameAndQuality

Originally committed as revision 2390 to svn://svn.mplayerhq.hu/mplayer/trunk/postproc

Michael Niedermayer authored on 2001/10/23 08:36:35
Showing 3 changed files
... ...
@@ -71,6 +71,7 @@ Notes:
71 71
 #include <inttypes.h>
72 72
 #include <stdio.h>
73 73
 #include <stdlib.h>
74
+#include <string.h>
74 75
 #include "../config.h"
75 76
 //#undef HAVE_MMX2
76 77
 //#define HAVE_3DNOW
... ...
@@ -88,6 +89,10 @@ Notes:
88 88
 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
89 89
 #endif
90 90
 
91
+#define GET_MODE_BUFFER_SIZE 500
92
+#define OPTIONS_ARRAY_SIZE 10
93
+
94
+
91 95
 static uint64_t packedYOffset=	0x0000000000000000LL;
92 96
 static uint64_t packedYScale=	0x0100010001000100LL;
93 97
 static uint64_t w05=		0x0005000500050005LL;
... ...
@@ -130,10 +135,35 @@ int vFlatnessThreshold= 56 - 16;
130 130
 //amount of "black" u r willing to loose to get a brightness corrected picture
131 131
 double maxClippedThreshold= 0.01;
132 132
 
133
-int maxAllowedY=255;
133
+int maxAllowedY=234;
134 134

                
135 135
 int minAllowedY=16;
136 136
 
137
+static struct PPFilter filters[]=
138
+{
139
+	{"hb", "hdeblock", 		1, 1, 3, H_DEBLOCK},
140
+	{"vb", "vdeblock", 		1, 2, 4, V_DEBLOCK},
141
+	{"vr", "rkvdeblock", 		1, 2, 4, H_RK1_FILTER},
142
+	{"h1", "x1hdeblock", 		1, 1, 3, H_X1_FILTER},
143
+	{"v1", "x1vdeblock", 		1, 2, 4, V_X1_FILTER},
144
+	{"dr", "dering", 		1, 5, 6, DERING},
145
+	{"al", "autolevels", 		0, 1, 2, LEVEL_FIX},
146
+	{"lb", "linblenddeint", 	0, 1, 6, LINEAR_BLEND_DEINT_FILTER},
147
+	{"li", "linipoldeint", 		0, 1, 6, LINEAR_IPOL_DEINT_FILTER},
148
+	{"ci", "cubicipoldeint",	0, 1, 6, CUBIC_IPOL_DEINT_FILTER},
149
+	{"md", "mediandeint", 		0, 1, 6, MEDIAN_DEINT_FILTER},
150
+	{NULL, NULL,0,0,0,0} //End Marker
151
+};
152
+
153
+static char *replaceTable[]=
154
+{
155
+	"default", 	"hdeblock:a,vdeblock:a,dering:a,autolevels",
156
+	"de", 		"hdeblock:a,vdeblock:a,dering:a,autolevels",
157
+	"fast", 	"x1hdeblock:a,x1vdeblock:a,dering:a,autolevels",
158
+	"fa", 		"x1hdeblock:a,x1vdeblock:a,dering:a,autolevels",
159
+	NULL //End Marker
160
+};
161
+
137 162
 #ifdef TIMING
138 163
 static inline long long rdtsc()
139 164
 {
... ...
@@ -2163,6 +2193,165 @@ int use_old_pp=0;
2163 2163
 static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
2164 2164
 	QP_STORE_T QPs[], int QPStride, int isColor, int mode);
2165 2165
 
2166
+/* -pp Command line Help
2167
+NOTE/FIXME: put this at an appropriate place (--help, html docs, man mplayer)?
2168
+
2169
+-pp <filterName>[:<option>[:<option>...]][,[-]<filterName>[:<option>...]]...
2170
+
2171
+long form example:
2172
+-pp vdeblock:autoq,hdeblock:autoq,linblenddeint		-pp default,-vdeblock
2173
+short form example:
2174
+-pp vb:a,hb:a,lb					-pp de,-vb
2175
+
2176
+Filters			Options
2177
+short	long name	short	long option	Description
2178
+*	*		a	autoq		cpu power dependant enabler
2179
+			c	chrom		chrominance filtring enabled
2180
+			y	nochrom		chrominance filtring disabled
2181
+hb	hdeblock				horizontal deblocking filter
2182
+vb	vdeblock				vertical deblocking filter
2183
+vr	rkvdeblock
2184
+h1	x1hdeblock				Experimental horizontal deblock filter 1
2185
+v1	x1vdeblock				Experimental vertical deblock filter 1
2186
+dr	dering					not implemented yet
2187
+al	autolevels				automatic brightness / contrast fixer
2188
+			f	fullyrange	stretch luminance range to (0..255)
2189
+lb	linblenddeint				linear blend deinterlacer
2190
+li	linipoldeint				linear interpolating deinterlacer
2191
+ci	cubicipoldeint				cubic interpolating deinterlacer
2192
+md	mediandeint				median deinterlacer
2193
+de	default					hdeblock:a,vdeblock:a,dering:a,autolevels
2194
+fa	fast					x1hdeblock:a,x1vdeblock:a,dering:a,autolevels
2195
+*/
2196
+
2197
+/**
2198
+ * returns a PPMode struct which will have a non 0 error variable if an error occured
2199
+ * name is the string after "-pp" on the command line
2200
+ * quality is a number from 0 to GET_PP_QUALITY_MAX
2201
+ */
2202
+struct PPMode getPPModeByNameAndQuality(char *name, int quality)
2203
+{
2204
+	char temp[GET_MODE_BUFFER_SIZE];
2205
+	char *p= temp;
2206
+	char *filterDelimiters= ",";
2207
+	char *optionDelimiters= ":";
2208
+	struct PPMode ppMode= {0,0,0,0,0,0};
2209
+	char *filterToken;
2210
+
2211
+	strncpy(temp, name, GET_MODE_BUFFER_SIZE);
2212
+
2213
+	for(;;){
2214
+		char *p2;
2215
+		char *filterName;
2216
+		int q= GET_PP_QUALITY_MAX;
2217
+		int chrom=-1;
2218
+		char *option;
2219
+		char *options[OPTIONS_ARRAY_SIZE];
2220
+		int i;
2221
+		int filterNameOk=0;
2222
+		int numOfUnknownOptions=0;
2223
+		int enable=1; //does the user want us to enabled or disabled the filter
2224
+
2225
+		filterToken= strtok(p, filterDelimiters);
2226
+		if(filterToken == NULL) break;
2227
+		p+= strlen(filterToken) + 1;
2228
+		filterName= strtok(filterToken, optionDelimiters);
2229
+		printf("%s::%s\n", filterToken, filterName);
2230
+
2231
+		if(*filterName == '-')
2232
+		{
2233
+			enable=0;
2234
+			filterName++;
2235
+		}
2236
+		for(;;){ //for all options
2237
+			option= strtok(NULL, optionDelimiters);
2238
+			if(option == NULL) break;
2239
+
2240
+			printf("%s\n", option);
2241
+			if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
2242
+			else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
2243
+			else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
2244
+			else
2245
+			{
2246
+				options[numOfUnknownOptions] = option;
2247
+				numOfUnknownOptions++;
2248
+				options[numOfUnknownOptions] = NULL;
2249
+			}
2250
+			if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
2251
+		}
2252
+
2253
+		/* replace stuff from the replace Table */
2254
+		for(i=0; replaceTable[2*i]!=NULL; i++)
2255
+		{
2256
+			if(!strcmp(replaceTable[2*i], filterName))
2257
+			{
2258
+				int newlen= strlen(replaceTable[2*i + 1]);
2259
+				int plen;
2260
+				int spaceLeft;
2261
+
2262
+				if(p==NULL) p= temp, *p=0; 	//last filter
2263
+				else p--, *p=',';		//not last filter
2264
+
2265
+				plen= strlen(p);
2266
+				spaceLeft= (int)p - (int)temp + plen;
2267
+				if(spaceLeft + newlen  >= GET_MODE_BUFFER_SIZE)
2268
+				{
2269
+					ppMode.error++;
2270
+					break;
2271
+				}
2272
+				memmove(p + newlen, p, plen+1);
2273
+				memcpy(p, replaceTable[2*i + 1], newlen);
2274
+				filterNameOk=1;
2275
+			}
2276
+		}
2277
+
2278
+		for(i=0; filters[i].shortName!=NULL; i++)
2279
+		{
2280
+			if(   !strcmp(filters[i].longName, filterName)
2281
+			   || !strcmp(filters[i].shortName, filterName))
2282
+			{
2283
+				ppMode.lumMode &= ~filters[i].mask;
2284
+				ppMode.chromMode &= ~filters[i].mask;
2285
+
2286
+				filterNameOk=1;
2287
+				if(!enable) break; // user wants to disable it
2288
+
2289
+				if(q >= filters[i].minLumQuality)
2290
+					ppMode.lumMode|= filters[i].mask;
2291
+				if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
2292
+					if(q >= filters[i].minChromQuality)
2293
+						ppMode.chromMode|= filters[i].mask;
2294
+
2295
+				if(filters[i].mask == LEVEL_FIX)
2296
+				{
2297
+					int o;
2298
+					ppMode.minAllowedY= 16;
2299
+					ppMode.maxAllowedY= 234;
2300
+					for(o=0; options[o]!=NULL; o++)
2301
+						if(  !strcmp(options[o],"fullyrange")
2302
+						   ||!strcmp(options[o],"f"))
2303
+						{
2304
+							ppMode.minAllowedY= 0;
2305
+							ppMode.maxAllowedY= 255;
2306
+							numOfUnknownOptions--;
2307
+						}
2308
+				}
2309
+			}
2310
+		}
2311
+		if(!filterNameOk) ppMode.error++;
2312
+		ppMode.error += numOfUnknownOptions;
2313
+	}
2314
+
2315
+	if(ppMode.lumMode & H_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_Y_H;
2316
+	if(ppMode.lumMode & V_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_Y_V;
2317
+	if(ppMode.chromMode & H_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_C_H;
2318
+	if(ppMode.chromMode & V_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_C_V;
2319
+	if(ppMode.lumMode & DERING) ppMode.oldMode |= PP_DERING_Y;
2320
+	if(ppMode.chromMode & DERING) ppMode.oldMode |= PP_DERING_C;
2321
+
2322
+	return ppMode;
2323
+}
2324
+
2166 2325
 /**
2167 2326
  * ...
2168 2327
  */
... ...
@@ -2172,6 +2361,18 @@ void  postprocess(unsigned char * src[], int src_stride,
2172 2172
                  QP_STORE_T *QP_store,  int QP_stride,
2173 2173
 					  int mode)
2174 2174
 {
2175
+/*
2176
+	static int qual=0;
2177
+
2178
+	struct PPMode ppMode= getPPModeByNameAndQuality("fast,default,-hdeblock,-vdeblock", qual);
2179
+	qual++;
2180
+	qual%=7;
2181
+	printf("\n%d %d %d %d\n", ppMode.lumMode, ppMode.chromMode, ppMode.oldMode, ppMode.error);
2182
+	postprocess2(src, src_stride, dst, dst_stride,
2183
+                 horizontal_size, vertical_size, QP_store, QP_stride, &ppMode);
2184
+
2185
+	return;
2186
+*/
2175 2187
 
2176 2188
 #ifdef HAVE_ODIVX_POSTPROCESS
2177 2189
 // Note: I could make this shit outside of this file, but it would mean one
... ...
@@ -2182,21 +2383,6 @@ void  postprocess(unsigned char * src[], int src_stride,
2182 2182
 	}
2183 2183
 #endif
2184 2184
 
2185
-/*
2186
-	long long T= rdtsc();
2187
-	for(int y=vertical_size-1; y>=0 ; y--)
2188
-		memcpy(dst[0] + y*src_stride, src[0] + y*src_stride,src_stride);
2189
-//	memcpy(dst[0], src[0],src_stride*vertical_size);
2190
-	printf("%4dk\r", (rdtsc()-T)/1000);
2191
-
2192
-	return;
2193
-*/
2194
-/*
2195
-	long long T= rdtsc();
2196
-	while( (rdtsc() - T)/1000 < 4000);
2197
-
2198
-	return;
2199
-*/
2200 2185
 	postProcess(src[0], src_stride, dst[0], dst_stride,
2201 2186
 		horizontal_size, vertical_size, QP_store, QP_stride, 0, mode);
2202 2187
 
... ...
@@ -2211,7 +2397,7 @@ void  postprocess(unsigned char * src[], int src_stride,
2211 2211
 		postProcess(src[1], src_stride, dst[1], dst_stride,
2212 2212
 			horizontal_size, vertical_size, QP_store, QP_stride, 1, mode);
2213 2213
 		postProcess(src[2], src_stride, dst[2], dst_stride,
2214
-			horizontal_size, vertical_size, QP_store, QP_stride, 1, mode);
2214
+			horizontal_size, vertical_size, QP_store, QP_stride, 2, mode);
2215 2215
 	}
2216 2216
 	else
2217 2217
 	{
... ...
@@ -2220,6 +2406,38 @@ void  postprocess(unsigned char * src[], int src_stride,
2220 2220
 	}
2221 2221
 }
2222 2222
 
2223
+void  postprocess2(unsigned char * src[], int src_stride,
2224
+                 unsigned char * dst[], int dst_stride,
2225
+                 int horizontal_size,   int vertical_size,
2226
+                 QP_STORE_T *QP_store,  int QP_stride,
2227
+		 struct PPMode *mode)
2228
+{
2229
+
2230
+#ifdef HAVE_ODIVX_POSTPROCESS
2231
+// Note: I could make this shit outside of this file, but it would mean one
2232
+// more function call...
2233
+	if(use_old_pp){
2234
+	    odivx_postprocess(src,src_stride,dst,dst_stride,horizontal_size,vertical_size,QP_store,QP_stride,
2235
+	    mode->oldMode);
2236
+	    return;
2237
+	}
2238
+#endif
2239
+
2240
+	postProcess(src[0], src_stride, dst[0], dst_stride,
2241
+		horizontal_size, vertical_size, QP_store, QP_stride, 0, mode->lumMode);
2242
+
2243
+	horizontal_size >>= 1;
2244
+	vertical_size   >>= 1;
2245
+	src_stride      >>= 1;
2246
+	dst_stride      >>= 1;
2247
+
2248
+	postProcess(src[1], src_stride, dst[1], dst_stride,
2249
+		horizontal_size, vertical_size, QP_store, QP_stride, 1, mode->chromMode);
2250
+	postProcess(src[2], src_stride, dst[2], dst_stride,
2251
+		horizontal_size, vertical_size, QP_store, QP_stride, 2, mode->chromMode);
2252
+}
2253
+
2254
+
2223 2255
 /**
2224 2256
  * gets the mode flags for a given quality (larger values mean slower but better postprocessing)
2225 2257
  * 0 <= quality <= 6
... ...
@@ -46,7 +46,7 @@
46 46
 #define H_RK1_FILTER	0x1000			// 4096 (not implemented yet)
47 47
 #define H_X1_FILTER	0x2000			// 8192
48 48
 
49
-// select between full y range (255-0) or standart one (
49
+// select between full y range (255-0) or standart one (234-16)
50 50
 #define FULL_Y_RANGE	0x8000			// 32768
51 51
 
52 52
 //Deinterlacing Filters
... ...
@@ -67,11 +67,38 @@
67 67
 
68 68
 #define QP_STORE_T int
69 69
 
70
+struct PPMode{
71
+	int lumMode; //acivates filters for luminance
72
+	int chromMode; //acivates filters for chrominance
73
+	int oldMode; // will be passed to odivx
74
+	int error; // non zero on error
75
+
76
+	int minAllowedY;
77
+	int maxAllowedY;
78
+};
79
+
80
+struct PPFilter{
81
+	char *shortName;
82
+	char *longName;
83
+	int chromDefault;
84
+	int minLumQuality;
85
+	int minChromQuality;
86
+	int mask;
87
+};
88
+
70 89
 void postprocess(unsigned char * src[], int src_stride,
71 90
                  unsigned char * dst[], int dst_stride,
72 91
                  int horizontal_size,   int vertical_size,
73 92
                  QP_STORE_T *QP_store,  int QP_stride, int mode);
74 93
 
94
+void postprocess2(unsigned char * src[], int src_stride,
95
+                 unsigned char * dst[], int dst_stride,
96
+                 int horizontal_size,   int vertical_size,
97
+                 QP_STORE_T *QP_store,  int QP_stride, struct PPMode *mode);
98
+
99
+
75 100
 int getPpModeForQuality(int quality);
76 101
 
102
+struct PPMode getPpModeByNameAndQuality(char *name, int quality);
103
+
77 104
 #endif
... ...
@@ -71,6 +71,7 @@ Notes:
71 71
 #include <inttypes.h>
72 72
 #include <stdio.h>
73 73
 #include <stdlib.h>
74
+#include <string.h>
74 75
 #include "../config.h"
75 76
 //#undef HAVE_MMX2
76 77
 //#define HAVE_3DNOW
... ...
@@ -88,6 +89,10 @@ Notes:
88 88
 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
89 89
 #endif
90 90
 
91
+#define GET_MODE_BUFFER_SIZE 500
92
+#define OPTIONS_ARRAY_SIZE 10
93
+
94
+
91 95
 static uint64_t packedYOffset=	0x0000000000000000LL;
92 96
 static uint64_t packedYScale=	0x0100010001000100LL;
93 97
 static uint64_t w05=		0x0005000500050005LL;
... ...
@@ -130,10 +135,35 @@ int vFlatnessThreshold= 56 - 16;
130 130
 //amount of "black" u r willing to loose to get a brightness corrected picture
131 131
 double maxClippedThreshold= 0.01;
132 132
 
133
-int maxAllowedY=255;
133
+int maxAllowedY=234;
134 134

                
135 135
 int minAllowedY=16;
136 136
 
137
+static struct PPFilter filters[]=
138
+{
139
+	{"hb", "hdeblock", 		1, 1, 3, H_DEBLOCK},
140
+	{"vb", "vdeblock", 		1, 2, 4, V_DEBLOCK},
141
+	{"vr", "rkvdeblock", 		1, 2, 4, H_RK1_FILTER},
142
+	{"h1", "x1hdeblock", 		1, 1, 3, H_X1_FILTER},
143
+	{"v1", "x1vdeblock", 		1, 2, 4, V_X1_FILTER},
144
+	{"dr", "dering", 		1, 5, 6, DERING},
145
+	{"al", "autolevels", 		0, 1, 2, LEVEL_FIX},
146
+	{"lb", "linblenddeint", 	0, 1, 6, LINEAR_BLEND_DEINT_FILTER},
147
+	{"li", "linipoldeint", 		0, 1, 6, LINEAR_IPOL_DEINT_FILTER},
148
+	{"ci", "cubicipoldeint",	0, 1, 6, CUBIC_IPOL_DEINT_FILTER},
149
+	{"md", "mediandeint", 		0, 1, 6, MEDIAN_DEINT_FILTER},
150
+	{NULL, NULL,0,0,0,0} //End Marker
151
+};
152
+
153
+static char *replaceTable[]=
154
+{
155
+	"default", 	"hdeblock:a,vdeblock:a,dering:a,autolevels",
156
+	"de", 		"hdeblock:a,vdeblock:a,dering:a,autolevels",
157
+	"fast", 	"x1hdeblock:a,x1vdeblock:a,dering:a,autolevels",
158
+	"fa", 		"x1hdeblock:a,x1vdeblock:a,dering:a,autolevels",
159
+	NULL //End Marker
160
+};
161
+
137 162
 #ifdef TIMING
138 163
 static inline long long rdtsc()
139 164
 {
... ...
@@ -2163,6 +2193,165 @@ int use_old_pp=0;
2163 2163
 static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
2164 2164
 	QP_STORE_T QPs[], int QPStride, int isColor, int mode);
2165 2165
 
2166
+/* -pp Command line Help
2167
+NOTE/FIXME: put this at an appropriate place (--help, html docs, man mplayer)?
2168
+
2169
+-pp <filterName>[:<option>[:<option>...]][,[-]<filterName>[:<option>...]]...
2170
+
2171
+long form example:
2172
+-pp vdeblock:autoq,hdeblock:autoq,linblenddeint		-pp default,-vdeblock
2173
+short form example:
2174
+-pp vb:a,hb:a,lb					-pp de,-vb
2175
+
2176
+Filters			Options
2177
+short	long name	short	long option	Description
2178
+*	*		a	autoq		cpu power dependant enabler
2179
+			c	chrom		chrominance filtring enabled
2180
+			y	nochrom		chrominance filtring disabled
2181
+hb	hdeblock				horizontal deblocking filter
2182
+vb	vdeblock				vertical deblocking filter
2183
+vr	rkvdeblock
2184
+h1	x1hdeblock				Experimental horizontal deblock filter 1
2185
+v1	x1vdeblock				Experimental vertical deblock filter 1
2186
+dr	dering					not implemented yet
2187
+al	autolevels				automatic brightness / contrast fixer
2188
+			f	fullyrange	stretch luminance range to (0..255)
2189
+lb	linblenddeint				linear blend deinterlacer
2190
+li	linipoldeint				linear interpolating deinterlacer
2191
+ci	cubicipoldeint				cubic interpolating deinterlacer
2192
+md	mediandeint				median deinterlacer
2193
+de	default					hdeblock:a,vdeblock:a,dering:a,autolevels
2194
+fa	fast					x1hdeblock:a,x1vdeblock:a,dering:a,autolevels
2195
+*/
2196
+
2197
+/**
2198
+ * returns a PPMode struct which will have a non 0 error variable if an error occured
2199
+ * name is the string after "-pp" on the command line
2200
+ * quality is a number from 0 to GET_PP_QUALITY_MAX
2201
+ */
2202
+struct PPMode getPPModeByNameAndQuality(char *name, int quality)
2203
+{
2204
+	char temp[GET_MODE_BUFFER_SIZE];
2205
+	char *p= temp;
2206
+	char *filterDelimiters= ",";
2207
+	char *optionDelimiters= ":";
2208
+	struct PPMode ppMode= {0,0,0,0,0,0};
2209
+	char *filterToken;
2210
+
2211
+	strncpy(temp, name, GET_MODE_BUFFER_SIZE);
2212
+
2213
+	for(;;){
2214
+		char *p2;
2215
+		char *filterName;
2216
+		int q= GET_PP_QUALITY_MAX;
2217
+		int chrom=-1;
2218
+		char *option;
2219
+		char *options[OPTIONS_ARRAY_SIZE];
2220
+		int i;
2221
+		int filterNameOk=0;
2222
+		int numOfUnknownOptions=0;
2223
+		int enable=1; //does the user want us to enabled or disabled the filter
2224
+
2225
+		filterToken= strtok(p, filterDelimiters);
2226
+		if(filterToken == NULL) break;
2227
+		p+= strlen(filterToken) + 1;
2228
+		filterName= strtok(filterToken, optionDelimiters);
2229
+		printf("%s::%s\n", filterToken, filterName);
2230
+
2231
+		if(*filterName == '-')
2232
+		{
2233
+			enable=0;
2234
+			filterName++;
2235
+		}
2236
+		for(;;){ //for all options
2237
+			option= strtok(NULL, optionDelimiters);
2238
+			if(option == NULL) break;
2239
+
2240
+			printf("%s\n", option);
2241
+			if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
2242
+			else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
2243
+			else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
2244
+			else
2245
+			{
2246
+				options[numOfUnknownOptions] = option;
2247
+				numOfUnknownOptions++;
2248
+				options[numOfUnknownOptions] = NULL;
2249
+			}
2250
+			if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
2251
+		}
2252
+
2253
+		/* replace stuff from the replace Table */
2254
+		for(i=0; replaceTable[2*i]!=NULL; i++)
2255
+		{
2256
+			if(!strcmp(replaceTable[2*i], filterName))
2257
+			{
2258
+				int newlen= strlen(replaceTable[2*i + 1]);
2259
+				int plen;
2260
+				int spaceLeft;
2261
+
2262
+				if(p==NULL) p= temp, *p=0; 	//last filter
2263
+				else p--, *p=',';		//not last filter
2264
+
2265
+				plen= strlen(p);
2266
+				spaceLeft= (int)p - (int)temp + plen;
2267
+				if(spaceLeft + newlen  >= GET_MODE_BUFFER_SIZE)
2268
+				{
2269
+					ppMode.error++;
2270
+					break;
2271
+				}
2272
+				memmove(p + newlen, p, plen+1);
2273
+				memcpy(p, replaceTable[2*i + 1], newlen);
2274
+				filterNameOk=1;
2275
+			}
2276
+		}
2277
+
2278
+		for(i=0; filters[i].shortName!=NULL; i++)
2279
+		{
2280
+			if(   !strcmp(filters[i].longName, filterName)
2281
+			   || !strcmp(filters[i].shortName, filterName))
2282
+			{
2283
+				ppMode.lumMode &= ~filters[i].mask;
2284
+				ppMode.chromMode &= ~filters[i].mask;
2285
+
2286
+				filterNameOk=1;
2287
+				if(!enable) break; // user wants to disable it
2288
+
2289
+				if(q >= filters[i].minLumQuality)
2290
+					ppMode.lumMode|= filters[i].mask;
2291
+				if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
2292
+					if(q >= filters[i].minChromQuality)
2293
+						ppMode.chromMode|= filters[i].mask;
2294
+
2295
+				if(filters[i].mask == LEVEL_FIX)
2296
+				{
2297
+					int o;
2298
+					ppMode.minAllowedY= 16;
2299
+					ppMode.maxAllowedY= 234;
2300
+					for(o=0; options[o]!=NULL; o++)
2301
+						if(  !strcmp(options[o],"fullyrange")
2302
+						   ||!strcmp(options[o],"f"))
2303
+						{
2304
+							ppMode.minAllowedY= 0;
2305
+							ppMode.maxAllowedY= 255;
2306
+							numOfUnknownOptions--;
2307
+						}
2308
+				}
2309
+			}
2310
+		}
2311
+		if(!filterNameOk) ppMode.error++;
2312
+		ppMode.error += numOfUnknownOptions;
2313
+	}
2314
+
2315
+	if(ppMode.lumMode & H_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_Y_H;
2316
+	if(ppMode.lumMode & V_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_Y_V;
2317
+	if(ppMode.chromMode & H_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_C_H;
2318
+	if(ppMode.chromMode & V_DEBLOCK) ppMode.oldMode |= PP_DEBLOCK_C_V;
2319
+	if(ppMode.lumMode & DERING) ppMode.oldMode |= PP_DERING_Y;
2320
+	if(ppMode.chromMode & DERING) ppMode.oldMode |= PP_DERING_C;
2321
+
2322
+	return ppMode;
2323
+}
2324
+
2166 2325
 /**
2167 2326
  * ...
2168 2327
  */
... ...
@@ -2172,6 +2361,18 @@ void  postprocess(unsigned char * src[], int src_stride,
2172 2172
                  QP_STORE_T *QP_store,  int QP_stride,
2173 2173
 					  int mode)
2174 2174
 {
2175
+/*
2176
+	static int qual=0;
2177
+
2178
+	struct PPMode ppMode= getPPModeByNameAndQuality("fast,default,-hdeblock,-vdeblock", qual);
2179
+	qual++;
2180
+	qual%=7;
2181
+	printf("\n%d %d %d %d\n", ppMode.lumMode, ppMode.chromMode, ppMode.oldMode, ppMode.error);
2182
+	postprocess2(src, src_stride, dst, dst_stride,
2183
+                 horizontal_size, vertical_size, QP_store, QP_stride, &ppMode);
2184
+
2185
+	return;
2186
+*/
2175 2187
 
2176 2188
 #ifdef HAVE_ODIVX_POSTPROCESS
2177 2189
 // Note: I could make this shit outside of this file, but it would mean one
... ...
@@ -2182,21 +2383,6 @@ void  postprocess(unsigned char * src[], int src_stride,
2182 2182
 	}
2183 2183
 #endif
2184 2184
 
2185
-/*
2186
-	long long T= rdtsc();
2187
-	for(int y=vertical_size-1; y>=0 ; y--)
2188
-		memcpy(dst[0] + y*src_stride, src[0] + y*src_stride,src_stride);
2189
-//	memcpy(dst[0], src[0],src_stride*vertical_size);
2190
-	printf("%4dk\r", (rdtsc()-T)/1000);
2191
-
2192
-	return;
2193
-*/
2194
-/*
2195
-	long long T= rdtsc();
2196
-	while( (rdtsc() - T)/1000 < 4000);
2197
-
2198
-	return;
2199
-*/
2200 2185
 	postProcess(src[0], src_stride, dst[0], dst_stride,
2201 2186
 		horizontal_size, vertical_size, QP_store, QP_stride, 0, mode);
2202 2187
 
... ...
@@ -2211,7 +2397,7 @@ void  postprocess(unsigned char * src[], int src_stride,
2211 2211
 		postProcess(src[1], src_stride, dst[1], dst_stride,
2212 2212
 			horizontal_size, vertical_size, QP_store, QP_stride, 1, mode);
2213 2213
 		postProcess(src[2], src_stride, dst[2], dst_stride,
2214
-			horizontal_size, vertical_size, QP_store, QP_stride, 1, mode);
2214
+			horizontal_size, vertical_size, QP_store, QP_stride, 2, mode);
2215 2215
 	}
2216 2216
 	else
2217 2217
 	{
... ...
@@ -2220,6 +2406,38 @@ void  postprocess(unsigned char * src[], int src_stride,
2220 2220
 	}
2221 2221
 }
2222 2222
 
2223
+void  postprocess2(unsigned char * src[], int src_stride,
2224
+                 unsigned char * dst[], int dst_stride,
2225
+                 int horizontal_size,   int vertical_size,
2226
+                 QP_STORE_T *QP_store,  int QP_stride,
2227
+		 struct PPMode *mode)
2228
+{
2229
+
2230
+#ifdef HAVE_ODIVX_POSTPROCESS
2231
+// Note: I could make this shit outside of this file, but it would mean one
2232
+// more function call...
2233
+	if(use_old_pp){
2234
+	    odivx_postprocess(src,src_stride,dst,dst_stride,horizontal_size,vertical_size,QP_store,QP_stride,
2235
+	    mode->oldMode);
2236
+	    return;
2237
+	}
2238
+#endif
2239
+
2240
+	postProcess(src[0], src_stride, dst[0], dst_stride,
2241
+		horizontal_size, vertical_size, QP_store, QP_stride, 0, mode->lumMode);
2242
+
2243
+	horizontal_size >>= 1;
2244
+	vertical_size   >>= 1;
2245
+	src_stride      >>= 1;
2246
+	dst_stride      >>= 1;
2247
+
2248
+	postProcess(src[1], src_stride, dst[1], dst_stride,
2249
+		horizontal_size, vertical_size, QP_store, QP_stride, 1, mode->chromMode);
2250
+	postProcess(src[2], src_stride, dst[2], dst_stride,
2251
+		horizontal_size, vertical_size, QP_store, QP_stride, 2, mode->chromMode);
2252
+}
2253
+
2254
+
2223 2255
 /**
2224 2256
  * gets the mode flags for a given quality (larger values mean slower but better postprocessing)
2225 2257
  * 0 <= quality <= 6