# HG changeset patch # User reimar # Date 1270141907 0 # Node ID e03e3df6fb7d3e58bdc028b777b076811676a162 # Parent 731050abce416b036a10683579de4be08b6e4eee Change/simplify the tableprint/tablegen API. diff -r 731050abce41 -r e03e3df6fb7d cbrt_tablegen.c --- a/cbrt_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/cbrt_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -25,18 +25,15 @@ #include "cbrt_tablegen.h" #include "tableprint.h" -void tableinit(void) +int main(void) { cbrt_tableinit(); -} + + write_fileheader(); -const struct tabledef tables[] = { - { - "static const uint32_t cbrt_tab[1<<13]", - write_uint32_array, - cbrt_tab, - 1 << 13, - 0 - }, - { NULL } -}; + printf("static const uint32_t cbrt_tab[1<<13] = {\n"); + write_uint32_array(cbrt_tab, 1 << 13); + printf("};\n"); + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d dv_tablegen.c --- a/dv_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/dv_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -33,18 +33,15 @@ "{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size) WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair) -void tableinit(void) +int main(void) { dv_vlc_map_tableinit(); -} + + write_fileheader(); -const struct tabledef tables[] = { - { - "static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]", - write_vlc_pair_2d_array, - dv_vlc_map, - DV_VLC_MAP_RUN_SIZE, - DV_VLC_MAP_LEV_SIZE - }, - { NULL } -}; + printf("static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE] = {\n"); + write_vlc_pair_2d_array(dv_vlc_map, DV_VLC_MAP_RUN_SIZE, DV_VLC_MAP_LEV_SIZE); + printf("};\n"); + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d mdct_tablegen.c --- a/mdct_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/mdct_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -32,29 +32,18 @@ #include "mdct_tablegen.h" #include "tableprint.h" -void tableinit(void) +int main(void) { int i; - for (i = 5; i <= 12; i++) - ff_init_ff_sine_windows(i); -} -#define SINE_TABLE_DEF(size) \ - { \ - "SINETABLE("#size")", \ - write_float_array, \ - ff_sine_##size, \ - size \ - }, + write_fileheader(); -const struct tabledef tables[] = { - SINE_TABLE_DEF( 32) - SINE_TABLE_DEF( 64) - SINE_TABLE_DEF( 128) - SINE_TABLE_DEF( 256) - SINE_TABLE_DEF( 512) - SINE_TABLE_DEF(1024) - SINE_TABLE_DEF(2048) - SINE_TABLE_DEF(4096) - { NULL } -}; + for (i = 5; i <= 12; i++) { + ff_init_ff_sine_windows(i); + printf("SINETABLE(%4i) = {\n", 1 << i); + write_float_array(ff_sine_windows[i], 1 << i); + printf("};\n"); + } + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d motionpixels_tablegen.c --- a/motionpixels_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/motionpixels_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -27,18 +27,15 @@ #include "motionpixels_tablegen.h" #include "tableprint.h" -void tableinit(void) +int main(void) { motionpixels_tableinit(); -} + + write_fileheader(); -const struct tabledef tables[] = { - { - "static const YuvPixel mp_rgb_yuv_table[1 << 15]", - write_int8_2d_array, - mp_rgb_yuv_table, - 1 << 15, - 3 - }, - { NULL } -}; + printf("static const YuvPixel mp_rgb_yuv_table[1 << 15] = {\n"); + write_int8_2d_array(mp_rgb_yuv_table, 1 << 15, 3); + printf("};\n"); + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d mpegaudio_tablegen.c --- a/mpegaudio_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/mpegaudio_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -25,36 +25,27 @@ #include "mpegaudio_tablegen.h" #include "tableprint.h" -void tableinit(void) +int main(void) { mpegaudio_tableinit(); -} + + write_fileheader(); + + printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n"); + write_int8_array(table_4_3_exp, TABLE_4_3_SIZE); + printf("};\n"); + + printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n"); + write_uint32_array(table_4_3_value, TABLE_4_3_SIZE); + printf("};\n"); -const struct tabledef tables[] = { - { - "static const int8_t table_4_3_exp[TABLE_4_3_SIZE]", - write_int8_array, - table_4_3_exp, - TABLE_4_3_SIZE - }, - { - "static const uint32_t table_4_3_value[TABLE_4_3_SIZE]", - write_uint32_array, - table_4_3_value, - TABLE_4_3_SIZE - }, - { - "static const uint32_t exp_table[512]", - write_uint32_array, - exp_table, - 512 - }, - { - "static const uint32_t expval_table[512][16]", - write_uint32_2d_array, - expval_table, - 512, - 16 - }, - { NULL } -}; + printf("static const uint32_t exp_table[512] = {\n"); + write_uint32_array(exp_table, 512); + printf("};\n"); + + printf("static const uint32_t expval_table[512][16] = {\n"); + write_uint32_2d_array(expval_table, 512, 16); + printf("};\n"); + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d qdm2_tablegen.c --- a/qdm2_tablegen.c Thu Apr 01 16:52:14 2010 +0000 +++ b/qdm2_tablegen.c Thu Apr 01 17:11:47 2010 +0000 @@ -25,48 +25,33 @@ #include "qdm2_tablegen.h" #include "tableprint.h" -void tableinit(void) +int main(void) { softclip_table_init(); rnd_table_init(); init_noise_samples(); -} + + write_fileheader(); + + printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n"); + write_uint16_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1); + printf("};\n"); + + printf("static const float noise_table[4096] = {\n"); + write_float_array(noise_table, 4096); + printf("};\n"); -const struct tabledef tables[] = { - { - "static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]", - write_uint16_array, - softclip_table, - HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1, - 0 - }, - { - "static const float noise_table[4096]", - write_float_array, - noise_table, - 4096, - 0 - }, - { - "static const uint8_t random_dequant_index[256][5]", - write_uint8_2d_array, - random_dequant_index, - 256, - 5 - }, - { - "static const uint8_t random_dequant_type24[128][3]", - write_uint8_2d_array, - random_dequant_type24, - 128, - 3 - }, - { - "static const float noise_samples[128]", - write_float_array, - noise_samples, - 128, - 0 - }, - { NULL } -}; + printf("static const uint8_t random_dequant_index[256][5] = {\n"); + write_uint8_2d_array(random_dequant_index, 256, 5); + printf("};\n"); + + printf("static const uint8_t random_dequant_type24[128][3] = {\n"); + write_uint8_2d_array(random_dequant_type24, 128, 3); + printf("};\n"); + + printf("static const float noise_samples[128] = {\n"); + write_float_array(noise_samples, 128); + printf("};\n"); + + return 0; +} diff -r 731050abce41 -r e03e3df6fb7d tableprint.c --- a/tableprint.c Thu Apr 01 16:52:14 2010 +0000 +++ b/tableprint.c Thu Apr 01 17:11:47 2010 +0000 @@ -34,18 +34,7 @@ WRITE_2D_FUNC(uint8, uint8_t) WRITE_2D_FUNC(uint32, uint32_t) -int main(int argc, char *argv[]) -{ - int i; - +void write_fileheader(void) { printf("/* This file was generated by libavcodec/tableprint */\n"); printf("#include \n"); - tableinit(); - - for (i = 0; tables[i].declaration; i++) { - printf("%s = {\n", tables[i].declaration); - tables[i].printfunc(tables[i].data, tables[i].size, tables[i].size2); - printf("};\n"); - } - return 0; } diff -r 731050abce41 -r e03e3df6fb7d tableprint.h --- a/tableprint.h Thu Apr 01 16:52:14 2010 +0000 +++ b/tableprint.h Thu Apr 01 17:11:47 2010 +0000 @@ -27,9 +27,8 @@ #include #define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\ -void write_##name##_array(const void *arg, int len, int dummy)\ +void write_##name##_array(const type *data, int len)\ {\ - const type *data = arg;\ int i;\ printf(" ");\ for (i = 0; i < len - 1; i++) {\ @@ -49,7 +48,7 @@ int i;\ printf(" {\n");\ for (i = 0; i < len; i++) {\ - write_##name##_array(data + i * len2, len2, 0);\ + write_##name##_array(data + i * len2, len2);\ printf(i == len - 1 ? " }\n" : " }, {\n");\ }\ } @@ -59,34 +58,17 @@ * * \{ */ -void write_int8_array (const void *, int, int); -void write_uint8_array (const void *, int, int); -void write_uint16_array (const void *, int, int); -void write_uint32_array (const void *, int, int); -void write_float_array (const void *, int, int); +void write_int8_array (const int8_t *, int); +void write_uint8_array (const uint8_t *, int); +void write_uint16_array (const uint16_t *, int); +void write_uint32_array (const uint32_t *, int); +void write_float_array (const float *, int); void write_int8_2d_array (const void *, int, int); void write_uint8_2d_array (const void *, int, int); void write_uint32_2d_array(const void *, int, int); /** \} */ // end of printfuncs group -struct tabledef { - /** String that declares the array. Adding " = { ..." after it should - * make a valid initializer, adding "extern" before and ";" if possible - * should make a valid extern declaration. */ - const char *declaration; - /** Function used to print the table data (i.e. the part in {}). - * Should be one of the predefined write_*_array functions. */ - void (*printfunc)(const void *, int, int); - /** Pointer passed to the printfunc, usually a pointer to the start - * of the array to be printed. */ - const void *data; - int size; ///< size of the first dimension of the array - int size2; ///< size of the second dimension of the array if any -}; - -/** Initializes all the tables described in the tables array */ -void tableinit(void); -/** Describes the tables that should be printed */ -extern const struct tabledef tables[]; +/** Write a standard file header */ +void write_fileheader(void); #endif /* AVCODEC_TABLEPRINT_H */