From 69aef1ffce27c5970ce4b93ff87211a760cf5ed0 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 18 Jan 2023 03:33:28 +0100 Subject: [PATCH] added libjpeg detection code, so postscript image embedding will be disabled if libjpeg not present --- Makefile.conf.in | 2 ++ config.h.in | 3 +++ scconfig/hooks.c | 37 +++++++++++++++++++++---------------- src/Makefile.in | 2 +- src/cairo_jpg.c | 5 ++++- src/psprint.c | 7 +++---- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Makefile.conf.in b/Makefile.conf.in index 0d44b71a..c795d63c 100644 --- a/Makefile.conf.in +++ b/Makefile.conf.in @@ -1,5 +1,6 @@ put /local/xschem/cflags [@ @cc/cflags@ + @?libs/sul/libjpeg/cflags@ @?libs/gui/cairo/cflags@ @?libs/gui/xrender/cflags@ @?libs/gui/xcb/cflags@ @@ -13,6 +14,7 @@ put /local/xschem/cflags [@ put /local/xschem/ldflags [@ @cc/ldflags@ -lm + @?libs/sul/libjpeg/ldflags@ @?libs/gui/cairo/ldflags@ @?libs/gui/xrender/ldflags@ @?libs/gui/xcb/ldflags@ diff --git a/config.h.in b/config.h.in index 4ec6741a..6fbb635e 100644 --- a/config.h.in +++ b/config.h.in @@ -20,6 +20,9 @@ print [@/*************************************************************/ /* Source: config.h.in; to regenerate run ./configure */ /*************************************************************/@] +print {\n\n/* Define this var if libjpeg is available and is to be used */\n} +print_ternary ?libs/sul/libjpeg/presents {#define HAS_LIBJPEG 1} {/*#undef HAS_LIBJPEG */} + print {\n\n/* Define this var if cairo is available and is to be used */\n} print_ternary ?libs/gui/cairo/presents {#define HAS_CAIRO 1} {/*#undef HAS_CAIRO */} diff --git a/scconfig/hooks.c b/scconfig/hooks.c index e46729b6..26512b3d 100644 --- a/scconfig/hooks.c +++ b/scconfig/hooks.c @@ -9,38 +9,38 @@ #define version "2.0.1" -int find_sul_pcre(const char *name, int logdepth, int fatal) +int find_sul_libjpeg(const char *name, int logdepth, int fatal) { const char *test_c = NL "#include " NL "#include " - NL "#include " + NL "#include " + NL "" NL "int main()" NL "{" - NL " const char *err;" - NL " int erro, ret;" - NL " pcre *p = pcre_compile(\"fo+b\", 0, &err, &erro, NULL);" - NL " ret = pcre_exec(p, NULL, \"hi foobar\", 9, 0, 0, &erro, 1);" - NL " if (ret == 0)" - NL " puts(\"OK\");" - NL " return 0;" + NL " struct jpeg_compress_struct cinfo;" + NL " struct jpeg_error_mgr jerr;" + NL " jerr.error_exit = NULL;" + NL " cinfo.err = jpeg_std_error(&jerr);" + NL " jpeg_create_compress(&cinfo);" + NL " jpeg_destroy_compress(&cinfo);" + NL " if(jerr.error_exit)" + NL " puts(\"OK\");" + NL " return 0;" NL "}" NL; - const char *node = "libs/sul/pcre"; + const char *node = "libs/sul/libjpeg"; if (require("cc/cc", logdepth, fatal)) return 1; - report("Checking for pcre... "); + report("Checking for libjpeg... "); - if (try_icl_pkg_config(logdepth, "libs/sul/pcre", test_c, NULL, "libpcre", NULL)) + if (try_icl_pkg_config(logdepth, node, test_c, NULL, "libjpeg", NULL)) return 0; - if (try_icl(logdepth, node, test_c, NULL, "-I/usr/include/pcre", "-lpcre")) - return 0; - - if (try_icl(logdepth, node, test_c, NULL, "-I/usr/include/pcre", "-lpcre3")) + if (try_icl(logdepth, node, test_c, NULL, NULL, "-ljpeg")) return 0; return try_fail(logdepth, node); @@ -123,6 +123,9 @@ int hook_preinit() /* Runs after initialization */ int hook_postinit() { + /* libjpeg detection */ + dep_add("libs/sul/libjpeg/*", find_sul_libjpeg); + db_mkdir("/local"); db_mkdir("/local/xschem"); @@ -289,6 +292,7 @@ int hook_detect_target() require("fstools/awk", 0, 1); require("libs/gui/xpm/*", 0, 1); require("libs/gui/cairo/*", 0, 0); + require("libs/sul/libjpeg/*", 0, 0); if (require("libs/gui/cairo-xcb/*", 0, 0) != 0) { put("libs/gui/xcb/presents", sfalse); @@ -357,6 +361,7 @@ int hook_generate() printf(" tcl: %s\n", get("/target/libs/script/tcl/ldflags")); printf(" tk: %s\n", get("/target/libs/script/tk/ldflags")); printf(" cairo: %s\n", istrue(get("/target/libs/gui/cairo/presents")) ? "yes" : "no"); + printf(" libjpeg: %s\n", istrue(get("/target/libs/sul/libjpeg/presents")) ? "yes" : "no"); printf(" xcb: %s\n", istrue(get("/target/libs/gui/xcb/presents")) ? "yes" : "no"); printf("\nConfiguration complete, ready to compile.\n\n"); diff --git a/src/Makefile.in b/src/Makefile.in index a3be5184..cea16e20 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -40,7 +40,7 @@ rawtovcd: rawtovcd.o $(CC) -o rawtovcd rawtovcd.o -lm xschem: $(OBJ) - $(CC) -o xschem $(OBJ) $(LDFLAGS) -ljpeg + $(CC) -o xschem $(OBJ) $(LDFLAGS) parselabel.c: parselabel.l expandlabel.h flex -l -oparselabel.c parselabel.l diff --git a/src/cairo_jpg.c b/src/cairo_jpg.c index f9ba96fe..5b4090b4 100644 --- a/src/cairo_jpg.c +++ b/src/cairo_jpg.c @@ -39,6 +39,8 @@ * @license LGPL3. */ +#include "../config.h" +#if defined(HAS_LIBJPEG) && defined(HAS_CAIRO) #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -625,4 +627,5 @@ int main(int argc, char **argv) } #endif - +#endif /* HAS_LIBJPEG && HAS_CAIRO */ +typedef int make_iso_compilers_happy; /* to avoid empty translation unit */ diff --git a/src/psprint.c b/src/psprint.c index 8ac7f4fb..426a3feb 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -122,9 +122,9 @@ unsigned char* bin2hex(const unsigned char* bin, size_t len) return out; } - void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, int flip) { + #if defined(HAS_LIBJPEG) && defined(HAS_CAIRO) int i; size_t data_size = 0; png_to_byte_closure_t closure = {NULL, 0, 0}; @@ -246,12 +246,12 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, i fprintf(fd, "grestore\n"); cairo_surface_destroy(surface); my_free(1663, &hexEncodedJPG); + #endif } - void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2) { - #if defined(HAS_CAIRO) + #if defined(HAS_LIBJPEG) && defined(HAS_CAIRO) double rw, rh, scale; cairo_surface_t* png_sfc; int save_draw_window, save_draw_grid, rwi, rhi; @@ -356,7 +356,6 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2) fprintf(fd, "grestore\n"); my_free(1666, &hexEncodedJPG); #endif - } static void set_lw(void) {