FFmpeg
sw_range_convert.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <string.h>
20 
21 #include "libavutil/common.h"
22 #include "libavutil/intreadwrite.h"
23 #include "libavutil/mem.h"
24 #include "libavutil/mem_internal.h"
25 
26 #include "libswscale/swscale.h"
28 
29 #include "checkasm.h"
30 
31 static void check_lumConvertRange(int from)
32 {
33  const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg";
34 #define LARGEST_INPUT_SIZE 512
35 #define INPUT_SIZES 6
36  static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
37  struct SwsContext *ctx;
38 
39  LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]);
40  LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]);
41 
42  declare_func(void, int16_t *dst, int width);
43 
45  if (sws_init_context(ctx, NULL, NULL) < 0)
46  fail();
47 
50  ctx->srcRange = from;
51  ctx->dstRange = !from;
52 
53  for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
54  int width = input_sizes[dstWi];
55  for (int i = 0; i < width; i++) {
56  uint8_t r = rnd();
57  dst0[i] = (int16_t) r << 7;
58  dst1[i] = (int16_t) r << 7;
59  }
61  if (check_func(ctx->lumConvertRange, "%s_%d", func_str, width)) {
62  call_ref(dst0, width);
63  call_new(dst1, width);
64  if (memcmp(dst0, dst1, width * sizeof(int16_t)))
65  fail();
66  bench_new(dst1, width);
67  }
68  }
69 
71 }
72 #undef LARGEST_INPUT_SIZE
73 #undef INPUT_SIZES
74 
75 static void check_chrConvertRange(int from)
76 {
77  const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg";
78 #define LARGEST_INPUT_SIZE 512
79 #define INPUT_SIZES 6
80  static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
81  struct SwsContext *ctx;
82 
83  LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]);
84  LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]);
85  LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE]);
86  LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE]);
87 
88  declare_func(void, int16_t *dstU, int16_t *dstV, int width);
89 
91  if (sws_init_context(ctx, NULL, NULL) < 0)
92  fail();
93 
96  ctx->srcRange = from;
97  ctx->dstRange = !from;
98 
99  for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
100  int width = input_sizes[dstWi];
101  for (int i = 0; i < width; i++) {
102  uint8_t r = rnd();
103  dstU0[i] = (int16_t) r << 7;
104  dstV0[i] = (int16_t) r << 7;
105  dstU1[i] = (int16_t) r << 7;
106  dstV1[i] = (int16_t) r << 7;
107  }
109  if (check_func(ctx->chrConvertRange, "%s_%d", func_str, width)) {
110  call_ref(dstU0, dstV0, width);
111  call_new(dstU1, dstV1, width);
112  if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) ||
113  memcmp(dstV0, dstV1, width * sizeof(int16_t)))
114  fail();
115  bench_new(dstU1, dstV1, width);
116  }
117  }
118 
120 }
121 #undef LARGEST_INPUT_SIZE
122 #undef INPUT_SIZES
123 
125 {
127  report("lumRangeFromJpeg");
129  report("chrRangeFromJpeg");
131  report("lumRangeToJpeg");
133  report("chrRangeToJpeg");
134 }
r
const char * r
Definition: vf_curves.c:127
mem_internal.h
check_func
#define check_func(func,...)
Definition: checkasm.h:176
call_ref
#define call_ref(...)
Definition: checkasm.h:191
fail
#define fail()
Definition: checkasm.h:185
checkasm.h
check_chrConvertRange
static void check_chrConvertRange(int from)
Definition: sw_range_convert.c:75
LARGEST_INPUT_SIZE
#define LARGEST_INPUT_SIZE
rnd
#define rnd()
Definition: checkasm.h:169
width
#define width
intreadwrite.h
input_sizes
static const int input_sizes[]
Definition: sw_rgb.c:186
from
const char * from
Definition: jacosubdec.c:66
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
call_new
#define call_new(...)
Definition: checkasm.h:294
NULL
#define NULL
Definition: coverity.c:32
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
sws_alloc_context
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
Definition: utils.c:1217
INPUT_SIZES
#define INPUT_SIZES
ff_sws_init_scale
void ff_sws_init_scale(SwsContext *c)
Definition: swscale.c:591
report
#define report
Definition: checkasm.h:188
bench_new
#define bench_new(...)
Definition: checkasm.h:365
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
common.h
swscale_internal.h
check_lumConvertRange
static void check_lumConvertRange(int from)
Definition: sw_range_convert.c:31
sws_init_context
av_warn_unused_result int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:2073
sws_freeContext
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2437
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
checkasm_check_sw_range_convert
void checkasm_check_sw_range_convert(void)
Definition: sw_range_convert.c:124
mem.h
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:180
SwsContext
Definition: swscale_internal.h:301
swscale.h