changeset 829:c39e14fc2392 libavcodec

cleanup
author michael
date Sat, 02 Nov 2002 13:58:14 +0000
parents ace3ccd18dd2
children 0a1fbae9f6e1
files libpostproc/postprocess.c libpostproc/postprocess.h libpostproc/postprocess_internal.h
diffstat 3 files changed, 179 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/libpostproc/postprocess.c	Sat Nov 02 11:28:08 2002 +0000
+++ b/libpostproc/postprocess.c	Sat Nov 02 13:58:14 2002 +0000
@@ -77,6 +77,7 @@
 //#define DEBUG_BRIGHTNESS
 #include "../libvo/fastmemcpy.h"
 #include "postprocess.h"
+#include "postprocess_internal.h"
 #include "../mangle.h"
 
 #define MIN(a,b) ((a) > (b) ? (b) : (a))
@@ -104,55 +105,6 @@
 
 static const int deringThreshold= 20;
 
-struct PPFilter{
-	char *shortName;
-	char *longName;
-	int chromDefault; 	// is chrominance filtering on by default if this filter is manually activated
-	int minLumQuality; 	// minimum quality to turn luminance filtering on
-	int minChromQuality;	// minimum quality to turn chrominance filtering on
-	int mask; 		// Bitmask to turn this filter on
-};
-
-typedef struct PPContext{
-	uint8_t *tempBlocks; //used for the horizontal code
-
-	/* we need 64bit here otherwise weŽll going to have a problem
-	   after watching a black picture for 5 hours*/
-	uint64_t *yHistogram;
-
-	uint64_t __attribute__((aligned(8))) packedYOffset;
-	uint64_t __attribute__((aligned(8))) packedYScale;
-
-	/* Temporal noise reducing buffers */
-	uint8_t *tempBlured[3];
-	int32_t *tempBluredPast[3];
-
-	/* Temporary buffers for handling the last row(s) */
-	uint8_t *tempDst;
-	uint8_t *tempSrc;
-
-	/* Temporary buffers for handling the last block */
-	uint8_t *tempDstBlock;
-	uint8_t *tempSrcBlock;
-	uint8_t *deintTemp;
-
-	uint64_t __attribute__((aligned(8))) pQPb;
-	uint64_t __attribute__((aligned(8))) pQPb2;
-
-	uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
-	uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
-	
-	QP_STORE_T *nonBQPTable;
-	
-	int QP;
-	int nonBQP;
-
-	int frameNum;
-	
-	int cpuCaps;
-
-	PPMode ppMode;
-} PPContext;
 
 static struct PPFilter filters[]=
 {
@@ -489,9 +441,10 @@
 // minor note: the HAVE_xyz is messed up after that line so dont use it
 
 static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
-	QP_STORE_T QPs[], int QPStride, int isColor, PPMode *ppMode, pp_context_t *vc)
+	QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
 {
 	PPContext *c= (PPContext *)vc;
+	PPMode *ppMode= (PPMode *)vm;
 	c->ppMode= *ppMode; //FIXME
 
 	// useing ifs here as they are faster than function pointers allthough the
@@ -570,27 +523,29 @@
  * name is the string after "-pp" on the command line
  * quality is a number from 0 to GET_PP_QUALITY_MAX
  */
-struct PPMode pp_get_mode_by_name_and_quality(char *name, int quality)
+pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
 {
 	char temp[GET_MODE_BUFFER_SIZE];
 	char *p= temp;
 	char *filterDelimiters= ",/";
 	char *optionDelimiters= ":";
-	struct PPMode ppMode;
+	struct PPMode *ppMode;
 	char *filterToken;
 
-	ppMode.lumMode= 0;
-	ppMode.chromMode= 0;
-	ppMode.maxTmpNoise[0]= 700;
-	ppMode.maxTmpNoise[1]= 1500;
-	ppMode.maxTmpNoise[2]= 3000;
-	ppMode.maxAllowedY= 234;
-	ppMode.minAllowedY= 16;
-	ppMode.baseDcDiff= 256/4;
-	ppMode.flatnessThreshold=40;
-	ppMode.flatnessThreshold= 56-16;
-	ppMode.maxClippedThreshold= 0.01;
-	ppMode.error=0;
+	ppMode= memalign(8, sizeof(PPMode));
+	
+	ppMode->lumMode= 0;
+	ppMode->chromMode= 0;
+	ppMode->maxTmpNoise[0]= 700;
+	ppMode->maxTmpNoise[1]= 1500;
+	ppMode->maxTmpNoise[2]= 3000;
+	ppMode->maxAllowedY= 234;
+	ppMode->minAllowedY= 16;
+	ppMode->baseDcDiff= 256/4;
+	ppMode->flatnessThreshold=40;
+	ppMode->flatnessThreshold= 56-16;
+	ppMode->maxClippedThreshold= 0.01;
+	ppMode->error=0;
 
 	strncpy(temp, name, GET_MODE_BUFFER_SIZE);
 
@@ -652,7 +607,7 @@
 				spaceLeft= p - temp + plen;
 				if(spaceLeft + newlen  >= GET_MODE_BUFFER_SIZE)
 				{
-					ppMode.error++;
+					ppMode->error++;
 					break;
 				}
 				memmove(p + newlen, p, plen+1);
@@ -667,30 +622,30 @@
 			if(   !strcmp(filters[i].longName, filterName)
 			   || !strcmp(filters[i].shortName, filterName))
 			{
-				ppMode.lumMode &= ~filters[i].mask;
-				ppMode.chromMode &= ~filters[i].mask;
+				ppMode->lumMode &= ~filters[i].mask;
+				ppMode->chromMode &= ~filters[i].mask;
 
 				filterNameOk=1;
 				if(!enable) break; // user wants to disable it
 
 				if(q >= filters[i].minLumQuality)
-					ppMode.lumMode|= filters[i].mask;
+					ppMode->lumMode|= filters[i].mask;
 				if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
 					if(q >= filters[i].minChromQuality)
-						ppMode.chromMode|= filters[i].mask;
+						ppMode->chromMode|= filters[i].mask;
 
 				if(filters[i].mask == LEVEL_FIX)
 				{
 					int o;
-					ppMode.minAllowedY= 16;
-					ppMode.maxAllowedY= 234;
+					ppMode->minAllowedY= 16;
+					ppMode->maxAllowedY= 234;
 					for(o=0; options[o]!=NULL; o++)
 					{
 						if(  !strcmp(options[o],"fullyrange")
 						   ||!strcmp(options[o],"f"))
 						{
-							ppMode.minAllowedY= 0;
-							ppMode.maxAllowedY= 255;
+							ppMode->minAllowedY= 0;
+							ppMode->maxAllowedY= 255;
 							numOfUnknownOptions--;
 						}
 					}
@@ -703,7 +658,7 @@
 					for(o=0; options[o]!=NULL; o++)
 					{
 						char *tail;
-						ppMode.maxTmpNoise[numOfNoises]=
+						ppMode->maxTmpNoise[numOfNoises]=
 							strtol(options[o], &tail, 0);
 						if(tail!=options[o])
 						{
@@ -724,14 +679,14 @@
 						if(tail==options[o]) break;
 
 						numOfUnknownOptions--;
-						if(o==0) ppMode.baseDcDiff= val;
-						else ppMode.flatnessThreshold= val;
+						if(o==0) ppMode->baseDcDiff= val;
+						else ppMode->flatnessThreshold= val;
 					}
 				}
 				else if(filters[i].mask == FORCE_QUANT)
 				{
 					int o;
-					ppMode.forcedQuant= 15;
+					ppMode->forcedQuant= 15;
 
 					for(o=0; options[o]!=NULL && o<1; o++)
 					{
@@ -740,20 +695,30 @@
 						if(tail==options[o]) break;
 
 						numOfUnknownOptions--;
-						ppMode.forcedQuant= val;
+						ppMode->forcedQuant= val;
 					}
 				}
 			}
 		}
-		if(!filterNameOk) ppMode.error++;
-		ppMode.error += numOfUnknownOptions;
+		if(!filterNameOk) ppMode->error++;
+		ppMode->error += numOfUnknownOptions;
 	}
 
-	if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode.lumMode, ppMode.chromMode);
+	if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
+	if(ppMode->error)
+	{
+		fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
+		free(ppMode);
+		return NULL;
+	}
 	return ppMode;
 }
 
-void *pp_get_context(int width, int height, int cpuCaps){
+void pp_free_mode(pp_mode_t *mode){
+    if(mode) free(mode);
+}
+
+pp_context_t *pp_get_context(int width, int height, int cpuCaps){
 	PPContext *c= memalign(32, sizeof(PPContext));
 	int i;
 	int mbWidth = (width+15)>>4;
@@ -812,11 +777,12 @@
                  uint8_t * dst[3], int dstStride[3],
                  int width, int height,
                  QP_STORE_T *QP_store,  int QPStride,
-		 PPMode *mode,  void *vc, int pict_type)
+		 pp_mode_t *vm,  void *vc, int pict_type)
 {
 	int mbWidth = (width+15)>>4;
 	int mbHeight= (height+15)>>4;
 	QP_STORE_T quantArray[2048/8];
+	PPMode *mode = (PPMode*)vm;
 	PPContext *c = (PPContext*)vc;
 
 	if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) 
--- a/libpostproc/postprocess.h	Sat Nov 02 11:28:08 2002 +0000
+++ b/libpostproc/postprocess.h	Sat Nov 02 13:58:14 2002 +0000
@@ -16,84 +16,27 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-// POSTPROCESS_H is defined by opendivx's postprocess.h
 #ifndef NEWPOSTPROCESS_H
 #define NEWPOSTPROCESS_H
 
-#define V_DEBLOCK	0x01
-#define H_DEBLOCK	0x02
-#define DERING		0x04
-#define LEVEL_FIX	0x08 /* Brightness & Contrast */
-
-#define LUM_V_DEBLOCK	V_DEBLOCK		//   1
-#define LUM_H_DEBLOCK	H_DEBLOCK		//   2
-#define CHROM_V_DEBLOCK	(V_DEBLOCK<<4)		//  16
-#define CHROM_H_DEBLOCK	(H_DEBLOCK<<4)		//  32
-#define LUM_DERING	DERING			//   4
-#define CHROM_DERING	(DERING<<4)		//  64
-#define LUM_LEVEL_FIX	LEVEL_FIX		//   8
-#define CHROM_LEVEL_FIX	(LEVEL_FIX<<4)		// 128 (not implemented yet)
-
-// Experimental vertical filters
-#define V_X1_FILTER	0x0200			// 512
-
-// Experimental horizontal filters
-#define H_X1_FILTER	0x2000			// 8192
-
-// select between full y range (255-0) or standart one (234-16)
-#define FULL_Y_RANGE	0x8000			// 32768
-
-//Deinterlacing Filters
-#define	LINEAR_IPOL_DEINT_FILTER	0x10000	// 65536
-#define	LINEAR_BLEND_DEINT_FILTER	0x20000	// 131072
-#define	CUBIC_BLEND_DEINT_FILTER	0x8000	// (not implemented yet)
-#define	CUBIC_IPOL_DEINT_FILTER		0x40000	// 262144
-#define	MEDIAN_DEINT_FILTER		0x80000	// 524288
-#define	FFMPEG_DEINT_FILTER		0x400000
-
-#define TEMP_NOISE_FILTER		0x100000
-#define FORCE_QUANT			0x200000
-
 #define GET_PP_QUALITY_MAX 6
 
-//use if u want a faster postprocessing code
-//cant differentiate between chroma & luma filters (both on or both off)
-//obviosly the -pp option at the commandline has no effect except turning the here selected
-//filters on
-//#define COMPILE_TIME_MODE 0x77
-
 #define QP_STORE_T int8_t
 
 typedef void pp_context_t;
-
-extern char *pp_help;
-
-//FIXME decide if this should be exported at all
-typedef struct PPMode{
-	int lumMode; 			// acivates filters for luminance
-	int chromMode; 			// acivates filters for chrominance
-	int error; 			// non zero on error
+typedef void pp_mode_t;
 
-	int minAllowedY; 		// for brigtness correction
-	int maxAllowedY; 		// for brihtness correction
-	float maxClippedThreshold;	// amount of "black" u r willing to loose to get a brightness corrected picture
-
-	int maxTmpNoise[3]; 		// for Temporal Noise Reducing filter (Maximal sum of abs differences)
-
-	int baseDcDiff;
-	int flatnessThreshold;
-
-	int forcedQuant; 		// quantizer if FORCE_QUANT is used
-} PPMode;
+extern char *pp_help; //a simple help text
 
 void  pp_postprocess(uint8_t * src[3], int srcStride[3],
                  uint8_t * dst[3], int dstStride[3],
                  int horizontalSize, int verticalSize,
                  QP_STORE_T *QP_store,  int QP_stride,
-		 PPMode *mode, pp_context_t *ppContext, int pict_type);
+		 pp_mode_t *mode, pp_context_t *ppContext, int pict_type);
 
 // name is the stuff after "-pp" on the command line
-PPMode pp_get_mode_by_name_and_quality(char *name, int quality);
+pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality);
+void pp_free_mode(pp_mode_t *mode);
 
 pp_context_t *pp_get_context(int width, int height, int cpuCaps);
 void pp_free_context(pp_context_t *ppContext);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpostproc/postprocess_internal.h	Sat Nov 02 13:58:14 2002 +0000
@@ -0,0 +1,125 @@
+/*
+    Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#define V_DEBLOCK	0x01
+#define H_DEBLOCK	0x02
+#define DERING		0x04
+#define LEVEL_FIX	0x08 /* Brightness & Contrast */
+
+#define LUM_V_DEBLOCK	V_DEBLOCK		//   1
+#define LUM_H_DEBLOCK	H_DEBLOCK		//   2
+#define CHROM_V_DEBLOCK	(V_DEBLOCK<<4)		//  16
+#define CHROM_H_DEBLOCK	(H_DEBLOCK<<4)		//  32
+#define LUM_DERING	DERING			//   4
+#define CHROM_DERING	(DERING<<4)		//  64
+#define LUM_LEVEL_FIX	LEVEL_FIX		//   8
+#define CHROM_LEVEL_FIX	(LEVEL_FIX<<4)		// 128 (not implemented yet)
+
+// Experimental vertical filters
+#define V_X1_FILTER	0x0200			// 512
+
+// Experimental horizontal filters
+#define H_X1_FILTER	0x2000			// 8192
+
+// select between full y range (255-0) or standart one (234-16)
+#define FULL_Y_RANGE	0x8000			// 32768
+
+//Deinterlacing Filters
+#define	LINEAR_IPOL_DEINT_FILTER	0x10000	// 65536
+#define	LINEAR_BLEND_DEINT_FILTER	0x20000	// 131072
+#define	CUBIC_BLEND_DEINT_FILTER	0x8000	// (not implemented yet)
+#define	CUBIC_IPOL_DEINT_FILTER		0x40000	// 262144
+#define	MEDIAN_DEINT_FILTER		0x80000	// 524288
+#define	FFMPEG_DEINT_FILTER		0x400000
+
+#define TEMP_NOISE_FILTER		0x100000
+#define FORCE_QUANT			0x200000
+
+//use if u want a faster postprocessing code
+//cant differentiate between chroma & luma filters (both on or both off)
+//obviosly the -pp option at the commandline has no effect except turning the here selected
+//filters on
+//#define COMPILE_TIME_MODE 0x77
+
+struct PPFilter{
+	char *shortName;
+	char *longName;
+	int chromDefault; 	// is chrominance filtering on by default if this filter is manually activated
+	int minLumQuality; 	// minimum quality to turn luminance filtering on
+	int minChromQuality;	// minimum quality to turn chrominance filtering on
+	int mask; 		// Bitmask to turn this filter on
+};
+
+typedef struct PPMode{
+	int lumMode; 			// acivates filters for luminance
+	int chromMode; 			// acivates filters for chrominance
+	int error; 			// non zero on error
+
+	int minAllowedY; 		// for brigtness correction
+	int maxAllowedY; 		// for brihtness correction
+	float maxClippedThreshold;	// amount of "black" u r willing to loose to get a brightness corrected picture
+
+	int maxTmpNoise[3]; 		// for Temporal Noise Reducing filter (Maximal sum of abs differences)
+
+	int baseDcDiff;
+	int flatnessThreshold;
+
+	int forcedQuant; 		// quantizer if FORCE_QUANT is used
+} PPMode;
+
+typedef struct PPContext{
+	uint8_t *tempBlocks; //used for the horizontal code
+
+	/* we need 64bit here otherwise weŽll going to have a problem
+	   after watching a black picture for 5 hours*/
+	uint64_t *yHistogram;
+
+	uint64_t __attribute__((aligned(8))) packedYOffset;
+	uint64_t __attribute__((aligned(8))) packedYScale;
+
+	/* Temporal noise reducing buffers */
+	uint8_t *tempBlured[3];
+	int32_t *tempBluredPast[3];
+
+	/* Temporary buffers for handling the last row(s) */
+	uint8_t *tempDst;
+	uint8_t *tempSrc;
+
+	/* Temporary buffers for handling the last block */
+	uint8_t *tempDstBlock;
+	uint8_t *tempSrcBlock;
+	uint8_t *deintTemp;
+
+	uint64_t __attribute__((aligned(8))) pQPb;
+	uint64_t __attribute__((aligned(8))) pQPb2;
+
+	uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
+	uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
+	
+	QP_STORE_T *nonBQPTable;
+	
+	int QP;
+	int nonBQP;
+
+	int frameNum;
+	
+	int cpuCaps;
+
+	PPMode ppMode;
+} PPContext;
+