Index: trunk/INSTALL =================================================================== --- trunk/INSTALL (revision 27145) +++ trunk/INSTALL (revision 27146) @@ -20,7 +20,7 @@ - optional: glib and gtk2 if you are using the GTK GUI - optional: gtkglext if you need opengl rendering - optional: motif or lesstif if you are using the lesstif frontend - - optional: gdlib if you are using the png HID + - optional: gdlib if you want to export/import to/from png, jpg or gif For developers: - flex Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 27145) +++ trunk/scconfig/Rev.h (revision 27146) @@ -1 +1 @@ -static const int myrev = 27123; +static const int myrev = 27146; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 27145) +++ trunk/scconfig/Rev.tab (revision 27146) @@ -1,4 +1,4 @@ -27123 configure hidlib: pixmap support framework: new .c file in the hidlib +27146 configure hidlib: pixmap support framework: new .c file in the hidlib and pnm 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/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 27145) +++ trunk/scconfig/plugins.h (revision 27146) @@ -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_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) plugin_def("import_ttf", "import ttf glyphs", sbuildin, 1, 0) Index: trunk/src_plugins/import_pxm_pnm/Makefile =================================================================== --- trunk/src_plugins/import_pxm_pnm/Makefile (nonexistent) +++ trunk/src_plugins/import_pxm_pnm/Makefile (revision 27146) @@ -0,0 +1,6 @@ +all: + cd ../../src && $(MAKE) mod_import_pxm_pnm + +clean: + rm *.o *.so 2>/dev/null ; true + Index: trunk/src_plugins/import_pxm_pnm/Plug.tmpasm =================================================================== --- trunk/src_plugins/import_pxm_pnm/Plug.tmpasm (nonexistent) +++ trunk/src_plugins/import_pxm_pnm/Plug.tmpasm (revision 27146) @@ -0,0 +1,8 @@ +put /local/pcb/mod {import_pxm_pnm} +put /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_pxm_pnm/import_pxm_pnm.o @] + +switch /local/pcb/import_pxm_pnm/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_pnm/import_pxm_pnm.c =================================================================== --- trunk/src_plugins/import_pxm_pnm/import_pxm_pnm.c (nonexistent) +++ trunk/src_plugins/import_pxm_pnm/import_pxm_pnm.c (revision 27146) @@ -0,0 +1,143 @@ +/* + * 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 "plugins.h" +#include "pixmap.h" +#include "safe_fs.h" + +static const char *import_pxm_pnm_cookie = "import_pxm_pnm"; + +#define ADDPX(pxm, r_, g_, b_, transparent) \ +do { \ + int r = r_, g = g_, b = b_; \ + if ((r < 0) || (g < 0) || (b < 0)) { \ + fclose(f); \ + return -1; \ + } \ + if (transparent) { \ + *o++ = pxm->tr; \ + *o++ = pxm->tg; \ + *o++ = pxm->tb; \ + } \ + else { \ + if ((r == pxm->tr) && (g == pxm->tg) && (b == pxm->tb)) \ + b--; \ + *o++ = r; \ + *o++ = g; \ + *o++ = b; \ + } \ +} while(0) + +int pnm_load(pcb_hidlib_t *hidlib, pcb_pixmap_t *pxm, const char *fn) +{ + FILE *f; + char *s, line[1024]; + unsigned char *o; + int n, type; + + f = pcb_fopen(hidlib, fn, "rb"); + if (f == NULL) + return -1; + + fgets(line, sizeof(line) - 1, f); + if ((line[0] != 'P') || ((line[1] != '4') && (line[1] != '5') && (line[1] == '6')) || (line[2] != '\n')) { + fclose(f); + return -1; + } + type = line[1]; + + fgets(line, sizeof(line) - 1, f); + s = strchr(line, ' '); + if (s == NULL) { + fclose(f); + return -1; + } + *s = '\0'; + s++; + pxm->sx = atoi(line); + pxm->sy = atoi(s); + + if ((pxm->sx <= 0) || (pxm->sy <= 0) || (pxm->sx > 100000) || (pxm->sy > 100000)) { + fclose(f); + return -1; + } + + pxm->tr = pxm->tg = 127; + pxm->tb = 128; + n = pxm->sx * pxm->sy; + o = pxm->p = malloc(n * 3); + + switch(type) { + case '6': + fgets(line, sizeof(line) - 1, f); + for(; n>0; n--) + ADDPX(pxm, fgetc(f), fgetc(f), fgetc(f), 0); + break; + case '5': + fgets(line, sizeof(line) - 1, f); + for(; n>0; n--) { + int px = fgetc(f); + ADDPX(pxm, px, px, px, 0); + } + break; + case '4': + for(;n>0;) { + int m, c, px; + c = fgetc(f); + for(m = 0; m < 8; m++) { + px = (c & 128) ? 0 : 255; + ADDPX(pxm, px, px, px, 0); + c <<= 1; + n--; + } + } + break; + } + fclose(f); + return 0; +} + + +int pplg_check_ver_import_pxm_pnm(int ver_needed) { return 0; } + +void pplg_uninit_import_pxm_pnm(void) +{ +} + +#include "dolists.h" +int pplg_init_import_pxm_pnm(void) +{ + PCB_API_CHK_VER; + return 0; +} Index: trunk/src_plugins/import_pxm_pnm/import_pxm_pnm.pup =================================================================== --- trunk/src_plugins/import_pxm_pnm/import_pxm_pnm.pup (nonexistent) +++ trunk/src_plugins/import_pxm_pnm/import_pxm_pnm.pup (revision 27146) @@ -0,0 +1,9 @@ +$class import +$short import pixmaps from pnm +$long Import pnm P4, P5 and P6 into pcb-rnd pixmaps +$state works +$fmt-native no +$fmt-feature-r import pixmap +$package import-geo +default buildin +autoload 1 Index: trunk/src_plugins/plugins_ALL.tmpasm =================================================================== --- trunk/src_plugins/plugins_ALL.tmpasm (revision 27145) +++ trunk/src_plugins/plugins_ALL.tmpasm (revision 27146) @@ -61,6 +61,7 @@ include {../src_plugins/import_mentor_sch/Plug.tmpasm} include {../src_plugins/import_mucs/Plug.tmpasm} include {../src_plugins/import_netlist/Plug.tmpasm} +include {../src_plugins/import_pxm_pnm/Plug.tmpasm} include {../src_plugins/import_sch/Plug.tmpasm} include {../src_plugins/import_tinycad/Plug.tmpasm} include {../src_plugins/import_ttf/Plug.tmpasm}