1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
static void check_lumConvertRange(int from)
{
const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg";
#define LARGEST_INPUT_SIZE 512
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
SwsContext *sws;
SwsInternal *c;
LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]);
declare_func(void, int16_t *dst, int width);
sws = sws_alloc_context();
if (sws_init_context(sws, NULL, NULL) < 0)
fail();
c = sws_internal(sws);
c->srcFormat = AV_PIX_FMT_YUV444P;
c->dstFormat = AV_PIX_FMT_YUV444P;
c->srcRange = from;
c->dstRange = !from;
for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) {
int width = input_sizes[dstWi];
for (int i = 0; i < width; i++) {
uint8_t r = rnd();
dst0[i] = (int16_t) r << 7;
dst1[i] = (int16_t) r << 7;
}
ff_sws_init_scale(c);
if (check_func(c->lumConvertRange, "%s_%d", func_str, width)) {
call_ref(dst0, width);
call_new(dst1, width);
if (memcmp(dst0, dst1, width * sizeof(int16_t)))
fail();
bench_new(dst1, width);
}
}
sws_freeContext(sws);
}
#undef LARGEST_INPUT_SIZE
static void check_chrConvertRange(int from)
{
const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg";
#define LARGEST_INPUT_SIZE 512
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
SwsContext *sws;
SwsInternal *c;
LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE]);
declare_func(void, int16_t *dstU, int16_t *dstV, int width);
sws = sws_alloc_context();
if (sws_init_context(sws, NULL, NULL) < 0)
fail();
c = sws_internal(sws);
c->srcFormat = AV_PIX_FMT_YUV444P;
c->dstFormat = AV_PIX_FMT_YUV444P;
c->srcRange = from;
c->dstRange = !from;
for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) {
int width = input_sizes[dstWi];
for (int i = 0; i < width; i++) {
uint8_t r = rnd();
dstU0[i] = (int16_t) r << 7;
dstV0[i] = (int16_t) r << 7;
dstU1[i] = (int16_t) r << 7;
dstV1[i] = (int16_t) r << 7;
}
ff_sws_init_scale(c);
if (check_func(c->chrConvertRange, "%s_%d", func_str, width)) {
call_ref(dstU0, dstV0, width);
call_new(dstU1, dstV1, width);
if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) ||
memcmp(dstV0, dstV1, width * sizeof(int16_t)))
fail();
bench_new(dstU1, dstV1, width);
}
}
sws_freeContext(sws);
}
#undef LARGEST_INPUT_SIZE
void checkasm_check_sw_range_convert(void)
{
check_lumConvertRange(1);
report("lumRangeFromJpeg");
check_chrConvertRange(1);
report("chrRangeFromJpeg");
check_lumConvertRange(0);
report("lumRangeToJpeg");
check_chrConvertRange(0);
report("chrRangeToJpeg");
}
|