History

swscale/yuv2rgb: prepare YUV2RGBFUNC macro for multi-planar rgb

This will be used in the upcoming yuv42{0,2}p -> gbrp unscaled colorspace converters. There is no difference in performance.

Ramiro Polla committed 2 years ago

Commit af5adf51 parent 24063e71 file · +48 −35Browse files

Unified · Split

libswscale/yuv2rgb.c+48−35
@@ -124,7 +124,7 @@ const int *sws_getCoefficients(int colorspace) · 123 unmodified lines
124 dst_##l[12 * i + 8] = dst_##l[12 * i + 9] = g[Y]; \124 dst_##l[12 * i + 8] = dst_##l[12 * i + 9] = g[Y]; \
125 dst_##l[12 * i + 10] = dst_##l[12 * i + 11] = r[Y];125 dst_##l[12 * i + 10] = dst_##l[12 * i + 11] = r[Y];
126 126
127#define YUV2RGBFUNC(func_name, dst_type, alpha, yuv422) \127#define YUV2RGBFUNC(func_name, dst_type, alpha, yuv422, nb_dst_planes) \
128 static int func_name(SwsContext *c, const uint8_t *src[], \128 static int func_name(SwsContext *c, const uint8_t *src[], \
129 int srcStride[], int srcSliceY, int srcSliceH, \129 int srcStride[], int srcSliceY, int srcSliceH, \
130 uint8_t *dst[], int dstStride[]) \130 uint8_t *dst[], int dstStride[]) \
@@ -137,6 +137,7 @@ const int *sws_getCoefficients(int colorspace) · 6 unmodified lines
137 (dst_type *)(dst[0] + (yd) * dstStride[0]); \137 (dst_type *)(dst[0] + (yd) * dstStride[0]); \
138 dst_type *dst_2 = \138 dst_type *dst_2 = \
139 (dst_type *)(dst[0] + (yd + 1) * dstStride[0]); \139 (dst_type *)(dst[0] + (yd + 1) * dstStride[0]); \
140 dst_type av_unused *dst1_1, *dst1_2, *dst2_1, *dst2_2; \
140 dst_type av_unused *r, *g, *b; \141 dst_type av_unused *r, *g, *b; \
141 const uint8_t *py_1 = src[0] + y * srcStride[0]; \142 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
142 const uint8_t *py_2 = py_1 + srcStride[0]; \143 const uint8_t *py_2 = py_1 + srcStride[0]; \
@@ -145,6 +146,12 @@ const int *sws_getCoefficients(int colorspace) · 2 unmodified lines
145 const uint8_t av_unused *pu_2, *pv_2; \146 const uint8_t av_unused *pu_2, *pv_2; \
146 const uint8_t av_unused *pa_1, *pa_2; \147 const uint8_t av_unused *pa_1, *pa_2; \
147 unsigned int h_size = c->dstW >> 3; \148 unsigned int h_size = c->dstW >> 3; \
149 if (nb_dst_planes > 1) { \
150 dst1_1 = (dst_type *)(dst[1] + (yd) * dstStride[1]); \
151 dst1_2 = (dst_type *)(dst[1] + (yd + 1) * dstStride[1]); \
152 dst2_1 = (dst_type *)(dst[2] + (yd) * dstStride[2]); \
153 dst2_2 = (dst_type *)(dst[2] + (yd + 1) * dstStride[2]); \
154 } \
148 if (yuv422) { \155 if (yuv422) { \
149 pu_2 = pu_1 + srcStride[1]; \156 pu_2 = pu_1 + srcStride[1]; \
150 pv_2 = pv_1 + srcStride[2]; \157 pv_2 = pv_1 + srcStride[2]; \
@@ -156,7 +163,7 @@ const int *sws_getCoefficients(int colorspace) · 5 unmodified lines
156 while (h_size--) { \163 while (h_size--) { \
157 int av_unused U, V, Y; \164 int av_unused U, V, Y; \
158 165
159#define ENDYUV2RGBLINE(dst_delta, ss, alpha, yuv422) \166#define ENDYUV2RGBLINE(dst_delta, ss, alpha, yuv422, nb_dst_planes) \
160 pu_1 += 4 >> ss; \167 pu_1 += 4 >> ss; \
161 pv_1 += 4 >> ss; \168 pv_1 += 4 >> ss; \
162 if (yuv422) { \169 if (yuv422) { \
@@ -171,6 +178,12 @@ const int *sws_getCoefficients(int colorspace) · 8 unmodified lines
171 } \178 } \
172 dst_1 += dst_delta >> ss; \179 dst_1 += dst_delta >> ss; \
173 dst_2 += dst_delta >> ss; \180 dst_2 += dst_delta >> ss; \
181 if (nb_dst_planes > 1) { \
182 dst1_1 += dst_delta >> ss; \
183 dst1_2 += dst_delta >> ss; \
184 dst2_1 += dst_delta >> ss; \
185 dst2_2 += dst_delta >> ss; \
186 } \
174 } \187 } \
175 if (c->dstW & (4 >> ss)) { \188 if (c->dstW & (4 >> ss)) { \
176 int av_unused Y, U, V; \189 int av_unused Y, U, V; \
@@ -181,8 +194,8 @@ const int *sws_getCoefficients(int colorspace) · 4 unmodified lines
181 return srcSliceH; \194 return srcSliceH; \
182 }195 }
183 196
184#define YUV420FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta) \197#define YUV420FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta, nb_dst_planes) \
185 YUV2RGBFUNC(func_name, dst_type, alpha, 0) \198 YUV2RGBFUNC(func_name, dst_type, alpha, 0, nb_dst_planes) \
186 LOADCHROMA(1, 0); \199 LOADCHROMA(1, 0); \
187 PUTFUNC(1, 0, abase); \200 PUTFUNC(1, 0, abase); \
188 PUTFUNC(2, 0, abase); \201 PUTFUNC(2, 0, abase); \
@@ -198,7 +211,7 @@ const int *sws_getCoefficients(int colorspace) · 9 unmodified lines
198 LOADCHROMA(1, 3); \211 LOADCHROMA(1, 3); \
199 PUTFUNC(2, 3, abase); \212 PUTFUNC(2, 3, abase); \
200 PUTFUNC(1, 3, abase); \213 PUTFUNC(1, 3, abase); \
201 ENDYUV2RGBLINE(dst_delta, 0, alpha, 0) \214 ENDYUV2RGBLINE(dst_delta, 0, alpha, 0, nb_dst_planes) \
202 LOADCHROMA(1, 0); \215 LOADCHROMA(1, 0); \
203 PUTFUNC(1, 0, abase); \216 PUTFUNC(1, 0, abase); \
204 PUTFUNC(2, 0, abase); \217 PUTFUNC(2, 0, abase); \
@@ -206,14 +219,14 @@ const int *sws_getCoefficients(int colorspace) · 1 unmodified line
206 LOADCHROMA(1, 1); \219 LOADCHROMA(1, 1); \
207 PUTFUNC(2, 1, abase); \220 PUTFUNC(2, 1, abase); \
208 PUTFUNC(1, 1, abase); \221 PUTFUNC(1, 1, abase); \
209 ENDYUV2RGBLINE(dst_delta, 1, alpha, 0) \222 ENDYUV2RGBLINE(dst_delta, 1, alpha, 0, nb_dst_planes) \
210 LOADCHROMA(1, 0); \223 LOADCHROMA(1, 0); \
211 PUTFUNC(1, 0, abase); \224 PUTFUNC(1, 0, abase); \
212 PUTFUNC(2, 0, abase); \225 PUTFUNC(2, 0, abase); \
213 ENDYUV2RGBFUNC()226 ENDYUV2RGBFUNC()
214 227
215#define YUV422FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta) \228#define YUV422FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta, nb_dst_planes) \
216 YUV2RGBFUNC(func_name, dst_type, alpha, 1) \229 YUV2RGBFUNC(func_name, dst_type, alpha, 1, nb_dst_planes) \
217 LOADCHROMA(1, 0); \230 LOADCHROMA(1, 0); \
218 PUTFUNC(1, 0, abase); \231 PUTFUNC(1, 0, abase); \
219 \232 \
@@ -237,7 +250,7 @@ const int *sws_getCoefficients(int colorspace) · 17 unmodified lines
237 \250 \
238 LOADCHROMA(1, 3); \251 LOADCHROMA(1, 3); \
239 PUTFUNC(1, 3, abase); \252 PUTFUNC(1, 3, abase); \
240 ENDYUV2RGBLINE(dst_delta, 0, alpha, 1) \253 ENDYUV2RGBLINE(dst_delta, 0, alpha, 1, nb_dst_planes) \
241 LOADCHROMA(1, 0); \254 LOADCHROMA(1, 0); \
242 PUTFUNC(1, 0, abase); \255 PUTFUNC(1, 0, abase); \
243 \256 \
@@ -249,7 +262,7 @@ const int *sws_getCoefficients(int colorspace) · 5 unmodified lines
249 \262 \
250 LOADCHROMA(1, 1); \263 LOADCHROMA(1, 1); \
251 PUTFUNC(1, 1, abase); \264 PUTFUNC(1, 1, abase); \
252 ENDYUV2RGBLINE(dst_delta, 1, alpha, 1) \265 ENDYUV2RGBLINE(dst_delta, 1, alpha, 1, nb_dst_planes) \
253 LOADCHROMA(1, 0); \266 LOADCHROMA(1, 0); \
254 PUTFUNC(1, 0, abase); \267 PUTFUNC(1, 0, abase); \
255 \268 \
@@ -258,7 +271,7 @@ const int *sws_getCoefficients(int colorspace) · 2 unmodified lines
258 ENDYUV2RGBFUNC()271 ENDYUV2RGBFUNC()
259 272
260#define YUV420FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \273#define YUV420FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \
261 YUV2RGBFUNC(func_name, dst_type, 0, 0) \274 YUV2RGBFUNC(func_name, dst_type, 0, 0, 1) \
262 LOADDITHER \275 LOADDITHER \
263 \276 \
264 LOADCHROMA(1, 0); \277 LOADCHROMA(1, 0); \
@@ -276,7 +289,7 @@ const int *sws_getCoefficients(int colorspace) · 11 unmodified lines
276 LOADCHROMA(1, 3); \289 LOADCHROMA(1, 3); \
277 PUTFUNC(2, 3, 6 + 8); \290 PUTFUNC(2, 3, 6 + 8); \
278 PUTFUNC(1, 3, 6); \291 PUTFUNC(1, 3, 6); \
279 ENDYUV2RGBLINE(dst_delta, 0, 0, 0) \292 ENDYUV2RGBLINE(dst_delta, 0, 0, 0, 1) \
280 LOADDITHER \293 LOADDITHER \
281 \294 \
282 LOADCHROMA(1, 0); \295 LOADCHROMA(1, 0); \
@@ -286,7 +299,7 @@ const int *sws_getCoefficients(int colorspace) · 3 unmodified lines
286 LOADCHROMA(1, 1); \299 LOADCHROMA(1, 1); \
287 PUTFUNC(2, 1, 2 + 8); \300 PUTFUNC(2, 1, 2 + 8); \
288 PUTFUNC(1, 1, 2); \301 PUTFUNC(1, 1, 2); \
289 ENDYUV2RGBLINE(dst_delta, 1, 0, 0) \302 ENDYUV2RGBLINE(dst_delta, 1, 0, 0, 1) \
290 LOADDITHER \303 LOADDITHER \
291 \304 \
292 LOADCHROMA(1, 0); \305 LOADCHROMA(1, 0); \
@@ -295,7 +308,7 @@ const int *sws_getCoefficients(int colorspace) · 2 unmodified lines
295 ENDYUV2RGBFUNC()308 ENDYUV2RGBFUNC()
296 309
297#define YUV422FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \310#define YUV422FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \
298 YUV2RGBFUNC(func_name, dst_type, 0, 1) \311 YUV2RGBFUNC(func_name, dst_type, 0, 1, 1) \
299 LOADDITHER \312 LOADDITHER \
300 \313 \
301 LOADCHROMA(1, 0); \314 LOADCHROMA(1, 0); \
@@ -321,7 +334,7 @@ const int *sws_getCoefficients(int colorspace) · 19 unmodified lines
321 \334 \
322 LOADCHROMA(1, 3); \335 LOADCHROMA(1, 3); \
323 PUTFUNC(1, 3, 6); \336 PUTFUNC(1, 3, 6); \
324 ENDYUV2RGBLINE(dst_delta, 0, 0, 1) \337 ENDYUV2RGBLINE(dst_delta, 0, 0, 1, 1) \
325 LOADDITHER \338 LOADDITHER \
326 \339 \
327 LOADCHROMA(1, 0); \340 LOADCHROMA(1, 0); \
@@ -335,7 +348,7 @@ const int *sws_getCoefficients(int colorspace) · 7 unmodified lines
335 \348 \
336 LOADCHROMA(1, 1); \349 LOADCHROMA(1, 1); \
337 PUTFUNC(1, 1, 2); \350 PUTFUNC(1, 1, 2); \
338 ENDYUV2RGBLINE(dst_delta, 1, 0, 1) \351 ENDYUV2RGBLINE(dst_delta, 1, 0, 1, 1) \
339 LOADDITHER \352 LOADDITHER \
340 \353 \
341 LOADCHROMA(1, 0); \354 LOADCHROMA(1, 0); \
@@ -431,7 +444,7 @@ const int *sws_getCoefficients(int colorspace) · 89 unmodified lines
431 g[Y + d64[1 + o]] + \444 g[Y + d64[1 + o]] + \
432 b[Y + d128[1 + o]];445 b[Y + d128[1 + o]];
433 446
434YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0)447YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0, 1)
435 const uint8_t *d128 = ff_dither_8x8_220[yd & 7];448 const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
436 char out_1 = 0, out_2 = 0;449 char out_1 = 0, out_2 = 0;
437 g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];450 g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
@@ -494,18 +507,18 @@ YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0) · 56 unmodified lines
494ENDYUV2RGBFUNC()507ENDYUV2RGBFUNC()
495 508
496// YUV420509// YUV420
497YUV420FUNC(yuv2rgb_c_48, uint8_t, 0, 0, PUTRGB48, 48)510YUV420FUNC(yuv2rgb_c_48, uint8_t, 0, 0, PUTRGB48, 48, 1)
498YUV420FUNC(yuv2rgb_c_bgr48, uint8_t, 0, 0, PUTBGR48, 48)511YUV420FUNC(yuv2rgb_c_bgr48, uint8_t, 0, 0, PUTBGR48, 48, 1)
499YUV420FUNC(yuv2rgb_c_32, uint32_t, 0, 0, PUTRGB, 8)512YUV420FUNC(yuv2rgb_c_32, uint32_t, 0, 0, PUTRGB, 8, 1)
500#if HAVE_BIGENDIAN513#if HAVE_BIGENDIAN
501YUV420FUNC(yuva2argb_c, uint32_t, 1, 24, PUTRGBA, 8)514YUV420FUNC(yuva2argb_c, uint32_t, 1, 24, PUTRGBA, 8, 1)
502YUV420FUNC(yuva2rgba_c, uint32_t, 1, 0, PUTRGBA, 8)515YUV420FUNC(yuva2rgba_c, uint32_t, 1, 0, PUTRGBA, 8, 1)
503#else516#else
504YUV420FUNC(yuva2rgba_c, uint32_t, 1, 24, PUTRGBA, 8)517YUV420FUNC(yuva2rgba_c, uint32_t, 1, 24, PUTRGBA, 8, 1)
505YUV420FUNC(yuva2argb_c, uint32_t, 1, 0, PUTRGBA, 8)518YUV420FUNC(yuva2argb_c, uint32_t, 1, 0, PUTRGBA, 8, 1)
506#endif519#endif
507YUV420FUNC(yuv2rgb_c_24_rgb, uint8_t, 0, 0, PUTRGB24, 24)520YUV420FUNC(yuv2rgb_c_24_rgb, uint8_t, 0, 0, PUTRGB24, 24, 1)
508YUV420FUNC(yuv2rgb_c_24_bgr, uint8_t, 0, 0, PUTBGR24, 24)521YUV420FUNC(yuv2rgb_c_24_bgr, uint8_t, 0, 0, PUTBGR24, 24, 1)
509YUV420FUNC_DITHER(yuv2rgb_c_16_ordered_dither, uint16_t, LOADDITHER16, PUTRGB16, 8)522YUV420FUNC_DITHER(yuv2rgb_c_16_ordered_dither, uint16_t, LOADDITHER16, PUTRGB16, 8)
510YUV420FUNC_DITHER(yuv2rgb_c_15_ordered_dither, uint16_t, LOADDITHER15, PUTRGB15, 8)523YUV420FUNC_DITHER(yuv2rgb_c_15_ordered_dither, uint16_t, LOADDITHER15, PUTRGB15, 8)
511YUV420FUNC_DITHER(yuv2rgb_c_12_ordered_dither, uint16_t, LOADDITHER12, PUTRGB12, 8)524YUV420FUNC_DITHER(yuv2rgb_c_12_ordered_dither, uint16_t, LOADDITHER12, PUTRGB12, 8)
@@ -514,18 +527,18 @@ YUV420FUNC_DITHER(yuv2rgb_c_4_ordered_dither, uint8_t, LOADDITHER4D, PUTRGB4D · 2 unmodified lines
514YUV420FUNC_DITHER(yuv2rgb_c_4b_ordered_dither, uint8_t, LOADDITHER4DB, PUTRGB4DB, 8)527YUV420FUNC_DITHER(yuv2rgb_c_4b_ordered_dither, uint8_t, LOADDITHER4DB, PUTRGB4DB, 8)
515 528
516// YUV422529// YUV422
517YUV422FUNC(yuv422p_rgb48_c, uint8_t, 0, 0, PUTRGB48, 48)530YUV422FUNC(yuv422p_rgb48_c, uint8_t, 0, 0, PUTRGB48, 48, 1)
518YUV422FUNC(yuv422p_bgr48_c, uint8_t, 0, 0, PUTBGR48, 48)531YUV422FUNC(yuv422p_bgr48_c, uint8_t, 0, 0, PUTBGR48, 48, 1)
519YUV422FUNC(yuv422p_rgb32_c, uint32_t, 0, 0, PUTRGB, 8)532YUV422FUNC(yuv422p_rgb32_c, uint32_t, 0, 0, PUTRGB, 8, 1)
520#if HAVE_BIGENDIAN533#if HAVE_BIGENDIAN
521YUV422FUNC(yuva422p_argb_c, uint32_t, 1, 24, PUTRGBA, 8)534YUV422FUNC(yuva422p_argb_c, uint32_t, 1, 24, PUTRGBA, 8, 1)
522YUV422FUNC(yuva422p_rgba_c, uint32_t, 1, 0, PUTRGBA, 8)535YUV422FUNC(yuva422p_rgba_c, uint32_t, 1, 0, PUTRGBA, 8, 1)
523#else536#else
524YUV422FUNC(yuva422p_rgba_c, uint32_t, 1, 24, PUTRGBA, 8)537YUV422FUNC(yuva422p_rgba_c, uint32_t, 1, 24, PUTRGBA, 8, 1)
525YUV422FUNC(yuva422p_argb_c, uint32_t, 1, 0, PUTRGBA, 8)538YUV422FUNC(yuva422p_argb_c, uint32_t, 1, 0, PUTRGBA, 8, 1)
526#endif539#endif
527YUV422FUNC(yuv422p_rgb24_c, uint8_t, 0, 0, PUTRGB24, 24)540YUV422FUNC(yuv422p_rgb24_c, uint8_t, 0, 0, PUTRGB24, 24, 1)
528YUV422FUNC(yuv422p_bgr24_c, uint8_t, 0, 0, PUTBGR24, 24)541YUV422FUNC(yuv422p_bgr24_c, uint8_t, 0, 0, PUTBGR24, 24, 1)
529YUV422FUNC_DITHER(yuv422p_bgr16, uint16_t, LOADDITHER16, PUTRGB16, 8)542YUV422FUNC_DITHER(yuv422p_bgr16, uint16_t, LOADDITHER16, PUTRGB16, 8)
530YUV422FUNC_DITHER(yuv422p_bgr15, uint16_t, LOADDITHER15, PUTRGB15, 8)543YUV422FUNC_DITHER(yuv422p_bgr15, uint16_t, LOADDITHER15, PUTRGB15, 8)
531YUV422FUNC_DITHER(yuv422p_bgr12, uint16_t, LOADDITHER12, PUTRGB12, 8)544YUV422FUNC_DITHER(yuv422p_bgr12, uint16_t, LOADDITHER12, PUTRGB12, 8)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t