2012-01-06 14:49:06 -08:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-09-02 21:30:08 +00:00
|
|
|
//
|
2013-06-06 23:05:58 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2011-09-02 21:30:08 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Speed-critical functions.
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
|
|
|
#ifndef WEBP_DSP_DSP_H_
|
|
|
|
#define WEBP_DSP_DSP_H_
|
|
|
|
|
|
|
|
#include "../webp/types.h"
|
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2011-09-02 21:30:08 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// CPU detection
|
|
|
|
|
2014-04-24 20:38:28 -07:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
# define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
|
|
|
|
# define LOCAL_GCC_PREREQ(maj, min) \
|
|
|
|
(LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
|
|
|
|
#else
|
|
|
|
# define LOCAL_GCC_PREREQ(maj, min) 0
|
|
|
|
#endif
|
|
|
|
|
2013-08-16 20:42:50 -07:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER > 1310 && \
|
|
|
|
(defined(_M_X64) || defined(_M_IX86))
|
2011-12-15 17:03:57 -08:00
|
|
|
#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__SSE2__) || defined(WEBP_MSC_SSE2)
|
|
|
|
#define WEBP_USE_SSE2
|
|
|
|
#endif
|
|
|
|
|
2012-05-08 13:22:24 -07:00
|
|
|
#if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
|
|
|
|
#define WEBP_ANDROID_NEON // Android targets that might support NEON
|
|
|
|
#endif
|
|
|
|
|
2014-05-13 23:37:01 -07:00
|
|
|
#if defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON) || defined(__aarch64__)
|
2012-05-08 13:22:24 -07:00
|
|
|
#define WEBP_USE_NEON
|
|
|
|
#endif
|
|
|
|
|
2013-12-25 12:16:01 +01:00
|
|
|
#if defined(__mips__)
|
|
|
|
#define WEBP_USE_MIPS32
|
|
|
|
#endif
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
typedef enum {
|
|
|
|
kSSE2,
|
2011-09-12 13:03:01 +00:00
|
|
|
kSSE3,
|
2014-05-16 18:43:11 -07:00
|
|
|
kAVX,
|
2014-05-16 18:43:11 -07:00
|
|
|
kAVX2,
|
2013-12-25 12:16:01 +01:00
|
|
|
kNEON,
|
|
|
|
kMIPS32
|
2011-09-02 21:30:08 +00:00
|
|
|
} CPUFeature;
|
|
|
|
// returns true if the CPU supports the feature.
|
|
|
|
typedef int (*VP8CPUInfo)(CPUFeature feature);
|
|
|
|
extern VP8CPUInfo VP8GetCPUInfo;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Encoding
|
|
|
|
|
|
|
|
// Transforms
|
|
|
|
// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
|
|
|
|
// will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
|
|
|
|
typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
|
|
|
|
int do_two);
|
|
|
|
typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
|
|
|
|
typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
|
|
|
|
extern VP8Idct VP8ITransform;
|
|
|
|
extern VP8Fdct VP8FTransform;
|
|
|
|
extern VP8WHT VP8FTransformWHT;
|
|
|
|
// Predictions
|
|
|
|
// *dst is the destination block. *top and *left can be NULL.
|
|
|
|
typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
|
|
|
|
const uint8_t* top);
|
|
|
|
typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
|
|
|
|
extern VP8Intra4Preds VP8EncPredLuma4;
|
|
|
|
extern VP8IntraPreds VP8EncPredLuma16;
|
|
|
|
extern VP8IntraPreds VP8EncPredChroma8;
|
|
|
|
|
|
|
|
typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
|
|
|
|
extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
|
|
|
|
typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
|
|
|
|
const uint16_t* const weights);
|
|
|
|
extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
|
|
|
|
|
|
|
|
typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
|
|
|
|
extern VP8BlockCopy VP8Copy4x4;
|
|
|
|
// Quantization
|
|
|
|
struct VP8Matrix; // forward declaration
|
|
|
|
typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
|
2014-04-07 18:02:25 +02:00
|
|
|
const struct VP8Matrix* const mtx);
|
2011-09-02 21:30:08 +00:00
|
|
|
extern VP8QuantizeBlock VP8EncQuantizeBlock;
|
|
|
|
|
2013-12-10 14:21:47 +01:00
|
|
|
// specific to 2nd transform:
|
|
|
|
typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
|
|
|
|
const struct VP8Matrix* const mtx);
|
|
|
|
extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
|
|
|
|
|
2012-09-03 19:40:52 +02:00
|
|
|
// Collect histogram for susceptibility calculation and accumulate in histo[].
|
|
|
|
struct VP8Histogram;
|
|
|
|
typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
|
|
|
|
int start_block, int end_block,
|
|
|
|
struct VP8Histogram* const histo);
|
2011-09-02 21:30:08 +00:00
|
|
|
extern const int VP8DspScan[16 + 4 + 4];
|
|
|
|
extern VP8CHisto VP8CollectHistogram;
|
|
|
|
|
|
|
|
void VP8EncDspInit(void); // must be called before using any of the above
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Decoding
|
|
|
|
|
|
|
|
typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
|
|
|
|
// when doing two transforms, coeffs is actually int16_t[2][16].
|
|
|
|
typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
|
|
|
|
extern VP8DecIdct2 VP8Transform;
|
2013-10-08 22:05:38 +02:00
|
|
|
extern VP8DecIdct VP8TransformAC3;
|
2011-09-02 21:30:08 +00:00
|
|
|
extern VP8DecIdct VP8TransformUV;
|
|
|
|
extern VP8DecIdct VP8TransformDC;
|
|
|
|
extern VP8DecIdct VP8TransformDCUV;
|
2012-11-01 09:09:23 -07:00
|
|
|
extern VP8WHT VP8TransformWHT;
|
2011-09-02 21:30:08 +00:00
|
|
|
|
|
|
|
// *dst is the destination block, with stride BPS. Boundary samples are
|
|
|
|
// assumed accessible when needed.
|
|
|
|
typedef void (*VP8PredFunc)(uint8_t* dst);
|
2012-01-27 17:39:47 -08:00
|
|
|
extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
|
|
|
|
extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
|
|
|
|
extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
|
2011-09-02 21:30:08 +00:00
|
|
|
|
2014-02-13 19:32:21 -08:00
|
|
|
// clipping tables (for filtering)
|
|
|
|
extern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127]
|
|
|
|
extern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15]
|
|
|
|
extern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255]
|
|
|
|
extern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255]
|
|
|
|
void VP8InitClipTables(void); // must be called first
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
// simple filter (only for luma)
|
|
|
|
typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
|
|
|
|
extern VP8SimpleFilterFunc VP8SimpleVFilter16;
|
|
|
|
extern VP8SimpleFilterFunc VP8SimpleHFilter16;
|
|
|
|
extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges
|
|
|
|
extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
|
|
|
|
|
|
|
|
// regular filter (on both macroblock edges and inner edges)
|
|
|
|
typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
|
|
|
|
int thresh, int ithresh, int hev_t);
|
|
|
|
typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
|
|
|
|
int thresh, int ithresh, int hev_t);
|
|
|
|
// on outer edge
|
|
|
|
extern VP8LumaFilterFunc VP8VFilter16;
|
|
|
|
extern VP8LumaFilterFunc VP8HFilter16;
|
|
|
|
extern VP8ChromaFilterFunc VP8VFilter8;
|
|
|
|
extern VP8ChromaFilterFunc VP8HFilter8;
|
|
|
|
|
|
|
|
// on inner edge
|
|
|
|
extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether
|
|
|
|
extern VP8LumaFilterFunc VP8HFilter16i;
|
|
|
|
extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether
|
|
|
|
extern VP8ChromaFilterFunc VP8HFilter8i;
|
|
|
|
|
|
|
|
// must be called before anything using the above
|
2012-01-27 17:39:47 -08:00
|
|
|
void VP8DspInit(void);
|
2011-09-02 21:30:08 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// WebP I/O
|
|
|
|
|
|
|
|
#define FANCY_UPSAMPLING // undefined to remove fancy upsampling support
|
|
|
|
|
2013-08-19 12:40:25 -07:00
|
|
|
// Convert a pair of y/u/v lines together to the output rgb/a colorspace.
|
|
|
|
// bottom_y can be NULL if only one line of output is needed (at top/bottom).
|
2011-09-02 21:30:08 +00:00
|
|
|
typedef void (*WebPUpsampleLinePairFunc)(
|
|
|
|
const uint8_t* top_y, const uint8_t* bottom_y,
|
|
|
|
const uint8_t* top_u, const uint8_t* top_v,
|
|
|
|
const uint8_t* cur_u, const uint8_t* cur_v,
|
|
|
|
uint8_t* top_dst, uint8_t* bottom_dst, int len);
|
|
|
|
|
2012-06-28 00:34:23 -07:00
|
|
|
#ifdef FANCY_UPSAMPLING
|
2011-09-02 21:30:08 +00:00
|
|
|
|
|
|
|
// Fancy upsampling functions to convert YUV to RGB(A) modes
|
|
|
|
extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
|
|
|
|
|
|
|
|
// Initializes SSE2 version of the fancy upsamplers.
|
|
|
|
void WebPInitUpsamplersSSE2(void);
|
|
|
|
|
2013-01-17 18:06:26 -08:00
|
|
|
// NEON version
|
|
|
|
void WebPInitUpsamplersNEON(void);
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
#endif // FANCY_UPSAMPLING
|
|
|
|
|
|
|
|
// Point-sampling methods.
|
2014-05-20 09:43:02 -07:00
|
|
|
typedef void (*WebPSamplePlaneFunc)(const uint8_t* y, int y_stride,
|
|
|
|
const uint8_t* u, const uint8_t* v,
|
|
|
|
int uv_stride,
|
|
|
|
uint8_t* dst, int dst_stride,
|
|
|
|
int width, int height);
|
|
|
|
|
|
|
|
typedef void (*WebPSamplerRowFunc)(const uint8_t* y,
|
|
|
|
const uint8_t* u, const uint8_t* v,
|
|
|
|
uint8_t* dst, int len);
|
|
|
|
// Generic function to apply 'WebPSamplerRowFunc' to the whole plane:
|
|
|
|
void WebPSamplerProcessPlane(const uint8_t* y, int y_stride,
|
|
|
|
const uint8_t* u, const uint8_t* v, int uv_stride,
|
|
|
|
uint8_t* dst, int dst_stride,
|
|
|
|
int width, int height, WebPSamplerRowFunc func);
|
2011-09-02 21:30:08 +00:00
|
|
|
|
2014-01-25 18:12:09 +01:00
|
|
|
// Sampling functions to convert YUV to RGB(A) modes
|
2014-05-20 09:43:02 -07:00
|
|
|
extern WebPSamplePlaneFunc WebPSamplers[/* MODE_LAST */];
|
2011-09-02 21:30:08 +00:00
|
|
|
|
2013-12-27 14:06:35 +01:00
|
|
|
// Initializes MIPS version of the samplers.
|
|
|
|
void WebPInitSamplersMIPS32(void);
|
|
|
|
|
2012-06-28 00:34:23 -07:00
|
|
|
// General function for converting two lines of ARGB or RGBA.
|
|
|
|
// 'alpha_is_last' should be true if 0xff000000 is stored in memory as
|
|
|
|
// as 0x00, 0x00, 0x00, 0xff (little endian).
|
|
|
|
WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
// YUV444->RGB converters
|
|
|
|
typedef void (*WebPYUV444Converter)(const uint8_t* y,
|
|
|
|
const uint8_t* u, const uint8_t* v,
|
|
|
|
uint8_t* dst, int len);
|
|
|
|
|
|
|
|
extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
|
|
|
|
|
|
|
|
// Main function to be called
|
|
|
|
void WebPInitUpsamplers(void);
|
2014-01-25 18:12:09 +01:00
|
|
|
void WebPInitSamplers(void);
|
2011-09-02 21:30:08 +00:00
|
|
|
|
2012-06-04 07:40:32 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Pre-multiply planes with alpha values
|
|
|
|
|
|
|
|
// Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
|
|
|
|
// alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
|
|
|
|
extern void (*WebPApplyAlphaMultiply)(
|
|
|
|
uint8_t* rgba, int alpha_first, int w, int h, int stride);
|
|
|
|
|
|
|
|
// Same, buf specifically for RGBA4444 format
|
|
|
|
extern void (*WebPApplyAlphaMultiply4444)(
|
|
|
|
uint8_t* rgba4444, int w, int h, int stride);
|
|
|
|
|
|
|
|
// To be called first before using the above.
|
|
|
|
void WebPInitPremultiply(void);
|
|
|
|
|
|
|
|
void WebPInitPremultiplySSE2(void); // should not be called directly.
|
2013-01-17 18:06:26 -08:00
|
|
|
void WebPInitPremultiplyNEON(void);
|
2012-06-04 07:40:32 -07:00
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2011-09-02 21:30:08 +00:00
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2011-09-07 05:31:28 +00:00
|
|
|
#endif /* WEBP_DSP_DSP_H_ */
|