Skip to content

Commit 5efd630

Browse files
committedJan 12, 2024
mv SharpYuvEstimate420Risk to extras/
There's no need for this in libsharpyuv currently. This avoids an ABI bump and library size increase. Change-Id: I3e4c79052fdb4d628a2d36491547233dd0b6dc34
1 parent e78e924 commit 5efd630

14 files changed

+207
-217
lines changed
 

‎Android.mk

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ sharpyuv_srcs := \
4242
sharpyuv/sharpyuv_dsp.c \
4343
sharpyuv/sharpyuv_gamma.c \
4444
sharpyuv/sharpyuv_neon.$(NEON) \
45-
sharpyuv/sharpyuv_risk_table.c \
4645
sharpyuv/sharpyuv_sse2.c \
4746

4847
dec_srcs := \

‎Makefile.vc

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ SHARPYUV_OBJS = \
185185
$(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \
186186
$(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \
187187
$(DIROBJ)\sharpyuv\sharpyuv_neon.obj \
188-
$(DIROBJ)\sharpyuv\sharpyuv_risk_table.obj \
189188
$(DIROBJ)\sharpyuv\sharpyuv_sse2.obj \
190189

191190
DEC_OBJS = \
@@ -322,6 +321,7 @@ ENC_OBJS = \
322321
EXTRAS_OBJS = \
323322
$(DIROBJ)\extras\extras.obj \
324323
$(DIROBJ)\extras\quality_estimate.obj \
324+
$(DIROBJ)\extras\sharpyuv_risk_table.obj \
325325

326326
IMAGEIO_UTIL_OBJS = \
327327
$(DIROBJ)\imageio\imageio_util.obj \

‎build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ model {
112112
include "sharpyuv_dsp.c"
113113
include "sharpyuv_gamma.c"
114114
include "sharpyuv_neon.c"
115-
include "sharpyuv_risk_table.c"
116115
include "sharpyuv_sse2.c"
117116
srcDir "src/dec"
118117
include "alpha_dec.c"

‎extras/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ noinst_HEADERS += ../src/webp/types.h
77

88
libwebpextras_la_SOURCES =
99
libwebpextras_la_SOURCES += extras.c extras.h quality_estimate.c
10+
libwebpextras_la_SOURCES += sharpyuv_risk_table.c sharpyuv_risk_table.h
1011

1112
libwebpextras_la_CPPFLAGS = $(AM_CPPFLAGS)
1213
libwebpextras_la_LDFLAGS = -lm

‎extras/extras.c

+164-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
//
1212

1313
#include "extras/extras.h"
14-
#include "webp/format_constants.h"
15-
#include "src/dsp/dsp.h"
1614

1715
#include <assert.h>
16+
#include <limits.h>
1817
#include <string.h>
1918

19+
#include "extras/sharpyuv_risk_table.h"
20+
#include "sharpyuv/sharpyuv.h"
21+
#include "src/dsp/dsp.h"
22+
#include "src/utils/utils.h"
23+
#include "webp/format_constants.h"
24+
#include "webp/types.h"
25+
2026
#define XTRA_MAJ_VERSION 1
2127
#define XTRA_MIN_VERSION 3
2228
#define XTRA_REV_VERSION 2
@@ -160,3 +166,159 @@ int WebPUnmultiplyARGB(WebPPicture* pic) {
160166
}
161167

162168
//------------------------------------------------------------------------------
169+
// 420 risk metric
170+
171+
#define YUV_FIX 16 // fixed-point precision for RGB->YUV
172+
static const int kYuvHalf = 1 << (YUV_FIX - 1);
173+
174+
// Maps a value in [0, (256 << YUV_FIX) - 1] to [0,
175+
// precomputed_scores_table_sampling - 1]. It is important that the extremal
176+
// values are preserved and 1:1 mapped:
177+
// ConvertValue(0) = 0
178+
// ConvertValue((256 << 16) - 1) = rgb_sampling_size - 1
179+
static int SharpYuvConvertValueToSampledIdx(int v, int rgb_sampling_size) {
180+
v = (v + kYuvHalf) >> YUV_FIX;
181+
v = (v < 0) ? 0 : (v > 255) ? 255 : v;
182+
return (v * (rgb_sampling_size - 1)) / 255;
183+
}
184+
185+
#undef YUV_FIX
186+
187+
// For each pixel, computes the index to look up that color in a precomputed
188+
// risk score table where the YUV space is subsampled to a size of
189+
// precomputed_scores_table_sampling^3 (see sharpyuv_risk_table.h)
190+
static int SharpYuvConvertToYuvSharpnessIndex(
191+
int r, int g, int b, const SharpYuvConversionMatrix* matrix,
192+
int precomputed_scores_table_sampling) {
193+
const int y = SharpYuvConvertValueToSampledIdx(
194+
matrix->rgb_to_y[0] * r + matrix->rgb_to_y[1] * g +
195+
matrix->rgb_to_y[2] * b + matrix->rgb_to_y[3],
196+
precomputed_scores_table_sampling);
197+
const int u = SharpYuvConvertValueToSampledIdx(
198+
matrix->rgb_to_u[0] * r + matrix->rgb_to_u[1] * g +
199+
matrix->rgb_to_u[2] * b + matrix->rgb_to_u[3],
200+
precomputed_scores_table_sampling);
201+
const int v = SharpYuvConvertValueToSampledIdx(
202+
matrix->rgb_to_v[0] * r + matrix->rgb_to_v[1] * g +
203+
matrix->rgb_to_v[2] * b + matrix->rgb_to_v[3],
204+
precomputed_scores_table_sampling);
205+
return y + u * precomputed_scores_table_sampling +
206+
v * precomputed_scores_table_sampling *
207+
precomputed_scores_table_sampling;
208+
}
209+
210+
static void SharpYuvRowToYuvSharpnessIndex(
211+
const uint8_t* r_ptr, const uint8_t* g_ptr, const uint8_t* b_ptr,
212+
int rgb_step, int rgb_bit_depth, int width, uint16_t* dst,
213+
const SharpYuvConversionMatrix* matrix,
214+
int precomputed_scores_table_sampling) {
215+
int i;
216+
assert(rgb_bit_depth == 8);
217+
(void)rgb_bit_depth; // Unused for now.
218+
for (i = 0; i < width;
219+
++i, r_ptr += rgb_step, g_ptr += rgb_step, b_ptr += rgb_step) {
220+
dst[i] =
221+
SharpYuvConvertToYuvSharpnessIndex(r_ptr[0], g_ptr[0], b_ptr[0], matrix,
222+
precomputed_scores_table_sampling);
223+
}
224+
}
225+
226+
#define SAFE_ALLOC(W, H, T) ((T*)WebPSafeMalloc((uint64_t)(W) * (H), sizeof(T)))
227+
228+
static int DoEstimateRisk(const uint8_t* r_ptr, const uint8_t* g_ptr,
229+
const uint8_t* b_ptr, int rgb_step, int rgb_stride,
230+
int rgb_bit_depth, int width, int height,
231+
const SharpYuvOptions* options,
232+
const uint8_t precomputed_scores_table[],
233+
int precomputed_scores_table_sampling,
234+
float* score_out) {
235+
const int sampling3 = precomputed_scores_table_sampling *
236+
precomputed_scores_table_sampling *
237+
precomputed_scores_table_sampling;
238+
const int kNoiseLevel = 4;
239+
double total_score = 0;
240+
double count = 0;
241+
// Rows of indices in
242+
uint16_t* row1 = SAFE_ALLOC(width, 1, uint16_t);
243+
uint16_t* row2 = SAFE_ALLOC(width, 1, uint16_t);
244+
uint16_t* tmp;
245+
int i, j;
246+
247+
if (row1 == NULL || row2 == NULL) {
248+
WebPFree(row1);
249+
WebPFree(row2);
250+
return 0;
251+
}
252+
253+
// Convert the first row ahead.
254+
SharpYuvRowToYuvSharpnessIndex(r_ptr, g_ptr, b_ptr, rgb_step, rgb_bit_depth,
255+
width, row2, options->yuv_matrix,
256+
precomputed_scores_table_sampling);
257+
258+
for (j = 1; j < height; ++j) {
259+
r_ptr += rgb_stride;
260+
g_ptr += rgb_stride;
261+
b_ptr += rgb_stride;
262+
// Swap row 1 and row 2.
263+
tmp = row1;
264+
row1 = row2;
265+
row2 = tmp;
266+
// Convert the row below.
267+
SharpYuvRowToYuvSharpnessIndex(r_ptr, g_ptr, b_ptr, rgb_step, rgb_bit_depth,
268+
width, row2, options->yuv_matrix,
269+
precomputed_scores_table_sampling);
270+
for (i = 0; i < width - 1; ++i) {
271+
const int idx0 = row1[i + 0];
272+
const int idx1 = row1[i + 1];
273+
const int idx2 = row2[i + 0];
274+
const int score = precomputed_scores_table[idx0 + sampling3 * idx1] +
275+
precomputed_scores_table[idx0 + sampling3 * idx2] +
276+
precomputed_scores_table[idx1 + sampling3 * idx2];
277+
if (score > kNoiseLevel) {
278+
total_score += score;
279+
count += 1.0;
280+
}
281+
}
282+
}
283+
if (count > 0.) total_score /= count;
284+
285+
// If less than 1% of pixels were evaluated -> below noise level.
286+
if (100. * count / (width * height) < 1.) total_score = 0.;
287+
288+
// Rescale to [0:100]
289+
total_score = (total_score > 25.) ? 100. : total_score * 100. / 25.;
290+
291+
WebPFree(row1);
292+
WebPFree(row2);
293+
294+
*score_out = (float)total_score;
295+
return 1;
296+
}
297+
298+
#undef SAFE_ALLOC
299+
300+
int SharpYuvEstimate420Risk(const void* r_ptr, const void* g_ptr,
301+
const void* b_ptr, int rgb_step, int rgb_stride,
302+
int rgb_bit_depth, int width, int height,
303+
const SharpYuvOptions* options, float* score) {
304+
if (width < 1 || height < 1 || width == INT_MAX || height == INT_MAX ||
305+
r_ptr == NULL || g_ptr == NULL || b_ptr == NULL || options == NULL ||
306+
score == NULL) {
307+
return 0;
308+
}
309+
if (rgb_bit_depth != 8) {
310+
return 0;
311+
}
312+
313+
if (width <= 4 || height <= 4) {
314+
*score = 0.0f; // too small, no real risk.
315+
return 1;
316+
}
317+
318+
return DoEstimateRisk(
319+
(const uint8_t*)r_ptr, (const uint8_t*)g_ptr, (const uint8_t*)b_ptr,
320+
rgb_step, rgb_stride, rgb_bit_depth, width, height, options,
321+
kSharpYuvPrecomputedRisk, kSharpYuvPrecomputedRiskYuvSampling, score);
322+
}
323+
324+
//------------------------------------------------------------------------------

‎extras/extras.h

+34-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
extern "C" {
1818
#endif
1919

20+
#include "sharpyuv/sharpyuv.h"
2021
#include "webp/encode.h"
2122

22-
#define WEBP_EXTRAS_ABI_VERSION 0x0002 // MAJOR(8b) + MINOR(8b)
23+
#define WEBP_EXTRAS_ABI_VERSION 0x0003 // MAJOR(8b) + MINOR(8b)
2324

2425
//------------------------------------------------------------------------------
2526

@@ -70,6 +71,38 @@ WEBP_EXTERN int VP8EstimateQuality(const uint8_t* const data, size_t size);
7071

7172
//------------------------------------------------------------------------------
7273

74+
// Computes a score between 0 and 100 which represents the risk of having visual
75+
// quality loss from converting an RGB image to YUV420.
76+
// A low score, typically < 40, means there is a low risk of artifacts from
77+
// chroma subsampling and a simple averaging algorithm can be used instead of
78+
// the more expensive SharpYuvConvert function.
79+
// A medium score, typically >= 40 and < 70, means that simple chroma
80+
// subsampling will produce artifacts and it may be advisable to use the more
81+
// costly SharpYuvConvert for YUV420 conversion.
82+
// A high score, typically >= 70, means there is a very high risk of artifacts
83+
// from chroma subsampling even with SharpYuvConvert, and best results might be
84+
// achieved by using YUV444.
85+
// If not using SharpYuvConvert, a threshold of about 50 can be used to decide
86+
// between (simple averaging) 420 and 444.
87+
// r_ptr, g_ptr, b_ptr: pointers to the source r, g and b channels. Should point
88+
// to uint8_t buffers if rgb_bit_depth is 8, or uint16_t buffers otherwise.
89+
// rgb_step: distance in bytes between two horizontally adjacent pixels on the
90+
// r, g and b channels. If rgb_bit_depth is > 8, it should be a
91+
// multiple of 2.
92+
// rgb_stride: distance in bytes between two vertically adjacent pixels on the
93+
// r, g, and b channels. If rgb_bit_depth is > 8, it should be a
94+
// multiple of 2.
95+
// rgb_bit_depth: number of bits for each r/g/b value. Only a value of 8 is
96+
// currently supported.
97+
// width, height: width and height of the image in pixels
98+
// Returns 0 on failure.
99+
WEBP_EXTERN int SharpYuvEstimate420Risk(
100+
const void* r_ptr, const void* g_ptr, const void* b_ptr, int rgb_step,
101+
int rgb_stride, int rgb_bit_depth, int width, int height,
102+
const SharpYuvOptions* options, float* score);
103+
104+
//------------------------------------------------------------------------------
105+
73106
#ifdef __cplusplus
74107
} // extern "C"
75108
#endif
File renamed without changes.

‎sharpyuv/sharpyuv_risk_table.h ‎extras/sharpyuv_risk_table.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//
1010
// Precomputed data for 420 risk estimation.
1111

12-
#ifndef WEBP_SHARPYUV_SHARPYUV_RISK_TABLE_H_
13-
#define WEBP_SHARPYUV_SHARPYUV_RISK_TABLE_H_
12+
#ifndef WEBP_EXTRAS_SHARPYUV_RISK_TABLE_H_
13+
#define WEBP_EXTRAS_SHARPYUV_RISK_TABLE_H_
1414

1515
#include "src/webp/types.h"
1616

@@ -24,4 +24,4 @@ extern const int kSharpYuvPrecomputedRiskYuvSampling;
2424
// Table size: kSharpYuvPrecomputedRiskYuvSampling^6 bytes or 114 KiB
2525
extern const uint8_t kSharpYuvPrecomputedRisk[];
2626

27-
#endif // WEBP_SHARPYUV_SHARPYUV_RISK_TABLE_H_
27+
#endif // WEBP_EXTRAS_SHARPYUV_RISK_TABLE_H_

‎makefile.unix

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ SHARPYUV_OBJS = \
133133
sharpyuv/sharpyuv_dsp.o \
134134
sharpyuv/sharpyuv_gamma.o \
135135
sharpyuv/sharpyuv_neon.o \
136-
sharpyuv/sharpyuv_risk_table.o \
137136
sharpyuv/sharpyuv_sse2.o \
138137

139138
DEC_OBJS = \
@@ -292,6 +291,7 @@ UTILS_ENC_OBJS = \
292291
EXTRA_OBJS = \
293292
extras/extras.o \
294293
extras/quality_estimate.o \
294+
extras/sharpyuv_risk_table.o \
295295

296296
LIBWEBPDECODER_OBJS = $(DEC_OBJS) $(DSP_DEC_OBJS) $(UTILS_DEC_OBJS)
297297
LIBWEBP_OBJS = $(LIBWEBPDECODER_OBJS) $(ENC_OBJS) \

‎sharpyuv/Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ libsharpyuv_la_SOURCES += sharpyuv_cpu.c sharpyuv_cpu.h
3030
libsharpyuv_la_SOURCES += sharpyuv_csp.c sharpyuv_csp.h
3131
libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h
3232
libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h
33-
libsharpyuv_la_SOURCES += sharpyuv_risk_table.c sharpyuv_risk_table.h
3433
libsharpyuv_la_SOURCES += sharpyuv.c sharpyuv.h
3534

3635
libsharpyuv_la_CPPFLAGS = $(AM_CPPFLAGS)

‎sharpyuv/sharpyuv.c

+2-103
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "sharpyuv/sharpyuv_cpu.h"
2424
#include "sharpyuv/sharpyuv_dsp.h"
2525
#include "sharpyuv/sharpyuv_gamma.h"
26-
#include "sharpyuv/sharpyuv_risk_table.h"
2726

2827
//------------------------------------------------------------------------------
2928

@@ -436,6 +435,8 @@ static int DoSharpArgbToYuv(const uint8_t* r_ptr, const uint8_t* g_ptr,
436435
return ok;
437436
}
438437

438+
#undef SAFE_ALLOC
439+
439440
#if defined(WEBP_USE_THREAD) && !defined(_WIN32)
440441
#include <pthread.h> // NOLINT
441442

@@ -571,105 +572,3 @@ int SharpYuvConvertWithOptions(const void* r_ptr, const void* g_ptr,
571572
}
572573

573574
//------------------------------------------------------------------------------
574-
// 420 risk metric
575-
576-
static int DoEstimateRisk(const uint8_t* r_ptr, const uint8_t* g_ptr,
577-
const uint8_t* b_ptr, int rgb_step, int rgb_stride,
578-
int rgb_bit_depth, int width, int height,
579-
const SharpYuvOptions* options,
580-
const uint8_t precomputed_scores_table[],
581-
int precomputed_scores_table_sampling,
582-
float* score_out) {
583-
const int sampling3 = precomputed_scores_table_sampling *
584-
precomputed_scores_table_sampling *
585-
precomputed_scores_table_sampling;
586-
const int kNoiseLevel = 4;
587-
double total_score = 0;
588-
double count = 0;
589-
// Rows of indices in
590-
uint16_t* row1 = SAFE_ALLOC(width, 1, uint16_t);
591-
uint16_t* row2 = SAFE_ALLOC(width, 1, uint16_t);
592-
uint16_t* tmp;
593-
int i, j;
594-
595-
if (row1 == NULL || row2 == NULL) {
596-
free(row1);
597-
free(row2);
598-
return 0;
599-
}
600-
601-
// Convert the first row ahead.
602-
SharpYuvRowToYuvSharpnessIndex(r_ptr, g_ptr, b_ptr, rgb_step, rgb_bit_depth,
603-
width, row2, options->yuv_matrix,
604-
precomputed_scores_table_sampling);
605-
606-
for (j = 1; j < height; ++j) {
607-
r_ptr += rgb_stride;
608-
g_ptr += rgb_stride;
609-
b_ptr += rgb_stride;
610-
// Swap row 1 and row 2.
611-
tmp = row1;
612-
row1 = row2;
613-
row2 = tmp;
614-
// Convert the row below.
615-
SharpYuvRowToYuvSharpnessIndex(r_ptr, g_ptr, b_ptr, rgb_step, rgb_bit_depth,
616-
width, row2, options->yuv_matrix,
617-
precomputed_scores_table_sampling);
618-
for (i = 0; i < width - 1; ++i) {
619-
const int idx0 = row1[i + 0];
620-
const int idx1 = row1[i + 1];
621-
const int idx2 = row2[i + 0];
622-
const int score = precomputed_scores_table[idx0 + sampling3 * idx1] +
623-
precomputed_scores_table[idx0 + sampling3 * idx2] +
624-
precomputed_scores_table[idx1 + sampling3 * idx2];
625-
if (score > kNoiseLevel) {
626-
total_score += score;
627-
count += 1.0;
628-
}
629-
}
630-
}
631-
if (count > 0.) total_score /= count;
632-
633-
// If less than 1% of pixels were evaluated -> below noise level.
634-
if (100. * count / (width * height) < 1.) total_score = 0.;
635-
636-
// Rescale to [0:100]
637-
total_score = (total_score > 25.) ? 100. : total_score * 100. / 25.;
638-
639-
free(row1);
640-
free(row2);
641-
642-
*score_out = (float)total_score;
643-
return 1;
644-
}
645-
646-
int SharpYuvEstimate420Risk(const void* r_ptr, const void* g_ptr,
647-
const void* b_ptr, int rgb_step, int rgb_stride,
648-
int rgb_bit_depth, int width, int height,
649-
const SharpYuvOptions* options, float* score) {
650-
if (width < 1 || height < 1 || width == INT_MAX || height == INT_MAX ||
651-
r_ptr == NULL || g_ptr == NULL || b_ptr == NULL || options == NULL ||
652-
score == NULL) {
653-
return 0;
654-
}
655-
if (rgb_bit_depth != 8) {
656-
return 0;
657-
}
658-
659-
if (width <= 4 || height <= 4) {
660-
*score = 0.0f; // too small, no real risk.
661-
return 1;
662-
}
663-
664-
// The address of the function pointer is used to avoid a read race.
665-
SharpYuvInit((VP8CPUInfo)&SharpYuvGetCPUInfo);
666-
667-
return DoEstimateRisk(
668-
(const uint8_t*)r_ptr, (const uint8_t*)g_ptr, (const uint8_t*)b_ptr,
669-
rgb_step, rgb_stride, rgb_bit_depth, width, height, options,
670-
kSharpYuvPrecomputedRisk, kSharpYuvPrecomputedRiskYuvSampling, score);
671-
}
672-
673-
#undef SAFE_ALLOC
674-
675-
//------------------------------------------------------------------------------

‎sharpyuv/sharpyuv.h

+1-31
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353

5454
// SharpYUV API version following the convention from semver.org
5555
#define SHARPYUV_VERSION_MAJOR 0
56-
#define SHARPYUV_VERSION_MINOR 5
56+
#define SHARPYUV_VERSION_MINOR 4
5757
#define SHARPYUV_VERSION_PATCH 0
5858
// Version as a uint32_t. The major number is the high 8 bits.
5959
// The minor number is the middle 8 bits. The patch number is the low 16 bits.
@@ -164,36 +164,6 @@ SHARPYUV_EXTERN int SharpYuvConvertWithOptions(
164164
int u_stride, void* v_ptr, int v_stride, int yuv_bit_depth, int width,
165165
int height, const SharpYuvOptions* options);
166166

167-
// Computes a score between 0 and 100 which represents the risk of having visual
168-
// quality loss from converting an RGB image to YUV420.
169-
// A low score, typically < 40, means there is a low risk of artifacts from
170-
// chroma subsampling and a simple averaging algorithm can be used instead of
171-
// the more expensive SharpYuvConvert function.
172-
// A medium score, typically >= 40 and < 70, means that simple chroma
173-
// subsampling will produce artifacts and it may be advisable to use the more
174-
// costly SharpYuvConvert for YUV420 conversion.
175-
// A high score, typically >= 70, means there is a very high risk of artifacts
176-
// from chroma subsampling even with SharpYuvConvert, and best results might be
177-
// achieved by using YUV444.
178-
// If not using SharpYuvConvert, a threshold of about 50 can be used to decide
179-
// between (simple averaging) 420 and 444.
180-
// r_ptr, g_ptr, b_ptr: pointers to the source r, g and b channels. Should point
181-
// to uint8_t buffers if rgb_bit_depth is 8, or uint16_t buffers otherwise.
182-
// rgb_step: distance in bytes between two horizontally adjacent pixels on the
183-
// r, g and b channels. If rgb_bit_depth is > 8, it should be a
184-
// multiple of 2.
185-
// rgb_stride: distance in bytes between two vertically adjacent pixels on the
186-
// r, g, and b channels. If rgb_bit_depth is > 8, it should be a
187-
// multiple of 2.
188-
// rgb_bit_depth: number of bits for each r/g/b value. Only a value of 8 is
189-
// currently supported.
190-
// width, height: width and height of the image in pixels
191-
// Returns 0 on failure.
192-
SHARPYUV_EXTERN int SharpYuvEstimate420Risk(
193-
const void* r_ptr, const void* g_ptr, const void* b_ptr, int rgb_step,
194-
int rgb_stride, int rgb_bit_depth, int width, int height,
195-
const SharpYuvOptions* options, float* score);
196-
197167
// TODO(b/194336375): Add YUV444 to YUV420 conversion. Maybe also add 422
198168
// support (it's rarely used in practice, especially for images).
199169

‎sharpyuv/sharpyuv_dsp.c

-62
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <assert.h>
1717
#include <stdlib.h>
1818

19-
#include "sharpyuv/sharpyuv.h"
2019
#include "sharpyuv/sharpyuv_cpu.h"
2120
#include "src/webp/types.h"
2221

@@ -64,58 +63,6 @@ static void SharpYuvFilterRow_C(const int16_t* A, const int16_t* B, int len,
6463
}
6564
#endif // !WEBP_NEON_OMIT_C_CODE
6665

67-
#define YUV_FIX 16 // fixed-point precision for RGB->YUV
68-
static const int kYuvHalf = 1 << (YUV_FIX - 1);
69-
70-
// Maps a value in [0, (256 << YUV_FIX) - 1] to [0,
71-
// precomputed_scores_table_sampling - 1]. It is important that the extremal
72-
// values are preserved and 1:1 mapped:
73-
// ConvertValue(0) = 0
74-
// ConvertValue((256 << 16) - 1) = rgb_sampling_size - 1
75-
static int SharpYuvConvertValueToSampledIdx(int v, int rgb_sampling_size) {
76-
v = (v + kYuvHalf) >> YUV_FIX;
77-
v = (v < 0) ? 0 : (v > 255) ? 255 : v;
78-
return (v * (rgb_sampling_size - 1)) / 255;
79-
}
80-
81-
#undef YUV_FIX
82-
83-
static int SharpYuvConvertToYuvSharpnessIndex(
84-
int r, int g, int b, const SharpYuvConversionMatrix* matrix,
85-
int precomputed_scores_table_sampling) {
86-
const int y = SharpYuvConvertValueToSampledIdx(
87-
matrix->rgb_to_y[0] * r + matrix->rgb_to_y[1] * g +
88-
matrix->rgb_to_y[2] * b + matrix->rgb_to_y[3],
89-
precomputed_scores_table_sampling);
90-
const int u = SharpYuvConvertValueToSampledIdx(
91-
matrix->rgb_to_u[0] * r + matrix->rgb_to_u[1] * g +
92-
matrix->rgb_to_u[2] * b + matrix->rgb_to_u[3],
93-
precomputed_scores_table_sampling);
94-
const int v = SharpYuvConvertValueToSampledIdx(
95-
matrix->rgb_to_v[0] * r + matrix->rgb_to_v[1] * g +
96-
matrix->rgb_to_v[2] * b + matrix->rgb_to_v[3],
97-
precomputed_scores_table_sampling);
98-
return y + u * precomputed_scores_table_sampling +
99-
v * precomputed_scores_table_sampling *
100-
precomputed_scores_table_sampling;
101-
}
102-
103-
static void SharpYuvRowToYuvSharpnessIndex_C(
104-
const uint8_t* r_ptr, const uint8_t* g_ptr, const uint8_t* b_ptr,
105-
int rgb_step, int rgb_bit_depth, int width, uint16_t* dst,
106-
const SharpYuvConversionMatrix* matrix,
107-
int precomputed_scores_table_sampling) {
108-
int i;
109-
assert(rgb_bit_depth == 8);
110-
(void)rgb_bit_depth; // Unused for now.
111-
for (i = 0; i < width;
112-
++i, r_ptr += rgb_step, g_ptr += rgb_step, b_ptr += rgb_step) {
113-
dst[i] =
114-
SharpYuvConvertToYuvSharpnessIndex(r_ptr[0], g_ptr[0], b_ptr[0], matrix,
115-
precomputed_scores_table_sampling);
116-
}
117-
}
118-
11966
//-----------------------------------------------------------------------------
12067

12168
uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,
@@ -124,13 +71,6 @@ void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, int16_t* dst,
12471
int len);
12572
void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
12673
const uint16_t* best_y, uint16_t* out, int bit_depth);
127-
void (*SharpYuvRowToYuvSharpnessIndex)(const uint8_t* r_ptr,
128-
const uint8_t* g_ptr,
129-
const uint8_t* b_ptr, int rgb_step,
130-
int rgb_bit_depth, int width,
131-
uint16_t* dst,
132-
const SharpYuvConversionMatrix* matrix,
133-
int precomputed_scores_table_sampling);
13474

13575
extern VP8CPUInfo SharpYuvGetCPUInfo;
13676
extern void InitSharpYuvSSE2(void);
@@ -142,8 +82,6 @@ void SharpYuvInitDsp(void) {
14282
SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
14383
SharpYuvFilterRow = SharpYuvFilterRow_C;
14484
#endif
145-
// There is only a C version for now so always include it.
146-
SharpYuvRowToYuvSharpnessIndex = SharpYuvRowToYuvSharpnessIndex_C;
14785

14886
if (SharpYuvGetCPUInfo != NULL) {
14987
#if defined(WEBP_HAVE_SSE2)

‎sharpyuv/sharpyuv_dsp.h

-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_
1313
#define WEBP_SHARPYUV_SHARPYUV_DSP_H_
1414

15-
#include "sharpyuv/sharpyuv.h"
1615
#include "sharpyuv/sharpyuv_cpu.h"
1716
#include "src/webp/types.h"
1817

@@ -24,15 +23,6 @@ extern void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
2423
const uint16_t* best_y, uint16_t* out,
2524
int bit_depth);
2625

27-
// For each pixel, computes the index to look up that color in a precomputed
28-
// risk score table where the YUV space is subsampled to a size of
29-
// precomputed_scores_table_sampling^3 (see sharpyuv_risk_table.h)
30-
extern void (*SharpYuvRowToYuvSharpnessIndex)(
31-
const uint8_t* r_ptr, const uint8_t* g_ptr, const uint8_t* b_ptr,
32-
int rgb_step, int rgb_bit_depth, int width, uint16_t* dst,
33-
const SharpYuvConversionMatrix* matrix,
34-
int precomputed_scores_table_sampling);
35-
3626
void SharpYuvInitDsp(void);
3727

3828
#endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_

0 commit comments

Comments
 (0)
Please sign in to comment.