Add sse2/avx2 version of aom_dc_predictor_wxh()
[aom.git] / tools_common.h
blob6fa9b6afaf363e81fe0510ca995880a47e418c9c
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 TOOLS_COMMON_H_
12 #define TOOLS_COMMON_H_
14 #include <stdio.h>
16 #include "./aom_config.h"
17 #include "aom/aom_codec.h"
18 #include "aom/aom_image.h"
19 #include "aom/aom_integer.h"
20 #include "aom_ports/msvc.h"
22 #if CONFIG_AV1_ENCODER
23 #include "./y4minput.h"
24 #endif
26 #if defined(_MSC_VER)
27 /* MSVS uses _f{seek,tell}i64. */
28 #define fseeko _fseeki64
29 #define ftello _ftelli64
30 typedef int64_t FileOffset;
31 #elif defined(_WIN32)
32 #include <sys/types.h> /* NOLINT*/
33 /* MinGW uses f{seek,tell}o64 for large files. */
34 #define fseeko fseeko64
35 #define ftello ftello64
36 typedef off64_t FileOffset;
37 #elif CONFIG_OS_SUPPORT
38 #include <sys/types.h> /* NOLINT*/
39 typedef off_t FileOffset;
40 /* Use 32-bit file operations in WebM file format when building ARM
41 * executables (.axf) with RVCT. */
42 #else
43 #define fseeko fseek
44 #define ftello ftell
45 typedef long FileOffset; /* NOLINT */
46 #endif /* CONFIG_OS_SUPPORT */
48 #if CONFIG_OS_SUPPORT
49 #if defined(_MSC_VER)
50 #include <io.h> /* NOLINT */
51 #define isatty _isatty
52 #define fileno _fileno
53 #else
54 #include <unistd.h> /* NOLINT */
55 #endif /* _MSC_VER */
56 #endif /* CONFIG_OS_SUPPORT */
58 #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
60 #ifndef PATH_MAX
61 #define PATH_MAX 512
62 #endif
64 #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
65 #define IVF_FILE_HDR_SZ 32
67 #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
69 #define AV1_FOURCC 0x31305641
71 enum VideoFileType {
72 #if CONFIG_OBU_NO_IVF
73 FILE_TYPE_OBU,
74 #endif
75 FILE_TYPE_RAW,
76 FILE_TYPE_IVF,
77 FILE_TYPE_Y4M,
78 FILE_TYPE_WEBM
81 struct FileTypeDetectionBuffer {
82 char buf[4];
83 size_t buf_read;
84 size_t position;
87 struct AvxRational {
88 int numerator;
89 int denominator;
92 struct AvxInputContext {
93 const char *filename;
94 FILE *file;
95 int64_t length;
96 struct FileTypeDetectionBuffer detect;
97 enum VideoFileType file_type;
98 uint32_t width;
99 uint32_t height;
100 struct AvxRational pixel_aspect_ratio;
101 aom_img_fmt_t fmt;
102 aom_bit_depth_t bit_depth;
103 int only_i420;
104 uint32_t fourcc;
105 struct AvxRational framerate;
106 #if CONFIG_AV1_ENCODER
107 y4m_input y4m;
108 #endif
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
115 #if defined(__GNUC__)
116 #define AOM_NO_RETURN __attribute__((noreturn))
117 #else
118 #define AOM_NO_RETURN
119 #endif
121 /* Sets a stdio stream into binary mode */
122 FILE *set_binary_mode(FILE *stream);
124 void die(const char *fmt, ...) AOM_NO_RETURN;
125 void fatal(const char *fmt, ...) AOM_NO_RETURN;
126 void warn(const char *fmt, ...);
128 void die_codec(aom_codec_ctx_t *ctx, const char *s) AOM_NO_RETURN;
130 /* The tool including this file must define usage_exit() */
131 void usage_exit(void) AOM_NO_RETURN;
133 #undef AOM_NO_RETURN
135 int read_yuv_frame(struct AvxInputContext *input_ctx, aom_image_t *yuv_frame);
137 typedef struct AvxInterface {
138 const char *const name;
139 const uint32_t fourcc;
140 aom_codec_iface_t *(*const codec_interface)();
141 } AvxInterface;
143 int get_aom_encoder_count(void);
144 const AvxInterface *get_aom_encoder_by_index(int i);
145 const AvxInterface *get_aom_encoder_by_name(const char *name);
147 int get_aom_decoder_count(void);
148 const AvxInterface *get_aom_decoder_by_index(int i);
149 const AvxInterface *get_aom_decoder_by_name(const char *name);
150 const AvxInterface *get_aom_decoder_by_fourcc(uint32_t fourcc);
152 void aom_img_write(const aom_image_t *img, FILE *file);
153 int aom_img_read(aom_image_t *img, FILE *file);
155 double sse_to_psnr(double samples, double peak, double mse);
156 void aom_img_upshift(aom_image_t *dst, aom_image_t *src, int input_shift);
157 void aom_img_downshift(aom_image_t *dst, aom_image_t *src, int down_shift);
158 void aom_img_truncate_16_to_8(aom_image_t *dst, aom_image_t *src);
160 #ifdef __cplusplus
161 } /* extern "C" */
162 #endif
164 #endif // TOOLS_COMMON_H_