[FFmpeg-devel] [PATCH 2/2] tablegen: implement and use tablegen_copy_array macros
Diego Elio 'Flameeyes' Pettenò
flameeyes
Sun Jun 27 02:40:53 CEST 2010
Two macros (tablegen_copy_array and tablegen_copy_2d_array) take the
modifiers (not all tables are static, and they might not be constant
either), the type, and the name of the array. It'll be copied with the same
parameters and with the correct size of the currently-defined object.
---
libavcodec/aac_tablegen.c | 4 +---
libavcodec/cbrt_tablegen.c | 4 +---
libavcodec/mpegaudio_tablegen.c | 29 ++++++-----------------------
libavcodec/pcm_tablegen.c | 9 ++-------
libavcodec/qdm2_tablegen.c | 23 +++++------------------
libavcodec/tableprint.h | 16 ++++++++++++++++
6 files changed, 31 insertions(+), 54 deletions(-)
diff --git a/libavcodec/aac_tablegen.c b/libavcodec/aac_tablegen.c
index de1c957..2c51496 100644
--- a/libavcodec/aac_tablegen.c
+++ b/libavcodec/aac_tablegen.c
@@ -31,9 +31,7 @@ int main(void)
write_fileheader();
- printf("const float ff_aac_pow2sf_tab[428] = {\n");
- write_float_array(ff_aac_pow2sf_tab, 428);
- printf("};\n");
+ tablegen_copy_array(const, float, ff_aac_pow2sf_tab);
return 0;
}
diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c
index 5cbceb2..6dbd792 100644
--- a/libavcodec/cbrt_tablegen.c
+++ b/libavcodec/cbrt_tablegen.c
@@ -31,9 +31,7 @@ int main(void)
write_fileheader();
- printf("static const uint32_t cbrt_tab[1<<13] = {\n");
- write_uint32_t_array(cbrt_tab, 1 << 13);
- printf("};\n");
+ tablegen_copy_array(static const, uint32_t, cbrt_tab);
return 0;
}
diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c
index 57e239c..24c1f93 100644
--- a/libavcodec/mpegaudio_tablegen.c
+++ b/libavcodec/mpegaudio_tablegen.c
@@ -31,29 +31,12 @@ int main(void)
write_fileheader();
- printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
- write_int8_t_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_t_array(table_4_3_value, TABLE_4_3_SIZE);
- printf("};\n");
-
- printf("static const uint32_t exp_table[512] = {\n");
- write_uint32_t_array(exp_table, 512);
- printf("};\n");
-
- printf("static const float exp_table_float[512] = {\n");
- write_float_array(exp_table_float, 512);
- printf("};\n");
-
- printf("static const uint32_t expval_table[512][16] = {\n");
- write_uint32_t_2d_array(expval_table, 512, 16);
- printf("};\n");
-
- printf("static const float expval_table_float[512][16] = {\n");
- write_float_2d_array(expval_table_float, 512, 16);
- printf("};\n");
+ tablegen_copy_array(static const, int8_t, table_4_3_exp);
+ tablegen_copy_array(static const, uint32_t, table_4_3_value);
+ tablegen_copy_array(static const, uint32_t, exp_table);
+ tablegen_copy_array(static const, float, exp_table_float);
+ tablegen_copy_2d_array(static const, uint32_t, expval_table);
+ tablegen_copy_2d_array(static const, float, expval_table_float);
return 0;
}
diff --git a/libavcodec/pcm_tablegen.c b/libavcodec/pcm_tablegen.c
index 13b33dd..b3b3778 100644
--- a/libavcodec/pcm_tablegen.c
+++ b/libavcodec/pcm_tablegen.c
@@ -32,13 +32,8 @@ int main(void)
write_fileheader();
- printf("static const uint8_t linear_to_alaw[1 << 14] = {\n");
- write_uint8_t_array(linear_to_alaw, 1 << 14);
- printf("};\n");
-
- printf("static const uint8_t linear_to_ulaw[1 << 14] = {\n");
- write_uint8_t_array(linear_to_ulaw, 1 << 14);
- printf("};\n");
+ tablegen_copy_array(static const, uint8_t, linear_to_alaw);
+ tablegen_copy_array(static const, uint8_t, linear_to_ulaw);
return 0;
}
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index d11599b..e863091 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -33,25 +33,12 @@ int main(void)
write_fileheader();
- printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
- write_uint16_t_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1);
- printf("};\n");
+ tablegen_copy_array(static const, uint16_t, softclip_table);
+ tablegen_copy_array(static const, float, noise_table);
+ tablegen_copy_array(static const, float, noise_samples);
- printf("static const float noise_table[4096] = {\n");
- write_float_array(noise_table, 4096);
- printf("};\n");
-
- printf("static const uint8_t random_dequant_index[256][5] = {\n");
- write_uint8_t_2d_array(random_dequant_index, 256, 5);
- printf("};\n");
-
- printf("static const uint8_t random_dequant_type24[128][3] = {\n");
- write_uint8_t_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");
+ tablegen_copy_2d_array(static const, uint8_t, random_dequant_index);
+ tablegen_copy_2d_array(static const, uint8_t, random_dequant_type24);
return 0;
}
diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h
index 849bccf..d80bcc7 100644
--- a/libavcodec/tableprint.h
+++ b/libavcodec/tableprint.h
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <stdio.h>
+#include "libavutil/common.h"
#define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\
void write_##type##_array(const type *data, int len)\
@@ -72,4 +73,19 @@ void write_float_2d_array (const void *, int, int);
/** Write a standard file header */
void write_fileheader(void);
+#define tablegen_copy_array(modifier, type, name) \
+ printf(#modifier" "#type" "#name"[%zu] = {\n", \
+ FF_ARRAY_ELEMS(name)); \
+ write_##type##_array(name, FF_ARRAY_ELEMS(name)); \
+ printf("};\n");
+
+#define tablegen_copy_2d_array(modifier, type, name) \
+ printf(#modifier" "#type" "#name"[%zu][%zu] = {\n", \
+ FF_ARRAY_ELEMS(name), \
+ FF_ARRAY_ELEMS(name[0]) ); \
+ write_##type##_2d_array(name, \
+ FF_ARRAY_ELEMS(name), \
+ FF_ARRAY_ELEMS(name[0]) ); \
+ printf("};\n");
+
#endif /* AVCODEC_TABLEPRINT_H */
--
1.7.1
More information about the ffmpeg-devel
mailing list