1 // Copyright 2011 Google Inc. All Rights Reserved.
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 // -----------------------------------------------------------------------------
10 // Speed-critical functions.
12 // Author: Skal (pascal.massimino@gmail.com)
14 #ifndef WEBP_DSP_DSP_H_
15 #define WEBP_DSP_DSP_H_
17 #include "../webp/types.h"
23 //------------------------------------------------------------------------------
26 #if defined(_MSC_VER) && _MSC_VER > 1310 && \
27 (defined(_M_X64) || defined(_M_IX86))
28 #define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
31 #if defined(__SSE2__) || defined(WEBP_MSC_SSE2)
35 #if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
36 #define WEBP_ANDROID_NEON // Android targets that might support NEON
39 #if (defined(__ARM_NEON__) && !defined(__aarch64__)) || \
40 defined(WEBP_ANDROID_NEON)
49 // returns true if the CPU supports the feature.
50 typedef int (*VP8CPUInfo)(CPUFeature feature);
51 extern VP8CPUInfo VP8GetCPUInfo;
53 //------------------------------------------------------------------------------
57 // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
58 // will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
59 typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
61 typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
62 typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
63 extern VP8Idct VP8ITransform;
64 extern VP8Fdct VP8FTransform;
65 extern VP8WHT VP8ITransformWHT;
66 extern VP8WHT VP8FTransformWHT;
68 // *dst is the destination block. *top and *left can be NULL.
69 typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
71 typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
72 extern VP8Intra4Preds VP8EncPredLuma4;
73 extern VP8IntraPreds VP8EncPredLuma16;
74 extern VP8IntraPreds VP8EncPredChroma8;
76 typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
77 extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
78 typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
79 const uint16_t* const weights);
80 extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
82 typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
83 extern VP8BlockCopy VP8Copy4x4;
85 struct VP8Matrix; // forward declaration
86 typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
87 int n, const struct VP8Matrix* const mtx);
88 extern VP8QuantizeBlock VP8EncQuantizeBlock;
90 // specific to 2nd transform:
91 typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
92 const struct VP8Matrix* const mtx);
93 extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
95 // Collect histogram for susceptibility calculation and accumulate in histo[].
97 typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
98 int start_block, int end_block,
99 struct VP8Histogram* const histo);
100 extern const int VP8DspScan[16 + 4 + 4];
101 extern VP8CHisto VP8CollectHistogram;
103 void VP8EncDspInit(void); // must be called before using any of the above
105 //------------------------------------------------------------------------------
108 typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
109 // when doing two transforms, coeffs is actually int16_t[2][16].
110 typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
111 extern VP8DecIdct2 VP8Transform;
112 extern VP8DecIdct VP8TransformAC3;
113 extern VP8DecIdct VP8TransformUV;
114 extern VP8DecIdct VP8TransformDC;
115 extern VP8DecIdct VP8TransformDCUV;
116 extern VP8WHT VP8TransformWHT;
118 // *dst is the destination block, with stride BPS. Boundary samples are
119 // assumed accessible when needed.
120 typedef void (*VP8PredFunc)(uint8_t* dst);
121 extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
122 extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
123 extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
125 // simple filter (only for luma)
126 typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
127 extern VP8SimpleFilterFunc VP8SimpleVFilter16;
128 extern VP8SimpleFilterFunc VP8SimpleHFilter16;
129 extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges
130 extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
132 // regular filter (on both macroblock edges and inner edges)
133 typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
134 int thresh, int ithresh, int hev_t);
135 typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
136 int thresh, int ithresh, int hev_t);
138 extern VP8LumaFilterFunc VP8VFilter16;
139 extern VP8LumaFilterFunc VP8HFilter16;
140 extern VP8ChromaFilterFunc VP8VFilter8;
141 extern VP8ChromaFilterFunc VP8HFilter8;
144 extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether
145 extern VP8LumaFilterFunc VP8HFilter16i;
146 extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether
147 extern VP8ChromaFilterFunc VP8HFilter8i;
149 // must be called before anything using the above
150 void VP8DspInit(void);
152 //------------------------------------------------------------------------------
155 #define FANCY_UPSAMPLING // undefined to remove fancy upsampling support
157 // Convert a pair of y/u/v lines together to the output rgb/a colorspace.
158 // bottom_y can be NULL if only one line of output is needed (at top/bottom).
159 typedef void (*WebPUpsampleLinePairFunc)(
160 const uint8_t* top_y, const uint8_t* bottom_y,
161 const uint8_t* top_u, const uint8_t* top_v,
162 const uint8_t* cur_u, const uint8_t* cur_v,
163 uint8_t* top_dst, uint8_t* bottom_dst, int len);
165 #ifdef FANCY_UPSAMPLING
167 // Fancy upsampling functions to convert YUV to RGB(A) modes
168 extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
170 // Initializes SSE2 version of the fancy upsamplers.
171 void WebPInitUpsamplersSSE2(void);
174 void WebPInitUpsamplersNEON(void);
176 #endif // FANCY_UPSAMPLING
178 // Point-sampling methods.
179 typedef void (*WebPSampleLinePairFunc)(
180 const uint8_t* top_y, const uint8_t* bottom_y,
181 const uint8_t* u, const uint8_t* v,
182 uint8_t* top_dst, uint8_t* bottom_dst, int len);
184 extern const WebPSampleLinePairFunc WebPSamplers[/* MODE_LAST */];
186 // General function for converting two lines of ARGB or RGBA.
187 // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
188 // as 0x00, 0x00, 0x00, 0xff (little endian).
189 WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
191 // YUV444->RGB converters
192 typedef void (*WebPYUV444Converter)(const uint8_t* y,
193 const uint8_t* u, const uint8_t* v,
194 uint8_t* dst, int len);
196 extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
198 // Main function to be called
199 void WebPInitUpsamplers(void);
201 //------------------------------------------------------------------------------
202 // Pre-multiply planes with alpha values
204 // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
205 // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
206 extern void (*WebPApplyAlphaMultiply)(
207 uint8_t* rgba, int alpha_first, int w, int h, int stride);
209 // Same, buf specifically for RGBA4444 format
210 extern void (*WebPApplyAlphaMultiply4444)(
211 uint8_t* rgba4444, int w, int h, int stride);
213 // To be called first before using the above.
214 void WebPInitPremultiply(void);
216 void WebPInitPremultiplySSE2(void); // should not be called directly.
217 void WebPInitPremultiplyNEON(void);
219 //------------------------------------------------------------------------------
225 #endif /* WEBP_DSP_DSP_H_ */