Path: blob/master/thirdparty/libwebp/sharpyuv/sharpyuv_dsp.c
21345 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/dsp/cpu.h"20#include "src/webp/types.h"2122//-----------------------------------------------------------------------------2324#if !WEBP_NEON_OMIT_C_CODE25static uint16_t clip(int v, int max) {26return (v < 0) ? 0 : (v > max) ? max : (uint16_t)v;27}2829static uint64_t SharpYuvUpdateY_C(const uint16_t* ref, const uint16_t* src,30uint16_t* dst, int len, int bit_depth) {31uint64_t diff = 0;32int i;33const int max_y = (1 << bit_depth) - 1;34for (i = 0; i < len; ++i) {35const int diff_y = ref[i] - src[i];36const int new_y = (int)dst[i] + diff_y;37dst[i] = clip(new_y, max_y);38diff += (uint64_t)abs(diff_y);39}40return diff;41}4243static void SharpYuvUpdateRGB_C(const int16_t* ref, const int16_t* src,44int16_t* dst, int len) {45int i;46for (i = 0; i < len; ++i) {47const int diff_uv = ref[i] - src[i];48dst[i] += diff_uv;49}50}5152static void SharpYuvFilterRow_C(const int16_t* A, const int16_t* B, int len,53const uint16_t* best_y, uint16_t* out,54int bit_depth) {55int i;56const int max_y = (1 << bit_depth) - 1;57for (i = 0; i < len; ++i, ++A, ++B) {58const int v0 = (A[0] * 9 + A[1] * 3 + B[0] * 3 + B[1] + 8) >> 4;59const int v1 = (A[1] * 9 + A[0] * 3 + B[1] * 3 + B[0] + 8) >> 4;60out[2 * i + 0] = clip(best_y[2 * i + 0] + v0, max_y);61out[2 * i + 1] = clip(best_y[2 * i + 1] + v1, max_y);62}63}64#endif // !WEBP_NEON_OMIT_C_CODE6566//-----------------------------------------------------------------------------6768uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,69uint16_t* dst, int len, int bit_depth);70void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, int16_t* dst,71int len);72void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,73const uint16_t* best_y, uint16_t* out, int bit_depth);7475extern VP8CPUInfo SharpYuvGetCPUInfo;76extern void InitSharpYuvSSE2(void);77extern void InitSharpYuvNEON(void);7879void SharpYuvInitDsp(void) {80#if !WEBP_NEON_OMIT_C_CODE81SharpYuvUpdateY = SharpYuvUpdateY_C;82SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;83SharpYuvFilterRow = SharpYuvFilterRow_C;84#endif8586if (SharpYuvGetCPUInfo != NULL) {87#if defined(WEBP_HAVE_SSE2)88if (SharpYuvGetCPUInfo(kSSE2)) {89InitSharpYuvSSE2();90}91#endif // WEBP_HAVE_SSE292}9394#if defined(WEBP_HAVE_NEON)95if (WEBP_NEON_OMIT_C_CODE ||96(SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) {97InitSharpYuvNEON();98}99#endif // WEBP_HAVE_NEON100101assert(SharpYuvUpdateY != NULL);102assert(SharpYuvUpdateRGB != NULL);103assert(SharpYuvFilterRow != NULL);104}105106107