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  if (have_lsx(cpu_flags)) {
32  if (c->srcBpc == 8) {
33  if (c->dstBpc <= 14) {
34  c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
35  } else {
36  c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
37  }
38  } else {
39  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
41  }
42  switch (c->srcFormat) {
43  case AV_PIX_FMT_GBRAP:
44  case AV_PIX_FMT_GBRP:
45  {
46  c->readChrPlanar = planar_rgb_to_uv_lsx;
47  c->readLumPlanar = planar_rgb_to_y_lsx;
48  }
49  break;
50  }
51  if (c->dstBpc == 8)
52  c->yuv2planeX = ff_yuv2planeX_8_lsx;
53  }
54 #if HAVE_LASX
55  if (have_lasx(cpu_flags)) {
57  if (c->srcBpc == 8) {
58  if (c->dstBpc <= 14) {
59  c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
60  } else {
61  c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
62  }
63  } else {
64  c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
66  }
67  switch (c->srcFormat) {
68  case AV_PIX_FMT_GBRAP:
69  case AV_PIX_FMT_GBRP:
70  {
71  c->readChrPlanar = planar_rgb_to_uv_lasx;
72  c->readLumPlanar = planar_rgb_to_y_lasx;
73  }
74  break;
75  }
76  if (c->dstBpc == 8)
77  c->yuv2planeX = ff_yuv2planeX_8_lasx;
78  }
79 #endif // #if HAVE_LASX
80 }
81 
83 {
84 #if HAVE_LASX
86  if (have_lasx(cpu_flags))
88 #endif // #if HAVE_LASX
89 }
90 
92 {
94 #if HAVE_LASX
95  if (have_lasx(cpu_flags)) {
96  switch (c->dstFormat) {
97  case AV_PIX_FMT_RGB24:
98  return yuv420_rgb24_lasx;
99  case AV_PIX_FMT_BGR24:
100  return yuv420_bgr24_lasx;
101  case AV_PIX_FMT_RGBA:
102  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
103  break;
104  } else
105  return yuv420_rgba32_lasx;
106  case AV_PIX_FMT_ARGB:
107  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
108  break;
109  } else
110  return yuv420_argb32_lasx;
111  case AV_PIX_FMT_BGRA:
112  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
113  break;
114  } else
115  return yuv420_bgra32_lasx;
116  case AV_PIX_FMT_ABGR:
117  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
118  break;
119  } else
120  return yuv420_abgr32_lasx;
121  }
122  }
123 #endif // #if HAVE_LASX
124  if (have_lsx(cpu_flags)) {
125  switch (c->dstFormat) {
126  case AV_PIX_FMT_RGB24:
127  return yuv420_rgb24_lsx;
128  case AV_PIX_FMT_BGR24:
129  return yuv420_bgr24_lsx;
130  case AV_PIX_FMT_RGBA:
131  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
132  break;
133  } else
134  return yuv420_rgba32_lsx;
135  case AV_PIX_FMT_ARGB:
136  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
137  break;
138  } else
139  return yuv420_argb32_lsx;
140  case AV_PIX_FMT_BGRA:
141  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
142  break;
143  } else
144  return yuv420_bgra32_lsx;
145  case AV_PIX_FMT_ABGR:
146  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
147  break;
148  } else
149  return yuv420_abgr32_lsx;
150  }
151  }
152  return NULL;
153 }
ff_yuv2planeX_8_lasx
void ff_yuv2planeX_8_lasx(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output_lasx.c:25
yuv420_bgr24_lsx
int yuv420_bgr24_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
planar_rgb_to_uv_lsx
void planar_rgb_to_uv_lsx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv, void *opq)
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
ff_sws_init_output_lasx
av_cold void ff_sws_init_output_lasx(SwsContext *c)
Definition: output_lasx.c:1778
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:103
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
planar_rgb_to_y_lsx
void planar_rgb_to_y_lsx(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv, void *opq)
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
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
swscale_loongarch.h
ff_yuv2rgb_init_loongarch
av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c)
Definition: swscale_init_loongarch.c:91
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)
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:27
yuv420_abgr32_lsx
int yuv420_abgr32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
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_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
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
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_yuv2planeX_8_lsx
void ff_yuv2planeX_8_lsx(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
swscale_internal.h
planar_rgb_to_uv_lasx
void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv, void *opq)
Definition: input_lasx.c:25
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[])
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
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
rgb2rgb_init_loongarch
av_cold void rgb2rgb_init_loongarch(void)
Definition: swscale_init_loongarch.c:82
yuv420_rgba32_lsx
int yuv420_rgba32_lsx(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
planar_rgb_to_y_lasx
void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv, void *opq)
Definition: input_lasx.c:127
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
ff_sws_init_output_lsx
av_cold void ff_sws_init_output_lsx(SwsContext *c)
Definition: output_lsx.c:1627
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:854