1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * software YUV to RGB converter
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * Copyright (C) 2001-2007 Michael Niedermayer
5cabdff1aSopenharmony_ci *           (c) 2010 Konstantin Shishkov
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * This file is part of FFmpeg.
8cabdff1aSopenharmony_ci *
9cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
10cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
11cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
12cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
13cabdff1aSopenharmony_ci *
14cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
15cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
16cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17cabdff1aSopenharmony_ci * Lesser General Public License for more details.
18cabdff1aSopenharmony_ci *
19cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
20cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
21cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22cabdff1aSopenharmony_ci */
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_ci#include <stdint.h>
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ci#include "libavutil/x86/asm.h"
27cabdff1aSopenharmony_ci#include "libswscale/swscale_internal.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#define YUV2RGB_LOOP(depth)                                          \
30cabdff1aSopenharmony_ci    h_size = (c->dstW + 7) & ~7;                                     \
31cabdff1aSopenharmony_ci    if (h_size * depth > FFABS(dstStride[0]))                        \
32cabdff1aSopenharmony_ci        h_size -= 8;                                                 \
33cabdff1aSopenharmony_ci                                                                     \
34cabdff1aSopenharmony_ci    vshift = c->srcFormat != AV_PIX_FMT_YUV422P;                        \
35cabdff1aSopenharmony_ci                                                                     \
36cabdff1aSopenharmony_ci    for (y = 0; y < srcSliceH; y++) {                                \
37cabdff1aSopenharmony_ci        uint8_t *image    = dst[0] + (y + srcSliceY) * dstStride[0]; \
38cabdff1aSopenharmony_ci        const uint8_t *py = src[0] +               y * srcStride[0]; \
39cabdff1aSopenharmony_ci        const uint8_t *pu = src[1] +   (y >> vshift) * srcStride[1]; \
40cabdff1aSopenharmony_ci        const uint8_t *pv = src[2] +   (y >> vshift) * srcStride[2]; \
41cabdff1aSopenharmony_ci        x86_reg index = -h_size / 2;                                 \
42cabdff1aSopenharmony_ci
43cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_rgb24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
44cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
45cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
46cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_bgr24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
47cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
48cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
49cabdff1aSopenharmony_ci
50cabdff1aSopenharmony_ci#ifndef COMPILE_TEMPLATE_MMXEXT
51cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_rgb15)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
52cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
53cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
54cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_rgb16)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
55cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
56cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
57cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
58cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
59cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
60cabdff1aSopenharmony_ciextern void RENAME(ff_yuv_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
61cabdff1aSopenharmony_ci                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
62cabdff1aSopenharmony_ci                                     const uint8_t *py_2index);
63cabdff1aSopenharmony_ciextern void RENAME(ff_yuva_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
64cabdff1aSopenharmony_ci                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
65cabdff1aSopenharmony_ci                                      const uint8_t *py_2index, const uint8_t *pa_2index);
66cabdff1aSopenharmony_ciextern void RENAME(ff_yuva_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
67cabdff1aSopenharmony_ci                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
68cabdff1aSopenharmony_ci                                      const uint8_t *py_2index, const uint8_t *pa_2index);
69cabdff1aSopenharmony_ci
70cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
71cabdff1aSopenharmony_ci                                       int srcStride[],
72cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
73cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
74cabdff1aSopenharmony_ci{
75cabdff1aSopenharmony_ci    int y, h_size, vshift;
76cabdff1aSopenharmony_ci
77cabdff1aSopenharmony_ci    YUV2RGB_LOOP(2)
78cabdff1aSopenharmony_ci
79cabdff1aSopenharmony_ci#ifdef DITHER1XBPP
80cabdff1aSopenharmony_ci        c->blueDither  = ff_dither8[y       & 1];
81cabdff1aSopenharmony_ci        c->greenDither = ff_dither8[y       & 1];
82cabdff1aSopenharmony_ci        c->redDither   = ff_dither8[(y + 1) & 1];
83cabdff1aSopenharmony_ci#endif
84cabdff1aSopenharmony_ci
85cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
86cabdff1aSopenharmony_ci    }
87cabdff1aSopenharmony_ci    return srcSliceH;
88cabdff1aSopenharmony_ci}
89cabdff1aSopenharmony_ci
90cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
91cabdff1aSopenharmony_ci                                       int srcStride[],
92cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
93cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
94cabdff1aSopenharmony_ci{
95cabdff1aSopenharmony_ci    int y, h_size, vshift;
96cabdff1aSopenharmony_ci
97cabdff1aSopenharmony_ci    YUV2RGB_LOOP(2)
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_ci#ifdef DITHER1XBPP
100cabdff1aSopenharmony_ci        c->blueDither  = ff_dither8[y       & 1];
101cabdff1aSopenharmony_ci        c->greenDither = ff_dither4[y       & 1];
102cabdff1aSopenharmony_ci        c->redDither   = ff_dither8[(y + 1) & 1];
103cabdff1aSopenharmony_ci#endif
104cabdff1aSopenharmony_ci
105cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
106cabdff1aSopenharmony_ci    }
107cabdff1aSopenharmony_ci    return srcSliceH;
108cabdff1aSopenharmony_ci}
109cabdff1aSopenharmony_ci
110cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[],
111cabdff1aSopenharmony_ci                                       int srcStride[],
112cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
113cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
114cabdff1aSopenharmony_ci{
115cabdff1aSopenharmony_ci    int y, h_size, vshift;
116cabdff1aSopenharmony_ci
117cabdff1aSopenharmony_ci    YUV2RGB_LOOP(4)
118cabdff1aSopenharmony_ci
119cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
120cabdff1aSopenharmony_ci    }
121cabdff1aSopenharmony_ci    return srcSliceH;
122cabdff1aSopenharmony_ci}
123cabdff1aSopenharmony_ci
124cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
125cabdff1aSopenharmony_ci                                       int srcStride[],
126cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
127cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
128cabdff1aSopenharmony_ci{
129cabdff1aSopenharmony_ci    int y, h_size, vshift;
130cabdff1aSopenharmony_ci
131cabdff1aSopenharmony_ci    YUV2RGB_LOOP(4)
132cabdff1aSopenharmony_ci
133cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
134cabdff1aSopenharmony_ci    }
135cabdff1aSopenharmony_ci    return srcSliceH;
136cabdff1aSopenharmony_ci}
137cabdff1aSopenharmony_ci
138cabdff1aSopenharmony_cistatic inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
139cabdff1aSopenharmony_ci                                       int srcStride[],
140cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
141cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
142cabdff1aSopenharmony_ci{
143cabdff1aSopenharmony_ci    int y, h_size, vshift;
144cabdff1aSopenharmony_ci    YUV2RGB_LOOP(4)
145cabdff1aSopenharmony_ci
146cabdff1aSopenharmony_ci        const uint8_t *pa = src[3] + y * srcStride[3];
147cabdff1aSopenharmony_ci        RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
148cabdff1aSopenharmony_ci    }
149cabdff1aSopenharmony_ci    return srcSliceH;
150cabdff1aSopenharmony_ci}
151cabdff1aSopenharmony_ci
152cabdff1aSopenharmony_cistatic inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
153cabdff1aSopenharmony_ci                                        int srcStride[],
154cabdff1aSopenharmony_ci                                        int srcSliceY, int srcSliceH,
155cabdff1aSopenharmony_ci                                        uint8_t *dst[], int dstStride[])
156cabdff1aSopenharmony_ci{
157cabdff1aSopenharmony_ci    int y, h_size, vshift;
158cabdff1aSopenharmony_ci
159cabdff1aSopenharmony_ci    YUV2RGB_LOOP(4)
160cabdff1aSopenharmony_ci
161cabdff1aSopenharmony_ci        const uint8_t *pa = src[3] + y * srcStride[3];
162cabdff1aSopenharmony_ci        RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
163cabdff1aSopenharmony_ci    }
164cabdff1aSopenharmony_ci    return srcSliceH;
165cabdff1aSopenharmony_ci}
166cabdff1aSopenharmony_ci#endif
167cabdff1aSopenharmony_ci
168cabdff1aSopenharmony_ci#if !defined(COMPILE_TEMPLATE_MMX)
169cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
170cabdff1aSopenharmony_ci                                       int srcStride[],
171cabdff1aSopenharmony_ci                                       int srcSliceY, int srcSliceH,
172cabdff1aSopenharmony_ci                                       uint8_t *dst[], int dstStride[])
173cabdff1aSopenharmony_ci{
174cabdff1aSopenharmony_ci    int y, h_size, vshift;
175cabdff1aSopenharmony_ci
176cabdff1aSopenharmony_ci    YUV2RGB_LOOP(3)
177cabdff1aSopenharmony_ci
178cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
179cabdff1aSopenharmony_ci    }
180cabdff1aSopenharmony_ci    return srcSliceH;
181cabdff1aSopenharmony_ci}
182cabdff1aSopenharmony_ci
183cabdff1aSopenharmony_cistatic inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
184cabdff1aSopenharmony_ci                                        int srcStride[],
185cabdff1aSopenharmony_ci                                        int srcSliceY, int srcSliceH,
186cabdff1aSopenharmony_ci                                        uint8_t *dst[], int dstStride[])
187cabdff1aSopenharmony_ci{
188cabdff1aSopenharmony_ci    int y, h_size, vshift;
189cabdff1aSopenharmony_ci
190cabdff1aSopenharmony_ci    YUV2RGB_LOOP(3)
191cabdff1aSopenharmony_ci
192cabdff1aSopenharmony_ci        RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
193cabdff1aSopenharmony_ci    }
194cabdff1aSopenharmony_ci    return srcSliceH;
195cabdff1aSopenharmony_ci}
196cabdff1aSopenharmony_ci#endif
197