dsp.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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 ([email protected])
  13. #ifndef WEBP_DSP_DSP_H_
  14. #define WEBP_DSP_DSP_H_
  15. #ifdef HAVE_CONFIG_H
  16. #include "../webp/config.h"
  17. #endif
  18. #include "../webp/types.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define BPS 32 // this is the common stride for enc/dec
  23. //------------------------------------------------------------------------------
  24. // CPU detection
  25. #if defined(__GNUC__)
  26. # define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
  27. # define LOCAL_GCC_PREREQ(maj, min) \
  28. (LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
  29. #else
  30. # define LOCAL_GCC_VERSION 0
  31. # define LOCAL_GCC_PREREQ(maj, min) 0
  32. #endif
  33. #ifndef __has_builtin
  34. # define __has_builtin(x) 0
  35. #endif
  36. #if defined(_MSC_VER) && _MSC_VER > 1310 && \
  37. (defined(_M_X64) || defined(_M_IX86))
  38. #define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
  39. #endif
  40. #if defined(_MSC_VER) && _MSC_VER >= 1500 && \
  41. (defined(_M_X64) || defined(_M_IX86))
  42. #define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets
  43. #endif
  44. // WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp
  45. // files without intrinsics, allowing the corresponding Init() to be called.
  46. // Files containing intrinsics will need to be built targeting the instruction
  47. // set so should succeed on one of the earlier tests.
  48. #if defined(__SSE2__) || defined(WEBP_MSC_SSE2) || defined(WEBP_HAVE_SSE2)
  49. #define WEBP_USE_SSE2
  50. #endif
  51. #if defined(__SSE4_1__) || defined(WEBP_MSC_SSE41) || defined(WEBP_HAVE_SSE41)
  52. #define WEBP_USE_SSE41
  53. #endif
  54. #if defined(__AVX2__) || defined(WEBP_HAVE_AVX2)
  55. #define WEBP_USE_AVX2
  56. #endif
  57. #if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
  58. #define WEBP_ANDROID_NEON // Android targets that might support NEON
  59. #endif
  60. // The intrinsics currently cause compiler errors with arm-nacl-gcc and the
  61. // inline assembly would need to be modified for use with Native Client.
  62. #if (defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON) || \
  63. defined(__aarch64__) || defined(WEBP_HAVE_NEON)) && \
  64. !defined(__native_client__)
  65. #define WEBP_USE_NEON
  66. #endif
  67. #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM)
  68. #define WEBP_USE_NEON
  69. #define WEBP_USE_INTRINSICS
  70. #endif
  71. #if defined(__mips__) && !defined(__mips64) && \
  72. defined(__mips_isa_rev) && (__mips_isa_rev >= 1) && (__mips_isa_rev < 6)
  73. #define WEBP_USE_MIPS32
  74. #if (__mips_isa_rev >= 2)
  75. #define WEBP_USE_MIPS32_R2
  76. #if defined(__mips_dspr2) || (__mips_dsp_rev >= 2)
  77. #define WEBP_USE_MIPS_DSP_R2
  78. #endif
  79. #endif
  80. #endif
  81. #if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5)
  82. #define WEBP_USE_MSA
  83. #endif
  84. // This macro prevents thread_sanitizer from reporting known concurrent writes.
  85. #define WEBP_TSAN_IGNORE_FUNCTION
  86. #if defined(__has_feature)
  87. #if __has_feature(thread_sanitizer)
  88. #undef WEBP_TSAN_IGNORE_FUNCTION
  89. #define WEBP_TSAN_IGNORE_FUNCTION __attribute__((no_sanitize_thread))
  90. #endif
  91. #endif
  92. #define WEBP_UBSAN_IGNORE_UNDEF
  93. #define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW
  94. #if !defined(WEBP_FORCE_ALIGNED) && defined(__clang__) && \
  95. defined(__has_attribute)
  96. #if __has_attribute(no_sanitize)
  97. // This macro prevents the undefined behavior sanitizer from reporting
  98. // failures. This is only meant to silence unaligned loads on platforms that
  99. // are known to support them.
  100. #undef WEBP_UBSAN_IGNORE_UNDEF
  101. #define WEBP_UBSAN_IGNORE_UNDEF \
  102. __attribute__((no_sanitize("undefined")))
  103. // This macro prevents the undefined behavior sanitizer from reporting
  104. // failures related to unsigned integer overflows. This is only meant to
  105. // silence cases where this well defined behavior is expected.
  106. #undef WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW
  107. #define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW \
  108. __attribute__((no_sanitize("unsigned-integer-overflow")))
  109. #endif
  110. #endif
  111. typedef enum {
  112. kSSE2,
  113. kSSE3,
  114. kSSE4_1,
  115. kAVX,
  116. kAVX2,
  117. kNEON,
  118. kMIPS32,
  119. kMIPSdspR2,
  120. kMSA
  121. } CPUFeature;
  122. // returns true if the CPU supports the feature.
  123. typedef int (*VP8CPUInfo)(CPUFeature feature);
  124. WEBP_EXTERN(VP8CPUInfo) VP8GetCPUInfo;
  125. //------------------------------------------------------------------------------
  126. // Init stub generator
  127. // Defines an init function stub to ensure each module exposes a symbol,
  128. // avoiding a compiler warning.
  129. #define WEBP_DSP_INIT_STUB(func) \
  130. extern void func(void); \
  131. WEBP_TSAN_IGNORE_FUNCTION void func(void) {}
  132. //------------------------------------------------------------------------------
  133. // Encoding
  134. // Transforms
  135. // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
  136. // will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
  137. typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
  138. int do_two);
  139. typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
  140. typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
  141. extern VP8Idct VP8ITransform;
  142. extern VP8Fdct VP8FTransform;
  143. extern VP8Fdct VP8FTransform2; // performs two transforms at a time
  144. extern VP8WHT VP8FTransformWHT;
  145. // Predictions
  146. // *dst is the destination block. *top and *left can be NULL.
  147. typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
  148. const uint8_t* top);
  149. typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
  150. extern VP8Intra4Preds VP8EncPredLuma4;
  151. extern VP8IntraPreds VP8EncPredLuma16;
  152. extern VP8IntraPreds VP8EncPredChroma8;
  153. typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
  154. extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
  155. typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
  156. const uint16_t* const weights);
  157. // The weights for VP8TDisto4x4 and VP8TDisto16x16 contain a row-major
  158. // 4 by 4 symmetric matrix.
  159. extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
  160. typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
  161. extern VP8BlockCopy VP8Copy4x4;
  162. extern VP8BlockCopy VP8Copy16x8;
  163. // Quantization
  164. struct VP8Matrix; // forward declaration
  165. typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
  166. const struct VP8Matrix* const mtx);
  167. // Same as VP8QuantizeBlock, but quantizes two consecutive blocks.
  168. typedef int (*VP8Quantize2Blocks)(int16_t in[32], int16_t out[32],
  169. const struct VP8Matrix* const mtx);
  170. extern VP8QuantizeBlock VP8EncQuantizeBlock;
  171. extern VP8Quantize2Blocks VP8EncQuantize2Blocks;
  172. // specific to 2nd transform:
  173. typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
  174. const struct VP8Matrix* const mtx);
  175. extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
  176. extern const int VP8DspScan[16 + 4 + 4];
  177. // Collect histogram for susceptibility calculation.
  178. #define MAX_COEFF_THRESH 31 // size of histogram used by CollectHistogram.
  179. typedef struct {
  180. // We only need to store max_value and last_non_zero, not the distribution.
  181. int max_value;
  182. int last_non_zero;
  183. } VP8Histogram;
  184. typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
  185. int start_block, int end_block,
  186. VP8Histogram* const histo);
  187. extern VP8CHisto VP8CollectHistogram;
  188. // General-purpose util function to help VP8CollectHistogram().
  189. void VP8SetHistogramData(const int distribution[MAX_COEFF_THRESH + 1],
  190. VP8Histogram* const histo);
  191. // must be called before using any of the above
  192. void VP8EncDspInit(void);
  193. //------------------------------------------------------------------------------
  194. // cost functions (encoding)
  195. extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p)
  196. // approximate cost per level:
  197. extern const uint16_t VP8LevelFixedCosts[2047 /*MAX_LEVEL*/ + 1];
  198. extern const uint8_t VP8EncBands[16 + 1];
  199. struct VP8Residual;
  200. typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs,
  201. struct VP8Residual* const res);
  202. extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs;
  203. // Cost calculation function.
  204. typedef int (*VP8GetResidualCostFunc)(int ctx0,
  205. const struct VP8Residual* const res);
  206. extern VP8GetResidualCostFunc VP8GetResidualCost;
  207. // must be called before anything using the above
  208. void VP8EncDspCostInit(void);
  209. //------------------------------------------------------------------------------
  210. // SSIM utils
  211. // struct for accumulating statistical moments
  212. typedef struct {
  213. double w; // sum(w_i) : sum of weights
  214. double xm, ym; // sum(w_i * x_i), sum(w_i * y_i)
  215. double xxm, xym, yym; // sum(w_i * x_i * x_i), etc.
  216. } VP8DistoStats;
  217. #define VP8_SSIM_KERNEL 3 // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1
  218. typedef void (*VP8SSIMAccumulateClippedFunc)(const uint8_t* src1, int stride1,
  219. const uint8_t* src2, int stride2,
  220. int xo, int yo, // center position
  221. int W, int H, // plane dimension
  222. VP8DistoStats* const stats);
  223. // This version is called with the guarantee that you can load 8 bytes and
  224. // 8 rows at offset src1 and src2
  225. typedef void (*VP8SSIMAccumulateFunc)(const uint8_t* src1, int stride1,
  226. const uint8_t* src2, int stride2,
  227. VP8DistoStats* const stats);
  228. extern VP8SSIMAccumulateFunc VP8SSIMAccumulate; // unclipped / unchecked
  229. extern VP8SSIMAccumulateClippedFunc VP8SSIMAccumulateClipped; // with clipping
  230. // must be called before using any of the above directly
  231. void VP8SSIMDspInit(void);
  232. //------------------------------------------------------------------------------
  233. // Decoding
  234. typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
  235. // when doing two transforms, coeffs is actually int16_t[2][16].
  236. typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
  237. extern VP8DecIdct2 VP8Transform;
  238. extern VP8DecIdct VP8TransformAC3;
  239. extern VP8DecIdct VP8TransformUV;
  240. extern VP8DecIdct VP8TransformDC;
  241. extern VP8DecIdct VP8TransformDCUV;
  242. extern VP8WHT VP8TransformWHT;
  243. // *dst is the destination block, with stride BPS. Boundary samples are
  244. // assumed accessible when needed.
  245. typedef void (*VP8PredFunc)(uint8_t* dst);
  246. extern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
  247. extern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
  248. extern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
  249. // clipping tables (for filtering)
  250. extern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127]
  251. extern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15]
  252. extern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255]
  253. extern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255]
  254. // must be called first
  255. void VP8InitClipTables(void);
  256. // simple filter (only for luma)
  257. typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
  258. extern VP8SimpleFilterFunc VP8SimpleVFilter16;
  259. extern VP8SimpleFilterFunc VP8SimpleHFilter16;
  260. extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges
  261. extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
  262. // regular filter (on both macroblock edges and inner edges)
  263. typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
  264. int thresh, int ithresh, int hev_t);
  265. typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
  266. int thresh, int ithresh, int hev_t);
  267. // on outer edge
  268. extern VP8LumaFilterFunc VP8VFilter16;
  269. extern VP8LumaFilterFunc VP8HFilter16;
  270. extern VP8ChromaFilterFunc VP8VFilter8;
  271. extern VP8ChromaFilterFunc VP8HFilter8;
  272. // on inner edge
  273. extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether
  274. extern VP8LumaFilterFunc VP8HFilter16i;
  275. extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether
  276. extern VP8ChromaFilterFunc VP8HFilter8i;
  277. // Dithering. Combines dithering values (centered around 128) with dst[],
  278. // according to: dst[] = clip(dst[] + (((dither[]-128) + 8) >> 4)
  279. #define VP8_DITHER_DESCALE 4
  280. #define VP8_DITHER_DESCALE_ROUNDER (1 << (VP8_DITHER_DESCALE - 1))
  281. #define VP8_DITHER_AMP_BITS 7
  282. #define VP8_DITHER_AMP_CENTER (1 << VP8_DITHER_AMP_BITS)
  283. extern void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst,
  284. int dst_stride);
  285. // must be called before anything using the above
  286. void VP8DspInit(void);
  287. //------------------------------------------------------------------------------
  288. // WebP I/O
  289. #define FANCY_UPSAMPLING // undefined to remove fancy upsampling support
  290. // Convert a pair of y/u/v lines together to the output rgb/a colorspace.
  291. // bottom_y can be NULL if only one line of output is needed (at top/bottom).
  292. typedef void (*WebPUpsampleLinePairFunc)(
  293. const uint8_t* top_y, const uint8_t* bottom_y,
  294. const uint8_t* top_u, const uint8_t* top_v,
  295. const uint8_t* cur_u, const uint8_t* cur_v,
  296. uint8_t* top_dst, uint8_t* bottom_dst, int len);
  297. #ifdef FANCY_UPSAMPLING
  298. // Fancy upsampling functions to convert YUV to RGB(A) modes
  299. extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
  300. #endif // FANCY_UPSAMPLING
  301. // Per-row point-sampling methods.
  302. typedef void (*WebPSamplerRowFunc)(const uint8_t* y,
  303. const uint8_t* u, const uint8_t* v,
  304. uint8_t* dst, int len);
  305. // Generic function to apply 'WebPSamplerRowFunc' to the whole plane:
  306. void WebPSamplerProcessPlane(const uint8_t* y, int y_stride,
  307. const uint8_t* u, const uint8_t* v, int uv_stride,
  308. uint8_t* dst, int dst_stride,
  309. int width, int height, WebPSamplerRowFunc func);
  310. // Sampling functions to convert rows of YUV to RGB(A)
  311. extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */];
  312. // General function for converting two lines of ARGB or RGBA.
  313. // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
  314. // as 0x00, 0x00, 0x00, 0xff (little endian).
  315. WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
  316. // YUV444->RGB converters
  317. typedef void (*WebPYUV444Converter)(const uint8_t* y,
  318. const uint8_t* u, const uint8_t* v,
  319. uint8_t* dst, int len);
  320. extern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
  321. // Must be called before using the WebPUpsamplers[] (and for premultiplied
  322. // colorspaces like rgbA, rgbA4444, etc)
  323. void WebPInitUpsamplers(void);
  324. // Must be called before using WebPSamplers[]
  325. void WebPInitSamplers(void);
  326. // Must be called before using WebPYUV444Converters[]
  327. void WebPInitYUV444Converters(void);
  328. //------------------------------------------------------------------------------
  329. // ARGB -> YUV converters
  330. // Convert ARGB samples to luma Y.
  331. extern void (*WebPConvertARGBToY)(const uint32_t* argb, uint8_t* y, int width);
  332. // Convert ARGB samples to U/V with downsampling. do_store should be '1' for
  333. // even lines and '0' for odd ones. 'src_width' is the original width, not
  334. // the U/V one.
  335. extern void (*WebPConvertARGBToUV)(const uint32_t* argb, uint8_t* u, uint8_t* v,
  336. int src_width, int do_store);
  337. // Convert a row of accumulated (four-values) of rgba32 toward U/V
  338. extern void (*WebPConvertRGBA32ToUV)(const uint16_t* rgb,
  339. uint8_t* u, uint8_t* v, int width);
  340. // Convert RGB or BGR to Y
  341. extern void (*WebPConvertRGB24ToY)(const uint8_t* rgb, uint8_t* y, int width);
  342. extern void (*WebPConvertBGR24ToY)(const uint8_t* bgr, uint8_t* y, int width);
  343. // used for plain-C fallback.
  344. extern void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v,
  345. int src_width, int do_store);
  346. extern void WebPConvertRGBA32ToUV_C(const uint16_t* rgb,
  347. uint8_t* u, uint8_t* v, int width);
  348. // Must be called before using the above.
  349. void WebPInitConvertARGBToYUV(void);
  350. //------------------------------------------------------------------------------
  351. // Rescaler
  352. struct WebPRescaler;
  353. // Import a row of data and save its contribution in the rescaler.
  354. // 'channel' denotes the channel number to be imported. 'Expand' corresponds to
  355. // the wrk->x_expand case. Otherwise, 'Shrink' is to be used.
  356. typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk,
  357. const uint8_t* src);
  358. extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand;
  359. extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink;
  360. // Export one row (starting at x_out position) from rescaler.
  361. // 'Expand' corresponds to the wrk->y_expand case.
  362. // Otherwise 'Shrink' is to be used
  363. typedef void (*WebPRescalerExportRowFunc)(struct WebPRescaler* const wrk);
  364. extern WebPRescalerExportRowFunc WebPRescalerExportRowExpand;
  365. extern WebPRescalerExportRowFunc WebPRescalerExportRowShrink;
  366. // Plain-C implementation, as fall-back.
  367. extern void WebPRescalerImportRowExpandC(struct WebPRescaler* const wrk,
  368. const uint8_t* src);
  369. extern void WebPRescalerImportRowShrinkC(struct WebPRescaler* const wrk,
  370. const uint8_t* src);
  371. extern void WebPRescalerExportRowExpandC(struct WebPRescaler* const wrk);
  372. extern void WebPRescalerExportRowShrinkC(struct WebPRescaler* const wrk);
  373. // Main entry calls:
  374. extern void WebPRescalerImportRow(struct WebPRescaler* const wrk,
  375. const uint8_t* src);
  376. // Export one row (starting at x_out position) from rescaler.
  377. extern void WebPRescalerExportRow(struct WebPRescaler* const wrk);
  378. // Must be called first before using the above.
  379. void WebPRescalerDspInit(void);
  380. //------------------------------------------------------------------------------
  381. // Utilities for processing transparent channel.
  382. // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
  383. // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
  384. extern void (*WebPApplyAlphaMultiply)(
  385. uint8_t* rgba, int alpha_first, int w, int h, int stride);
  386. // Same, buf specifically for RGBA4444 format
  387. extern void (*WebPApplyAlphaMultiply4444)(
  388. uint8_t* rgba4444, int w, int h, int stride);
  389. // Dispatch the values from alpha[] plane to the ARGB destination 'dst'.
  390. // Returns true if alpha[] plane has non-trivial values different from 0xff.
  391. extern int (*WebPDispatchAlpha)(const uint8_t* alpha, int alpha_stride,
  392. int width, int height,
  393. uint8_t* dst, int dst_stride);
  394. // Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the
  395. // A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units.
  396. extern void (*WebPDispatchAlphaToGreen)(const uint8_t* alpha, int alpha_stride,
  397. int width, int height,
  398. uint32_t* dst, int dst_stride);
  399. // Extract the alpha values from 32b values in argb[] and pack them into alpha[]
  400. // (this is the opposite of WebPDispatchAlpha).
  401. // Returns true if there's only trivial 0xff alpha values.
  402. extern int (*WebPExtractAlpha)(const uint8_t* argb, int argb_stride,
  403. int width, int height,
  404. uint8_t* alpha, int alpha_stride);
  405. // Pre-Multiply operation transforms x into x * A / 255 (where x=Y,R,G or B).
  406. // Un-Multiply operation transforms x into x * 255 / A.
  407. // Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row.
  408. extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse);
  409. // Same a WebPMultARGBRow(), but for several rows.
  410. void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows,
  411. int inverse);
  412. // Same for a row of single values, with side alpha values.
  413. extern void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha,
  414. int width, int inverse);
  415. // Same a WebPMultRow(), but for several 'num_rows' rows.
  416. void WebPMultRows(uint8_t* ptr, int stride,
  417. const uint8_t* alpha, int alpha_stride,
  418. int width, int num_rows, int inverse);
  419. // Plain-C versions, used as fallback by some implementations.
  420. void WebPMultRowC(uint8_t* const ptr, const uint8_t* const alpha,
  421. int width, int inverse);
  422. void WebPMultARGBRowC(uint32_t* const ptr, int width, int inverse);
  423. // To be called first before using the above.
  424. void WebPInitAlphaProcessing(void);
  425. // ARGB packing function: a/r/g/b input is rgba or bgra order.
  426. extern void (*VP8PackARGB)(const uint8_t* a, const uint8_t* r,
  427. const uint8_t* g, const uint8_t* b, int len,
  428. uint32_t* out);
  429. // RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order.
  430. extern void (*VP8PackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
  431. int len, int step, uint32_t* out);
  432. // To be called first before using the above.
  433. void VP8EncDspARGBInit(void);
  434. //------------------------------------------------------------------------------
  435. // Filter functions
  436. typedef enum { // Filter types.
  437. WEBP_FILTER_NONE = 0,
  438. WEBP_FILTER_HORIZONTAL,
  439. WEBP_FILTER_VERTICAL,
  440. WEBP_FILTER_GRADIENT,
  441. WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1, // end marker
  442. WEBP_FILTER_BEST, // meta-types
  443. WEBP_FILTER_FAST
  444. } WEBP_FILTER_TYPE;
  445. typedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height,
  446. int stride, uint8_t* out);
  447. // In-place un-filtering.
  448. // Warning! 'prev_line' pointer can be equal to 'cur_line' or 'preds'.
  449. typedef void (*WebPUnfilterFunc)(const uint8_t* prev_line, const uint8_t* preds,
  450. uint8_t* cur_line, int width);
  451. // Filter the given data using the given predictor.
  452. // 'in' corresponds to a 2-dimensional pixel array of size (stride * height)
  453. // in raster order.
  454. // 'stride' is number of bytes per scan line (with possible padding).
  455. // 'out' should be pre-allocated.
  456. extern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST];
  457. // In-place reconstruct the original data from the given filtered data.
  458. // The reconstruction will be done for 'num_rows' rows starting from 'row'
  459. // (assuming rows upto 'row - 1' are already reconstructed).
  460. extern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST];
  461. // To be called first before using the above.
  462. void VP8FiltersInit(void);
  463. #ifdef __cplusplus
  464. } // extern "C"
  465. #endif
  466. #endif /* WEBP_DSP_DSP_H_ */