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.

175 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. #define V_DEBLOCK 0x01
  20. #define H_DEBLOCK 0x02
  21. #define DERING 0x04
  22. #define LEVEL_FIX 0x08 ///< Brightness & Contrast
  23. #define LUM_V_DEBLOCK V_DEBLOCK // 1
  24. #define LUM_H_DEBLOCK H_DEBLOCK // 2
  25. #define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 16
  26. #define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 32
  27. #define LUM_DERING DERING // 4
  28. #define CHROM_DERING (DERING<<4) // 64
  29. #define LUM_LEVEL_FIX LEVEL_FIX // 8
  30. #define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)
  31. // Experimental vertical filters
  32. #define V_X1_FILTER 0x0200 // 512
  33. #define V_A_DEBLOCK 0x0400
  34. // Experimental horizontal filters
  35. #define H_X1_FILTER 0x2000 // 8192
  36. #define H_A_DEBLOCK 0x4000
  37. /// select between full y range (255-0) or standart one (234-16)
  38. #define FULL_Y_RANGE 0x8000 // 32768
  39. //Deinterlacing Filters
  40. #define LINEAR_IPOL_DEINT_FILTER 0x10000 // 65536
  41. #define LINEAR_BLEND_DEINT_FILTER 0x20000 // 131072
  42. #define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)
  43. #define CUBIC_IPOL_DEINT_FILTER 0x40000 // 262144
  44. #define MEDIAN_DEINT_FILTER 0x80000 // 524288
  45. #define FFMPEG_DEINT_FILTER 0x400000
  46. #define LOWPASS5_DEINT_FILTER 0x800000
  47. #define TEMP_NOISE_FILTER 0x100000
  48. #define FORCE_QUANT 0x200000
  49. #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
  50. # define PIC
  51. #endif
  52. //use if u want a faster postprocessing code
  53. //cant differentiate between chroma & luma filters (both on or both off)
  54. //obviosly the -pp option at the commandline has no effect except turning the here selected
  55. //filters on
  56. //#define COMPILE_TIME_MODE 0x77
  57. #if 1
  58. static inline int CLIP(int a){
  59. if(a&256) return ((a)>>31)^(-1);
  60. else return a;
  61. }
  62. //#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a))
  63. #elif 0
  64. #define CLIP(a) clip_tab[a]
  65. #else
  66. #define CLIP(a) (a)
  67. #endif
  68. /**
  69. * Postprocessng filter.
  70. */
  71. struct PPFilter{
  72. const char *shortName;
  73. const char *longName;
  74. int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated
  75. int minLumQuality; ///< minimum quality to turn luminance filtering on
  76. int minChromQuality; ///< minimum quality to turn chrominance filtering on
  77. int mask; ///< Bitmask to turn this filter on
  78. };
  79. /**
  80. * Postprocessng mode.
  81. */
  82. typedef struct PPMode{
  83. int lumMode; ///< acivates filters for luminance
  84. int chromMode; ///< acivates filters for chrominance
  85. int error; ///< non zero on error
  86. int minAllowedY; ///< for brigtness correction
  87. int maxAllowedY; ///< for brihtness correction
  88. float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture
  89. int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)
  90. int baseDcDiff;
  91. int flatnessThreshold;
  92. int forcedQuant; ///< quantizer if FORCE_QUANT is used
  93. } PPMode;
  94. /**
  95. * postprocess context.
  96. */
  97. typedef struct PPContext{
  98. uint8_t *tempBlocks; ///<used for the horizontal code
  99. /**
  100. * luma histogram.
  101. * we need 64bit here otherwise we'll going to have a problem
  102. * after watching a black picture for 5 hours
  103. */
  104. uint64_t *yHistogram;
  105. uint64_t __attribute__((aligned(8))) packedYOffset;
  106. uint64_t __attribute__((aligned(8))) packedYScale;
  107. /** Temporal noise reducing buffers */
  108. uint8_t *tempBlured[3];
  109. int32_t *tempBluredPast[3];
  110. /** Temporary buffers for handling the last row(s) */
  111. uint8_t *tempDst;
  112. uint8_t *tempSrc;
  113. uint8_t *deintTemp;
  114. uint64_t __attribute__((aligned(8))) pQPb;
  115. uint64_t __attribute__((aligned(8))) pQPb2;
  116. uint64_t __attribute__((aligned(8))) mmxDcOffset[64];
  117. uint64_t __attribute__((aligned(8))) mmxDcThreshold[64];
  118. QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale
  119. QP_STORE_T *nonBQPTable;
  120. QP_STORE_T *forcedQPTable;
  121. int QP;
  122. int nonBQP;
  123. int frameNum;
  124. int cpuCaps;
  125. int qpStride; ///<size of qp buffers (needed to realloc them if needed)
  126. int stride; ///<size of some buffers (needed to realloc them if needed)
  127. int hChromaSubSample;
  128. int vChromaSubSample;
  129. PPMode ppMode;
  130. } PPContext;
  131. static inline void linecpy(void *dest, void *src, int lines, int stride)
  132. {
  133. if (stride > 0) {
  134. memcpy(dest, src, lines*stride);
  135. } else {
  136. memcpy(dest+(lines-1)*stride, src+(lines-1)*stride, -lines*stride);
  137. }
  138. }