Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libwebp / dsp / dsp.h
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
9 //
10 //   Speed-critical functions.
11 //
12 // Author: Skal (pascal.massimino@gmail.com)
13
14 #ifndef WEBP_DSP_DSP_H_
15 #define WEBP_DSP_DSP_H_
16
17 #ifdef HAVE_CONFIG_H
18 #include "../webp/config.h"
19 #endif
20
21 #include "../webp/types.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 //------------------------------------------------------------------------------
28 // CPU detection
29
30 #if defined(__GNUC__)
31 # define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
32 # define LOCAL_GCC_PREREQ(maj, min) \
33     (LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
34 #else
35 # define LOCAL_GCC_VERSION 0
36 # define LOCAL_GCC_PREREQ(maj, min) 0
37 #endif
38
39 #ifdef __clang__
40 # define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__)
41 # define LOCAL_CLANG_PREREQ(maj, min) \
42     (LOCAL_CLANG_VERSION >= (((maj) << 8) | (min)))
43 #else
44 # define LOCAL_CLANG_VERSION 0
45 # define LOCAL_CLANG_PREREQ(maj, min) 0
46 #endif  // __clang__
47
48 #if defined(_MSC_VER) && _MSC_VER > 1310 && \
49     (defined(_M_X64) || defined(_M_IX86))
50 #define WEBP_MSC_SSE2  // Visual C++ SSE2 targets
51 #endif
52
53 // WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp
54 // files without intrinsics, allowing the corresponding Init() to be called.
55 // Files containing intrinsics will need to be built targeting the instruction
56 // set so should succeed on one of the earlier tests.
57 #if defined(__SSE2__) || defined(WEBP_MSC_SSE2) || defined(WEBP_HAVE_SSE2)
58 #define WEBP_USE_SSE2
59 #endif
60
61 #if defined(__AVX2__) || defined(WEBP_HAVE_AVX2)
62 #define WEBP_USE_AVX2
63 #endif
64
65 #if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
66 #define WEBP_ANDROID_NEON  // Android targets that might support NEON
67 #endif
68
69 #if defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON) || defined(__aarch64__)
70 #define WEBP_USE_NEON
71 #endif
72
73 #if defined(__mips__) && !defined(__mips64) && (__mips_isa_rev < 6)
74 #define WEBP_USE_MIPS32
75 #if (__mips_isa_rev >= 2)
76 #define WEBP_USE_MIPS32_R2
77 #endif
78 #endif
79
80 typedef enum {
81   kSSE2,
82   kSSE3,
83   kAVX,
84   kAVX2,
85   kNEON,
86   kMIPS32
87 } CPUFeature;
88 // returns true if the CPU supports the feature.
89 typedef int (*VP8CPUInfo)(CPUFeature feature);
90 extern VP8CPUInfo VP8GetCPUInfo;
91
92 //------------------------------------------------------------------------------
93 // Encoding
94
95 // Transforms
96 // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
97 //          will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
98 typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
99                         int do_two);
100 typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
101 typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
102 extern VP8Idct VP8ITransform;
103 extern VP8Fdct VP8FTransform;
104 extern VP8WHT VP8FTransformWHT;
105 // Predictions
106 // *dst is the destination block. *top and *left can be NULL.
107 typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
108                               const uint8_t* top);
109 typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
110 extern VP8Intra4Preds VP8EncPredLuma4;
111 extern VP8IntraPreds VP8EncPredLuma16;
112 extern VP8IntraPreds VP8EncPredChroma8;
113
114 typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
115 extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
116 typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
117                           const uint16_t* const weights);
118 extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
119
120 typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
121 extern VP8BlockCopy VP8Copy4x4;
122 // Quantization
123 struct VP8Matrix;   // forward declaration
124 typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
125                                 const struct VP8Matrix* const mtx);
126 extern VP8QuantizeBlock VP8EncQuantizeBlock;
127
128 // specific to 2nd transform:
129 typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
130                                    const struct VP8Matrix* const mtx);
131 extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
132
133 // Collect histogram for susceptibility calculation and accumulate in histo[].
134 struct VP8Histogram;
135 typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
136                           int start_block, int end_block,
137                           struct VP8Histogram* const histo);
138 extern const int VP8DspScan[16 + 4 + 4];
139 extern VP8CHisto VP8CollectHistogram;
140
141 void VP8EncDspInit(void);   // must be called before using any of the above
142
143 //------------------------------------------------------------------------------
144 // Decoding
145
146 typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
147 // when doing two transforms, coeffs is actually int16_t[2][16].
148 typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
149 extern VP8DecIdct2 VP8Transform;
150 extern VP8DecIdct VP8TransformAC3;
151 extern VP8DecIdct VP8TransformUV;
152 extern VP8DecIdct VP8TransformDC;
153 extern VP8DecIdct VP8TransformDCUV;
154 extern VP8WHT VP8TransformWHT;
155
156 // *dst is the destination block, with stride BPS. Boundary samples are
157 // assumed accessible when needed.
158 typedef void (*VP8PredFunc)(uint8_t* dst);
159 extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
160 extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
161 extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
162
163 // clipping tables (for filtering)
164 extern const int8_t* const VP8ksclip1;  // clips [-1020, 1020] to [-128, 127]
165 extern const int8_t* const VP8ksclip2;  // clips [-112, 112] to [-16, 15]
166 extern const uint8_t* const VP8kclip1;  // clips [-255,511] to [0,255]
167 extern const uint8_t* const VP8kabs0;   // abs(x) for x in [-255,255]
168 void VP8InitClipTables(void);           // must be called first
169
170 // simple filter (only for luma)
171 typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
172 extern VP8SimpleFilterFunc VP8SimpleVFilter16;
173 extern VP8SimpleFilterFunc VP8SimpleHFilter16;
174 extern VP8SimpleFilterFunc VP8SimpleVFilter16i;  // filter 3 inner edges
175 extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
176
177 // regular filter (on both macroblock edges and inner edges)
178 typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
179                                   int thresh, int ithresh, int hev_t);
180 typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
181                                     int thresh, int ithresh, int hev_t);
182 // on outer edge
183 extern VP8LumaFilterFunc VP8VFilter16;
184 extern VP8LumaFilterFunc VP8HFilter16;
185 extern VP8ChromaFilterFunc VP8VFilter8;
186 extern VP8ChromaFilterFunc VP8HFilter8;
187
188 // on inner edge
189 extern VP8LumaFilterFunc VP8VFilter16i;   // filtering 3 inner edges altogether
190 extern VP8LumaFilterFunc VP8HFilter16i;
191 extern VP8ChromaFilterFunc VP8VFilter8i;  // filtering u and v altogether
192 extern VP8ChromaFilterFunc VP8HFilter8i;
193
194 // must be called before anything using the above
195 void VP8DspInit(void);
196
197 //------------------------------------------------------------------------------
198 // WebP I/O
199
200 #define FANCY_UPSAMPLING   // undefined to remove fancy upsampling support
201
202 // Convert a pair of y/u/v lines together to the output rgb/a colorspace.
203 // bottom_y can be NULL if only one line of output is needed (at top/bottom).
204 typedef void (*WebPUpsampleLinePairFunc)(
205     const uint8_t* top_y, const uint8_t* bottom_y,
206     const uint8_t* top_u, const uint8_t* top_v,
207     const uint8_t* cur_u, const uint8_t* cur_v,
208     uint8_t* top_dst, uint8_t* bottom_dst, int len);
209
210 #ifdef FANCY_UPSAMPLING
211
212 // Fancy upsampling functions to convert YUV to RGB(A) modes
213 extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
214
215 #endif    // FANCY_UPSAMPLING
216
217 // Per-row point-sampling methods.
218 typedef void (*WebPSamplerRowFunc)(const uint8_t* y,
219                                    const uint8_t* u, const uint8_t* v,
220                                    uint8_t* dst, int len);
221 // Generic function to apply 'WebPSamplerRowFunc' to the whole plane:
222 void WebPSamplerProcessPlane(const uint8_t* y, int y_stride,
223                              const uint8_t* u, const uint8_t* v, int uv_stride,
224                              uint8_t* dst, int dst_stride,
225                              int width, int height, WebPSamplerRowFunc func);
226
227 // Sampling functions to convert rows of YUV to RGB(A)
228 extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */];
229
230 // General function for converting two lines of ARGB or RGBA.
231 // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
232 // as 0x00, 0x00, 0x00, 0xff (little endian).
233 WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
234
235 // YUV444->RGB converters
236 typedef void (*WebPYUV444Converter)(const uint8_t* y,
237                                     const uint8_t* u, const uint8_t* v,
238                                     uint8_t* dst, int len);
239
240 extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
241
242 // Must be called before using the WebPUpsamplers[] (and for premultiplied
243 // colorspaces like rgbA, rgbA4444, etc)
244 void WebPInitUpsamplers(void);
245 // Must be called before using WebPSamplers[]
246 void WebPInitSamplers(void);
247
248 //------------------------------------------------------------------------------
249 // Utilities for processing transparent channel.
250
251 // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
252 // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
253 extern void (*WebPApplyAlphaMultiply)(
254     uint8_t* rgba, int alpha_first, int w, int h, int stride);
255
256 // Same, buf specifically for RGBA4444 format
257 extern void (*WebPApplyAlphaMultiply4444)(
258     uint8_t* rgba4444, int w, int h, int stride);
259
260 // Extract the alpha values from 32b values in argb[] and pack them into alpha[]
261 // (this is the opposite of WebPDispatchAlpha).
262 // Returns true if there's only trivial 0xff alpha values.
263 extern int (*WebPExtractAlpha)(const uint8_t* argb, int argb_stride,
264                                int width, int height,
265                                uint8_t* alpha, int alpha_stride);
266
267 // Pre-Multiply operation transforms x into x * A / 255  (where x=Y,R,G or B).
268 // Un-Multiply operation transforms x into x * 255 / A.
269
270 // Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row.
271 extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse);
272
273 // Same a WebPMultARGBRow(), but for several rows.
274 void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows,
275                       int inverse);
276
277 // Same for a row of single values, with side alpha values.
278 extern void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha,
279                            int width, int inverse);
280
281 // Same a WebPMultRow(), but for several 'num_rows' rows.
282 void WebPMultRows(uint8_t* ptr, int stride,
283                   const uint8_t* alpha, int alpha_stride,
284                   int width, int num_rows, int inverse);
285
286 // To be called first before using the above.
287 void WebPInitAlphaProcessing(void);
288
289 #ifdef __cplusplus
290 }    // extern "C"
291 #endif
292
293 #endif  /* WEBP_DSP_DSP_H_ */