FFmpeg
tableprint.h
Go to the documentation of this file.
1 /*
2  * Generate a file for hardcoded tables
3  *
4  * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef AVCODEC_TABLEPRINT_H
24 #define AVCODEC_TABLEPRINT_H
25 
26 #include <inttypes.h>
27 #include <stdio.h>
28 
29 #include "libavutil/common.h"
30 #include "libavutil/mem_internal.h"
31 
32 #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\
33 void write_##type##_array(const type *data, int len)\
34 {\
35  int i;\
36  printf(" ");\
37  for (i = 0; i < len - 1; i++) {\
38  printf(" "fmtstr",", __VA_ARGS__);\
39  if ((i & linebrk) == linebrk) printf("\n ");\
40  }\
41  printf(" "fmtstr"\n", __VA_ARGS__);\
42 }
43 
44 #define WRITE_1D_FUNC(type, fmtstr, linebrk)\
45  WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, data[i])
46 
47 #define WRITE_2D_FUNC(type)\
48 void write_##type##_2d_array(const void *arg, int len, int len2)\
49 {\
50  const type *data = arg;\
51  int i;\
52  printf(" {\n");\
53  for (i = 0; i < len; i++) {\
54  write_##type##_array(data + i * len2, len2);\
55  printf(i == len - 1 ? " }\n" : " }, {\n");\
56  }\
57 }
58 
59 /**
60  * @name Predefined functions for printing tables
61  *
62  * @{
63  */
64 void write_int8_t_array (const int8_t *, int);
65 void write_uint8_t_array (const uint8_t *, int);
66 void write_uint16_t_array (const uint16_t *, int);
67 void write_uint32_t_array (const uint32_t *, int);
68 void write_int32_t_array (const int32_t *, int);
69 void write_float_array (const float *, int);
70 void write_int8_t_2d_array (const void *, int, int);
71 void write_uint8_t_2d_array (const void *, int, int);
72 void write_uint32_t_2d_array(const void *, int, int);
73 void write_float_2d_array (const void *, int, int);
74 /** @} */ // end of printfuncs group
75 
76 /*
77  * MSVC doesn't have %zu, since it was introduced in C99,
78  * but has its own %Iu for printing size_t values.
79  */
80 #if defined(_MSC_VER)
81 #define FMT "Iu"
82 #else
83 #define FMT "zu"
84 #endif
85 
86 #define WRITE_ARRAY_ALIGNED(prefix, align, type, name) \
87  do { \
88  const size_t array_size = FF_ARRAY_ELEMS(name); \
89  printf(prefix" DECLARE_ALIGNED("#align", " \
90  #type", "#name")[%"FMT"] = {\n", \
91  array_size); \
92  write_##type##_array(name, array_size); \
93  printf("};\n"); \
94  } while(0)
95 
96 #define WRITE_ARRAY(prefix, type, name) \
97  do { \
98  const size_t array_size = FF_ARRAY_ELEMS(name); \
99  printf(prefix" "#type" "#name"[%"FMT"] = {\n", \
100  array_size); \
101  write_##type##_array(name, array_size); \
102  printf("};\n"); \
103  } while(0)
104 
105 #define WRITE_2D_ARRAY(prefix, type, name) \
106  do { \
107  const size_t array_size1 = FF_ARRAY_ELEMS(name); \
108  const size_t array_size2 = FF_ARRAY_ELEMS(name[0]); \
109  printf(prefix" "#type" "#name"[%"FMT"][%"FMT"] = {\n", \
110  array_size1, array_size2 ); \
111  write_##type##_2d_array(name, array_size1, array_size2); \
112  printf("};\n"); \
113  } while(0)
114 
115 
116 WRITE_1D_FUNC(int8_t, "%3"PRIi8, 15)
117 WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15)
118 WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7)
119 WRITE_1D_FUNC(int16_t, "%5"PRIi16, 7)
120 WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7)
121 WRITE_1D_FUNC(int32_t, "0x%08"PRIx32, 7)
122 WRITE_1D_FUNC(float, "%.18e", 3)
123 
124 WRITE_2D_FUNC(int8_t)
125 WRITE_2D_FUNC(uint8_t)
126 WRITE_2D_FUNC(uint32_t)
127 WRITE_2D_FUNC(float)
128 
129 static inline void write_fileheader(void)
130 {
131  printf("/* This file was automatically generated. */\n");
132  printf("#include <stdint.h>\n");
133 }
134 
135 #endif /* AVCODEC_TABLEPRINT_H */
#define WRITE_2D_FUNC(type)
Definition: tableprint.h:47
void write_float_2d_array(const void *, int, int)
void write_uint32_t_array(const uint32_t *, int)
uint8_t
void write_int8_t_array(const int8_t *, int)
void write_uint32_t_2d_array(const void *, int, int)
void write_uint16_t_array(const uint16_t *, int)
void write_uint8_t_2d_array(const void *, int, int)
void write_float_array(const float *, int)
int32_t
void write_int8_t_2d_array(const void *, int, int)
void write_int32_t_array(const int32_t *, int)
common internal and external API header
void write_uint8_t_array(const uint8_t *, int)
printf("static const uint8_t my_array[100] = {\n")
#define WRITE_1D_FUNC(type, fmtstr, linebrk)
Definition: tableprint.h:44
static void write_fileheader(void)
Definition: tableprint.h:129