diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2009-06-30 13:02:23 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2009-06-30 13:02:23 +0000 |
commit | aa2684341170424783f9937d8fe441fb3984d825 (patch) | |
tree | b7b1adaf3867666f15d7bf9bacf804846372eff7 /desktop | |
parent | 38356d46ff15fe669c59bdf6aa96b7f4248d1b6a (diff) | |
download | netsurf-aa2684341170424783f9937d8fe441fb3984d825.tar.gz netsurf-aa2684341170424783f9937d8fe441fb3984d825.tar.bz2 |
Improve bitmap plotter API
svn path=/trunk/netsurf/; revision=8195
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/history_core.c | 2 | ||||
-rw-r--r-- | desktop/knockout.c | 160 | ||||
-rw-r--r-- | desktop/plotters.h | 9 | ||||
-rw-r--r-- | desktop/save_pdf/pdf_plotters.c | 73 |
4 files changed, 77 insertions, 167 deletions
diff --git a/desktop/history_core.c b/desktop/history_core.c index d6feb69be..6ec2cc137 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -635,7 +635,7 @@ bool history_redraw_entry(struct history *history, } if (!plot.bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, - entry->bitmap, 0xffffff, NULL)) + entry->bitmap, 0xffffff, 0)) return false; if (!plot.rectangle(entry->x - 1 + xoffset, entry->y - 1 + yoffset, WIDTH + 1, HEIGHT + 1, diff --git a/desktop/knockout.c b/desktop/knockout.c index 64d79bcd0..4df32bb50 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -83,7 +83,7 @@ struct knockout_entry; static void knockout_set_plotters(void); static void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *box); static bool knockout_plot_fill_recursive(struct knockout_box *box, colour c); -static bool knockout_plot_bitmap_tile_recursive(struct knockout_box *box, +static bool knockout_plot_bitmap_recursive(struct knockout_box *box, struct knockout_entry *entry); static bool knockout_plot_clg(colour c); @@ -101,10 +101,8 @@ static bool knockout_plot_disc(int x, int y, int radius, colour colour, bool fil static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c); static bool knockout_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, struct content *content); -static bool knockout_plot_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, - bool repeat_x, bool repeat_y, struct content *content); + bitmap_flags_t flags); static bool knockout_plot_flush(void); static bool knockout_plot_group_start(const char *name); static bool knockout_plot_group_end(void); @@ -113,22 +111,21 @@ static bool knockout_plot_path(const float *p, unsigned int n, colour fill, const struct plotter_table knockout_plotters = { - knockout_plot_clg, - knockout_plot_rectangle, - knockout_plot_line, - knockout_plot_polygon, - knockout_plot_fill, - knockout_plot_clip, - knockout_plot_text, - knockout_plot_disc, - knockout_plot_arc, - knockout_plot_bitmap, - knockout_plot_bitmap_tile, - knockout_plot_group_start, - knockout_plot_group_end, - knockout_plot_flush, - knockout_plot_path, - true + .clg = knockout_plot_clg, + .rectangle = knockout_plot_rectangle, + .line = knockout_plot_line, + .polygon = knockout_plot_polygon, + .fill = knockout_plot_fill, + .clip = knockout_plot_clip, + .text = knockout_plot_text, + .disc = knockout_plot_disc, + .arc = knockout_plot_arc, + .bitmap = knockout_plot_bitmap, + .group_start = knockout_plot_group_start, + .group_end = knockout_plot_group_end, + .flush = knockout_plot_flush, + .path = knockout_plot_path, + .option_knockout = true, }; @@ -142,8 +139,7 @@ typedef enum { KNOCKOUT_PLOT_TEXT, KNOCKOUT_PLOT_DISC, KNOCKOUT_PLOT_ARC, - KNOCKOUT_PLOT_BITMAP, /* knockout */ - KNOCKOUT_PLOT_BITMAP_TILE, /* knockout, knocked out */ + KNOCKOUT_PLOT_BITMAP, /* knockout, knocked out */ KNOCKOUT_PLOT_GROUP_START, KNOCKOUT_PLOT_GROUP_END, } knockout_type; @@ -238,20 +234,9 @@ struct knockout_entry { int height; struct bitmap *bitmap; colour bg; - struct content *content; + bitmap_flags_t flags; } bitmap; struct { - int x; - int y; - int width; - int height; - struct bitmap *bitmap; - colour bg; - bool repeat_x; - bool repeat_y; - struct content *content; - } bitmap_tile; - struct { const char *name; } group_start; } data; @@ -418,40 +403,26 @@ bool knockout_plot_flush(void) knockout_entries[i].data.arc.c); break; case KNOCKOUT_PLOT_BITMAP: - success &= plot.bitmap( - knockout_entries[i].data.bitmap.x, - knockout_entries[i].data.bitmap.y, - knockout_entries[i].data.bitmap.width, - knockout_entries[i].data.bitmap.height, - knockout_entries[i].data.bitmap.bitmap, - knockout_entries[i].data.bitmap.bg, - knockout_entries[i].data.bitmap.content); - break; - case KNOCKOUT_PLOT_BITMAP_TILE: box = knockout_entries[i].box->child; if (box) { - success &= knockout_plot_bitmap_tile_recursive(box, + success &= knockout_plot_bitmap_recursive(box, &knockout_entries[i]); } else if (!knockout_entries[i].box->deleted) { - success &= plot.bitmap_tile( - knockout_entries[i].data. - bitmap_tile.x, + success &= plot.bitmap( knockout_entries[i].data. - bitmap_tile.y, + bitmap.x, knockout_entries[i].data. - bitmap_tile.width, + bitmap.y, knockout_entries[i].data. - bitmap_tile.height, + bitmap.width, knockout_entries[i].data. - bitmap_tile.bitmap, + bitmap.height, knockout_entries[i].data. - bitmap_tile.bg, + bitmap.bitmap, knockout_entries[i].data. - bitmap_tile.repeat_x, + bitmap.bg, knockout_entries[i].data. - bitmap_tile.repeat_y, - knockout_entries[i].data. - bitmap_tile.content); + bitmap.flags); } break; case KNOCKOUT_PLOT_GROUP_START: @@ -635,7 +606,7 @@ bool knockout_plot_fill_recursive(struct knockout_box *box, colour c) } -bool knockout_plot_bitmap_tile_recursive(struct knockout_box *box, +bool knockout_plot_bitmap_recursive(struct knockout_box *box, struct knockout_entry *entry) { bool success = true; @@ -645,21 +616,19 @@ bool knockout_plot_bitmap_tile_recursive(struct knockout_box *box, if (parent->deleted) continue; if (parent->child) - knockout_plot_bitmap_tile_recursive(parent->child, entry); + knockout_plot_bitmap_recursive(parent->child, entry); else { success &= plot.clip(parent->bbox.x0, parent->bbox.y0, parent->bbox.x1, parent->bbox.y1); - success &= plot.bitmap_tile(entry->data.bitmap_tile.x, - entry->data.bitmap_tile.y, - entry->data.bitmap_tile.width, - entry->data.bitmap_tile.height, - entry->data.bitmap_tile.bitmap, - entry->data.bitmap_tile.bg, - entry->data.bitmap_tile.repeat_x, - entry->data.bitmap_tile.repeat_y, - entry->data.bitmap_tile.content); + success &= plot.bitmap(entry->data.bitmap.x, + entry->data.bitmap.y, + entry->data.bitmap.width, + entry->data.bitmap.height, + entry->data.bitmap.bitmap, + entry->data.bitmap.bg, + entry->data.bitmap.flags); } } return success; @@ -852,40 +821,11 @@ bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, colour return true; } -bool knockout_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, struct content *content) -{ - int kx0, ky0, kx1, ky1; - - /* opaque bitmaps knockout, but don't get knocked out */ - if (bitmap_get_opaque(bitmap)) { - /* get our bounds */ - kx0 = (x > clip_x0_cur) ? x : clip_x0_cur; - ky0 = (y > clip_y0_cur) ? y : clip_y0_cur; - kx1 = (x + width < clip_x1_cur) ? x + width : clip_x1_cur; - ky1 = (y + height< clip_y1_cur) ? y + height: clip_y1_cur; - if ((kx0 > clip_x1_cur) || (kx1 < clip_x0_cur) || - (ky0 > clip_y1_cur) || (ky1 < clip_y0_cur)) - return true; - knockout_calculate(kx0, ky0, kx1, ky1, NULL); - } - knockout_entries[knockout_entry_cur].data.bitmap.x = x; - knockout_entries[knockout_entry_cur].data.bitmap.y = y; - knockout_entries[knockout_entry_cur].data.bitmap.width = width; - knockout_entries[knockout_entry_cur].data.bitmap.height = height; - knockout_entries[knockout_entry_cur].data.bitmap.bitmap = bitmap; - knockout_entries[knockout_entry_cur].data.bitmap.bg = bg; - knockout_entries[knockout_entry_cur].data.bitmap.content = content; - knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_BITMAP; - if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) - knockout_plot_flush(); - return true; -} -bool knockout_plot_bitmap_tile(int x, int y, int width, int height, +bool knockout_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, - bool repeat_x, bool repeat_y, struct content *content) + bitmap_flags_t flags) { int kx0, ky0, kx1, ky1; @@ -894,7 +834,7 @@ bool knockout_plot_bitmap_tile(int x, int y, int width, int height, ky0 = clip_y0_cur; kx1 = clip_x1_cur; ky1 = clip_y1_cur; - if (!repeat_x) { + if (!(flags & BITMAPF_REPEAT_X)) { if (x > kx0) kx0 = x; if (x + width < kx1) @@ -902,7 +842,7 @@ bool knockout_plot_bitmap_tile(int x, int y, int width, int height, if ((kx0 > clip_x1_cur) || (kx1 < clip_x0_cur)) return true; } - if (!repeat_y) { + if (!(flags & BITMAPF_REPEAT_Y)) { if (y > ky0) ky0 = y; if (y + height < ky1) @@ -923,16 +863,14 @@ bool knockout_plot_bitmap_tile(int x, int y, int width, int height, knockout_boxes[knockout_box_cur].next = knockout_list; knockout_list = &knockout_boxes[knockout_box_cur]; knockout_entries[knockout_entry_cur].box = &knockout_boxes[knockout_box_cur]; - knockout_entries[knockout_entry_cur].data.bitmap_tile.x = x; - knockout_entries[knockout_entry_cur].data.bitmap_tile.y = y; - knockout_entries[knockout_entry_cur].data.bitmap_tile.width = width; - knockout_entries[knockout_entry_cur].data.bitmap_tile.height = height; - knockout_entries[knockout_entry_cur].data.bitmap_tile.bitmap = bitmap; - knockout_entries[knockout_entry_cur].data.bitmap_tile.bg = bg; - knockout_entries[knockout_entry_cur].data.bitmap_tile.repeat_x = repeat_x; - knockout_entries[knockout_entry_cur].data.bitmap_tile.repeat_y = repeat_y; - knockout_entries[knockout_entry_cur].data.bitmap_tile.content = content; - knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_BITMAP_TILE; + knockout_entries[knockout_entry_cur].data.bitmap.x = x; + knockout_entries[knockout_entry_cur].data.bitmap.y = y; + knockout_entries[knockout_entry_cur].data.bitmap.width = width; + knockout_entries[knockout_entry_cur].data.bitmap.height = height; + knockout_entries[knockout_entry_cur].data.bitmap.bitmap = bitmap; + knockout_entries[knockout_entry_cur].data.bitmap.bg = bg; + knockout_entries[knockout_entry_cur].data.bitmap.flags = flags; + knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_BITMAP; if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) || (++knockout_box_cur >= KNOCKOUT_BOXES)) knockout_plot_flush(); diff --git a/desktop/plotters.h b/desktop/plotters.h index 6d2b66783..8173168eb 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -30,6 +30,10 @@ struct bitmap; +typedef unsigned long bitmap_flags_t; +#define BITMAPF_NONE 0 +#define BITMAPF_REPEAT_X 1 +#define BITMAPF_REPEAT_Y 2 /** Set of target specific plotting functions. * @@ -108,10 +112,7 @@ struct plotter_table { bool (*arc)(int x, int y, int radius, int angle1, int angle2, colour c); bool (*bitmap)(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, - struct content *content); - bool (*bitmap_tile)(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, - bool repeat_x, bool repeat_y, struct content *content); + bitmap_flags_t flags); bool (*group_start)(const char *name); /**< optional, may be NULL */ bool (*group_end)(void); /**< optional, may be NULL */ bool (*flush)(void); /**< optional, may be NULL */ diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 5bcba0a3d..92ede016a 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -59,15 +59,13 @@ static bool pdf_plot_text(int x, int y, const struct css_style *style, static bool pdf_plot_disc(int x, int y, int radius, colour c, bool filled); static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c); -static bool pdf_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, struct content *content); static bool pdf_plot_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, - bool repeat_x, bool repeat_y, struct content *content); + bitmap_flags_t flags); static bool pdf_plot_path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]); -static HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content); +static HPDF_Image pdf_extract_image(struct bitmap *bitmap); static void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data); @@ -126,22 +124,18 @@ static int last_clip_x0, last_clip_y0, last_clip_x1, last_clip_y1; static const struct print_settings *settings; static const struct plotter_table pdf_plotters = { - pdf_plot_clg, - pdf_plot_rectangle, - pdf_plot_line, - pdf_plot_polygon, - pdf_plot_fill, - pdf_plot_clip, - pdf_plot_text, - pdf_plot_disc, - pdf_plot_arc, - pdf_plot_bitmap, - pdf_plot_bitmap_tile, - NULL, - NULL, - NULL, - pdf_plot_path, - false + .clg = pdf_plot_clg, + .rectangle = pdf_plot_rectangle, + .line = pdf_plot_line, + .polygon = pdf_plot_polygon, + .fill = pdf_plot_fill, + .clip = pdf_plot_clip, + .text = pdf_plot_text, + .disc = pdf_plot_disc, + .arc = pdf_plot_arc, + .bitmap = pdf_plot_bitmap_tile, + .path = pdf_plot_path, + .option_knockout = false, }; const struct printer pdf_printer = { @@ -346,36 +340,10 @@ bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c) return true; } -bool pdf_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, struct content *content) -{ - HPDF_Image image; - -#ifdef PDF_DEBUG - LOG(("%d %d %d %d %p 0x%x %p", x, y, width, height, - bitmap, bg, content)); -#endif - if (width == 0 || height == 0) - return true; - - apply_clip_and_mode(false, TRANSPARENT, TRANSPARENT, 0., DashPattern_eNone); - - image = pdf_extract_image(bitmap, content); - - if (!image) - return false; - - HPDF_Page_DrawImage(pdf_page, image, - x, page_height - y - height, - width, height); - return true; - - -} bool pdf_plot_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, - bool repeat_x, bool repeat_y, struct content *content) + bitmap_flags_t flags) { HPDF_Image image; HPDF_REAL current_x, current_y ; @@ -390,13 +358,13 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, apply_clip_and_mode(false, TRANSPARENT, TRANSPARENT, 0., DashPattern_eNone); - image = pdf_extract_image(bitmap, content); + image = pdf_extract_image(bitmap); if (!image) return false; /*The position of the next tile*/ - max_width = (repeat_x) ? page_width : width; - max_height = (repeat_y) ? page_height : height; + max_width = (flags & BITMAPF_REPEAT_X) ? page_width : width; + max_height = (flags & BITMAPF_REPEAT_Y) ? page_height : height; for (current_y = 0; current_y < max_height; current_y += height) for (current_x = 0; current_x < max_width; current_x += width) @@ -408,9 +376,12 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, return true; } -HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) +HPDF_Image pdf_extract_image(struct bitmap *bitmap) { HPDF_Image image = NULL; + struct content *content = NULL; + + /* TODO - get content from bitmap pointer */ if (content) { /*Not sure if I don't have to check if downloading has been |