1*b2055c35SXin Li // Copyright 2011 Google Inc. All Rights Reserved. 2*b2055c35SXin Li // 3*b2055c35SXin Li // Use of this source code is governed by a BSD-style license 4*b2055c35SXin Li // that can be found in the COPYING file in the root of the source 5*b2055c35SXin Li // tree. An additional intellectual property rights grant can be found 6*b2055c35SXin Li // in the file PATENTS. All contributing project authors may 7*b2055c35SXin Li // be found in the AUTHORS file in the root of the source tree. 8*b2055c35SXin Li // ----------------------------------------------------------------------------- 9*b2055c35SXin Li // 10*b2055c35SXin Li // Speed-critical functions. 11*b2055c35SXin Li // 12*b2055c35SXin Li // Author: Skal ([email protected]) 13*b2055c35SXin Li 14*b2055c35SXin Li #ifndef WEBP_DSP_DSP_H_ 15*b2055c35SXin Li #define WEBP_DSP_DSP_H_ 16*b2055c35SXin Li 17*b2055c35SXin Li #ifdef HAVE_CONFIG_H 18*b2055c35SXin Li #include "src/webp/config.h" 19*b2055c35SXin Li #endif 20*b2055c35SXin Li 21*b2055c35SXin Li #include "src/dsp/cpu.h" 22*b2055c35SXin Li #include "src/webp/types.h" 23*b2055c35SXin Li 24*b2055c35SXin Li #ifdef __cplusplus 25*b2055c35SXin Li extern "C" { 26*b2055c35SXin Li #endif 27*b2055c35SXin Li 28*b2055c35SXin Li #define BPS 32 // this is the common stride for enc/dec 29*b2055c35SXin Li 30*b2055c35SXin Li //------------------------------------------------------------------------------ 31*b2055c35SXin Li // WEBP_RESTRICT 32*b2055c35SXin Li 33*b2055c35SXin Li // Declares a pointer with the restrict type qualifier if available. 34*b2055c35SXin Li // This allows code to hint to the compiler that only this pointer references a 35*b2055c35SXin Li // particular object or memory region within the scope of the block in which it 36*b2055c35SXin Li // is declared. This may allow for improved optimizations due to the lack of 37*b2055c35SXin Li // pointer aliasing. See also: 38*b2055c35SXin Li // https://en.cppreference.com/w/c/language/restrict 39*b2055c35SXin Li #if defined(__GNUC__) 40*b2055c35SXin Li #define WEBP_RESTRICT __restrict__ 41*b2055c35SXin Li #elif defined(_MSC_VER) 42*b2055c35SXin Li #define WEBP_RESTRICT __restrict 43*b2055c35SXin Li #else 44*b2055c35SXin Li #define WEBP_RESTRICT 45*b2055c35SXin Li #endif 46*b2055c35SXin Li 47*b2055c35SXin Li 48*b2055c35SXin Li //------------------------------------------------------------------------------ 49*b2055c35SXin Li // Init stub generator 50*b2055c35SXin Li 51*b2055c35SXin Li // Defines an init function stub to ensure each module exposes a symbol, 52*b2055c35SXin Li // avoiding a compiler warning. 53*b2055c35SXin Li #define WEBP_DSP_INIT_STUB(func) \ 54*b2055c35SXin Li extern void func(void); \ 55*b2055c35SXin Li void func(void) {} 56*b2055c35SXin Li 57*b2055c35SXin Li //------------------------------------------------------------------------------ 58*b2055c35SXin Li // Encoding 59*b2055c35SXin Li 60*b2055c35SXin Li // Transforms 61*b2055c35SXin Li // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms 62*b2055c35SXin Li // will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4). 63*b2055c35SXin Li typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst, 64*b2055c35SXin Li int do_two); 65*b2055c35SXin Li typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out); 66*b2055c35SXin Li typedef void (*VP8WHT)(const int16_t* in, int16_t* out); 67*b2055c35SXin Li extern VP8Idct VP8ITransform; 68*b2055c35SXin Li extern VP8Fdct VP8FTransform; 69*b2055c35SXin Li extern VP8Fdct VP8FTransform2; // performs two transforms at a time 70*b2055c35SXin Li extern VP8WHT VP8FTransformWHT; 71*b2055c35SXin Li // Predictions 72*b2055c35SXin Li // *dst is the destination block. *top and *left can be NULL. 73*b2055c35SXin Li typedef void (*VP8IntraPreds)(uint8_t* dst, const uint8_t* left, 74*b2055c35SXin Li const uint8_t* top); 75*b2055c35SXin Li typedef void (*VP8Intra4Preds)(uint8_t* dst, const uint8_t* top); 76*b2055c35SXin Li extern VP8Intra4Preds VP8EncPredLuma4; 77*b2055c35SXin Li extern VP8IntraPreds VP8EncPredLuma16; 78*b2055c35SXin Li extern VP8IntraPreds VP8EncPredChroma8; 79*b2055c35SXin Li 80*b2055c35SXin Li typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref); 81*b2055c35SXin Li extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4; 82*b2055c35SXin Li typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref, 83*b2055c35SXin Li const uint16_t* const weights); 84*b2055c35SXin Li // The weights for VP8TDisto4x4 and VP8TDisto16x16 contain a row-major 85*b2055c35SXin Li // 4 by 4 symmetric matrix. 86*b2055c35SXin Li extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16; 87*b2055c35SXin Li 88*b2055c35SXin Li // Compute the average (DC) of four 4x4 blocks. 89*b2055c35SXin Li // Each sub-4x4 block #i sum is stored in dc[i]. 90*b2055c35SXin Li typedef void (*VP8MeanMetric)(const uint8_t* ref, uint32_t dc[4]); 91*b2055c35SXin Li extern VP8MeanMetric VP8Mean16x4; 92*b2055c35SXin Li 93*b2055c35SXin Li typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst); 94*b2055c35SXin Li extern VP8BlockCopy VP8Copy4x4; 95*b2055c35SXin Li extern VP8BlockCopy VP8Copy16x8; 96*b2055c35SXin Li // Quantization 97*b2055c35SXin Li struct VP8Matrix; // forward declaration 98*b2055c35SXin Li typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16], 99*b2055c35SXin Li const struct VP8Matrix* const mtx); 100*b2055c35SXin Li // Same as VP8QuantizeBlock, but quantizes two consecutive blocks. 101*b2055c35SXin Li typedef int (*VP8Quantize2Blocks)(int16_t in[32], int16_t out[32], 102*b2055c35SXin Li const struct VP8Matrix* const mtx); 103*b2055c35SXin Li 104*b2055c35SXin Li extern VP8QuantizeBlock VP8EncQuantizeBlock; 105*b2055c35SXin Li extern VP8Quantize2Blocks VP8EncQuantize2Blocks; 106*b2055c35SXin Li 107*b2055c35SXin Li // specific to 2nd transform: 108*b2055c35SXin Li typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16], 109*b2055c35SXin Li const struct VP8Matrix* const mtx); 110*b2055c35SXin Li extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT; 111*b2055c35SXin Li 112*b2055c35SXin Li extern const int VP8DspScan[16 + 4 + 4]; 113*b2055c35SXin Li 114*b2055c35SXin Li // Collect histogram for susceptibility calculation. 115*b2055c35SXin Li #define MAX_COEFF_THRESH 31 // size of histogram used by CollectHistogram. 116*b2055c35SXin Li typedef struct { 117*b2055c35SXin Li // We only need to store max_value and last_non_zero, not the distribution. 118*b2055c35SXin Li int max_value; 119*b2055c35SXin Li int last_non_zero; 120*b2055c35SXin Li } VP8Histogram; 121*b2055c35SXin Li typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred, 122*b2055c35SXin Li int start_block, int end_block, 123*b2055c35SXin Li VP8Histogram* const histo); 124*b2055c35SXin Li extern VP8CHisto VP8CollectHistogram; 125*b2055c35SXin Li // General-purpose util function to help VP8CollectHistogram(). 126*b2055c35SXin Li void VP8SetHistogramData(const int distribution[MAX_COEFF_THRESH + 1], 127*b2055c35SXin Li VP8Histogram* const histo); 128*b2055c35SXin Li 129*b2055c35SXin Li // must be called before using any of the above 130*b2055c35SXin Li void VP8EncDspInit(void); 131*b2055c35SXin Li 132*b2055c35SXin Li //------------------------------------------------------------------------------ 133*b2055c35SXin Li // cost functions (encoding) 134*b2055c35SXin Li 135*b2055c35SXin Li extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p) 136*b2055c35SXin Li // approximate cost per level: 137*b2055c35SXin Li extern const uint16_t VP8LevelFixedCosts[2047 /*MAX_LEVEL*/ + 1]; 138*b2055c35SXin Li extern const uint8_t VP8EncBands[16 + 1]; 139*b2055c35SXin Li 140*b2055c35SXin Li struct VP8Residual; 141*b2055c35SXin Li typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs, 142*b2055c35SXin Li struct VP8Residual* const res); 143*b2055c35SXin Li extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs; 144*b2055c35SXin Li 145*b2055c35SXin Li // Cost calculation function. 146*b2055c35SXin Li typedef int (*VP8GetResidualCostFunc)(int ctx0, 147*b2055c35SXin Li const struct VP8Residual* const res); 148*b2055c35SXin Li extern VP8GetResidualCostFunc VP8GetResidualCost; 149*b2055c35SXin Li 150*b2055c35SXin Li // must be called before anything using the above 151*b2055c35SXin Li void VP8EncDspCostInit(void); 152*b2055c35SXin Li 153*b2055c35SXin Li //------------------------------------------------------------------------------ 154*b2055c35SXin Li // SSIM / PSNR utils 155*b2055c35SXin Li 156*b2055c35SXin Li // struct for accumulating statistical moments 157*b2055c35SXin Li typedef struct { 158*b2055c35SXin Li uint32_t w; // sum(w_i) : sum of weights 159*b2055c35SXin Li uint32_t xm, ym; // sum(w_i * x_i), sum(w_i * y_i) 160*b2055c35SXin Li uint32_t xxm, xym, yym; // sum(w_i * x_i * x_i), etc. 161*b2055c35SXin Li } VP8DistoStats; 162*b2055c35SXin Li 163*b2055c35SXin Li // Compute the final SSIM value 164*b2055c35SXin Li // The non-clipped version assumes stats->w = (2 * VP8_SSIM_KERNEL + 1)^2. 165*b2055c35SXin Li double VP8SSIMFromStats(const VP8DistoStats* const stats); 166*b2055c35SXin Li double VP8SSIMFromStatsClipped(const VP8DistoStats* const stats); 167*b2055c35SXin Li 168*b2055c35SXin Li #define VP8_SSIM_KERNEL 3 // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1 169*b2055c35SXin Li typedef double (*VP8SSIMGetClippedFunc)(const uint8_t* src1, int stride1, 170*b2055c35SXin Li const uint8_t* src2, int stride2, 171*b2055c35SXin Li int xo, int yo, // center position 172*b2055c35SXin Li int W, int H); // plane dimension 173*b2055c35SXin Li 174*b2055c35SXin Li #if !defined(WEBP_REDUCE_SIZE) 175*b2055c35SXin Li // This version is called with the guarantee that you can load 8 bytes and 176*b2055c35SXin Li // 8 rows at offset src1 and src2 177*b2055c35SXin Li typedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1, 178*b2055c35SXin Li const uint8_t* src2, int stride2); 179*b2055c35SXin Li 180*b2055c35SXin Li extern VP8SSIMGetFunc VP8SSIMGet; // unclipped / unchecked 181*b2055c35SXin Li extern VP8SSIMGetClippedFunc VP8SSIMGetClipped; // with clipping 182*b2055c35SXin Li #endif 183*b2055c35SXin Li 184*b2055c35SXin Li #if !defined(WEBP_DISABLE_STATS) 185*b2055c35SXin Li typedef uint32_t (*VP8AccumulateSSEFunc)(const uint8_t* src1, 186*b2055c35SXin Li const uint8_t* src2, int len); 187*b2055c35SXin Li extern VP8AccumulateSSEFunc VP8AccumulateSSE; 188*b2055c35SXin Li #endif 189*b2055c35SXin Li 190*b2055c35SXin Li // must be called before using any of the above directly 191*b2055c35SXin Li void VP8SSIMDspInit(void); 192*b2055c35SXin Li 193*b2055c35SXin Li //------------------------------------------------------------------------------ 194*b2055c35SXin Li // Decoding 195*b2055c35SXin Li 196*b2055c35SXin Li typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst); 197*b2055c35SXin Li // when doing two transforms, coeffs is actually int16_t[2][16]. 198*b2055c35SXin Li typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two); 199*b2055c35SXin Li extern VP8DecIdct2 VP8Transform; 200*b2055c35SXin Li extern VP8DecIdct VP8TransformAC3; 201*b2055c35SXin Li extern VP8DecIdct VP8TransformUV; 202*b2055c35SXin Li extern VP8DecIdct VP8TransformDC; 203*b2055c35SXin Li extern VP8DecIdct VP8TransformDCUV; 204*b2055c35SXin Li extern VP8WHT VP8TransformWHT; 205*b2055c35SXin Li 206*b2055c35SXin Li #define WEBP_TRANSFORM_AC3_C1 20091 207*b2055c35SXin Li #define WEBP_TRANSFORM_AC3_C2 35468 208*b2055c35SXin Li #define WEBP_TRANSFORM_AC3_MUL1(a) ((((a) * WEBP_TRANSFORM_AC3_C1) >> 16) + (a)) 209*b2055c35SXin Li #define WEBP_TRANSFORM_AC3_MUL2(a) (((a) * WEBP_TRANSFORM_AC3_C2) >> 16) 210*b2055c35SXin Li 211*b2055c35SXin Li // *dst is the destination block, with stride BPS. Boundary samples are 212*b2055c35SXin Li // assumed accessible when needed. 213*b2055c35SXin Li typedef void (*VP8PredFunc)(uint8_t* dst); 214*b2055c35SXin Li extern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */]; 215*b2055c35SXin Li extern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */]; 216*b2055c35SXin Li extern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */]; 217*b2055c35SXin Li 218*b2055c35SXin Li // clipping tables (for filtering) 219*b2055c35SXin Li extern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127] 220*b2055c35SXin Li extern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15] 221*b2055c35SXin Li extern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255] 222*b2055c35SXin Li extern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255] 223*b2055c35SXin Li // must be called first 224*b2055c35SXin Li void VP8InitClipTables(void); 225*b2055c35SXin Li 226*b2055c35SXin Li // simple filter (only for luma) 227*b2055c35SXin Li typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh); 228*b2055c35SXin Li extern VP8SimpleFilterFunc VP8SimpleVFilter16; 229*b2055c35SXin Li extern VP8SimpleFilterFunc VP8SimpleHFilter16; 230*b2055c35SXin Li extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges 231*b2055c35SXin Li extern VP8SimpleFilterFunc VP8SimpleHFilter16i; 232*b2055c35SXin Li 233*b2055c35SXin Li // regular filter (on both macroblock edges and inner edges) 234*b2055c35SXin Li typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride, 235*b2055c35SXin Li int thresh, int ithresh, int hev_t); 236*b2055c35SXin Li typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride, 237*b2055c35SXin Li int thresh, int ithresh, int hev_t); 238*b2055c35SXin Li // on outer edge 239*b2055c35SXin Li extern VP8LumaFilterFunc VP8VFilter16; 240*b2055c35SXin Li extern VP8LumaFilterFunc VP8HFilter16; 241*b2055c35SXin Li extern VP8ChromaFilterFunc VP8VFilter8; 242*b2055c35SXin Li extern VP8ChromaFilterFunc VP8HFilter8; 243*b2055c35SXin Li 244*b2055c35SXin Li // on inner edge 245*b2055c35SXin Li extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether 246*b2055c35SXin Li extern VP8LumaFilterFunc VP8HFilter16i; 247*b2055c35SXin Li extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether 248*b2055c35SXin Li extern VP8ChromaFilterFunc VP8HFilter8i; 249*b2055c35SXin Li 250*b2055c35SXin Li // Dithering. Combines dithering values (centered around 128) with dst[], 251*b2055c35SXin Li // according to: dst[] = clip(dst[] + (((dither[]-128) + 8) >> 4) 252*b2055c35SXin Li #define VP8_DITHER_DESCALE 4 253*b2055c35SXin Li #define VP8_DITHER_DESCALE_ROUNDER (1 << (VP8_DITHER_DESCALE - 1)) 254*b2055c35SXin Li #define VP8_DITHER_AMP_BITS 7 255*b2055c35SXin Li #define VP8_DITHER_AMP_CENTER (1 << VP8_DITHER_AMP_BITS) 256*b2055c35SXin Li extern void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst, 257*b2055c35SXin Li int dst_stride); 258*b2055c35SXin Li 259*b2055c35SXin Li // must be called before anything using the above 260*b2055c35SXin Li void VP8DspInit(void); 261*b2055c35SXin Li 262*b2055c35SXin Li //------------------------------------------------------------------------------ 263*b2055c35SXin Li // WebP I/O 264*b2055c35SXin Li 265*b2055c35SXin Li #define FANCY_UPSAMPLING // undefined to remove fancy upsampling support 266*b2055c35SXin Li 267*b2055c35SXin Li // Convert a pair of y/u/v lines together to the output rgb/a colorspace. 268*b2055c35SXin Li // bottom_y can be NULL if only one line of output is needed (at top/bottom). 269*b2055c35SXin Li typedef void (*WebPUpsampleLinePairFunc)( 270*b2055c35SXin Li const uint8_t* top_y, const uint8_t* bottom_y, 271*b2055c35SXin Li const uint8_t* top_u, const uint8_t* top_v, 272*b2055c35SXin Li const uint8_t* cur_u, const uint8_t* cur_v, 273*b2055c35SXin Li uint8_t* top_dst, uint8_t* bottom_dst, int len); 274*b2055c35SXin Li 275*b2055c35SXin Li #ifdef FANCY_UPSAMPLING 276*b2055c35SXin Li 277*b2055c35SXin Li // Fancy upsampling functions to convert YUV to RGB(A) modes 278*b2055c35SXin Li extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; 279*b2055c35SXin Li 280*b2055c35SXin Li #endif // FANCY_UPSAMPLING 281*b2055c35SXin Li 282*b2055c35SXin Li // Per-row point-sampling methods. 283*b2055c35SXin Li typedef void (*WebPSamplerRowFunc)(const uint8_t* y, 284*b2055c35SXin Li const uint8_t* u, const uint8_t* v, 285*b2055c35SXin Li uint8_t* dst, int len); 286*b2055c35SXin Li // Generic function to apply 'WebPSamplerRowFunc' to the whole plane: 287*b2055c35SXin Li void WebPSamplerProcessPlane(const uint8_t* y, int y_stride, 288*b2055c35SXin Li const uint8_t* u, const uint8_t* v, int uv_stride, 289*b2055c35SXin Li uint8_t* dst, int dst_stride, 290*b2055c35SXin Li int width, int height, WebPSamplerRowFunc func); 291*b2055c35SXin Li 292*b2055c35SXin Li // Sampling functions to convert rows of YUV to RGB(A) 293*b2055c35SXin Li extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */]; 294*b2055c35SXin Li 295*b2055c35SXin Li // General function for converting two lines of ARGB or RGBA. 296*b2055c35SXin Li // 'alpha_is_last' should be true if 0xff000000 is stored in memory as 297*b2055c35SXin Li // as 0x00, 0x00, 0x00, 0xff (little endian). 298*b2055c35SXin Li WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last); 299*b2055c35SXin Li 300*b2055c35SXin Li // YUV444->RGB converters 301*b2055c35SXin Li typedef void (*WebPYUV444Converter)(const uint8_t* y, 302*b2055c35SXin Li const uint8_t* u, const uint8_t* v, 303*b2055c35SXin Li uint8_t* dst, int len); 304*b2055c35SXin Li 305*b2055c35SXin Li extern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */]; 306*b2055c35SXin Li 307*b2055c35SXin Li // Must be called before using the WebPUpsamplers[] (and for premultiplied 308*b2055c35SXin Li // colorspaces like rgbA, rgbA4444, etc) 309*b2055c35SXin Li void WebPInitUpsamplers(void); 310*b2055c35SXin Li // Must be called before using WebPSamplers[] 311*b2055c35SXin Li void WebPInitSamplers(void); 312*b2055c35SXin Li // Must be called before using WebPYUV444Converters[] 313*b2055c35SXin Li void WebPInitYUV444Converters(void); 314*b2055c35SXin Li 315*b2055c35SXin Li //------------------------------------------------------------------------------ 316*b2055c35SXin Li // ARGB -> YUV converters 317*b2055c35SXin Li 318*b2055c35SXin Li // Convert ARGB samples to luma Y. 319*b2055c35SXin Li extern void (*WebPConvertARGBToY)(const uint32_t* argb, uint8_t* y, int width); 320*b2055c35SXin Li // Convert ARGB samples to U/V with downsampling. do_store should be '1' for 321*b2055c35SXin Li // even lines and '0' for odd ones. 'src_width' is the original width, not 322*b2055c35SXin Li // the U/V one. 323*b2055c35SXin Li extern void (*WebPConvertARGBToUV)(const uint32_t* argb, uint8_t* u, uint8_t* v, 324*b2055c35SXin Li int src_width, int do_store); 325*b2055c35SXin Li 326*b2055c35SXin Li // Convert a row of accumulated (four-values) of rgba32 toward U/V 327*b2055c35SXin Li extern void (*WebPConvertRGBA32ToUV)(const uint16_t* rgb, 328*b2055c35SXin Li uint8_t* u, uint8_t* v, int width); 329*b2055c35SXin Li 330*b2055c35SXin Li // Convert RGB or BGR to Y 331*b2055c35SXin Li extern void (*WebPConvertRGB24ToY)(const uint8_t* rgb, uint8_t* y, int width); 332*b2055c35SXin Li extern void (*WebPConvertBGR24ToY)(const uint8_t* bgr, uint8_t* y, int width); 333*b2055c35SXin Li 334*b2055c35SXin Li // used for plain-C fallback. 335*b2055c35SXin Li extern void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v, 336*b2055c35SXin Li int src_width, int do_store); 337*b2055c35SXin Li extern void WebPConvertRGBA32ToUV_C(const uint16_t* rgb, 338*b2055c35SXin Li uint8_t* u, uint8_t* v, int width); 339*b2055c35SXin Li 340*b2055c35SXin Li // Must be called before using the above. 341*b2055c35SXin Li void WebPInitConvertARGBToYUV(void); 342*b2055c35SXin Li 343*b2055c35SXin Li //------------------------------------------------------------------------------ 344*b2055c35SXin Li // Rescaler 345*b2055c35SXin Li 346*b2055c35SXin Li struct WebPRescaler; 347*b2055c35SXin Li 348*b2055c35SXin Li // Import a row of data and save its contribution in the rescaler. 349*b2055c35SXin Li // 'channel' denotes the channel number to be imported. 'Expand' corresponds to 350*b2055c35SXin Li // the wrk->x_expand case. Otherwise, 'Shrink' is to be used. 351*b2055c35SXin Li typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk, 352*b2055c35SXin Li const uint8_t* src); 353*b2055c35SXin Li 354*b2055c35SXin Li extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand; 355*b2055c35SXin Li extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink; 356*b2055c35SXin Li 357*b2055c35SXin Li // Export one row (starting at x_out position) from rescaler. 358*b2055c35SXin Li // 'Expand' corresponds to the wrk->y_expand case. 359*b2055c35SXin Li // Otherwise 'Shrink' is to be used 360*b2055c35SXin Li typedef void (*WebPRescalerExportRowFunc)(struct WebPRescaler* const wrk); 361*b2055c35SXin Li extern WebPRescalerExportRowFunc WebPRescalerExportRowExpand; 362*b2055c35SXin Li extern WebPRescalerExportRowFunc WebPRescalerExportRowShrink; 363*b2055c35SXin Li 364*b2055c35SXin Li // Plain-C implementation, as fall-back. 365*b2055c35SXin Li extern void WebPRescalerImportRowExpand_C(struct WebPRescaler* const wrk, 366*b2055c35SXin Li const uint8_t* src); 367*b2055c35SXin Li extern void WebPRescalerImportRowShrink_C(struct WebPRescaler* const wrk, 368*b2055c35SXin Li const uint8_t* src); 369*b2055c35SXin Li extern void WebPRescalerExportRowExpand_C(struct WebPRescaler* const wrk); 370*b2055c35SXin Li extern void WebPRescalerExportRowShrink_C(struct WebPRescaler* const wrk); 371*b2055c35SXin Li 372*b2055c35SXin Li // Main entry calls: 373*b2055c35SXin Li extern void WebPRescalerImportRow(struct WebPRescaler* const wrk, 374*b2055c35SXin Li const uint8_t* src); 375*b2055c35SXin Li // Export one row (starting at x_out position) from rescaler. 376*b2055c35SXin Li extern void WebPRescalerExportRow(struct WebPRescaler* const wrk); 377*b2055c35SXin Li 378*b2055c35SXin Li // Must be called first before using the above. 379*b2055c35SXin Li void WebPRescalerDspInit(void); 380*b2055c35SXin Li 381*b2055c35SXin Li //------------------------------------------------------------------------------ 382*b2055c35SXin Li // Utilities for processing transparent channel. 383*b2055c35SXin Li 384*b2055c35SXin Li // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h. 385*b2055c35SXin Li // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last). 386*b2055c35SXin Li extern void (*WebPApplyAlphaMultiply)( 387*b2055c35SXin Li uint8_t* rgba, int alpha_first, int w, int h, int stride); 388*b2055c35SXin Li 389*b2055c35SXin Li // Same, buf specifically for RGBA4444 format 390*b2055c35SXin Li extern void (*WebPApplyAlphaMultiply4444)( 391*b2055c35SXin Li uint8_t* rgba4444, int w, int h, int stride); 392*b2055c35SXin Li 393*b2055c35SXin Li // Dispatch the values from alpha[] plane to the ARGB destination 'dst'. 394*b2055c35SXin Li // Returns true if alpha[] plane has non-trivial values different from 0xff. 395*b2055c35SXin Li extern int (*WebPDispatchAlpha)(const uint8_t* WEBP_RESTRICT alpha, 396*b2055c35SXin Li int alpha_stride, int width, int height, 397*b2055c35SXin Li uint8_t* WEBP_RESTRICT dst, int dst_stride); 398*b2055c35SXin Li 399*b2055c35SXin Li // Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the 400*b2055c35SXin Li // A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units. 401*b2055c35SXin Li extern void (*WebPDispatchAlphaToGreen)(const uint8_t* WEBP_RESTRICT alpha, 402*b2055c35SXin Li int alpha_stride, int width, int height, 403*b2055c35SXin Li uint32_t* WEBP_RESTRICT dst, 404*b2055c35SXin Li int dst_stride); 405*b2055c35SXin Li 406*b2055c35SXin Li // Extract the alpha values from 32b values in argb[] and pack them into alpha[] 407*b2055c35SXin Li // (this is the opposite of WebPDispatchAlpha). 408*b2055c35SXin Li // Returns true if there's only trivial 0xff alpha values. 409*b2055c35SXin Li extern int (*WebPExtractAlpha)(const uint8_t* WEBP_RESTRICT argb, 410*b2055c35SXin Li int argb_stride, int width, int height, 411*b2055c35SXin Li uint8_t* WEBP_RESTRICT alpha, 412*b2055c35SXin Li int alpha_stride); 413*b2055c35SXin Li 414*b2055c35SXin Li // Extract the green values from 32b values in argb[] and pack them into alpha[] 415*b2055c35SXin Li // (this is the opposite of WebPDispatchAlphaToGreen). 416*b2055c35SXin Li extern void (*WebPExtractGreen)(const uint32_t* WEBP_RESTRICT argb, 417*b2055c35SXin Li uint8_t* WEBP_RESTRICT alpha, int size); 418*b2055c35SXin Li 419*b2055c35SXin Li // Pre-Multiply operation transforms x into x * A / 255 (where x=Y,R,G or B). 420*b2055c35SXin Li // Un-Multiply operation transforms x into x * 255 / A. 421*b2055c35SXin Li 422*b2055c35SXin Li // Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row. 423*b2055c35SXin Li extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse); 424*b2055c35SXin Li 425*b2055c35SXin Li // Same a WebPMultARGBRow(), but for several rows. 426*b2055c35SXin Li void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows, 427*b2055c35SXin Li int inverse); 428*b2055c35SXin Li 429*b2055c35SXin Li // Same for a row of single values, with side alpha values. 430*b2055c35SXin Li extern void (*WebPMultRow)(uint8_t* WEBP_RESTRICT const ptr, 431*b2055c35SXin Li const uint8_t* WEBP_RESTRICT const alpha, 432*b2055c35SXin Li int width, int inverse); 433*b2055c35SXin Li 434*b2055c35SXin Li // Same a WebPMultRow(), but for several 'num_rows' rows. 435*b2055c35SXin Li void WebPMultRows(uint8_t* WEBP_RESTRICT ptr, int stride, 436*b2055c35SXin Li const uint8_t* WEBP_RESTRICT alpha, int alpha_stride, 437*b2055c35SXin Li int width, int num_rows, int inverse); 438*b2055c35SXin Li 439*b2055c35SXin Li // Plain-C versions, used as fallback by some implementations. 440*b2055c35SXin Li void WebPMultRow_C(uint8_t* WEBP_RESTRICT const ptr, 441*b2055c35SXin Li const uint8_t* WEBP_RESTRICT const alpha, 442*b2055c35SXin Li int width, int inverse); 443*b2055c35SXin Li void WebPMultARGBRow_C(uint32_t* const ptr, int width, int inverse); 444*b2055c35SXin Li 445*b2055c35SXin Li #ifdef WORDS_BIGENDIAN 446*b2055c35SXin Li // ARGB packing function: a/r/g/b input is rgba or bgra order. 447*b2055c35SXin Li extern void (*WebPPackARGB)(const uint8_t* WEBP_RESTRICT a, 448*b2055c35SXin Li const uint8_t* WEBP_RESTRICT r, 449*b2055c35SXin Li const uint8_t* WEBP_RESTRICT g, 450*b2055c35SXin Li const uint8_t* WEBP_RESTRICT b, 451*b2055c35SXin Li int len, uint32_t* WEBP_RESTRICT out); 452*b2055c35SXin Li #endif 453*b2055c35SXin Li 454*b2055c35SXin Li // RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order. 455*b2055c35SXin Li extern void (*WebPPackRGB)(const uint8_t* WEBP_RESTRICT r, 456*b2055c35SXin Li const uint8_t* WEBP_RESTRICT g, 457*b2055c35SXin Li const uint8_t* WEBP_RESTRICT b, 458*b2055c35SXin Li int len, int step, uint32_t* WEBP_RESTRICT out); 459*b2055c35SXin Li 460*b2055c35SXin Li // This function returns true if src[i] contains a value different from 0xff. 461*b2055c35SXin Li extern int (*WebPHasAlpha8b)(const uint8_t* src, int length); 462*b2055c35SXin Li // This function returns true if src[4*i] contains a value different from 0xff. 463*b2055c35SXin Li extern int (*WebPHasAlpha32b)(const uint8_t* src, int length); 464*b2055c35SXin Li // replaces transparent values in src[] by 'color'. 465*b2055c35SXin Li extern void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color); 466*b2055c35SXin Li 467*b2055c35SXin Li // To be called first before using the above. 468*b2055c35SXin Li void WebPInitAlphaProcessing(void); 469*b2055c35SXin Li 470*b2055c35SXin Li //------------------------------------------------------------------------------ 471*b2055c35SXin Li // Filter functions 472*b2055c35SXin Li 473*b2055c35SXin Li typedef enum { // Filter types. 474*b2055c35SXin Li WEBP_FILTER_NONE = 0, 475*b2055c35SXin Li WEBP_FILTER_HORIZONTAL, 476*b2055c35SXin Li WEBP_FILTER_VERTICAL, 477*b2055c35SXin Li WEBP_FILTER_GRADIENT, 478*b2055c35SXin Li WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1, // end marker 479*b2055c35SXin Li WEBP_FILTER_BEST, // meta-types 480*b2055c35SXin Li WEBP_FILTER_FAST 481*b2055c35SXin Li } WEBP_FILTER_TYPE; 482*b2055c35SXin Li 483*b2055c35SXin Li typedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height, 484*b2055c35SXin Li int stride, uint8_t* out); 485*b2055c35SXin Li // In-place un-filtering. 486*b2055c35SXin Li // Warning! 'prev_line' pointer can be equal to 'cur_line' or 'preds'. 487*b2055c35SXin Li typedef void (*WebPUnfilterFunc)(const uint8_t* prev_line, const uint8_t* preds, 488*b2055c35SXin Li uint8_t* cur_line, int width); 489*b2055c35SXin Li 490*b2055c35SXin Li // Filter the given data using the given predictor. 491*b2055c35SXin Li // 'in' corresponds to a 2-dimensional pixel array of size (stride * height) 492*b2055c35SXin Li // in raster order. 493*b2055c35SXin Li // 'stride' is number of bytes per scan line (with possible padding). 494*b2055c35SXin Li // 'out' should be pre-allocated. 495*b2055c35SXin Li extern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; 496*b2055c35SXin Li 497*b2055c35SXin Li // In-place reconstruct the original data from the given filtered data. 498*b2055c35SXin Li // The reconstruction will be done for 'num_rows' rows starting from 'row' 499*b2055c35SXin Li // (assuming rows upto 'row - 1' are already reconstructed). 500*b2055c35SXin Li extern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; 501*b2055c35SXin Li 502*b2055c35SXin Li // To be called first before using the above. 503*b2055c35SXin Li void VP8FiltersInit(void); 504*b2055c35SXin Li 505*b2055c35SXin Li #ifdef __cplusplus 506*b2055c35SXin Li } // extern "C" 507*b2055c35SXin Li #endif 508*b2055c35SXin Li 509*b2055c35SXin Li #endif // WEBP_DSP_DSP_H_ 510