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.

177 lines
5.8KB

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