Coverage Report

Created: 2026-05-30 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/sharpyuv/sharpyuv_dsp.c
Line
Count
Source
1
// Copyright 2022 Google Inc. All Rights Reserved.
2
//
3
// Use of this source code is governed by a BSD-style license
4
// that can be found in the COPYING file in the root of the source
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
9
//
10
// Speed-critical functions for Sharp YUV.
11
//
12
// Author: Skal (pascal.massimino@gmail.com)
13
14
#include "./sharpyuv_dsp.h"
15
16
#include <assert.h>
17
#include <stdlib.h>
18
19
#include "./sharpyuv_cpu.h"
20
#include "src/dsp/cpu.h"
21
#include "webp/types.h"
22
23
//-----------------------------------------------------------------------------
24
25
#if !WEBP_NEON_OMIT_C_CODE
26
291M
static uint16_t clip(int v, int max) {
27
291M
  return (v < 0) ? 0 : (v > max) ? max : (uint16_t)v;
28
291M
}
29
30
static uint64_t SharpYuvUpdateY_C(const uint16_t* ref, const uint16_t* src,
31
496k
                                  uint16_t* dst, int len, int bit_depth) {
32
496k
  uint64_t diff = 0;
33
496k
  int i;
34
496k
  const int max_y = (1 << bit_depth) - 1;
35
74.7M
  for (i = 0; i < len; ++i) {
36
74.2M
    const int diff_y = ref[i] - src[i];
37
74.2M
    const int new_y = (int)dst[i] + diff_y;
38
74.2M
    dst[i] = clip(new_y, max_y);
39
74.2M
    diff += (uint64_t)abs(diff_y);
40
74.2M
  }
41
496k
  return diff;
42
496k
}
43
44
static void SharpYuvUpdateRGB_C(const int16_t* ref, const int16_t* src,
45
496k
                                int16_t* dst, int len) {
46
496k
  int i;
47
56.2M
  for (i = 0; i < len; ++i) {
48
55.7M
    const int diff_uv = ref[i] - src[i];
49
55.7M
    dst[i] += diff_uv;
50
55.7M
  }
51
496k
}
52
53
static void SharpYuvFilterRow_C(const int16_t* A, const int16_t* B, int len,
54
                                const uint16_t* best_y, uint16_t* out,
55
2.97M
                                int bit_depth) {
56
2.97M
  int i;
57
2.97M
  const int max_y = (1 << bit_depth) - 1;
58
111M
  for (i = 0; i < len; ++i, ++A, ++B) {
59
108M
    const int v0 = (A[0] * 9 + A[1] * 3 + B[0] * 3 + B[1] + 8) >> 4;
60
108M
    const int v1 = (A[1] * 9 + A[0] * 3 + B[1] * 3 + B[0] + 8) >> 4;
61
108M
    out[2 * i + 0] = clip(best_y[2 * i + 0] + v0, max_y);
62
108M
    out[2 * i + 1] = clip(best_y[2 * i + 1] + v1, max_y);
63
108M
  }
64
2.97M
}
65
#endif  // !WEBP_NEON_OMIT_C_CODE
66
67
//-----------------------------------------------------------------------------
68
69
uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,
70
                            uint16_t* dst, int len, int bit_depth);
71
void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, int16_t* dst,
72
                          int len);
73
void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
74
                          const uint16_t* best_y, uint16_t* out, int bit_depth);
75
76
extern VP8CPUInfo SharpYuvGetCPUInfo;
77
extern void InitSharpYuvSSE2(void);
78
extern void InitSharpYuvNEON(void);
79
80
8.43k
void SharpYuvInitDsp(void) {
81
8.43k
#if !WEBP_NEON_OMIT_C_CODE
82
8.43k
  SharpYuvUpdateY = SharpYuvUpdateY_C;
83
8.43k
  SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
84
8.43k
  SharpYuvFilterRow = SharpYuvFilterRow_C;
85
8.43k
#endif
86
87
8.43k
  if (SharpYuvGetCPUInfo != NULL) {
88
8.43k
#if defined(WEBP_HAVE_SSE2)
89
8.43k
    if (SharpYuvGetCPUInfo(kSSE2)) {
90
5.78k
      InitSharpYuvSSE2();
91
5.78k
    }
92
8.43k
#endif  // WEBP_HAVE_SSE2
93
8.43k
  }
94
95
#if defined(WEBP_HAVE_NEON)
96
  if (WEBP_NEON_OMIT_C_CODE ||
97
      (SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) {
98
    InitSharpYuvNEON();
99
  }
100
#endif  // WEBP_HAVE_NEON
101
102
8.43k
  assert(SharpYuvUpdateY != NULL);
103
8.43k
  assert(SharpYuvUpdateRGB != NULL);
104
  assert(SharpYuvFilterRow != NULL);
105
8.43k
}