2022-02-18 11:19:18 +01:00
|
|
|
// Copyright 2022 Google Inc. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Speed-critical functions for Sharp YUV.
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
|
|
|
#include "sharpyuv/sharpyuv_dsp.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-10-22 04:04:53 +02:00
|
|
|
#include "sharpyuv/sharpyuv_cpu.h"
|
2022-02-18 11:19:18 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if !WEBP_NEON_OMIT_C_CODE
|
2022-05-17 15:02:31 +02:00
|
|
|
static uint16_t clip(int v, int max) {
|
|
|
|
return (v < 0) ? 0 : (v > max) ? max : (uint16_t)v;
|
2022-02-18 11:19:18 +01:00
|
|
|
}
|
|
|
|
|
2022-04-11 11:55:10 +02:00
|
|
|
static uint64_t SharpYuvUpdateY_C(const uint16_t* ref, const uint16_t* src,
|
2022-05-17 15:02:31 +02:00
|
|
|
uint16_t* dst, int len, int bit_depth) {
|
2022-02-18 11:19:18 +01:00
|
|
|
uint64_t diff = 0;
|
|
|
|
int i;
|
2022-05-17 15:02:31 +02:00
|
|
|
const int max_y = (1 << bit_depth) - 1;
|
2022-02-18 11:19:18 +01:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
const int diff_y = ref[i] - src[i];
|
|
|
|
const int new_y = (int)dst[i] + diff_y;
|
2022-05-17 15:02:31 +02:00
|
|
|
dst[i] = clip(new_y, max_y);
|
2022-02-18 11:19:18 +01:00
|
|
|
diff += (uint64_t)abs(diff_y);
|
|
|
|
}
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
2022-04-11 11:55:10 +02:00
|
|
|
static void SharpYuvUpdateRGB_C(const int16_t* ref, const int16_t* src,
|
2022-02-18 11:19:18 +01:00
|
|
|
int16_t* dst, int len) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
const int diff_uv = ref[i] - src[i];
|
|
|
|
dst[i] += diff_uv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 11:55:10 +02:00
|
|
|
static void SharpYuvFilterRow_C(const int16_t* A, const int16_t* B, int len,
|
2022-05-17 15:02:31 +02:00
|
|
|
const uint16_t* best_y, uint16_t* out,
|
|
|
|
int bit_depth) {
|
2022-02-18 11:19:18 +01:00
|
|
|
int i;
|
2022-05-17 15:02:31 +02:00
|
|
|
const int max_y = (1 << bit_depth) - 1;
|
2022-02-18 11:19:18 +01:00
|
|
|
for (i = 0; i < len; ++i, ++A, ++B) {
|
|
|
|
const int v0 = (A[0] * 9 + A[1] * 3 + B[0] * 3 + B[1] + 8) >> 4;
|
|
|
|
const int v1 = (A[1] * 9 + A[0] * 3 + B[1] * 3 + B[0] + 8) >> 4;
|
2022-05-17 15:02:31 +02:00
|
|
|
out[2 * i + 0] = clip(best_y[2 * i + 0] + v0, max_y);
|
|
|
|
out[2 * i + 1] = clip(best_y[2 * i + 1] + v1, max_y);
|
2022-02-18 11:19:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !WEBP_NEON_OMIT_C_CODE
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2022-04-11 11:55:10 +02:00
|
|
|
uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,
|
2022-05-17 15:02:31 +02:00
|
|
|
uint16_t* dst, int len, int bit_depth);
|
2022-04-11 11:55:10 +02:00
|
|
|
void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, int16_t* dst,
|
2022-02-18 11:19:18 +01:00
|
|
|
int len);
|
2022-04-11 11:55:10 +02:00
|
|
|
void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
|
2022-05-17 15:02:31 +02:00
|
|
|
const uint16_t* best_y, uint16_t* out,
|
|
|
|
int bit_depth);
|
2022-02-18 11:19:18 +01:00
|
|
|
|
2023-04-26 22:22:52 +02:00
|
|
|
extern VP8CPUInfo SharpYuvGetCPUInfo;
|
2022-04-11 11:55:10 +02:00
|
|
|
extern void InitSharpYuvSSE2(void);
|
|
|
|
extern void InitSharpYuvNEON(void);
|
2022-02-18 11:19:18 +01:00
|
|
|
|
2022-10-22 04:04:53 +02:00
|
|
|
void SharpYuvInitDsp(void) {
|
2022-02-18 11:19:18 +01:00
|
|
|
#if !WEBP_NEON_OMIT_C_CODE
|
2022-04-11 11:55:10 +02:00
|
|
|
SharpYuvUpdateY = SharpYuvUpdateY_C;
|
|
|
|
SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
|
|
|
|
SharpYuvFilterRow = SharpYuvFilterRow_C;
|
2022-02-18 11:19:18 +01:00
|
|
|
#endif
|
|
|
|
|
2022-10-22 04:04:53 +02:00
|
|
|
if (SharpYuvGetCPUInfo != NULL) {
|
2022-02-18 11:19:18 +01:00
|
|
|
#if defined(WEBP_HAVE_SSE2)
|
2022-10-22 04:04:53 +02:00
|
|
|
if (SharpYuvGetCPUInfo(kSSE2)) {
|
|
|
|
InitSharpYuvSSE2();
|
|
|
|
}
|
2022-02-18 11:19:18 +01:00
|
|
|
#endif // WEBP_HAVE_SSE2
|
2022-10-22 04:04:53 +02:00
|
|
|
}
|
2022-02-18 11:19:18 +01:00
|
|
|
|
|
|
|
#if defined(WEBP_HAVE_NEON)
|
2022-10-22 04:04:53 +02:00
|
|
|
if (WEBP_NEON_OMIT_C_CODE ||
|
|
|
|
(SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) {
|
2022-04-11 11:55:10 +02:00
|
|
|
InitSharpYuvNEON();
|
2022-02-18 11:19:18 +01:00
|
|
|
}
|
|
|
|
#endif // WEBP_HAVE_NEON
|
|
|
|
|
2022-04-11 11:55:10 +02:00
|
|
|
assert(SharpYuvUpdateY != NULL);
|
|
|
|
assert(SharpYuvUpdateRGB != NULL);
|
|
|
|
assert(SharpYuvFilterRow != NULL);
|
2022-02-18 11:19:18 +01:00
|
|
|
}
|