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->dstBpc <= 14) {
33  if (c->srcRange) {
34  c->lumConvertRange = lumRangeFromJpeg_lsx;
35  c->chrConvertRange = chrRangeFromJpeg_lsx;
36  } else {
37  c->lumConvertRange = lumRangeToJpeg_lsx;
38  c->chrConvertRange = chrRangeToJpeg_lsx;
39  }
40  }
41  }
42 #if HAVE_LASX
43  if (have_lasx(cpu_flags)) {
44  if (c->dstBpc <= 14) {
45  if (c->srcRange) {
46  c->lumConvertRange = lumRangeFromJpeg_lasx;
47  c->chrConvertRange = chrRangeFromJpeg_lasx;
48  } else {
49  c->lumConvertRange = lumRangeToJpeg_lasx;
50  c->chrConvertRange = chrRangeToJpeg_lasx;
51  }
52  }
53  }
54 #endif // #if HAVE_LASX
55 }
56 
58 {
60  if (have_lsx(cpu_flags)) {
61  ff_sws_init_output_lsx(c, &c->yuv2plane1, &c->yuv2planeX,
62  &c->yuv2nv12cX, &c->yuv2packed1,
63  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
65  if (c->srcBpc == 8) {
66  if (c->dstBpc <= 14) {
67  c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
68  } else {
69  c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
70  }
71  } else {
72  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
74  }
75  }
76 #if HAVE_LASX
77  if (have_lasx(cpu_flags)) {
78  ff_sws_init_output_lasx(c, &c->yuv2plane1, &c->yuv2planeX,
79  &c->yuv2nv12cX, &c->yuv2packed1,
80  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
82  if (c->srcBpc == 8) {
83  if (c->dstBpc <= 14) {
84  c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
85  } else {
86  c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
87  }
88  } else {
89  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
91  }
92  }
93 #endif // #if HAVE_LASX
94 }
95 
97 {
98 #if HAVE_LASX
100  if (have_lasx(cpu_flags))
102 #endif // #if HAVE_LASX
103 }
104 
106 {
107  int cpu_flags = av_get_cpu_flags();
108 #if HAVE_LASX
109  if (have_lasx(cpu_flags)) {
110  if (c->srcFormat == AV_PIX_FMT_YUV420P) {
111  switch (c->dstFormat) {
112  case AV_PIX_FMT_RGB24:
113  return yuv420_rgb24_lasx;
114  case AV_PIX_FMT_BGR24:
115  return yuv420_bgr24_lasx;
116  case AV_PIX_FMT_RGBA:
117  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
118  break;
119  } else
120  return yuv420_rgba32_lasx;
121  case AV_PIX_FMT_ARGB:
122  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
123  break;
124  } else
125  return yuv420_argb32_lasx;
126  case AV_PIX_FMT_BGRA:
127  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
128  break;
129  } else
130  return yuv420_bgra32_lasx;
131  case AV_PIX_FMT_ABGR:
132  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
133  break;
134  } else
135  return yuv420_abgr32_lasx;
136  }
137  }
138  }
139 #endif // #if HAVE_LASX
140  if (have_lsx(cpu_flags)) {
141  if (c->srcFormat == AV_PIX_FMT_YUV420P) {
142  switch (c->dstFormat) {
143  case AV_PIX_FMT_RGB24:
144  return yuv420_rgb24_lsx;
145  case AV_PIX_FMT_BGR24:
146  return yuv420_bgr24_lsx;
147  case AV_PIX_FMT_RGBA:
148  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
149  break;
150  } else
151  return yuv420_rgba32_lsx;
152  case AV_PIX_FMT_ARGB:
153  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
154  break;
155  } else
156  return yuv420_argb32_lsx;
157  case AV_PIX_FMT_BGRA:
158  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
159  break;
160  } else
161  return yuv420_bgra32_lsx;
162  case AV_PIX_FMT_ABGR:
163  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
164  break;
165  } else
166  return yuv420_abgr32_lsx;
167  }
168  }
169  }
170  return NULL;
171 }
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:107
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:1627
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:57
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:105
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:1778
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:330
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:105
rgb2rgb_init_loongarch
av_cold void rgb2rgb_init_loongarch(void)
Definition: swscale_init_loongarch.c:96
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:880