1a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Copyright 2010 Google Inc. All Rights Reserved. 29aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 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. 89aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// ----------------------------------------------------------------------------- 99aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 10a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Speed-critical decoding functions. 119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Author: Skal (pascal.massimino@gmail.com) 139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 14a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "./dsp.h" 15a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "../dec/vp8i.h" 169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 189aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern "C" { 199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 21a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// run-time tables (~4k) 239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 249aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic uint8_t abs0[255 + 255 + 1]; // abs(i) 259aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic uint8_t abs1[255 + 255 + 1]; // abs(i)>>1 269aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic int8_t sclip1[1020 + 1020 + 1]; // clips [-1020, 1020] to [-128, 127] 279aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic int8_t sclip2[112 + 112 + 1]; // clips [-112, 112] to [-16, 15] 289aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic uint8_t clip1[255 + 510 + 1]; // clips [-255,510] to [0,255] 299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3003d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// We declare this variable 'volatile' to prevent instruction reordering 3103d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// and make sure it's set to true _last_ (so as to be thread-safe) 3203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arorastatic volatile int tables_ok = 0; 339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 34a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic void DspInitTables(void) { 359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (!tables_ok) { 369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = -255; i <= 255; ++i) { 389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold abs0[255 + i] = (i < 0) ? -i : i; 399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold abs1[255 + i] = abs0[255 + i] >> 1; 409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = -1020; i <= 1020; ++i) { 429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold sclip1[1020 + i] = (i < -128) ? -128 : (i > 127) ? 127 : i; 439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = -112; i <= 112; ++i) { 459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold sclip2[112 + i] = (i < -16) ? -16 : (i > 15) ? 15 : i; 469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = -255; i <= 255 + 255; ++i) { 489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold clip1[255 + i] = (i < 0) ? 0 : (i > 255) ? 255 : i; 499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tables_ok = 1; 519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 54a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE uint8_t clip_8b(int v) { 559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255; 569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 58a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Transforms (Paragraph 14.4) 609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define STORE(x, y, v) \ 629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst[x + y * BPS] = clip_8b(dst[x + y * BPS] + ((v) >> 3)) 639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 649aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic const int kC1 = 20091 + (1 << 16); 659aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic const int kC2 = 35468; 669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define MUL(a, b) (((a) * (b)) >> 16) 679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 68466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arorastatic void TransformOne(const int16_t* in, uint8_t* dst) { 699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int C[4 * 4], *tmp; 709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp = C; 729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { // vertical pass 739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a = in[0] + in[8]; // [-4096, 4094] 749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int b = in[0] - in[8]; // [-4095, 4095] 759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int c = MUL(in[4], kC2) - MUL(in[12], kC1); // [-3783, 3783] 769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int d = MUL(in[4], kC1) + MUL(in[12], kC2); // [-3785, 3781] 779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[0] = a + d; // [-7881, 7875] 789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[1] = b + c; // [-7878, 7878] 799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[2] = b - c; // [-7878, 7878] 809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[3] = a - d; // [-7877, 7879] 819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp += 4; 829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold in++; 839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Each pass is expanding the dynamic range by ~3.85 (upper bound). 859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // The exact value is (2. + (kC1 + kC2) / 65536). 869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // After the second pass, maximum interval is [-3794, 3794], assuming 879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // an input in [-2048, 2047] interval. We then need to add a dst value 889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // in the [0, 255] range. 899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // In the worst case scenario, the input to clip_8b() can be as large as 909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // [-60713, 60968]. 919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp = C; 929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { // horizontal pass 939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int dc = tmp[0] + 4; 949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a = dc + tmp[8]; 959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int b = dc - tmp[8]; 969aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int c = MUL(tmp[4], kC2) - MUL(tmp[12], kC1); 979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int d = MUL(tmp[4], kC1) + MUL(tmp[12], kC2); 989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold STORE(0, 0, a + d); 999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold STORE(1, 0, b + c); 1009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold STORE(2, 0, b - c); 1019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold STORE(3, 0, a - d); 1029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp++; 1039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst += BPS; 1049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#undef MUL 1079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 108466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arorastatic void TransformTwo(const int16_t* in, uint8_t* dst, int do_two) { 109466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora TransformOne(in, dst); 110466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora if (do_two) { 111466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora TransformOne(in + 16, dst + 4); 112466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora } 113466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora} 114466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 1159aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TransformUV(const int16_t* in, uint8_t* dst) { 116466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8Transform(in + 0 * 16, dst, 1); 117466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8Transform(in + 2 * 16, dst + 4 * BPS, 1); 1189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1209aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TransformDC(const int16_t *in, uint8_t* dst) { 1219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int DC = in[0] + 4; 1229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i, j; 1239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 4; ++j) { 1249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { 1259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold STORE(i, j, DC); 1269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1309aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TransformDCUV(const int16_t* in, uint8_t* dst) { 1319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (in[0 * 16]) TransformDC(in + 0 * 16, dst); 1329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (in[1 * 16]) TransformDC(in + 1 * 16, dst + 4); 1339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (in[2 * 16]) TransformDC(in + 2 * 16, dst + 4 * BPS); 1349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (in[3 * 16]) TransformDC(in + 3 * 16, dst + 4 * BPS + 4); 1359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#undef STORE 1389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 139a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 1409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Paragraph 14.3 1419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1429aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TransformWHT(const int16_t* in, int16_t* out) { 1439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int tmp[16]; 1449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 1459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { 1469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a0 = in[0 + i] + in[12 + i]; 1479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a1 = in[4 + i] + in[ 8 + i]; 1489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a2 = in[4 + i] - in[ 8 + i]; 1499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a3 = in[0 + i] - in[12 + i]; 1509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[0 + i] = a0 + a1; 1519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[8 + i] = a0 - a1; 1529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[4 + i] = a3 + a2; 1539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold tmp[12 + i] = a3 - a2; 1549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { 1569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int dc = tmp[0 + i * 4] + 3; // w/ rounder 1579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a0 = dc + tmp[3 + i * 4]; 1589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a1 = tmp[1 + i * 4] + tmp[2 + i * 4]; 1599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a2 = tmp[1 + i * 4] - tmp[2 + i * 4]; 1609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a3 = dc - tmp[3 + i * 4]; 1619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold out[ 0] = (a0 + a1) >> 3; 1629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold out[16] = (a3 + a2) >> 3; 1639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold out[32] = (a0 - a1) >> 3; 1649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold out[48] = (a3 - a2) >> 3; 1659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold out += 64; 1669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1699aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid (*VP8TransformWHT)(const int16_t* in, int16_t* out) = TransformWHT; 1709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 171a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 1729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Intra predictions 1739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 174a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define DST(x, y) dst[(x) + (y) * BPS] 1759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 176a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void TrueMotion(uint8_t *dst, int size) { 1779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t* top = dst - BPS; 1789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t* const clip0 = clip1 + 255 - top[-1]; 1799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int y; 1809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (y = 0; y < size; ++y) { 1819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t* const clip = clip0 + dst[-1]; 1829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int x; 1839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (x = 0; x < size; ++x) { 1849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst[x] = clip[top[x]]; 1859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst += BPS; 1879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 1889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 1899aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TM4(uint8_t *dst) { TrueMotion(dst, 4); } 1909aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TM8uv(uint8_t *dst) { TrueMotion(dst, 8); } 1919aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void TM16(uint8_t *dst) { TrueMotion(dst, 16); } 1929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 193a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 1949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 16x16 1959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1969aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VE16(uint8_t *dst) { // vertical 1979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 1989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 16; ++j) { 1999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memcpy(dst + j * BPS, dst - BPS, 16); 2009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2039aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HE16(uint8_t *dst) { // horizontal 2049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 2059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 16; j > 0; --j) { 2069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memset(dst, dst[-1], 16); 2079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst += BPS; 2089aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 211a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void Put16(int v, uint8_t* dst) { 2129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 2139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 16; ++j) { 2149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memset(dst + j * BPS, v, 16); 2159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2189aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC16(uint8_t *dst) { // DC 2199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int DC = 16; 2209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 2219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 16; ++j) { 2229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC += dst[-1 + j * BPS] + dst[j - BPS]; 2239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold Put16(DC >> 5, dst); 2259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2279aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC16NoTop(uint8_t *dst) { // DC with top samples not available 2289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int DC = 8; 2299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 2309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 16; ++j) { 2319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC += dst[-1 + j * BPS]; 2329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold Put16(DC >> 4, dst); 2349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2369aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC16NoLeft(uint8_t *dst) { // DC with left samples not available 2379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int DC = 8; 2389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 2399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 16; ++i) { 2409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC += dst[i - BPS]; 2419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold Put16(DC >> 4, dst); 2439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2459aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC16NoTopLeft(uint8_t *dst) { // DC with no top and left samples 2469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold Put16(0x80, dst); 2479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 249a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 2509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 4x4 2519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2) 2539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define AVG2(a, b) (((a) + (b) + 1) >> 1) 2549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2559aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VE4(uint8_t *dst) { // vertical 2569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t* top = dst - BPS; 2579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t vals[4] = { 2589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold AVG3(top[-1], top[0], top[1]), 2599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold AVG3(top[ 0], top[1], top[2]), 2609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold AVG3(top[ 1], top[2], top[3]), 2619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold AVG3(top[ 2], top[3], top[4]) 2629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold }; 2639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 2649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) { 2659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memcpy(dst + i * BPS, vals, sizeof(vals)); 2669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 2679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2699aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HE4(uint8_t *dst) { // horizontal 2709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[-1 - BPS]; 2719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[-1]; 2729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[-1 + BPS]; 2739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int D = dst[-1 + 2 * BPS]; 2749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int E = dst[-1 + 3 * BPS]; 2759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold *(uint32_t*)(dst + 0 * BPS) = 0x01010101U * AVG3(A, B, C); 2769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold *(uint32_t*)(dst + 1 * BPS) = 0x01010101U * AVG3(B, C, D); 2779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold *(uint32_t*)(dst + 2 * BPS) = 0x01010101U * AVG3(C, D, E); 2789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold *(uint32_t*)(dst + 3 * BPS) = 0x01010101U * AVG3(D, E, E); 2799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2819aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC4(uint8_t *dst) { // DC 2829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t dc = 4; 2839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 2849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) dc += dst[i - BPS] + dst[-1 + i * BPS]; 2859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dc >>= 3; 2869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 4; ++i) memset(dst + i * BPS, dc, 4); 2879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 2889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2899aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void RD4(uint8_t *dst) { // Down-right 2909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int I = dst[-1 + 0 * BPS]; 2919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int J = dst[-1 + 1 * BPS]; 2929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int K = dst[-1 + 2 * BPS]; 2939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int L = dst[-1 + 3 * BPS]; 2949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int X = dst[-1 - BPS]; 2959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[0 - BPS]; 2969aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[1 - BPS]; 2979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[2 - BPS]; 2989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int D = dst[3 - BPS]; 299a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 3) = AVG3(J, K, L); 300a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 2) = DST(1, 3) = AVG3(I, J, K); 301a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 1) = DST(1, 2) = DST(2, 3) = AVG3(X, I, J); 302a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = DST(1, 1) = DST(2, 2) = DST(3, 3) = AVG3(A, X, I); 303a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = DST(2, 1) = DST(3, 2) = AVG3(B, A, X); 304a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = DST(3, 1) = AVG3(C, B, A); 305a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = AVG3(D, C, B); 3069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 3079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3089aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void LD4(uint8_t *dst) { // Down-Left 3099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[0 - BPS]; 3109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[1 - BPS]; 3119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[2 - BPS]; 3129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int D = dst[3 - BPS]; 3139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int E = dst[4 - BPS]; 3149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int F = dst[5 - BPS]; 3159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int G = dst[6 - BPS]; 3169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int H = dst[7 - BPS]; 317a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = AVG3(A, B, C); 318a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = DST(0, 1) = AVG3(B, C, D); 319a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E); 320a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F); 321a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G); 322a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 2) = DST(2, 3) = AVG3(F, G, H); 323a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 3) = AVG3(G, H, H); 3249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 3259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3269aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VR4(uint8_t *dst) { // Vertical-Right 3279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int I = dst[-1 + 0 * BPS]; 3289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int J = dst[-1 + 1 * BPS]; 3299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int K = dst[-1 + 2 * BPS]; 3309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int X = dst[-1 - BPS]; 3319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[0 - BPS]; 3329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[1 - BPS]; 3339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[2 - BPS]; 3349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int D = dst[3 - BPS]; 335a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = DST(1, 2) = AVG2(X, A); 336a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = DST(2, 2) = AVG2(A, B); 337a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = DST(3, 2) = AVG2(B, C); 338a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = AVG2(C, D); 3399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 340a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 3) = AVG3(K, J, I); 341a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 2) = AVG3(J, I, X); 342a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 1) = DST(1, 3) = AVG3(I, X, A); 343a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 1) = DST(2, 3) = AVG3(X, A, B); 344a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 1) = DST(3, 3) = AVG3(A, B, C); 345a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 1) = AVG3(B, C, D); 3469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 3479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3489aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VL4(uint8_t *dst) { // Vertical-Left 3499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[0 - BPS]; 3509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[1 - BPS]; 3519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[2 - BPS]; 3529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int D = dst[3 - BPS]; 3539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int E = dst[4 - BPS]; 3549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int F = dst[5 - BPS]; 3559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int G = dst[6 - BPS]; 3569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int H = dst[7 - BPS]; 357a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = AVG2(A, B); 358a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = DST(0, 2) = AVG2(B, C); 359a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = DST(1, 2) = AVG2(C, D); 360a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = DST(2, 2) = AVG2(D, E); 3619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 362a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 1) = AVG3(A, B, C); 363a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 1) = DST(0, 3) = AVG3(B, C, D); 364a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 1) = DST(1, 3) = AVG3(C, D, E); 365a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 1) = DST(2, 3) = AVG3(D, E, F); 366a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 2) = AVG3(E, F, G); 367a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 3) = AVG3(F, G, H); 3689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 3699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3709aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HU4(uint8_t *dst) { // Horizontal-Up 3719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int I = dst[-1 + 0 * BPS]; 3729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int J = dst[-1 + 1 * BPS]; 3739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int K = dst[-1 + 2 * BPS]; 3749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int L = dst[-1 + 3 * BPS]; 375a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = AVG2(I, J); 376a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = DST(0, 1) = AVG2(J, K); 377a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 1) = DST(0, 2) = AVG2(K, L); 378a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = AVG3(I, J, K); 379a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = DST(1, 1) = AVG3(J, K, L); 380a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 1) = DST(1, 2) = AVG3(K, L, L); 381a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 2) = DST(2, 2) = 382a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L; 3839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 3849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3859aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HD4(uint8_t *dst) { // Horizontal-Down 3869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int I = dst[-1 + 0 * BPS]; 3879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int J = dst[-1 + 1 * BPS]; 3889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int K = dst[-1 + 2 * BPS]; 3899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int L = dst[-1 + 3 * BPS]; 3909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int X = dst[-1 - BPS]; 3919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int A = dst[0 - BPS]; 3929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int B = dst[1 - BPS]; 3939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int C = dst[2 - BPS]; 3949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 395a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 0) = DST(2, 1) = AVG2(I, X); 396a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 1) = DST(2, 2) = AVG2(J, I); 397a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 2) = DST(2, 3) = AVG2(K, J); 398a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(0, 3) = AVG2(L, K); 3999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 400a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(3, 0) = AVG3(A, B, C); 401a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(2, 0) = AVG3(X, A, B); 402a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 0) = DST(3, 1) = AVG3(I, X, A); 403a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 1) = DST(3, 2) = AVG3(J, I, X); 404a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 2) = DST(3, 3) = AVG3(K, J, I); 405a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DST(1, 3) = AVG3(L, K, J); 4069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 408a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#undef DST 4099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#undef AVG3 4109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#undef AVG2 4119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 412a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 4139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Chroma 4149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4159aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VE8uv(uint8_t *dst) { // vertical 4169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 4179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 8; ++j) { 4189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memcpy(dst + j * BPS, dst - BPS, 8); 4199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4229aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HE8uv(uint8_t *dst) { // horizontal 4239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 4249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 8; ++j) { 4259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold memset(dst, dst[-1], 8); 4269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dst += BPS; 4279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// helper for chroma-DC predictions 4311e7bf8805bd030c19924a5306837ecd72c295751Vikas Arorastatic WEBP_INLINE void Put8x8uv(uint8_t value, uint8_t* dst) { 4329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int j; 4331e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora#ifndef WEBP_REFERENCE_IMPLEMENTATION 4341e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora const uint64_t v = (uint64_t)value * 0x0101010101010101ULL; 4359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (j = 0; j < 8; ++j) { 4369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold *(uint64_t*)(dst + j * BPS) = v; 4379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4381e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora#else 4391e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora for (j = 0; j < 8; ++j) memset(dst + j * BPS, value, 8); 4401e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora#endif 4419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4439aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC8uv(uint8_t *dst) { // DC 4449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int dc0 = 8; 4459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 4469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 8; ++i) { 4479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dc0 += dst[i - BPS] + dst[-1 + i * BPS]; 4489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4491e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora Put8x8uv(dc0 >> 4, dst); 4509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4529aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC8uvNoLeft(uint8_t *dst) { // DC with no left samples 4539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int dc0 = 4; 4549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 4559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 8; ++i) { 4569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dc0 += dst[i - BPS]; 4579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4581e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora Put8x8uv(dc0 >> 3, dst); 4599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4619aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC8uvNoTop(uint8_t *dst) { // DC with no top samples 4629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int dc0 = 4; 4639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 4649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 8; ++i) { 4659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold dc0 += dst[-1 + i * BPS]; 4669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 4671e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora Put8x8uv(dc0 >> 3, dst); 4689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4709aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void DC8uvNoTopLeft(uint8_t *dst) { // DC with nothing 4711e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora Put8x8uv(0x80, dst); 4729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 4739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 474a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 4759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// default C implementations 4769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 477a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraconst VP8PredFunc VP8PredLuma4[NUM_BMODES] = { 4789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC4, TM4, VE4, HE4, RD4, VR4, LD4, VL4, HD4, HU4 4799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 4809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 481a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraconst VP8PredFunc VP8PredLuma16[NUM_B_DC_MODES] = { 4829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC16, TM16, VE16, HE16, 4839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC16NoTop, DC16NoLeft, DC16NoTopLeft 4849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 4859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 486a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraconst VP8PredFunc VP8PredChroma8[NUM_B_DC_MODES] = { 4879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC8uv, TM8uv, VE8uv, HE8uv, 4889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC8uvNoTop, DC8uvNoLeft, DC8uvNoTopLeft 4899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 4909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 491a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 4929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Edge filtering functions 4939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 4949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 4 pixels in, 2 pixels out 495a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void do_filter2(uint8_t* p, int step) { 4969aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; 4979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a = 3 * (q0 - p0) + sclip1[1020 + p1 - q1]; 4989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a1 = sclip2[112 + ((a + 4) >> 3)]; 4999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a2 = sclip2[112 + ((a + 3) >> 3)]; 5009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[-step] = clip1[255 + p0 + a2]; 5019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ 0] = clip1[255 + q0 - a1]; 5029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 4 pixels in, 4 pixels out 505a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void do_filter4(uint8_t* p, int step) { 5069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; 5079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a = 3 * (q0 - p0); 5089aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a1 = sclip2[112 + ((a + 4) >> 3)]; 5099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a2 = sclip2[112 + ((a + 3) >> 3)]; 5109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a3 = (a1 + 1) >> 1; 5119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[-2*step] = clip1[255 + p1 + a3]; 5129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[- step] = clip1[255 + p0 + a2]; 5139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ 0] = clip1[255 + q0 - a1]; 5149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ step] = clip1[255 + q1 - a3]; 5159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 6 pixels in, 6 pixels out 518a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void do_filter6(uint8_t* p, int step) { 5199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p2 = p[-3*step], p1 = p[-2*step], p0 = p[-step]; 5209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int q0 = p[0], q1 = p[step], q2 = p[2*step]; 5219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a = sclip1[1020 + 3 * (q0 - p0) + sclip1[1020 + p1 - q1]]; 5229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a1 = (27 * a + 63) >> 7; // eq. to ((3 * a + 7) * 9) >> 7 5239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a2 = (18 * a + 63) >> 7; // eq. to ((2 * a + 7) * 9) >> 7 5249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int a3 = (9 * a + 63) >> 7; // eq. to ((1 * a + 7) * 9) >> 7 5259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[-3*step] = clip1[255 + p2 + a3]; 5269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[-2*step] = clip1[255 + p1 + a2]; 5279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[- step] = clip1[255 + p0 + a1]; 5289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ 0] = clip1[255 + q0 - a1]; 5299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ step] = clip1[255 + q1 - a2]; 5309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p[ 2*step] = clip1[255 + q2 - a3]; 5319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 533a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE int hev(const uint8_t* p, int step, int thresh) { 5349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; 5359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return (abs0[255 + p1 - p0] > thresh) || (abs0[255 + q1 - q0] > thresh); 5369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 538a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE int needs_filter(const uint8_t* p, int step, int thresh) { 5399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; 5409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return (2 * abs0[255 + p0 - q0] + abs1[255 + p1 - q1]) <= thresh; 5419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 543a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE int needs_filter2(const uint8_t* p, 544a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int step, int t, int it) { 5459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int p3 = p[-4*step], p2 = p[-3*step], p1 = p[-2*step], p0 = p[-step]; 5469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int q0 = p[0], q1 = p[step], q2 = p[2*step], q3 = p[3*step]; 5479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if ((2 * abs0[255 + p0 - q0] + abs1[255 + p1 - q1]) > t) 5489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return 0; 5499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return abs0[255 + p3 - p2] <= it && abs0[255 + p2 - p1] <= it && 5509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold abs0[255 + p1 - p0] <= it && abs0[255 + q3 - q2] <= it && 5519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold abs0[255 + q2 - q1] <= it && abs0[255 + q1 - q0] <= it; 5529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 554a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 5559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Simple In-loop filtering (Paragraph 15.2) 5569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5579aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void SimpleVFilter16(uint8_t* p, int stride, int thresh) { 5589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 5599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 16; ++i) { 5609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (needs_filter(p + i, stride, thresh)) { 5619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter2(p + i, stride); 5629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5669aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void SimpleHFilter16(uint8_t* p, int stride, int thresh) { 5679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int i; 5689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (i = 0; i < 16; ++i) { 5699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (needs_filter(p + i * stride, 1, thresh)) { 5709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter2(p + i * stride, 1); 5719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5759aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void SimpleVFilter16i(uint8_t* p, int stride, int thresh) { 5769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int k; 5779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (k = 3; k > 0; --k) { 5789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += 4 * stride; 5799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold SimpleVFilter16(p, stride, thresh); 5809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 5839aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void SimpleHFilter16i(uint8_t* p, int stride, int thresh) { 5849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int k; 5859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (k = 3; k > 0; --k) { 5869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += 4; 5879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold SimpleHFilter16(p, stride, thresh); 5889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 5899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 5909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 591a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 5929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Complex In-loop filtering (Paragraph 15.3) 5939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 594a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void FilterLoop26(uint8_t* p, 595a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int hstride, int vstride, int size, 596a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int thresh, int ithresh, int hev_thresh) { 5979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold while (size-- > 0) { 5989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (needs_filter2(p, hstride, thresh, ithresh)) { 5999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (hev(p, hstride, hev_thresh)) { 6009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter2(p, hstride); 6019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } else { 6029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter6(p, hstride); 6039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += vstride; 6069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6089aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 609a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE void FilterLoop24(uint8_t* p, 610a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int hstride, int vstride, int size, 611a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int thresh, int ithresh, int hev_thresh) { 6129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold while (size-- > 0) { 6139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (needs_filter2(p, hstride, thresh, ithresh)) { 6149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold if (hev(p, hstride, hev_thresh)) { 6159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter2(p, hstride); 6169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } else { 6179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold do_filter4(p, hstride); 6189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += vstride; 6219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// on macroblock edges 6259aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VFilter16(uint8_t* p, int stride, 6269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(p, stride, 1, 16, thresh, ithresh, hev_thresh); 6289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6309aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HFilter16(uint8_t* p, int stride, 6319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(p, 1, stride, 16, thresh, ithresh, hev_thresh); 6339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// on three inner edges 6369aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VFilter16i(uint8_t* p, int stride, 6379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int k; 6399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (k = 3; k > 0; --k) { 6409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += 4 * stride; 6419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(p, stride, 1, 16, thresh, ithresh, hev_thresh); 6429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6459aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HFilter16i(uint8_t* p, int stride, 6469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int k; 6489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold for (k = 3; k > 0; --k) { 6499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold p += 4; 6509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(p, 1, stride, 16, thresh, ithresh, hev_thresh); 6519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 6529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 8-pixels wide variant, for chroma filtering 6559aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VFilter8(uint8_t* u, uint8_t* v, int stride, 6569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(u, stride, 1, 8, thresh, ithresh, hev_thresh); 6589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(v, stride, 1, 8, thresh, ithresh, hev_thresh); 6599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6619aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HFilter8(uint8_t* u, uint8_t* v, int stride, 6629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(u, 1, stride, 8, thresh, ithresh, hev_thresh); 6649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop26(v, 1, stride, 8, thresh, ithresh, hev_thresh); 6659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6679aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void VFilter8i(uint8_t* u, uint8_t* v, int stride, 6689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(u + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh); 6709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(v + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh); 6719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 6739aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstatic void HFilter8i(uint8_t* u, uint8_t* v, int stride, 6749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int thresh, int ithresh, int hev_thresh) { 6759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(u + 4, 1, stride, 8, thresh, ithresh, hev_thresh); 6769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold FilterLoop24(v + 4, 1, stride, 8, thresh, ithresh, hev_thresh); 6779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 6789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 679a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 680466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 681a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8DecIdct2 VP8Transform; 682a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8DecIdct VP8TransformUV; 683a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8DecIdct VP8TransformDC; 684a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8DecIdct VP8TransformDCUV; 685466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 686a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8LumaFilterFunc VP8VFilter16; 687a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8LumaFilterFunc VP8HFilter16; 688a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8ChromaFilterFunc VP8VFilter8; 689a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8ChromaFilterFunc VP8HFilter8; 690a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8LumaFilterFunc VP8VFilter16i; 691a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8LumaFilterFunc VP8HFilter16i; 692a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8ChromaFilterFunc VP8VFilter8i; 693a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8ChromaFilterFunc VP8HFilter8i; 694a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8SimpleFilterFunc VP8SimpleVFilter16; 695a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8SimpleFilterFunc VP8SimpleHFilter16; 696a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8SimpleFilterFunc VP8SimpleVFilter16i; 697a2415724fb3466168b2af5b08bd94ba732c0e753Vikas AroraVP8SimpleFilterFunc VP8SimpleHFilter16i; 698466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 699466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Aroraextern void VP8DspInitSSE2(void); 700a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern void VP8DspInitNEON(void); 7019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 70203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Aroravoid VP8DspInit(void) { 703a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora DspInitTables(); 704a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 705a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8Transform = TransformTwo; 706a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8TransformUV = TransformUV; 707a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8TransformDC = TransformDC; 708a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8TransformDCUV = TransformDCUV; 709a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 710a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8VFilter16 = VFilter16; 711a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8HFilter16 = HFilter16; 712a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8VFilter8 = VFilter8; 713a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8HFilter8 = HFilter8; 714a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8VFilter16i = VFilter16i; 715a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8HFilter16i = HFilter16i; 716a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8VFilter8i = VFilter8i; 717a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8HFilter8i = HFilter8i; 718a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8SimpleVFilter16 = SimpleVFilter16; 719a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8SimpleHFilter16 = SimpleHFilter16; 720a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8SimpleVFilter16i = SimpleVFilter16i; 721a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8SimpleHFilter16i = SimpleHFilter16i; 722a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 723466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // If defined, use CPUInfo() to overwrite some pointers with faster versions. 724a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (VP8GetCPUInfo) { 725a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#if defined(WEBP_USE_SSE2) 726a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (VP8GetCPUInfo(kSSE2)) { 727466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8DspInitSSE2(); 728466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora } 729a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#elif defined(WEBP_USE_NEON) 730a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (VP8GetCPUInfo(kNEON)) { 731a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora VP8DspInitNEON(); 732466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora } 733a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 734466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora } 7359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} 7369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 7379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 7389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} // extern "C" 7399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 740