y4menc.c 2.61 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 11
 */

12
#include <assert.h>
Tom Finegan's avatar
Tom Finegan committed
13 14

#include "common/y4menc.h"
15

16
int y4m_write_file_header(char *buf, size_t len, int width, int height,
17 18
                          const struct AvxRational *framerate,
                          aom_img_fmt_t fmt, unsigned int bit_depth) {
19 20 21
  const char *color;
  switch (bit_depth) {
    case 8:
22
      color = fmt == AOM_IMG_FMT_444A
23
                  ? "C444alpha\n"
clang-format's avatar
clang-format committed
24 25 26
                  : fmt == AOM_IMG_FMT_I444
                        ? "C444\n"
                        : fmt == AOM_IMG_FMT_I422 ? "C422\n" : "C420jpeg\n";
27 28
      break;
    case 9:
29
      color = fmt == AOM_IMG_FMT_I44416
30
                  ? "C444p9 XYSCSS=444P9\n"
31
                  : fmt == AOM_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9\n"
32
                                              : "C420p9 XYSCSS=420P9\n";
33 34
      break;
    case 10:
35
      color = fmt == AOM_IMG_FMT_I44416
36
                  ? "C444p10 XYSCSS=444P10\n"
37
                  : fmt == AOM_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10\n"
38
                                              : "C420p10 XYSCSS=420P10\n";
39 40
      break;
    case 12:
41
      color = fmt == AOM_IMG_FMT_I44416
42
                  ? "C444p12 XYSCSS=444P12\n"
43
                  : fmt == AOM_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12\n"
44
                                              : "C420p12 XYSCSS=420P12\n";
45 46
      break;
    case 14:
47
      color = fmt == AOM_IMG_FMT_I44416
48
                  ? "C444p14 XYSCSS=444P14\n"
49
                  : fmt == AOM_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14\n"
50
                                              : "C420p14 XYSCSS=420P14\n";
51 52
      break;
    case 16:
53
      color = fmt == AOM_IMG_FMT_I44416
54
                  ? "C444p16 XYSCSS=444P16\n"
55
                  : fmt == AOM_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16\n"
56
                                              : "C420p16 XYSCSS=420P16\n";
57
      break;
58
    default: color = NULL; assert(0);
59
  }
60 61
  return snprintf(buf, len, "YUV4MPEG2 W%u H%u F%u:%u I%c %s", width, height,
                  framerate->numerator, framerate->denominator, 'p', color);
62 63
}

64 65
int y4m_write_frame_header(char *buf, size_t len) {
  return snprintf(buf, len, "FRAME\n");
66
}