FFmpeg
Loading...
Searching...
No Matches
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
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdio.h>
20
21#include "libavutil/common.h"
22#include "libavutil/cpu.h"
24#include "libavutil/pixdesc.h"
26
27int main(void)
28{
29 static const enum AVPixelFormat formats[] = {
33 };
34 const int cpu_flags = av_get_cpu_flags();
37
38 if (!sws)
39 return 1;
40 c = sws_internal(sws);
41
42 for (int native = 0; native < 2; native++) {
43 av_force_cpu_flags(native ? cpu_flags : 0);
44 for (int p = 0; p < FF_ARRAY_ELEMS(formats); p++) {
45 const int depth = av_pix_fmt_desc_get(formats[p])->comp[0].depth;
46 const int shift = (depth <= 14 ? 15 : 19) - depth;
47 const int center = 128 << (depth - 8);
48 const int samples[] = {
49 0, 16 << (depth - 8), center - 1, center,
50 center + 1, 235 << (depth - 8), 240 << (depth - 8),
51 (1 << depth) - 1,
52 };
53 DECLARE_ALIGNED(32, int16_t, u16)[16];
54 DECLARE_ALIGNED(32, int16_t, v16)[16];
55 DECLARE_ALIGNED(32, int32_t, u32)[16];
56 DECLARE_ALIGNED(32, int32_t, v32)[16];
57
58 sws->src_format = sws->dst_format = formats[p];
59 c->dstBpc = depth;
60 for (int from = 0; from < 2; from++) {
61 sws->src_range = from;
62 sws->dst_range = !from;
64 for (int i = 0; i < 16; i++) {
65 const int u = samples[i % 8] << shift;
66 const int v = samples[7 - i % 8] << shift;
67 if (depth == 16) {
68 u32[i] = u;
69 v32[i] = v;
70 } else {
71 u16[i] = u;
72 v16[i] = v;
73 }
74 }
75 c->chrConvertRange(depth == 16 ? (int16_t *) u32 : u16,
76 depth == 16 ? (int16_t *) v32 : v16, 16,
77 c->chrConvertRange_coeff,
78 c->chrConvertRange_offset);
79 printf("%s %2d-bit %s U:", native ? "native" : "c ",
80 depth, from ? "full-to-limited" : "limited-to-full");
81 for (int i = 0; i < 8; i++)
82 printf(" %d", depth == 16 ? u32[i] : u16[i]);
83 printf(" V:");
84 for (int i = 0; i < 8; i++)
85 printf(" %d", depth == 16 ? v32[i] : v16[i]);
86 printf("\n");
87 }
88 }
89 }
90
92 sws_freeContext(sws);
93 return 0;
94}
int32_t
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
common internal and external API header
__device__ int printf(const char *,...)
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition utils.c:1082
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2338
static int shift(int a, int b)
Definition bonk.c:261
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
const char * from
Definition jacosubdec.c:65
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition cpu.c:81
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:555
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:547
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:561
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:551
int main(void)
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
int depth
Number of bits in the component.
Definition pixdesc.h:57
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
Main external API structure.
Definition swscale.h:227
int dst_format
Destination pixel format.
Definition swscale.h:275
int src_format
Source pixel format.
Definition swscale.h:274
int dst_range
Destination is full range.
Definition swscale.h:277
int src_range
Source is full range.
Definition swscale.h:276
av_cold void ff_sws_init_range_convert(SwsInternal *c)
Definition swscale.c:652
static SwsInternal * sws_internal(const SwsContext *sws)
static double c[64]