dsp.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright 2011 Google Inc. All Rights Reserved.
  2. //
  3. // This code is licensed under the same terms as WebM:
  4. // Software License Agreement: http://www.webmproject.org/license/software/
  5. // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
  6. // -----------------------------------------------------------------------------
  7. //
  8. // Speed-critical functions.
  9. //
  10. // Author: Skal ([email protected])
  11. #ifndef WEBP_DSP_DSP_H_
  12. #define WEBP_DSP_DSP_H_
  13. #include "../types.h"
  14. #if defined(__cplusplus) || defined(c_plusplus)
  15. extern "C" {
  16. #endif
  17. //------------------------------------------------------------------------------
  18. // CPU detection
  19. #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
  20. #define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
  21. #endif
  22. #if defined(__SSE2__) || defined(WEBP_MSC_SSE2)
  23. #define WEBP_USE_SSE2
  24. #endif
  25. #if defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_NEON__)
  26. #define WEBP_ANDROID_NEON // Android targets that might support NEON
  27. #endif
  28. #if ( (defined(__ARM_NEON__) && !defined(__aarch64__)) || defined(WEBP_ANDROID_NEON)) && !defined(PSP2_ENABLED)
  29. #define WEBP_USE_NEON
  30. #endif
  31. typedef enum {
  32. kSSE2,
  33. kSSE3,
  34. kNEON
  35. } CPUFeature;
  36. // returns true if the CPU supports the feature.
  37. typedef int (*VP8CPUInfo)(CPUFeature feature);
  38. extern VP8CPUInfo VP8GetCPUInfo;
  39. //------------------------------------------------------------------------------
  40. // Encoding
  41. int VP8GetAlpha(const int histo[]);
  42. // Transforms
  43. // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
  44. // will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
  45. typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
  46. int do_two);
  47. typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
  48. typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
  49. extern VP8Idct VP8ITransform;
  50. extern VP8Fdct VP8FTransform;
  51. extern VP8WHT VP8ITransformWHT;
  52. extern VP8WHT VP8FTransformWHT;
  53. // Predictions
  54. // *dst is the destination block. *top and *left can be NULL.
  55. typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
  56. const uint8_t* top);
  57. typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
  58. extern VP8Intra4Preds VP8EncPredLuma4;
  59. extern VP8IntraPreds VP8EncPredLuma16;
  60. extern VP8IntraPreds VP8EncPredChroma8;
  61. typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
  62. extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
  63. typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
  64. const uint16_t* const weights);
  65. extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
  66. typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
  67. extern VP8BlockCopy VP8Copy4x4;
  68. // Quantization
  69. struct VP8Matrix; // forward declaration
  70. typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
  71. int n, const struct VP8Matrix* const mtx);
  72. extern VP8QuantizeBlock VP8EncQuantizeBlock;
  73. // Compute susceptibility based on DCT-coeff histograms:
  74. // the higher, the "easier" the macroblock is to compress.
  75. typedef int (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
  76. int start_block, int end_block);
  77. extern const int VP8DspScan[16 + 4 + 4];
  78. extern VP8CHisto VP8CollectHistogram;
  79. void VP8EncDspInit(void); // must be called before using any of the above
  80. //------------------------------------------------------------------------------
  81. // Decoding
  82. typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
  83. // when doing two transforms, coeffs is actually int16_t[2][16].
  84. typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
  85. extern VP8DecIdct2 VP8Transform;
  86. extern VP8DecIdct VP8TransformUV;
  87. extern VP8DecIdct VP8TransformDC;
  88. extern VP8DecIdct VP8TransformDCUV;
  89. extern void (*VP8TransformWHT)(const int16_t* in, int16_t* out);
  90. // *dst is the destination block, with stride BPS. Boundary samples are
  91. // assumed accessible when needed.
  92. typedef void (*VP8PredFunc)(uint8_t* dst);
  93. extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
  94. extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
  95. extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
  96. // simple filter (only for luma)
  97. typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
  98. extern VP8SimpleFilterFunc VP8SimpleVFilter16;
  99. extern VP8SimpleFilterFunc VP8SimpleHFilter16;
  100. extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges
  101. extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
  102. // regular filter (on both macroblock edges and inner edges)
  103. typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
  104. int thresh, int ithresh, int hev_t);
  105. typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
  106. int thresh, int ithresh, int hev_t);
  107. // on outer edge
  108. extern VP8LumaFilterFunc VP8VFilter16;
  109. extern VP8LumaFilterFunc VP8HFilter16;
  110. extern VP8ChromaFilterFunc VP8VFilter8;
  111. extern VP8ChromaFilterFunc VP8HFilter8;
  112. // on inner edge
  113. extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether
  114. extern VP8LumaFilterFunc VP8HFilter16i;
  115. extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether
  116. extern VP8ChromaFilterFunc VP8HFilter8i;
  117. // must be called before anything using the above
  118. void VP8DspInit(void);
  119. //------------------------------------------------------------------------------
  120. // WebP I/O
  121. #define FANCY_UPSAMPLING // undefined to remove fancy upsampling support
  122. typedef void (*WebPUpsampleLinePairFunc)(
  123. const uint8_t* top_y, const uint8_t* bottom_y,
  124. const uint8_t* top_u, const uint8_t* top_v,
  125. const uint8_t* cur_u, const uint8_t* cur_v,
  126. uint8_t* top_dst, uint8_t* bottom_dst, int len);
  127. #ifdef FANCY_UPSAMPLING
  128. // Fancy upsampling functions to convert YUV to RGB(A) modes
  129. extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
  130. // Initializes SSE2 version of the fancy upsamplers.
  131. void WebPInitUpsamplersSSE2(void);
  132. #endif // FANCY_UPSAMPLING
  133. // Point-sampling methods.
  134. typedef void (*WebPSampleLinePairFunc)(
  135. const uint8_t* top_y, const uint8_t* bottom_y,
  136. const uint8_t* u, const uint8_t* v,
  137. uint8_t* top_dst, uint8_t* bottom_dst, int len);
  138. extern const WebPSampleLinePairFunc WebPSamplers[/* MODE_LAST */];
  139. // General function for converting two lines of ARGB or RGBA.
  140. // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
  141. // as 0x00, 0x00, 0x00, 0xff (little endian).
  142. WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
  143. // YUV444->RGB converters
  144. typedef void (*WebPYUV444Converter)(const uint8_t* y,
  145. const uint8_t* u, const uint8_t* v,
  146. uint8_t* dst, int len);
  147. extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
  148. // Main function to be called
  149. void WebPInitUpsamplers(void);
  150. //------------------------------------------------------------------------------
  151. // Pre-multiply planes with alpha values
  152. // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
  153. // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
  154. extern void (*WebPApplyAlphaMultiply)(
  155. uint8_t* rgba, int alpha_first, int w, int h, int stride);
  156. // Same, buf specifically for RGBA4444 format
  157. extern void (*WebPApplyAlphaMultiply4444)(
  158. uint8_t* rgba4444, int w, int h, int stride);
  159. // To be called first before using the above.
  160. void WebPInitPremultiply(void);
  161. void WebPInitPremultiplySSE2(void); // should not be called directly.
  162. //------------------------------------------------------------------------------
  163. #if defined(__cplusplus) || defined(c_plusplus)
  164. } // extern "C"
  165. #endif
  166. #endif /* WEBP_DSP_DSP_H_ */