Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 27154) +++ trunk/scconfig/Rev.h (revision 27155) @@ -1 +1 @@ -static const int myrev = 27146; +static const int myrev = 27155; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 27154) +++ trunk/scconfig/Rev.tab (revision 27155) @@ -1,4 +1,4 @@ -27146 configure hidlib: pixmap support framework: new .c file in the hidlib and pnm loader plugin +27155 configure hidlib: pixmap support framework: new .c file in the hidlib and pnm, png, jpeg, gif loader plugin 27100 configure hidlib: move base64 to core for reuse in hidlib (mainly for pixmaps) 27086 configure hidlib: tests and utils should use hidlib instead of manual object linking from the source tree 27069 configure retire the export_bboard plugin in favor of subc pixmaps that are going to be implemented soon Index: trunk/scconfig/hooks.c =================================================================== --- trunk/scconfig/hooks.c (revision 27154) +++ trunk/scconfig/hooks.c (revision 27155) @@ -426,7 +426,7 @@ want_gtk2 = plug_is_enabled("hid_gtk2_gdk") || plug_is_enabled("hid_gtk2_gl"); want_gtk3 = plug_is_enabled("hid_gtk3_cairo"); want_gtk = want_gtk2 | want_gtk3; - want_gd = plug_is_enabled("export_png") || plug_is_enabled("export_gcode"); + want_gd = plug_is_enabled("export_png") || plug_is_enabled("import_pxm_gd") || plug_is_enabled("export_gcode"); want_stroke = plug_is_enabled("stroke"); want_cairo = plug_is_enabled("hid_gtk3_cairo"); want_xml2 = plug_is_enabled("io_eagle"); @@ -704,6 +704,7 @@ hook_custom_arg("disable-gd-png", NULL); hook_custom_arg("disable-gd-jpg", NULL); hook_custom_arg("disable-export_png", NULL); + hook_custom_arg("disable-import_pxm_gd", NULL); hook_custom_arg("disable-export_gcode", NULL); want_gd = 0; goto disable_gd_formats; Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 27154) +++ trunk/scconfig/plugins.h (revision 27155) @@ -78,6 +78,7 @@ plugin_def("import_mentor_sch","import mentor graphics sch", sbuildin, 1, 0) plugin_def("import_mucs", "import mucs routing", sbuildin, 1, 0) plugin_def("import_netlist", "import netlist", sbuildin, 1, 0) +plugin_def("import_pxm_gd", "import pixmaps from png/gif/jpg", sbuildin, 1, 0) plugin_def("import_pxm_pnm", "import pixmaps from pnm ", sbuildin, 1, 0) plugin_def("import_sch", "import sch", sbuildin, 1, 0) plugin_def("import_tinycad", "import tinycad .net", sbuildin, 1, 0) Index: trunk/src_plugins/import_pxm_gd/Makefile =================================================================== --- trunk/src_plugins/import_pxm_gd/Makefile (nonexistent) +++ trunk/src_plugins/import_pxm_gd/Makefile (revision 27155) @@ -0,0 +1,6 @@ +all: + cd ../../src && $(MAKE) mod_import_pxm_gd + +clean: + rm *.o *.so 2>/dev/null ; true + Index: trunk/src_plugins/import_pxm_gd/Plug.tmpasm =================================================================== --- trunk/src_plugins/import_pxm_gd/Plug.tmpasm (nonexistent) +++ trunk/src_plugins/import_pxm_gd/Plug.tmpasm (revision 27155) @@ -0,0 +1,8 @@ +put /local/pcb/mod {import_pxm_gd} +put /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_pxm_gd/import_pxm_gd.o @] + +switch /local/pcb/import_pxm_gd/controls + case {buildin} include /local/pcb/tmpasm/buildin; end; + case {plugin} include /local/pcb/tmpasm/plugin; end; + case {disable} include /local/pcb/tmpasm/disable; end; +end Index: trunk/src_plugins/import_pxm_gd/import_pxm_gd.c =================================================================== --- trunk/src_plugins/import_pxm_gd/import_pxm_gd.c (nonexistent) +++ trunk/src_plugins/import_pxm_gd/import_pxm_gd.c (revision 27155) @@ -0,0 +1,146 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * pixmap loader for pnm + * pcb-rnd Copyright (C) 2019 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" + +#include +#include +#include +#include + +#include "plugins.h" +#include "pixmap.h" +#include "safe_fs.h" + +static const char *import_pxm_gd_cookie = "import_pxm_gd"; + +static int gd_load(pcb_hidlib_t *hidlib, pcb_pixmap_t *pxm, const char *fn, gdImagePtr (*loader)(FILE *f)) +{ + int x, y; + gdImagePtr gdi; + FILE *f; + + f = pcb_fopen(hidlib, fn, "rb"); + if (f == NULL) + return -1; + gdi = loader(f); + if (gdi != NULL) { + unsigned char *p; + int r, g, b, a; + pxm->sx = gdi->sx; + pxm->sy = gdi->sy; + pxm->tr = pxm->tg = 127; + pxm->tb = 128; + pxm->size = pxm->sx * pxm->sy * 3; + p = pxm->p = malloc(pxm->size); + for(y = 0; y < pxm->sy; y++) { + for(x = 0; x < pxm->sx; x++) { + int pix = gdImageGetPixel(gdi, x, y); + r = gdImageRed(gdi, pix); + g = gdImageGreen(gdi, pix); + b = gdImageBlue(gdi, pix); + a = gdImageAlpha(gdi, pix); + + if (a == 0) { + if ((r == pxm->tr) && (g == pxm->tg) && (b == pxm->tb)) + b--; + *p++ = r; + *p++ = g; + *p++ = b; + } + else { + *p++ = pxm->tr; + *p++ = pxm->tg; + *p++ = pxm->tb; + } + } + } + } + fclose(f); + return (gdi == NULL); +} + +#ifdef HAVE_GDIMAGEPNG +static int gd_png_load(pcb_hidlib_t *hidlib, pcb_pixmap_t *pxm, const char *fn) +{ + gd_load(hidlib, pxm, fn, gdImageCreateFromPng); +} + +static const pcb_pixmap_import_t pxm_gd_png_imp = { + "png (gd)", + gd_png_load +}; +#endif + +#ifdef HAVE_GDIMAGEJPEG +static int gd_jpg_load(pcb_hidlib_t *hidlib, pcb_pixmap_t *pxm, const char *fn) +{ + gd_load(hidlib, pxm, fn, gdImageCreateFromJpeg); +} + +static const pcb_pixmap_import_t pxm_gd_jpg_imp = { + "jpg (gd)", + gd_jpg_load +}; +#endif + +#ifdef HAVE_GDIMAGEGIF +static int gd_gif_load(pcb_hidlib_t *hidlib, pcb_pixmap_t *pxm, const char *fn) +{ + gd_load(hidlib, pxm, fn, gdImageCreateFromGif); +} + +static const pcb_pixmap_import_t pxm_gd_gif_imp = { + "gif (gd)", + gd_gif_load +}; +#endif + +int pplg_check_ver_import_pxm_gd(int ver_needed) { return 0; } + +void pplg_uninit_import_pxm_gd(void) +{ + pcb_pixmap_unreg_import_all(import_pxm_gd_cookie); +} + +#include "dolists.h" +int pplg_init_import_pxm_gd(void) +{ + PCB_API_CHK_VER; + +#ifdef HAVE_GDIMAGEPNG + pcb_pixmap_reg_import(&pxm_gd_png_imp, import_pxm_gd_cookie); +#endif +#ifdef HAVE_GDIMAGEJPEG + pcb_pixmap_reg_import(&pxm_gd_jpg_imp, import_pxm_gd_cookie); +#endif +#ifdef HAVE_GDIMAGEGIF + pcb_pixmap_reg_import(&pxm_gd_gif_imp, import_pxm_gd_cookie); +#endif + return 0; +} Index: trunk/src_plugins/import_pxm_gd/import_pxm_gd.pup =================================================================== --- trunk/src_plugins/import_pxm_gd/import_pxm_gd.pup (nonexistent) +++ trunk/src_plugins/import_pxm_gd/import_pxm_gd.pup (revision 27155) @@ -0,0 +1,9 @@ +$class import +$short import pixmaps from png/gif/jpg +$long Import png, gif and jpeg using libgd +$state works +$fmt-native no +$fmt-feature-r import pixmap +$package import-geo +default buildin +autoload 1