From: <wog...@us...> - 2011-05-01 22:10:00
|
Revision: 4462 http://navit.svn.sourceforge.net/navit/?rev=4462&view=rev Author: woglinde Date: 2011-05-01 22:09:54 +0000 (Sun, 01 May 2011) Log Message: ----------- Fix:core:Check for nullpointers before use members in graphics_free() Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2011-05-01 22:09:47 UTC (rev 4461) +++ trunk/navit/navit/graphics.c 2011-05-01 22:09:54 UTC (rev 4462) @@ -393,6 +393,8 @@ */ void graphics_free(struct graphics *gra) { + if (!gra) + return; gra->meth.graphics_destroy(gra->priv); g_free(gra->default_font); graphics_font_destroy_all(gra); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2011-05-09 11:57:28
|
Revision: 4474 http://navit.svn.sourceforge.net/navit/?rev=4474&view=rev Author: martin-s Date: 2011-05-09 11:57:21 +0000 (Mon, 09 May 2011) Log Message: ----------- Fix:Core:MSVC fixes Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2011-05-09 11:55:57 UTC (rev 4473) +++ trunk/navit/navit/graphics.c 2011-05-09 11:57:21 UTC (rev 4474) @@ -1254,7 +1254,7 @@ struct point *res=g_alloca(sizeof(struct point)*maxpoints); struct point pos, poso, neg, nego; int i, dx=0, dy=0, l=0, dxo=0, dyo=0; - struct offset o,oo={}; + struct offset o,oo={0,0,0,0}; int fow=0, fowo=0, delta; int wi, ppos = maxpoints/2, npos = maxpoints/2; int state,prec=5; @@ -1649,6 +1649,7 @@ char * graphics_icon_path(char *icon) { + static char *navit_sharedir; char *ret=NULL; struct file_wordexp *wordexp=NULL; dbg(1,"enter %s\n",icon); @@ -1670,7 +1671,6 @@ // ret=g_strdup_printf("res/drawable-%s/%s",android_density ,icon); ret=g_strdup_printf("res/drawable/%s" ,icon); #else - static char *navit_sharedir; if (! navit_sharedir) navit_sharedir = getenv("NAVIT_SHAREDIR"); ret=g_strdup_printf("%s/xpm/%s", navit_sharedir, icon); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wog...@us...> - 2012-01-20 21:32:35
|
Revision: 4900 http://navit.svn.sourceforge.net/navit/?rev=4900&view=rev Author: woglinde Date: 2012-01-20 21:32:30 +0000 (Fri, 20 Jan 2012) Log Message: ----------- Fix:core:When destroying the graphics, destroy the graphics_gc's too, guard graphics_destroy_gc against null pointer Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-01-20 21:32:10 UTC (rev 4899) +++ trunk/navit/navit/graphics.c 2012-01-20 21:32:30 UTC (rev 4900) @@ -402,6 +402,9 @@ { if (!gra) return; + graphics_gc_destroy(gra->gc[0]); + graphics_gc_destroy(gra->gc[1]); + graphics_gc_destroy(gra->gc[2]); gra->meth.graphics_destroy(gra->priv); g_free(gra->default_font); graphics_font_destroy_all(gra); @@ -449,6 +452,8 @@ */ void graphics_gc_destroy(struct graphics_gc *gc) { + if (!gc) + return; gc->meth.gc_destroy(gc->priv); g_free(gc); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wog...@us...> - 2012-03-04 13:22:10
|
Revision: 4962 http://navit.svn.sourceforge.net/navit/?rev=4962&view=rev Author: woglinde Date: 2012-03-04 13:22:04 +0000 (Sun, 04 Mar 2012) Log Message: ----------- Fix:core:use dbg instead of printf Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-03-04 12:56:53 UTC (rev 4961) +++ trunk/navit/navit/graphics.c 2012-03-04 13:22:04 UTC (rev 4962) @@ -1841,7 +1841,7 @@ display_draw_arrows(gra,gc,pa,count); break; default: - printf("Unhandled element type %d\n", e->type); + dbg(0, "Unhandled element type %d\n", e->type); } di=di->next; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2012-04-07 19:20:30
|
Revision: 5011 http://navit.svn.sourceforge.net/navit/?rev=5011&view=rev Author: mdankov Date: 2012-04-07 19:20:24 +0000 (Sat, 07 Apr 2012) Log Message: ----------- Fix:core:Allow itemgra's of order 0 to be displayed when zoom level allows to fit more than 1/8 of the planet on the screen. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-04-04 19:19:34 UTC (rev 5010) +++ trunk/navit/navit/graphics.c 2012-04-07 19:20:24 UTC (rev 5011) @@ -2197,8 +2197,10 @@ gra->meth.draw_mode(gra->priv, (flags & 8)?draw_mode_begin_clear:draw_mode_begin); if (!(flags & 2)) gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y); - if (l) - xdisplay_draw(displaylist, gra, l, order+l->order_delta); + if (l) { + order+=l->order_delta; + xdisplay_draw(displaylist, gra, l, order>0?order:0); + } if (flags & 1) callback_list_call_attr_0(gra->cbl, attr_postdraw); if (!(flags & 4)) @@ -2229,7 +2231,7 @@ displaylist->seq++; if (l) order+=l->order_delta; - displaylist->order=order; + displaylist->order=order>0?order:0; displaylist->busy=1; displaylist->layout=l; if (async) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2012-05-23 21:32:16
|
Revision: 5112 http://navit.svn.sourceforge.net/navit/?rev=5112&view=rev Author: mdankov Date: 2012-05-23 21:32:10 +0000 (Wed, 23 May 2012) Log Message: ----------- Fix:core:Made graphics.c code compatible with n800 again. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-05-22 16:31:17 UTC (rev 5111) +++ trunk/navit/navit/graphics.c 2012-05-23 21:32:10 UTC (rev 5112) @@ -245,7 +245,7 @@ this_->contrast=65536; this_->gamma=65536; this_->font_size=20; - this_->image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal); + this_->image_cache_hash = g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free); while (*attrs) { graphics_set_attr_do(this_,*attrs); attrs++; @@ -411,14 +411,18 @@ GHashTableIter iter; char *key; struct graphics_image *img; - g_hash_table_iter_init (&iter, gra->image_cache_hash); - while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &img)) { - g_hash_table_iter_remove (&iter); - g_free(key); + GList *l; + + /* We can't specify context (pointer to struct graphics) for g_hash_table_new to have it passed to free function + so we have to free img->priv manually, the rest would be freed by g_hash_table_destroy. GHashTableIter isn't used because it + broke n800 build at r5107. + */ + for(l=g_hash_table_get_values(gra->image_cache_hash);l;l=g_list_next(l)) { + img=l->data; if (img && gra->meth.image_free) gra->meth.image_free(gra->priv, img->priv); - g_free(img); } + g_hash_table_destroy(gra->image_cache_hash); } graphics_gc_destroy(gra->gc[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2012-05-28 15:40:55
|
Revision: 5115 http://navit.svn.sourceforge.net/navit/?rev=5115&view=rev Author: mdankov Date: 2012-05-28 15:40:44 +0000 (Mon, 28 May 2012) Log Message: ----------- Fix:core:Try to fix n800 build again. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-05-25 20:00:00 UTC (rev 5114) +++ trunk/navit/navit/graphics.c 2012-05-28 15:40:44 UTC (rev 5115) @@ -408,20 +408,19 @@ /* If it's not an overlay, free the image cache. */ if(!gra->parent) { - GHashTableIter iter; - char *key; struct graphics_image *img; - GList *l; + GList *ll, *l; /* We can't specify context (pointer to struct graphics) for g_hash_table_new to have it passed to free function so we have to free img->priv manually, the rest would be freed by g_hash_table_destroy. GHashTableIter isn't used because it broke n800 build at r5107. */ - for(l=g_hash_table_get_values(gra->image_cache_hash);l;l=g_list_next(l)) { + for(ll=l=g_hash_to_list(gra->image_cache_hash);l;l=g_list_next(l)) { img=l->data; if (img && gra->meth.image_free) gra->meth.image_free(gra->priv, img->priv); } + g_list_free(ll); g_hash_table_destroy(gra->image_cache_hash); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2012-06-07 21:24:39
|
Revision: 5138 http://navit.svn.sourceforge.net/navit/?rev=5138&view=rev Author: mdankov Date: 2012-06-07 21:24:33 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Fix:core:Two more leaks in graphics.c Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-06-07 21:07:12 UTC (rev 5137) +++ trunk/navit/navit/graphics.c 2012-06-07 21:24:33 UTC (rev 5138) @@ -429,6 +429,7 @@ graphics_gc_destroy(gra->gc[2]); g_free(gra->default_font); graphics_font_destroy_all(gra); + g_free(gra->font); gra->meth.graphics_destroy(gra->priv); g_free(gra); } @@ -719,6 +720,7 @@ this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate); if (this_->priv) { dbg(1,"Using image '%s' for '%s' at %dx%d\n", new_name, path, newwidth, newheight); + g_free(new_name); break; } g_free(new_name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wog...@us...> - 2012-06-20 07:50:15
|
Revision: 5152 http://navit.svn.sourceforge.net/navit/?rev=5152&view=rev Author: woglinde Date: 2012-06-20 07:50:09 +0000 (Wed, 20 Jun 2012) Log Message: ----------- Fix:core: fix small memleak for struct graphics Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-06-18 19:23:29 UTC (rev 5151) +++ trunk/navit/navit/graphics.c 2012-06-20 07:50:09 UTC (rev 5152) @@ -424,6 +424,7 @@ g_hash_table_destroy(gra->image_cache_hash); } + attr_list_free(gra->attrs); graphics_gc_destroy(gra->gc[0]); graphics_gc_destroy(gra->gc[1]); graphics_gc_destroy(gra->gc[2]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2012-12-29 19:54:27
|
Revision: 5333 http://navit.svn.sourceforge.net/navit/?rev=5333&view=rev Author: sleske Date: 2012-12-29 19:54:21 +0000 (Sat, 29 Dec 2012) Log Message: ----------- Fix:core:Fix integer overflow that causes wrong lines on map at high zoom levels. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2012-12-26 18:02:05 UTC (rev 5332) +++ trunk/navit/navit/graphics.c 2012-12-29 19:54:21 UTC (rev 5333) @@ -1557,40 +1557,43 @@ if (code1 & code2) return 0; if (code1 & 1) { - p1->y+=(r->lu.x-p1->x)*dy/dx; - p1->w+=(r->lu.x-p1->x)*dw/dx; + // We must cast to float to avoid integer + // overflow (i.e. undefined behaviour) at high + // zoom levels. + p1->y+=(((float)r->lu.x)-p1->x)*dy/dx; + p1->w+=(((float)r->lu.x)-p1->x)*dw/dx; p1->x=r->lu.x; } else if (code1 & 2) { - p1->y+=(r->rl.x-p1->x)*dy/dx; - p1->w+=(r->rl.x-p1->x)*dw/dx; + p1->y+=(((float)r->rl.x)-p1->x)*dy/dx; + p1->w+=(((float)r->rl.x)-p1->x)*dw/dx; p1->x=r->rl.x; } else if (code1 & 4) { - p1->x+=(r->lu.y-p1->y)*dx/dy; - p1->w+=(r->lu.y-p1->y)*dw/dy; + p1->x+=(((float)r->lu.y)-p1->y)*dx/dy; + p1->w+=(((float)r->lu.y)-p1->y)*dw/dy; p1->y=r->lu.y; } else if (code1 & 8) { - p1->x+=(r->rl.y-p1->y)*dx/dy; - p1->w+=(r->rl.y-p1->y)*dw/dy; + p1->x+=(((float)r->rl.y)-p1->y)*dx/dy; + p1->w+=(((float)r->rl.y)-p1->y)*dw/dy; p1->y=r->rl.y; } code1=clipcode(p1, r); if (code1 & code2) return 0; if (code2 & 1) { - p2->y+=(r->lu.x-p2->x)*dy/dx; - p2->w+=(r->lu.x-p2->x)*dw/dx; + p2->y+=(((float)r->lu.x)-p2->x)*dy/dx; + p2->w+=(((float)r->lu.x)-p2->x)*dw/dx; p2->x=r->lu.x; } else if (code2 & 2) { - p2->y+=(r->rl.x-p2->x)*dy/dx; - p2->w+=(r->rl.x-p2->x)*dw/dx; + p2->y+=(((float)r->rl.x)-p2->x)*dy/dx; + p2->w+=(((float)r->rl.x)-p2->x)*dw/dx; p2->x=r->rl.x; } else if (code2 & 4) { - p2->x+=(r->lu.y-p2->y)*dx/dy; - p2->w+=(r->lu.y-p2->y)*dw/dy; + p2->x+=(((float)r->lu.y)-p2->y)*dx/dy; + p2->w+=(((float)r->lu.y)-p2->y)*dw/dy; p2->y=r->lu.y; } else if (code2 & 8) { - p2->x+=(r->rl.y-p2->y)*dx/dy; - p2->w+=(r->rl.y-p2->y)*dw/dy; + p2->x+=(((float)r->rl.y)-p2->y)*dx/dy; + p2->w+=(((float)r->rl.y)-p2->y)*dw/dy; p2->y=r->rl.y; } code2=clipcode(p2, r); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2013-01-20 10:21:41
|
Revision: 5343 http://navit.svn.sourceforge.net/navit/?rev=5343&view=rev Author: martin-s Date: 2013-01-20 10:21:32 +0000 (Sun, 20 Jan 2013) Log Message: ----------- Fix:Core:Fix vs compile Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-01-20 09:06:37 UTC (rev 5342) +++ trunk/navit/navit/graphics.c 2013-01-20 10:21:32 UTC (rev 5343) @@ -2128,9 +2128,10 @@ { while (layers) { struct layer *layer=layers->data; + GList *itemgras; if (layer->ref) layer=layer->ref; - GList *itemgras=layer->itemgras; + itemgras=layer->itemgras; while (itemgras) { struct itemgra *itemgra=itemgras->data; GList *types=itemgra->type; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-01-20 18:16:56
|
Revision: 5345 http://navit.svn.sourceforge.net/navit/?rev=5345&view=rev Author: sleske Date: 2013-01-20 18:16:49 +0000 (Sun, 20 Jan 2013) Log Message: ----------- Fix:core:Refactor code for polyline clipping|Introduce enums, rename variables, simplify conditions. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-01-20 15:01:00 UTC (rev 5344) +++ trunk/navit/navit/graphics.c 2013-01-20 18:16:49 UTC (rev 5345) @@ -1524,80 +1524,95 @@ int x,y,w; }; +enum relative_pos { + INSIDE = 0, + LEFT_OF = 1, + RIGHT_OF = 2, + ABOVE = 4, + BELOW = 8 +}; + static int -clipcode(struct wpoint *p, struct point_rect *r) +relative_pos(struct wpoint *p, struct point_rect *r) { - int code=0; + int relative_pos=INSIDE; if (p->x < r->lu.x) - code=1; - if (p->x > r->rl.x) - code=2; + relative_pos=LEFT_OF; + else if (p->x > r->rl.x) + relative_pos=RIGHT_OF; if (p->y < r->lu.y) - code |=4; - if (p->y > r->rl.y) - code |=8; - return code; + relative_pos |=ABOVE; + else if (p->y > r->rl.y) + relative_pos |=BELOW; + return relative_pos; } +enum clip_result { + CLIPRES_INVISIBLE = 0, + CLIPRES_VISIBLE = 1, + CLIPRES_START_CLIPPED = 2, + CLIPRES_END_CLIPPED = 4, +}; static int -clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *r) +clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *clip_rect) { - int code1,code2,ret=1; + int rel_pos1,rel_pos2; + int ret = CLIPRES_VISIBLE; int dx,dy,dw; - code1=clipcode(p1, r); - if (code1) - ret |= 2; - code2=clipcode(p2, r); - if (code2) - ret |= 4; + rel_pos1=relative_pos(p1, clip_rect); + if (rel_pos1!=INSIDE) + ret |= CLIPRES_START_CLIPPED; + rel_pos2=relative_pos(p2, clip_rect); + if (rel_pos2!=INSIDE) + ret |= CLIPRES_END_CLIPPED; dx=p2->x-p1->x; dy=p2->y-p1->y; dw=p2->w-p1->w; - while (code1 || code2) { - if (code1 & code2) - return 0; - if (code1 & 1) { + while ((rel_pos1!=INSIDE) || (rel_pos2!=INSIDE)) { + if (rel_pos1 & rel_pos2) + return CLIPRES_INVISIBLE; + if (rel_pos1 & LEFT_OF) { // We must cast to float to avoid integer - // overflow (i.e. undefined behaviour) at high + // overflow (i.e. undefined behaviour) at high // zoom levels. - p1->y+=(((float)r->lu.x)-p1->x)*dy/dx; - p1->w+=(((float)r->lu.x)-p1->x)*dw/dx; - p1->x=r->lu.x; - } else if (code1 & 2) { - p1->y+=(((float)r->rl.x)-p1->x)*dy/dx; - p1->w+=(((float)r->rl.x)-p1->x)*dw/dx; - p1->x=r->rl.x; - } else if (code1 & 4) { - p1->x+=(((float)r->lu.y)-p1->y)*dx/dy; - p1->w+=(((float)r->lu.y)-p1->y)*dw/dy; - p1->y=r->lu.y; - } else if (code1 & 8) { - p1->x+=(((float)r->rl.y)-p1->y)*dx/dy; - p1->w+=(((float)r->rl.y)-p1->y)*dw/dy; - p1->y=r->rl.y; + p1->y+=(((float)clip_rect->lu.x)-p1->x)*dy/dx; + p1->w+=(((float)clip_rect->lu.x)-p1->x)*dw/dx; + p1->x=clip_rect->lu.x; + } else if (rel_pos1 & RIGHT_OF) { + p1->y+=(((float)clip_rect->rl.x)-p1->x)*dy/dx; + p1->w+=(((float)clip_rect->rl.x)-p1->x)*dw/dx; + p1->x=clip_rect->rl.x; + } else if (rel_pos1 & ABOVE) { + p1->x+=(((float)clip_rect->lu.y)-p1->y)*dx/dy; + p1->w+=(((float)clip_rect->lu.y)-p1->y)*dw/dy; + p1->y=clip_rect->lu.y; + } else if (rel_pos1 & BELOW) { + p1->x+=(((float)clip_rect->rl.y)-p1->y)*dx/dy; + p1->w+=(((float)clip_rect->rl.y)-p1->y)*dw/dy; + p1->y=clip_rect->rl.y; } - code1=clipcode(p1, r); - if (code1 & code2) - return 0; - if (code2 & 1) { - p2->y+=(((float)r->lu.x)-p2->x)*dy/dx; - p2->w+=(((float)r->lu.x)-p2->x)*dw/dx; - p2->x=r->lu.x; - } else if (code2 & 2) { - p2->y+=(((float)r->rl.x)-p2->x)*dy/dx; - p2->w+=(((float)r->rl.x)-p2->x)*dw/dx; - p2->x=r->rl.x; - } else if (code2 & 4) { - p2->x+=(((float)r->lu.y)-p2->y)*dx/dy; - p2->w+=(((float)r->lu.y)-p2->y)*dw/dy; - p2->y=r->lu.y; - } else if (code2 & 8) { - p2->x+=(((float)r->rl.y)-p2->y)*dx/dy; - p2->w+=(((float)r->rl.y)-p2->y)*dw/dy; - p2->y=r->rl.y; + rel_pos1=relative_pos(p1, clip_rect); + if (rel_pos1 & rel_pos2) + return CLIPRES_INVISIBLE; + if (rel_pos2 & LEFT_OF) { + p2->y+=(((float)clip_rect->lu.x)-p2->x)*dy/dx; + p2->w+=(((float)clip_rect->lu.x)-p2->x)*dw/dx; + p2->x=clip_rect->lu.x; + } else if (rel_pos2 & RIGHT_OF) { + p2->y+=(((float)clip_rect->rl.x)-p2->x)*dy/dx; + p2->w+=(((float)clip_rect->rl.x)-p2->x)*dw/dx; + p2->x=clip_rect->rl.x; + } else if (rel_pos2 & ABOVE) { + p2->x+=(((float)clip_rect->lu.y)-p2->y)*dx/dy; + p2->w+=(((float)clip_rect->lu.y)-p2->y)*dw/dy; + p2->y=clip_rect->lu.y; + } else if (rel_pos2 & BELOW) { + p2->x+=(((float)clip_rect->rl.y)-p2->y)*dx/dy; + p2->w+=(((float)clip_rect->rl.y)-p2->y)*dw/dy; + p2->y=clip_rect->rl.y; } - code2=clipcode(p2, r); + rel_pos2=relative_pos(p2, clip_rect); } return ret; } @@ -1605,10 +1620,11 @@ static void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int step, int poly) { - struct point *p=g_alloca(sizeof(struct point)*(count+1)); + struct point *points_to_draw=g_alloca(sizeof(struct point)*(count+1)); int *w=g_alloca(sizeof(int)*(count*step+1)); - struct wpoint p1,p2; - int i,code,out=0; + struct wpoint segment_start,segment_end; + int i,points_to_draw_cnt=0; + int clip_result; int wmax; struct point_rect r=gra->r; @@ -1625,35 +1641,37 @@ r.lu.y-=wmax; r.rl.x+=wmax; r.rl.y+=wmax; + // Iterate over line segments, push them into points_to_draw + // until we reach a completely invisible segment... for (i = 0 ; i < count ; i++) { if (i) { - p1.x=pa[i-1].x; - p1.y=pa[i-1].y; - p1.w=width[(i-1)*step]; - p2.x=pa[i].x; - p2.y=pa[i].y; - p2.w=width[i*step]; - /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */ - code=clip_line(&p1, &p2, &r); - if (((code == 1 || code == 5) && i == 1) || (code & 2)) { - p[out].x=p1.x; - p[out].y=p1.y; - w[out*step]=p1.w; - out++; + segment_start.x=pa[i-1].x; + segment_start.y=pa[i-1].y; + segment_start.w=width[(i-1)*step]; + segment_end.x=pa[i].x; + segment_end.y=pa[i].y; + segment_end.w=width[i*step]; + clip_result=clip_line(&segment_start, &segment_end, &r); + if (clip_result != CLIPRES_INVISIBLE) { + if ((i == 1) || (clip_result & CLIPRES_START_CLIPPED)) { + points_to_draw[points_to_draw_cnt].x=segment_start.x; + points_to_draw[points_to_draw_cnt].y=segment_start.y; + w[points_to_draw_cnt*step]=segment_start.w; + points_to_draw_cnt++; + } + points_to_draw[points_to_draw_cnt].x=segment_end.x; + points_to_draw[points_to_draw_cnt].y=segment_end.y; + w[points_to_draw_cnt*step]=segment_end.w; + points_to_draw_cnt++; } - if (code) { - p[out].x=p2.x; - p[out].y=p2.y; - w[out*step]=p2.w; - out++; - } - if (i == count-1 || (code & 4)) { - if (out > 1) { + if ((i == count-1) || (clip_result & CLIPRES_END_CLIPPED)) { + // ... then draw the resulting polyline + if (points_to_draw_cnt > 1) { if (poly) { - graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step); + graphics_draw_polyline_as_polygon(gra, gc, points_to_draw, points_to_draw_cnt, w, step); } else - gra->meth.draw_lines(gra->priv, gc->priv, p, out); - out=0; + gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt); + points_to_draw_cnt=0; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-01-20 18:17:15
|
Revision: 5346 http://navit.svn.sourceforge.net/navit/?rev=5346&view=rev Author: sleske Date: 2013-01-20 18:17:09 +0000 (Sun, 20 Jan 2013) Log Message: ----------- Fix:core:Refactoring|Extract method clip_line_endoint_to_rect_edge. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-01-20 18:16:49 UTC (rev 5345) +++ trunk/navit/navit/graphics.c 2013-01-20 18:17:09 UTC (rev 5346) @@ -1547,6 +1547,31 @@ return relative_pos; } +static void +clip_line_endoint_to_rect_edge(struct wpoint *p, int rel_pos, int dx, int dy, int dw, struct point_rect *clip_rect) +{ + // We must cast to float to avoid integer + // overflow (i.e. undefined behaviour) at high + // zoom levels. + if (rel_pos & LEFT_OF) { + p->y+=(((float)clip_rect->lu.x)-p->x)*dy/dx; + p->w+=(((float)clip_rect->lu.x)-p->x)*dw/dx; + p->x=clip_rect->lu.x; + } else if (rel_pos & RIGHT_OF) { + p->y+=(((float)clip_rect->rl.x)-p->x)*dy/dx; + p->w+=(((float)clip_rect->rl.x)-p->x)*dw/dx; + p->x=clip_rect->rl.x; + } else if (rel_pos & ABOVE) { + p->x+=(((float)clip_rect->lu.y)-p->y)*dx/dy; + p->w+=(((float)clip_rect->lu.y)-p->y)*dw/dy; + p->y=clip_rect->lu.y; + } else if (rel_pos & BELOW) { + p->x+=(((float)clip_rect->rl.y)-p->y)*dx/dy; + p->w+=(((float)clip_rect->rl.y)-p->y)*dw/dy; + p->y=clip_rect->rl.y; + } +} + enum clip_result { CLIPRES_INVISIBLE = 0, CLIPRES_VISIBLE = 1, @@ -1572,46 +1597,11 @@ while ((rel_pos1!=INSIDE) || (rel_pos2!=INSIDE)) { if (rel_pos1 & rel_pos2) return CLIPRES_INVISIBLE; - if (rel_pos1 & LEFT_OF) { - // We must cast to float to avoid integer - // overflow (i.e. undefined behaviour) at high - // zoom levels. - p1->y+=(((float)clip_rect->lu.x)-p1->x)*dy/dx; - p1->w+=(((float)clip_rect->lu.x)-p1->x)*dw/dx; - p1->x=clip_rect->lu.x; - } else if (rel_pos1 & RIGHT_OF) { - p1->y+=(((float)clip_rect->rl.x)-p1->x)*dy/dx; - p1->w+=(((float)clip_rect->rl.x)-p1->x)*dw/dx; - p1->x=clip_rect->rl.x; - } else if (rel_pos1 & ABOVE) { - p1->x+=(((float)clip_rect->lu.y)-p1->y)*dx/dy; - p1->w+=(((float)clip_rect->lu.y)-p1->y)*dw/dy; - p1->y=clip_rect->lu.y; - } else if (rel_pos1 & BELOW) { - p1->x+=(((float)clip_rect->rl.y)-p1->y)*dx/dy; - p1->w+=(((float)clip_rect->rl.y)-p1->y)*dw/dy; - p1->y=clip_rect->rl.y; - } + clip_line_endoint_to_rect_edge(p1, rel_pos1, dx, dy, dw, clip_rect); rel_pos1=relative_pos(p1, clip_rect); if (rel_pos1 & rel_pos2) return CLIPRES_INVISIBLE; - if (rel_pos2 & LEFT_OF) { - p2->y+=(((float)clip_rect->lu.x)-p2->x)*dy/dx; - p2->w+=(((float)clip_rect->lu.x)-p2->x)*dw/dx; - p2->x=clip_rect->lu.x; - } else if (rel_pos2 & RIGHT_OF) { - p2->y+=(((float)clip_rect->rl.x)-p2->x)*dy/dx; - p2->w+=(((float)clip_rect->rl.x)-p2->x)*dw/dx; - p2->x=clip_rect->rl.x; - } else if (rel_pos2 & ABOVE) { - p2->x+=(((float)clip_rect->lu.y)-p2->y)*dx/dy; - p2->w+=(((float)clip_rect->lu.y)-p2->y)*dw/dy; - p2->y=clip_rect->lu.y; - } else if (rel_pos2 & BELOW) { - p2->x+=(((float)clip_rect->rl.y)-p2->y)*dx/dy; - p2->w+=(((float)clip_rect->rl.y)-p2->y)*dw/dy; - p2->y=clip_rect->rl.y; - } + clip_line_endoint_to_rect_edge(p2, rel_pos2, dx, dy, dw, clip_rect); rel_pos2=relative_pos(p2, clip_rect); } return ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-03-10 20:13:55
|
Revision: 5405 http://navit.svn.sourceforge.net/navit/?rev=5405&view=rev Author: sleske Date: 2013-03-10 20:13:49 +0000 (Sun, 10 Mar 2013) Log Message: ----------- Fix:internal:Refactoring: Remove parameter step from graphics_draw_polyline_* , it's always =1 Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-03-10 07:57:20 UTC (rev 5404) +++ trunk/navit/navit/graphics.c 2013-03-10 20:13:49 UTC (rev 5405) @@ -1407,7 +1407,7 @@ } static void -graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width, int step) +graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width) { int maxpoints=200; struct point *res=g_alloca(sizeof(struct point)*maxpoints); @@ -1422,7 +1422,7 @@ i=0; for (;;) { wi=*width; - width+=step; + width++; if (i < count - 1) { int dxs,dys,lscales; @@ -1508,11 +1508,8 @@ i++; if (i >= count) break; - if (step) { - wi=*width; - calc_offsets(wi*lscale, l, dx, dy, &oo); - } else - oo=o; + wi=*width; + calc_offsets(wi*lscale, l, dx, dy, &oo); dxo = -dx; dyo = -dy; fowo=fow; @@ -1608,10 +1605,10 @@ } static void -graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int step, int poly) +graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int poly) { struct point *points_to_draw=g_alloca(sizeof(struct point)*(count+1)); - int *w=g_alloca(sizeof(int)*(count*step+1)); + int *w=g_alloca(sizeof(int)*(count+1)); struct wpoint segment_start,segment_end; int i,points_to_draw_cnt=0; int clip_result; @@ -1619,11 +1616,9 @@ struct point_rect r=gra->r; wmax=width[0]; - if (step) { - for (i = 1 ; i < count ; i++) { - if (width[i*step] > wmax) - wmax=width[i*step]; - } + for (i = 1 ; i < count ; i++) { + if (width[i] > wmax) + wmax=width[i]; } if (wmax <= 0) return; @@ -1637,28 +1632,28 @@ if (i) { segment_start.x=pa[i-1].x; segment_start.y=pa[i-1].y; - segment_start.w=width[(i-1)*step]; + segment_start.w=width[(i-1)]; segment_end.x=pa[i].x; segment_end.y=pa[i].y; - segment_end.w=width[i*step]; + segment_end.w=width[i]; clip_result=clip_line(&segment_start, &segment_end, &r); if (clip_result != CLIPRES_INVISIBLE) { if ((i == 1) || (clip_result & CLIPRES_START_CLIPPED)) { points_to_draw[points_to_draw_cnt].x=segment_start.x; points_to_draw[points_to_draw_cnt].y=segment_start.y; - w[points_to_draw_cnt*step]=segment_start.w; + w[points_to_draw_cnt]=segment_start.w; points_to_draw_cnt++; } points_to_draw[points_to_draw_cnt].x=segment_end.x; points_to_draw[points_to_draw_cnt].y=segment_end.y; - w[points_to_draw_cnt*step]=segment_end.w; + w[points_to_draw_cnt]=segment_end.w; points_to_draw_cnt++; } if ((i == count-1) || (clip_result & CLIPRES_END_CLIPPED)) { // ... then draw the resulting polyline if (points_to_draw_cnt > 1) { if (poly) { - graphics_draw_polyline_as_polygon(gra, gc, points_to_draw, points_to_draw_cnt, w, step); + graphics_draw_polyline_as_polygon(gra, gc, points_to_draw, points_to_draw_cnt, w); } else gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt); points_to_draw_cnt=0; @@ -1909,7 +1904,7 @@ if (width[i] < 2) width[i]=2; } - graphics_draw_polyline_clipped(gra, gc, pa, count, width, 1, e->u.polyline.width > 1); + graphics_draw_polyline_clipped(gra, gc, pa, count, width, e->u.polyline.width > 1); } break; case element_circle: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-03-18 22:19:00
|
Revision: 5417 http://navit.svn.sourceforge.net/navit/?rev=5417&view=rev Author: sleske Date: 2013-03-18 22:18:53 +0000 (Mon, 18 Mar 2013) Log Message: ----------- Fix:core:Do not use max. linewidth for clipping rectangle, as linewidth may itself need clipping.|May fix #1062. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-03-17 20:25:39 UTC (rev 5416) +++ trunk/navit/navit/graphics.c 2013-03-18 22:18:53 UTC (rev 5417) @@ -1612,20 +1612,22 @@ struct wpoint segment_start,segment_end; int i,points_to_draw_cnt=0; int clip_result; - int wmax; + int r_width, r_height; struct point_rect r=gra->r; - wmax=width[0]; - for (i = 1 ; i < count ; i++) { - if (width[i] > wmax) - wmax=width[i]; - } - if (wmax <= 0) - return; - r.lu.x-=wmax; - r.lu.y-=wmax; - r.rl.x+=wmax; - r.rl.y+=wmax; + r_width=r.rl.x-r.lu.x; + r_height=r.rl.y-r.lu.y; + + // Expand clipping rect by 1/3 so wide, slanted lines do not + // partially end before screen border. + // Ideally we would expand by the line width here, but in 3D + // mode the width is variable and needs clipping itself, so that + // would get complicated. Anyway, 1/3 of screen size should be + // enough... + r.lu.x-=r_width/3; + r.lu.y-=r_height/3; + r.rl.x+=r_width/3; + r.rl.y+=r_height/3; // Iterate over line segments, push them into points_to_draw // until we reach a completely invisible segment... for (i = 0 ; i < count ; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-03-18 22:19:21
|
Revision: 5418 http://navit.svn.sourceforge.net/navit/?rev=5418&view=rev Author: sleske Date: 2013-03-18 22:19:15 +0000 (Mon, 18 Mar 2013) Log Message: ----------- Fix:core:Fix signed int overflow in polygon clipping, to fix rendering errors in high zoom levels.|May be related to #1062. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-03-18 22:18:53 UTC (rev 5417) +++ trunk/navit/navit/graphics.c 2013-03-18 22:19:15 UTC (rev 5418) @@ -1689,19 +1689,19 @@ int dy=p2->y-p1->y; switch(edge) { case 0: - ret->y=p1->y+(r->lu.x-p1->x)*dy/dx; + ret->y=p1->y+((float)r->lu.x-p1->x)*dy/dx; ret->x=r->lu.x; break; case 1: - ret->y=p1->y+(r->rl.x-p1->x)*dy/dx; + ret->y=p1->y+((float)r->rl.x-p1->x)*dy/dx; ret->x=r->rl.x; break; case 2: - ret->x=p1->x+(r->lu.y-p1->y)*dx/dy; + ret->x=p1->x+((float)r->lu.y-p1->y)*dx/dy; ret->y=r->lu.y; break; case 3: - ret->x=p1->x+(r->rl.y-p1->y)*dx/dy; + ret->x=p1->x+((float)r->rl.y-p1->y)*dx/dy; ret->y=r->rl.y; break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2013-05-31 20:08:50
|
Revision: 5521 http://navit.svn.sourceforge.net/navit/?rev=5521&view=rev Author: martin-s Date: 2013-05-31 20:08:43 +0000 (Fri, 31 May 2013) Log Message: ----------- Add:Core:Disallow buffer: as icon name Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-05-30 22:07:32 UTC (rev 5520) +++ trunk/navit/navit/graphics.c 2013-05-31 20:08:43 UTC (rev 5521) @@ -726,7 +726,8 @@ this_->width=newwidth; this_->height=newheight; dbg(2,"Trying to load image '%s' for '%s' at %dx%d\n", new_name, path, newwidth, newheight); - this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate); + if (strcmp(new_name,"buffer:")) + this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate); if (this_->priv) { dbg(1,"Using image '%s' for '%s' at %dx%d\n", new_name, path, newwidth, newheight); g_free(new_name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2013-05-31 20:09:35
|
Revision: 5522 http://navit.svn.sourceforge.net/navit/?rev=5522&view=rev Author: martin-s Date: 2013-05-31 20:09:28 +0000 (Fri, 31 May 2013) Log Message: ----------- Fix:Core:Actually use xpm icons Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-05-31 20:08:43 UTC (rev 5521) +++ trunk/navit/navit/graphics.c 2013-05-31 20:09:28 UTC (rev 5522) @@ -688,7 +688,7 @@ newheight=h; name=g_strndup(path,s-path); - for (i = 1 ; i < 6 ; i++) { + for (i = 1 ; i <= 6 ; i++) { new_name=NULL; switch (i) { case 1: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2013-08-04 15:45:02
|
Revision: 5560 http://sourceforge.net/p/navit/code/5560 Author: martin-s Date: 2013-08-04 15:44:59 +0000 (Sun, 04 Aug 2013) Log Message: ----------- Add:Core:Improved line to polygon conversion for more quality and speed Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-08-03 23:43:43 UTC (rev 5559) +++ trunk/navit/navit/graphics.c 2013-08-04 15:44:59 UTC (rev 5560) @@ -1186,9 +1186,11 @@ struct point * res) { int n, a, b; + dbg(1,"%d,%d - %d,%d x %d,%d-%d,%d\n",a1->x,a1->y,a1->x+adx,a1->y+ady,b1->x,b1->y,b1->x+bdx,b1->y+bdy); n = bdy * adx - bdx * ady; a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x); b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x); + dbg(1,"a %d b %d n %d\n",a,b,n); if (n < 0) { n = -n; a = -a; @@ -1204,6 +1206,7 @@ return 0; res->x = a1->x + a * adx / n; res->y = a1->y + a * ady / n; + dbg(1,"%d,%d\n",res->x,res->y); return 1; } @@ -1404,141 +1407,217 @@ return p; } -struct offset { - int px,py,nx,ny; +#if 0 +static void +debug_line(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int dx, int dy) +{ + struct point p[2]; + p[0]=p[1]=*pnt; + p[1].x+=dx; + p[1].y+=dy; + gra->meth.draw_lines(gra->priv, gc->priv, p, 2); +} + +static void +debug_point(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int s) +{ + struct point p[4]; + p[0]=p[1]=p[2]=*pnt; + p[0].x-=s; + p[0].y+=s; + p[1].x+=s; + p[1].y+=s; + p[2].y-=s; + p[3]=p[0]; + gra->meth.draw_lines(gra->priv, gc->priv, p, 4); +} +#endif + +struct draw_polyline_shape { + int wi; + int step; + int fow; + int dx,dy; + int dxw,dyw; + int l,lscale; }; +struct draw_polyline_context { + int prec; + int ppos,npos; + struct point *res; + struct draw_polyline_shape shape; + struct draw_polyline_shape prev_shape; +}; static void -calc_offsets(int wi, int l, int dx, int dy, struct offset *res) +draw_shape_update(struct draw_polyline_shape *shape) { - int x,y; + shape->dxw = -(shape->dx * shape->wi * shape->lscale) / shape->l; + shape->dyw = (shape->dy * shape->wi * shape->lscale) / shape->l; +} - x = (dx * wi) / l; - y = (dy * wi) / l; - if (x < 0) { - res->nx = -x/2; - res->px = (x-1)/2; +static void +draw_shape(struct draw_polyline_context *ctx, struct point *pnt, int wi) +{ + int dxs,dys,lscales; + int lscale=16; + int l; + struct draw_polyline_shape *shape=&ctx->shape; + struct draw_polyline_shape *prev=&ctx->prev_shape; + + *prev=*shape; + if (prev->wi != wi && prev->l) { + prev->wi=wi; + draw_shape_update(prev); + } + shape->wi=wi; + shape->dx = (pnt[1].x - pnt[0].x); + shape->dy = (pnt[1].y - pnt[0].y); + if (wi > 16) + shape->step=4; + else if (wi > 8) + shape->step=8; + else + shape->step=16; +#if 0 + l = int_sqrt(dx * dx * lscale * lscale + dy * dy * lscale * lscale); +#else + dxs=shape->dx*shape->dx; + dys=shape->dy*shape->dy; + lscales=lscale*lscale; + if (dxs + dys > lscales) + l = int_sqrt(dxs+dys)*lscale; + else + l = int_sqrt((dxs+dys)*lscales); +#endif + shape->fow=fowler(-shape->dy, shape->dx); + dbg(1,"fow=%d\n",shape->fow); + if (! l) + l=1; + if (wi*lscale > 10000) + lscale=10000/wi; + dbg_assert(wi*lscale <= 10000); + shape->l=l; + shape->lscale=lscale; + shape->wi=wi; + draw_shape_update(shape); +} + +static void +draw_point(struct draw_polyline_shape *shape, struct point *src, struct point *dst, int pos) +{ + if (pos) { + dst->x=(src->x*2-shape->dyw)/2; + dst->y=(src->y*2-shape->dxw)/2; } else { - res->nx = -(x+1)/2; - res->px = x/2; + dst->x=(src->x*2+shape->dyw)/2; + dst->y=(src->y*2+shape->dxw)/2; } - if (y < 0) { - res->ny = -y/2; - res->py = (y-1)/2; +} + +static void +draw_begin(struct draw_polyline_context *ctx, struct point *p) +{ + struct draw_polyline_shape *shape=&ctx->shape; + int i; + for (i = 0 ; i <= 32 ; i+=shape->step) { + ctx->res[ctx->ppos].x=(p->x*256+(shape->dyw*circle64[i].y)+(shape->dxw*circle64[i].x))/256; + ctx->res[ctx->ppos].y=(p->y*256+(shape->dxw*circle64[i].y)-(shape->dyw*circle64[i].x))/256; + ctx->ppos++; + } +} + +static int +draw_middle(struct draw_polyline_context *ctx, struct point *p) +{ + int delta=ctx->prev_shape.fow-ctx->shape.fow; + if (delta > 512) + delta-=1024; + if (delta < -512) + delta+=1024; + if (delta < 16 && delta > -16) { + draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0); + draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1); + return 1; + } + dbg(1,"delta %d\n",delta); + if (delta > 0) { + struct point pos,poso; + draw_point(&ctx->shape, p, &pos, 1); + draw_point(&ctx->prev_shape, p, &poso, 1); + if (delta >= 256) + return 0; + if (intersection(&pos, ctx->shape.dx, ctx->shape.dy, &poso, ctx->prev_shape.dx, ctx->prev_shape.dy, &ctx->res[ctx->ppos])) { + ctx->ppos++; + draw_point(&ctx->prev_shape, p, &ctx->res[ctx->npos--], 0); + draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0); + return 1; + } } else { - res->ny = -(y+1)/2; - res->py = y/2; + struct point neg,nego; + draw_point(&ctx->shape, p, &neg, 0); + draw_point(&ctx->prev_shape, p, &nego, 0); + if (delta <= -256) + return 0; + if (intersection(&neg, ctx->shape.dx, ctx->shape.dy, &nego, ctx->prev_shape.dx, ctx->prev_shape.dy, &ctx->res[ctx->npos])) { + ctx->npos--; + draw_point(&ctx->prev_shape, p, &ctx->res[ctx->ppos++], 1); + draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1); + return 1; + } } + return 0; } static void -graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width) +draw_end(struct draw_polyline_context *ctx, struct point *p) { + int i; + struct draw_polyline_shape *shape=&ctx->prev_shape; + for (i = 0 ; i <= 32 ; i+=shape->step) { + ctx->res[ctx->npos].x=(p->x*256+(shape->dyw*circle64[i].y)-(shape->dxw*circle64[i].x))/256; + ctx->res[ctx->npos].y=(p->y*256+(shape->dxw*circle64[i].y)+(shape->dyw*circle64[i].x))/256; + ctx->npos--; + } +} + +static void +draw_init_ctx(struct draw_polyline_context *ctx, int maxpoints) +{ + ctx->prec=1; + ctx->ppos=maxpoints/2; + ctx->npos=maxpoints/2-1; +} + + +static void +graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, struct graphics_gc_priv *gc_priv, struct point *pnt, int count, int *width, void (*draw)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)) +{ int maxpoints=200; - struct point *res=g_alloca(sizeof(struct point)*maxpoints); - struct point pos, poso, neg, nego; - int i, dx=0, dy=0, l=0, dxo=0, dyo=0; - struct offset o,oo={0,0,0,0}; - int fow=0, fowo=0, delta; - int wi, ppos = maxpoints/2, npos = maxpoints/2; - int state,prec=5; + struct draw_polyline_context ctx; + int i=0; int max_circle_points=20; - int lscale=16; + ctx.shape.l=0; + ctx.res=g_alloca(sizeof(struct point)*maxpoints); i=0; - for (;;) { - wi=*width; - width++; - if (i < count - 1) { - int dxs,dys,lscales; - - dx = (pnt[i + 1].x - pnt[i].x); - dy = (pnt[i + 1].y - pnt[i].y); -#if 0 - l = int_sqrt(dx * dx * lscale * lscale + dy * dy * lscale * lscale); -#else - dxs=dx*dx; - dys=dy*dy; - lscales=lscale*lscale; - if (dxs + dys > lscales) - l = int_sqrt(dxs+dys)*lscale; - else - l = int_sqrt((dxs+dys)*lscales); -#endif - fow=fowler(-dy, dx); + draw_init_ctx(&ctx, maxpoints); + draw_shape(&ctx, pnt, *width++); + draw_begin(&ctx,&pnt[0]); + for (i = 1 ; i < count -1 ; i++) { + draw_shape(&ctx, pnt+i, *width++); + if (ctx.npos < max_circle_points || ctx.ppos >= maxpoints-max_circle_points || !draw_middle(&ctx,&pnt[i])) { + struct draw_polyline_shape shape=ctx.shape; + draw_end(&ctx,&pnt[i]); + ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; + draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos); + draw_init_ctx(&ctx, maxpoints); + draw_begin(&ctx,&pnt[i]); } - if (! l) - l=1; - if (wi*lscale > 10000) - lscale=10000/wi; - dbg_assert(wi*lscale <= 10000); - calc_offsets(wi*lscale, l, dx, dy, &o); - pos.x = pnt[i].x + o.ny; - pos.y = pnt[i].y + o.px; - neg.x = pnt[i].x + o.py; - neg.y = pnt[i].y + o.nx; - if (! i) - state=0; - else if (i == count-1) - state=2; - else if (npos < max_circle_points || ppos >= maxpoints-max_circle_points) - state=3; - else - state=1; - switch (state) { - case 1: - if (fowo != fow) { - poso.x = pnt[i].x + oo.ny; - poso.y = pnt[i].y + oo.px; - nego.x = pnt[i].x + oo.py; - nego.y = pnt[i].y + oo.nx; - delta=fowo-fow; - if (delta < 0) - delta+=1024; - if (delta < 512) { - if (intersection(&pos, dx, dy, &poso, dxo, dyo, &res[ppos])) - ppos++; - res[--npos] = nego; - --npos; - draw_circle(&pnt[i], wi, prec, fowo-512, -delta, res, &npos, -1); - res[npos] = neg; - } else { - res[ppos++] = poso; - draw_circle(&pnt[i], wi, prec, fowo, 1024-delta, res, &ppos, 1); - res[ppos++] = pos; - if (intersection(&neg, dx, dy, &nego, dxo, dyo, &res[npos - 1])) - npos--; - } - } - break; - case 2: - case 3: - res[--npos] = neg; - --npos; - draw_circle(&pnt[i], wi, prec, fow-512, -512, res, &npos, -1); - res[npos] = pos; - res[ppos++] = pos; - dbg_assert(npos > 0); - dbg_assert(ppos < maxpoints); - gra->meth.draw_polygon(gra->priv, gc->priv, res+npos, ppos-npos); - if (state == 2) - break; - npos=maxpoints/2; - ppos=maxpoints/2; - case 0: - res[ppos++] = neg; - draw_circle(&pnt[i], wi, prec, fow+512, 512, res, &ppos, 1); - res[ppos++] = pos; - break; - } - i++; - if (i >= count) - break; - wi=*width; - calc_offsets(wi*lscale, l, dx, dy, &oo); - dxo = -dx; - dyo = -dy; - fowo=fow; } + draw_shape(&ctx, pnt+count-1, *width++); + draw_end(&ctx,&pnt[count-1]); + ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; + draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos); } @@ -1682,7 +1761,10 @@ // ... then draw the resulting polyline if (points_to_draw_cnt > 1) { if (poly) { - graphics_draw_polyline_as_polygon(gra, gc, points_to_draw, points_to_draw_cnt, w); + graphics_draw_polyline_as_polygon(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt, w, gra->meth.draw_polygon); +#if 0 + gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt); +#endif } else gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt); points_to_draw_cnt=0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sl...@us...> - 2013-08-11 22:39:57
|
Revision: 5575 http://sourceforge.net/p/navit/code/5575 Author: sleske Date: 2013-08-11 22:39:54 +0000 (Sun, 11 Aug 2013) Log Message: ----------- Fix:core:Fix buffer overflow in drawing code. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-08-11 20:26:52 UTC (rev 5574) +++ trunk/navit/navit/graphics.c 2013-08-11 22:39:54 UTC (rev 5575) @@ -1613,7 +1613,7 @@ draw_begin(&ctx,&pnt[i]); } } - draw_shape(&ctx, pnt+count-1, *width++); + ctx.prev_shape=ctx.shape; draw_end(&ctx,&pnt[count-1]); ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2013-08-24 07:12:18
|
Revision: 5595 http://sourceforge.net/p/navit/code/5595 Author: martin-s Date: 2013-08-24 07:12:16 +0000 (Sat, 24 Aug 2013) Log Message: ----------- Fix:Core:Draw line endpoints in correct width Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2013-08-24 07:10:58 UTC (rev 5594) +++ trunk/navit/navit/graphics.c 2013-08-24 07:12:16 UTC (rev 5595) @@ -1465,6 +1465,10 @@ struct draw_polyline_shape *shape=&ctx->shape; struct draw_polyline_shape *prev=&ctx->prev_shape; +#if 0 + dbg(0,"enter %d,%d - %d,%d %d\n",pnt[0].x,pnt[0].y,pnt[1].x,pnt[1].y,wi); +#endif + *prev=*shape; if (prev->wi != wi && prev->l) { prev->wi=wi; @@ -1597,6 +1601,13 @@ struct draw_polyline_context ctx; int i=0; int max_circle_points=20; + if (count < 2) + return; +#if 0 + dbg(0,"count=%d\n",count); + for (i = 0 ; i < count ; i++) + dbg(0,"%d,%d width %d\n",pnt[i].x,pnt[i].y,width[i]); +#endif ctx.shape.l=0; ctx.res=g_alloca(sizeof(struct point)*maxpoints); i=0; @@ -1613,6 +1624,7 @@ draw_begin(&ctx,&pnt[i]); } } + draw_shape(&ctx, &pnt[count-2], *width++); ctx.prev_shape=ctx.shape; draw_end(&ctx,&pnt[count-1]); ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; @@ -1978,6 +1990,7 @@ struct element *e=dc->e; struct graphics_image *img=dc->img; struct point p; + struct coord *c; char *path; while (di) { @@ -1994,10 +2007,23 @@ count=limit_count(di->c, count); if (dc->type == type_poly_water_tiled) mindist=0; + c=di->c; +#if 0 + if (dc->e->type == element_polygon) { + int max=1000; + int offset=5600; + c+=offset; + count-=offset; + if (count < 0) + count=0; + if (count > max) + count=max; + } +#endif if (dc->e->type == element_polyline) - count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width); + count=transform(dc->trans, dc->pro, c, pa, count, mindist, e->u.polyline.width, width); else - count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL); + count=transform(dc->trans, dc->pro, c, pa, count, mindist, 0, NULL); switch (e->type) { case element_polygon: graphics_draw_polygon_clipped(gra, gc, pa, count); @@ -2373,6 +2399,9 @@ count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel); if (! count) continue; +#if 0 + dbg(0,"%s 0x%x 0x%x\n",item_to_name(item->type), item->id_hi, item->id_lo); +#endif if (displaylist->dc.pro != pro) transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count); if (count == max) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2015-01-07 13:24:27
|
Revision: 5990 http://sourceforge.net/p/navit/code/5990 Author: mdankov Date: 2015-01-07 13:24:24 +0000 (Wed, 07 Jan 2015) Log Message: ----------- Add:core:Better algorithm to choose prescaled png to rescale it to needed size. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2015-01-03 11:48:22 UTC (rev 5989) +++ trunk/navit/navit/graphics.c 2015-01-07 13:24:24 UTC (rev 5990) @@ -611,36 +611,82 @@ static void image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path, char *name, int width, int height, int rotate, int zip) { - int i; - for (i = 1 ; i <= 6 ; i++) { + int i=0; + int stdsizes[]={8,12,16,22,24,32,36,48,64,72,96,128,192,256}; + const int numstdsizes=sizeof(stdsizes)/sizeof(int); + int sz; + int mode=1; + int bmstd=0; + sz=width>0?width:height; + while (mode<=8) { char *new_name=NULL; - switch (i) { + int n; + switch (mode) { case 1: /* The best variant both for cpu usage and quality would be prescaled png of a needed size */ + mode++; if (width != -1 && height != -1) { new_name=g_strdup_printf("%s_%d_%d.png", name, width, height); } break; case 2: + mode++; /* Try to load image by the exact name given by user. For example, if she wants to scale some prescaled png variant to a new size given as function params, or have default png image to be displayed unscaled. */ new_name=g_strdup(path); break; case 3: + mode++; /* Next, try uncompressed and compressed svgs as they should give best quality but rendering might take more cpu resources when the image is displayed for the first time */ new_name=g_strdup_printf("%s.svg", name); break; case 4: + mode++; new_name=g_strdup_printf("%s.svgz", name); break; case 5: - /* Scaling the default png to the needed size may give some quality loss */ + mode++; + /* If we have no size specifiers, try the default png now */ + if(sz<=0) { + new_name=g_strdup_printf("%s.png", name); + i=0; + break; + } + /* Find best matching size from standard row */ + for(bmstd=0;bmstd<numstdsizes;bmstd++) + if(stdsizes[bmstd]>sz) + break; + i=1; + /* Fall through */ + case 6: + /* Select closest matching image from standard row */ + if(sz>0) { + /* If size were specified, start with bmstd and then try standard sizes in row + * bmstd-1, bmstd+1, bmstd-2, bmstd+2 etc */ + n=bmstd+(i/2)*((i%2)*2-1); + if(++i==numstdsizes*2) + mode++; + } else { + /* If no size were specified, start with the smallest standard size and then try following ones */ + n=i++; + if(i==numstdsizes) + mode+=2; + } + if(n<0||n>=numstdsizes) + break; + new_name=g_strdup_printf("%s_%d_%d.png", name, stdsizes[n],stdsizes[n]); + break; + + case 7: + /* Scaling the default prescaled png of unknown size to the needed size will give random quality loss */ + mode++; new_name=g_strdup_printf("%s.png", name); break; - case 6: + case 8: /* xpm format is used as a last resort, because its not widely supported and we are moving to svg and png formats */ + mode++; new_name=g_strdup_printf("%s.xpm", name); break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2015-01-23 21:25:34
|
Revision: 6004 http://sourceforge.net/p/navit/code/6004 Author: mdankov Date: 2015-01-23 21:25:26 +0000 (Fri, 23 Jan 2015) Log Message: ----------- Fix:core:Better algorithm to select prescaled image to rescale. Try at first to load all bigger ones, then go down in standard sizes row. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2015-01-21 21:14:07 UTC (rev 6003) +++ trunk/navit/navit/graphics.c 2015-01-23 21:25:26 UTC (rev 6004) @@ -651,10 +651,10 @@ break; case 5: mode++; + i=0; /* If we have no size specifiers, try the default png now */ if(sz<=0) { new_name=g_strdup_printf("%s.png", name); - i=0; break; } /* Find best matching size from standard row */ @@ -664,12 +664,15 @@ i=1; /* Fall through */ case 6: - /* Select closest matching image from standard row */ + /* Select best matching image from standard row */ if(sz>0) { /* If size were specified, start with bmstd and then try standard sizes in row - * bmstd-1, bmstd+1, bmstd-2, bmstd+2 etc */ - n=bmstd+(i/2)*((i%2)*2-1); - if(++i==numstdsizes*2) + * bmstd, bmstd+1, bmstd+2, .. numstdsizes-1, bmstd-1, bmstd-2, .., 0 */ + n=bmstd+i; + if((bmstd+i)>=numstdsizes) + n=numstdsizes-i-1; + + if(++i==numstdsizes) mode++; } else { /* If no size were specified, start with the smallest standard size and then try following ones */ @@ -698,7 +701,7 @@ this_->width=width; this_->height=height; - dbg(lvl_info,"Trying to load image '%s' for '%s' at %dx%d\n", new_name, path, width, height); + dbg(lvl_debug,"Trying to load image '%s' for '%s' at %dx%d\n", new_name, path, width, height); if (zip) { unsigned char *start; int len; @@ -714,7 +717,7 @@ this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate); } if (this_->priv) { - dbg(lvl_debug,"Using image '%s' for '%s' at %dx%d\n", new_name, path, width, height); + dbg(lvl_info,"Using image '%s' for '%s' at %dx%d\n", new_name, path, width, height); g_free(new_name); break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2015-07-04 23:27:15
|
Revision: 6125 http://sourceforge.net/p/navit/code/6125 Author: mdankov Date: 2015-07-04 23:27:12 +0000 (Sat, 04 Jul 2015) Log Message: ----------- Add:core:Allow shell variables to be used in image names. Related to #1285. Modified Paths: -------------- trunk/navit/navit/graphics.c Modified: trunk/navit/navit/graphics.c =================================================================== --- trunk/navit/navit/graphics.c 2015-07-01 21:24:19 UTC (rev 6124) +++ trunk/navit/navit/graphics.c 2015-07-04 23:27:12 UTC (rev 6125) @@ -727,6 +727,9 @@ { struct graphics_image *this_; char* hash_key = g_strdup_printf("%s*%d*%d*%d",path,w,h,rotate); + struct file_wordexp *we; + int i; + char **paths; if ( g_hash_table_lookup_extended( gra->image_cache_hash, hash_key, NULL, (gpointer)&this_) ) { g_free(hash_key); @@ -738,15 +741,19 @@ this_->height=h; this_->width=w; - if(!this_->priv) { + we=file_wordexp_new(path); + paths=file_wordexp_get_array(we); + + for(i=0;i<file_wordexp_get_count(we) && !this_->priv;i++) { char *ext; char *s, *name; - int len=strlen(path); + char *pathi=paths[i]; + int len=strlen(pathi); int i,k; int newwidth=-1, newheight=-1; - ext=g_utf8_strrchr(path,-1,'.'); - i=path-ext+len; + ext=g_utf8_strrchr(pathi,-1,'.'); + i=pathi-ext+len; /* Dont allow too long or too short file name extensions*/ if(ext && ((i>5) || (i<1))) @@ -756,10 +763,10 @@ if(ext) s=ext-1; else - s=path+len; + s=pathi+len; k=1; - while(s>path && g_ascii_isdigit(*s)) { + while(s>pathi && g_ascii_isdigit(*s)) { if(newheight<0) newheight=0; newheight+=(*s-'0')*k; @@ -767,10 +774,10 @@ s--; } - if(k>1 && s>path && *s=='_') { + if(k>1 && s>pathi && *s=='_') { k=1; s--; - while(s>path && g_ascii_isdigit(*s)) { + while(s>pathi && g_ascii_isdigit(*s)) { if(newwidth<0) newwidth=0; newwidth+=(*s-'0')*k;; @@ -779,13 +786,13 @@ } } - if(k==1 || s<=path || *s!='_') { + if(k==1 || s<=pathi || *s!='_') { newwidth=-1; newheight=-1; if(ext) s=ext; else - s=path+len; + s=pathi+len; } @@ -795,16 +802,18 @@ if(h!=-1) newheight=h; - name=g_strndup(path,s-path); + name=g_strndup(pathi,s-pathi); #if 0 if (!strstr(name,"test.zip")) #endif - image_new_helper(gra, this_, path, name, newwidth, newheight, rotate, 0); - if (!this_->priv && strstr(path, ".zip/")) - image_new_helper(gra, this_, path, name, newwidth, newheight, rotate, 1); + image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 0); + if (!this_->priv && strstr(pathi, ".zip/")) + image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 1); g_free(name); } + file_wordexp_destroy(we); + if (! this_->priv) { dbg(lvl_error,"No image for '%s'\n", path); g_free(this_); @@ -2132,7 +2141,7 @@ if (img) dc->img=img; else - dbg(lvl_error,"failed to load icon '%s'\n", path); + dbg(lvl_debug,"failed to load icon '%s'\n", path); g_free(path); } if (img) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |