Index: trunk/src_plugins/export_png/draw_png.c =================================================================== --- trunk/src_plugins/export_png/draw_png.c (revision 36295) +++ trunk/src_plugins/export_png/draw_png.c (revision 36296) @@ -46,6 +46,10 @@ #include +#define RND_PNG_FMT_gif "GIF" +#define RND_PNG_FMT_jpg "JPEG" +#define RND_PNG_FMT_png "PNG" + #define FROM_DRAW_PNG_C #include "draw_png.h" @@ -137,6 +141,59 @@ rnd_message(RND_MSG_ERROR, "rnd_png_finish(): Invalid graphic file format. This is a bug. Please report it.\n"); } +#undef HAVE_SOME_FORMAT +const char *rnd_png_filetypes[] = { +#ifdef PCB_HAVE_GDIMAGEPNG + RND_PNG_FMT_png, +#define HAVE_SOME_FORMAT 1 +#endif + +#ifdef PCB_HAVE_GDIMAGEGIF + RND_PNG_FMT_gif, +#define HAVE_SOME_FORMAT 1 +#endif + +#ifdef PCB_HAVE_GDIMAGEJPEG + RND_PNG_FMT_jpg, +#define HAVE_SOME_FORMAT 1 +#endif + + NULL +}; + +int rnd_png_has_any_format(void) +{ +#ifdef HAVE_SOME_FORMAT + return 1; +#else + return 0; +#endif +} + +const char *rnd_png_get_file_suffix(int filetype_idx) +{ + const char *result = NULL; + const char *fmt; + + if ((filetype_idx >= 0) && (filetype_idx < (sizeof(rnd_png_filetypes)/sizeof(rnd_png_filetypes[0])))) + fmt = rnd_png_filetypes[filetype_idx]; + + if (fmt == NULL) { /* Do nothing */ } + else if (strcmp(fmt, RND_PNG_FMT_gif) == 0) + result = ".gif"; + else if (strcmp(fmt, RND_PNG_FMT_jpg) == 0) + result = ".jpg"; + else if (strcmp(fmt, RND_PNG_FMT_png) == 0) + result = ".png"; + + if (result == NULL) { + fprintf(stderr, "Error: Invalid graphic file format\n"); + result = ".???"; + } + return result; +} + + void rnd_png_uninit(rnd_png_t *pctx) { if (pctx->color_cache_inited) { Index: trunk/src_plugins/export_png/draw_png.h =================================================================== --- trunk/src_plugins/export_png/draw_png.h (revision 36295) +++ trunk/src_plugins/export_png/draw_png.h (revision 36296) @@ -71,10 +71,6 @@ double spare_d1, spare_d2, spare_d3, spare_d4; } rnd_png_t; -#define RND_PNG_FMT_gif "GIF" -#define RND_PNG_FMT_jpg "JPEG" -#define RND_PNG_FMT_png "PNG" - void rnd_png_init(rnd_png_t *pctx, rnd_hidlib_t *hidlib); void rnd_png_uninit(rnd_png_t *pctx); @@ -85,6 +81,11 @@ void rnd_png_start(rnd_png_t *pctx); void rnd_png_finish(rnd_png_t *pctx, FILE *f, const char *fmt); +/* Available file types (compile time configuration) */ +const char *rnd_png_get_file_suffix(int filetype_idx); +extern const char *rnd_png_filetypes[]; +int rnd_png_has_any_format(void); + /* HID API standard drawing calls */ rnd_hid_gc_t rnd_png_make_gc(rnd_hid_t *hid); void rnd_png_destroy_gc(rnd_hid_gc_t gc); Index: trunk/src_plugins/export_png/png.c =================================================================== --- trunk/src_plugins/export_png/png.c (revision 36295) +++ trunk/src_plugins/export_png/png.c (revision 36296) @@ -82,27 +82,6 @@ register this HID and will refrain from doing so at the end of this file. */ -#undef HAVE_SOME_FORMAT - -static const char *filetypes[] = { -#ifdef PCB_HAVE_GDIMAGEPNG - RND_PNG_FMT_png, -#define HAVE_SOME_FORMAT 1 -#endif - -#ifdef PCB_HAVE_GDIMAGEGIF - RND_PNG_FMT_gif, -#define HAVE_SOME_FORMAT 1 -#endif - -#ifdef PCB_HAVE_GDIMAGEJPEG - RND_PNG_FMT_jpg, -#define HAVE_SOME_FORMAT 1 -#endif - - NULL -}; - #include "png_photo1.c" static FILE *png_f; @@ -218,7 +197,7 @@ %end-doc */ {"format", "Export file format", - RND_HATT_ENUM, 0, 0, {0, 0, 0}, filetypes}, + RND_HATT_ENUM, 0, 0, {0, 0, 0}, rnd_png_filetypes}, #define HA_filetype 9 /* %start-doc options "93 PNG Options" @@ -318,31 +297,9 @@ static rnd_hid_attr_val_t png_values[NUM_OPTIONS]; -static const char *get_file_suffix(void) -{ - const char *result = NULL; - const char *fmt; - - fmt = filetypes[png_values[HA_filetype].lng]; - - if (fmt == NULL) { /* Do nothing */ } - else if (strcmp(fmt, RND_PNG_FMT_gif) == 0) - result = ".gif"; - else if (strcmp(fmt, RND_PNG_FMT_jpg) == 0) - result = ".jpg"; - else if (strcmp(fmt, RND_PNG_FMT_png) == 0) - result = ".png"; - - if (result == NULL) { - fprintf(stderr, "Error: Invalid graphic file format\n"); - result = ".???"; - } - return result; -} - static const rnd_export_opt_t *png_get_export_options(rnd_hid_t *hid, int *n) { - const char *suffix = get_file_suffix(); + const char *suffix = rnd_png_get_file_suffix(png_values[HA_filetype].lng); const char *val = png_values[HA_pngfile].str; if ((PCB != NULL) && ((val == NULL) || (*val == '\0'))) @@ -405,7 +362,7 @@ if (pctx->photo_mode) png_photo_foot(); - rnd_png_finish(pctx, f, filetypes[png_options[HA_filetype].lng]); + rnd_png_finish(pctx, f, rnd_png_filetypes[png_options[HA_filetype].lng]); } @@ -690,9 +647,9 @@ void pplg_uninit_export_png(void) { rnd_export_remove_opts_by_cookie(png_cookie); -#ifdef HAVE_SOME_FORMAT - rnd_hid_remove_hid(&png_hid); -#endif + + if (rnd_png_has_any_format()) + rnd_hid_remove_hid(&png_hid); } int pplg_init_export_png(void) @@ -731,10 +688,10 @@ png_hid.usage = png_usage; -#ifdef HAVE_SOME_FORMAT - rnd_hid_register_hid(&png_hid); - rnd_hid_load_defaults(&png_hid, png_attribute_list, NUM_OPTIONS); -#endif + if (rnd_png_has_any_format()) { + rnd_hid_register_hid(&png_hid); + rnd_hid_load_defaults(&png_hid, png_attribute_list, NUM_OPTIONS); + } return 0; }