FFmpeg
sw_rgb.c
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <string.h>
21 
22 #include "libavutil/common.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/mem_internal.h"
26 
27 #include "libswscale/rgb2rgb.h"
28 
29 #include "checkasm.h"
30 
31 #define randomize_buffers(buf, size) \
32  do { \
33  int j; \
34  for (j = 0; j < size; j+=4) \
35  AV_WN32(buf + j, rnd()); \
36  } while (0)
37 
38 static const uint8_t width[] = {12, 16, 20, 32, 36, 128};
39 static const struct {uint8_t w, h, s;} planes[] = {
40  {12,16,12}, {16,16,16}, {20,23,25}, {32,18,48}, {8,128,16}, {128,128,128}
41 };
42 
43 #define MAX_STRIDE 128
44 #define MAX_HEIGHT 128
45 
46 static void check_shuffle_bytes(void * func, const char * report)
47 {
48  int i;
53 
54  declare_func_emms(AV_CPU_FLAG_MMX, void, const uint8_t *src, uint8_t *dst, int src_size);
55 
56  memset(dst0, 0, MAX_STRIDE);
57  memset(dst1, 0, MAX_STRIDE);
59  memcpy(src1, src0, MAX_STRIDE);
60 
61  if (check_func(func, "%s", report)) {
62  for (i = 0; i < 6; i ++) {
63  call_ref(src0, dst0, width[i]);
64  call_new(src1, dst1, width[i]);
65  if (memcmp(dst0, dst1, MAX_STRIDE))
66  fail();
67  }
68  bench_new(src0, dst0, width[5]);
69  }
70 }
71 
72 static void check_uyvy_to_422p(void)
73 {
74  int i;
75 
80  LOCAL_ALIGNED_32(uint8_t, dst_u_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
81  LOCAL_ALIGNED_32(uint8_t, dst_u_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
82  LOCAL_ALIGNED_32(uint8_t, dst_v_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
83  LOCAL_ALIGNED_32(uint8_t, dst_v_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
84 
85  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
86  const uint8_t *src, int width, int height,
87  int lumStride, int chromStride, int srcStride);
88 
90  memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT * 2);
91 
92  if (check_func(uyvytoyuv422, "uyvytoyuv422")) {
93  for (i = 0; i < 6; i ++) {
94  memset(dst_y_0, 0, MAX_STRIDE * MAX_HEIGHT);
95  memset(dst_y_1, 0, MAX_STRIDE * MAX_HEIGHT);
96  memset(dst_u_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
97  memset(dst_u_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
98  memset(dst_v_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
99  memset(dst_v_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
100 
101  call_ref(dst_y_0, dst_u_0, dst_v_0, src0, planes[i].w, planes[i].h,
102  MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
103  call_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[i].w, planes[i].h,
104  MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
105  if (memcmp(dst_y_0, dst_y_1, MAX_STRIDE * MAX_HEIGHT) ||
106  memcmp(dst_u_0, dst_u_1, (MAX_STRIDE/2) * MAX_HEIGHT) ||
107  memcmp(dst_v_0, dst_v_1, (MAX_STRIDE/2) * MAX_HEIGHT))
108  fail();
109  }
110  bench_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[5].w, planes[5].h,
111  MAX_STRIDE, MAX_STRIDE / 2, planes[5].s);
112  }
113 }
114 
115 static void check_interleave_bytes(void)
116 {
119  LOCAL_ALIGNED_16(uint8_t, dst0_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
120  LOCAL_ALIGNED_16(uint8_t, dst1_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
121  // Intentionally using unaligned buffers, as this function doesn't have
122  // any alignment requirements.
123  uint8_t *src0 = src0_buf + 1;
124  uint8_t *src1 = src1_buf + 1;
125  uint8_t *dst0 = dst0_buf + 2;
126  uint8_t *dst1 = dst1_buf + 2;
127 
128  declare_func_emms(AV_CPU_FLAG_MMX, void, const uint8_t *, const uint8_t *,
129  uint8_t *, int, int, int, int, int);
130 
133 
134  if (check_func(interleaveBytes, "interleave_bytes")) {
135  for (int i = 0; i <= 16; i++) {
136  // Try all widths [1,16], and try one random width.
137 
138  int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
139  int h = 1 + (rnd() % (MAX_HEIGHT-2));
140 
141  int src0_offset = 0, src0_stride = MAX_STRIDE;
142  int src1_offset = 0, src1_stride = MAX_STRIDE;
143  int dst_offset = 0, dst_stride = 2 * MAX_STRIDE;
144 
145  memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
146  memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
147 
148  // Try different combinations of negative strides
149  if (i & 1) {
150  src0_offset = (h-1)*src0_stride;
151  src0_stride = -src0_stride;
152  }
153  if (i & 2) {
154  src1_offset = (h-1)*src1_stride;
155  src1_stride = -src1_stride;
156  }
157  if (i & 4) {
158  dst_offset = (h-1)*dst_stride;
159  dst_stride = -dst_stride;
160  }
161 
162  call_ref(src0 + src0_offset, src1 + src1_offset, dst0 + dst_offset,
163  w, h, src0_stride, src1_stride, dst_stride);
164  call_new(src0 + src0_offset, src1 + src1_offset, dst1 + dst_offset,
165  w, h, src0_stride, src1_stride, dst_stride);
166  // Check a one pixel-pair edge around the destination area,
167  // to catch overwrites past the end.
168  checkasm_check(uint8_t, dst0, 2*MAX_STRIDE, dst1, 2*MAX_STRIDE,
169  2 * w + 2, h + 1, "dst");
170  }
171 
172  bench_new(src0, src1, dst1, 127, MAX_HEIGHT,
174  }
175  if (check_func(interleaveBytes, "interleave_bytes_aligned")) {
176  // Bench the function in a more typical case, with aligned
177  // buffers and widths.
178  bench_new(src0_buf, src1_buf, dst1_buf, 128, MAX_HEIGHT,
180  }
181 }
182 
184 {
186 
187  check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
188  report("shuffle_bytes_2103");
189 
190  check_shuffle_bytes(shuffle_bytes_0321, "shuffle_bytes_0321");
191  report("shuffle_bytes_0321");
192 
193  check_shuffle_bytes(shuffle_bytes_1230, "shuffle_bytes_1230");
194  report("shuffle_bytes_1230");
195 
196  check_shuffle_bytes(shuffle_bytes_3012, "shuffle_bytes_3012");
197  report("shuffle_bytes_3012");
198 
199  check_shuffle_bytes(shuffle_bytes_3210, "shuffle_bytes_3210");
200  report("shuffle_bytes_3210");
201 
203  report("uyvytoyuv422");
204 
206  report("interleave_bytes");
207 }
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:67
declare_func_emms
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:130
shuffle_bytes_3012
void(* shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:57
mem_internal.h
MAX_STRIDE
#define MAX_STRIDE
Definition: sw_rgb.c:43
h
uint8_t h
Definition: sw_rgb.c:39
check_func
#define check_func(func,...)
Definition: checkasm.h:124
shuffle_bytes_3210
void(* shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:58
call_ref
#define call_ref(...)
Definition: checkasm.h:139
check_shuffle_bytes
static void check_shuffle_bytes(void *func, const char *report)
Definition: sw_rgb.c:46
s
uint8_t s
Definition: sw_rgb.c:39
fail
#define fail()
Definition: checkasm.h:133
checkasm.h
randomize_buffers
#define randomize_buffers(buf, size)
Definition: sw_rgb.c:31
rnd
#define rnd()
Definition: checkasm.h:117
intreadwrite.h
check_uyvy_to_422p
static void check_uyvy_to_422p(void)
Definition: sw_rgb.c:72
shuffle_bytes_1230
void(* shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:56
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
shuffle_bytes_2103
void(* shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:55
interleaveBytes
void(* interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, int width, int height, int src1Stride, int src2Stride, int dstStride)
Definition: rgb2rgb.c:88
checkasm_check_sw_rgb
void checkasm_check_sw_rgb(void)
Definition: sw_rgb.c:183
call_new
#define call_new(...)
Definition: checkasm.h:211
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:136
planes
static const struct @323 planes[]
src
#define src
Definition: vp8dsp.c:255
ff_sws_rgb2rgb_init
av_cold void ff_sws_rgb2rgb_init(void)
Definition: rgb2rgb.c:137
MAX_HEIGHT
#define MAX_HEIGHT
Definition: sw_rgb.c:44
check_interleave_bytes
static void check_interleave_bytes(void)
Definition: sw_rgb.c:115
shuffle_bytes_0321
void(* shuffle_bytes_0321)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:54
height
#define height
src0
#define src0
Definition: h264pred.c:139
uyvytoyuv422
void(* uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride)
Definition: rgb2rgb.c:107
src1
#define src1
Definition: h264pred.c:140
report
#define report
Definition: checkasm.h:136
i
int i
Definition: input.c:407
bench_new
#define bench_new(...)
Definition: checkasm.h:271
common.h
width
static const uint8_t width[]
Definition: sw_rgb.c:38
uint8_t
uint8_t
Definition: audio_convert.c:194
w
uint8_t w
Definition: sw_rgb.c:39
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:31
mem.h
checkasm_check
#define checkasm_check(prefix,...)
Definition: checkasm.h:290
rgb2rgb.h