History

swscale/range_convert: saturate output instead of limiting input

For bit depths <= 14, the result is saturated to 15 bits. For bit depths > 14, the result is saturated to 19 bits. x86_64: chrRangeFromJpeg8_1920_c: 2126.5 2127.4 (1.00x) chrRangeFromJpeg16_1920_c: 2331.4 2325.2 (1.00x) chrRangeToJpeg8_1920_c: 3163.0 3166.9 (1.00x) chrRangeToJpeg16_1920_c: 3163.7 2152.4 (1.47x) lumRangeFromJpeg8_1920_c: 1262.2 1263.0 (1.00x) lumRangeFromJpeg16_1920_c: 1079.5 1080.5 (1.00x) lumRangeToJpeg8_1920_c: 1860.5 1886.8 (0.99x) lumRangeToJpeg16_1920_c: 1910.2 1077.0 (1.77x) aarch64 A55: chrRangeFromJpeg8_1920_c: 28836.2 28835.2 (1.00x) chrRangeFromJpeg16_1920_c: 28840.1 28839.8 (1.00x) chrRangeToJpeg8_1920_c: 44196.2 23074.7 (1.92x) chrRangeToJpeg16_1920_c: 36527.3 17318.9 (2.11x) lumRangeFromJpeg8_1920_c: 15388.5 15389.7 (1.00x) lumRangeFromJpeg16_1920_c: 15389.3 15388.2 (1.00x) lumRangeToJpeg8_1920_c: 23069.7 19227.8 (1.20x) lumRangeToJpeg16_1920_c: 19227.8 15387.0 (1.25x) aarch64 A76: chrRangeFromJpeg8_1920_c: 6334.7 6324.4 (1.00x) chrRangeFromJpeg16_1920_c: 6336.0 6339.9 (1.00x) chrRangeToJpeg8_1920_c: 11474.5 9656.0 (1.19x) chrRangeToJpeg16_1920_c: 9640.5 6340.4 (1.52x) lumRangeFromJpeg8_1920_c: 4453.2 4422.0 (1.01x) lumRangeFromJpeg16_1920_c: 4414.2 4420.9 (1.00x) lumRangeToJpeg8_1920_c: 6645.0 5949.1 (1.12x) lumRangeToJpeg16_1920_c: 6005.2 4446.8 (1.35x)

Ramiro Polla committed 2 years ago

Commit 2d1358a1 parent 536a44e5 files · +29 −10Browse files

Unified · Split

5 files
  1. libswscale/aarch64/swscale.c +5 −0
  2. libswscale/loongarch/swscale_init_loongarch.c +5 −0
  3. libswscale/riscv/swscale.c +5 −0
  4. libswscale/swscale.c +14 −7
  5. libswscale/x86/range_convert.asm +0 −3
libswscale/aarch64/swscale.c+5−0
@@ -225,6 +225,10 @@ void ff_chrRangeToJpeg_neon(int16_t *dstU, int16_t *dstV, int width); · 224 unmodified lines
225 225
226av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c)226av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c)
227{227{
228 /* This code is currently disabled because of changes in the base
229 * implementation of these functions. This code should be enabled
230 * again once those changes are ported to this architecture. */
231#if 0
228 int cpu_flags = av_get_cpu_flags();232 int cpu_flags = av_get_cpu_flags();
229 233
230 if (have_neon(cpu_flags)) {234 if (have_neon(cpu_flags)) {
@@ -238,6 +242,7 @@ av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c) · 7 unmodified lines
238 }242 }
239 }243 }
240 }244 }
245#endif
241}246}
242 247
243av_cold void ff_sws_init_swscale_aarch64(SwsInternal *c)248av_cold void ff_sws_init_swscale_aarch64(SwsInternal *c)
libswscale/loongarch/swscale_init_loongarch.c+5−0
@@ -26,6 +26,10 @@ · 25 unmodified lines
26 26
27av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c)27av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c)
28{28{
29 /* This code is currently disabled because of changes in the base
30 * implementation of these functions. This code should be enabled
31 * again once those changes are ported to this architecture. */
32#if 0
29 int cpu_flags = av_get_cpu_flags();33 int cpu_flags = av_get_cpu_flags();
30 34
31 if (have_lsx(cpu_flags)) {35 if (have_lsx(cpu_flags)) {
@@ -52,6 +56,7 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c) · 20 unmodified lines
52 }56 }
53 }57 }
54#endif // #if HAVE_LASX58#endif // #if HAVE_LASX
59#endif
55}60}
56 61
57av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c)62av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c)
libswscale/riscv/swscale.c+5−0
@@ -28,6 +28,10 @@ void ff_range_chr_from_jpeg_16_rvv(int16_t *, int16_t *, int); · 27 unmodified lines
28 28
29av_cold void ff_sws_init_range_convert_riscv(SwsInternal *c)29av_cold void ff_sws_init_range_convert_riscv(SwsInternal *c)
30{30{
31 /* This code is currently disabled because of changes in the base
32 * implementation of these functions. This code should be enabled
33 * again once those changes are ported to this architecture. */
34#if 0
31#if HAVE_RVV35#if HAVE_RVV
32 int flags = av_get_cpu_flags();36 int flags = av_get_cpu_flags();
33 37
@@ -47,6 +51,7 @@ av_cold void ff_sws_init_range_convert_riscv(SwsInternal *c) · 13 unmodified lines
47 c->chrConvertRange = convs[from].chr;51 c->chrConvertRange = convs[from].chr;
48 }52 }
49#endif53#endif
54#endif
50}55}
51 56
52#define RVV_INPUT(name) \57#define RVV_INPUT(name) \
libswscale/swscale.c+14−7
@@ -160,8 +160,10 @@ static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width) · 159 unmodified lines
160{160{
161 int i;161 int i;
162 for (i = 0; i < width; i++) {162 for (i = 0; i < width; i++) {
163 dstU[i] = (FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12; // -264163 int U = (dstU[i] * 4663 - 9289992) >> 12; // -264
164 dstV[i] = (FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12; // -264164 int V = (dstV[i] * 4663 - 9289992) >> 12; // -264
165 dstU[i] = FFMIN(U, (1 << 15) - 1);
166 dstV[i] = FFMIN(V, (1 << 15) - 1);
165 }167 }
166}168}
167 169
@@ -177,8 +179,10 @@ static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width) · 9 unmodified lines
177static void lumRangeToJpeg_c(int16_t *dst, int width)179static void lumRangeToJpeg_c(int16_t *dst, int width)
178{180{
179 int i;181 int i;
180 for (i = 0; i < width; i++)182 for (i = 0; i < width; i++) {
181 dst[i] = (FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;183 int Y = (dst[i] * 19077 - 39057361) >> 14;
184 dst[i] = FFMIN(Y, (1 << 15) - 1);
185 }
182}186}
183 187
184static void lumRangeFromJpeg_c(int16_t *dst, int width)188static void lumRangeFromJpeg_c(int16_t *dst, int width)
@@ -194,8 +198,10 @@ static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width) · 9 unmodified lines
194 int32_t *dstU = (int32_t *) _dstU;198 int32_t *dstU = (int32_t *) _dstU;
195 int32_t *dstV = (int32_t *) _dstV;199 int32_t *dstV = (int32_t *) _dstV;
196 for (i = 0; i < width; i++) {200 for (i = 0; i < width; i++) {
197 dstU[i] = ((int)(FFMIN(dstU[i], 30775 << 4) * 4663U - (9289992 << 4))) >> 12; // -264201 int U = ((int)(dstU[i] * 4663U - (9289992 << 4))) >> 12; // -264
198 dstV[i] = ((int)(FFMIN(dstV[i], 30775 << 4) * 4663U - (9289992 << 4))) >> 12; // -264202 int V = ((int)(dstV[i] * 4663U - (9289992 << 4))) >> 12; // -264
203 dstU[i] = FFMIN(U, (1 << 19) - 1);
204 dstV[i] = FFMIN(V, (1 << 19) - 1);
199 }205 }
200}206}
201 207
@@ -215,7 +221,8 @@ static void lumRangeToJpeg16_c(int16_t *_dst, int width) · 13 unmodified lines
215 int i;221 int i;
216 int32_t *dst = (int32_t *) _dst;222 int32_t *dst = (int32_t *) _dst;
217 for (i = 0; i < width; i++) {223 for (i = 0; i < width; i++) {
218 dst[i] = ((int)(FFMIN(dst[i], 30189 << 4) * 4769U - (39057361 << 2))) >> 12;224 int Y = ((int)(dst[i] * 4769U - (39057361 << 2))) >> 12;
225 dst[i] = FFMIN(Y, (1 << 19) - 1);
219 }226 }
220}227}
221 228
libswscale/x86/range_convert.asm+0−3
@@ -40,9 +40,6 @@ lum_from_offset: times 4 dd 33561947 · 39 unmodified lines
40 40
41SECTION .text41SECTION .text
42 42
43; NOTE: there is no need to clamp the input when converting to jpeg range
44; (like we do in the C code) because packssdw will saturate the output.
45
46;-----------------------------------------------------------------------------43;-----------------------------------------------------------------------------
47; lumConvertRange44; lumConvertRange
48;45;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t