Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 10 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 11 | * Based on code from the OggTheora software codec source code, |
| 12 | * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors. |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 13 | */ |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 14 | #include <errno.h> |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 17 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "aom/aom_integer.h" |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 19 | #include "y4minput.h" |
| 20 | |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 21 | // Reads 'size' bytes from 'file' into 'buf' with some fault tolerance. |
| 22 | // Returns true on success. |
| 23 | static int file_read(void *buf, size_t size, FILE *file) { |
| 24 | const int kMaxRetries = 5; |
| 25 | int retry_count = 0; |
James Zern | d586698 | 2014-03-15 12:35:44 -0700 | [diff] [blame] | 26 | int file_error; |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 27 | size_t len = 0; |
| 28 | do { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 29 | const size_t n = fread((uint8_t *)buf + len, 1, size - len, file); |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 30 | len += n; |
James Zern | d586698 | 2014-03-15 12:35:44 -0700 | [diff] [blame] | 31 | file_error = ferror(file); |
| 32 | if (file_error) { |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 33 | if (errno == EINTR || errno == EAGAIN) { |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 34 | clearerr(file); |
| 35 | continue; |
| 36 | } else { |
| 37 | fprintf(stderr, "Error reading file: %u of %u bytes read, %d: %s\n", |
| 38 | (uint32_t)len, (uint32_t)size, errno, strerror(errno)); |
| 39 | return 0; |
| 40 | } |
| 41 | } |
James Zern | d586698 | 2014-03-15 12:35:44 -0700 | [diff] [blame] | 42 | } while (!feof(file) && len < size && ++retry_count < kMaxRetries); |
| 43 | |
| 44 | if (!feof(file) && len != size) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 45 | fprintf(stderr, |
| 46 | "Error reading file: %u of %u bytes read," |
| 47 | " error: %d, retries: %d, %d: %s\n", |
| 48 | (uint32_t)len, (uint32_t)size, file_error, retry_count, errno, |
| 49 | strerror(errno)); |
James Zern | d586698 | 2014-03-15 12:35:44 -0700 | [diff] [blame] | 50 | } |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 51 | return len == size; |
| 52 | } |
| 53 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 54 | static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 55 | int got_w; |
| 56 | int got_h; |
| 57 | int got_fps; |
| 58 | int got_interlace; |
| 59 | int got_par; |
| 60 | int got_chroma; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 61 | char *p; |
| 62 | char *q; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 63 | got_w = got_h = got_fps = got_interlace = got_par = got_chroma = 0; |
| 64 | for (p = _tags;; p = q) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 65 | /*Skip any leading spaces.*/ |
James Zern | e0c265e | 2016-07-19 20:46:39 -0700 | [diff] [blame] | 66 | while (*p == ' ') p++; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 67 | /*If that's all we have, stop.*/ |
James Zern | e0c265e | 2016-07-19 20:46:39 -0700 | [diff] [blame] | 68 | if (p[0] == '\0') break; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 69 | /*Find the end of this tag.*/ |
James Zern | e0c265e | 2016-07-19 20:46:39 -0700 | [diff] [blame] | 70 | for (q = p + 1; *q != '\0' && *q != ' '; q++) { |
| 71 | } |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 72 | /*Process the tag.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 73 | switch (p[0]) { |
| 74 | case 'W': { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 75 | if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1) return -1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 76 | got_w = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 77 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 78 | case 'H': { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 79 | if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1) return -1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 80 | got_h = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 81 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 82 | case 'F': { |
| 83 | if (sscanf(p + 1, "%d:%d", &_y4m->fps_n, &_y4m->fps_d) != 2) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 84 | return -1; |
| 85 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 86 | got_fps = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 87 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 88 | case 'I': { |
| 89 | _y4m->interlace = p[1]; |
| 90 | got_interlace = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 91 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 92 | case 'A': { |
| 93 | if (sscanf(p + 1, "%d:%d", &_y4m->par_n, &_y4m->par_d) != 2) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 94 | return -1; |
| 95 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 96 | got_par = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 97 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 98 | case 'C': { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 99 | if (q - p > 16) return -1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 100 | memcpy(_y4m->chroma_type, p + 1, q - p - 1); |
| 101 | _y4m->chroma_type[q - p - 1] = '\0'; |
| 102 | got_chroma = 1; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 103 | } break; |
| 104 | /*Ignore unknown tags.*/ |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 105 | } |
| 106 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 107 | if (!got_w || !got_h || !got_fps) return -1; |
| 108 | if (!got_interlace) _y4m->interlace = '?'; |
| 109 | if (!got_par) _y4m->par_n = _y4m->par_d = 0; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 110 | /*Chroma-type is not specified in older files, e.g., those generated by |
| 111 | mplayer.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 112 | if (!got_chroma) strcpy(_y4m->chroma_type, "420"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 116 | /*All anti-aliasing filters in the following conversion functions are based on |
| 117 | one of two window functions: |
| 118 | The 6-tap Lanczos window (for down-sampling and shifts): |
| 119 | sinc(\pi*t)*sinc(\pi*t/3), |t|<3 (sinc(t)==sin(t)/t) |
| 120 | 0, |t|>=3 |
| 121 | The 4-tap Mitchell window (for up-sampling): |
| 122 | 7|t|^3-12|t|^2+16/3, |t|<1 |
| 123 | -(7/3)|x|^3+12|x|^2-20|x|+32/3, |t|<2 |
| 124 | 0, |t|>=2 |
| 125 | The number of taps is intentionally kept small to reduce computational |
| 126 | overhead and limit ringing. |
| 127 | |
| 128 | The taps from these filters are scaled so that their sum is 1, and the result |
| 129 | is scaled by 128 and rounded to integers to create a filter whose |
| 130 | intermediate values fit inside 16 bits. |
| 131 | Coefficients are rounded in such a way as to ensure their sum is still 128, |
| 132 | which is usually equivalent to normal rounding. |
| 133 | |
| 134 | Conversions which require both horizontal and vertical filtering could |
| 135 | have these steps pipelined, for less memory consumption and better cache |
| 136 | performance, but we do them separately for simplicity.*/ |
| 137 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 138 | #define OC_MINI(_a, _b) ((_a) > (_b) ? (_b) : (_a)) |
| 139 | #define OC_MAXI(_a, _b) ((_a) < (_b) ? (_b) : (_a)) |
| 140 | #define OC_CLAMPI(_a, _b, _c) (OC_MAXI(_a, OC_MINI(_b, _c))) |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 141 | |
| 142 | /*420jpeg chroma samples are sited like: |
| 143 | Y-------Y-------Y-------Y------- |
| 144 | | | | | |
| 145 | | BR | | BR | |
| 146 | | | | | |
| 147 | Y-------Y-------Y-------Y------- |
| 148 | | | | | |
| 149 | | | | | |
| 150 | | | | | |
| 151 | Y-------Y-------Y-------Y------- |
| 152 | | | | | |
| 153 | | BR | | BR | |
| 154 | | | | | |
| 155 | Y-------Y-------Y-------Y------- |
| 156 | | | | | |
| 157 | | | | | |
| 158 | | | | | |
| 159 | |
| 160 | 420mpeg2 chroma samples are sited like: |
| 161 | Y-------Y-------Y-------Y------- |
| 162 | | | | | |
| 163 | BR | BR | |
| 164 | | | | | |
| 165 | Y-------Y-------Y-------Y------- |
| 166 | | | | | |
| 167 | | | | | |
| 168 | | | | | |
| 169 | Y-------Y-------Y-------Y------- |
| 170 | | | | | |
| 171 | BR | BR | |
| 172 | | | | | |
| 173 | Y-------Y-------Y-------Y------- |
| 174 | | | | | |
| 175 | | | | | |
| 176 | | | | | |
| 177 | |
| 178 | We use a resampling filter to shift the site locations one quarter pixel (at |
| 179 | the chroma plane's resolution) to the right. |
| 180 | The 4:2:2 modes look exactly the same, except there are twice as many chroma |
| 181 | lines, and they are vertically co-sited with the luma samples in both the |
| 182 | mpeg2 and jpeg cases (thus requiring no vertical resampling).*/ |
| 183 | static void y4m_42xmpeg2_42xjpeg_helper(unsigned char *_dst, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 184 | const unsigned char *_src, int _c_w, |
| 185 | int _c_h) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 186 | int y; |
| 187 | int x; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 188 | for (y = 0; y < _c_h; y++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 189 | /*Filter: [4 -17 114 35 -9 1]/128, derived from a 6-tap Lanczos |
| 190 | window.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 191 | for (x = 0; x < OC_MINI(_c_w, 2); x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 192 | _dst[x] = (unsigned char)OC_CLAMPI( |
| 193 | 0, (4 * _src[0] - 17 * _src[OC_MAXI(x - 1, 0)] + 114 * _src[x] + |
| 194 | 35 * _src[OC_MINI(x + 1, _c_w - 1)] - |
| 195 | 9 * _src[OC_MINI(x + 2, _c_w - 1)] + |
| 196 | _src[OC_MINI(x + 3, _c_w - 1)] + 64) >> |
| 197 | 7, |
| 198 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 199 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 200 | for (; x < _c_w - 3; x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 201 | _dst[x] = (unsigned char)OC_CLAMPI( |
| 202 | 0, (4 * _src[x - 2] - 17 * _src[x - 1] + 114 * _src[x] + |
| 203 | 35 * _src[x + 1] - 9 * _src[x + 2] + _src[x + 3] + 64) >> |
| 204 | 7, |
| 205 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 206 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 207 | for (; x < _c_w; x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 208 | _dst[x] = (unsigned char)OC_CLAMPI( |
| 209 | 0, (4 * _src[x - 2] - 17 * _src[x - 1] + 114 * _src[x] + |
| 210 | 35 * _src[OC_MINI(x + 1, _c_w - 1)] - |
| 211 | 9 * _src[OC_MINI(x + 2, _c_w - 1)] + _src[_c_w - 1] + 64) >> |
| 212 | 7, |
| 213 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 214 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 215 | _dst += _c_w; |
| 216 | _src += _c_w; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
| 220 | /*Handles both 422 and 420mpeg2 to 422jpeg and 420jpeg, respectively.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 221 | static void y4m_convert_42xmpeg2_42xjpeg(y4m_input *_y4m, unsigned char *_dst, |
| 222 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 223 | int c_w; |
| 224 | int c_h; |
| 225 | int c_sz; |
| 226 | int pli; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 227 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 228 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 229 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 230 | c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
| 231 | c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 232 | c_sz = c_w * c_h; |
| 233 | for (pli = 1; pli < 3; pli++) { |
| 234 | y4m_42xmpeg2_42xjpeg_helper(_dst, _aux, c_w, c_h); |
| 235 | _dst += c_sz; |
| 236 | _aux += c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | /*This format is only used for interlaced content, but is included for |
| 241 | completeness. |
| 242 | |
| 243 | 420jpeg chroma samples are sited like: |
| 244 | Y-------Y-------Y-------Y------- |
| 245 | | | | | |
| 246 | | BR | | BR | |
| 247 | | | | | |
| 248 | Y-------Y-------Y-------Y------- |
| 249 | | | | | |
| 250 | | | | | |
| 251 | | | | | |
| 252 | Y-------Y-------Y-------Y------- |
| 253 | | | | | |
| 254 | | BR | | BR | |
| 255 | | | | | |
| 256 | Y-------Y-------Y-------Y------- |
| 257 | | | | | |
| 258 | | | | | |
| 259 | | | | | |
| 260 | |
| 261 | 420paldv chroma samples are sited like: |
| 262 | YR------Y-------YR------Y------- |
| 263 | | | | | |
| 264 | | | | | |
| 265 | | | | | |
| 266 | YB------Y-------YB------Y------- |
| 267 | | | | | |
| 268 | | | | | |
| 269 | | | | | |
| 270 | YR------Y-------YR------Y------- |
| 271 | | | | | |
| 272 | | | | | |
| 273 | | | | | |
| 274 | YB------Y-------YB------Y------- |
| 275 | | | | | |
| 276 | | | | | |
| 277 | | | | | |
| 278 | |
| 279 | We use a resampling filter to shift the site locations one quarter pixel (at |
| 280 | the chroma plane's resolution) to the right. |
| 281 | Then we use another filter to move the C_r location down one quarter pixel, |
| 282 | and the C_b location up one quarter pixel.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 283 | static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m, unsigned char *_dst, |
| 284 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 285 | unsigned char *tmp; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 286 | int c_w; |
| 287 | int c_h; |
| 288 | int c_sz; |
| 289 | int pli; |
| 290 | int y; |
| 291 | int x; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 292 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 293 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 294 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 295 | c_w = (_y4m->pic_w + 1) / 2; |
| 296 | c_h = (_y4m->pic_h + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
| 297 | c_sz = c_w * c_h; |
| 298 | tmp = _aux + 2 * c_sz; |
| 299 | for (pli = 1; pli < 3; pli++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 300 | /*First do the horizontal re-sampling. |
| 301 | This is the same as the mpeg2 case, except that after the horizontal |
| 302 | case, we need to apply a second vertical filter.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 303 | y4m_42xmpeg2_42xjpeg_helper(tmp, _aux, c_w, c_h); |
| 304 | _aux += c_sz; |
| 305 | switch (pli) { |
| 306 | case 1: { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 307 | /*Slide C_b up a quarter-pel. |
| 308 | This is the same filter used above, but in the other order.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 309 | for (x = 0; x < c_w; x++) { |
| 310 | for (y = 0; y < OC_MINI(c_h, 3); y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 311 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 312 | 0, (tmp[0] - 9 * tmp[OC_MAXI(y - 2, 0) * c_w] + |
| 313 | 35 * tmp[OC_MAXI(y - 1, 0) * c_w] + 114 * tmp[y * c_w] - |
| 314 | 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] + |
| 315 | 4 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + 64) >> |
| 316 | 7, |
| 317 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 318 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 319 | for (; y < c_h - 2; y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 320 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 321 | 0, (tmp[(y - 3) * c_w] - 9 * tmp[(y - 2) * c_w] + |
| 322 | 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - |
| 323 | 17 * tmp[(y + 1) * c_w] + 4 * tmp[(y + 2) * c_w] + 64) >> |
| 324 | 7, |
| 325 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 326 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 327 | for (; y < c_h; y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 328 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 329 | 0, (tmp[(y - 3) * c_w] - 9 * tmp[(y - 2) * c_w] + |
| 330 | 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - |
| 331 | 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] + |
| 332 | 4 * tmp[(c_h - 1) * c_w] + 64) >> |
| 333 | 7, |
| 334 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 335 | } |
| 336 | _dst++; |
| 337 | tmp++; |
| 338 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 339 | _dst += c_sz - c_w; |
| 340 | tmp -= c_w; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 341 | } break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 342 | case 2: { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 343 | /*Slide C_r down a quarter-pel. |
| 344 | This is the same as the horizontal filter.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 345 | for (x = 0; x < c_w; x++) { |
| 346 | for (y = 0; y < OC_MINI(c_h, 2); y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 347 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 348 | 0, |
| 349 | (4 * tmp[0] - 17 * tmp[OC_MAXI(y - 1, 0) * c_w] + |
| 350 | 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - |
| 351 | 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + |
| 352 | tmp[OC_MINI(y + 3, c_h - 1) * c_w] + 64) >> |
| 353 | 7, |
| 354 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 355 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 356 | for (; y < c_h - 3; y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 357 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 358 | 0, (4 * tmp[(y - 2) * c_w] - 17 * tmp[(y - 1) * c_w] + |
| 359 | 114 * tmp[y * c_w] + 35 * tmp[(y + 1) * c_w] - |
| 360 | 9 * tmp[(y + 2) * c_w] + tmp[(y + 3) * c_w] + 64) >> |
| 361 | 7, |
| 362 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 363 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 364 | for (; y < c_h; y++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 365 | _dst[y * c_w] = (unsigned char)OC_CLAMPI( |
| 366 | 0, |
| 367 | (4 * tmp[(y - 2) * c_w] - 17 * tmp[(y - 1) * c_w] + |
| 368 | 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - |
| 369 | 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + tmp[(c_h - 1) * c_w] + |
| 370 | 64) >> |
| 371 | 7, |
| 372 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 373 | } |
| 374 | _dst++; |
| 375 | tmp++; |
| 376 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 377 | } break; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 378 | } |
| 379 | /*For actual interlaced material, this would have to be done separately on |
| 380 | each field, and the shift amounts would be different. |
| 381 | C_r moves down 1/8, C_b up 3/8 in the top field, and C_r moves down 3/8, |
| 382 | C_b up 1/8 in the bottom field. |
| 383 | The corresponding filters would be: |
| 384 | Down 1/8 (reverse order for up): [3 -11 125 15 -4 0]/128 |
| 385 | Down 3/8 (reverse order for up): [4 -19 98 56 -13 2]/128*/ |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /*Perform vertical filtering to reduce a single plane from 4:2:2 to 4:2:0. |
| 390 | This is used as a helper by several converation routines.*/ |
| 391 | static void y4m_422jpeg_420jpeg_helper(unsigned char *_dst, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 392 | const unsigned char *_src, int _c_w, |
| 393 | int _c_h) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 394 | int y; |
| 395 | int x; |
| 396 | /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 397 | for (x = 0; x < _c_w; x++) { |
| 398 | for (y = 0; y < OC_MINI(_c_h, 2); y += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 399 | _dst[(y >> 1) * _c_w] = |
| 400 | OC_CLAMPI(0, (64 * _src[0] + 78 * _src[OC_MINI(1, _c_h - 1) * _c_w] - |
| 401 | 17 * _src[OC_MINI(2, _c_h - 1) * _c_w] + |
| 402 | 3 * _src[OC_MINI(3, _c_h - 1) * _c_w] + 64) >> |
| 403 | 7, |
| 404 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 405 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 406 | for (; y < _c_h - 3; y += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 407 | _dst[(y >> 1) * _c_w] = |
| 408 | OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] + _src[(y + 3) * _c_w]) - |
| 409 | 17 * (_src[(y - 1) * _c_w] + _src[(y + 2) * _c_w]) + |
| 410 | 78 * (_src[y * _c_w] + _src[(y + 1) * _c_w]) + 64) >> |
| 411 | 7, |
| 412 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 413 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 414 | for (; y < _c_h; y += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 415 | _dst[(y >> 1) * _c_w] = OC_CLAMPI( |
| 416 | 0, |
| 417 | (3 * (_src[(y - 2) * _c_w] + _src[(_c_h - 1) * _c_w]) - |
| 418 | 17 * (_src[(y - 1) * _c_w] + _src[OC_MINI(y + 2, _c_h - 1) * _c_w]) + |
| 419 | 78 * (_src[y * _c_w] + _src[OC_MINI(y + 1, _c_h - 1) * _c_w]) + |
| 420 | 64) >> |
| 421 | 7, |
| 422 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 423 | } |
| 424 | _src++; |
| 425 | _dst++; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /*420jpeg chroma samples are sited like: |
| 430 | Y-------Y-------Y-------Y------- |
| 431 | | | | | |
| 432 | | BR | | BR | |
| 433 | | | | | |
| 434 | Y-------Y-------Y-------Y------- |
| 435 | | | | | |
| 436 | | | | | |
| 437 | | | | | |
| 438 | Y-------Y-------Y-------Y------- |
| 439 | | | | | |
| 440 | | BR | | BR | |
| 441 | | | | | |
| 442 | Y-------Y-------Y-------Y------- |
| 443 | | | | | |
| 444 | | | | | |
| 445 | | | | | |
| 446 | |
| 447 | 422jpeg chroma samples are sited like: |
| 448 | Y---BR--Y-------Y---BR--Y------- |
| 449 | | | | | |
| 450 | | | | | |
| 451 | | | | | |
| 452 | Y---BR--Y-------Y---BR--Y------- |
| 453 | | | | | |
| 454 | | | | | |
| 455 | | | | | |
| 456 | Y---BR--Y-------Y---BR--Y------- |
| 457 | | | | | |
| 458 | | | | | |
| 459 | | | | | |
| 460 | Y---BR--Y-------Y---BR--Y------- |
| 461 | | | | | |
| 462 | | | | | |
| 463 | | | | | |
| 464 | |
| 465 | We use a resampling filter to decimate the chroma planes by two in the |
| 466 | vertical direction.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 467 | static void y4m_convert_422jpeg_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
| 468 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 469 | int c_w; |
| 470 | int c_h; |
| 471 | int c_sz; |
| 472 | int dst_c_w; |
| 473 | int dst_c_h; |
| 474 | int dst_c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 475 | int pli; |
| 476 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 477 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 478 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 479 | c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
| 480 | c_h = _y4m->pic_h; |
| 481 | dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
| 482 | dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 483 | c_sz = c_w * c_h; |
| 484 | dst_c_sz = dst_c_w * dst_c_h; |
| 485 | for (pli = 1; pli < 3; pli++) { |
| 486 | y4m_422jpeg_420jpeg_helper(_dst, _aux, c_w, c_h); |
| 487 | _aux += c_sz; |
| 488 | _dst += dst_c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
| 492 | /*420jpeg chroma samples are sited like: |
| 493 | Y-------Y-------Y-------Y------- |
| 494 | | | | | |
| 495 | | BR | | BR | |
| 496 | | | | | |
| 497 | Y-------Y-------Y-------Y------- |
| 498 | | | | | |
| 499 | | | | | |
| 500 | | | | | |
| 501 | Y-------Y-------Y-------Y------- |
| 502 | | | | | |
| 503 | | BR | | BR | |
| 504 | | | | | |
| 505 | Y-------Y-------Y-------Y------- |
| 506 | | | | | |
| 507 | | | | | |
| 508 | | | | | |
| 509 | |
| 510 | 422 chroma samples are sited like: |
| 511 | YBR-----Y-------YBR-----Y------- |
| 512 | | | | | |
| 513 | | | | | |
| 514 | | | | | |
| 515 | YBR-----Y-------YBR-----Y------- |
| 516 | | | | | |
| 517 | | | | | |
| 518 | | | | | |
| 519 | YBR-----Y-------YBR-----Y------- |
| 520 | | | | | |
| 521 | | | | | |
| 522 | | | | | |
| 523 | YBR-----Y-------YBR-----Y------- |
| 524 | | | | | |
| 525 | | | | | |
| 526 | | | | | |
| 527 | |
| 528 | We use a resampling filter to shift the original site locations one quarter |
| 529 | pixel (at the original chroma resolution) to the right. |
| 530 | Then we use a second resampling filter to decimate the chroma planes by two |
| 531 | in the vertical direction.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 532 | static void y4m_convert_422_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
| 533 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 534 | unsigned char *tmp; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 535 | int c_w; |
| 536 | int c_h; |
| 537 | int c_sz; |
| 538 | int dst_c_h; |
| 539 | int dst_c_sz; |
| 540 | int pli; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 541 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 542 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 543 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 544 | c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
| 545 | c_h = _y4m->pic_h; |
| 546 | dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 547 | c_sz = c_w * c_h; |
| 548 | dst_c_sz = c_w * dst_c_h; |
| 549 | tmp = _aux + 2 * c_sz; |
| 550 | for (pli = 1; pli < 3; pli++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 551 | /*In reality, the horizontal and vertical steps could be pipelined, for |
| 552 | less memory consumption and better cache performance, but we do them |
| 553 | separately for simplicity.*/ |
| 554 | /*First do horizontal filtering (convert to 422jpeg)*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 555 | y4m_42xmpeg2_42xjpeg_helper(tmp, _aux, c_w, c_h); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 556 | /*Now do the vertical filtering.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 557 | y4m_422jpeg_420jpeg_helper(_dst, tmp, c_w, c_h); |
| 558 | _aux += c_sz; |
| 559 | _dst += dst_c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | /*420jpeg chroma samples are sited like: |
| 564 | Y-------Y-------Y-------Y------- |
| 565 | | | | | |
| 566 | | BR | | BR | |
| 567 | | | | | |
| 568 | Y-------Y-------Y-------Y------- |
| 569 | | | | | |
| 570 | | | | | |
| 571 | | | | | |
| 572 | Y-------Y-------Y-------Y------- |
| 573 | | | | | |
| 574 | | BR | | BR | |
| 575 | | | | | |
| 576 | Y-------Y-------Y-------Y------- |
| 577 | | | | | |
| 578 | | | | | |
| 579 | | | | | |
| 580 | |
| 581 | 411 chroma samples are sited like: |
| 582 | YBR-----Y-------Y-------Y------- |
| 583 | | | | | |
| 584 | | | | | |
| 585 | | | | | |
| 586 | YBR-----Y-------Y-------Y------- |
| 587 | | | | | |
| 588 | | | | | |
| 589 | | | | | |
| 590 | YBR-----Y-------Y-------Y------- |
| 591 | | | | | |
| 592 | | | | | |
| 593 | | | | | |
| 594 | YBR-----Y-------Y-------Y------- |
| 595 | | | | | |
| 596 | | | | | |
| 597 | | | | | |
| 598 | |
| 599 | We use a filter to resample at site locations one eighth pixel (at the source |
| 600 | chroma plane's horizontal resolution) and five eighths of a pixel to the |
| 601 | right. |
| 602 | Then we use another filter to decimate the planes by 2 in the vertical |
| 603 | direction.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 604 | static void y4m_convert_411_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
| 605 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 606 | unsigned char *tmp; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 607 | int c_w; |
| 608 | int c_h; |
| 609 | int c_sz; |
| 610 | int dst_c_w; |
| 611 | int dst_c_h; |
| 612 | int dst_c_sz; |
| 613 | int tmp_sz; |
| 614 | int pli; |
| 615 | int y; |
| 616 | int x; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 617 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 618 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 619 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 620 | c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
| 621 | c_h = _y4m->pic_h; |
| 622 | dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
| 623 | dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 624 | c_sz = c_w * c_h; |
| 625 | dst_c_sz = dst_c_w * dst_c_h; |
| 626 | tmp_sz = dst_c_w * c_h; |
| 627 | tmp = _aux + 2 * c_sz; |
| 628 | for (pli = 1; pli < 3; pli++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 629 | /*In reality, the horizontal and vertical steps could be pipelined, for |
| 630 | less memory consumption and better cache performance, but we do them |
| 631 | separately for simplicity.*/ |
| 632 | /*First do horizontal filtering (convert to 422jpeg)*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 633 | for (y = 0; y < c_h; y++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 634 | /*Filters: [1 110 18 -1]/128 and [-3 50 86 -5]/128, both derived from a |
| 635 | 4-tap Mitchell window.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 636 | for (x = 0; x < OC_MINI(c_w, 1); x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 637 | tmp[x << 1] = (unsigned char)OC_CLAMPI( |
| 638 | 0, (111 * _aux[0] + 18 * _aux[OC_MINI(1, c_w - 1)] - |
| 639 | _aux[OC_MINI(2, c_w - 1)] + 64) >> |
| 640 | 7, |
| 641 | 255); |
| 642 | tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( |
| 643 | 0, (47 * _aux[0] + 86 * _aux[OC_MINI(1, c_w - 1)] - |
| 644 | 5 * _aux[OC_MINI(2, c_w - 1)] + 64) >> |
| 645 | 7, |
| 646 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 647 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 648 | for (; x < c_w - 2; x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 649 | tmp[x << 1] = |
| 650 | (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] + |
| 651 | 18 * _aux[x + 1] - _aux[x + 2] + 64) >> |
| 652 | 7, |
| 653 | 255); |
| 654 | tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( |
| 655 | 0, (-3 * _aux[x - 1] + 50 * _aux[x] + 86 * _aux[x + 1] - |
| 656 | 5 * _aux[x + 2] + 64) >> |
| 657 | 7, |
| 658 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 659 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 660 | for (; x < c_w; x++) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 661 | tmp[x << 1] = (unsigned char)OC_CLAMPI( |
| 662 | 0, (_aux[x - 1] + 110 * _aux[x] + |
| 663 | 18 * _aux[OC_MINI(x + 1, c_w - 1)] - _aux[c_w - 1] + 64) >> |
| 664 | 7, |
| 665 | 255); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 666 | if ((x << 1 | 1) < dst_c_w) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 667 | tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( |
| 668 | 0, |
| 669 | (-3 * _aux[x - 1] + 50 * _aux[x] + |
| 670 | 86 * _aux[OC_MINI(x + 1, c_w - 1)] - 5 * _aux[c_w - 1] + 64) >> |
| 671 | 7, |
| 672 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 673 | } |
| 674 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 675 | tmp += dst_c_w; |
| 676 | _aux += c_w; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 677 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 678 | tmp -= tmp_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 679 | /*Now do the vertical filtering.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 680 | y4m_422jpeg_420jpeg_helper(_dst, tmp, dst_c_w, c_h); |
| 681 | _dst += dst_c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
| 685 | /*Convert 444 to 420jpeg.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 686 | static void y4m_convert_444_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
| 687 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 688 | unsigned char *tmp; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 689 | int c_w; |
| 690 | int c_h; |
| 691 | int c_sz; |
| 692 | int dst_c_w; |
| 693 | int dst_c_h; |
| 694 | int dst_c_sz; |
| 695 | int tmp_sz; |
| 696 | int pli; |
| 697 | int y; |
| 698 | int x; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 699 | /*Skip past the luma data.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 700 | _dst += _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 701 | /*Compute the size of each chroma plane.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 702 | c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
| 703 | c_h = _y4m->pic_h; |
| 704 | dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
| 705 | dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 706 | c_sz = c_w * c_h; |
| 707 | dst_c_sz = dst_c_w * dst_c_h; |
| 708 | tmp_sz = dst_c_w * c_h; |
| 709 | tmp = _aux + 2 * c_sz; |
| 710 | for (pli = 1; pli < 3; pli++) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 711 | /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 712 | for (y = 0; y < c_h; y++) { |
| 713 | for (x = 0; x < OC_MINI(c_w, 2); x += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 714 | tmp[x >> 1] = |
| 715 | OC_CLAMPI(0, (64 * _aux[0] + 78 * _aux[OC_MINI(1, c_w - 1)] - |
| 716 | 17 * _aux[OC_MINI(2, c_w - 1)] + |
| 717 | 3 * _aux[OC_MINI(3, c_w - 1)] + 64) >> |
| 718 | 7, |
| 719 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 720 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 721 | for (; x < c_w - 3; x += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 722 | tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[x + 3]) - |
| 723 | 17 * (_aux[x - 1] + _aux[x + 2]) + |
| 724 | 78 * (_aux[x] + _aux[x + 1]) + 64) >> |
| 725 | 7, |
| 726 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 727 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 728 | for (; x < c_w; x += 2) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 729 | tmp[x >> 1] = OC_CLAMPI( |
| 730 | 0, (3 * (_aux[x - 2] + _aux[c_w - 1]) - |
| 731 | 17 * (_aux[x - 1] + _aux[OC_MINI(x + 2, c_w - 1)]) + |
| 732 | 78 * (_aux[x] + _aux[OC_MINI(x + 1, c_w - 1)]) + 64) >> |
| 733 | 7, |
| 734 | 255); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 735 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 736 | tmp += dst_c_w; |
| 737 | _aux += c_w; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 738 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 739 | tmp -= tmp_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 740 | /*Now do the vertical filtering.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 741 | y4m_422jpeg_420jpeg_helper(_dst, tmp, dst_c_w, c_h); |
| 742 | _dst += dst_c_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
| 746 | /*The image is padded with empty chroma components at 4:2:0.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 747 | static void y4m_convert_mono_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
| 748 | unsigned char *_aux) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 749 | int c_sz; |
Yaowu Xu | 618e7ef | 2014-07-11 16:27:21 -0700 | [diff] [blame] | 750 | (void)_aux; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 751 | _dst += _y4m->pic_w * _y4m->pic_h; |
| 752 | c_sz = ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h) * |
| 753 | ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v); |
| 754 | memset(_dst, 128, c_sz * 2); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /*No conversion function needed.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 758 | static void y4m_convert_null(y4m_input *_y4m, unsigned char *_dst, |
| 759 | unsigned char *_aux) { |
Yaowu Xu | 618e7ef | 2014-07-11 16:27:21 -0700 | [diff] [blame] | 760 | (void)_y4m; |
| 761 | (void)_dst; |
| 762 | (void)_aux; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 763 | } |
| 764 | |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 765 | int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, |
| 766 | int only_420) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 767 | char buffer[80] = { 0 }; |
| 768 | int ret; |
| 769 | int i; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 770 | /*Read until newline, or 80 cols, whichever happens first.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 771 | for (i = 0; i < 79; i++) { |
| 772 | if (_nskip > 0) { |
| 773 | buffer[i] = *_skip++; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 774 | _nskip--; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 775 | } else { |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 776 | if (!file_read(buffer + i, 1, _fin)) return -1; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 777 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 778 | if (buffer[i] == '\n') break; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 779 | } |
| 780 | /*We skipped too much header data.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 781 | if (_nskip > 0) return -1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 782 | if (i == 79) { |
| 783 | fprintf(stderr, "Error parsing header; not a YUV2MPEG2 file?\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 784 | return -1; |
| 785 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 786 | buffer[i] = '\0'; |
| 787 | if (memcmp(buffer, "YUV4MPEG", 8)) { |
| 788 | fprintf(stderr, "Incomplete magic for YUV4MPEG file.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 789 | return -1; |
| 790 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 791 | if (buffer[8] != '2') { |
| 792 | fprintf(stderr, "Incorrect YUV input file version; YUV4MPEG2 required.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 793 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 794 | ret = y4m_parse_tags(_y4m, buffer + 5); |
| 795 | if (ret < 0) { |
| 796 | fprintf(stderr, "Error parsing YUV4MPEG2 header.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 797 | return ret; |
| 798 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 799 | if (_y4m->interlace == '?') { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 800 | fprintf(stderr, |
| 801 | "Warning: Input video interlacing format unknown; " |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 802 | "assuming progressive scan.\n"); |
| 803 | } else if (_y4m->interlace != 'p') { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 804 | fprintf(stderr, |
| 805 | "Input video is interlaced; " |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 806 | "Only progressive scan handled.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 807 | return -1; |
| 808 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 809 | _y4m->aom_fmt = AOM_IMG_FMT_I420; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 810 | _y4m->bps = 12; |
| 811 | _y4m->bit_depth = 8; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 812 | if (strcmp(_y4m->chroma_type, "420") == 0 || |
| 813 | strcmp(_y4m->chroma_type, "420jpeg") == 0) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 814 | _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = |
| 815 | _y4m->dst_c_dec_v = 2; |
| 816 | _y4m->dst_buf_read_sz = |
| 817 | _y4m->pic_w * _y4m->pic_h + |
| 818 | 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 819 | /* Natively supported: no conversion required. */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 820 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 821 | _y4m->convert = y4m_convert_null; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 822 | } else if (strcmp(_y4m->chroma_type, "420p10") == 0) { |
| 823 | _y4m->src_c_dec_h = 2; |
| 824 | _y4m->dst_c_dec_h = 2; |
| 825 | _y4m->src_c_dec_v = 2; |
| 826 | _y4m->dst_c_dec_v = 2; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 827 | _y4m->dst_buf_read_sz = |
| 828 | 2 * (_y4m->pic_w * _y4m->pic_h + |
| 829 | 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2)); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 830 | /* Natively supported: no conversion required. */ |
| 831 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 832 | _y4m->convert = y4m_convert_null; |
| 833 | _y4m->bit_depth = 10; |
| 834 | _y4m->bps = 15; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 835 | _y4m->aom_fmt = AOM_IMG_FMT_I42016; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 836 | if (only_420) { |
| 837 | fprintf(stderr, "Unsupported conversion from 420p10 to 420jpeg\n"); |
| 838 | return -1; |
| 839 | } |
| 840 | } else if (strcmp(_y4m->chroma_type, "420p12") == 0) { |
| 841 | _y4m->src_c_dec_h = 2; |
| 842 | _y4m->dst_c_dec_h = 2; |
| 843 | _y4m->src_c_dec_v = 2; |
| 844 | _y4m->dst_c_dec_v = 2; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 845 | _y4m->dst_buf_read_sz = |
| 846 | 2 * (_y4m->pic_w * _y4m->pic_h + |
| 847 | 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2)); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 848 | /* Natively supported: no conversion required. */ |
| 849 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 850 | _y4m->convert = y4m_convert_null; |
| 851 | _y4m->bit_depth = 12; |
| 852 | _y4m->bps = 18; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 853 | _y4m->aom_fmt = AOM_IMG_FMT_I42016; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 854 | if (only_420) { |
| 855 | fprintf(stderr, "Unsupported conversion from 420p12 to 420jpeg\n"); |
| 856 | return -1; |
| 857 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 858 | } else if (strcmp(_y4m->chroma_type, "420mpeg2") == 0) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 859 | _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = |
| 860 | _y4m->dst_c_dec_v = 2; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 861 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 862 | /*Chroma filter required: read into the aux buf first.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 863 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 864 | 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 865 | _y4m->convert = y4m_convert_42xmpeg2_42xjpeg; |
| 866 | } else if (strcmp(_y4m->chroma_type, "420paldv") == 0) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 867 | _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = |
| 868 | _y4m->dst_c_dec_v = 2; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 869 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 870 | /*Chroma filter required: read into the aux buf first. |
| 871 | We need to make two filter passes, so we need some extra space in the |
| 872 | aux buffer.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 873 | _y4m->aux_buf_sz = 3 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 874 | _y4m->aux_buf_read_sz = |
| 875 | 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 876 | _y4m->convert = y4m_convert_42xpaldv_42xjpeg; |
| 877 | } else if (strcmp(_y4m->chroma_type, "422jpeg") == 0) { |
| 878 | _y4m->src_c_dec_h = _y4m->dst_c_dec_h = 2; |
| 879 | _y4m->src_c_dec_v = 1; |
| 880 | _y4m->dst_c_dec_v = 2; |
| 881 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 882 | /*Chroma filter required: read into the aux buf first.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 883 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = |
| 884 | 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 885 | _y4m->convert = y4m_convert_422jpeg_420jpeg; |
| 886 | } else if (strcmp(_y4m->chroma_type, "422") == 0) { |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 887 | _y4m->src_c_dec_h = 2; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 888 | _y4m->src_c_dec_v = 1; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 889 | if (only_420) { |
| 890 | _y4m->dst_c_dec_h = 2; |
| 891 | _y4m->dst_c_dec_v = 2; |
| 892 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
| 893 | /*Chroma filter required: read into the aux buf first. |
| 894 | We need to make two filter passes, so we need some extra space in the |
| 895 | aux buffer.*/ |
| 896 | _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 897 | _y4m->aux_buf_sz = |
| 898 | _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 899 | _y4m->convert = y4m_convert_422_420jpeg; |
| 900 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 901 | _y4m->aom_fmt = AOM_IMG_FMT_I422; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 902 | _y4m->bps = 16; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 903 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 904 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 905 | _y4m->dst_buf_read_sz = |
| 906 | _y4m->pic_w * _y4m->pic_h + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 907 | /*Natively supported: no conversion required.*/ |
| 908 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 909 | _y4m->convert = y4m_convert_null; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 910 | } |
| 911 | } else if (strcmp(_y4m->chroma_type, "422p10") == 0) { |
| 912 | _y4m->src_c_dec_h = 2; |
| 913 | _y4m->src_c_dec_v = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 914 | _y4m->aom_fmt = AOM_IMG_FMT_I42216; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 915 | _y4m->bps = 20; |
| 916 | _y4m->bit_depth = 10; |
| 917 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 918 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 919 | _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h + |
| 920 | 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h); |
| 921 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 922 | _y4m->convert = y4m_convert_null; |
| 923 | if (only_420) { |
| 924 | fprintf(stderr, "Unsupported conversion from 422p10 to 420jpeg\n"); |
| 925 | return -1; |
| 926 | } |
| 927 | } else if (strcmp(_y4m->chroma_type, "422p12") == 0) { |
| 928 | _y4m->src_c_dec_h = 2; |
| 929 | _y4m->src_c_dec_v = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 930 | _y4m->aom_fmt = AOM_IMG_FMT_I42216; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 931 | _y4m->bps = 24; |
| 932 | _y4m->bit_depth = 12; |
| 933 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 934 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 935 | _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h + |
| 936 | 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h); |
| 937 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 938 | _y4m->convert = y4m_convert_null; |
| 939 | if (only_420) { |
| 940 | fprintf(stderr, "Unsupported conversion from 422p12 to 420jpeg\n"); |
| 941 | return -1; |
| 942 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 943 | } else if (strcmp(_y4m->chroma_type, "411") == 0) { |
| 944 | _y4m->src_c_dec_h = 4; |
| 945 | _y4m->dst_c_dec_h = 2; |
| 946 | _y4m->src_c_dec_v = 1; |
| 947 | _y4m->dst_c_dec_v = 2; |
| 948 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 949 | /*Chroma filter required: read into the aux buf first. |
| 950 | We need to make two filter passes, so we need some extra space in the |
| 951 | aux buffer.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 952 | _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 3) / 4) * _y4m->pic_h; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 953 | _y4m->aux_buf_sz = |
| 954 | _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 955 | _y4m->convert = y4m_convert_411_420jpeg; |
| 956 | } else if (strcmp(_y4m->chroma_type, "444") == 0) { |
| 957 | _y4m->src_c_dec_h = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 958 | _y4m->src_c_dec_v = 1; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 959 | if (only_420) { |
| 960 | _y4m->dst_c_dec_h = 2; |
| 961 | _y4m->dst_c_dec_v = 2; |
| 962 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
| 963 | /*Chroma filter required: read into the aux buf first. |
| 964 | We need to make two filter passes, so we need some extra space in the |
| 965 | aux buffer.*/ |
| 966 | _y4m->aux_buf_read_sz = 2 * _y4m->pic_w * _y4m->pic_h; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 967 | _y4m->aux_buf_sz = |
| 968 | _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 969 | _y4m->convert = y4m_convert_444_420jpeg; |
| 970 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 971 | _y4m->aom_fmt = AOM_IMG_FMT_I444; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 972 | _y4m->bps = 24; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 973 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 974 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 975 | _y4m->dst_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h; |
| 976 | /*Natively supported: no conversion required.*/ |
| 977 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 978 | _y4m->convert = y4m_convert_null; |
| 979 | } |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 980 | } else if (strcmp(_y4m->chroma_type, "444p10") == 0) { |
| 981 | _y4m->src_c_dec_h = 1; |
| 982 | _y4m->src_c_dec_v = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 983 | _y4m->aom_fmt = AOM_IMG_FMT_I44416; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 984 | _y4m->bps = 30; |
| 985 | _y4m->bit_depth = 10; |
| 986 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 987 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 988 | _y4m->dst_buf_read_sz = 2 * 3 * _y4m->pic_w * _y4m->pic_h; |
| 989 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 990 | _y4m->convert = y4m_convert_null; |
| 991 | if (only_420) { |
| 992 | fprintf(stderr, "Unsupported conversion from 444p10 to 420jpeg\n"); |
| 993 | return -1; |
| 994 | } |
| 995 | } else if (strcmp(_y4m->chroma_type, "444p12") == 0) { |
| 996 | _y4m->src_c_dec_h = 1; |
| 997 | _y4m->src_c_dec_v = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 998 | _y4m->aom_fmt = AOM_IMG_FMT_I44416; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 999 | _y4m->bps = 36; |
| 1000 | _y4m->bit_depth = 12; |
| 1001 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 1002 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 1003 | _y4m->dst_buf_read_sz = 2 * 3 * _y4m->pic_w * _y4m->pic_h; |
| 1004 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 1005 | _y4m->convert = y4m_convert_null; |
| 1006 | if (only_420) { |
| 1007 | fprintf(stderr, "Unsupported conversion from 444p12 to 420jpeg\n"); |
| 1008 | return -1; |
| 1009 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1010 | } else if (strcmp(_y4m->chroma_type, "444alpha") == 0) { |
| 1011 | _y4m->src_c_dec_h = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1012 | _y4m->src_c_dec_v = 1; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1013 | if (only_420) { |
| 1014 | _y4m->dst_c_dec_h = 2; |
| 1015 | _y4m->dst_c_dec_v = 2; |
| 1016 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
| 1017 | /*Chroma filter required: read into the aux buf first. |
| 1018 | We need to make two filter passes, so we need some extra space in the |
| 1019 | aux buffer. |
| 1020 | The extra plane also gets read into the aux buf. |
| 1021 | It will be discarded.*/ |
| 1022 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h; |
| 1023 | _y4m->convert = y4m_convert_444_420jpeg; |
| 1024 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1025 | _y4m->aom_fmt = AOM_IMG_FMT_444A; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1026 | _y4m->bps = 32; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1027 | _y4m->dst_c_dec_h = _y4m->src_c_dec_h; |
| 1028 | _y4m->dst_c_dec_v = _y4m->src_c_dec_v; |
| 1029 | _y4m->dst_buf_read_sz = 4 * _y4m->pic_w * _y4m->pic_h; |
| 1030 | /*Natively supported: no conversion required.*/ |
| 1031 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 1032 | _y4m->convert = y4m_convert_null; |
| 1033 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1034 | } else if (strcmp(_y4m->chroma_type, "mono") == 0) { |
| 1035 | _y4m->src_c_dec_h = _y4m->src_c_dec_v = 0; |
| 1036 | _y4m->dst_c_dec_h = _y4m->dst_c_dec_v = 2; |
| 1037 | _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1038 | /*No extra space required, but we need to clear the chroma planes.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1039 | _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
| 1040 | _y4m->convert = y4m_convert_mono_420jpeg; |
| 1041 | } else { |
| 1042 | fprintf(stderr, "Unknown chroma sampling type: %s\n", _y4m->chroma_type); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1043 | return -1; |
| 1044 | } |
| 1045 | /*The size of the final frame buffers is always computed from the |
| 1046 | destination chroma decimation type.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1047 | _y4m->dst_buf_sz = |
| 1048 | _y4m->pic_w * _y4m->pic_h + |
| 1049 | 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h) * |
| 1050 | ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1051 | if (_y4m->bit_depth == 8) |
Yaowu Xu | a0af416 | 2014-10-08 08:38:15 -0700 | [diff] [blame] | 1052 | _y4m->dst_buf = (unsigned char *)malloc(_y4m->dst_buf_sz); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1053 | else |
Yaowu Xu | a0af416 | 2014-10-08 08:38:15 -0700 | [diff] [blame] | 1054 | _y4m->dst_buf = (unsigned char *)malloc(2 * _y4m->dst_buf_sz); |
Jim Bankoski | e35c54e | 2014-08-19 09:00:44 -0700 | [diff] [blame] | 1055 | |
| 1056 | if (_y4m->aux_buf_sz > 0) |
| 1057 | _y4m->aux_buf = (unsigned char *)malloc(_y4m->aux_buf_sz); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1058 | return 0; |
| 1059 | } |
| 1060 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1061 | void y4m_input_close(y4m_input *_y4m) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1062 | free(_y4m->dst_buf); |
| 1063 | free(_y4m->aux_buf); |
| 1064 | } |
| 1065 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1066 | int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, aom_image_t *_img) { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1067 | char frame[6]; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1068 | int pic_sz; |
| 1069 | int c_w; |
| 1070 | int c_h; |
| 1071 | int c_sz; |
| 1072 | int bytes_per_sample = _y4m->bit_depth > 8 ? 2 : 1; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1073 | /*Read and skip the frame header.*/ |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 1074 | if (!file_read(frame, 6, _fin)) return 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1075 | if (memcmp(frame, "FRAME", 5)) { |
| 1076 | fprintf(stderr, "Loss of framing in Y4M input data\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1077 | return -1; |
| 1078 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1079 | if (frame[5] != '\n') { |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1080 | char c; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1081 | int j; |
| 1082 | for (j = 0; j < 79 && file_read(&c, 1, _fin) && c != '\n'; j++) { |
| 1083 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1084 | if (j == 79) { |
| 1085 | fprintf(stderr, "Error parsing Y4M frame header\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1086 | return -1; |
| 1087 | } |
| 1088 | } |
| 1089 | /*Read the frame data that needs no conversion.*/ |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 1090 | if (!file_read(_y4m->dst_buf, _y4m->dst_buf_read_sz, _fin)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1091 | fprintf(stderr, "Error reading Y4M frame data.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1092 | return -1; |
| 1093 | } |
| 1094 | /*Read the frame data that does need conversion.*/ |
James Zern | df0829f | 2014-02-12 16:30:43 -0800 | [diff] [blame] | 1095 | if (!file_read(_y4m->aux_buf, _y4m->aux_buf_read_sz, _fin)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1096 | fprintf(stderr, "Error reading Y4M frame data.\n"); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1097 | return -1; |
| 1098 | } |
| 1099 | /*Now convert the just read frame.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1100 | (*_y4m->convert)(_y4m, _y4m->dst_buf, _y4m->aux_buf); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1101 | /*Fill in the frame buffer pointers. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1102 | We don't use aom_img_wrap() because it forces padding for odd picture |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1103 | sizes, which would require a separate fread call for every row.*/ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1104 | memset(_img, 0, sizeof(*_img)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1105 | /*Y4M has the planes in Y'CbCr order, which libaom calls Y, U, and V.*/ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1106 | _img->fmt = _y4m->aom_fmt; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1107 | _img->w = _img->d_w = _y4m->pic_w; |
| 1108 | _img->h = _img->d_h = _y4m->pic_h; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1109 | _img->x_chroma_shift = _y4m->dst_c_dec_h >> 1; |
| 1110 | _img->y_chroma_shift = _y4m->dst_c_dec_v >> 1; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1111 | _img->bps = _y4m->bps; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1112 | |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1113 | /*Set up the buffer pointers.*/ |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1114 | pic_sz = _y4m->pic_w * _y4m->pic_h * bytes_per_sample; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1115 | c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1116 | c_w *= bytes_per_sample; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1117 | c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
| 1118 | c_sz = c_w * c_h; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1119 | _img->stride[AOM_PLANE_Y] = _img->stride[AOM_PLANE_ALPHA] = |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1120 | _y4m->pic_w * bytes_per_sample; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1121 | _img->stride[AOM_PLANE_U] = _img->stride[AOM_PLANE_V] = c_w; |
| 1122 | _img->planes[AOM_PLANE_Y] = _y4m->dst_buf; |
| 1123 | _img->planes[AOM_PLANE_U] = _y4m->dst_buf + pic_sz; |
| 1124 | _img->planes[AOM_PLANE_V] = _y4m->dst_buf + pic_sz + c_sz; |
| 1125 | _img->planes[AOM_PLANE_ALPHA] = _y4m->dst_buf + pic_sz + 2 * c_sz; |
Timothy B. Terriberry | c4d7e5e | 2010-10-27 16:04:02 -0700 | [diff] [blame] | 1126 | return 1; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1127 | } |