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