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