diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-10 01:49:30 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-10 01:49:30 +0200 |
commit | 2e6b26a5541e7f3c4729deddf6b0f4e3eb55bfb8 (patch) | |
tree | 03d50e78428c903573f2b5208aee8e5ec0fba160 | |
parent | d914e3415af1c9c7d8644dfa50fdcf9a79cc01d5 (diff) | |
download | mupdf-2e6b26a5541e7f3c4729deddf6b0f4e3eb55bfb8.tar.xz |
Make global edge list struct opaque, and remove active edge list struct.
-rw-r--r-- | draw/draw_device.c | 13 | ||||
-rw-r--r-- | draw/draw_edge.c | 147 | ||||
-rw-r--r-- | fitz/fitz.h | 34 |
3 files changed, 85 insertions, 109 deletions
diff --git a/draw/draw_device.c b/draw/draw_device.c index ab33dc35..6796de2f 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -12,7 +12,6 @@ struct fz_draw_device_s { fz_glyph_cache *cache; fz_gel *gel; - fz_ael *ael; fz_pixmap *dest; fz_bbox scissor; @@ -59,7 +58,7 @@ fz_draw_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm, colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; - fz_scan_convert(dev->gel, dev->ael, even_odd, bbox, dev->dest, colorbv); + fz_scan_convert(dev->gel, even_odd, bbox, dev->dest, colorbv); } static void @@ -97,7 +96,7 @@ fz_draw_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matri colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; - fz_scan_convert(dev->gel, dev->ael, 0, bbox, dev->dest, colorbv); + fz_scan_convert(dev->gel, 0, bbox, dev->dest, colorbv); } static void @@ -139,7 +138,7 @@ fz_draw_clip_path(void *user, fz_path *path, int even_odd, fz_matrix ctm) fz_clear_pixmap(mask); fz_clear_pixmap(dest); - fz_scan_convert(dev->gel, dev->ael, even_odd, bbox, mask, NULL); + fz_scan_convert(dev->gel, even_odd, bbox, mask, NULL); dev->stack[dev->top].scissor = dev->scissor; dev->stack[dev->top].mask = mask; @@ -186,7 +185,7 @@ fz_draw_clip_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_ fz_clear_pixmap(dest); if (!fz_is_empty_rect(bbox)) - fz_scan_convert(dev->gel, dev->ael, 0, bbox, mask, NULL); + fz_scan_convert(dev->gel, 0, bbox, mask, NULL); dev->stack[dev->top].scissor = dev->scissor; dev->stack[dev->top].mask = mask; @@ -983,8 +982,9 @@ fz_draw_free_user(void *user) { fz_draw_device *dev = user; /* TODO: pop and free the stacks */ + if (dev->top > 0) + fz_warn("items left on stack in draw device: %d", dev->top); fz_free_gel(dev->gel); - fz_free_ael(dev->ael); fz_free(dev); } @@ -995,7 +995,6 @@ fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest) fz_draw_device *ddev = fz_malloc(sizeof(fz_draw_device)); ddev->cache = cache; ddev->gel = fz_new_gel(); - ddev->ael = fz_new_ael(); ddev->dest = dest; ddev->top = 0; diff --git a/draw/draw_edge.c b/draw/draw_edge.c index f0ed23df..c2e7b09e 100644 --- a/draw/draw_edge.c +++ b/draw/draw_edge.c @@ -109,6 +109,26 @@ fz_set_aa_level(int level) * See Mike Abrash -- Graphics Programming Black Book (notably chapter 40) */ +typedef struct fz_edge_s fz_edge; + +struct fz_edge_s +{ + int x, e, h, y; + int adj_up, adj_down; + int xmove; + int xdir, ydir; /* -1 or +1 */ +}; + +struct fz_gel_s +{ + fz_bbox clip; + fz_bbox bbox; + int cap, len; + fz_edge *edges; + int acap, alen; + fz_edge **active; +}; + fz_gel * fz_new_gel(void) { @@ -125,6 +145,10 @@ fz_new_gel(void) gel->bbox.x0 = gel->bbox.y0 = BBOX_MAX; gel->bbox.x1 = gel->bbox.y1 = BBOX_MIN; + gel->acap = 64; + gel->alen = 0; + gel->active = fz_calloc(gel->acap, sizeof(fz_edge*)); + return gel; } @@ -152,6 +176,7 @@ fz_reset_gel(fz_gel *gel, fz_bbox clip) void fz_free_gel(fz_gel *gel) { + fz_free(gel->active); fz_free(gel->edges); fz_free(gel); } @@ -378,26 +403,8 @@ fz_is_rect_gel(fz_gel *gel) * Active Edge List -- keep track of active edges while sweeping */ -fz_ael * -fz_new_ael(void) -{ - fz_ael *ael; - ael = fz_malloc(sizeof(fz_ael)); - ael->cap = 64; - ael->len = 0; - ael->edges = fz_calloc(ael->cap, sizeof(fz_edge*)); - return ael; -} - -void -fz_free_ael(fz_ael *ael) -{ - fz_free(ael->edges); - fz_free(ael); -} - static void -sort_ael(fz_edge **a, int n) +sort_active(fz_edge **a, int n) { int h, i, k; fz_edge *t; @@ -430,38 +437,38 @@ sort_ael(fz_edge **a, int n) } static void -insert_ael(fz_ael *ael, fz_gel *gel, int y, int *e) +insert_active(fz_gel *gel, int y, int *e) { /* insert edges that start here */ while (*e < gel->len && gel->edges[*e].y == y) { - if (ael->len + 1 == ael->cap) { - int newcap = ael->cap + 64; - fz_edge **newedges = fz_realloc(ael->edges, newcap, sizeof(fz_edge*)); - ael->edges = newedges; - ael->cap = newcap; + if (gel->alen + 1 == gel->acap) { + int newcap = gel->acap + 64; + fz_edge **newactive = fz_realloc(gel->active, newcap, sizeof(fz_edge*)); + gel->active = newactive; + gel->acap = newcap; } - ael->edges[ael->len++] = &gel->edges[(*e)++]; + gel->active[gel->alen++] = &gel->edges[(*e)++]; } /* shell-sort the edges by increasing x */ - sort_ael(ael->edges, ael->len); + sort_active(gel->active, gel->alen); } static void -advance_ael(fz_ael *ael) +advance_active(fz_gel *gel) { fz_edge *edge; int i = 0; - while (i < ael->len) + while (i < gel->alen) { - edge = ael->edges[i]; + edge = gel->active[i]; edge->h --; /* terminator! */ if (edge->h == 0) { - ael->edges[i] = ael->edges[--ael->len]; + gel->active[i] = gel->active[--gel->alen]; } else { @@ -512,32 +519,32 @@ static inline void add_span_aa(int *list, int x0, int x1, int xofs) } } -static inline void non_zero_winding_aa(fz_ael *ael, int *list, int xofs) +static inline void non_zero_winding_aa(fz_gel *gel, int *list, int xofs) { int winding = 0; int x = 0; int i; - for (i = 0; i < ael->len; i++) + for (i = 0; i < gel->alen; i++) { - if (!winding && (winding + ael->edges[i]->ydir)) - x = ael->edges[i]->x; - if (winding && !(winding + ael->edges[i]->ydir)) - add_span_aa(list, x, ael->edges[i]->x, xofs); - winding += ael->edges[i]->ydir; + if (!winding && (winding + gel->active[i]->ydir)) + x = gel->active[i]->x; + if (winding && !(winding + gel->active[i]->ydir)) + add_span_aa(list, x, gel->active[i]->x, xofs); + winding += gel->active[i]->ydir; } } -static inline void even_odd_aa(fz_ael *ael, int *list, int xofs) +static inline void even_odd_aa(fz_gel *gel, int *list, int xofs) { int even = 0; int x = 0; int i; - for (i = 0; i < ael->len; i++) + for (i = 0; i < gel->alen; i++) { if (!even) - x = ael->edges[i]->x; + x = gel->active[i]->x; else - add_span_aa(list, x, ael->edges[i]->x, xofs); + add_span_aa(list, x, gel->active[i]->x, xofs); even = !even; } } @@ -564,7 +571,7 @@ static inline void blit_aa(fz_pixmap *dst, int x, int y, } static void -fz_scan_convert_aa(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, +fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip, fz_pixmap *dst, unsigned char *color) { unsigned char *alphas; @@ -595,7 +602,7 @@ fz_scan_convert_aa(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, yc = fz_idiv(y, fz_aa_vscale); yd = yc; - while (ael->len > 0 || e < gel->len) + while (gel->alen > 0 || e < gel->len) { yc = fz_idiv(y, fz_aa_vscale); if (yc != yd) @@ -609,19 +616,19 @@ fz_scan_convert_aa(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, } yd = yc; - insert_ael(ael, gel, y, &e); + insert_active(gel, y, &e); if (yd >= clip.y0 && yd < clip.y1) { if (eofill) - even_odd_aa(ael, deltas, xofs); + even_odd_aa(gel, deltas, xofs); else - non_zero_winding_aa(ael, deltas, xofs); + non_zero_winding_aa(gel, deltas, xofs); } - advance_ael(ael); + advance_active(gel); - if (ael->len > 0) + if (gel->alen > 0) y ++; else if (e < gel->len) y = gel->edges[e].y; @@ -657,60 +664,60 @@ static inline void blit_sharp(int x0, int x1, int y, } } -static inline void non_zero_winding_sharp(fz_ael *ael, int y, +static inline void non_zero_winding_sharp(fz_gel *gel, int y, fz_bbox clip, fz_pixmap *dst, unsigned char *color) { int winding = 0; int x = 0; int i; - for (i = 0; i < ael->len; i++) + for (i = 0; i < gel->alen; i++) { - if (!winding && (winding + ael->edges[i]->ydir)) - x = ael->edges[i]->x; - if (winding && !(winding + ael->edges[i]->ydir)) - blit_sharp(x, ael->edges[i]->x, y, clip, dst, color); - winding += ael->edges[i]->ydir; + if (!winding && (winding + gel->active[i]->ydir)) + x = gel->active[i]->x; + if (winding && !(winding + gel->active[i]->ydir)) + blit_sharp(x, gel->active[i]->x, y, clip, dst, color); + winding += gel->active[i]->ydir; } } -static inline void even_odd_sharp(fz_ael *ael, int y, +static inline void even_odd_sharp(fz_gel *gel, int y, fz_bbox clip, fz_pixmap *dst, unsigned char *color) { int even = 0; int x = 0; int i; - for (i = 0; i < ael->len; i++) + for (i = 0; i < gel->len; i++) { if (!even) - x = ael->edges[i]->x; + x = gel->active[i]->x; else - blit_sharp(x, ael->edges[i]->x, y, clip, dst, color); + blit_sharp(x, gel->active[i]->x, y, clip, dst, color); even = !even; } } static void -fz_scan_convert_sharp(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, +fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip, fz_pixmap *dst, unsigned char *color) { int e = 0; int y = gel->edges[0].y; - while (ael->len > 0 || e < gel->len) + while (gel->alen > 0 || e < gel->len) { - insert_ael(ael, gel, y, &e); + insert_active(gel, y, &e); if (y >= clip.y0 && y < clip.y1) { if (eofill) - even_odd_sharp(ael, y, clip, dst, color); + even_odd_sharp(gel, y, clip, dst, color); else - non_zero_winding_sharp(ael, y, clip, dst, color); + non_zero_winding_sharp(gel, y, clip, dst, color); } - advance_ael(ael); + advance_active(gel); - if (ael->len > 0) + if (gel->alen > 0) y ++; else if (e < gel->len) y = gel->edges[e].y; @@ -718,11 +725,11 @@ fz_scan_convert_sharp(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, } void -fz_scan_convert(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, +fz_scan_convert(fz_gel *gel, int eofill, fz_bbox clip, fz_pixmap *dst, unsigned char *color) { if (fz_aa_level > 0) - fz_scan_convert_aa(gel, ael, eofill, clip, dst, color); + fz_scan_convert_aa(gel, eofill, clip, dst, color); else - fz_scan_convert_sharp(gel, ael, eofill, clip, dst, color); + fz_scan_convert_sharp(gel, eofill, clip, dst, color); } diff --git a/fitz/fitz.h b/fitz/fitz.h index 2ee28f86..b1578b20 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -910,47 +910,17 @@ void fz_free_glyph_cache(fz_glyph_cache *); int fz_get_aa_level(void); void fz_set_aa_level(int bits); -typedef struct fz_edge_s fz_edge; typedef struct fz_gel_s fz_gel; -typedef struct fz_ael_s fz_ael; - -struct fz_edge_s -{ - int x, e, h, y; - int adj_up, adj_down; - int xmove; - int xdir, ydir; /* -1 or +1 */ -}; - -struct fz_gel_s -{ - fz_bbox clip; - fz_bbox bbox; - int cap; - int len; - fz_edge *edges; -}; - -struct fz_ael_s -{ - int cap; - int len; - fz_edge **edges; -}; fz_gel *fz_new_gel(void); void fz_insert_gel(fz_gel *gel, float x0, float y0, float x1, float y1); -fz_bbox fz_bound_gel(fz_gel *gel); void fz_reset_gel(fz_gel *gel, fz_bbox clip); void fz_sort_gel(fz_gel *gel); +fz_bbox fz_bound_gel(fz_gel *gel); void fz_free_gel(fz_gel *gel); int fz_is_rect_gel(fz_gel *gel); -fz_ael *fz_new_ael(void); -void fz_free_ael(fz_ael *ael); - -void fz_scan_convert(fz_gel *gel, fz_ael *ael, int eofill, - fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv); +void fz_scan_convert(fz_gel *gel, int eofill, fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv); void fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); void fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); |