Index: trunk/src/color_cache.h =================================================================== --- trunk/src/color_cache.h (revision 29306) +++ trunk/src/color_cache.h (nonexistent) @@ -1,90 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2018 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") - */ - -#ifndef PCB_COLOR_CACHE_H -#define PCB_COLOR_CACHE_H - -#include -#include -#include -#include -#include - -typedef void (*pcb_clrcache_free_t)(pcb_clrcache_t *cache, void *hidclr); - -struct pcb_clrcache_s { - htip_t ht; - int hidsize; - pcb_clrcache_free_t hidfree; - - void *user_data; /* the caller can set this up after pcb_clrcache_init and use it in hidfree() */ -}; - -PCB_INLINE void pcb_clrcache_init(pcb_clrcache_t *cache, int hidsize, pcb_clrcache_free_t hidfree) -{ - htip_init(&cache->ht, longhash, longkeyeq); - cache->hidsize = hidsize; - cache->hidfree = hidfree; - cache->user_data = NULL; -} - -PCB_INLINE void pcb_clrcache_del(pcb_clrcache_t *cache, const pcb_color_t *color) -{ - void *old = htip_get(&cache->ht, color->packed); - if (old == NULL) - return; - if (cache->hidfree != NULL) - cache->hidfree(cache, old); - free(old); -} - -PCB_INLINE void *pcb_clrcache_get(pcb_clrcache_t *cache, const pcb_color_t *color, int alloc) -{ - void *clr = htip_get(&cache->ht, color->packed); - if (clr != NULL) - return clr; - - if (!alloc) - return NULL; - - clr = calloc(cache->hidsize, 1); - htip_set(&cache->ht, color->packed, clr); - return clr; -} - -PCB_INLINE void pcb_clrcache_uninit(pcb_clrcache_t *cache) -{ - htip_entry_t *e; - - for(e = htip_first(&cache->ht); e != NULL; e = htip_next(&cache->ht, e)) { - if (cache->hidfree != NULL) - cache->hidfree(cache, e->value); - free(e->value); - } - htip_uninit(&cache->ht); -} - -#endif Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 29306) +++ trunk/src/Makefile.dep (revision 29307) @@ -2116,7 +2116,7 @@ obj_line.h obj_poly_list.h obj_poly.h librnd/poly/polyarea.h \ obj_text_list.h obj_text.h font.h ../src_3rd/genht/htip.h \ librnd/core/box.h librnd/core/math_helper.h librnd/core/misc_util.h \ - layer_grp.h rats_patch.h board.h librnd/core/hidlib.h color_cache.h \ + layer_grp.h rats_patch.h board.h librnd/core/hidlib.h librnd/core/color_cache.h \ ../src_3rd/genht/hash.h data.h crosshair.h vtonpoint.h librnd/core/hid.h \ librnd/core/error.h route.h buffer.h ../src_3rd/libfungw/fungw.h \ obj_rat_list.h obj_rat.h idpath.h obj_subc_list.h obj_subc.h \ @@ -2752,7 +2752,7 @@ librnd/core/globalconst.h data_parent.h obj_poly.h \ librnd/poly/polyarea.h route.h draw.h layer.h obj_arc_list.h obj_arc.h \ obj_line_list.h obj_poly_list.h obj_text_list.h obj_text.h font.h \ - ../src_3rd/genht/htip.h librnd/core/grid.h color_cache.h \ + ../src_3rd/genht/htip.h librnd/core/grid.h librnd/core/color_cache.h \ ../src_3rd/genht/hash.h librnd/core/hid_attrib.h funchash_core.h \ librnd/core/funchash.h funchash_core_list.h librnd/core/pixmap.h \ ../src_plugins/lib_gtk_common/pcb_gtk.h \ @@ -2815,7 +2815,7 @@ obj_arc_list.h obj_arc.h ../src_3rd/genlist/gentdlist_impl.h \ ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ obj_line_list.h obj_poly_list.h obj_text_list.h obj_text.h font.h \ - ../src_3rd/genht/htip.h ../src_3rd/genvector/gds_char.h color_cache.h \ + ../src_3rd/genht/htip.h ../src_3rd/genvector/gds_char.h librnd/core/color_cache.h \ ../src_3rd/genht/hash.h librnd/core/hid_attrib.h \ librnd/core/hidlib_conf.h librnd/core/conf.h librnd/core/pcb-printf.h \ ../src_3rd/liblihata/lihata.h ../src_3rd/genvector/vtp0.h \ @@ -3014,7 +3014,7 @@ librnd/poly/rtree.h ../src_3rd/genrtree/genrtree_api.h ht_subc.h \ ../src_3rd/genht/ht.h ../src_3rd/genht/hash.h obj_pstk_list.h obj_pstk.h \ vtpadstack.h obj_pstk_shape.h polygon.h vtpadstack_t.h draw.h \ - color_cache.h crosshair.h librnd/core/conf_hid.h layer.h \ + librnd/core/color_cache.h crosshair.h librnd/core/conf_hid.h layer.h \ librnd/core/event.h librnd/core/plugins.h ../src_3rd/puplug/puplug.h \ ../src_3rd/puplug/libs.h ../src_3rd/puplug/os_dep.h \ ../src_3rd/puplug/config.h ../src_3rd/puplug/libs.h \ Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 29306) +++ trunk/src/Makefile.in (revision 29307) @@ -592,7 +592,7 @@ # rndlib: corner case: some headers are not derived from the objects sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/hid_dlg.h } {} sub /local/pcb/HDRS_HIDLIB {polygon1.h } {} -append /local/pcb/HDRS_HIDLIB {$(LIBRND)/config.h $(LIBRND)/core/hid.h $(LIBRND)/core/global_typedefs.h $(LIBRND)/core/globalconst.h $(LIBRND)/core/math_helper.h $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/hid_inlines.h $(LIBRND)/core/rotate.h $(LIBRND)/core/fptr_cast.h $(LIBRND)/core/safe_fs_dir.h $(LIBRND)/core/compat_inc.h $(LIBRND)/poly/rtree2_compat.h } +append /local/pcb/HDRS_HIDLIB {$(LIBRND)/config.h $(LIBRND)/core/hid.h $(LIBRND)/core/global_typedefs.h $(LIBRND)/core/globalconst.h $(LIBRND)/core/math_helper.h $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/hid_inlines.h $(LIBRND)/core/rotate.h $(LIBRND)/core/fptr_cast.h $(LIBRND)/core/safe_fs_dir.h $(LIBRND)/core/compat_inc.h $(LIBRND)/poly/rtree2_compat.h $(LIBRND)/core/color_cache.h } gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/dom_[^ ]*.h } {} gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/tree_[^ ]*.h } {} gsub /local/pcb/HDRS_3RDLIB {../src_3rd/libfungw/fungw_ptr.h ../src_3rd/libfungw/fungw_debug.h ../src_3rd/libfungw/fungw_call.h } {} Index: trunk/src/librnd/core/color_cache.h =================================================================== --- trunk/src/librnd/core/color_cache.h (nonexistent) +++ trunk/src/librnd/core/color_cache.h (revision 29307) @@ -0,0 +1,90 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018 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") + */ + +#ifndef PCB_COLOR_CACHE_H +#define PCB_COLOR_CACHE_H + +#include +#include +#include +#include +#include + +typedef void (*pcb_clrcache_free_t)(pcb_clrcache_t *cache, void *hidclr); + +struct pcb_clrcache_s { + htip_t ht; + int hidsize; + pcb_clrcache_free_t hidfree; + + void *user_data; /* the caller can set this up after pcb_clrcache_init and use it in hidfree() */ +}; + +PCB_INLINE void pcb_clrcache_init(pcb_clrcache_t *cache, int hidsize, pcb_clrcache_free_t hidfree) +{ + htip_init(&cache->ht, longhash, longkeyeq); + cache->hidsize = hidsize; + cache->hidfree = hidfree; + cache->user_data = NULL; +} + +PCB_INLINE void pcb_clrcache_del(pcb_clrcache_t *cache, const pcb_color_t *color) +{ + void *old = htip_get(&cache->ht, color->packed); + if (old == NULL) + return; + if (cache->hidfree != NULL) + cache->hidfree(cache, old); + free(old); +} + +PCB_INLINE void *pcb_clrcache_get(pcb_clrcache_t *cache, const pcb_color_t *color, int alloc) +{ + void *clr = htip_get(&cache->ht, color->packed); + if (clr != NULL) + return clr; + + if (!alloc) + return NULL; + + clr = calloc(cache->hidsize, 1); + htip_set(&cache->ht, color->packed, clr); + return clr; +} + +PCB_INLINE void pcb_clrcache_uninit(pcb_clrcache_t *cache) +{ + htip_entry_t *e; + + for(e = htip_first(&cache->ht); e != NULL; e = htip_next(&cache->ht, e)) { + if (cache->hidfree != NULL) + cache->hidfree(cache, e->value); + free(e->value); + } + htip_uninit(&cache->ht); +} + +#endif Index: trunk/src_plugins/export_png/png.c =================================================================== --- trunk/src_plugins/export_png/png.c (revision 29306) +++ trunk/src_plugins/export_png/png.c (revision 29307) @@ -43,7 +43,7 @@ #include "board.h" #include -#include "color_cache.h" +#include #include "data.h" #include "draw.h" #include Index: trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c =================================================================== --- trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c (revision 29306) +++ trunk/src_plugins/hid_gtk2_gdk/gtkhid-gdk.c (revision 29307) @@ -7,7 +7,7 @@ #include "draw.h" #include #include -#include "color_cache.h" +#include #include #include "funchash_core.h" #include Index: trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c =================================================================== --- trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c (revision 29306) +++ trunk/src_plugins/hid_gtk2_gl/gtkhid-gl.c (revision 29307) @@ -4,7 +4,7 @@ #include "crosshair.h" #include "draw.h" -#include "color_cache.h" +#include #include #include #include "funchash_core.h" Index: trunk/src_plugins/hid_lesstif/main.c =================================================================== --- trunk/src_plugins/hid_lesstif/main.c (revision 29306) +++ trunk/src_plugins/hid_lesstif/main.c (revision 29307) @@ -20,7 +20,7 @@ #include "data.h" #include "draw.h" #include -#include "color_cache.h" +#include #include "crosshair.h" #include #include "layer.h"