X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fbbox.c;h=1f245676bf0236598497349eaa7c045c288c912b;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hp=226d1bbbab124fd6c47c5827b23157ae22b656d4;hpb=c10fb05b68fa1c717ef7d62d84bfb29008d41c33;p=swftools.git diff --git a/lib/pdf/bbox.c b/lib/pdf/bbox.c index 226d1bb..1f24567 100644 --- a/lib/pdf/bbox.c +++ b/lib/pdf/bbox.c @@ -118,6 +118,7 @@ static void head_delete(context_t*context, head_t*h) assert(!h->prev); context->heads = h->next; } + free(h); } #define POINTS_TO_HEAD(ptr) (((head_t*)(ptr))->magic==HEAD_MAGIC) @@ -264,17 +265,49 @@ static void overlap_bboxes(context_t*context) } while(changed); } +typedef struct _circle_coord { + S16 x,y; +} circle_coord_t; + +static int compare_circle_coord(const void *_v1, const void *_v2) +{ + circle_coord_t*v1=(circle_coord_t*)_v1; + circle_coord_t*v2=(circle_coord_t*)_v2; + return (v1->x*v1->x + v1->y*v1->y) - (v2->x*v2->x + v2->y*v2->y); +} + static head_t* search_vicinity(context_t*context, head_t*h, int max_radius, double*cos, double*sin) { + static circle_coord_t*circle_order = 0; + static int circle_order_size = 0; + + if(!circle_order) { + circle_order_size = (max_radius*(max_radius+1))/2; + circle_order = malloc(sizeof(circle_coord_t)*circle_order_size); + int x,y; + int i = 0; + for(y=0;ygroup; - /* FIXME: this function isn't very efficient. We need a better way to iterate - through all points, sorted by distance, in the neighborhood of a coordinate */ - for(t=3;tx+cos[s]*t/4.0+0.5; - int y=h->y+sin[s]*t/4.0+0.5; + for(s=0;s<4;s++) { + int x=h->x+xx*signx[s]; + int y=h->y+yy*signy[s]; if(x>=0 && y>=0 && xwidth && yheight) { int pos = y*context->width+x; if(data[pos]) { @@ -315,17 +348,26 @@ static void fix_small_boxes(context_t*context) while(h) { head_t*next = h->next; if(!h->seen) { - if(h->bbox.xmax - h->bbox.ymin < 16 - && h->bbox.ymax - h->bbox.ymin < 16) { + if(h->bbox.xmax - h->bbox.xmin < 32 + || h->bbox.ymax - h->bbox.ymin < 32) { head_t*other = search_vicinity(context, h, 64, costab, sintab); if(other) { merge(context, h->pos, other->pos); changed = 1; break; } else { + //printf("nothing in the vicinity of %d,%d,%d,%d\n", h->bbox); h->seen = 1; } - } + } /*else { + printf("area %d,%d,%d,%d is large enough (%dx%d)\n", + h->bbox.xmin, + h->bbox.ymin, + h->bbox.xmax, + h->bbox.ymax, + h->bbox.xmax - h->bbox.xmin, + h->bbox.ymax - h->bbox.ymin); + } */ } h = next; } @@ -377,6 +419,9 @@ ibbox_t*get_bitmap_bboxes(unsigned char*alpha, int width, int height) void**group = annotate(&context); fix_small_boxes(&context); overlap_bboxes(&context); +#ifdef MAIN + display(&context); +#endif ibbox_t*bboxes = 0;