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  if (c->srcFormat == AV_PIX_FMT_YUV420P) {
97  switch (c->dstFormat) {
98  case AV_PIX_FMT_RGB24:
99  return yuv420_rgb24_lasx;
100  case AV_PIX_FMT_BGR24:
101  return yuv420_bgr24_lasx;
102  case AV_PIX_FMT_RGBA:
103  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
104  break;
105  } else
106  return yuv420_rgba32_lasx;
107  case AV_PIX_FMT_ARGB:
108  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
109  break;
110  } else
111  return yuv420_argb32_lasx;
112  case AV_PIX_FMT_BGRA:
113  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
114  break;
115  } else
116  return yuv420_bgra32_lasx;
117  case AV_PIX_FMT_ABGR:
118  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
119  break;
120  } else
121  return yuv420_abgr32_lasx;
122  }
123  }
124  }
125 #endif // #if HAVE_LASX
126  if (have_lsx(cpu_flags)) {
127  if (c->srcFormat == AV_PIX_FMT_YUV420P) {
128  switch (c->dstFormat) {
129  case AV_PIX_FMT_RGB24:
130  return yuv420_rgb24_lsx;
131  case AV_PIX_FMT_BGR24:
132  return yuv420_bgr24_lsx;
133  case AV_PIX_FMT_RGBA:
134  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
135  break;
136  } else
137  return yuv420_rgba32_lsx;
138  case AV_PIX_FMT_ARGB:
139  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
140  break;
141  } else
142  return yuv420_argb32_lsx;
143  case AV_PIX_FMT_BGRA:
144  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
145  break;
146  } else
147  return yuv420_bgra32_lsx;
148  case AV_PIX_FMT_ABGR:
149  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
150  break;
151  } else
152  return yuv420_abgr32_lsx;
153  }
154  }
155  }
156  return NULL;
157 }
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_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
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