/*1* Copyright (C) 2001-2002 Michael Niedermayer ([email protected])2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920/**21* @file22* internal API header.23*/2425#ifndef POSTPROC_POSTPROCESS_INTERNAL_H26#define POSTPROC_POSTPROCESS_INTERNAL_H2728#include <string.h>29#include "libavutil/avutil.h"30#include "libavutil/intmath.h"31#include "libavutil/log.h"32#include "postprocess.h"3334#define V_DEBLOCK 0x0135#define H_DEBLOCK 0x0236#define DERING 0x0437#define LEVEL_FIX 0x08 ///< Brightness & Contrast3839#define LUM_V_DEBLOCK V_DEBLOCK // 140#define LUM_H_DEBLOCK H_DEBLOCK // 241#define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 1642#define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 3243#define LUM_DERING DERING // 444#define CHROM_DERING (DERING<<4) // 6445#define LUM_LEVEL_FIX LEVEL_FIX // 846#define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)4748// Experimental vertical filters49#define V_X1_FILTER 0x0200 // 51250#define V_A_DEBLOCK 0x04005152// Experimental horizontal filters53#define H_X1_FILTER 0x2000 // 819254#define H_A_DEBLOCK 0x40005556/// select between full y range (255-0) or standard one (234-16)57#define FULL_Y_RANGE 0x8000 // 327685859//Deinterlacing Filters60#define LINEAR_IPOL_DEINT_FILTER 0x10000 // 6553661#define LINEAR_BLEND_DEINT_FILTER 0x20000 // 13107262#define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)63#define CUBIC_IPOL_DEINT_FILTER 0x40000 // 26214464#define MEDIAN_DEINT_FILTER 0x80000 // 52428865#define FFMPEG_DEINT_FILTER 0x40000066#define LOWPASS5_DEINT_FILTER 0x8000006768#define TEMP_NOISE_FILTER 0x10000069#define FORCE_QUANT 0x20000070#define BITEXACT 0x100000071#define VISUALIZE 0x20000007273//use if you want a faster postprocessing code74//cannot differentiate between chroma & luma filters (both on or both off)75//obviously the -pp option on the command line has no effect except turning the here selected76//filters on77//#define COMPILE_TIME_MODE 0x777879/**80* Postprocessing filter.81*/82struct PPFilter{83const char *shortName;84const char *longName;85int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated86int minLumQuality; ///< minimum quality to turn luminance filtering on87int minChromQuality; ///< minimum quality to turn chrominance filtering on88int mask; ///< Bitmask to turn this filter on89};9091/**92* Postprocessing mode.93*/94typedef struct PPMode{95int lumMode; ///< activates filters for luminance96int chromMode; ///< activates filters for chrominance97int error; ///< non zero on error9899int minAllowedY; ///< for brightness correction100int maxAllowedY; ///< for brightness correction101AVRational maxClippedThreshold; ///< amount of "black" you are willing to lose to get a brightness-corrected picture102103int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)104105int baseDcDiff;106int flatnessThreshold;107108int forcedQuant; ///< quantizer if FORCE_QUANT is used109} PPMode;110111/**112* postprocess context.113*/114typedef struct PPContext{115/**116* info on struct for av_log117*/118const AVClass *av_class;119120uint8_t *tempBlocks; ///<used for the horizontal code121122/**123* luma histogram.124* we need 64bit here otherwise we'll going to have a problem125* after watching a black picture for 5 hours126*/127uint64_t *yHistogram;128129DECLARE_ALIGNED(8, uint64_t, packedYOffset);130DECLARE_ALIGNED(8, uint64_t, packedYScale);131132/** Temporal noise reducing buffers */133uint8_t *tempBlurred[3];134int32_t *tempBlurredPast[3];135136/** Temporary buffers for handling the last row(s) */137uint8_t *tempDst;138uint8_t *tempSrc;139140uint8_t *deintTemp;141142DECLARE_ALIGNED(8, uint64_t, pQPb);143DECLARE_ALIGNED(8, uint64_t, pQPb2);144145DECLARE_ALIGNED(32, uint64_t, pQPb_block)[4];146DECLARE_ALIGNED(32, uint64_t, pQPb2_block)[4];147148DECLARE_ALIGNED(32, uint64_t, mmxDcOffset)[64];149DECLARE_ALIGNED(32, uint64_t, mmxDcThreshold)[64];150151QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale152QP_STORE_T *nonBQPTable;153QP_STORE_T *forcedQPTable;154155int QP;156int nonBQP;157158DECLARE_ALIGNED(32, int, QP_block)[4];159DECLARE_ALIGNED(32, int, nonBQP_block)[4];160161int frameNum;162163int cpuCaps;164165int qpStride; ///<size of qp buffers (needed to realloc them if needed)166int stride; ///<size of some buffers (needed to realloc them if needed)167168int hChromaSubSample;169int vChromaSubSample;170171PPMode ppMode;172} PPContext;173174175static inline void linecpy(void *dest, const void *src, int lines, int stride) {176if (stride > 0) {177memcpy(dest, src, lines*stride);178} else {179memcpy((uint8_t*)dest+(lines-1)*stride, (const uint8_t*)src+(lines-1)*stride, -lines*stride);180}181}182183#endif /* POSTPROC_POSTPROCESS_INTERNAL_H */184185186