2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include "video-format.h"
33 * @short_description: Support library for video operations
37 * This library contains some helper functions and includes the
38 * videosink and videofilter base classes.
43 #include "video-orc.h"
45 /* Line conversion to AYUV */
47 #define GET_PLANE_STRIDE(plane) (stride(plane))
48 #define GET_PLANE_LINE(plane, line) \
49 (gpointer)(((guint8*)(data[plane])) + stride[plane] * (line))
51 #define GET_COMP_STRIDE(comp) \
52 GST_VIDEO_FORMAT_INFO_STRIDE (info, stride, comp)
53 #define GET_COMP_DATA(comp) \
54 GST_VIDEO_FORMAT_INFO_DATA (info, data, comp)
56 #define GET_COMP_LINE(comp, line) \
57 (gpointer)(((guint8*)GET_COMP_DATA (comp)) + \
58 GET_COMP_STRIDE(comp) * (line))
60 #define GET_LINE(line) GET_PLANE_LINE (0, line)
62 #define GET_Y_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_Y, line)
63 #define GET_U_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_U, line)
64 #define GET_V_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_V, line)
66 #define GET_R_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_R, line)
67 #define GET_G_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_G, line)
68 #define GET_B_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_B, line)
70 #define GET_A_LINE(line) GET_COMP_LINE(GST_VIDEO_COMP_A, line)
72 #define GET_UV_420(line, flags) \
73 (flags & GST_VIDEO_PACK_FLAG_INTERLACED ? \
74 ((line & ~3) >> 1) + (line & 1) : \
76 #define GET_UV_410(line, flags) \
77 (flags & GST_VIDEO_PACK_FLAG_INTERLACED ? \
78 ((line & ~7) >> 2) + (line & 1) : \
81 #define PACK_420 GST_VIDEO_FORMAT_AYUV, unpack_planar_420, 1, pack_planar_420
83 unpack_planar_420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
84 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
85 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
87 gint uv = GET_UV_420 (y, flags);
88 guint8 *y_line = GET_Y_LINE (y);
89 guint8 *u_line = GET_U_LINE (uv);
90 guint8 *v_line = GET_V_LINE (uv);
93 video_orc_unpack_I420 (dest, y_line, u_line, v_line, width);
98 ayuv[i * 4 + 2] = u_line[i / 2 + 1];
99 ayuv[i * 4 + 3] = v_line[i / 2 + 1];
104 pack_planar_420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
105 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
106 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
109 gint uv = GET_UV_420 (y, flags);
110 guint8 *y_line = GET_Y_LINE (y);
111 guint8 *u_line = GET_U_LINE (uv);
112 guint8 *v_line = GET_V_LINE (uv);
113 const guint8 *ayuv = src;
115 video_orc_pack_I420 (y_line, u_line, v_line, src, width / 2);
120 y_line[i] = ayuv[i * 4 + 1];
121 u_line[i / 2 + 1] = ayuv[i * 4 + 2];
122 v_line[i / 2 + 1] = ayuv[i * 4 + 3];
126 #define PACK_YUY2 GST_VIDEO_FORMAT_AYUV, unpack_YUY2, 1, pack_YUY2
128 unpack_YUY2 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
129 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
130 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
132 guint8 *line = GET_LINE (y);
135 video_orc_unpack_YUY2 (dest, line, width / 2);
141 d[i * 4 + 1] = line[i * 2 + 0];
142 d[i * 4 + 2] = line[i * 2 + 1];
143 d[i * 4 + 3] = line[i * 2 + 3];
148 pack_YUY2 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
149 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
150 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
153 guint8 *line = GET_LINE (y);
154 const guint8 *ayuv = src;
156 video_orc_pack_YUY2 (line, src, width / 2);
161 line[i * 2 + 0] = ayuv[i * 4 + 1];
162 line[i * 2 + 1] = ayuv[i * 4 + 2];
163 line[i * 2 + 3] = ayuv[i * 4 + 3];
167 #define PACK_UYVY GST_VIDEO_FORMAT_AYUV, unpack_UYVY, 1, pack_UYVY
169 unpack_UYVY (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
170 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
171 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
173 guint8 *line = GET_LINE (y);
176 video_orc_unpack_UYVY (dest, line, width / 2);
182 d[i * 4 + 1] = line[i * 2 + 1];
183 d[i * 4 + 2] = line[i * 2 + 0];
184 d[i * 4 + 3] = line[i * 2 + 2];
189 pack_UYVY (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
190 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
191 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
194 guint8 *line = GET_LINE (y);
195 const guint8 *ayuv = src;
197 video_orc_pack_UYVY (line, src, width / 2);
202 line[i * 2 + 0] = ayuv[i * 4 + 2];
203 line[i * 2 + 1] = ayuv[i * 4 + 1];
204 line[i * 2 + 2] = ayuv[i * 4 + 3];
208 #define PACK_YVYU GST_VIDEO_FORMAT_AYUV, unpack_YVYU, 1, pack_YVYU
210 unpack_YVYU (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
211 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
212 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
214 guint8 *line = GET_LINE (y);
217 video_orc_unpack_YVYU (dest, line, width / 2);
223 d[i * 4 + 1] = line[i * 2 + 0];
224 d[i * 4 + 2] = line[i * 2 + 3];
225 d[i * 4 + 3] = line[i * 2 + 1];
230 pack_YVYU (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
231 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
232 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
235 guint8 *line = GET_LINE (y);
236 const guint8 *ayuv = src;
238 video_orc_pack_YVYU (GET_LINE (y), src, width / 2);
243 line[i * 2 + 0] = ayuv[i * 4 + 1];
244 line[i * 2 + 1] = ayuv[i * 4 + 3];
245 line[i * 2 + 3] = ayuv[i * 4 + 2];
249 #define PACK_v308 GST_VIDEO_FORMAT_AYUV, unpack_v308, 1, pack_v308
251 unpack_v308 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
252 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
253 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
256 const guint8 *s = GET_LINE (y);
259 for (i = 0; i < width; i++) {
261 d[i * 4 + 1] = s[i * 3 + 0];
262 d[i * 4 + 2] = s[i * 3 + 1];
263 d[i * 4 + 3] = s[i * 3 + 2];
268 pack_v308 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
269 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
270 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
274 guint8 *d = GET_LINE (y);
275 const guint8 *s = src;
277 for (i = 0; i < width; i++) {
278 d[i * 3 + 0] = s[i * 4 + 1];
279 d[i * 3 + 1] = s[i * 4 + 2];
280 d[i * 3 + 2] = s[i * 4 + 3];
284 #define PACK_AYUV GST_VIDEO_FORMAT_AYUV, unpack_copy4, 1, pack_copy4
285 #define PACK_ARGB GST_VIDEO_FORMAT_ARGB, unpack_copy4, 1, pack_copy4
287 unpack_copy4 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
288 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
289 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
291 memcpy (dest, GET_LINE (y), width * 4);
295 pack_copy4 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
296 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
297 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
300 memcpy (GET_LINE (y), src, width * 4);
303 #define PACK_v210 GST_VIDEO_FORMAT_AYUV64, unpack_v210, 1, pack_v210
305 unpack_v210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
306 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
307 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
310 const guint8 *s = GET_LINE (y);
313 for (i = 0; i < width - 5; i += 6) {
314 guint32 a0, a1, a2, a3;
315 guint16 y0, y1, y2, y3, y4, y5;
319 a0 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 0);
320 a1 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 4);
321 a2 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 8);
322 a3 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 12);
324 u0 = ((a0 >> 0) & 0x3ff) << 6;
325 y0 = ((a0 >> 10) & 0x3ff) << 6;
326 v0 = ((a0 >> 20) & 0x3ff) << 6;
327 y1 = ((a1 >> 0) & 0x3ff) << 6;
329 u2 = ((a1 >> 10) & 0x3ff) << 6;
330 y2 = ((a1 >> 20) & 0x3ff) << 6;
331 v2 = ((a2 >> 0) & 0x3ff) << 6;
332 y3 = ((a2 >> 10) & 0x3ff) << 6;
334 u4 = ((a2 >> 20) & 0x3ff) << 6;
335 y4 = ((a3 >> 0) & 0x3ff) << 6;
336 v4 = ((a3 >> 10) & 0x3ff) << 6;
337 y5 = ((a3 >> 20) & 0x3ff) << 6;
339 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
356 d[4 * (i + 0) + 0] = 0xffff;
357 d[4 * (i + 0) + 1] = y0;
358 d[4 * (i + 0) + 2] = u0;
359 d[4 * (i + 0) + 3] = v0;
361 d[4 * (i + 1) + 0] = 0xffff;
362 d[4 * (i + 1) + 1] = y1;
363 d[4 * (i + 1) + 2] = u0;
364 d[4 * (i + 1) + 3] = v0;
366 d[4 * (i + 2) + 0] = 0xffff;
367 d[4 * (i + 2) + 1] = y2;
368 d[4 * (i + 2) + 2] = u2;
369 d[4 * (i + 2) + 3] = v2;
371 d[4 * (i + 3) + 0] = 0xffff;
372 d[4 * (i + 3) + 1] = y3;
373 d[4 * (i + 3) + 2] = u2;
374 d[4 * (i + 3) + 3] = v2;
376 d[4 * (i + 4) + 0] = 0xffff;
377 d[4 * (i + 4) + 1] = y4;
378 d[4 * (i + 4) + 2] = u4;
379 d[4 * (i + 4) + 3] = v4;
381 d[4 * (i + 5) + 0] = 0xffff;
382 d[4 * (i + 5) + 1] = y5;
383 d[4 * (i + 5) + 2] = u4;
384 d[4 * (i + 5) + 3] = v4;
389 pack_v210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
390 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
391 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
395 guint8 *d = GET_LINE (y);
396 const guint16 *s = src;
398 for (i = 0; i < width - 5; i += 6) {
399 guint32 a0, a1, a2, a3;
400 guint16 y0, y1, y2, y3, y4, y5;
404 y0 = s[4 * (i + 0) + 1] >> 6;
405 y1 = s[4 * (i + 1) + 1] >> 6;
406 y2 = s[4 * (i + 2) + 1] >> 6;
407 y3 = s[4 * (i + 3) + 1] >> 6;
408 y4 = s[4 * (i + 4) + 1] >> 6;
409 y5 = s[4 * (i + 5) + 1] >> 6;
411 u0 = s[4 * (i + 0) + 2] >> 6;
412 u1 = s[4 * (i + 2) + 2] >> 6;
413 u2 = s[4 * (i + 4) + 2] >> 6;
415 v0 = s[4 * (i + 0) + 3] >> 6;
416 v1 = s[4 * (i + 2) + 3] >> 6;
417 v2 = s[4 * (i + 4) + 3] >> 6;
419 a0 = u0 | (y0 << 10) | (v0 << 20);
420 a1 = y1 | (u1 << 10) | (y2 << 20);
421 a2 = v1 | (y3 << 10) | (u2 << 20);
422 a3 = y4 | (v2 << 10) | (y5 << 20);
424 GST_WRITE_UINT32_LE (d + (i / 6) * 16 + 0, a0);
425 GST_WRITE_UINT32_LE (d + (i / 6) * 16 + 4, a1);
426 GST_WRITE_UINT32_LE (d + (i / 6) * 16 + 8, a2);
427 GST_WRITE_UINT32_LE (d + (i / 6) * 16 + 12, a3);
431 #define PACK_v216 GST_VIDEO_FORMAT_AYUV64, unpack_v216, 1, pack_v216
433 unpack_v216 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
434 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
435 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
438 const guint8 *s = GET_LINE (y);
441 for (i = 0; i < width; i++) {
442 d[i * 4 + 0] = 0xffff;
443 d[i * 4 + 1] = GST_READ_UINT16_LE (s + i * 4 + 2);
444 d[i * 4 + 2] = GST_READ_UINT16_LE (s + (i >> 1) * 8 + 0);
445 d[i * 4 + 3] = GST_READ_UINT16_LE (s + (i >> 1) * 8 + 4);
450 pack_v216 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
451 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
452 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
456 guint8 *d = GET_LINE (y);
457 const guint16 *s = src;
459 for (i = 0; i < width - 1; i += 2) {
460 GST_WRITE_UINT16_LE (d + i * 4 + 0, s[(i + 0) * 4 + 2]);
461 GST_WRITE_UINT16_LE (d + i * 4 + 2, s[(i + 0) * 4 + 1]);
462 GST_WRITE_UINT16_LE (d + i * 4 + 4, s[(i + 0) * 4 + 3]);
463 GST_WRITE_UINT16_LE (d + i * 4 + 6, s[(i + 1) * 4 + 1]);
465 if (i == width - 1) {
466 GST_WRITE_UINT16_LE (d + i * 4 + 0, s[i * 4 + 2]);
467 GST_WRITE_UINT16_LE (d + i * 4 + 2, s[i * 4 + 1]);
468 GST_WRITE_UINT16_LE (d + i * 4 + 4, s[i * 4 + 3]);
469 GST_WRITE_UINT16_LE (d + i * 4 + 6, s[i * 4 + 1]);
473 #define PACK_Y41B GST_VIDEO_FORMAT_AYUV, unpack_Y41B, 1, pack_Y41B
475 unpack_Y41B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
476 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
477 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
479 guint8 *y_line = GET_Y_LINE (y);
480 guint8 *u_line = GET_U_LINE (y);
481 guint8 *v_line = GET_V_LINE (y);
484 video_orc_unpack_YUV9 (dest, y_line, u_line, v_line, width / 2);
490 d[i * 4 + 1] = y_line[i];
491 d[i * 4 + 2] = u_line[i >> 2];
492 d[i * 4 + 3] = v_line[i >> 2];
497 pack_Y41B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
498 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
499 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
503 guint8 *destY = GET_Y_LINE (y);
504 guint8 *destU = GET_U_LINE (y);
505 guint8 *destV = GET_V_LINE (y);
506 const guint8 *s = src;
508 for (i = 0; i < width - 3; i += 4) {
509 destY[i] = s[i * 4 + 1];
510 destY[i + 1] = s[i * 4 + 5];
511 destY[i + 2] = s[i * 4 + 9];
512 destY[i + 3] = s[i * 4 + 13];
514 destU[i >> 2] = s[i * 4 + 2];
515 destV[i >> 2] = s[i * 4 + 3];
518 destY[i] = s[i * 4 + 1];
519 destU[i >> 2] = s[i * 4 + 2];
520 destV[i >> 2] = s[i * 4 + 3];
522 destY[i + 1] = s[i * 4 + 5];
524 destY[i + 2] = s[i * 4 + 9];
528 #define PACK_Y42B GST_VIDEO_FORMAT_AYUV, unpack_Y42B, 1, pack_Y42B
530 unpack_Y42B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
531 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
532 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
534 guint8 *y_line = GET_Y_LINE (y);
535 guint8 *u_line = GET_U_LINE (y);
536 guint8 *v_line = GET_V_LINE (y);
539 video_orc_unpack_Y42B (dest, y_line, u_line, v_line, width / 2);
545 d[i * 4 + 1] = y_line[i];
546 d[i * 4 + 2] = u_line[i / 2 + 1];
547 d[i * 4 + 3] = v_line[i / 2 + 1];
552 pack_Y42B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
553 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
554 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
557 guint8 *y_line = GET_Y_LINE (y);
558 guint8 *u_line = GET_U_LINE (y);
559 guint8 *v_line = GET_V_LINE (y);
560 const guint8 *ayuv = src;
562 video_orc_pack_Y42B (y_line, u_line, v_line, src, width / 2);
567 y_line[i] = ayuv[i * 4 + 1];
568 u_line[i / 2 + 1] = ayuv[i * 4 + 2];
569 v_line[i / 2 + 1] = ayuv[i * 4 + 3];
573 #define PACK_Y444 GST_VIDEO_FORMAT_AYUV, unpack_Y444, 1, pack_Y444
575 unpack_Y444 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
576 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
577 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
579 video_orc_unpack_Y444 (dest, GET_Y_LINE (y), GET_U_LINE (y),
580 GET_V_LINE (y), width);
584 pack_Y444 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
585 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
586 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
589 video_orc_pack_Y444 (GET_Y_LINE (y), GET_U_LINE (y), GET_V_LINE (y), src,
593 #define PACK_GBR GST_VIDEO_FORMAT_ARGB, unpack_GBR, 1, pack_GBR
595 unpack_GBR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
596 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
597 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
599 video_orc_unpack_Y444 (dest, GET_R_LINE (y), GET_G_LINE (y),
600 GET_B_LINE (y), width);
604 pack_GBR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
605 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
606 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
609 video_orc_pack_Y444 (GET_R_LINE (y), GET_G_LINE (y), GET_B_LINE (y), src,
613 #define PACK_GRAY8 GST_VIDEO_FORMAT_AYUV, unpack_GRAY8, 1, pack_GRAY8
615 unpack_GRAY8 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
616 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
617 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
619 video_orc_unpack_GRAY8 (dest, GET_LINE (y), width);
623 pack_GRAY8 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
624 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
625 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
628 video_orc_pack_GRAY8 (GET_LINE (y), src, width);
631 #define PACK_GRAY16_BE GST_VIDEO_FORMAT_AYUV64, unpack_GRAY16_BE, 1, pack_GRAY16_BE
633 unpack_GRAY16_BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
634 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
635 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
638 const guint16 *s = GET_LINE (y);
641 for (i = 0; i < width; i++) {
642 d[i * 4 + 0] = 0xffff;
643 d[i * 4 + 1] = GST_READ_UINT16_BE (s + i);
644 d[i * 4 + 2] = 0x8000;
645 d[i * 4 + 3] = 0x8000;
650 pack_GRAY16_BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
651 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
652 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
656 guint16 *d = GET_LINE (y);
657 const guint16 *s = src;
659 for (i = 0; i < width; i++) {
660 GST_WRITE_UINT16_BE (d + i, s[i * 4 + 1]);
664 #define PACK_GRAY16_LE GST_VIDEO_FORMAT_AYUV64, unpack_GRAY16_LE, 1, pack_GRAY16_LE
666 unpack_GRAY16_LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
667 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
668 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
671 const guint16 *s = GET_LINE (y);
674 for (i = 0; i < width; i++) {
675 d[i * 4 + 0] = 0xffff;
676 d[i * 4 + 1] = GST_READ_UINT16_LE (s + i);
677 d[i * 4 + 2] = 0x8000;
678 d[i * 4 + 3] = 0x8000;
683 pack_GRAY16_LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
684 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
685 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
689 guint16 *d = GET_LINE (y);
690 const guint16 *s = src;
692 for (i = 0; i < width; i++) {
693 GST_WRITE_UINT16_LE (d + i, s[i * 4 + 1]);
697 #define PACK_RGB16 GST_VIDEO_FORMAT_ARGB, unpack_RGB16, 1, pack_RGB16
699 unpack_RGB16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
700 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
701 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
704 const guint16 *s = GET_LINE (y);
705 guint8 *d = dest, r, g, b;
707 for (i = 0; i < width; i++) {
708 r = ((s[i] >> 11) & 0x1f) << 3;
709 g = ((s[i] >> 5) & 0x3f) << 2;
710 b = ((s[i]) & 0x1f) << 3;
712 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
726 pack_RGB16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
727 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
728 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
732 guint16 *d = GET_LINE (y);
733 const guint8 *s = src;
735 for (i = 0; i < width; i++) {
736 d[i] = ((s[i * 4 + 1] >> 3) << 11) |
737 ((s[i * 4 + 2] >> 2) << 5) | (s[i * 4 + 3] >> 3);
741 #define PACK_BGR16 GST_VIDEO_FORMAT_ARGB, unpack_BGR16, 1, pack_BGR16
743 unpack_BGR16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
744 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
745 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
748 const guint16 *s = GET_LINE (y);
749 guint8 *d = dest, r, g, b;
751 for (i = 0; i < width; i++) {
752 b = ((s[i] >> 11) & 0x1f) << 3;
753 g = ((s[i] >> 5) & 0x3f) << 2;
754 r = ((s[i]) & 0x1f) << 3;
756 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
770 pack_BGR16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
771 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
772 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
776 guint16 *d = GET_LINE (y);
777 const guint8 *s = src;
779 for (i = 0; i < width; i++) {
780 d[i] = ((s[i * 4 + 3] >> 3) << 11) |
781 ((s[i * 4 + 2] >> 2) << 5) | (s[i * 4 + 1] >> 3);
785 #define PACK_RGB15 GST_VIDEO_FORMAT_ARGB, unpack_RGB15, 1, pack_RGB15
787 unpack_RGB15 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
788 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
789 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
792 const guint16 *s = GET_LINE (y);
793 guint8 *d = dest, r, g, b;
795 for (i = 0; i < width; i++) {
796 r = ((s[i] >> 10) & 0x1f) << 3;
797 g = ((s[i] >> 5) & 0x1f) << 3;
798 b = ((s[i]) & 0x1f) << 3;
800 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
814 pack_RGB15 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
815 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
816 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
820 guint16 *d = GET_LINE (y);
821 const guint8 *s = src;
823 for (i = 0; i < width; i++) {
824 d[i] = ((s[i * 4 + 1] >> 3) << 10) |
825 ((s[i * 4 + 2] >> 3) << 5) | (s[i * 4 + 3] >> 3);
829 #define PACK_BGR15 GST_VIDEO_FORMAT_ARGB, unpack_BGR15, 1, pack_BGR15
831 unpack_BGR15 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
832 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
833 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
836 const guint16 *s = GET_LINE (y);
837 guint8 *d = dest, r, g, b;
839 for (i = 0; i < width; i++) {
840 b = ((s[i] >> 10) & 0x1f) << 3;
841 g = ((s[i] >> 5) & 0x1f) << 3;
842 r = ((s[i]) & 0x1f) << 3;
844 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
858 pack_BGR15 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
859 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
860 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
864 guint16 *d = GET_LINE (y);
865 const guint8 *s = src;
867 for (i = 0; i < width; i++) {
868 d[i] = ((s[i * 4 + 3] >> 3) << 10) |
869 ((s[i * 4 + 2] >> 3) << 5) | (s[i * 4 + 1] >> 3);
873 #define PACK_BGRA GST_VIDEO_FORMAT_ARGB, unpack_BGRA, 1, pack_BGRA
875 unpack_BGRA (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
876 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
877 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
879 video_orc_unpack_BGRA (dest, GET_LINE (y), width);
883 pack_BGRA (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
884 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
885 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
888 video_orc_pack_BGRA (GET_LINE (y), src, width);
891 #define PACK_ABGR GST_VIDEO_FORMAT_ARGB, unpack_ABGR, 1, pack_ABGR
893 unpack_ABGR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
894 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
895 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
897 video_orc_unpack_ABGR (dest, GET_LINE (y), width);
901 pack_ABGR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
902 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
903 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
906 video_orc_pack_ABGR (GET_LINE (y), src, width);
909 #define PACK_RGBA GST_VIDEO_FORMAT_ARGB, unpack_RGBA, 1, pack_RGBA
911 unpack_RGBA (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
912 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
913 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
915 video_orc_unpack_RGBA (dest, GET_LINE (y), width);
919 pack_RGBA (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
920 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
921 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
924 video_orc_pack_RGBA (GET_LINE (y), src, width);
927 #define PACK_RGB GST_VIDEO_FORMAT_ARGB, unpack_RGB, 1, pack_RGB
929 unpack_RGB (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
930 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
931 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
934 const guint8 *s = GET_LINE (y);
937 for (i = 0; i < width; i++) {
939 d[i * 4 + 1] = s[i * 3 + 0];
940 d[i * 4 + 2] = s[i * 3 + 1];
941 d[i * 4 + 3] = s[i * 3 + 2];
946 pack_RGB (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
947 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
948 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
952 guint8 *d = GET_LINE (y);
953 const guint8 *s = src;
955 for (i = 0; i < width; i++) {
956 d[i * 3 + 0] = s[i * 4 + 1];
957 d[i * 3 + 1] = s[i * 4 + 2];
958 d[i * 3 + 2] = s[i * 4 + 3];
962 #define PACK_BGR GST_VIDEO_FORMAT_ARGB, unpack_BGR, 1, pack_BGR
964 unpack_BGR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
965 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
966 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
969 const guint8 *s = GET_LINE (y);
972 for (i = 0; i < width; i++) {
974 d[i * 4 + 1] = s[i * 3 + 2];
975 d[i * 4 + 2] = s[i * 3 + 1];
976 d[i * 4 + 3] = s[i * 3 + 0];
981 pack_BGR (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
982 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
983 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
987 guint8 *d = GET_LINE (y);
988 const guint8 *s = src;
990 for (i = 0; i < width; i++) {
991 d[i * 3 + 0] = s[i * 4 + 3];
992 d[i * 3 + 1] = s[i * 4 + 2];
993 d[i * 3 + 2] = s[i * 4 + 1];
997 #define PACK_NV12 GST_VIDEO_FORMAT_AYUV, unpack_NV12, 1, pack_NV12
999 unpack_NV12 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1000 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1001 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1003 gint uv = GET_UV_420 (y, flags);
1004 guint8 *y_line = GET_PLANE_LINE (0, y);
1005 guint8 *uv_line = GET_PLANE_LINE (1, uv);
1008 video_orc_unpack_NV12 (dest, y_line, uv_line, width / 2);
1013 d[i * 4 + 0] = 0xff;
1014 d[i * 4 + 1] = y_line[i];
1015 d[i * 4 + 2] = uv_line[i + 0];
1016 d[i * 4 + 3] = uv_line[i + 1];
1021 pack_NV12 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1022 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1023 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1026 gint uv = GET_UV_420 (y, flags);
1027 guint8 *y_line = GET_PLANE_LINE (0, y);
1028 guint8 *uv_line = GET_PLANE_LINE (1, uv);
1029 const guint8 *ayuv = src;
1031 video_orc_pack_NV12 (y_line, uv_line, src, width / 2);
1036 y_line[i] = ayuv[i * 4 + 1];
1037 uv_line[i + 0] = ayuv[i * 4 + 2];
1038 uv_line[i + 1] = ayuv[i * 4 + 3];
1042 #define PACK_NV21 GST_VIDEO_FORMAT_AYUV, unpack_NV21, 1, pack_NV21
1044 unpack_NV21 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1045 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1046 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1048 gint uv = GET_UV_420 (y, flags);
1049 guint8 *y_line = GET_PLANE_LINE (0, y);
1050 guint8 *uv_line = GET_PLANE_LINE (1, uv);
1053 video_orc_unpack_NV21 (dest, y_line, uv_line, width / 2);
1058 d[i * 4 + 0] = 0xff;
1059 d[i * 4 + 1] = y_line[i];
1060 d[i * 4 + 2] = uv_line[i + 1];
1061 d[i * 4 + 3] = uv_line[i + 0];
1066 pack_NV21 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1067 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1068 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1071 gint uv = GET_UV_420 (y, flags);
1072 guint8 *y_line = GET_PLANE_LINE (0, y);
1073 guint8 *uv_line = GET_PLANE_LINE (1, uv);
1074 const guint8 *ayuv = src;
1076 video_orc_pack_NV21 (y_line, uv_line, src, width / 2);
1081 y_line[i] = ayuv[i * 4 + 1];
1082 uv_line[i + 0] = ayuv[i * 4 + 3];
1083 uv_line[i + 1] = ayuv[i * 4 + 2];
1087 #define PACK_NV16 GST_VIDEO_FORMAT_AYUV, unpack_NV16, 1, pack_NV16
1089 unpack_NV16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1090 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1091 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1093 guint8 *y_line = GET_PLANE_LINE (0, y);
1094 guint8 *uv_line = GET_PLANE_LINE (1, y);
1097 video_orc_unpack_NV12 (dest, y_line, uv_line, width / 2);
1102 d[i * 4 + 0] = 0xff;
1103 d[i * 4 + 1] = y_line[i];
1104 d[i * 4 + 2] = uv_line[i + 0];
1105 d[i * 4 + 3] = uv_line[i + 1];
1110 pack_NV16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1111 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1112 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1115 guint8 *y_line = GET_PLANE_LINE (0, y);
1116 guint8 *uv_line = GET_PLANE_LINE (1, y);
1117 const guint8 *ayuv = src;
1119 video_orc_pack_NV12 (y_line, uv_line, src, width / 2);
1124 y_line[i] = ayuv[i * 4 + 1];
1125 uv_line[i + 0] = ayuv[i * 4 + 2];
1126 uv_line[i + 1] = ayuv[i * 4 + 3];
1130 #define PACK_NV24 GST_VIDEO_FORMAT_AYUV, unpack_NV24, 1, pack_NV24
1132 unpack_NV24 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1133 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1134 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1136 video_orc_unpack_NV12 (dest,
1137 GET_PLANE_LINE (0, y), GET_PLANE_LINE (1, y), width);
1141 pack_NV24 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1142 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1143 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1146 video_orc_pack_NV12 (GET_PLANE_LINE (0, y),
1147 GET_PLANE_LINE (1, y), src, width);
1150 #define PACK_UYVP GST_VIDEO_FORMAT_AYUV64, unpack_UYVP, 1, pack_UYVP
1152 unpack_UYVP (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1153 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1154 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1157 const guint8 *s = GET_LINE (y);
1160 for (i = 0; i < width - 1; i += 2) {
1165 u0 = ((s[(i / 2) * 5 + 0] << 2) | (s[(i / 2) * 5 + 1] >> 6)) << 6;
1166 y0 = (((s[(i / 2) * 5 + 1] & 0x3f) << 4) | (s[(i / 2) * 5 + 2] >> 4)) << 6;
1167 v0 = (((s[(i / 2) * 5 + 2] & 0x0f) << 6) | (s[(i / 2) * 5 + 3] >> 2)) << 6;
1168 y1 = (((s[(i / 2) * 5 + 3] & 0x03) << 8) | s[(i / 2) * 5 + 4]) << 6;
1170 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1177 d[i * 4 + 0] = 0xffff;
1182 d[i * 4 + 4] = 0xffff;
1190 pack_UYVP (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1191 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1192 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1196 guint8 *d = GET_LINE (y);
1197 const guint16 *s = src;
1199 for (i = 0; i < width; i += 2) {
1204 y0 = s[4 * (i + 0) + 1];
1205 y1 = (i < width - 1 ? s[4 * (i + 1) + 1] : y0);
1207 u0 = s[4 * (i + 0) + 2];
1208 v0 = s[4 * (i + 0) + 3];
1210 d[(i / 2) * 5 + 0] = u0 >> 8;
1211 d[(i / 2) * 5 + 1] = (u0 & 0xc0) | y0 >> 10;
1212 d[(i / 2) * 5 + 2] = ((y0 & 0x3c0) >> 2) | (v0 >> 12);
1213 d[(i / 2) * 5 + 3] = ((v0 & 0xfc0) >> 4) | (y1 >> 14);
1214 d[(i / 2) * 5 + 4] = (y1 >> 6);
1218 #define PACK_A420 GST_VIDEO_FORMAT_AYUV, unpack_A420, 1, pack_A420
1220 unpack_A420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1221 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1222 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1224 gint uv = GET_UV_420 (y, flags);
1226 video_orc_unpack_A420 (dest, GET_Y_LINE (y), GET_U_LINE (uv),
1227 GET_V_LINE (uv), GET_A_LINE (y), width);
1231 pack_A420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1232 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1233 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1236 gint uv = GET_UV_420 (y, flags);
1237 guint8 *y_line = GET_Y_LINE (y);
1238 guint8 *u_line = GET_U_LINE (uv);
1239 guint8 *v_line = GET_V_LINE (uv);
1240 guint8 *a_line = GET_A_LINE (y);
1241 const guint8 *ayuv = src;
1243 video_orc_pack_A420 (y_line, u_line, v_line, a_line, src, width / 2);
1248 a_line[i] = ayuv[i * 4 + 0];
1249 y_line[i] = ayuv[i * 4 + 1];
1250 u_line[i / 2 + 1] = ayuv[i * 4 + 2];
1251 v_line[i / 2 + 1] = ayuv[i * 4 + 3];
1255 #define PACK_RGB8P GST_VIDEO_FORMAT_ARGB, unpack_RGB8P, 1, pack_RGB8P
1257 unpack_RGB8P (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1258 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1259 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1262 const guint8 *s = GET_LINE (y);
1263 const guint32 *p = data[1];
1266 for (i = 0; i < width; i++) {
1267 guint32 v = p[s[i]];
1268 d[i * 4 + 0] = (v >> 24) & 0xff;
1269 d[i * 4 + 1] = (v >> 16) & 0xff;
1270 d[i * 4 + 2] = (v >> 8) & 0xff;
1271 d[i * 4 + 3] = (v) & 0xff;
1275 static const guint32 std_palette_RGB8P[] = {
1276 0xff000000, 0xff000033, 0xff000066, 0xff000099, 0xff0000cc, 0xff0000ff,
1277 0xff003300, 0xff003333, 0xff003366, 0xff003399, 0xff0033cc, 0xff0033ff,
1278 0xff006600, 0xff006633, 0xff006666, 0xff006699, 0xff0066cc, 0xff0066ff,
1279 0xff009900, 0xff009933, 0xff009966, 0xff009999, 0xff0099cc, 0xff0099ff,
1280 0xff00cc00, 0xff00cc33, 0xff00cc66, 0xff00cc99, 0xff00cccc, 0xff00ccff,
1281 0xff00ff00, 0xff00ff33, 0xff00ff66, 0xff00ff99, 0xff00ffcc, 0xff00ffff,
1282 0xff330000, 0xff330033, 0xff330066, 0xff330099, 0xff3300cc, 0xff3300ff,
1283 0xff333300, 0xff333333, 0xff333366, 0xff333399, 0xff3333cc, 0xff3333ff,
1284 0xff336600, 0xff336633, 0xff336666, 0xff336699, 0xff3366cc, 0xff3366ff,
1285 0xff339900, 0xff339933, 0xff339966, 0xff339999, 0xff3399cc, 0xff3399ff,
1286 0xff33cc00, 0xff33cc33, 0xff33cc66, 0xff33cc99, 0xff33cccc, 0xff33ccff,
1287 0xff33ff00, 0xff33ff33, 0xff33ff66, 0xff33ff99, 0xff33ffcc, 0xff33ffff,
1288 0xff660000, 0xff660033, 0xff660066, 0xff660099, 0xff6600cc, 0xff6600ff,
1289 0xff663300, 0xff663333, 0xff663366, 0xff663399, 0xff6633cc, 0xff6633ff,
1290 0xff666600, 0xff666633, 0xff666666, 0xff666699, 0xff6666cc, 0xff6666ff,
1291 0xff669900, 0xff669933, 0xff669966, 0xff669999, 0xff6699cc, 0xff6699ff,
1292 0xff66cc00, 0xff66cc33, 0xff66cc66, 0xff66cc99, 0xff66cccc, 0xff66ccff,
1293 0xff66ff00, 0xff66ff33, 0xff66ff66, 0xff66ff99, 0xff66ffcc, 0xff66ffff,
1294 0xff990000, 0xff990033, 0xff990066, 0xff990099, 0xff9900cc, 0xff9900ff,
1295 0xff993300, 0xff993333, 0xff993366, 0xff993399, 0xff9933cc, 0xff9933ff,
1296 0xff996600, 0xff996633, 0xff996666, 0xff996699, 0xff9966cc, 0xff9966ff,
1297 0xff999900, 0xff999933, 0xff999966, 0xff999999, 0xff9999cc, 0xff9999ff,
1298 0xff99cc00, 0xff99cc33, 0xff99cc66, 0xff99cc99, 0xff99cccc, 0xff99ccff,
1299 0xff99ff00, 0xff99ff33, 0xff99ff66, 0xff99ff99, 0xff99ffcc, 0xff99ffff,
1300 0xffcc0000, 0xffcc0033, 0xffcc0066, 0xffcc0099, 0xffcc00cc, 0xffcc00ff,
1301 0xffcc3300, 0xffcc3333, 0xffcc3366, 0xffcc3399, 0xffcc33cc, 0xffcc33ff,
1302 0xffcc6600, 0xffcc6633, 0xffcc6666, 0xffcc6699, 0xffcc66cc, 0xffcc66ff,
1303 0xffcc9900, 0xffcc9933, 0xffcc9966, 0xffcc9999, 0xffcc99cc, 0xffcc99ff,
1304 0xffcccc00, 0xffcccc33, 0xffcccc66, 0xffcccc99, 0xffcccccc, 0xffccccff,
1305 0xffccff00, 0xffccff33, 0xffccff66, 0xffccff99, 0xffccffcc, 0xffccffff,
1306 0xffff0000, 0xffff0033, 0xffff0066, 0xffff0099, 0xffff00cc, 0xffff00ff,
1307 0xffff3300, 0xffff3333, 0xffff3366, 0xffff3399, 0xffff33cc, 0xffff33ff,
1308 0xffff6600, 0xffff6633, 0xffff6666, 0xffff6699, 0xffff66cc, 0xffff66ff,
1309 0xffff9900, 0xffff9933, 0xffff9966, 0xffff9999, 0xffff99cc, 0xffff99ff,
1310 0xffffcc00, 0xffffcc33, 0xffffcc66, 0xffffcc99, 0xffffcccc, 0xffffccff,
1311 0xffffff00, 0xffffff33, 0xffffff66, 0xffffff99, 0xffffffcc, 0xffffffff,
1312 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1313 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1314 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1315 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1316 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1317 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1318 0xff000000, 0xff000000, 0xff000000, 0xff000000
1322 pack_RGB8P (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1323 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1324 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1328 guint8 *d = GET_LINE (y);
1329 const guint8 *s = src;
1331 /* Use our poor man's palette, taken from ffmpegcolorspace too */
1332 for (i = 0; i < width; i++) {
1333 /* crude approximation for alpha ! */
1334 if (s[i * 4 + 0] < 0x80)
1338 ((((s[i * 4 + 1]) / 47) % 6) * 6 * 6 + (((s[i * 4 +
1339 2]) / 47) % 6) * 6 + (((s[i * 4 + 3]) / 47) % 6));
1343 #define PACK_410 GST_VIDEO_FORMAT_AYUV, unpack_410, 1, pack_410
1345 unpack_410 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1346 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1347 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1349 gint uv = GET_UV_410 (y, flags);
1350 guint8 *y_line = GET_Y_LINE (y);
1351 guint8 *u_line = GET_U_LINE (uv);
1352 guint8 *v_line = GET_V_LINE (uv);
1355 video_orc_unpack_YUV9 (dest, y_line, u_line, v_line, width / 2);
1360 d[i * 4 + 0] = 0xff;
1361 d[i * 4 + 1] = y_line[i];
1362 d[i * 4 + 2] = u_line[i >> 2];
1363 d[i * 4 + 3] = v_line[i >> 2];
1368 pack_410 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1369 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1370 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1374 gint uv = GET_UV_410 (y, flags);
1375 guint8 *destY = GET_Y_LINE (y);
1376 guint8 *destU = GET_U_LINE (uv);
1377 guint8 *destV = GET_V_LINE (uv);
1378 const guint8 *s = src;
1380 for (i = 0; i < width - 3; i += 4) {
1381 destY[i] = s[i * 4 + 1];
1382 destY[i + 1] = s[i * 4 + 5];
1383 destY[i + 2] = s[i * 4 + 9];
1384 destY[i + 3] = s[i * 4 + 13];
1386 destU[i >> 2] = s[i * 4 + 2];
1387 destV[i >> 2] = s[i * 4 + 3];
1391 destY[i] = s[i * 4 + 1];
1393 destU[i >> 2] = s[i * 4 + 2];
1394 destV[i >> 2] = s[i * 4 + 3];
1397 destY[i + 1] = s[i * 4 + 5];
1399 destY[i + 2] = s[i * 4 + 9];
1403 #define PACK_IYU1 GST_VIDEO_FORMAT_AYUV, unpack_IYU1, 1, pack_IYU1
1405 unpack_IYU1 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1406 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1407 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1410 const guint8 *s = GET_LINE (y);
1412 guint8 y0, y1, y2, y3;
1416 for (i = 0; i < width - 3; i += 4) {
1417 y0 = s[(i >> 2) * 6 + 1];
1418 y1 = s[(i >> 2) * 6 + 2];
1419 y2 = s[(i >> 2) * 6 + 4];
1420 y3 = s[(i >> 2) * 6 + 5];
1422 u0 = s[(i >> 2) * 6 + 0];
1423 v0 = s[(i >> 2) * 6 + 3];
1425 d[i * 4 + 0] = 0xff;
1430 d[i * 4 + 4] = 0xff;
1435 d[i * 4 + 8] = 0xff;
1440 d[i * 4 + 12] = 0xff;
1446 u0 = s[(i >> 2) * 6 + 0];
1447 v0 = s[(i >> 2) * 6 + 3];
1449 d[i * 4 + 0] = 0xff;
1450 d[i * 4 + 1] = s[(i >> 2) * 6 + 1];
1454 if (i < width - 1) {
1455 d[i * 4 + 4] = 0xff;
1456 d[i * 4 + 5] = s[(i >> 2) * 6 + 2];
1460 if (i < width - 2) {
1461 d[i * 4 + 8] = 0xff;
1462 d[i * 4 + 9] = s[(i >> 2) * 6 + 4];
1470 pack_IYU1 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1471 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1472 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1476 guint8 *d = GET_LINE (y);
1477 const guint8 *s = src;
1479 for (i = 0; i < width - 3; i += 4) {
1480 d[(i >> 2) * 6 + 0] = s[i * 4 + 2];
1481 d[(i >> 2) * 6 + 1] = s[i * 4 + 1];
1482 d[(i >> 2) * 6 + 2] = s[i * 4 + 5];
1483 d[(i >> 2) * 6 + 3] = s[i * 4 + 3];
1484 d[(i >> 2) * 6 + 4] = s[i * 4 + 9];
1485 d[(i >> 2) * 6 + 5] = s[i * 4 + 13];
1488 d[(i >> 2) * 6 + 1] = s[i * 4 + 1];
1489 d[(i >> 2) * 6 + 0] = s[i * 4 + 2];
1490 d[(i >> 2) * 6 + 3] = s[i * 4 + 3];
1492 d[(i >> 2) * 6 + 2] = s[i * 4 + 5];
1494 d[(i >> 2) * 6 + 4] = s[i * 4 + 9];
1498 #define PACK_ARGB64 GST_VIDEO_FORMAT_ARGB64, unpack_copy8, 1, pack_copy8
1499 #define PACK_AYUV64 GST_VIDEO_FORMAT_AYUV64, unpack_copy8, 1, pack_copy8
1501 unpack_copy8 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1502 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1503 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1505 memcpy (dest, GET_LINE (y), width * 8);
1509 pack_copy8 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1510 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1511 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1514 memcpy (GET_LINE (y), src, width * 8);
1517 #define PACK_r210 GST_VIDEO_FORMAT_ARGB64, unpack_r210, 1, pack_r210
1519 unpack_r210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1520 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1521 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1524 const guint8 *s = GET_LINE (y);
1525 guint16 *d = dest, R, G, B;
1527 for (i = 0; i < width; i++) {
1528 guint32 x = GST_READ_UINT32_BE (s + i * 4);
1530 R = ((x >> 14) & 0xffc0);
1531 G = ((x >> 4) & 0xffc0);
1532 B = ((x << 6) & 0xffc0);
1534 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1540 d[i * 4 + 0] = 0xffff;
1548 pack_r210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1549 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1550 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1554 guint8 *d = GET_LINE (y);
1555 const guint16 *s = src;
1557 for (i = 0; i < width; i++) {
1559 x |= (s[i * 4 + 1] & 0xffc0) << 14;
1560 x |= (s[i * 4 + 2] & 0xffc0) << 4;
1561 x |= (s[i * 4 + 3] & 0xffc0) >> 6;
1562 GST_WRITE_UINT32_BE (d + i * 4, x);
1566 #define PACK_GBR_10LE GST_VIDEO_FORMAT_ARGB64, unpack_GBR_10LE, 1, pack_GBR_10LE
1568 unpack_GBR_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1569 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1570 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1573 guint16 *srcG = GET_G_LINE (y);
1574 guint16 *srcB = GET_B_LINE (y);
1575 guint16 *srcR = GET_R_LINE (y);
1576 guint16 *d = dest, G, B, R;
1578 for (i = 0; i < width; i++) {
1579 G = GST_READ_UINT16_LE (srcG + i) << 6;
1580 B = GST_READ_UINT16_LE (srcB + i) << 6;
1581 R = GST_READ_UINT16_LE (srcR + i) << 6;
1583 d[i * 4 + 0] = 0xffff;
1591 pack_GBR_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1592 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1593 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1597 guint16 *destG = GET_G_LINE (y);
1598 guint16 *destB = GET_B_LINE (y);
1599 guint16 *destR = GET_R_LINE (y);
1601 const guint16 *s = src;
1603 for (i = 0; i < width; i++) {
1604 G = (s[i * 4 + 2]) >> 6;
1605 B = (s[i * 4 + 3]) >> 6;
1606 R = (s[i * 4 + 1]) >> 6;
1608 GST_WRITE_UINT16_LE (destG + i, G);
1609 GST_WRITE_UINT16_LE (destB + i, B);
1610 GST_WRITE_UINT16_LE (destR + i, R);
1614 #define PACK_GBR_10BE GST_VIDEO_FORMAT_ARGB64, unpack_GBR_10BE, 1, pack_GBR_10BE
1616 unpack_GBR_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1617 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1618 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1621 guint16 *srcG = GET_G_LINE (y);
1622 guint16 *srcB = GET_B_LINE (y);
1623 guint16 *srcR = GET_R_LINE (y);
1624 guint16 *d = dest, G, B, R;
1626 for (i = 0; i < width; i++) {
1627 G = GST_READ_UINT16_BE (srcG + i) << 6;
1628 B = GST_READ_UINT16_BE (srcB + i) << 6;
1629 R = GST_READ_UINT16_BE (srcR + i) << 6;
1631 d[i * 4 + 0] = 0xffff;
1639 pack_GBR_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1640 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1641 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1645 guint16 *destG = GET_G_LINE (y);
1646 guint16 *destB = GET_B_LINE (y);
1647 guint16 *destR = GET_R_LINE (y);
1649 const guint16 *s = src;
1651 for (i = 0; i < width; i++) {
1652 G = s[i * 4 + 2] >> 6;
1653 B = s[i * 4 + 3] >> 6;
1654 R = s[i * 4 + 1] >> 6;
1656 GST_WRITE_UINT16_BE (destG + i, G);
1657 GST_WRITE_UINT16_BE (destB + i, B);
1658 GST_WRITE_UINT16_BE (destR + i, R);
1662 #define PACK_Y444_10LE GST_VIDEO_FORMAT_AYUV64, unpack_Y444_10LE, 1, pack_Y444_10LE
1664 unpack_Y444_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1665 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1666 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1669 guint16 *srcY = GET_Y_LINE (y);
1670 guint16 *srcU = GET_U_LINE (y);
1671 guint16 *srcV = GET_V_LINE (y);
1672 guint16 *d = dest, Y, U, V;
1674 for (i = 0; i < width; i++) {
1675 Y = GST_READ_UINT16_LE (srcY + i) << 6;
1676 U = GST_READ_UINT16_LE (srcU + i) << 6;
1677 V = GST_READ_UINT16_LE (srcV + i) << 6;
1679 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1685 d[i * 4 + 0] = 0xffff;
1693 pack_Y444_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1694 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1695 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1699 guint16 *destY = GET_Y_LINE (y);
1700 guint16 *destU = GET_U_LINE (y);
1701 guint16 *destV = GET_V_LINE (y);
1703 const guint16 *s = src;
1705 for (i = 0; i < width; i++) {
1706 Y = (s[i * 4 + 1]) >> 6;
1707 U = (s[i * 4 + 2]) >> 6;
1708 V = (s[i * 4 + 3]) >> 6;
1710 GST_WRITE_UINT16_LE (destY + i, Y);
1711 GST_WRITE_UINT16_LE (destU + i, U);
1712 GST_WRITE_UINT16_LE (destV + i, V);
1716 #define PACK_Y444_10BE GST_VIDEO_FORMAT_AYUV64, unpack_Y444_10BE, 1, pack_Y444_10BE
1718 unpack_Y444_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1719 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1720 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1723 guint16 *srcY = GET_Y_LINE (y);
1724 guint16 *srcU = GET_U_LINE (y);
1725 guint16 *srcV = GET_V_LINE (y);
1726 guint16 *d = dest, Y, U, V;
1728 for (i = 0; i < width; i++) {
1729 Y = GST_READ_UINT16_BE (srcY + i) << 6;
1730 U = GST_READ_UINT16_BE (srcU + i) << 6;
1731 V = GST_READ_UINT16_BE (srcV + i) << 6;
1733 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1739 d[i * 4 + 0] = 0xffff;
1747 pack_Y444_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1748 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1749 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1753 guint16 *destY = GET_Y_LINE (y);
1754 guint16 *destU = GET_U_LINE (y);
1755 guint16 *destV = GET_V_LINE (y);
1757 const guint16 *s = src;
1759 for (i = 0; i < width; i++) {
1760 Y = s[i * 4 + 1] >> 6;
1761 U = s[i * 4 + 2] >> 6;
1762 V = s[i * 4 + 3] >> 6;
1764 GST_WRITE_UINT16_BE (destY + i, Y);
1765 GST_WRITE_UINT16_BE (destU + i, U);
1766 GST_WRITE_UINT16_BE (destV + i, V);
1770 #define PACK_I420_10LE GST_VIDEO_FORMAT_AYUV64, unpack_I420_10LE, 1, pack_I420_10LE
1772 unpack_I420_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1773 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1774 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1777 gint uv = GET_UV_420 (y, flags);
1778 guint16 *srcY = GET_Y_LINE (y);
1779 guint16 *srcU = GET_U_LINE (uv);
1780 guint16 *srcV = GET_V_LINE (uv);
1781 guint16 *d = dest, Y, U, V;
1783 for (i = 0; i < width; i++) {
1784 Y = GST_READ_UINT16_LE (srcY + i) << 6;
1785 U = GST_READ_UINT16_LE (srcU + (i >> 1)) << 6;
1786 V = GST_READ_UINT16_LE (srcV + (i >> 1)) << 6;
1788 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1794 d[i * 4 + 0] = 0xffff;
1802 pack_I420_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1803 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1804 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1808 gint uv = GET_UV_420 (y, flags);
1809 guint16 *destY = GET_Y_LINE (y);
1810 guint16 *destU = GET_U_LINE (uv);
1811 guint16 *destV = GET_V_LINE (uv);
1812 guint16 Y0, Y1, U, V;
1813 const guint16 *s = src;
1815 for (i = 0; i < width - 1; i += 2) {
1816 Y0 = s[i * 4 + 1] >> 6;
1817 Y1 = s[i * 4 + 5] >> 6;
1818 U = s[i * 4 + 2] >> 6;
1819 V = s[i * 4 + 3] >> 6;
1821 GST_WRITE_UINT16_LE (destY + i + 0, Y0);
1822 GST_WRITE_UINT16_LE (destY + i + 1, Y1);
1823 GST_WRITE_UINT16_LE (destU + (i >> 1), U);
1824 GST_WRITE_UINT16_LE (destV + (i >> 1), V);
1826 if (i == width - 1) {
1827 Y0 = s[i * 4 + 1] >> 6;
1828 U = s[i * 4 + 2] >> 6;
1829 V = s[i * 4 + 3] >> 6;
1831 GST_WRITE_UINT16_LE (destY + i, Y0);
1832 GST_WRITE_UINT16_LE (destU + (i >> 1), U);
1833 GST_WRITE_UINT16_LE (destV + (i >> 1), V);
1837 #define PACK_I420_10BE GST_VIDEO_FORMAT_AYUV64, unpack_I420_10BE, 1, pack_I420_10BE
1839 unpack_I420_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1840 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1841 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1844 gint uv = GET_UV_420 (y, flags);
1845 guint16 *srcY = GET_Y_LINE (y);
1846 guint16 *srcU = GET_U_LINE (uv);
1847 guint16 *srcV = GET_V_LINE (uv);
1848 guint16 *d = dest, Y, U, V;
1850 for (i = 0; i < width; i++) {
1851 Y = GST_READ_UINT16_BE (srcY + i) << 6;
1852 U = GST_READ_UINT16_BE (srcU + (i >> 1)) << 6;
1853 V = GST_READ_UINT16_BE (srcV + (i >> 1)) << 6;
1855 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1861 d[i * 4 + 0] = 0xffff;
1869 pack_I420_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1870 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1871 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1875 gint uv = GET_UV_420 (y, flags);
1876 guint16 *destY = GET_Y_LINE (y);
1877 guint16 *destU = GET_U_LINE (uv);
1878 guint16 *destV = GET_V_LINE (uv);
1879 guint16 Y0, Y1, U, V;
1880 const guint16 *s = src;
1882 for (i = 0; i < width - 1; i += 2) {
1883 Y0 = s[i * 4 + 1] >> 6;
1884 Y1 = s[i * 4 + 5] >> 6;
1885 U = s[i * 4 + 2] >> 6;
1886 V = s[i * 4 + 3] >> 6;
1888 GST_WRITE_UINT16_BE (destY + i + 0, Y0);
1889 GST_WRITE_UINT16_BE (destY + i + 1, Y1);
1890 GST_WRITE_UINT16_BE (destU + (i >> 1), U);
1891 GST_WRITE_UINT16_BE (destV + (i >> 1), V);
1893 if (i == width - 1) {
1894 Y0 = s[i * 4 + 1] >> 6;
1895 U = s[i * 4 + 2] >> 6;
1896 V = s[i * 4 + 3] >> 6;
1898 GST_WRITE_UINT16_BE (destY + i, Y0);
1899 GST_WRITE_UINT16_BE (destU + (i >> 1), U);
1900 GST_WRITE_UINT16_BE (destV + (i >> 1), V);
1904 #define PACK_I422_10LE GST_VIDEO_FORMAT_AYUV64, unpack_I422_10LE, 1, pack_I422_10LE
1906 unpack_I422_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1907 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1908 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1911 guint16 *srcY = GET_Y_LINE (y);
1912 guint16 *srcU = GET_U_LINE (y);
1913 guint16 *srcV = GET_V_LINE (y);
1914 guint16 *d = dest, Y, U, V;
1916 for (i = 0; i < width; i++) {
1917 Y = GST_READ_UINT16_LE (srcY + i) << 6;
1918 U = GST_READ_UINT16_LE (srcU + (i >> 1)) << 6;
1919 V = GST_READ_UINT16_LE (srcV + (i >> 1)) << 6;
1921 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1927 d[i * 4 + 0] = 0xffff;
1935 pack_I422_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1936 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
1937 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
1941 guint16 *destY = GET_Y_LINE (y);
1942 guint16 *destU = GET_U_LINE (y);
1943 guint16 *destV = GET_V_LINE (y);
1944 guint16 Y0, Y1, U, V;
1945 const guint16 *s = src;
1947 for (i = 0; i < width - 1; i += 2) {
1948 Y0 = s[i * 4 + 1] >> 6;
1949 Y1 = s[i * 4 + 5] >> 6;
1950 U = s[i * 4 + 2] >> 6;
1951 V = s[i * 4 + 3] >> 6;
1953 GST_WRITE_UINT16_LE (destY + i + 0, Y0);
1954 GST_WRITE_UINT16_LE (destY + i + 1, Y1);
1955 GST_WRITE_UINT16_LE (destU + (i >> 1), U);
1956 GST_WRITE_UINT16_LE (destV + (i >> 1), V);
1958 if (i == width - 1) {
1959 Y0 = s[i * 4 + 1] >> 6;
1960 U = s[i * 4 + 2] >> 6;
1961 V = s[i * 4 + 3] >> 6;
1963 GST_WRITE_UINT16_LE (destY + i, Y0);
1964 GST_WRITE_UINT16_LE (destU + (i >> 1), U);
1965 GST_WRITE_UINT16_LE (destV + (i >> 1), V);
1969 #define PACK_I422_10BE GST_VIDEO_FORMAT_AYUV64, unpack_I422_10BE, 1, pack_I422_10BE
1971 unpack_I422_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
1972 gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
1973 const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
1976 guint16 *srcY = GET_Y_LINE (y);
1977 guint16 *srcU = GET_U_LINE (y);
1978 guint16 *srcV = GET_V_LINE (y);
1979 guint16 *d = dest, Y, U, V;
1981 for (i = 0; i < width; i++) {
1982 Y = GST_READ_UINT16_BE (srcY + i) << 6;
1983 U = GST_READ_UINT16_BE (srcU + (i >> 1)) << 6;
1984 V = GST_READ_UINT16_BE (srcV + (i >> 1)) << 6;
1986 if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
1992 d[i * 4 + 0] = 0xffff;
2000 pack_I422_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
2001 const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
2002 const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
2006 guint16 *destY = GET_Y_LINE (y);
2007 guint16 *destU = GET_U_LINE (y);
2008 guint16 *destV = GET_V_LINE (y);
2009 guint16 Y0, Y1, U, V;
2010 const guint16 *s = src;
2012 for (i = 0; i < width - 1; i += 2) {
2013 Y0 = s[i * 4 + 1] >> 6;
2014 Y1 = s[i * 4 + 5] >> 6;
2015 U = s[i * 4 + 2] >> 6;
2016 V = s[i * 4 + 3] >> 6;
2018 GST_WRITE_UINT16_BE (destY + i + 0, Y0);
2019 GST_WRITE_UINT16_BE (destY + i + 1, Y1);
2020 GST_WRITE_UINT16_BE (destU + (i >> 1), U);
2021 GST_WRITE_UINT16_BE (destV + (i >> 1), V);
2023 if (i == width - 1) {
2024 Y0 = s[i * 4 + 1] >> 6;
2025 U = s[i * 4 + 2] >> 6;
2026 V = s[i * 4 + 3] >> 6;
2028 GST_WRITE_UINT16_BE (destY + i, Y0);
2029 GST_WRITE_UINT16_BE (destU + (i >> 1), U);
2030 GST_WRITE_UINT16_BE (destV + (i >> 1), V);
2037 GstVideoFormatInfo info;
2040 /* depths: bits, n_components, shift, depth */
2041 #define DPTH0 0, 0, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
2042 #define DPTH8 8, 1, { 0, 0, 0, 0 }, { 8, 0, 0, 0 }
2043 #define DPTH8_32 8, 2, { 0, 0, 0, 0 }, { 8, 32, 0, 0 }
2044 #define DPTH888 8, 3, { 0, 0, 0, 0 }, { 8, 8, 8, 0 }
2045 #define DPTH8888 8, 4, { 0, 0, 0, 0 }, { 8, 8, 8, 8 }
2046 #define DPTH10_10_10 10, 3, { 0, 0, 0, 0 }, { 10, 10, 10, 0 }
2047 #define DPTH16 16, 1, { 0, 0, 0, 0 }, { 16, 0, 0, 0 }
2048 #define DPTH16_16_16 16, 3, { 0, 0, 0, 0 }, { 16, 16, 16, 0 }
2049 #define DPTH16_16_16_16 16, 4, { 0, 0, 0, 0 }, { 16, 16, 16, 16 }
2050 #define DPTH555 16, 3, { 10, 5, 0, 0 }, { 5, 5, 5, 0 }
2051 #define DPTH565 16, 3, { 11, 5, 0, 0 }, { 5, 6, 5, 0 }
2054 #define PSTR0 { 0, 0, 0, 0 }
2055 #define PSTR1 { 1, 0, 0, 0 }
2056 #define PSTR14 { 1, 4, 0, 0 }
2057 #define PSTR111 { 1, 1, 1, 0 }
2058 #define PSTR1111 { 1, 1, 1, 1 }
2059 #define PSTR122 { 1, 2, 2, 0 }
2060 #define PSTR2 { 2, 0, 0, 0 }
2061 #define PSTR222 { 2, 2, 2, 0 }
2062 #define PSTR244 { 2, 4, 4, 0 }
2063 #define PSTR444 { 4, 4, 4, 0 }
2064 #define PSTR4444 { 4, 4, 4, 4 }
2065 #define PSTR333 { 3, 3, 3, 0 }
2066 #define PSTR488 { 4, 8, 8, 0 }
2067 #define PSTR8888 { 8, 8, 8, 8 }
2069 /* planes, in what plane do we find component N */
2070 #define PLANE_NA 0, { 0, 0, 0, 0 }
2071 #define PLANE0 1, { 0, 0, 0, 0 }
2072 #define PLANE01 2, { 0, 1, 0, 0 }
2073 #define PLANE011 2, { 0, 1, 1, 0 }
2074 #define PLANE012 3, { 0, 1, 2, 0 }
2075 #define PLANE0123 4, { 0, 1, 2, 3 }
2076 #define PLANE021 3, { 0, 2, 1, 0 }
2077 #define PLANE201 3, { 2, 0, 1, 0 }
2080 #define OFFS0 { 0, 0, 0, 0 }
2081 #define OFFS013 { 0, 1, 3, 0 }
2082 #define OFFS102 { 1, 0, 2, 0 }
2083 #define OFFS1230 { 1, 2, 3, 0 }
2084 #define OFFS012 { 0, 1, 2, 0 }
2085 #define OFFS210 { 2, 1, 0, 0 }
2086 #define OFFS123 { 1, 2, 3, 0 }
2087 #define OFFS321 { 3, 2, 1, 0 }
2088 #define OFFS0123 { 0, 1, 2, 3 }
2089 #define OFFS2103 { 2, 1, 0, 3 }
2090 #define OFFS3210 { 3, 2, 1, 0 }
2091 #define OFFS031 { 0, 3, 1, 0 }
2092 #define OFFS204 { 2, 0, 4, 0 }
2093 #define OFFS001 { 0, 0, 1, 0 }
2094 #define OFFS010 { 0, 1, 0, 0 }
2095 #define OFFS104 { 1, 0, 4, 0 }
2096 #define OFFS2460 { 2, 4, 6, 0 }
2098 /* subsampling, w_sub, h_sub */
2099 #define SUB410 { 0, 2, 2, 0 }, { 0, 2, 2, 0 }
2100 #define SUB411 { 0, 2, 2, 0 }, { 0, 0, 0, 0 }
2101 #define SUB420 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
2102 #define SUB422 { 0, 1, 1, 0 }, { 0, 0, 0, 0 }
2103 #define SUB4 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
2104 #define SUB44 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
2105 #define SUB444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
2106 #define SUB4444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
2107 #define SUB4204 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
2109 #define MAKE_YUV_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack ) \
2110 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV, depth, pstride, plane, offs, sub, pack } }
2111 #define MAKE_YUV_LE_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack ) \
2112 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
2113 #define MAKE_YUVA_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack) \
2114 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_ALPHA, depth, pstride, plane, offs, sub, pack } }
2115 #define MAKE_YUVA_PACK_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack) \
2116 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_UNPACK, depth, pstride, plane, offs, sub, pack } }
2117 #define MAKE_YUVA_LE_PACK_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack) \
2118 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_UNPACK | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
2119 #define MAKE_YUV_C_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub, pack) \
2120 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_COMPLEX, depth, pstride, plane, offs, sub, pack } }
2122 #define MAKE_RGB_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2123 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB, depth, pstride, plane, offs, sub, pack } }
2124 #define MAKE_RGB_LE_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2125 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
2126 #define MAKE_RGBA_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2127 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA, depth, pstride, plane, offs, sub, pack } }
2128 #define MAKE_RGBAP_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2129 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_PALETTE, depth, pstride, plane, offs, sub, pack } }
2130 #define MAKE_RGBA_PACK_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2131 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_UNPACK, depth, pstride, plane, offs, sub, pack } }
2132 #define MAKE_RGBA_LE_PACK_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2133 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA | GST_VIDEO_FORMAT_FLAG_UNPACK | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
2135 #define MAKE_GRAY_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2136 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY, depth, pstride, plane, offs, sub, pack } }
2137 #define MAKE_GRAY_LE_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
2138 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
2140 static VideoFormat formats[] = {
2141 {0x00000000, {GST_VIDEO_FORMAT_UNKNOWN, "UNKNOWN", "unknown video", 0, DPTH0,
2142 PSTR0, PLANE_NA, OFFS0}},
2143 {0x00000000, {GST_VIDEO_FORMAT_ENCODED, "ENCODED", "encoded video",
2144 GST_VIDEO_FORMAT_FLAG_COMPLEX, DPTH0, PSTR0, PLANE_NA, OFFS0}},
2146 MAKE_YUV_FORMAT (I420, "raw video", GST_MAKE_FOURCC ('I', '4', '2', '0'),
2147 DPTH888, PSTR111, PLANE012, OFFS0, SUB420, PACK_420),
2148 MAKE_YUV_FORMAT (YV12, "raw video", GST_MAKE_FOURCC ('Y', 'V', '1', '2'),
2149 DPTH888, PSTR111, PLANE021, OFFS0, SUB420, PACK_420),
2150 MAKE_YUV_FORMAT (YUY2, "raw video", GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'),
2151 DPTH888, PSTR244, PLANE0, OFFS013, SUB422, PACK_YUY2),
2152 MAKE_YUV_FORMAT (UYVY, "raw video", GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'),
2153 DPTH888, PSTR244, PLANE0, OFFS102, SUB422, PACK_UYVY),
2154 MAKE_YUVA_PACK_FORMAT (AYUV, "raw video", GST_MAKE_FOURCC ('A', 'Y', 'U',
2155 'V'), DPTH8888, PSTR4444, PLANE0, OFFS1230, SUB4444, PACK_AYUV),
2156 MAKE_RGB_FORMAT (RGBx, "raw video", DPTH888, PSTR444, PLANE0, OFFS012,
2158 MAKE_RGB_FORMAT (BGRx, "raw video", DPTH888, PSTR444, PLANE0, OFFS210,
2160 MAKE_RGB_FORMAT (xRGB, "raw video", DPTH888, PSTR444, PLANE0, OFFS123,
2162 MAKE_RGB_FORMAT (xBGR, "raw video", DPTH888, PSTR444, PLANE0, OFFS321,
2164 MAKE_RGBA_FORMAT (RGBA, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS0123,
2165 SUB4444, PACK_RGBA),
2166 MAKE_RGBA_FORMAT (BGRA, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS2103,
2167 SUB4444, PACK_BGRA),
2168 MAKE_RGBA_PACK_FORMAT (ARGB, "raw video", DPTH8888, PSTR4444, PLANE0,
2169 OFFS1230, SUB4444, PACK_ARGB),
2170 MAKE_RGBA_FORMAT (ABGR, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS3210,
2171 SUB4444, PACK_ABGR),
2172 MAKE_RGB_FORMAT (RGB, "raw video", DPTH888, PSTR333, PLANE0, OFFS012, SUB444,
2174 MAKE_RGB_FORMAT (BGR, "raw video", DPTH888, PSTR333, PLANE0, OFFS210, SUB444,
2177 MAKE_YUV_FORMAT (Y41B, "raw video", GST_MAKE_FOURCC ('Y', '4', '1', 'B'),
2178 DPTH888, PSTR111, PLANE012, OFFS0, SUB411, PACK_Y41B),
2179 MAKE_YUV_FORMAT (Y42B, "raw video", GST_MAKE_FOURCC ('Y', '4', '2', 'B'),
2180 DPTH888, PSTR111, PLANE012, OFFS0, SUB422, PACK_Y42B),
2181 MAKE_YUV_FORMAT (YVYU, "raw video", GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'),
2182 DPTH888, PSTR244, PLANE0, OFFS031, SUB422, PACK_YVYU),
2183 MAKE_YUV_FORMAT (Y444, "raw video", GST_MAKE_FOURCC ('Y', '4', '4', '4'),
2184 DPTH888, PSTR111, PLANE012, OFFS0, SUB444, PACK_Y444),
2185 MAKE_YUV_C_FORMAT (v210, "raw video", GST_MAKE_FOURCC ('v', '2', '1', '0'),
2186 DPTH10_10_10, PSTR0, PLANE0, OFFS0, SUB422, PACK_v210),
2187 MAKE_YUV_FORMAT (v216, "raw video", GST_MAKE_FOURCC ('v', '2', '1', '6'),
2188 DPTH16_16_16, PSTR488, PLANE0, OFFS204, SUB422, PACK_v216),
2189 MAKE_YUV_FORMAT (NV12, "raw video", GST_MAKE_FOURCC ('N', 'V', '1', '2'),
2190 DPTH888, PSTR122, PLANE011, OFFS001, SUB420, PACK_NV12),
2191 MAKE_YUV_FORMAT (NV21, "raw video", GST_MAKE_FOURCC ('N', 'V', '2', '1'),
2192 DPTH888, PSTR122, PLANE011, OFFS010, SUB420, PACK_NV21),
2194 MAKE_GRAY_FORMAT (GRAY8, "raw video", DPTH8, PSTR1, PLANE0, OFFS0, SUB4,
2196 MAKE_GRAY_FORMAT (GRAY16_BE, "raw video", DPTH16, PSTR2, PLANE0, OFFS0, SUB4,
2198 MAKE_GRAY_LE_FORMAT (GRAY16_LE, "raw video", DPTH16, PSTR2, PLANE0, OFFS0,
2199 SUB4, PACK_GRAY16_LE),
2201 MAKE_YUV_FORMAT (v308, "raw video", GST_MAKE_FOURCC ('v', '3', '0', '8'),
2202 DPTH888, PSTR333, PLANE0, OFFS012, SUB444, PACK_v308),
2204 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2205 MAKE_RGB_LE_FORMAT (RGB16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0,
2206 SUB444, PACK_RGB16),
2207 MAKE_RGB_LE_FORMAT (BGR16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0,
2208 SUB444, PACK_BGR16),
2209 MAKE_RGB_LE_FORMAT (RGB15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0,
2210 SUB444, PACK_RGB15),
2211 MAKE_RGB_LE_FORMAT (BGR15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0,
2212 SUB444, PACK_BGR15),
2214 MAKE_RGB_FORMAT (RGB16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0, SUB444,
2216 MAKE_RGB_FORMAT (BGR16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0, SUB444,
2218 MAKE_RGB_FORMAT (RGB15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0, SUB444,
2220 MAKE_RGB_FORMAT (BGR15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0, SUB444,
2224 MAKE_YUV_C_FORMAT (UYVP, "raw video", GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'),
2225 DPTH10_10_10, PSTR0, PLANE0, OFFS0, SUB422, PACK_UYVP),
2226 MAKE_YUVA_FORMAT (A420, "raw video", GST_MAKE_FOURCC ('A', '4', '2', '0'),
2227 DPTH8888, PSTR1111, PLANE0123, OFFS0, SUB4204, PACK_A420),
2228 MAKE_RGBAP_FORMAT (RGB8P, "raw video", DPTH8_32, PSTR14, PLANE01,
2229 OFFS0, SUB44, PACK_RGB8P),
2230 MAKE_YUV_FORMAT (YUV9, "raw video", GST_MAKE_FOURCC ('Y', 'U', 'V', '9'),
2231 DPTH888, PSTR111, PLANE012, OFFS0, SUB410, PACK_410),
2232 MAKE_YUV_FORMAT (YVU9, "raw video", GST_MAKE_FOURCC ('Y', 'V', 'U', '9'),
2233 DPTH888, PSTR111, PLANE021, OFFS0, SUB410, PACK_410),
2234 MAKE_YUV_FORMAT (IYU1, "raw video", GST_MAKE_FOURCC ('I', 'Y', 'U', '1'),
2235 DPTH888, PSTR0, PLANE0, OFFS104, SUB411, PACK_IYU1),
2236 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2237 MAKE_RGBA_LE_PACK_FORMAT (ARGB64, "raw video", DPTH16_16_16_16, PSTR8888,
2239 OFFS2460, SUB444, PACK_ARGB64),
2240 MAKE_YUVA_LE_PACK_FORMAT (AYUV64, "raw video", 0x00000000, DPTH16_16_16_16,
2241 PSTR8888, PLANE0, OFFS2460, SUB444, PACK_AYUV64),
2243 MAKE_RGBA_PACK_FORMAT (ARGB64, "raw video", DPTH16_16_16_16, PSTR8888, PLANE0,
2244 OFFS2460, SUB444, PACK_ARGB64),
2245 MAKE_YUVA_PACK_FORMAT (AYUV64, "raw video", 0x00000000, DPTH16_16_16_16,
2246 PSTR8888, PLANE0, OFFS2460, SUB444, PACK_AYUV64),
2248 MAKE_RGB_FORMAT (r210, "raw video", DPTH10_10_10, PSTR444, PLANE0, OFFS0,
2250 MAKE_YUV_FORMAT (I420_10BE, "raw video", 0x00000000, DPTH10_10_10,
2251 PSTR222, PLANE012, OFFS0, SUB420, PACK_I420_10BE),
2252 MAKE_YUV_LE_FORMAT (I420_10LE, "raw video", 0x00000000, DPTH10_10_10,
2253 PSTR222, PLANE012, OFFS0, SUB420, PACK_I420_10LE),
2254 MAKE_YUV_FORMAT (I422_10BE, "raw video", 0x00000000, DPTH10_10_10,
2255 PSTR222, PLANE012, OFFS0, SUB422, PACK_I422_10BE),
2256 MAKE_YUV_LE_FORMAT (I422_10LE, "raw video", 0x00000000, DPTH10_10_10,
2257 PSTR222, PLANE012, OFFS0, SUB422, PACK_I422_10LE),
2258 MAKE_YUV_FORMAT (Y444_10BE, "raw video", 0x00000000, DPTH10_10_10,
2259 PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_10BE),
2260 MAKE_YUV_LE_FORMAT (Y444_10LE, "raw video", 0x00000000, DPTH10_10_10,
2261 PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_10LE),
2262 MAKE_RGB_FORMAT (GBR, "raw video", DPTH888, PSTR111, PLANE201, OFFS0, SUB444,
2264 MAKE_RGB_FORMAT (GBR_10BE, "raw video", DPTH10_10_10, PSTR222, PLANE201,
2267 MAKE_RGB_LE_FORMAT (GBR_10LE, "raw video", DPTH10_10_10, PSTR222, PLANE201,
2270 MAKE_YUV_FORMAT (NV16, "raw video", GST_MAKE_FOURCC ('N', 'V', '1', '6'),
2271 DPTH888, PSTR111, PLANE011, OFFS001, SUB422, PACK_NV16),
2272 MAKE_YUV_FORMAT (NV24, "raw video", GST_MAKE_FOURCC ('N', 'V', '2', '4'),
2273 DPTH888, PSTR111, PLANE011, OFFS001, SUB444, PACK_NV24),
2276 static GstVideoFormat
2277 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
2279 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
2280 blue_mask == 0x0000ff00) {
2281 return GST_VIDEO_FORMAT_RGBx;
2283 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
2284 blue_mask == 0xff000000) {
2285 return GST_VIDEO_FORMAT_BGRx;
2287 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
2288 blue_mask == 0x000000ff) {
2289 return GST_VIDEO_FORMAT_xRGB;
2291 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
2292 blue_mask == 0x00ff0000) {
2293 return GST_VIDEO_FORMAT_xBGR;
2296 return GST_VIDEO_FORMAT_UNKNOWN;
2299 static GstVideoFormat
2300 gst_video_format_from_rgba32_masks (int red_mask, int green_mask,
2301 int blue_mask, int alpha_mask)
2303 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
2304 blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
2305 return GST_VIDEO_FORMAT_RGBA;
2307 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
2308 blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
2309 return GST_VIDEO_FORMAT_BGRA;
2311 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
2312 blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
2313 return GST_VIDEO_FORMAT_ARGB;
2315 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
2316 blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
2317 return GST_VIDEO_FORMAT_ABGR;
2319 return GST_VIDEO_FORMAT_UNKNOWN;
2322 static GstVideoFormat
2323 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
2325 if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
2326 return GST_VIDEO_FORMAT_RGB;
2328 if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
2329 return GST_VIDEO_FORMAT_BGR;
2332 return GST_VIDEO_FORMAT_UNKNOWN;
2335 #define GST_VIDEO_COMP1_MASK_16_INT 0xf800
2336 #define GST_VIDEO_COMP2_MASK_16_INT 0x07e0
2337 #define GST_VIDEO_COMP3_MASK_16_INT 0x001f
2339 #define GST_VIDEO_COMP1_MASK_15_INT 0x7c00
2340 #define GST_VIDEO_COMP2_MASK_15_INT 0x03e0
2341 #define GST_VIDEO_COMP3_MASK_15_INT 0x001f
2343 static GstVideoFormat
2344 gst_video_format_from_rgb16_masks (int red_mask, int green_mask, int blue_mask)
2346 if (red_mask == GST_VIDEO_COMP1_MASK_16_INT
2347 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
2348 && blue_mask == GST_VIDEO_COMP3_MASK_16_INT) {
2349 return GST_VIDEO_FORMAT_RGB16;
2351 if (red_mask == GST_VIDEO_COMP3_MASK_16_INT
2352 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
2353 && blue_mask == GST_VIDEO_COMP1_MASK_16_INT) {
2354 return GST_VIDEO_FORMAT_BGR16;
2356 if (red_mask == GST_VIDEO_COMP1_MASK_15_INT
2357 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
2358 && blue_mask == GST_VIDEO_COMP3_MASK_15_INT) {
2359 return GST_VIDEO_FORMAT_RGB15;
2361 if (red_mask == GST_VIDEO_COMP3_MASK_15_INT
2362 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
2363 && blue_mask == GST_VIDEO_COMP1_MASK_15_INT) {
2364 return GST_VIDEO_FORMAT_BGR15;
2366 return GST_VIDEO_FORMAT_UNKNOWN;
2370 * gst_video_format_from_masks:
2371 * @depth: the amount of bits used for a pixel
2372 * @bpp: the amount of bits used to store a pixel. This value is bigger than
2374 * @endianness: the endianness of the masks, #G_LITTLE_ENDIAN or #G_BIG_ENDIAN
2375 * @red_mask: the red mask
2376 * @green_mask: the green mask
2377 * @blue_mask: the blue mask
2378 * @alpha_mask: the alpha mask, or 0 if no alpha mask
2380 * Find the #GstVideoFormat for the given parameters.
2382 * Returns: a #GstVideoFormat or GST_VIDEO_FORMAT_UNKNOWN when the parameters to
2383 * not specify a known format.
2386 gst_video_format_from_masks (gint depth, gint bpp, gint endianness,
2387 guint red_mask, guint green_mask, guint blue_mask, guint alpha_mask)
2389 GstVideoFormat format;
2391 /* our caps system handles 24/32bpp RGB as big-endian. */
2392 if ((bpp == 24 || bpp == 32) && endianness == G_LITTLE_ENDIAN) {
2393 red_mask = GUINT32_TO_BE (red_mask);
2394 green_mask = GUINT32_TO_BE (green_mask);
2395 blue_mask = GUINT32_TO_BE (blue_mask);
2396 alpha_mask = GUINT32_TO_BE (alpha_mask);
2397 endianness = G_BIG_ENDIAN;
2405 if (depth == 30 && bpp == 32) {
2406 format = GST_VIDEO_FORMAT_r210;
2407 } else if (depth == 24 && bpp == 32) {
2408 format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
2410 } else if (depth == 32 && bpp == 32 && alpha_mask) {
2411 format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
2412 blue_mask, alpha_mask);
2413 } else if (depth == 24 && bpp == 24) {
2414 format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
2416 } else if ((depth == 15 || depth == 16) && bpp == 16 &&
2417 endianness == G_BYTE_ORDER) {
2418 format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
2420 } else if (depth == 8 && bpp == 8) {
2421 format = GST_VIDEO_FORMAT_RGB8P;
2422 } else if (depth == 64 && bpp == 64) {
2423 format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
2424 blue_mask, alpha_mask);
2425 if (format == GST_VIDEO_FORMAT_ARGB) {
2426 format = GST_VIDEO_FORMAT_ARGB64;
2428 format = GST_VIDEO_FORMAT_UNKNOWN;
2431 format = GST_VIDEO_FORMAT_UNKNOWN;
2437 * gst_video_format_from_fourcc:
2438 * @fourcc: a FOURCC value representing raw YUV video
2440 * Converts a FOURCC value into the corresponding #GstVideoFormat.
2441 * If the FOURCC cannot be represented by #GstVideoFormat,
2442 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
2444 * Returns: the #GstVideoFormat describing the FOURCC value
2447 gst_video_format_from_fourcc (guint32 fourcc)
2450 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
2451 return GST_VIDEO_FORMAT_I420;
2452 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
2453 return GST_VIDEO_FORMAT_YV12;
2454 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
2455 return GST_VIDEO_FORMAT_YUY2;
2456 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
2457 return GST_VIDEO_FORMAT_YVYU;
2458 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
2459 return GST_VIDEO_FORMAT_UYVY;
2460 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
2461 return GST_VIDEO_FORMAT_AYUV;
2462 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
2463 return GST_VIDEO_FORMAT_Y41B;
2464 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
2465 return GST_VIDEO_FORMAT_Y42B;
2466 case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
2467 return GST_VIDEO_FORMAT_Y444;
2468 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
2469 return GST_VIDEO_FORMAT_v210;
2470 case GST_MAKE_FOURCC ('v', '2', '1', '6'):
2471 return GST_VIDEO_FORMAT_v216;
2472 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
2473 return GST_VIDEO_FORMAT_NV12;
2474 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
2475 return GST_VIDEO_FORMAT_NV21;
2476 case GST_MAKE_FOURCC ('N', 'V', '1', '6'):
2477 return GST_VIDEO_FORMAT_NV16;
2478 case GST_MAKE_FOURCC ('N', 'V', '2', '4'):
2479 return GST_VIDEO_FORMAT_NV24;
2480 case GST_MAKE_FOURCC ('v', '3', '0', '8'):
2481 return GST_VIDEO_FORMAT_v308;
2482 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
2483 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
2484 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
2485 return GST_VIDEO_FORMAT_GRAY8;
2486 case GST_MAKE_FOURCC ('Y', '1', '6', ' '):
2487 return GST_VIDEO_FORMAT_GRAY16_LE;
2488 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'):
2489 return GST_VIDEO_FORMAT_UYVP;
2490 case GST_MAKE_FOURCC ('A', '4', '2', '0'):
2491 return GST_VIDEO_FORMAT_A420;
2492 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
2493 return GST_VIDEO_FORMAT_YUV9;
2494 case GST_MAKE_FOURCC ('Y', 'V', 'U', '9'):
2495 return GST_VIDEO_FORMAT_YVU9;
2496 case GST_MAKE_FOURCC ('I', 'Y', 'U', '1'):
2497 return GST_VIDEO_FORMAT_IYU1;
2498 case GST_MAKE_FOURCC ('A', 'Y', '6', '4'):
2499 return GST_VIDEO_FORMAT_AYUV64;
2501 return GST_VIDEO_FORMAT_UNKNOWN;
2506 * gst_video_format_from_string:
2507 * @format: a format string
2509 * Convert the @format string to its #GstVideoFormat.
2511 * Returns: the #GstVideoFormat for @format or GST_VIDEO_FORMAT_UNKNOWN when the
2512 * string is not a known format.
2515 gst_video_format_from_string (const gchar * format)
2519 g_return_val_if_fail (format != NULL, GST_VIDEO_FORMAT_UNKNOWN);
2521 for (i = 0; i < G_N_ELEMENTS (formats); i++) {
2522 if (strcmp (GST_VIDEO_FORMAT_INFO_NAME (&formats[i].info), format) == 0)
2523 return GST_VIDEO_FORMAT_INFO_FORMAT (&formats[i].info);
2525 return GST_VIDEO_FORMAT_UNKNOWN;
2530 * gst_video_format_to_fourcc:
2531 * @format: a #GstVideoFormat video format
2533 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
2534 * a few YUV formats have corresponding FOURCC values. If @format has
2535 * no corresponding FOURCC value, 0 is returned.
2537 * Returns: the FOURCC corresponding to @format
2540 gst_video_format_to_fourcc (GstVideoFormat format)
2542 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
2544 if (format >= G_N_ELEMENTS (formats))
2547 return formats[format].fourcc;
2551 gst_video_format_to_string (GstVideoFormat format)
2553 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
2555 if (format >= G_N_ELEMENTS (formats))
2558 return GST_VIDEO_FORMAT_INFO_NAME (&formats[format].info);
2562 * gst_video_format_get_info:
2563 * @format: a #GstVideoFormat
2565 * Get the #GstVideoFormatInfo for @format
2567 * Returns: The #GstVideoFormatInfo for @format.
2569 const GstVideoFormatInfo *
2570 gst_video_format_get_info (GstVideoFormat format)
2572 g_return_val_if_fail (format < G_N_ELEMENTS (formats), NULL);
2574 return &formats[format].info;
2578 * gst_video_format_get_palette:
2579 * @format: a #GstVideoFormat
2580 * @size: (out): size of the palette in bytes
2582 * Get the default palette of @format. This the palette used in the pack
2583 * function for paletted formats.
2585 * Returns: the default palette of @format or %NULL when @format does not have a
2591 gst_video_format_get_palette (GstVideoFormat format, gsize * size)
2593 g_return_val_if_fail (format < G_N_ELEMENTS (formats), NULL);
2594 g_return_val_if_fail (size != NULL, NULL);
2597 case GST_VIDEO_FORMAT_RGB8P:
2598 *size = sizeof (std_palette_RGB8P);
2599 return std_palette_RGB8P;