Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 1 | /* |
Krishna Rapaka | 7319db5 | 2021-09-28 20:35:29 -0700 | [diff] [blame] | 2 | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 3 | * |
Vibhoothi | 41c6dd7 | 2021-10-12 18:48:26 +0000 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 3-Clause Clear License |
| 5 | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
| 6 | * License was not distributed with this source code in the LICENSE file, you |
| 7 | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
| 8 | * Alliance for Open Media Patent License 1.0 was not distributed with this |
| 9 | * source code in the PATENTS file, you can obtain it at |
| 10 | * aomedia.org/license/patent-license/. |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 11 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 12 | * Based on code from the OggTheora software codec source code, |
| 13 | * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors. |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 14 | */ |
James Zern | 0f51278 | 2013-12-15 18:40:23 -0800 | [diff] [blame] | 15 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 16 | #ifndef AOM_COMMON_Y4MINPUT_H_ |
| 17 | #define AOM_COMMON_Y4MINPUT_H_ |
James Zern | 0f51278 | 2013-12-15 18:40:23 -0800 | [diff] [blame] | 18 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 19 | #include <stdio.h> |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom/aom_image.h" |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 21 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 26 | typedef struct y4m_input y4m_input; |
| 27 | |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 28 | /*The function used to perform chroma conversion.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 29 | typedef void (*y4m_convert_func)(y4m_input *_y4m, unsigned char *_dst, |
| 30 | unsigned char *_src); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 31 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 32 | struct y4m_input { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 33 | int pic_w; |
| 34 | int pic_h; |
| 35 | int fps_n; |
| 36 | int fps_d; |
| 37 | int par_n; |
| 38 | int par_d; |
| 39 | char interlace; |
| 40 | int src_c_dec_h; |
| 41 | int src_c_dec_v; |
| 42 | int dst_c_dec_h; |
| 43 | int dst_c_dec_v; |
| 44 | char chroma_type[16]; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 45 | /*The size of each converted frame buffer.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 46 | size_t dst_buf_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 47 | /*The amount to read directly into the converted frame buffer.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 48 | size_t dst_buf_read_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 49 | /*The size of the auxilliary buffer.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 50 | size_t aux_buf_sz; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 51 | /*The amount to read into the auxilliary buffer.*/ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 52 | size_t aux_buf_read_sz; |
| 53 | y4m_convert_func convert; |
| 54 | unsigned char *dst_buf; |
| 55 | unsigned char *aux_buf; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 56 | enum aom_img_fmt aom_fmt; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 57 | int bps; |
| 58 | unsigned int bit_depth; |
Elliott Karpilovsky | 8d57041 | 2021-02-02 22:49:56 -0800 | [diff] [blame] | 59 | aom_color_range_t color_range; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 62 | /** |
Elliott Karpilovsky | 7296116 | 2021-01-19 18:17:26 -0800 | [diff] [blame] | 63 | * Open the input file, treating it as Y4M. |y4m_ctx| is filled in after |
Elliott Karpilovsky | 48fe4c3 | 2021-01-12 18:49:54 -0800 | [diff] [blame] | 64 | * reading it. Note that |csp| should only be set for 420 input, and the input |
| 65 | * chroma is shifted if necessary. The code does not support the conversion |
| 66 | * from co-located to vertical. The |skip_buffer| indicates bytes that were |
| 67 | * previously read from |file|, to do input-type detection; this buffer will |
| 68 | * be read before the |file| is read. It is of size |num_skip|, which *must* |
| 69 | * be 8 or less. |
| 70 | * |
| 71 | * Returns 0 on success, -1 on failure. |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 72 | */ |
Elliott Karpilovsky | 48fe4c3 | 2021-01-12 18:49:54 -0800 | [diff] [blame] | 73 | int y4m_input_open(y4m_input *y4m_ctx, FILE *file, char *skip_buffer, |
| 74 | int num_skip, aom_chroma_sample_position_t csp, |
| 75 | int only_420); |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 76 | void y4m_input_close(y4m_input *_y4m); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 77 | 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] | 78 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 79 | #ifdef __cplusplus |
| 80 | } // extern "C" |
| 81 | #endif |
| 82 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 83 | #endif // AOM_COMMON_Y4MINPUT_H_ |