Libav 0.7.1
|
00001 /* 00002 * Generate a file for hardcoded tables 00003 * 00004 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef AVCODEC_TABLEPRINT_H 00024 #define AVCODEC_TABLEPRINT_H 00025 00026 #include <inttypes.h> 00027 #include <stdio.h> 00028 00029 #include "libavutil/common.h" 00030 00031 #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\ 00032 void write_##type##_array(const type *data, int len)\ 00033 {\ 00034 int i;\ 00035 printf(" ");\ 00036 for (i = 0; i < len - 1; i++) {\ 00037 printf(" "fmtstr",", __VA_ARGS__);\ 00038 if ((i & linebrk) == linebrk) printf("\n ");\ 00039 }\ 00040 printf(" "fmtstr"\n", __VA_ARGS__);\ 00041 } 00042 00043 #define WRITE_1D_FUNC(type, fmtstr, linebrk)\ 00044 WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, data[i]) 00045 00046 #define WRITE_2D_FUNC(type)\ 00047 void write_##type##_2d_array(const void *arg, int len, int len2)\ 00048 {\ 00049 const type *data = arg;\ 00050 int i;\ 00051 printf(" {\n");\ 00052 for (i = 0; i < len; i++) {\ 00053 write_##type##_array(data + i * len2, len2);\ 00054 printf(i == len - 1 ? " }\n" : " }, {\n");\ 00055 }\ 00056 } 00057 00062 void write_int8_t_array (const int8_t *, int); 00063 void write_uint8_t_array (const uint8_t *, int); 00064 void write_uint16_t_array (const uint16_t *, int); 00065 void write_uint32_t_array (const uint32_t *, int); 00066 void write_float_array (const float *, int); 00067 void write_int8_t_2d_array (const void *, int, int); 00068 void write_uint8_t_2d_array (const void *, int, int); 00069 void write_uint32_t_2d_array(const void *, int, int); 00070 void write_float_2d_array (const void *, int, int); // end of printfuncs group 00072 00073 #define WRITE_ARRAY(prefix, type, name) \ 00074 do { \ 00075 const size_t array_size = FF_ARRAY_ELEMS(name); \ 00076 printf(prefix" "#type" "#name"[%zu] = {\n", \ 00077 array_size); \ 00078 write_##type##_array(name, array_size); \ 00079 printf("};\n"); \ 00080 } while(0) 00081 00082 #define WRITE_2D_ARRAY(prefix, type, name) \ 00083 do { \ 00084 const size_t array_size1 = FF_ARRAY_ELEMS(name); \ 00085 const size_t array_size2 = FF_ARRAY_ELEMS(name[0]); \ 00086 printf(prefix" "#type" "#name"[%zu][%zu] = {\n", \ 00087 array_size1, array_size2 ); \ 00088 write_##type##_2d_array(name, array_size1, array_size2); \ 00089 printf("};\n"); \ 00090 } while(0) 00091 00092 00093 WRITE_1D_FUNC(int8_t, "%3"PRIi8, 15) 00094 WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15) 00095 WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7) 00096 WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7) 00097 WRITE_1D_FUNC(float, "%.18e", 3) 00098 00099 WRITE_2D_FUNC(int8_t) 00100 WRITE_2D_FUNC(uint8_t) 00101 WRITE_2D_FUNC(uint32_t) 00102 WRITE_2D_FUNC(float) 00103 00104 static inline void write_fileheader(void) 00105 { 00106 printf("/* This file was automatically generated. */\n"); 00107 printf("#include <stdint.h>\n"); 00108 } 00109 00110 #endif /* AVCODEC_TABLEPRINT_H */