FFmpeg
swscale_init_loongarch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Loongson Technology Corporation Limited
3  * Contributed by Hao Chen(chenhao@loongson.cn)
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "swscale_loongarch.h"
24 #include "libswscale/rgb2rgb.h"
26 
28 {
29  /* This code is currently disabled because of changes in the base
30  * implementation of these functions. This code should be enabled
31  * again once those changes are ported to this architecture. */
32 #if 0
34 
35  if (have_lsx(cpu_flags)) {
36  if (c->dstBpc <= 14) {
37  if (c->opts.src_range) {
38  c->lumConvertRange = lumRangeFromJpeg_lsx;
39  c->chrConvertRange = chrRangeFromJpeg_lsx;
40  } else {
41  c->lumConvertRange = lumRangeToJpeg_lsx;
42  c->chrConvertRange = chrRangeToJpeg_lsx;
43  }
44  }
45  }
46 #if HAVE_LASX
47  if (have_lasx(cpu_flags)) {
48  if (c->dstBpc <= 14) {
49  if (c->opts.src_range) {
50  c->lumConvertRange = lumRangeFromJpeg_lasx;
51  c->chrConvertRange = chrRangeFromJpeg_lasx;
52  } else {
53  c->lumConvertRange = lumRangeToJpeg_lasx;
54  c->chrConvertRange = chrRangeToJpeg_lasx;
55  }
56  }
57  }
58 #endif // #if HAVE_LASX
59 #endif
60 }
61 
63 {
65  if (have_lsx(cpu_flags)) {
66  ff_sws_init_output_lsx(c, &c->yuv2plane1, &c->yuv2planeX,
67  &c->yuv2nv12cX, &c->yuv2packed1,
68  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
70  if (c->srcBpc == 8) {
71  if (c->dstBpc <= 14) {
72  c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
73  } else {
74  c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
75  }
76  } else {
77  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
79  }
80  }
81 #if HAVE_LASX
82  if (have_lasx(cpu_flags)) {
83  ff_sws_init_output_lasx(c, &c->yuv2plane1, &c->yuv2planeX,
84  &c->yuv2nv12cX, &c->yuv2packed1,
85  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
87  if (c->srcBpc == 8) {
88  if (c->dstBpc <= 14) {
89  c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
90  } else {
91  c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
92  }
93  } else {
94  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
96  }
97  }
98 #endif // #if HAVE_LASX
99 }
100 
102 {
103 #if HAVE_LASX
104  int cpu_flags = av_get_cpu_flags();
105  if (have_lasx(cpu_flags))
107 #endif // #if HAVE_LASX
108 }
109 
111 {
112  int cpu_flags = av_get_cpu_flags();
113 #if HAVE_LASX
114  if (have_lasx(cpu_flags)) {
115  if (c->opts.src_format == AV_PIX_FMT_YUV420P) {
116  switch (c->opts.dst_format) {
117  case AV_PIX_FMT_RGB24:
118  return yuv420_rgb24_lasx;
119  case AV_PIX_FMT_BGR24:
120  return yuv420_bgr24_lasx;
121  case AV_PIX_FMT_RGBA:
122  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
123  break;
124  } else
125  return yuv420_rgba32_lasx;
126  case AV_PIX_FMT_ARGB:
127  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
128  break;
129  } else
130  return yuv420_argb32_lasx;
131  case AV_PIX_FMT_BGRA:
132  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
133  break;
134  } else
135  return yuv420_bgra32_lasx;
136  case AV_PIX_FMT_ABGR:
137  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
138  break;
139  } else
140  return yuv420_abgr32_lasx;
141  }
142  }
143  }
144 #endif // #if HAVE_LASX
145  if (have_lsx(cpu_flags)) {
146  if (c->opts.src_format == AV_PIX_FMT_YUV420P) {
147  switch (c->opts.dst_format) {
148  case AV_PIX_FMT_RGB24:
149  return yuv420_rgb24_lsx;
150  case AV_PIX_FMT_BGR24:
151  return yuv420_bgr24_lsx;
152  case AV_PIX_FMT_RGBA:
153  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
154  break;
155  } else
156  return yuv420_rgba32_lsx;
157  case AV_PIX_FMT_ARGB:
158  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
159  break;
160  } else
161  return yuv420_argb32_lsx;
162  case AV_PIX_FMT_BGRA:
163  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
164  break;
165  } else
166  return yuv420_bgra32_lsx;
167  case AV_PIX_FMT_ABGR:
168  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format)) {
169  break;
170  } else
171  return yuv420_abgr32_lsx;
172  }
173  }
174  }
175  return NULL;
176 }
ff_hscale_8_to_19_lasx
void ff_hscale_8_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lasx.c:474
ff_hscale_16_to_15_lsx
void ff_hscale_16_to_15_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lsx.c:26
ff_sws_init_range_convert_loongarch
av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c)
Definition: swscale_init_loongarch.c:27
chrRangeFromJpeg_lsx
void chrRangeFromJpeg_lsx(int16_t *dstU, int16_t *dstV, int width)
have_lasx
#define have_lasx(flags)
Definition: cpu.h:29
yuv420_argb32_lsx
int yuv420_argb32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:56
swscale_loongarch.h
ff_hscale_8_to_19_lsx
void ff_hscale_8_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
av_cold
#define av_cold
Definition: attributes.h:90
ff_hscale_8_to_15_lasx
void ff_hscale_8_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lasx.c:314
lumRangeToJpeg_lsx
void lumRangeToJpeg_lsx(int16_t *dst, int width)
ff_sws_init_input_lsx
av_cold void ff_sws_init_input_lsx(SwsInternal *c)
Definition: input_lsx.c:24
ff_sws_init_input_lasx
av_cold void ff_sws_init_input_lasx(SwsInternal *c)
Definition: input_lasx.c:204
yuv420_bgr24_lsx
int yuv420_bgr24_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
ff_hscale_16_to_15_lasx
void ff_hscale_16_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lasx.c:676
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
yuv420_rgba32_lsx
int yuv420_rgba32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
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:92
NULL
#define NULL
Definition: coverity.c:32
ff_sws_init_output_lsx
av_cold void ff_sws_init_output_lsx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX)
Definition: output_lsx.c:1612
chrRangeToJpeg_lsx
void chrRangeToJpeg_lsx(int16_t *dstU, int16_t *dstV, int width)
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
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
have_lsx
#define have_lsx(flags)
Definition: cpu.h:28
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
ff_sws_init_swscale_loongarch
av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c)
Definition: swscale_init_loongarch.c:62
lumRangeFromJpeg_lsx
void lumRangeFromJpeg_lsx(int16_t *dst, int width)
ff_interleave_bytes_lasx
void ff_interleave_bytes_lasx(const uint8_t *src1, const uint8_t *src2, uint8_t *dest, int width, int height, int src1Stride, int src2Stride, int dstStride)
Definition: rgb2rgb_lasx.c:25
ff_yuv2rgb_init_loongarch
av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c)
Definition: swscale_init_loongarch.c:110
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
yuv420_bgra32_lsx
int yuv420_bgra32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale_internal.h
ff_sws_init_output_lasx
av_cold void ff_sws_init_output_lasx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX)
Definition: output_lasx.c:1757
yuv420_rgb24_lsx
int yuv420_rgb24_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
SwsInternal
Definition: swscale_internal.h:317
ff_hscale_16_to_19_lasx
void ff_hscale_16_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lasx.c:823
ff_hscale_8_to_15_lsx
void ff_hscale_8_to_15_lsx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
yuv420_abgr32_lsx
int yuv420_abgr32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
SwsFunc
int(* SwsFunc)(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_internal.h:92
rgb2rgb_init_loongarch
av_cold void rgb2rgb_init_loongarch(void)
Definition: swscale_init_loongarch.c:101
cpu.h
rgb2rgb.h
ff_hscale_16_to_19_lsx
void ff_hscale_16_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale_lsx.c:42
isALPHA
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:878