hadamard: Add 4x4 test.
[aom.git] / common / tools_common.h
blob79348c2ffa60b2ffcaf9e126e804d15a22766af5
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
11 #ifndef AOM_COMMON_TOOLS_COMMON_H_
12 #define AOM_COMMON_TOOLS_COMMON_H_
14 #include <stdio.h>
16 #include "config/aom_config.h"
18 #include "aom/aom_codec.h"
19 #include "aom/aom_image.h"
20 #include "aom/aom_integer.h"
21 #include "aom_ports/mem.h"
22 #include "aom_ports/msvc.h"
24 #if CONFIG_AV1_ENCODER
25 #include "common/y4minput.h"
26 #endif
28 #if defined(_MSC_VER)
29 /* MSVS uses _f{seek,tell}i64. */
30 #define fseeko _fseeki64
31 #define ftello _ftelli64
32 typedef int64_t FileOffset;
33 #elif defined(_WIN32)
34 #include <sys/types.h> /* NOLINT*/
35 /* MinGW uses f{seek,tell}o64 for large files. */
36 #define fseeko fseeko64
37 #define ftello ftello64
38 typedef off64_t FileOffset;
39 #elif CONFIG_OS_SUPPORT
40 #include <sys/types.h> /* NOLINT*/
41 typedef off_t FileOffset;
42 /* Use 32-bit file operations in WebM file format when building ARM
43 * executables (.axf) with RVCT. */
44 #else
45 #define fseeko fseek
46 #define ftello ftell
47 typedef long FileOffset; /* NOLINT */
48 #endif /* CONFIG_OS_SUPPORT */
50 #if CONFIG_OS_SUPPORT
51 #if defined(_MSC_VER)
52 #include <io.h> /* NOLINT */
53 #define isatty _isatty
54 #define fileno _fileno
55 #else
56 #include <unistd.h> /* NOLINT */
57 #endif /* _MSC_VER */
58 #endif /* CONFIG_OS_SUPPORT */
60 #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
62 #ifndef PATH_MAX
63 #define PATH_MAX 512
64 #endif
66 #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
67 #define IVF_FILE_HDR_SZ 32
69 #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
71 #define AV1_FOURCC 0x31305641
73 enum VideoFileType {
74 FILE_TYPE_OBU,
75 FILE_TYPE_RAW,
76 FILE_TYPE_IVF,
77 FILE_TYPE_Y4M,
78 FILE_TYPE_WEBM
81 // Used in lightfield example.
82 enum {
83 YUV1D, // 1D tile output for conformance test.
84 YUV, // Tile output in YUV format.
85 NV12, // Tile output in NV12 format.
86 } UENUM1BYTE(OUTPUT_FORMAT);
88 // The fourcc for large_scale_tile encoding is "LSTC".
89 #define LST_FOURCC 0x4354534c
91 struct FileTypeDetectionBuffer {
92 char buf[4];
93 size_t buf_read;
94 size_t position;
97 struct AvxRational {
98 int numerator;
99 int denominator;
102 struct AvxInputContext {
103 const char *filename;
104 FILE *file;
105 int64_t length;
106 struct FileTypeDetectionBuffer detect;
107 enum VideoFileType file_type;
108 uint32_t width;
109 uint32_t height;
110 struct AvxRational pixel_aspect_ratio;
111 aom_img_fmt_t fmt;
112 aom_bit_depth_t bit_depth;
113 int only_i420;
114 uint32_t fourcc;
115 struct AvxRational framerate;
116 #if CONFIG_AV1_ENCODER
117 y4m_input y4m;
118 #endif
119 aom_color_range_t color_range;
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
126 #if defined(__GNUC__)
127 #define AOM_NO_RETURN __attribute__((noreturn))
128 #elif defined(_MSC_VER)
129 #define AOM_NO_RETURN __declspec(noreturn)
130 #else
131 #define AOM_NO_RETURN
132 #endif
134 // Tells the compiler to perform `printf` format string checking if the
135 // compiler supports it; see the 'format' attribute in
136 // <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>.
137 #define AOM_TOOLS_FORMAT_PRINTF(string_index, first_to_check)
138 #if defined(__has_attribute)
139 #if __has_attribute(format)
140 #undef AOM_TOOLS_FORMAT_PRINTF
141 #define AOM_TOOLS_FORMAT_PRINTF(string_index, first_to_check) \
142 __attribute__((__format__(__printf__, string_index, first_to_check)))
143 #endif
144 #endif
146 /* Sets a stdio stream into binary mode */
147 FILE *set_binary_mode(FILE *stream);
149 AOM_NO_RETURN void die(const char *fmt, ...) AOM_TOOLS_FORMAT_PRINTF(1, 2);
150 AOM_NO_RETURN void fatal(const char *fmt, ...) AOM_TOOLS_FORMAT_PRINTF(1, 2);
151 void aom_tools_warn(const char *fmt, ...) AOM_TOOLS_FORMAT_PRINTF(1, 2);
153 AOM_NO_RETURN void die_codec(aom_codec_ctx_t *ctx, const char *s);
155 /* The tool including this file must define usage_exit() */
156 AOM_NO_RETURN void usage_exit(void);
158 #undef AOM_NO_RETURN
160 // The AOM library can support different encoders / decoders. These
161 // functions provide different ways to lookup / iterate through them.
162 // The return result may be NULL to indicate no codec was found.
163 int get_aom_encoder_count();
164 aom_codec_iface_t *get_aom_encoder_by_index(int i);
165 aom_codec_iface_t *get_aom_encoder_by_short_name(const char *name);
166 // If the interface is unknown, returns NULL.
167 const char *get_short_name_by_aom_encoder(aom_codec_iface_t *encoder);
168 // If the interface is unknown, returns 0.
169 uint32_t get_fourcc_by_aom_encoder(aom_codec_iface_t *iface);
171 int get_aom_decoder_count();
172 aom_codec_iface_t *get_aom_decoder_by_index(int i);
173 aom_codec_iface_t *get_aom_decoder_by_short_name(const char *name);
174 aom_codec_iface_t *get_aom_decoder_by_fourcc(uint32_t fourcc);
175 const char *get_short_name_by_aom_decoder(aom_codec_iface_t *decoder);
176 // If the interface is unknown, returns 0.
177 uint32_t get_fourcc_by_aom_decoder(aom_codec_iface_t *iface);
179 int read_yuv_frame(struct AvxInputContext *input_ctx, aom_image_t *yuv_frame);
181 void aom_img_write(const aom_image_t *img, FILE *file);
182 int aom_img_read(aom_image_t *img, FILE *file);
184 double sse_to_psnr(double samples, double peak, double mse);
185 void aom_img_upshift(aom_image_t *dst, const aom_image_t *src, int input_shift);
186 void aom_img_downshift(aom_image_t *dst, const aom_image_t *src,
187 int down_shift);
188 void aom_shift_img(unsigned int output_bit_depth, aom_image_t **img_ptr,
189 aom_image_t **img_shifted_ptr);
190 void aom_img_truncate_16_to_8(aom_image_t *dst, const aom_image_t *src);
192 // Output in NV12 format.
193 void aom_img_write_nv12(const aom_image_t *img, FILE *file);
195 #ifdef __cplusplus
196 } /* extern "C" */
197 #endif
199 #endif // AOM_COMMON_TOOLS_COMMON_H_