FFmpeg
sw_xyz2rgb.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 Arpad Panyik <Arpad.Panyik@arm.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <string.h>
22 
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem_internal.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/pixfmt.h"
27 
28 #include "libswscale/swscale.h"
30 
31 #include "checkasm.h"
32 
33 #define NUM_LINES 4
34 #define MAX_LINE_SIZE 1920
35 
36 #define randomize_buffers(buf, size) \
37  do { \
38  for (int j = 0; j < size; j += 2) \
39  AV_WN32(buf + j, rnd()); \
40  } while (0)
41 
42 static void check_xyz12Torgb48le(void)
43 {
44  static const int input_sizes[] = {1, 2, 3, 4, 5, 6, 7, 8, 16, 17, 21, 31,
45  32, 64, 128, 256, 512, 1024,
47 
48  const int src_stride = 3 * sizeof(uint16_t) * MAX_LINE_SIZE;
49  const int dst_stride = src_stride;
50 
51  const int src_pix_fmt = AV_PIX_FMT_XYZ12LE;
52  const int dst_pix_fmt = AV_PIX_FMT_RGB48LE;
53 
54  const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
55  const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
56 
57  LOCAL_ALIGNED_8(uint16_t, src, [3 * MAX_LINE_SIZE * NUM_LINES]);
58  LOCAL_ALIGNED_8(uint16_t, dst_ref, [3 * MAX_LINE_SIZE * NUM_LINES]);
59  LOCAL_ALIGNED_8(uint16_t, dst_new, [3 * MAX_LINE_SIZE * NUM_LINES]);
60 
61  declare_func(void, const SwsInternal *, uint8_t *, int, const uint8_t *,
62  int, int, int);
63 
64  SwsInternal c;
65  memset(&c, 0, sizeof(c));
66  c.opts.src_format = src_pix_fmt;
69 
71 
72  for (int height = 1; height <= NUM_LINES; height++) {
73  for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
74  int width = input_sizes[isi];
75 
76  if (check_func(c.xyz12Torgb48, "%s_%s_%dx%d", src_desc->name,
77  dst_desc->name, width, height)) {
78  memset(dst_ref, 0xFE,
79  3 * sizeof(uint16_t) * MAX_LINE_SIZE * NUM_LINES);
80  memset(dst_new, 0xFE,
81  3 * sizeof(uint16_t) * MAX_LINE_SIZE * NUM_LINES);
82 
83  call_ref(&c, (uint8_t *)dst_ref, dst_stride,
84  (const uint8_t *)src, src_stride, width, height);
85  call_new(&c, (uint8_t *)dst_new, dst_stride,
86  (const uint8_t *)src, src_stride, width, height);
87 
88  checkasm_check(uint16_t, dst_ref, dst_stride, dst_new,
89  dst_stride, width, height, "dst_rgb");
90 
91  if (!(width & 3) && height == NUM_LINES) {
92  bench_new(&c, (uint8_t *)dst_new,
93  dst_stride, (const uint8_t *)src, src_stride,
94  width, height);
95  }
96  }
97  }
98  }
99 }
100 
101 #undef NUM_LINES
102 #undef MAX_LINE_SIZE
103 
105 {
107  report("xyz12Torgb48le");
108 }
AV_PIX_FMT_XYZ12LE
@ AV_PIX_FMT_XYZ12LE
packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as lit...
Definition: pixfmt.h:196
checkasm_check_sw_xyz2rgb
void checkasm_check_sw_xyz2rgb(void)
Definition: sw_xyz2rgb.c:104
mem_internal.h
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
pixdesc.h
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:70
check_func
#define check_func(func,...)
Definition: checkasm.h:205
NUM_LINES
#define NUM_LINES
Definition: sw_xyz2rgb.c:33
call_ref
#define call_ref(...)
Definition: checkasm.h:220
checkasm.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
check_xyz12Torgb48le
static void check_xyz12Torgb48le(void)
Definition: sw_xyz2rgb.c:42
MAX_LINE_SIZE
#define MAX_LINE_SIZE
Definition: sw_xyz2rgb.c:34
intreadwrite.h
input_sizes
static const int input_sizes[]
Definition: sw_rgb.c:347
LOCAL_ALIGNED_8
#define LOCAL_ALIGNED_8(t, v,...)
Definition: mem_internal.h:128
call_new
#define call_new(...)
Definition: checkasm.h:323
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:110
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_sws_init_xyzdsp
av_cold void ff_sws_init_xyzdsp(SwsInternal *c)
Definition: swscale.c:860
height
#define height
Definition: dsp.h:89
report
#define report
Definition: checkasm.h:217
bench_new
#define bench_new(...)
Definition: checkasm.h:408
swscale_internal.h
SwsInternal
Definition: swscale_internal.h:330
pixfmt.h
ff_sws_fill_xyztables
av_cold int ff_sws_fill_xyztables(SwsInternal *c)
Definition: utils.c:722
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:209
checkasm_check
#define checkasm_check(prefix,...)
Definition: checkasm.h:455
width
#define width
Definition: dsp.h:89
src
#define src
Definition: vp8dsp.c:248
swscale.h
randomize_buffers
#define randomize_buffers(buf, size)
Definition: sw_xyz2rgb.c:36