1a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Copyright 2011 Google Inc. All Rights Reserved. 2a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 30406ce1417f76f2034833414dcecc9f56253640cVikas Arora// Use of this source code is governed by a BSD-style license 40406ce1417f76f2034833414dcecc9f56253640cVikas Arora// that can be found in the COPYING file in the root of the source 50406ce1417f76f2034833414dcecc9f56253640cVikas Arora// tree. An additional intellectual property rights grant can be found 60406ce1417f76f2034833414dcecc9f56253640cVikas Arora// in the file PATENTS. All contributing project authors may 70406ce1417f76f2034833414dcecc9f56253640cVikas Arora// be found in the AUTHORS file in the root of the source tree. 8a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// ----------------------------------------------------------------------------- 9a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 10a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Speed-critical functions. 11a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 12a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Author: Skal (pascal.massimino@gmail.com) 13a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 14a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#ifndef WEBP_DSP_DSP_H_ 15a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define WEBP_DSP_DSP_H_ 16a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 170912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#ifdef HAVE_CONFIG_H 18a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#include "src/webp/config.h" 190912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#endif 200912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 21a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#include "src/webp/types.h" 22a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 238b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora#ifdef __cplusplus 24a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern "C" { 25a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 26a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 277c8da7ce66017295a65ec028084b90800be377f8James Zern#define BPS 32 // this is the common stride for enc/dec 287c8da7ce66017295a65ec028084b90800be377f8James Zern 29a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 30a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// CPU detection 31a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 32af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#if defined(__GNUC__) 33af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora# define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__) 34af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora# define LOCAL_GCC_PREREQ(maj, min) \ 35af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora (LOCAL_GCC_VERSION >= (((maj) << 8) | (min))) 36af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#else 378c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora# define LOCAL_GCC_VERSION 0 38af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora# define LOCAL_GCC_PREREQ(maj, min) 0 39af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#endif 40af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 41a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if defined(__clang__) 42a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern# define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__) 43a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern# define LOCAL_CLANG_PREREQ(maj, min) \ 44a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern (LOCAL_CLANG_VERSION >= (((maj) << 8) | (min))) 45a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#else 46a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern# define LOCAL_CLANG_VERSION 0 47a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern# define LOCAL_CLANG_PREREQ(maj, min) 0 48a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 49a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 50e8a1b86cc3afe4791ab40d89240c40797a400131James Zern#ifndef __has_builtin 51e8a1b86cc3afe4791ab40d89240c40797a400131James Zern# define __has_builtin(x) 0 52e8a1b86cc3afe4791ab40d89240c40797a400131James Zern#endif 538c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora 54a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern// for now, none of the optimizations below are available in emscripten 55a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !defined(EMSCRIPTEN) 56a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 578b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora#if defined(_MSC_VER) && _MSC_VER > 1310 && \ 588b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora (defined(_M_X64) || defined(_M_IX86)) 59a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets 60a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 61a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 627c8da7ce66017295a65ec028084b90800be377f8James Zern#if defined(_MSC_VER) && _MSC_VER >= 1500 && \ 637c8da7ce66017295a65ec028084b90800be377f8James Zern (defined(_M_X64) || defined(_M_IX86)) 647c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets 657c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 667c8da7ce66017295a65ec028084b90800be377f8James Zern 67af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp 68af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// files without intrinsics, allowing the corresponding Init() to be called. 69af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Files containing intrinsics will need to be built targeting the instruction 70af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// set so should succeed on one of the earlier tests. 71af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#if defined(__SSE2__) || defined(WEBP_MSC_SSE2) || defined(WEBP_HAVE_SSE2) 72a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define WEBP_USE_SSE2 73a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 74a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 757c8da7ce66017295a65ec028084b90800be377f8James Zern#if defined(__SSE4_1__) || defined(WEBP_MSC_SSE41) || defined(WEBP_HAVE_SSE41) 767c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_USE_SSE41 777c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 787c8da7ce66017295a65ec028084b90800be377f8James Zern 79af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#if defined(__AVX2__) || defined(WEBP_HAVE_AVX2) 80af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#define WEBP_USE_AVX2 81af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#endif 82af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 839e80ee991168a0a6c2a906dd2c17c5e17df4566eJames Zern// The intrinsics currently cause compiler errors with arm-nacl-gcc and the 849e80ee991168a0a6c2a906dd2c17c5e17df4566eJames Zern// inline assembly would need to be modified for use with Native Client. 8598a63a77eb8652c81d64b5b7c3d8a347111807caJames Zern#if (defined(__ARM_NEON__) || \ 8698a63a77eb8652c81d64b5b7c3d8a347111807caJames Zern defined(__aarch64__) || defined(WEBP_HAVE_NEON)) && \ 8798a63a77eb8652c81d64b5b7c3d8a347111807caJames Zern !defined(__native_client__) 88a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define WEBP_USE_NEON 89a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 90a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 91a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !defined(WEBP_USE_NEON) && defined(__ANDROID__) && \ 92a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern defined(__ARM_ARCH_7A__) && defined(HAVE_CPU_FEATURES_H) 93a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_ANDROID_NEON // Android targets that may have NEON 94a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_USE_NEON 95a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 96a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 977c8da7ce66017295a65ec028084b90800be377f8James Zern#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM) 987c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_USE_NEON 997c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_USE_INTRINSICS 1007c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 1017c8da7ce66017295a65ec028084b90800be377f8James Zern 102e8a1b86cc3afe4791ab40d89240c40797a400131James Zern#if defined(__mips__) && !defined(__mips64) && \ 103e8a1b86cc3afe4791ab40d89240c40797a400131James Zern defined(__mips_isa_rev) && (__mips_isa_rev >= 1) && (__mips_isa_rev < 6) 104af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#define WEBP_USE_MIPS32 1058c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora#if (__mips_isa_rev >= 2) 1068c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora#define WEBP_USE_MIPS32_R2 107a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if defined(__mips_dspr2) || (defined(__mips_dsp_rev) && __mips_dsp_rev >= 2) 1087c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_USE_MIPS_DSP_R2 1097c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 1107c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 1117c8da7ce66017295a65ec028084b90800be377f8James Zern#endif 1127c8da7ce66017295a65ec028084b90800be377f8James Zern 1130912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5) 1140912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define WEBP_USE_MSA 1150912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#endif 1160912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 117a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif /* EMSCRIPTEN */ 118a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 119a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#ifndef WEBP_DSP_OMIT_C_CODE 120a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_DSP_OMIT_C_CODE 1 121a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 122a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 123a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if (defined(__aarch64__) || defined(__ARM_NEON__)) && WEBP_DSP_OMIT_C_CODE 124a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_NEON_OMIT_C_CODE 1 125a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#else 126a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_NEON_OMIT_C_CODE 0 127a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 128a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 129a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !(LOCAL_CLANG_PREREQ(3,8) || LOCAL_GCC_PREREQ(4,8) || defined(__aarch64__)) 130a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_NEON_WORK_AROUND_GCC 1 131a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#else 132a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_NEON_WORK_AROUND_GCC 0 133a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 134a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 1357c8da7ce66017295a65ec028084b90800be377f8James Zern// This macro prevents thread_sanitizer from reporting known concurrent writes. 1367c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_TSAN_IGNORE_FUNCTION 1377c8da7ce66017295a65ec028084b90800be377f8James Zern#if defined(__has_feature) 1387c8da7ce66017295a65ec028084b90800be377f8James Zern#if __has_feature(thread_sanitizer) 1397c8da7ce66017295a65ec028084b90800be377f8James Zern#undef WEBP_TSAN_IGNORE_FUNCTION 1407c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_TSAN_IGNORE_FUNCTION __attribute__((no_sanitize_thread)) 1418c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora#endif 142af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora#endif 143af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 1440912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define WEBP_UBSAN_IGNORE_UNDEF 1450912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW 146fa39824bb690c5806358871f46940d0450973d8aJames Zern#if defined(__clang__) && defined(__has_attribute) 1470912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#if __has_attribute(no_sanitize) 1480912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// This macro prevents the undefined behavior sanitizer from reporting 1490912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// failures. This is only meant to silence unaligned loads on platforms that 1500912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// are known to support them. 1510912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#undef WEBP_UBSAN_IGNORE_UNDEF 1520912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define WEBP_UBSAN_IGNORE_UNDEF \ 1530912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern __attribute__((no_sanitize("undefined"))) 1540912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 1550912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// This macro prevents the undefined behavior sanitizer from reporting 1560912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// failures related to unsigned integer overflows. This is only meant to 1570912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// silence cases where this well defined behavior is expected. 1580912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#undef WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW 1590912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW \ 1600912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern __attribute__((no_sanitize("unsigned-integer-overflow"))) 1610912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#endif 1620912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#endif 1630912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 164a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern// Regularize the definition of WEBP_SWAP_16BIT_CSP (backward compatibility) 165a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !defined(WEBP_SWAP_16BIT_CSP) 166a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#define WEBP_SWAP_16BIT_CSP 0 167a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 168a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 169a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef enum { 170a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora kSSE2, 171a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora kSSE3, 172fa39824bb690c5806358871f46940d0450973d8aJames Zern kSlowSSSE3, // special feature for slow SSSE3 architectures 1737c8da7ce66017295a65ec028084b90800be377f8James Zern kSSE4_1, 174af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora kAVX, 175af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora kAVX2, 176af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora kNEON, 1777c8da7ce66017295a65ec028084b90800be377f8James Zern kMIPS32, 1780912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern kMIPSdspR2, 1790912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern kMSA 180a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} CPUFeature; 181a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// returns true if the CPU supports the feature. 182a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef int (*VP8CPUInfo)(CPUFeature feature); 183a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames ZernWEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; 1847c8da7ce66017295a65ec028084b90800be377f8James Zern 1857c8da7ce66017295a65ec028084b90800be377f8James Zern//------------------------------------------------------------------------------ 1867c8da7ce66017295a65ec028084b90800be377f8James Zern// Init stub generator 1877c8da7ce66017295a65ec028084b90800be377f8James Zern 1887c8da7ce66017295a65ec028084b90800be377f8James Zern// Defines an init function stub to ensure each module exposes a symbol, 1897c8da7ce66017295a65ec028084b90800be377f8James Zern// avoiding a compiler warning. 1907c8da7ce66017295a65ec028084b90800be377f8James Zern#define WEBP_DSP_INIT_STUB(func) \ 1917c8da7ce66017295a65ec028084b90800be377f8James Zern extern void func(void); \ 1927c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_TSAN_IGNORE_FUNCTION void func(void) {} 193a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 194a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 195a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Encoding 196a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 197a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Transforms 198a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms 199a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4). 200a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst, 201a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int do_two); 202a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out); 203a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8WHT)(const int16_t* in, int16_t* out); 204a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8Idct VP8ITransform; 205a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8Fdct VP8FTransform; 2067c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8Fdct VP8FTransform2; // performs two transforms at a time 207a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8WHT VP8FTransformWHT; 208a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Predictions 209a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// *dst is the destination block. *top and *left can be NULL. 210a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left, 211a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint8_t* top); 212a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top); 213a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8Intra4Preds VP8EncPredLuma4; 214a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8IntraPreds VP8EncPredLuma16; 215a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8IntraPreds VP8EncPredChroma8; 216a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 217a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref); 218a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4; 219a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref, 220a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint16_t* const weights); 2210912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// The weights for VP8TDisto4x4 and VP8TDisto16x16 contain a row-major 2220912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// 4 by 4 symmetric matrix. 223a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8WMetric VP8TDisto4x4, VP8TDisto16x16; 224a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 225fa39824bb690c5806358871f46940d0450973d8aJames Zern// Compute the average (DC) of four 4x4 blocks. 226fa39824bb690c5806358871f46940d0450973d8aJames Zern// Each sub-4x4 block #i sum is stored in dc[i]. 227fa39824bb690c5806358871f46940d0450973d8aJames Zerntypedef void (*VP8MeanMetric)(const uint8_t* ref, uint32_t dc[4]); 228fa39824bb690c5806358871f46940d0450973d8aJames Zernextern VP8MeanMetric VP8Mean16x4; 229fa39824bb690c5806358871f46940d0450973d8aJames Zern 230a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst); 231a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8BlockCopy VP8Copy4x4; 2327c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8BlockCopy VP8Copy16x8; 233a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Quantization 234a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastruct VP8Matrix; // forward declaration 235a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16], 236af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora const struct VP8Matrix* const mtx); 2377c8da7ce66017295a65ec028084b90800be377f8James Zern// Same as VP8QuantizeBlock, but quantizes two consecutive blocks. 2387c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef int (*VP8Quantize2Blocks)(int16_t in[32], int16_t out[32], 2397c8da7ce66017295a65ec028084b90800be377f8James Zern const struct VP8Matrix* const mtx); 2407c8da7ce66017295a65ec028084b90800be377f8James Zern 241a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8QuantizeBlock VP8EncQuantizeBlock; 2427c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8Quantize2Blocks VP8EncQuantize2Blocks; 243a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 2448b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora// specific to 2nd transform: 2458b720228d581a84fd173b6dcb2fa295b59db489aVikas Aroratypedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16], 2468b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora const struct VP8Matrix* const mtx); 2478b720228d581a84fd173b6dcb2fa295b59db489aVikas Aroraextern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT; 2488b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 2497c8da7ce66017295a65ec028084b90800be377f8James Zernextern const int VP8DspScan[16 + 4 + 4]; 2507c8da7ce66017295a65ec028084b90800be377f8James Zern 2517c8da7ce66017295a65ec028084b90800be377f8James Zern// Collect histogram for susceptibility calculation. 2527c8da7ce66017295a65ec028084b90800be377f8James Zern#define MAX_COEFF_THRESH 31 // size of histogram used by CollectHistogram. 2537c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef struct { 2547c8da7ce66017295a65ec028084b90800be377f8James Zern // We only need to store max_value and last_non_zero, not the distribution. 2557c8da7ce66017295a65ec028084b90800be377f8James Zern int max_value; 2567c8da7ce66017295a65ec028084b90800be377f8James Zern int last_non_zero; 2577c8da7ce66017295a65ec028084b90800be377f8James Zern} VP8Histogram; 2581e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroratypedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred, 2591e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora int start_block, int end_block, 2607c8da7ce66017295a65ec028084b90800be377f8James Zern VP8Histogram* const histo); 261a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8CHisto VP8CollectHistogram; 2627c8da7ce66017295a65ec028084b90800be377f8James Zern// General-purpose util function to help VP8CollectHistogram(). 2637c8da7ce66017295a65ec028084b90800be377f8James Zernvoid VP8SetHistogramData(const int distribution[MAX_COEFF_THRESH + 1], 2647c8da7ce66017295a65ec028084b90800be377f8James Zern VP8Histogram* const histo); 265a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 2667c8da7ce66017295a65ec028084b90800be377f8James Zern// must be called before using any of the above 2677c8da7ce66017295a65ec028084b90800be377f8James Zernvoid VP8EncDspInit(void); 2687c8da7ce66017295a65ec028084b90800be377f8James Zern 2697c8da7ce66017295a65ec028084b90800be377f8James Zern//------------------------------------------------------------------------------ 2707c8da7ce66017295a65ec028084b90800be377f8James Zern// cost functions (encoding) 2717c8da7ce66017295a65ec028084b90800be377f8James Zern 2727c8da7ce66017295a65ec028084b90800be377f8James Zernextern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p) 2737c8da7ce66017295a65ec028084b90800be377f8James Zern// approximate cost per level: 2747c8da7ce66017295a65ec028084b90800be377f8James Zernextern const uint16_t VP8LevelFixedCosts[2047 /*MAX_LEVEL*/ + 1]; 2757c8da7ce66017295a65ec028084b90800be377f8James Zernextern const uint8_t VP8EncBands[16 + 1]; 2767c8da7ce66017295a65ec028084b90800be377f8James Zern 2777c8da7ce66017295a65ec028084b90800be377f8James Zernstruct VP8Residual; 2787c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs, 2797c8da7ce66017295a65ec028084b90800be377f8James Zern struct VP8Residual* const res); 2807c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs; 2817c8da7ce66017295a65ec028084b90800be377f8James Zern 2827c8da7ce66017295a65ec028084b90800be377f8James Zern// Cost calculation function. 2837c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef int (*VP8GetResidualCostFunc)(int ctx0, 2847c8da7ce66017295a65ec028084b90800be377f8James Zern const struct VP8Residual* const res); 2857c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8GetResidualCostFunc VP8GetResidualCost; 2867c8da7ce66017295a65ec028084b90800be377f8James Zern 2877c8da7ce66017295a65ec028084b90800be377f8James Zern// must be called before anything using the above 2887c8da7ce66017295a65ec028084b90800be377f8James Zernvoid VP8EncDspCostInit(void); 289a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 290a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 291fa39824bb690c5806358871f46940d0450973d8aJames Zern// SSIM / PSNR utils 2920912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 2930912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// struct for accumulating statistical moments 2940912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zerntypedef struct { 295fa39824bb690c5806358871f46940d0450973d8aJames Zern uint32_t w; // sum(w_i) : sum of weights 296fa39824bb690c5806358871f46940d0450973d8aJames Zern uint32_t xm, ym; // sum(w_i * x_i), sum(w_i * y_i) 297fa39824bb690c5806358871f46940d0450973d8aJames Zern uint32_t xxm, xym, yym; // sum(w_i * x_i * x_i), etc. 2980912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern} VP8DistoStats; 2990912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 300fa39824bb690c5806358871f46940d0450973d8aJames Zern// Compute the final SSIM value 301fa39824bb690c5806358871f46940d0450973d8aJames Zern// The non-clipped version assumes stats->w = (2 * VP8_SSIM_KERNEL + 1)^2. 302fa39824bb690c5806358871f46940d0450973d8aJames Zerndouble VP8SSIMFromStats(const VP8DistoStats* const stats); 303fa39824bb690c5806358871f46940d0450973d8aJames Zerndouble VP8SSIMFromStatsClipped(const VP8DistoStats* const stats); 304fa39824bb690c5806358871f46940d0450973d8aJames Zern 3050912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define VP8_SSIM_KERNEL 3 // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1 306fa39824bb690c5806358871f46940d0450973d8aJames Zerntypedef double (*VP8SSIMGetClippedFunc)(const uint8_t* src1, int stride1, 307fa39824bb690c5806358871f46940d0450973d8aJames Zern const uint8_t* src2, int stride2, 308fa39824bb690c5806358871f46940d0450973d8aJames Zern int xo, int yo, // center position 309fa39824bb690c5806358871f46940d0450973d8aJames Zern int W, int H); // plane dimension 3100912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 311a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !defined(WEBP_REDUCE_SIZE) 3120912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// This version is called with the guarantee that you can load 8 bytes and 3130912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// 8 rows at offset src1 and src2 314fa39824bb690c5806358871f46940d0450973d8aJames Zerntypedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1, 315fa39824bb690c5806358871f46940d0450973d8aJames Zern const uint8_t* src2, int stride2); 316fa39824bb690c5806358871f46940d0450973d8aJames Zern 317fa39824bb690c5806358871f46940d0450973d8aJames Zernextern VP8SSIMGetFunc VP8SSIMGet; // unclipped / unchecked 318fa39824bb690c5806358871f46940d0450973d8aJames Zernextern VP8SSIMGetClippedFunc VP8SSIMGetClipped; // with clipping 319a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 3200912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 321a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#if !defined(WEBP_DISABLE_STATS) 322fa39824bb690c5806358871f46940d0450973d8aJames Zerntypedef uint32_t (*VP8AccumulateSSEFunc)(const uint8_t* src1, 323fa39824bb690c5806358871f46940d0450973d8aJames Zern const uint8_t* src2, int len); 324fa39824bb690c5806358871f46940d0450973d8aJames Zernextern VP8AccumulateSSEFunc VP8AccumulateSSE; 325a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern#endif 3260912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 3270912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// must be called before using any of the above directly 3280912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zernvoid VP8SSIMDspInit(void); 3290912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 3300912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern//------------------------------------------------------------------------------ 331a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Decoding 332a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 333a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst); 334a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// when doing two transforms, coeffs is actually int16_t[2][16]. 335a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two); 336a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8DecIdct2 VP8Transform; 3378b720228d581a84fd173b6dcb2fa295b59db489aVikas Aroraextern VP8DecIdct VP8TransformAC3; 338a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8DecIdct VP8TransformUV; 339a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8DecIdct VP8TransformDC; 340a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8DecIdct VP8TransformDCUV; 3411e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroraextern VP8WHT VP8TransformWHT; 342a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 343a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// *dst is the destination block, with stride BPS. Boundary samples are 344a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// assumed accessible when needed. 345a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8PredFunc)(uint8_t* dst); 3467c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */]; 3477c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */]; 3487c8da7ce66017295a65ec028084b90800be377f8James Zernextern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */]; 349a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 350af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// clipping tables (for filtering) 351af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127] 352af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15] 353af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255] 354af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255] 3557c8da7ce66017295a65ec028084b90800be377f8James Zern// must be called first 3567c8da7ce66017295a65ec028084b90800be377f8James Zernvoid VP8InitClipTables(void); 357af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 358a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// simple filter (only for luma) 359a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh); 360a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8SimpleFilterFunc VP8SimpleVFilter16; 361a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8SimpleFilterFunc VP8SimpleHFilter16; 362a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges 363a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8SimpleFilterFunc VP8SimpleHFilter16i; 364a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 365a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// regular filter (on both macroblock edges and inner edges) 366a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride, 367a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int thresh, int ithresh, int hev_t); 368a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride, 369a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int thresh, int ithresh, int hev_t); 370a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// on outer edge 371a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8LumaFilterFunc VP8VFilter16; 372a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8LumaFilterFunc VP8HFilter16; 373a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8ChromaFilterFunc VP8VFilter8; 374a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8ChromaFilterFunc VP8HFilter8; 375a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 376a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// on inner edge 377a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether 378a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8LumaFilterFunc VP8HFilter16i; 379a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether 380a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern VP8ChromaFilterFunc VP8HFilter8i; 381a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 3820912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// Dithering. Combines dithering values (centered around 128) with dst[], 3830912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// according to: dst[] = clip(dst[] + (((dither[]-128) + 8) >> 4) 3840912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define VP8_DITHER_DESCALE 4 3850912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define VP8_DITHER_DESCALE_ROUNDER (1 << (VP8_DITHER_DESCALE - 1)) 3860912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define VP8_DITHER_AMP_BITS 7 3870912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern#define VP8_DITHER_AMP_CENTER (1 << VP8_DITHER_AMP_BITS) 3880912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zernextern void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst, 3890912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern int dst_stride); 3900912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern 391a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// must be called before anything using the above 392a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8DspInit(void); 393a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 394a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 395a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// WebP I/O 396a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 397a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define FANCY_UPSAMPLING // undefined to remove fancy upsampling support 398a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 3998b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora// Convert a pair of y/u/v lines together to the output rgb/a colorspace. 4008b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora// bottom_y can be NULL if only one line of output is needed (at top/bottom). 401a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*WebPUpsampleLinePairFunc)( 402a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint8_t* top_y, const uint8_t* bottom_y, 403a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint8_t* top_u, const uint8_t* top_v, 404a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint8_t* cur_u, const uint8_t* cur_v, 405a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint8_t* top_dst, uint8_t* bottom_dst, int len); 406a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 407a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#ifdef FANCY_UPSAMPLING 408a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 409a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Fancy upsampling functions to convert YUV to RGB(A) modes 410a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; 411a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 412a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif // FANCY_UPSAMPLING 413a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 414af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Per-row point-sampling methods. 415af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroratypedef void (*WebPSamplerRowFunc)(const uint8_t* y, 416af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora const uint8_t* u, const uint8_t* v, 417af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora uint8_t* dst, int len); 418af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Generic function to apply 'WebPSamplerRowFunc' to the whole plane: 419af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroravoid WebPSamplerProcessPlane(const uint8_t* y, int y_stride, 420af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora const uint8_t* u, const uint8_t* v, int uv_stride, 421af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora uint8_t* dst, int dst_stride, 422af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora int width, int height, WebPSamplerRowFunc func); 423a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 424af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Sampling functions to convert rows of YUV to RGB(A) 425af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */]; 426a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 427a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// General function for converting two lines of ARGB or RGBA. 428a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 'alpha_is_last' should be true if 0xff000000 is stored in memory as 429a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// as 0x00, 0x00, 0x00, 0xff (little endian). 430a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraWebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last); 431a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 432a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// YUV444->RGB converters 433a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroratypedef void (*WebPYUV444Converter)(const uint8_t* y, 434a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint8_t* u, const uint8_t* v, 435a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint8_t* dst, int len); 436a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 4377c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */]; 438a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 439af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Must be called before using the WebPUpsamplers[] (and for premultiplied 440af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// colorspaces like rgbA, rgbA4444, etc) 441a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid WebPInitUpsamplers(void); 442af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Must be called before using WebPSamplers[] 443af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroravoid WebPInitSamplers(void); 4447c8da7ce66017295a65ec028084b90800be377f8James Zern// Must be called before using WebPYUV444Converters[] 4457c8da7ce66017295a65ec028084b90800be377f8James Zernvoid WebPInitYUV444Converters(void); 4467c8da7ce66017295a65ec028084b90800be377f8James Zern 4477c8da7ce66017295a65ec028084b90800be377f8James Zern//------------------------------------------------------------------------------ 4487c8da7ce66017295a65ec028084b90800be377f8James Zern// ARGB -> YUV converters 4497c8da7ce66017295a65ec028084b90800be377f8James Zern 4507c8da7ce66017295a65ec028084b90800be377f8James Zern// Convert ARGB samples to luma Y. 4517c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPConvertARGBToY)(const uint32_t* argb, uint8_t* y, int width); 4527c8da7ce66017295a65ec028084b90800be377f8James Zern// Convert ARGB samples to U/V with downsampling. do_store should be '1' for 4537c8da7ce66017295a65ec028084b90800be377f8James Zern// even lines and '0' for odd ones. 'src_width' is the original width, not 4547c8da7ce66017295a65ec028084b90800be377f8James Zern// the U/V one. 4557c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPConvertARGBToUV)(const uint32_t* argb, uint8_t* u, uint8_t* v, 4567c8da7ce66017295a65ec028084b90800be377f8James Zern int src_width, int do_store); 4577c8da7ce66017295a65ec028084b90800be377f8James Zern 4587c8da7ce66017295a65ec028084b90800be377f8James Zern// Convert a row of accumulated (four-values) of rgba32 toward U/V 4597c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPConvertRGBA32ToUV)(const uint16_t* rgb, 4607c8da7ce66017295a65ec028084b90800be377f8James Zern uint8_t* u, uint8_t* v, int width); 4617c8da7ce66017295a65ec028084b90800be377f8James Zern 4627c8da7ce66017295a65ec028084b90800be377f8James Zern// Convert RGB or BGR to Y 4637c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPConvertRGB24ToY)(const uint8_t* rgb, uint8_t* y, int width); 4647c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPConvertBGR24ToY)(const uint8_t* bgr, uint8_t* y, int width); 4657c8da7ce66017295a65ec028084b90800be377f8James Zern 4667c8da7ce66017295a65ec028084b90800be377f8James Zern// used for plain-C fallback. 4677c8da7ce66017295a65ec028084b90800be377f8James Zernextern void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v, 4687c8da7ce66017295a65ec028084b90800be377f8James Zern int src_width, int do_store); 4697c8da7ce66017295a65ec028084b90800be377f8James Zernextern void WebPConvertRGBA32ToUV_C(const uint16_t* rgb, 4707c8da7ce66017295a65ec028084b90800be377f8James Zern uint8_t* u, uint8_t* v, int width); 4717c8da7ce66017295a65ec028084b90800be377f8James Zern 472fa39824bb690c5806358871f46940d0450973d8aJames Zern// utilities for accurate RGB->YUV conversion 473fa39824bb690c5806358871f46940d0450973d8aJames Zernextern uint64_t (*WebPSharpYUVUpdateY)(const uint16_t* src, const uint16_t* ref, 474fa39824bb690c5806358871f46940d0450973d8aJames Zern uint16_t* dst, int len); 475fa39824bb690c5806358871f46940d0450973d8aJames Zernextern void (*WebPSharpYUVUpdateRGB)(const int16_t* src, const int16_t* ref, 476fa39824bb690c5806358871f46940d0450973d8aJames Zern int16_t* dst, int len); 477fa39824bb690c5806358871f46940d0450973d8aJames Zernextern void (*WebPSharpYUVFilterRow)(const int16_t* A, const int16_t* B, 478fa39824bb690c5806358871f46940d0450973d8aJames Zern int len, 479fa39824bb690c5806358871f46940d0450973d8aJames Zern const uint16_t* best_y, uint16_t* out); 480fa39824bb690c5806358871f46940d0450973d8aJames Zern 4817c8da7ce66017295a65ec028084b90800be377f8James Zern// Must be called before using the above. 4827c8da7ce66017295a65ec028084b90800be377f8James Zernvoid WebPInitConvertARGBToYUV(void); 4837c8da7ce66017295a65ec028084b90800be377f8James Zern 4847c8da7ce66017295a65ec028084b90800be377f8James Zern//------------------------------------------------------------------------------ 4857c8da7ce66017295a65ec028084b90800be377f8James Zern// Rescaler 4867c8da7ce66017295a65ec028084b90800be377f8James Zern 4877c8da7ce66017295a65ec028084b90800be377f8James Zernstruct WebPRescaler; 4887c8da7ce66017295a65ec028084b90800be377f8James Zern 4897c8da7ce66017295a65ec028084b90800be377f8James Zern// Import a row of data and save its contribution in the rescaler. 4907c8da7ce66017295a65ec028084b90800be377f8James Zern// 'channel' denotes the channel number to be imported. 'Expand' corresponds to 4917c8da7ce66017295a65ec028084b90800be377f8James Zern// the wrk->x_expand case. Otherwise, 'Shrink' is to be used. 4927c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk, 4937c8da7ce66017295a65ec028084b90800be377f8James Zern const uint8_t* src); 4947c8da7ce66017295a65ec028084b90800be377f8James Zern 4957c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPRescalerImportRowFunc WebPRescalerImportRowExpand; 4967c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPRescalerImportRowFunc WebPRescalerImportRowShrink; 4977c8da7ce66017295a65ec028084b90800be377f8James Zern 4987c8da7ce66017295a65ec028084b90800be377f8James Zern// Export one row (starting at x_out position) from rescaler. 4997c8da7ce66017295a65ec028084b90800be377f8James Zern// 'Expand' corresponds to the wrk->y_expand case. 5007c8da7ce66017295a65ec028084b90800be377f8James Zern// Otherwise 'Shrink' is to be used 5017c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef void (*WebPRescalerExportRowFunc)(struct WebPRescaler* const wrk); 5027c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPRescalerExportRowFunc WebPRescalerExportRowExpand; 5037c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPRescalerExportRowFunc WebPRescalerExportRowShrink; 5047c8da7ce66017295a65ec028084b90800be377f8James Zern 5057c8da7ce66017295a65ec028084b90800be377f8James Zern// Plain-C implementation, as fall-back. 506a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern void WebPRescalerImportRowExpand_C(struct WebPRescaler* const wrk, 507a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern const uint8_t* src); 508a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern void WebPRescalerImportRowShrink_C(struct WebPRescaler* const wrk, 509a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern const uint8_t* src); 510a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern void WebPRescalerExportRowExpand_C(struct WebPRescaler* const wrk); 511a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern void WebPRescalerExportRowShrink_C(struct WebPRescaler* const wrk); 5127c8da7ce66017295a65ec028084b90800be377f8James Zern 5137c8da7ce66017295a65ec028084b90800be377f8James Zern// Main entry calls: 5147c8da7ce66017295a65ec028084b90800be377f8James Zernextern void WebPRescalerImportRow(struct WebPRescaler* const wrk, 5157c8da7ce66017295a65ec028084b90800be377f8James Zern const uint8_t* src); 5167c8da7ce66017295a65ec028084b90800be377f8James Zern// Export one row (starting at x_out position) from rescaler. 5177c8da7ce66017295a65ec028084b90800be377f8James Zernextern void WebPRescalerExportRow(struct WebPRescaler* const wrk); 5187c8da7ce66017295a65ec028084b90800be377f8James Zern 5197c8da7ce66017295a65ec028084b90800be377f8James Zern// Must be called first before using the above. 5207c8da7ce66017295a65ec028084b90800be377f8James Zernvoid WebPRescalerDspInit(void); 521a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 522a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 523af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Utilities for processing transparent channel. 524a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 525a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h. 526a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last). 527a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern void (*WebPApplyAlphaMultiply)( 528a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint8_t* rgba, int alpha_first, int w, int h, int stride); 529a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 530a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Same, buf specifically for RGBA4444 format 531a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern void (*WebPApplyAlphaMultiply4444)( 532a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint8_t* rgba4444, int w, int h, int stride); 5338c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora 5347c8da7ce66017295a65ec028084b90800be377f8James Zern// Dispatch the values from alpha[] plane to the ARGB destination 'dst'. 5357c8da7ce66017295a65ec028084b90800be377f8James Zern// Returns true if alpha[] plane has non-trivial values different from 0xff. 5367c8da7ce66017295a65ec028084b90800be377f8James Zernextern int (*WebPDispatchAlpha)(const uint8_t* alpha, int alpha_stride, 5377c8da7ce66017295a65ec028084b90800be377f8James Zern int width, int height, 5387c8da7ce66017295a65ec028084b90800be377f8James Zern uint8_t* dst, int dst_stride); 5397c8da7ce66017295a65ec028084b90800be377f8James Zern 5407c8da7ce66017295a65ec028084b90800be377f8James Zern// Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the 5417c8da7ce66017295a65ec028084b90800be377f8James Zern// A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units. 5427c8da7ce66017295a65ec028084b90800be377f8James Zernextern void (*WebPDispatchAlphaToGreen)(const uint8_t* alpha, int alpha_stride, 5437c8da7ce66017295a65ec028084b90800be377f8James Zern int width, int height, 5447c8da7ce66017295a65ec028084b90800be377f8James Zern uint32_t* dst, int dst_stride); 5457c8da7ce66017295a65ec028084b90800be377f8James Zern 5468c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora// Extract the alpha values from 32b values in argb[] and pack them into alpha[] 5478c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora// (this is the opposite of WebPDispatchAlpha). 5488c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora// Returns true if there's only trivial 0xff alpha values. 5498c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Aroraextern int (*WebPExtractAlpha)(const uint8_t* argb, int argb_stride, 5508c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora int width, int height, 5518c098653157979e397d3954fc2ea0ee43bae6ab2Vikas Arora uint8_t* alpha, int alpha_stride); 552a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 553fa39824bb690c5806358871f46940d0450973d8aJames Zern// Extract the green values from 32b values in argb[] and pack them into alpha[] 554fa39824bb690c5806358871f46940d0450973d8aJames Zern// (this is the opposite of WebPDispatchAlphaToGreen). 555fa39824bb690c5806358871f46940d0450973d8aJames Zernextern void (*WebPExtractGreen)(const uint32_t* argb, uint8_t* alpha, int size); 556fa39824bb690c5806358871f46940d0450973d8aJames Zern 557af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Pre-Multiply operation transforms x into x * A / 255 (where x=Y,R,G or B). 558af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Un-Multiply operation transforms x into x * 255 / A. 559a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 560af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row. 561af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse); 562a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 563af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Same a WebPMultARGBRow(), but for several rows. 564af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroravoid WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows, 565af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora int inverse); 566af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 567af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Same for a row of single values, with side alpha values. 568af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroraextern void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha, 569af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora int width, int inverse); 570af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 571af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora// Same a WebPMultRow(), but for several 'num_rows' rows. 572af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Aroravoid WebPMultRows(uint8_t* ptr, int stride, 573af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora const uint8_t* alpha, int alpha_stride, 574af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora int width, int num_rows, int inverse); 575af51b94a435132e9014c324e25fb686b3d07a8c8Vikas Arora 5767c8da7ce66017295a65ec028084b90800be377f8James Zern// Plain-C versions, used as fallback by some implementations. 577a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernvoid WebPMultRow_C(uint8_t* const ptr, const uint8_t* const alpha, 578a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern int width, int inverse); 579a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernvoid WebPMultARGBRow_C(uint32_t* const ptr, int width, int inverse); 5807c8da7ce66017295a65ec028084b90800be377f8James Zern 5817c8da7ce66017295a65ec028084b90800be377f8James Zern// RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order. 582a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern void (*WebPPackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b, 583a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern int len, int step, uint32_t* out); 584a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern 585a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern// This function returns true if src[i] contains a value different from 0xff. 586a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern int (*WebPHasAlpha8b)(const uint8_t* src, int length); 587a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zern// This function returns true if src[4*i] contains a value different from 0xff. 588a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernextern int (*WebPHasAlpha32b)(const uint8_t* src, int length); 5897c8da7ce66017295a65ec028084b90800be377f8James Zern 5907c8da7ce66017295a65ec028084b90800be377f8James Zern// To be called first before using the above. 591a187300ff9a8a7c10b1fb2ec84223fdd14e6d47bJames Zernvoid WebPInitAlphaProcessing(void); 5927c8da7ce66017295a65ec028084b90800be377f8James Zern 5937c8da7ce66017295a65ec028084b90800be377f8James Zern//------------------------------------------------------------------------------ 5947c8da7ce66017295a65ec028084b90800be377f8James Zern// Filter functions 5957c8da7ce66017295a65ec028084b90800be377f8James Zern 5967c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef enum { // Filter types. 5977c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_NONE = 0, 5987c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_HORIZONTAL, 5997c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_VERTICAL, 6007c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_GRADIENT, 6017c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1, // end marker 6027c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_BEST, // meta-types 6037c8da7ce66017295a65ec028084b90800be377f8James Zern WEBP_FILTER_FAST 6047c8da7ce66017295a65ec028084b90800be377f8James Zern} WEBP_FILTER_TYPE; 6057c8da7ce66017295a65ec028084b90800be377f8James Zern 6067c8da7ce66017295a65ec028084b90800be377f8James Zerntypedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height, 6077c8da7ce66017295a65ec028084b90800be377f8James Zern int stride, uint8_t* out); 6080912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// In-place un-filtering. 6090912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern// Warning! 'prev_line' pointer can be equal to 'cur_line' or 'preds'. 6100912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zerntypedef void (*WebPUnfilterFunc)(const uint8_t* prev_line, const uint8_t* preds, 6110912efc2528d03c59d45dd9bdc9ff9ec800a3fc1James Zern uint8_t* cur_line, int width); 6127c8da7ce66017295a65ec028084b90800be377f8James Zern 6137c8da7ce66017295a65ec028084b90800be377f8James Zern// Filter the given data using the given predictor. 6147c8da7ce66017295a65ec028084b90800be377f8James Zern// 'in' corresponds to a 2-dimensional pixel array of size (stride * height) 6157c8da7ce66017295a65ec028084b90800be377f8James Zern// in raster order. 6167c8da7ce66017295a65ec028084b90800be377f8James Zern// 'stride' is number of bytes per scan line (with possible padding). 6177c8da7ce66017295a65ec028084b90800be377f8James Zern// 'out' should be pre-allocated. 6187c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; 6197c8da7ce66017295a65ec028084b90800be377f8James Zern 6207c8da7ce66017295a65ec028084b90800be377f8James Zern// In-place reconstruct the original data from the given filtered data. 6217c8da7ce66017295a65ec028084b90800be377f8James Zern// The reconstruction will be done for 'num_rows' rows starting from 'row' 6227c8da7ce66017295a65ec028084b90800be377f8James Zern// (assuming rows upto 'row - 1' are already reconstructed). 6237c8da7ce66017295a65ec028084b90800be377f8James Zernextern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; 6247c8da7ce66017295a65ec028084b90800be377f8James Zern 6257c8da7ce66017295a65ec028084b90800be377f8James Zern// To be called first before using the above. 6267c8da7ce66017295a65ec028084b90800be377f8James Zernvoid VP8FiltersInit(void); 6277c8da7ce66017295a65ec028084b90800be377f8James Zern 6288b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora#ifdef __cplusplus 629a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} // extern "C" 630a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 631a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 632a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif /* WEBP_DSP_DSP_H_ */ 633