Path: blob/master/thirdparty/libwebp/sharpyuv/sharpyuv_dsp.c
9898 views
// Copyright 2022 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Speed-critical functions for Sharp YUV.10//11// Author: Skal ([email protected])1213#include "sharpyuv/sharpyuv_dsp.h"1415#include <assert.h>16#include <stdlib.h>1718#include "sharpyuv/sharpyuv_cpu.h"19#include "src/webp/types.h"2021//-----------------------------------------------------------------------------2223#if !WEBP_NEON_OMIT_C_CODE24static uint16_t clip(int v, int max) {25return (v < 0) ? 0 : (v > max) ? max : (uint16_t)v;26}2728static uint64_t SharpYuvUpdateY_C(const uint16_t* ref, const uint16_t* src,29uint16_t* dst, int len, int bit_depth) {30uint64_t diff = 0;31int i;32const int max_y = (1 << bit_depth) - 1;33for (i = 0; i < len; ++i) {34const int diff_y = ref[i] - src[i];35const int new_y = (int)dst[i] + diff_y;36dst[i] = clip(new_y, max_y);37diff += (uint64_t)abs(diff_y);38}39return diff;40}4142static void SharpYuvUpdateRGB_C(const int16_t* ref, const int16_t* src,43int16_t* dst, int len) {44int i;45for (i = 0; i < len; ++i) {46const int diff_uv = ref[i] - src[i];47dst[i] += diff_uv;48}49}5051static void SharpYuvFilterRow_C(const int16_t* A, const int16_t* B, int len,52const uint16_t* best_y, uint16_t* out,53int bit_depth) {54int i;55const int max_y = (1 << bit_depth) - 1;56for (i = 0; i < len; ++i, ++A, ++B) {57const int v0 = (A[0] * 9 + A[1] * 3 + B[0] * 3 + B[1] + 8) >> 4;58const int v1 = (A[1] * 9 + A[0] * 3 + B[1] * 3 + B[0] + 8) >> 4;59out[2 * i + 0] = clip(best_y[2 * i + 0] + v0, max_y);60out[2 * i + 1] = clip(best_y[2 * i + 1] + v1, max_y);61}62}63#endif // !WEBP_NEON_OMIT_C_CODE6465//-----------------------------------------------------------------------------6667uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,68uint16_t* dst, int len, int bit_depth);69void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, int16_t* dst,70int len);71void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,72const uint16_t* best_y, uint16_t* out, int bit_depth);7374extern VP8CPUInfo SharpYuvGetCPUInfo;75extern void InitSharpYuvSSE2(void);76extern void InitSharpYuvNEON(void);7778void SharpYuvInitDsp(void) {79#if !WEBP_NEON_OMIT_C_CODE80SharpYuvUpdateY = SharpYuvUpdateY_C;81SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;82SharpYuvFilterRow = SharpYuvFilterRow_C;83#endif8485if (SharpYuvGetCPUInfo != NULL) {86#if defined(WEBP_HAVE_SSE2)87if (SharpYuvGetCPUInfo(kSSE2)) {88InitSharpYuvSSE2();89}90#endif // WEBP_HAVE_SSE291}9293#if defined(WEBP_HAVE_NEON)94if (WEBP_NEON_OMIT_C_CODE ||95(SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) {96InitSharpYuvNEON();97}98#endif // WEBP_HAVE_NEON99100assert(SharpYuvUpdateY != NULL);101assert(SharpYuvUpdateRGB != NULL);102assert(SharpYuvFilterRow != NULL);103}104105106