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 {
30 
31  if (have_lsx(cpu_flags)) {
32  if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
33  if (c->dstBpc <= 14) {
34  if (c->srcRange) {
35  c->lumConvertRange = lumRangeFromJpeg_lsx;
36  c->chrConvertRange = chrRangeFromJpeg_lsx;
37  } else {
38  c->lumConvertRange = lumRangeToJpeg_lsx;
39  c->chrConvertRange = chrRangeToJpeg_lsx;
40  }
41  }
42  }
43  }
44 #if HAVE_LASX
45  if (have_lasx(cpu_flags)) {
46  if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
47  if (c->dstBpc <= 14) {
48  if (c->srcRange) {
49  c->lumConvertRange = lumRangeFromJpeg_lasx;
50  c->chrConvertRange = chrRangeFromJpeg_lasx;
51  } else {
52  c->lumConvertRange = lumRangeToJpeg_lasx;
53  c->chrConvertRange = chrRangeToJpeg_lasx;
54  }
55  }
56  }
57  }
58 #endif // #if HAVE_LASX
59 }
60 
62 {
64  if (have_lsx(cpu_flags)) {
65  ff_sws_init_output_lsx(c, &c->yuv2plane1, &c->yuv2planeX,
66  &c->yuv2nv12cX, &c->yuv2packed1,
67  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
69  if (c->srcBpc == 8) {
70  if (c->dstBpc <= 14) {
71  c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
72  } else {
73  c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
74  }
75  } else {
76  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
78  }
79  }
80 #if HAVE_LASX
81  if (have_lasx(cpu_flags)) {
82  ff_sws_init_output_lasx(c, &c->yuv2plane1, &c->yuv2planeX,
83  &c->yuv2nv12cX, &c->yuv2packed1,
84  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
86  if (c->srcBpc == 8) {
87  if (c->dstBpc <= 14) {
88  c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
89  } else {
90  c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
91  }
92  } else {
93  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
95  }
96  }
97 #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->srcFormat == AV_PIX_FMT_YUV420P) {
116  switch (c->dstFormat) {
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->srcFormat)) {
123  break;
124  } else
125  return yuv420_rgba32_lasx;
126  case AV_PIX_FMT_ARGB:
127  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
128  break;
129  } else
130  return yuv420_argb32_lasx;
131  case AV_PIX_FMT_BGRA:
132  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
133  break;
134  } else
135  return yuv420_bgra32_lasx;
136  case AV_PIX_FMT_ABGR:
137  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
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->srcFormat == AV_PIX_FMT_YUV420P) {
147  switch (c->dstFormat) {
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->srcFormat)) {
154  break;
155  } else
156  return yuv420_rgba32_lsx;
157  case AV_PIX_FMT_ARGB:
158  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
159  break;
160  } else
161  return yuv420_argb32_lsx;
162  case AV_PIX_FMT_BGRA:
163  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
164  break;
165  } else
166  return yuv420_bgra32_lsx;
167  case AV_PIX_FMT_ABGR:
168  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
169  break;
170  } else
171  return yuv420_abgr32_lsx;
172  }
173  }
174  }
175  return NULL;
176 }
yuv420_bgr24_lsx
int yuv420_bgr24_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
chrRangeFromJpeg_lsx
void chrRangeFromJpeg_lsx(int16_t *dstU, int16_t *dstV, int width)
yuv420_rgb24_lsx
int yuv420_rgb24_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
have_lasx
#define have_lasx(flags)
Definition: cpu.h:29
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:107
ff_sws_init_output_lasx
av_cold void ff_sws_init_output_lasx(SwsContext *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:1778
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:56
SwsFunc
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: swscale_internal.h:99
swscale_loongarch.h
ff_yuv2rgb_init_loongarch
av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c)
Definition: swscale_init_loongarch.c:110
ff_hscale_8_to_15_lsx
void ff_hscale_8_to_15_lsx(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
ff_sws_init_input_lasx
av_cold void ff_sws_init_input_lasx(SwsContext *c)
Definition: input_lasx.c:204
av_cold
#define av_cold
Definition: attributes.h:90
ff_sws_init_swscale_loongarch
av_cold void ff_sws_init_swscale_loongarch(SwsContext *c)
Definition: swscale_init_loongarch.c:61
yuv420_abgr32_lsx
int yuv420_abgr32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
lumRangeToJpeg_lsx
void lumRangeToJpeg_lsx(int16_t *dst, int width)
ff_hscale_8_to_19_lsx
void ff_hscale_8_to_19_lsx(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
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
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:88
NULL
#define NULL
Definition: coverity.c:32
ff_hscale_16_to_15_lsx
void ff_hscale_16_to_15_lsx(SwsContext *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
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
yuv420_bgra32_lsx
int yuv420_bgra32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
lumRangeFromJpeg_lsx
void lumRangeFromJpeg_lsx(int16_t *dst, int width)
isAnyRGB
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:835
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
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
ff_sws_init_range_convert_loongarch
av_cold void ff_sws_init_range_convert_loongarch(SwsContext *c)
Definition: swscale_init_loongarch.c:27
swscale_internal.h
ff_sws_init_output_lsx
av_cold void ff_sws_init_output_lsx(SwsContext *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:1627
ff_hscale_8_to_15_lasx
void ff_hscale_8_to_15_lasx(SwsContext *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
ff_hscale_16_to_19_lasx
void ff_hscale_16_to_19_lasx(SwsContext *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
yuv420_argb32_lsx
int yuv420_argb32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
ff_hscale_16_to_15_lasx
void ff_hscale_16_to_15_lasx(SwsContext *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
ff_sws_init_input_lsx
av_cold void ff_sws_init_input_lsx(SwsContext *c)
Definition: input_lsx.c:24
rgb2rgb_init_loongarch
av_cold void rgb2rgb_init_loongarch(void)
Definition: swscale_init_loongarch.c:101
yuv420_rgba32_lsx
int yuv420_rgba32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
ff_hscale_8_to_19_lasx
void ff_hscale_8_to_19_lasx(SwsContext *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
SwsContext
Definition: swscale_internal.h:299
cpu.h
ff_hscale_16_to_19_lsx
void ff_hscale_16_to_19_lsx(SwsContext *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
rgb2rgb.h
isALPHA
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:857