You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.9KB

  1. /*
  2. * Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file postprocess_internal.h
  22. * internal api header.
  23. */
  24. #include "avutil.h"
  25. #define V_DEBLOCK 0x01
  26. #define H_DEBLOCK 0x02
  27. #define DERING 0x04
  28. #define LEVEL_FIX 0x08 ///< Brightness & Contrast
  29. #define LUM_V_DEBLOCK V_DEBLOCK // 1
  30. #define LUM_H_DEBLOCK H_DEBLOCK // 2
  31. #define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 16
  32. #define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 32
  33. #define LUM_DERING DERING // 4
  34. #define CHROM_DERING (DERING<<4) // 64
  35. #define LUM_LEVEL_FIX LEVEL_FIX // 8
  36. #define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)
  37. // Experimental vertical filters
  38. #define V_X1_FILTER 0x0200 // 512
  39. #define V_A_DEBLOCK 0x0400
  40. // Experimental horizontal filters
  41. #define H_X1_FILTER 0x2000 // 8192
  42. #define H_A_DEBLOCK 0x4000
  43. /// select between full y range (255-0) or standart one (234-16)
  44. #define FULL_Y_RANGE 0x8000 // 32768
  45. //Deinterlacing Filters
  46. #define LINEAR_IPOL_DEINT_FILTER 0x10000 // 65536
  47. #define LINEAR_BLEND_DEINT_FILTER 0x20000 // 131072
  48. #define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)
  49. #define CUBIC_IPOL_DEINT_FILTER 0x40000 // 262144
  50. #define MEDIAN_DEINT_FILTER 0x80000 // 524288
  51. #define FFMPEG_DEINT_FILTER 0x400000
  52. #define LOWPASS5_DEINT_FILTER 0x800000
  53. #define TEMP_NOISE_FILTER 0x100000
  54. #define FORCE_QUANT 0x200000
  55. #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
  56. # define PIC
  57. #endif
  58. //use if u want a faster postprocessing code
  59. //cant differentiate between chroma & luma filters (both on or both off)
  60. //obviosly the -pp option at the commandline has no effect except turning the here selected
  61. //filters on
  62. //#define COMPILE_TIME_MODE 0x77
  63. #if 1
  64. static inline int CLIP(int a){
  65. if(a&256) return ((a)>>31)^(-1);
  66. else return a;
  67. }
  68. //#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a))
  69. #elif 0
  70. #define CLIP(a) clip_tab[a]
  71. #else
  72. #define CLIP(a) (a)
  73. #endif
  74. /**
  75. * Postprocessng filter.
  76. */
  77. struct PPFilter{
  78. const char *shortName;
  79. const char *longName;
  80. int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated
  81. int minLumQuality; ///< minimum quality to turn luminance filtering on
  82. int minChromQuality; ///< minimum quality to turn chrominance filtering on
  83. int mask; ///< Bitmask to turn this filter on
  84. };
  85. /**
  86. * Postprocessng mode.
  87. */
  88. typedef struct PPMode{
  89. int lumMode; ///< acivates filters for luminance
  90. int chromMode; ///< acivates filters for chrominance
  91. int error; ///< non zero on error
  92. int minAllowedY; ///< for brigtness correction
  93. int maxAllowedY; ///< for brihtness correction
  94. float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture
  95. int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)
  96. int baseDcDiff;
  97. int flatnessThreshold;
  98. int forcedQuant; ///< quantizer if FORCE_QUANT is used
  99. } PPMode;
  100. /**
  101. * postprocess context.
  102. */
  103. typedef struct PPContext{
  104. /**
  105. * info on struct for av_log
  106. */
  107. AVClass *av_class;
  108. uint8_t *tempBlocks; ///<used for the horizontal code
  109. /**
  110. * luma histogram.
  111. * we need 64bit here otherwise we'll going to have a problem
  112. * after watching a black picture for 5 hours
  113. */
  114. uint64_t *yHistogram;
  115. DECLARE_ALIGNED(8, uint64_t, packedYOffset);
  116. DECLARE_ALIGNED(8, uint64_t, packedYScale);
  117. /** Temporal noise reducing buffers */
  118. uint8_t *tempBlured[3];
  119. int32_t *tempBluredPast[3];
  120. /** Temporary buffers for handling the last row(s) */
  121. uint8_t *tempDst;
  122. uint8_t *tempSrc;
  123. uint8_t *deintTemp;
  124. DECLARE_ALIGNED(8, uint64_t, pQPb);
  125. DECLARE_ALIGNED(8, uint64_t, pQPb2);
  126. DECLARE_ALIGNED(8, uint64_t, mmxDcOffset[64]);
  127. DECLARE_ALIGNED(8, uint64_t, mmxDcThreshold[64]);
  128. QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale
  129. QP_STORE_T *nonBQPTable;
  130. QP_STORE_T *forcedQPTable;
  131. int QP;
  132. int nonBQP;
  133. int frameNum;
  134. int cpuCaps;
  135. int qpStride; ///<size of qp buffers (needed to realloc them if needed)
  136. int stride; ///<size of some buffers (needed to realloc them if needed)
  137. int hChromaSubSample;
  138. int vChromaSubSample;
  139. PPMode ppMode;
  140. } PPContext;
  141. static inline void linecpy(void *dest, void *src, int lines, int stride)
  142. {
  143. if (stride > 0) {
  144. memcpy(dest, src, lines*stride);
  145. } else {
  146. memcpy(dest+(lines-1)*stride, src+(lines-1)*stride, -lines*stride);
  147. }
  148. }