xref: /aosp_15_r20/external/libaom/common/y4minput.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  *
11*77c1e3ccSAndroid Build Coastguard Worker  * Based on code from the OggTheora software codec source code,
12*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
13*77c1e3ccSAndroid Build Coastguard Worker  */
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_COMMON_Y4MINPUT_H_
16*77c1e3ccSAndroid Build Coastguard Worker #define AOM_COMMON_Y4MINPUT_H_
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_image.h"
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
22*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
23*77c1e3ccSAndroid Build Coastguard Worker #endif
24*77c1e3ccSAndroid Build Coastguard Worker 
25*77c1e3ccSAndroid Build Coastguard Worker typedef struct y4m_input y4m_input;
26*77c1e3ccSAndroid Build Coastguard Worker 
27*77c1e3ccSAndroid Build Coastguard Worker /*The function used to perform chroma conversion.*/
28*77c1e3ccSAndroid Build Coastguard Worker typedef void (*y4m_convert_func)(y4m_input *_y4m, unsigned char *_dst,
29*77c1e3ccSAndroid Build Coastguard Worker                                  unsigned char *_src);
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker struct y4m_input {
32*77c1e3ccSAndroid Build Coastguard Worker   int pic_w;
33*77c1e3ccSAndroid Build Coastguard Worker   int pic_h;
34*77c1e3ccSAndroid Build Coastguard Worker   int fps_n;
35*77c1e3ccSAndroid Build Coastguard Worker   int fps_d;
36*77c1e3ccSAndroid Build Coastguard Worker   int par_n;
37*77c1e3ccSAndroid Build Coastguard Worker   int par_d;
38*77c1e3ccSAndroid Build Coastguard Worker   char interlace;
39*77c1e3ccSAndroid Build Coastguard Worker   int src_c_dec_h;
40*77c1e3ccSAndroid Build Coastguard Worker   int src_c_dec_v;
41*77c1e3ccSAndroid Build Coastguard Worker   int dst_c_dec_h;
42*77c1e3ccSAndroid Build Coastguard Worker   int dst_c_dec_v;
43*77c1e3ccSAndroid Build Coastguard Worker   char chroma_type[16];
44*77c1e3ccSAndroid Build Coastguard Worker   /*The size of each converted frame buffer.*/
45*77c1e3ccSAndroid Build Coastguard Worker   size_t dst_buf_sz;
46*77c1e3ccSAndroid Build Coastguard Worker   /*The amount to read directly into the converted frame buffer.*/
47*77c1e3ccSAndroid Build Coastguard Worker   size_t dst_buf_read_sz;
48*77c1e3ccSAndroid Build Coastguard Worker   /*The size of the auxilliary buffer.*/
49*77c1e3ccSAndroid Build Coastguard Worker   size_t aux_buf_sz;
50*77c1e3ccSAndroid Build Coastguard Worker   /*The amount to read into the auxilliary buffer.*/
51*77c1e3ccSAndroid Build Coastguard Worker   size_t aux_buf_read_sz;
52*77c1e3ccSAndroid Build Coastguard Worker   y4m_convert_func convert;
53*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *dst_buf;
54*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *aux_buf;
55*77c1e3ccSAndroid Build Coastguard Worker   enum aom_img_fmt aom_fmt;
56*77c1e3ccSAndroid Build Coastguard Worker   int bps;
57*77c1e3ccSAndroid Build Coastguard Worker   unsigned int bit_depth;
58*77c1e3ccSAndroid Build Coastguard Worker   aom_color_range_t color_range;
59*77c1e3ccSAndroid Build Coastguard Worker };
60*77c1e3ccSAndroid Build Coastguard Worker 
61*77c1e3ccSAndroid Build Coastguard Worker /**
62*77c1e3ccSAndroid Build Coastguard Worker  * Open the input file, treating it as Y4M. |y4m_ctx| is filled in after
63*77c1e3ccSAndroid Build Coastguard Worker  * reading it. Note that |csp| should only be set for 420 input, and the input
64*77c1e3ccSAndroid Build Coastguard Worker  * chroma is shifted if necessary. The code does not support the conversion
65*77c1e3ccSAndroid Build Coastguard Worker  * from co-located to vertical. The |skip_buffer| indicates bytes that were
66*77c1e3ccSAndroid Build Coastguard Worker  * previously read from |file|, to do input-type detection; this buffer will
67*77c1e3ccSAndroid Build Coastguard Worker  * be read before the |file| is read. It is of size |num_skip|, which *must*
68*77c1e3ccSAndroid Build Coastguard Worker  * be 8 or less.
69*77c1e3ccSAndroid Build Coastguard Worker  *
70*77c1e3ccSAndroid Build Coastguard Worker  * Returns 0 on success, -1 on failure.
71*77c1e3ccSAndroid Build Coastguard Worker  */
72*77c1e3ccSAndroid Build Coastguard Worker int y4m_input_open(y4m_input *y4m_ctx, FILE *file, char *skip_buffer,
73*77c1e3ccSAndroid Build Coastguard Worker                    int num_skip, aom_chroma_sample_position_t csp,
74*77c1e3ccSAndroid Build Coastguard Worker                    int only_420);
75*77c1e3ccSAndroid Build Coastguard Worker void y4m_input_close(y4m_input *_y4m);
76*77c1e3ccSAndroid Build Coastguard Worker int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, aom_image_t *img);
77*77c1e3ccSAndroid Build Coastguard Worker 
78*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
79*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
80*77c1e3ccSAndroid Build Coastguard Worker #endif
81*77c1e3ccSAndroid Build Coastguard Worker 
82*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_COMMON_Y4MINPUT_H_
83