videoconvert.c 72.1 KB
Newer Older
1 2
/* GStreamer
 * Copyright (C) 2010 David Schleef <ds@schleef.org>
3
 * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

25
#include "videoconvert.h"
26 27
#include <glib.h>
#include <string.h>
28
#include "gstvideoconvertorc.h"
29 30


31
static void videoconvert_convert_generic (VideoConvert * convert,
32
    guint8 * dest, const guint8 * src);
33 34 35 36 37
static void videoconvert_convert_lookup_fastpath (VideoConvert * convert);
static void videoconvert_convert_lookup_getput (VideoConvert * convert);
static void videoconvert_dither_none (VideoConvert * convert, int j);
static void videoconvert_dither_verterr (VideoConvert * convert, int j);
static void videoconvert_dither_halftone (VideoConvert * convert, int j);
38 39


40 41
VideoConvert *
videoconvert_convert_new (GstVideoFormat to_format, ColorSpaceColorSpec to_spec,
42 43
    GstVideoFormat from_format, ColorSpaceColorSpec from_spec,
    int width, int height)
44
{
45
  VideoConvert *convert;
46 47
  int i;

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  g_return_val_if_fail (!gst_video_format_is_rgb (to_format)
      || to_spec == COLOR_SPEC_RGB, NULL);
  g_return_val_if_fail (!gst_video_format_is_yuv (to_format)
      || to_spec == COLOR_SPEC_YUV_BT709
      || to_spec == COLOR_SPEC_YUV_BT470_6, NULL);
  g_return_val_if_fail (gst_video_format_is_rgb (to_format)
      || gst_video_format_is_yuv (to_format)
      || (gst_video_format_is_gray (to_format) &&
          to_spec == COLOR_SPEC_GRAY), NULL);

  g_return_val_if_fail (!gst_video_format_is_rgb (from_format)
      || from_spec == COLOR_SPEC_RGB, NULL);
  g_return_val_if_fail (!gst_video_format_is_yuv (from_format)
      || from_spec == COLOR_SPEC_YUV_BT709
      || from_spec == COLOR_SPEC_YUV_BT470_6, NULL);
  g_return_val_if_fail (gst_video_format_is_rgb (from_format)
      || gst_video_format_is_yuv (from_format)
      || (gst_video_format_is_gray (from_format) &&
          from_spec == COLOR_SPEC_GRAY), NULL);

68 69
  convert = g_malloc (sizeof (VideoConvert));
  memset (convert, 0, sizeof (VideoConvert));
70 71

  convert->to_format = to_format;
72
  convert->to_spec = to_spec;
73
  convert->from_format = from_format;
74
  convert->from_spec = from_spec;
75 76
  convert->height = height;
  convert->width = width;
77 78
  convert->convert = videoconvert_convert_generic;
  convert->dither16 = videoconvert_dither_none;
79

80 81 82 83 84 85 86
  if (gst_video_format_get_component_depth (to_format, 0) > 8 ||
      gst_video_format_get_component_depth (from_format, 0) > 8) {
    convert->use_16bit = TRUE;
  } else {
    convert->use_16bit = FALSE;
  }

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  for (i = 0; i < 4; i++) {
    convert->dest_stride[i] = gst_video_format_get_row_stride (to_format, i,
        width);
    convert->dest_offset[i] = gst_video_format_get_component_offset (to_format,
        i, width, height);
    if (i == 0)
      convert->dest_offset[i] = 0;

    convert->src_stride[i] = gst_video_format_get_row_stride (from_format, i,
        width);
    convert->src_offset[i] = gst_video_format_get_component_offset (from_format,
        i, width, height);
    if (i == 0)
      convert->src_offset[i] = 0;

    GST_DEBUG ("%d: dest %d %d src %d %d", i,
        convert->dest_stride[i], convert->dest_offset[i],
        convert->src_stride[i], convert->src_offset[i]);
  }

107 108
  videoconvert_convert_lookup_fastpath (convert);
  videoconvert_convert_lookup_getput (convert);
109

110 111
  convert->tmpline = g_malloc (sizeof (guint8) * (width + 8) * 4);
  convert->tmpline16 = g_malloc (sizeof (guint16) * (width + 8) * 4);
112
  convert->errline = g_malloc (sizeof (guint16) * width * 4);
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  if (to_format == GST_VIDEO_FORMAT_RGB8_PALETTED) {
    /* build poor man's palette, taken from ffmpegcolorspace */
    static const guint8 pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
    guint32 *palette;
    gint r, g, b;

    convert->palette = palette = g_new (guint32, 256);
    i = 0;
    for (r = 0; r < 6; r++) {
      for (g = 0; g < 6; g++) {
        for (b = 0; b < 6; b++) {
          palette[i++] =
              (0xffU << 24) | (pal_value[r] << 16) | (pal_value[g] << 8) |
              pal_value[b];
        }
      }
    }
    palette[i++] = 0;           /* 100% transparent, i == 6*6*6 */
    while (i < 256)
      palette[i++] = 0xff000000;
  }

136 137 138 139
  return convert;
}

void
140
videoconvert_convert_free (VideoConvert * convert)
141
{
142 143 144
  g_free (convert->palette);
  g_free (convert->tmpline);
  g_free (convert->tmpline16);
145
  g_free (convert->errline);
146 147 148 149 150

  g_free (convert);
}

void
151
videoconvert_convert_set_interlaced (VideoConvert * convert,
152 153 154 155 156
    gboolean interlaced)
{
  convert->interlaced = interlaced;
}

157
void
158
videoconvert_convert_set_dither (VideoConvert * convert, int type)
159 160 161 162
{
  switch (type) {
    case 0:
    default:
163
      convert->dither16 = videoconvert_dither_none;
164 165
      break;
    case 1:
166
      convert->dither16 = videoconvert_dither_verterr;
167 168
      break;
    case 2:
169
      convert->dither16 = videoconvert_dither_halftone;
170 171 172 173
      break;
  }
}

174
void
175
videoconvert_convert_set_palette (VideoConvert * convert,
176
    const guint32 * palette)
177 178 179 180 181 182 183
{
  if (convert->palette == NULL) {
    convert->palette = g_malloc (sizeof (guint32) * 256);
  }
  memcpy (convert->palette, palette, sizeof (guint32) * 256);
}

184
const guint32 *
185
videoconvert_convert_get_palette (VideoConvert * convert)
186 187 188 189
{
  return convert->palette;
}

190
void
191
videoconvert_convert_convert (VideoConvert * convert,
192
    guint8 * dest, const guint8 * src)
193 194 195 196 197 198 199 200 201 202
{
  convert->convert (convert, dest, src);
}

/* Line conversion to AYUV */

#define FRAME_GET_LINE(dir, comp, line) \
  ((dir) + convert-> dir ## _offset[(comp)] + convert-> dir ## _stride[(comp)] * (line))

static void
203
getline_I420 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
204 205 206 207 208 209 210 211
{
  cogorc_getline_I420 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j >> 1),
      FRAME_GET_LINE (src, 2, j >> 1), convert->width);
}

static void
212
putline_I420 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
213 214 215 216 217 218 219
{
  cogorc_putline_I420 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j >> 1),
      FRAME_GET_LINE (dest, 2, j >> 1), src, convert->width / 2);
}

static void
220
getline_YV12 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
221 222 223 224 225 226 227 228
{
  cogorc_getline_I420 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j >> 1),
      FRAME_GET_LINE (src, 2, j >> 1), convert->width);
}

static void
229
putline_YV12 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
230 231 232 233 234 235 236
{
  cogorc_putline_I420 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j >> 1),
      FRAME_GET_LINE (dest, 2, j >> 1), src, convert->width / 2);
}

static void
237
getline_YUY2 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
238 239 240 241 242
{
  cogorc_getline_YUY2 (dest, FRAME_GET_LINE (src, 0, j), convert->width / 2);
}

static void
243
putline_YUY2 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
244 245 246 247 248
{
  cogorc_putline_YUY2 (FRAME_GET_LINE (dest, 0, j), src, convert->width / 2);
}

static void
249
getline_UYVY (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
250 251 252 253 254
{
  cogorc_getline_UYVY (dest, FRAME_GET_LINE (src, 0, j), convert->width / 2);
}

static void
255
putline_UYVY (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
256 257 258 259 260
{
  cogorc_putline_UYVY (FRAME_GET_LINE (dest, 0, j), src, convert->width / 2);
}

static void
261
getline_YVYU (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
262 263 264 265 266
{
  cogorc_getline_YVYU (dest, FRAME_GET_LINE (src, 0, j), convert->width / 2);
}

static void
267
putline_YVYU (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
268 269 270 271 272
{
  cogorc_putline_YVYU (FRAME_GET_LINE (dest, 0, j), src, convert->width / 2);
}

static void
273
getline_v308 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
274 275
{
  int i;
276
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
277 278 279 280 281 282 283 284 285
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = srcline[i * 3 + 0];
    dest[i * 4 + 2] = srcline[i * 3 + 1];
    dest[i * 4 + 3] = srcline[i * 3 + 2];
  }
}

static void
286
putline_v308 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
287 288 289 290 291 292 293 294 295 296 297
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i * 3 + 0] = src[i * 4 + 1];
    destline[i * 3 + 1] = src[i * 4 + 2];
    destline[i * 3 + 2] = src[i * 4 + 3];
  }
}

static void
298
getline_AYUV (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
299 300 301 302 303
{
  memcpy (dest, FRAME_GET_LINE (src, 0, j), convert->width * 4);
}

static void
304
putline_AYUV (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
305 306 307 308 309 310
{
  memcpy (FRAME_GET_LINE (dest, 0, j), src, convert->width * 4);
}

#if 0
static void
311
getline_v410 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
312 313
{
  int i;
314
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
315 316 317 318 319 320 321 322 323 324
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = GST_READ_UINT16_LE (srcline + i * 8 + 0);
    dest[i * 4 + 1] = GST_READ_UINT16_LE (srcline + i * 8 + 2);
    dest[i * 4 + 2] = GST_READ_UINT16_LE (srcline + i * 8 + 4);
    dest[i * 4 + 3] = GST_READ_UINT16_LE (srcline + i * 8 + 6);
  }
}
#endif

static void
325
getline_v210 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
326 327
{
  int i;
328
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390

  for (i = 0; i < convert->width; i += 6) {
    guint32 a0, a1, a2, a3;
    guint16 y0, y1, y2, y3, y4, y5;
    guint16 u0, u2, u4;
    guint16 v0, v2, v4;

    a0 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 0);
    a1 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 4);
    a2 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 8);
    a3 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 12);

    u0 = ((a0 >> 0) & 0x3ff) >> 2;
    y0 = ((a0 >> 10) & 0x3ff) >> 2;
    v0 = ((a0 >> 20) & 0x3ff) >> 2;
    y1 = ((a1 >> 0) & 0x3ff) >> 2;

    u2 = ((a1 >> 10) & 0x3ff) >> 2;
    y2 = ((a1 >> 20) & 0x3ff) >> 2;
    v2 = ((a2 >> 0) & 0x3ff) >> 2;
    y3 = ((a2 >> 10) & 0x3ff) >> 2;

    u4 = ((a2 >> 20) & 0x3ff) >> 2;
    y4 = ((a3 >> 0) & 0x3ff) >> 2;
    v4 = ((a3 >> 10) & 0x3ff) >> 2;
    y5 = ((a3 >> 20) & 0x3ff) >> 2;

    dest[4 * (i + 0) + 0] = 0xff;
    dest[4 * (i + 0) + 1] = y0;
    dest[4 * (i + 0) + 2] = u0;
    dest[4 * (i + 0) + 3] = v0;

    dest[4 * (i + 1) + 0] = 0xff;
    dest[4 * (i + 1) + 1] = y1;
    dest[4 * (i + 1) + 2] = u0;
    dest[4 * (i + 1) + 3] = v0;

    dest[4 * (i + 2) + 0] = 0xff;
    dest[4 * (i + 2) + 1] = y2;
    dest[4 * (i + 2) + 2] = u2;
    dest[4 * (i + 2) + 3] = v2;

    dest[4 * (i + 3) + 0] = 0xff;
    dest[4 * (i + 3) + 1] = y3;
    dest[4 * (i + 3) + 2] = u2;
    dest[4 * (i + 3) + 3] = v2;

    dest[4 * (i + 4) + 0] = 0xff;
    dest[4 * (i + 4) + 1] = y4;
    dest[4 * (i + 4) + 2] = u4;
    dest[4 * (i + 4) + 3] = v4;

    dest[4 * (i + 5) + 0] = 0xff;
    dest[4 * (i + 5) + 1] = y5;
    dest[4 * (i + 5) + 2] = u4;
    dest[4 * (i + 5) + 3] = v4;

  }

}

static void
391
putline_v210 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
392 393 394 395 396 397 398 399 400 401
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);

  for (i = 0; i < convert->width + 5; i += 6) {
    guint32 a0, a1, a2, a3;
    guint16 y0, y1, y2, y3, y4, y5;
    guint16 u0, u1, u2;
    guint16 v0, v1, v2;

402 403 404 405 406 407
    y0 = src[4 * (i + 0) + 1] << 2;
    y1 = src[4 * (i + 1) + 1] << 2;
    y2 = src[4 * (i + 2) + 1] << 2;
    y3 = src[4 * (i + 3) + 1] << 2;
    y4 = src[4 * (i + 4) + 1] << 2;
    y5 = src[4 * (i + 5) + 1] << 2;
408

409 410 411
    u0 = (src[4 * (i + 0) + 2] + src[4 * (i + 1) + 2]) << 1;
    u1 = (src[4 * (i + 2) + 2] + src[4 * (i + 3) + 2]) << 1;
    u2 = (src[4 * (i + 4) + 2] + src[4 * (i + 5) + 2]) << 1;
412

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    v0 = (src[4 * (i + 0) + 3] + src[4 * (i + 1) + 3]) << 1;
    v1 = (src[4 * (i + 2) + 3] + src[4 * (i + 3) + 3]) << 1;
    v2 = (src[4 * (i + 4) + 3] + src[4 * (i + 5) + 3]) << 1;

    a0 = u0 | (y0 << 10) | (v0 << 20);
    a1 = y1 | (u1 << 10) | (y2 << 20);
    a2 = v1 | (y3 << 10) | (u2 << 20);
    a3 = y4 | (v2 << 10) | (y5 << 20);

    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 0, a0);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 4, a1);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 8, a2);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 12, a3);
  }
}

static void
430
getline16_v210 (VideoConvert * convert, guint16 * dest, const guint8 * src,
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    int j)
{
  int i;
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);

  for (i = 0; i < convert->width; i += 6) {
    guint32 a0, a1, a2, a3;
    guint16 y0, y1, y2, y3, y4, y5;
    guint16 u0, u2, u4;
    guint16 v0, v2, v4;

    a0 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 0);
    a1 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 4);
    a2 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 8);
    a3 = GST_READ_UINT32_LE (srcline + (i / 6) * 16 + 12);

    u0 = ((a0 >> 0) & 0x3ff) << 6;
    y0 = ((a0 >> 10) & 0x3ff) << 6;
    v0 = ((a0 >> 20) & 0x3ff) << 6;
    y1 = ((a1 >> 0) & 0x3ff) << 6;

    u2 = ((a1 >> 10) & 0x3ff) << 6;
    y2 = ((a1 >> 20) & 0x3ff) << 6;
    v2 = ((a2 >> 0) & 0x3ff) << 6;
    y3 = ((a2 >> 10) & 0x3ff) << 6;

    u4 = ((a2 >> 20) & 0x3ff) << 6;
    y4 = ((a3 >> 0) & 0x3ff) << 6;
    v4 = ((a3 >> 10) & 0x3ff) << 6;
    y5 = ((a3 >> 20) & 0x3ff) << 6;

    dest[4 * (i + 0) + 0] = 0xffff;
    dest[4 * (i + 0) + 1] = y0;
    dest[4 * (i + 0) + 2] = u0;
    dest[4 * (i + 0) + 3] = v0;

    dest[4 * (i + 1) + 0] = 0xffff;
    dest[4 * (i + 1) + 1] = y1;
    dest[4 * (i + 1) + 2] = u0;
    dest[4 * (i + 1) + 3] = v0;

    dest[4 * (i + 2) + 0] = 0xffff;
    dest[4 * (i + 2) + 1] = y2;
    dest[4 * (i + 2) + 2] = u2;
    dest[4 * (i + 2) + 3] = v2;

    dest[4 * (i + 3) + 0] = 0xffff;
    dest[4 * (i + 3) + 1] = y3;
    dest[4 * (i + 3) + 2] = u2;
    dest[4 * (i + 3) + 3] = v2;

    dest[4 * (i + 4) + 0] = 0xffff;
    dest[4 * (i + 4) + 1] = y4;
    dest[4 * (i + 4) + 2] = u4;
    dest[4 * (i + 4) + 3] = v4;

    dest[4 * (i + 5) + 0] = 0xffff;
    dest[4 * (i + 5) + 1] = y5;
    dest[4 * (i + 5) + 2] = u4;
    dest[4 * (i + 5) + 3] = v4;

  }
}

static void
496
putline16_v210 (VideoConvert * convert, guint8 * dest, const guint16 * src,
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
    int j)
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);

  for (i = 0; i < convert->width + 5; i += 6) {
    guint32 a0, a1, a2, a3;
    guint16 y0, y1, y2, y3, y4, y5;
    guint16 u0, u1, u2;
    guint16 v0, v1, v2;

    y0 = src[4 * (i + 0) + 1] >> 6;
    y1 = src[4 * (i + 1) + 1] >> 6;
    y2 = src[4 * (i + 2) + 1] >> 6;
    y3 = src[4 * (i + 3) + 1] >> 6;
    y4 = src[4 * (i + 4) + 1] >> 6;
    y5 = src[4 * (i + 5) + 1] >> 6;

    u0 = (src[4 * (i + 0) + 2] + src[4 * (i + 1) + 2] + 1) >> 7;
    u1 = (src[4 * (i + 2) + 2] + src[4 * (i + 3) + 2] + 1) >> 7;
    u2 = (src[4 * (i + 4) + 2] + src[4 * (i + 5) + 2] + 1) >> 7;

    v0 = (src[4 * (i + 0) + 3] + src[4 * (i + 1) + 3] + 1) >> 7;
    v1 = (src[4 * (i + 2) + 3] + src[4 * (i + 3) + 3] + 1) >> 7;
    v2 = (src[4 * (i + 4) + 3] + src[4 * (i + 5) + 3] + 1) >> 7;
522

523 524 525 526
    a0 = u0 | (y0 << 10) | (v0 << 20);
    a1 = y1 | (u1 << 10) | (y2 << 20);
    a2 = v1 | (y3 << 10) | (u2 << 20);
    a3 = y4 | (v2 << 10) | (y5 << 20);
527 528 529 530 531 532 533 534 535

    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 0, a0);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 4, a1);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 8, a2);
    GST_WRITE_UINT32_LE (destline + (i / 6) * 16 + 12, a3);
  }
}

static void
536
getline_v216 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
537 538
{
  int i;
539
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
540 541
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
542 543 544
    dest[i * 4 + 1] = GST_READ_UINT16_LE (srcline + i * 4 + 2) >> 8;
    dest[i * 4 + 2] = GST_READ_UINT16_LE (srcline + (i >> 1) * 8 + 0) >> 8;
    dest[i * 4 + 3] = GST_READ_UINT16_LE (srcline + (i >> 1) * 8 + 4) >> 8;
545 546 547 548
  }
}

static void
549
putline_v216 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
550 551 552 553 554 555 556 557 558 559 560
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width / 2; i++) {
    GST_WRITE_UINT16_LE (destline + i * 8 + 0, src[(i * 2 + 0) * 4 + 2] << 8);
    GST_WRITE_UINT16_LE (destline + i * 8 + 2, src[(i * 2 + 0) * 4 + 1] << 8);
    GST_WRITE_UINT16_LE (destline + i * 8 + 4, src[(i * 2 + 1) * 4 + 3] << 8);
    GST_WRITE_UINT16_LE (destline + i * 8 + 8, src[(i * 2 + 0) * 4 + 1] << 8);
  }
}

561
static void
562
getline16_v216 (VideoConvert * convert, guint16 * dest, const guint8 * src,
563 564 565 566 567 568 569 570 571 572 573 574 575
    int j)
{
  int i;
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xffff;
    dest[i * 4 + 1] = GST_READ_UINT16_LE (srcline + i * 4 + 2);
    dest[i * 4 + 2] = GST_READ_UINT16_LE (srcline + (i >> 1) * 8 + 0);
    dest[i * 4 + 3] = GST_READ_UINT16_LE (srcline + (i >> 1) * 8 + 4);
  }
}

static void
576
putline16_v216 (VideoConvert * convert, guint8 * dest, const guint16 * src,
577 578 579 580 581 582 583 584 585 586 587 588
    int j)
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width / 2; i++) {
    GST_WRITE_UINT16_LE (destline + i * 8 + 0, src[(i * 2 + 0) * 4 + 2]);
    GST_WRITE_UINT16_LE (destline + i * 8 + 2, src[(i * 2 + 0) * 4 + 1]);
    GST_WRITE_UINT16_LE (destline + i * 8 + 4, src[(i * 2 + 1) * 4 + 3]);
    GST_WRITE_UINT16_LE (destline + i * 8 + 8, src[(i * 2 + 0) * 4 + 1]);
  }
}

589
static void
590
getline_Y41B (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
591
{
592 593
  cogorc_getline_YUV9 (dest,
      FRAME_GET_LINE (src, 0, j),
594 595
      FRAME_GET_LINE (src, 1, j), FRAME_GET_LINE (src, 2, j),
      convert->width / 2);
596 597 598
}

static void
599
putline_Y41B (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
{
  int i;
  guint8 *destlineY = FRAME_GET_LINE (dest, 0, j);
  guint8 *destlineU = FRAME_GET_LINE (dest, 1, j);
  guint8 *destlineV = FRAME_GET_LINE (dest, 2, j);

  for (i = 0; i < convert->width - 3; i += 4) {
    destlineY[i] = src[i * 4 + 1];
    destlineY[i + 1] = src[i * 4 + 5];
    destlineY[i + 2] = src[i * 4 + 9];
    destlineY[i + 3] = src[i * 4 + 13];

    destlineU[i >> 2] =
        (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10] + src[i * 4 + 14] +
        2) >> 2;
    destlineV[i >> 2] =
        (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11] + src[i * 4 + 15] +
        2) >> 2;
  }

  if (i == convert->width - 3) {
    destlineY[i] = src[i * 4 + 1];
    destlineY[i + 1] = src[i * 4 + 5];
    destlineY[i + 2] = src[i * 4 + 9];

    destlineU[i >> 2] =
        (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10] + 1) / 3;
    destlineV[i >> 2] =
        (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11] + 1) / 3;
  } else if (i == convert->width - 2) {
    destlineY[i] = src[i * 4 + 1];
    destlineY[i + 1] = src[i * 4 + 5];

    destlineU[i >> 2] = (src[i * 4 + 2] + src[i * 4 + 6] + 1) >> 1;
    destlineV[i >> 2] = (src[i * 4 + 3] + src[i * 4 + 7] + 1) >> 1;
  } else if (i == convert->width - 1) {
    destlineY[i + 1] = src[i * 4 + 5];

    destlineU[i >> 2] = src[i * 4 + 2];
    destlineV[i >> 2] = src[i * 4 + 3];
  }
}

643
static void
644
getline_Y42B (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
645 646 647 648 649 650 651 652
{
  cogorc_getline_Y42B (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j),
      FRAME_GET_LINE (src, 2, j), convert->width / 2);
}

static void
653
putline_Y42B (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
654 655 656 657 658 659 660
{
  cogorc_putline_Y42B (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j),
      FRAME_GET_LINE (dest, 2, j), src, convert->width / 2);
}

static void
661
getline_Y444 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
662 663 664 665 666 667 668
{
  cogorc_getline_Y444 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j), FRAME_GET_LINE (src, 2, j), convert->width);
}

static void
669
putline_Y444 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
670 671 672 673 674 675 676
{
  cogorc_putline_Y444 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j),
      FRAME_GET_LINE (dest, 2, j), src, convert->width);
}

static void
677
getline_Y800 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
678 679 680 681 682
{
  cogorc_getline_Y800 (dest, FRAME_GET_LINE (src, 0, j), convert->width);
}

static void
683
putline_Y800 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
684 685 686 687
{
  cogorc_putline_Y800 (FRAME_GET_LINE (dest, 0, j), src, convert->width);
}

688
static void
689
getline_Y16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
690 691 692 693 694
{
  cogorc_getline_Y16 (dest, FRAME_GET_LINE (src, 0, j), convert->width);
}

static void
695
putline_Y16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
696 697 698 699
{
  cogorc_putline_Y16 (FRAME_GET_LINE (dest, 0, j), src, convert->width);
}

700
static void
701
getline_RGB16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
702 703 704 705 706 707 708 709 710 711 712 713
{
  int i;
  const guint16 *srcline = (const guint16 *) FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = ((srcline[i] >> 11) & 0x1f) << 3;
    dest[i * 4 + 2] = ((srcline[i] >> 5) & 0x3f) << 2;
    dest[i * 4 + 3] = ((srcline[i]) & 0x1f) << 3;
  }
}

static void
714
putline_RGB16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
715 716 717 718 719 720 721 722 723 724 725
{
  int i;
  guint16 *destline = (guint16 *) FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i] =
        ((src[i * 4 + 1] >> 3) << 11) | ((src[i * 4 +
                2] >> 2) << 5) | (src[i * 4 + 3] >> 3);
  }
}

static void
726
getline_BGR16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
727 728 729 730 731 732 733 734 735 736 737 738
{
  int i;
  const guint16 *srcline = (const guint16 *) FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 3] = ((srcline[i] >> 11) & 0x1f) << 3;
    dest[i * 4 + 2] = ((srcline[i] >> 5) & 0x3f) << 2;
    dest[i * 4 + 1] = ((srcline[i]) & 0x1f) << 3;
  }
}

static void
739
putline_BGR16 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
740 741 742 743 744 745 746 747 748 749
{
  int i;
  guint16 *destline = (guint16 *) FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i] =
        ((src[i * 4 + 3] >> 3) << 11) | ((src[i * 4 +
                2] >> 2) << 5) | (src[i * 4 + 1] >> 3);
  }
}

750
static void
751
getline_RGB15 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
752 753 754 755 756 757 758 759 760 761 762 763
{
  int i;
  const guint16 *srcline = (const guint16 *) FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = ((srcline[i] >> 10) & 0x1f) << 3;
    dest[i * 4 + 2] = ((srcline[i] >> 5) & 0x1f) << 3;
    dest[i * 4 + 3] = ((srcline[i]) & 0x1f) << 3;
  }
}

static void
764
putline_RGB15 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
765 766 767 768 769 770 771 772 773 774 775
{
  int i;
  guint16 *destline = (guint16 *) FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i] =
        ((src[i * 4 + 1] >> 3) << 10) | ((src[i * 4 +
                2] >> 3) << 5) | (src[i * 4 + 3] >> 3);
  }
}

static void
776
getline_BGR15 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
777 778 779 780 781 782 783 784 785 786 787 788
{
  int i;
  const guint16 *srcline = (const guint16 *) FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 3] = ((srcline[i] >> 10) & 0x1f) << 3;
    dest[i * 4 + 2] = ((srcline[i] >> 5) & 0x1f) << 3;
    dest[i * 4 + 1] = ((srcline[i]) & 0x1f) << 3;
  }
}

static void
789
putline_BGR15 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
790 791 792 793 794 795 796 797 798 799
{
  int i;
  guint16 *destline = (guint16 *) FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i] =
        ((src[i * 4 + 3] >> 3) << 10) | ((src[i * 4 +
                2] >> 3) << 5) | (src[i * 4 + 1] >> 3);
  }
}

800
static void
801
getline_BGRA (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
802 803 804 805 806
{
  cogorc_getline_BGRA (dest, FRAME_GET_LINE (src, 0, j), convert->width);
}

static void
807
putline_BGRA (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
808 809 810 811 812
{
  cogorc_putline_BGRA (FRAME_GET_LINE (dest, 0, j), src, convert->width);
}

static void
813
getline_ABGR (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
814 815 816 817 818
{
  cogorc_getline_ABGR (dest, FRAME_GET_LINE (src, 0, j), convert->width);
}

static void
819
putline_ABGR (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
820 821 822 823 824
{
  cogorc_putline_ABGR (FRAME_GET_LINE (dest, 0, j), src, convert->width);
}

static void
825
getline_RGBA (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
826 827 828 829 830
{
  cogorc_getline_RGBA (dest, FRAME_GET_LINE (src, 0, j), convert->width);
}

static void
831
putline_RGBA (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
832 833 834 835 836
{
  cogorc_putline_RGBA (FRAME_GET_LINE (dest, 0, j), src, convert->width);
}

static void
837
getline_RGB (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
838 839
{
  int i;
840
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
841 842 843 844 845 846 847 848 849
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = srcline[i * 3 + 0];
    dest[i * 4 + 2] = srcline[i * 3 + 1];
    dest[i * 4 + 3] = srcline[i * 3 + 2];
  }
}

static void
850
putline_RGB (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
851 852 853 854 855 856 857 858 859 860 861
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i * 3 + 0] = src[i * 4 + 1];
    destline[i * 3 + 1] = src[i * 4 + 2];
    destline[i * 3 + 2] = src[i * 4 + 3];
  }
}

static void
862
getline_BGR (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
863 864
{
  int i;
865
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
866 867 868 869 870 871 872 873 874
  for (i = 0; i < convert->width; i++) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = srcline[i * 3 + 2];
    dest[i * 4 + 2] = srcline[i * 3 + 1];
    dest[i * 4 + 3] = srcline[i * 3 + 0];
  }
}

static void
875
putline_BGR (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
876 877 878 879 880 881 882 883 884 885 886
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width; i++) {
    destline[i * 3 + 0] = src[i * 4 + 3];
    destline[i * 3 + 1] = src[i * 4 + 2];
    destline[i * 3 + 2] = src[i * 4 + 1];
  }
}

static void
887
getline_NV12 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
888 889 890 891 892 893 894
{
  cogorc_getline_NV12 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j >> 1), convert->width / 2);
}

static void
895
putline_NV12 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
896 897 898 899 900 901
{
  cogorc_putline_NV12 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j >> 1), src, convert->width / 2);
}

static void
902
getline_NV21 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
903 904 905 906 907 908 909
{
  cogorc_getline_NV21 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 2, j >> 1), convert->width / 2);
}

static void
910
putline_NV21 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
911 912 913 914 915 916
{
  cogorc_putline_NV21 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 2, j >> 1), src, convert->width / 2);
}

static void
917
getline_UYVP (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
{
  int i;

  for (i = 0; i < convert->width; i += 2) {
    guint16 y0, y1;
    guint16 u0;
    guint16 v0;

    u0 = (src[(i / 2) * 5 + 0] << 2) | (src[(i / 2) * 5 + 1] >> 6);
    y0 = ((src[(i / 2) * 5 + 1] & 0x3f) << 4) | (src[(i / 2) * 5 + 2] >> 4);
    v0 = ((src[(i / 2) * 5 + 2] & 0x0f) << 6) | (src[(i / 2) * 5 + 3] >> 2);
    y1 = ((src[(i / 2) * 5 + 3] & 0x03) << 8) | src[(i / 2) * 5 + 4];

    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = y0 >> 2;
    dest[i * 4 + 2] = u0 >> 2;
    dest[i * 4 + 3] = v0 >> 2;
    dest[i * 4 + 4] = 0xff;
    dest[i * 4 + 5] = y1 >> 2;
    dest[i * 4 + 6] = u0 >> 2;
    dest[i * 4 + 7] = v0 >> 2;
  }
}

static void
943
putline_UYVP (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
{
  int i;

  for (i = 0; i < convert->width; i += 2) {
    guint16 y0, y1;
    guint16 u0;
    guint16 v0;

    y0 = src[4 * (i + 0) + 1];
    y1 = src[4 * (i + 1) + 1];
    u0 = (src[4 * (i + 0) + 2] + src[4 * (i + 1) + 2] + 1) >> 1;
    v0 = (src[4 * (i + 0) + 3] + src[4 * (i + 1) + 3] + 1) >> 1;

    dest[(i / 2) * 5 + 0] = u0;
    dest[(i / 2) * 5 + 1] = y0 >> 2;
    dest[(i / 2) * 5 + 2] = (y0 << 6) | (v0 >> 4);
    dest[(i / 2) * 5 + 3] = (v0 << 4) | (y1 >> 2);
    dest[(i / 2) * 5 + 4] = (y1 << 2);
  }
}

965
static void
966
getline_A420 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
967 968 969 970 971 972 973 974 975
{
  cogorc_getline_A420 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j >> 1),
      FRAME_GET_LINE (src, 2, j >> 1),
      FRAME_GET_LINE (src, 3, j), convert->width);
}

static void
976
putline_A420 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
977 978 979 980 981 982 983
{
  cogorc_putline_A420 (FRAME_GET_LINE (dest, 0, j),
      FRAME_GET_LINE (dest, 1, j >> 1),
      FRAME_GET_LINE (dest, 2, j >> 1),
      FRAME_GET_LINE (dest, 3, j), src, convert->width / 2);
}

984
static void
985
getline_RGB8P (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
986 987 988 989 990 991 992 993 994 995 996 997 998
{
  int i;
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    guint32 v = convert->palette[srcline[i]];
    dest[i * 4 + 0] = (v >> 24) & 0xff;
    dest[i * 4 + 1] = (v >> 16) & 0xff;
    dest[i * 4 + 2] = (v >> 8) & 0xff;
    dest[i * 4 + 3] = (v) & 0xff;
  }
}

static void
999
putline_RGB8P (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  /* Use our poor man's palette, taken from ffmpegcolorspace too */
  for (i = 0; i < convert->width; i++) {
    /* crude approximation for alpha ! */
    if (src[i * 4 + 0] < 0x80)
      destline[i] = 6 * 6 * 6;
    else
      destline[i] =
          ((((src[i * 4 + 1]) / 47) % 6) * 6 * 6 + (((src[i * 4 +
                          2]) / 47) % 6) * 6 + (((src[i * 4 + 3]) / 47) % 6));
  }
}
1014 1015 1016


static void
1017
getline_YUV9 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1018 1019 1020 1021
{
  cogorc_getline_YUV9 (dest,
      FRAME_GET_LINE (src, 0, j),
      FRAME_GET_LINE (src, 1, j >> 2),
1022
      FRAME_GET_LINE (src, 2, j >> 2), convert->width / 2);
1023 1024 1025
}

static void
1026
putline_YUV9 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
{
  int i;
  guint8 *destY = FRAME_GET_LINE (dest, 0, j);
  guint8 *destU = FRAME_GET_LINE (dest, 1, j >> 2);
  guint8 *destV = FRAME_GET_LINE (dest, 2, j >> 2);

  for (i = 0; i < convert->width - 3; i += 4) {
    destY[i] = src[i * 4 + 1];
    destY[i + 1] = src[i * 4 + 5];
    destY[i + 2] = src[i * 4 + 9];
    destY[i + 3] = src[i * 4 + 13];
    if (j % 4 == 0) {
      destU[i >> 2] =
          (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10] + src[i * 4 +
              14]) >> 2;
      destV[i >> 2] =
          (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11] + src[i * 4 +
              15]) >> 2;
    }
  }

  if (i == convert->width - 3) {
    destY[i] = src[i * 4 + 1];
    destY[i + 1] = src[i * 4 + 5];
    destY[i + 2] = src[i * 4 + 9];
    if (j % 4 == 0) {
      destU[i >> 2] = (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10]) / 3;
      destV[i >> 2] = (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11]) / 3;
    }
  } else if (i == convert->width - 2) {
    destY[i] = src[i * 4 + 1];
    destY[i + 1] = src[i * 4 + 5];
    if (j % 4 == 0) {
      destU[i >> 2] = (src[i * 4 + 2] + src[i * 4 + 6]) >> 1;
      destV[i >> 2] = (src[i * 4 + 3] + src[i * 4 + 7]) >> 1;
    }
  } else if (i == convert->width - 1) {
    destY[i] = src[i * 4 + 1];
    destU[i >> 2] = src[i * 4 + 2];
    destV[i >> 2] = src[i * 4 + 3];
  }
}
1069 1070

static void
1071
getline_IYU1 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
{
  int i;
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);

  for (i = 0; i < convert->width - 3; i += 4) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 4] = 0xff;
    dest[i * 4 + 8] = 0xff;
    dest[i * 4 + 12] = 0xff;
    dest[i * 4 + 1] = srcline[(i >> 2) * 6 + 1];
    dest[i * 4 + 5] = srcline[(i >> 2) * 6 + 2];
    dest[i * 4 + 9] = srcline[(i >> 2) * 6 + 4];
    dest[i * 4 + 13] = srcline[(i >> 2) * 6 + 5];
    dest[i * 4 + 2] = dest[i * 4 + 6] = dest[i * 4 + 10] = dest[i * 4 + 14] =
        srcline[(i >> 2) * 6 + 0];
    dest[i * 4 + 3] = dest[i * 4 + 7] = dest[i * 4 + 11] = dest[i * 4 + 15] =
        srcline[(i >> 2) * 6 + 3];
  }

  if (i == convert->width - 3) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 4] = 0xff;
    dest[i * 4 + 8] = 0xff;
    dest[i * 4 + 1] = srcline[(i >> 2) * 6 + 1];
    dest[i * 4 + 5] = srcline[(i >> 2) * 6 + 2];
    dest[i * 4 + 9] = srcline[(i >> 2) * 6 + 4];
    dest[i * 4 + 2] = dest[i * 4 + 6] = dest[i * 4 + 10] =
        srcline[(i >> 2) * 6 + 0];
    dest[i * 4 + 3] = dest[i * 4 + 7] = dest[i * 4 + 11] =
        srcline[(i >> 2) * 6 + 3];
  } else if (i == convert->width - 2) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 4] = 0xff;
    dest[i * 4 + 1] = srcline[(i >> 2) * 6 + 1];
    dest[i * 4 + 5] = srcline[(i >> 2) * 6 + 2];
    dest[i * 4 + 2] = dest[i * 4 + 6] = srcline[(i >> 2) * 6 + 0];
    dest[i * 4 + 3] = dest[i * 4 + 7] = srcline[(i >> 2) * 6 + 3];
  } else if (i == convert->width - 1) {
    dest[i * 4 + 0] = 0xff;
    dest[i * 4 + 1] = srcline[(i >> 2) * 6 + 1];
    dest[i * 4 + 2] = srcline[(i >> 2) * 6 + 0];
    dest[i * 4 + 3] = srcline[(i >> 2) * 6 + 3];
  }
}

static void
1118
putline_IYU1 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);

  for (i = 0; i < convert->width - 3; i += 4) {
    destline[(i >> 2) * 6 + 1] = src[i * 4 + 1];
    destline[(i >> 2) * 6 + 2] = src[i * 4 + 5];
    destline[(i >> 2) * 6 + 4] = src[i * 4 + 9];
    destline[(i >> 2) * 6 + 5] = src[i * 4 + 13];
    destline[(i >> 2) * 6 + 0] =
        (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10] + src[i * 4 +
            14]) >> 2;
    destline[(i >> 2) * 6 + 3] =
        (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11] + src[i * 4 +
            15]) >> 2;
  }

  if (i == convert->width - 3) {
    destline[(i >> 2) * 6 + 1] = src[i * 4 + 1];
    destline[(i >> 2) * 6 + 2] = src[i * 4 + 5];
    destline[(i >> 2) * 6 + 4] = src[i * 4 + 9];
    destline[(i >> 2) * 6 + 0] =
        (src[i * 4 + 2] + src[i * 4 + 6] + src[i * 4 + 10]) / 3;
    destline[(i >> 2) * 6 + 3] =
        (src[i * 4 + 3] + src[i * 4 + 7] + src[i * 4 + 11]) / 3;
  } else if (i == convert->width - 2) {
    destline[(i >> 2) * 6 + 1] = src[i * 4 + 1];
    destline[(i >> 2) * 6 + 2] = src[i * 4 + 5];
    destline[(i >> 2) * 6 + 0] = (src[i * 4 + 2] + src[i * 4 + 6]) >> 1;
    destline[(i >> 2) * 6 + 3] = (src[i * 4 + 3] + src[i * 4 + 7]) >> 1;
  } else if (i == convert->width - 1) {
    destline[(i >> 2) * 6 + 1] = src[i * 4 + 1];
    destline[(i >> 2) * 6 + 0] = src[i * 4 + 2];
    destline[(i >> 2) * 6 + 3] = src[i * 4 + 3];
  }
}
1155 1156

static void
1157
getline_AY64 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1158 1159 1160 1161 1162 1163 1164 1165 1166
{
  int i;
  const guint16 *srcline = (const guint16 *) FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width * 4; i++) {
    dest[i] = srcline[i] >> 8;
  }
}

static void
1167
putline_AY64 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1168 1169 1170 1171 1172 1173 1174 1175 1176
{
  int i;
  guint16 *destline = (guint16 *) FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width * 4; i++) {
    destline[i] = src[i] << 8;
  }
}

static void
1177
getline16_AY64 (VideoConvert * convert, guint16 * dest, const guint8 * src,
1178 1179 1180 1181 1182 1183
    int j)
{
  memcpy (dest, FRAME_GET_LINE (src, 0, j), convert->width * 8);
}

static void
1184
putline16_AY64 (VideoConvert * convert, guint8 * dest, const guint16 * src,
1185 1186 1187 1188 1189
    int j)
{
  memcpy (FRAME_GET_LINE (dest, 0, j), src, convert->width * 8);
}

1190
static void
1191
getline_r210 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
{
  int i;
  const guint8 *srcline = FRAME_GET_LINE (src, 0, j);
  for (i = 0; i < convert->width; i++) {
    guint8 x;
    dest[i * 4 + 0] = 0xff;
    x = GST_READ_UINT32_BE (srcline + i * 4);
    dest[i * 4 + 1] = (x >> 22) & 0xff;
    dest[i * 4 + 2] = (x >> 12) & 0xff;
    dest[i * 4 + 3] = (x >> 2) & 0xff;
  }
}

static void
1206
putline_r210 (VideoConvert * convert, guint8 * dest, const guint8 * src, int j)
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
{
  int i;
  guint8 *destline = FRAME_GET_LINE (dest, 0, j);
  for (i = 0; i < convert->width / 2; i++) {
    guint32 x = 0;
    x |= src[i * 4 + 1] << 22;
    x |= (src[i * 4 + 1] & 0xc0) << 14;
    x |= src[i * 4 + 2] << 12;
    x |= (src[i * 4 + 2] & 0xc0) << 10;
    x |= src[i * 4 + 3] << 2;
    x |= (src[i * 4 + 3] & 0xc0) >> 6;
    GST_WRITE_UINT32_BE (destline + i * 4, x);
  }
}

static void
1223
getline16_r210 (VideoConvert * convert, guint16 * dest, const guint8 * src,