dsp.h revision 8b720228d581a84fd173b6dcb2fa295b59db489a
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#include "webp/types.h" 18 19#ifdef __cplusplus 20extern "C" { 21#endif 22 23//------------------------------------------------------------------------------ 24// CPU detection 25 26#if defined(_MSC_VER) && _MSC_VER > 1310 && \ 27 (defined(_M_X64) || defined(_M_IX86)) 28#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets 29#endif 30 31#if defined(__SSE2__) || defined(WEBP_MSC_SSE2) 32#define WEBP_USE_SSE2 33#endif 34 35#if defined(__ANDROID__) && defined(__ARM_ARCH_7A__) 36#define WEBP_ANDROID_NEON // Android targets that might support NEON 37#endif 38 39#if defined(__ARM_NEON__) 40#define WEBP_USE_NEON 41#endif 42 43typedef enum { 44 kSSE2, 45 kSSE3, 46 kNEON 47} CPUFeature; 48// returns true if the CPU supports the feature. 49typedef int (*VP8CPUInfo)(CPUFeature feature); 50extern VP8CPUInfo VP8GetCPUInfo; 51 52//------------------------------------------------------------------------------ 53// Encoding 54 55// Transforms 56// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms 57// will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4). 58typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst, 59 int do_two); 60typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out); 61typedef void (*VP8WHT)(const int16_t* in, int16_t* out); 62extern VP8Idct VP8ITransform; 63extern VP8Fdct VP8FTransform; 64extern VP8WHT VP8ITransformWHT; 65extern VP8WHT VP8FTransformWHT; 66// Predictions 67// *dst is the destination block. *top and *left can be NULL. 68typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left, 69 const uint8_t* top); 70typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top); 71extern VP8Intra4Preds VP8EncPredLuma4; 72extern VP8IntraPreds VP8EncPredLuma16; 73extern VP8IntraPreds VP8EncPredChroma8; 74 75typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref); 76extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4; 77typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref, 78 const uint16_t* const weights); 79extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16; 80 81typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst); 82extern VP8BlockCopy VP8Copy4x4; 83// Quantization 84struct VP8Matrix; // forward declaration 85typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16], 86 int n, const struct VP8Matrix* const mtx); 87extern VP8QuantizeBlock VP8EncQuantizeBlock; 88 89// specific to 2nd transform: 90typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16], 91 const struct VP8Matrix* const mtx); 92extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT; 93 94// Collect histogram for susceptibility calculation and accumulate in histo[]. 95struct VP8Histogram; 96typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred, 97 int start_block, int end_block, 98 struct VP8Histogram* const histo); 99extern const int VP8DspScan[16 + 4 + 4]; 100extern VP8CHisto VP8CollectHistogram; 101 102void VP8EncDspInit(void); // must be called before using any of the above 103 104//------------------------------------------------------------------------------ 105// Decoding 106 107typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst); 108// when doing two transforms, coeffs is actually int16_t[2][16]. 109typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two); 110extern VP8DecIdct2 VP8Transform; 111extern VP8DecIdct VP8TransformAC3; 112extern VP8DecIdct VP8TransformUV; 113extern VP8DecIdct VP8TransformDC; 114extern VP8DecIdct VP8TransformDCUV; 115extern VP8WHT VP8TransformWHT; 116 117// *dst is the destination block, with stride BPS. Boundary samples are 118// assumed accessible when needed. 119typedef void (*VP8PredFunc)(uint8_t* dst); 120extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */]; 121extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */]; 122extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */]; 123 124// simple filter (only for luma) 125typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh); 126extern VP8SimpleFilterFunc VP8SimpleVFilter16; 127extern VP8SimpleFilterFunc VP8SimpleHFilter16; 128extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges 129extern VP8SimpleFilterFunc VP8SimpleHFilter16i; 130 131// regular filter (on both macroblock edges and inner edges) 132typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride, 133 int thresh, int ithresh, int hev_t); 134typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride, 135 int thresh, int ithresh, int hev_t); 136// on outer edge 137extern VP8LumaFilterFunc VP8VFilter16; 138extern VP8LumaFilterFunc VP8HFilter16; 139extern VP8ChromaFilterFunc VP8VFilter8; 140extern VP8ChromaFilterFunc VP8HFilter8; 141 142// on inner edge 143extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether 144extern VP8LumaFilterFunc VP8HFilter16i; 145extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether 146extern VP8ChromaFilterFunc VP8HFilter8i; 147 148// must be called before anything using the above 149void VP8DspInit(void); 150 151//------------------------------------------------------------------------------ 152// WebP I/O 153 154#define FANCY_UPSAMPLING // undefined to remove fancy upsampling support 155 156// Convert a pair of y/u/v lines together to the output rgb/a colorspace. 157// bottom_y can be NULL if only one line of output is needed (at top/bottom). 158typedef void (*WebPUpsampleLinePairFunc)( 159 const uint8_t* top_y, const uint8_t* bottom_y, 160 const uint8_t* top_u, const uint8_t* top_v, 161 const uint8_t* cur_u, const uint8_t* cur_v, 162 uint8_t* top_dst, uint8_t* bottom_dst, int len); 163 164#ifdef FANCY_UPSAMPLING 165 166// Fancy upsampling functions to convert YUV to RGB(A) modes 167extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; 168 169// Initializes SSE2 version of the fancy upsamplers. 170void WebPInitUpsamplersSSE2(void); 171 172// NEON version 173void WebPInitUpsamplersNEON(void); 174 175#endif // FANCY_UPSAMPLING 176 177// Point-sampling methods. 178typedef void (*WebPSampleLinePairFunc)( 179 const uint8_t* top_y, const uint8_t* bottom_y, 180 const uint8_t* u, const uint8_t* v, 181 uint8_t* top_dst, uint8_t* bottom_dst, int len); 182 183extern const WebPSampleLinePairFunc WebPSamplers[/* MODE_LAST */]; 184 185// General function for converting two lines of ARGB or RGBA. 186// 'alpha_is_last' should be true if 0xff000000 is stored in memory as 187// as 0x00, 0x00, 0x00, 0xff (little endian). 188WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last); 189 190// YUV444->RGB converters 191typedef void (*WebPYUV444Converter)(const uint8_t* y, 192 const uint8_t* u, const uint8_t* v, 193 uint8_t* dst, int len); 194 195extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */]; 196 197// Main function to be called 198void WebPInitUpsamplers(void); 199 200//------------------------------------------------------------------------------ 201// Pre-multiply planes with alpha values 202 203// Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h. 204// alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last). 205extern void (*WebPApplyAlphaMultiply)( 206 uint8_t* rgba, int alpha_first, int w, int h, int stride); 207 208// Same, buf specifically for RGBA4444 format 209extern void (*WebPApplyAlphaMultiply4444)( 210 uint8_t* rgba4444, int w, int h, int stride); 211 212// To be called first before using the above. 213void WebPInitPremultiply(void); 214 215void WebPInitPremultiplySSE2(void); // should not be called directly. 216void WebPInitPremultiplyNEON(void); 217 218//------------------------------------------------------------------------------ 219 220#ifdef __cplusplus 221} // extern "C" 222#endif 223 224#endif /* WEBP_DSP_DSP_H_ */ 225