From 4532d037cc45bc63a880ff9b4f44abe8d7be6f9a Mon Sep 17 00:00:00 2001 From: John Ellis Date: Wed, 6 Apr 2005 06:49:23 +0000 Subject: [PATCH] Wed Apr 6 02:43:40 2005 John Ellis * pan-view.c: Reimplement pixbuf_draw_triangle for efficiency. * pixbuf-renderer.c: Fix pr_queue_to_tiles only_existing argument to only have effect on tiles that not currently visible. Remove use of hard coded PR_TILE_SIZE from tile size calculations, as it is only supposed to be used as the default value. ##### Note: GQview CVS on sourceforge is not always up to date, please use ##### ##### an offical release when making enhancements and translation updates. ##### --- ChangeLog | 8 ++++ TODO | 5 +- src/pan-view.c | 104 ++++++++++++++++++++++++++++-------------- src/pixbuf-renderer.c | 23 ++++++---- 4 files changed, 96 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19228673..2f8361f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Apr 6 02:43:40 2005 John Ellis + + * pan-view.c: Reimplement pixbuf_draw_triangle for efficiency. + * pixbuf-renderer.c: Fix pr_queue_to_tiles only_existing argument to + only have effect on tiles that not currently visible. Remove use of + hard coded PR_TILE_SIZE from tile size calculations, as it is only + supposed to be used as the default value. + Tue Apr 5 05:09:29 2005 John Ellis * pixbuf-renderer.c: Add argument to pr_queue_to_tiles to only redraw diff --git a/TODO b/TODO index 38663f03..633cb8b1 100644 --- a/TODO +++ b/TODO @@ -34,7 +34,10 @@ Major: > should delete key actually work? > search should highlight all matching images (with toggle?) > should non-thumbnail images have a drop shadow? - d> uptimize pixbuf_draw_line (line endpoints should clip to draw region before draw loop) + d> optimize pixbuf_draw_line (line endpoints should clip to draw region before draw loop) + d> optimize pixbuf_draw_triangle + > does new pixbuf_draw_triangle contain line edge rounding error? + > move pixbuf_draw_* stuff into pixbuf_util.c > time line view: > allow use of file date or EXIF (embedded) date. diff --git a/src/pan-view.c b/src/pan-view.c index bf07e3a3..2284def8 100644 --- a/src/pan-view.c +++ b/src/pan-view.c @@ -435,7 +435,11 @@ static void pixbuf_draw_triangle(GdkPixbuf *pb, guchar *p_pix; guchar *pp; gint p_step; - gint i, j; + gdouble slope1, slope2; + gint slope1_x, slope1_y; + gint y; + gint t; + gint middle = FALSE; if (!pb) return; @@ -460,26 +464,68 @@ static void pixbuf_draw_triangle(GdkPixbuf *pb, p_pix = gdk_pixbuf_get_pixels(pb); p_step = (p_alpha) ? 4 : 3; - for (i = fy1; i < fy2; i++) + + if (y1 > y2) + { + t = x1; x1 = x2; x2 = t; + t = y1; y1 = y2; y2 = t; + } + if (y2 > y3) + { + t = x2; x2 = x3; x3 = t; + t = y2; y2 = y3; y3 = t; + } + if (y1 > y2) + { + t = x1; x1 = x2; x2 = t; + t = y1; y1 = y2; y2 = t; + } + + slope1 = (gdouble)(y2 - y1); + if (slope1) slope1 = (gdouble)(x2 - x1) / slope1; + slope1_x = x1; + slope1_y = y1; + slope2 = (gdouble)(y3 - y1); + if (slope2) slope2 = (gdouble)(x3 - x1) / slope2; + + for (y = fy1; y < fy2; y++) { - pp = p_pix + i * prs + (fx1 * p_step); - for (j = fx1; j < fx2; j++) + gint xa, xb; + + if (!middle && y > y2) { - gint z1, z2; + slope1 = (gdouble)(y3 - y2); + if (slope1) slope1 = (gdouble)(x3 - x2) / slope1; + slope1_x = x2; + slope1_y = y2; - z1 = (y1 - y2)*(j - x2) + (x2 - x1)*(i - y2); - z2 = (y2 - y3)*(j - x3) + (x3 - x2)*(i - y3); - if ((z1 ^ z2) >= 0) - { - z2 = (y3 - y1)*(j - x1) + (x1 - x3)*(i - y1); - if ((z1 ^ z2) >= 0) - { - pp[0] = (r * a + pp[0] * (256-a)) >> 8; - pp[1] = (g * a + pp[1] * (256-a)) >> 8; - pp[2] = (b * a + pp[2] * (256-a)) >> 8; - } - } - pp += p_step; + middle = TRUE; + } + + xa = slope1_x + ((gdouble)slope1 * (y - slope1_y) + 0.5); + xb = x1 + ((gdouble)slope2 * (y - y1) + 0.5); + + if (xa > xb) + { + t = xa; xa = xb; xb = t; + } + + xa = CLAMP(xa, fx1, fx2); + xb = CLAMP(xb, fx1, fx2); + + pp = p_pix + y * prs + xa * p_step; + + while (xa < xb) + { + *pp = (r * a + *pp * (256-a)) >> 8; + pp++; + *pp = (g * a + *pp * (256-a)) >> 8; + pp++; + *pp = (b * a + *pp * (256-a)) >> 8; + pp++; + if (p_alpha) pp++; + + xa++; } } } @@ -495,14 +541,8 @@ static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdoub { gdouble t; - t = x1; - x1 = x2; - x2 = t; - - t = y1; - y1 = y2; - y2 = t; - + t = x1; x1 = x2; x2 = t; + t = y1; y1 = y2; y2 = t; flip = TRUE; } @@ -559,14 +599,8 @@ static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdoub if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE; - t = x1; - x1 = x2; - x2 = t; - - t = y1; - y1 = y2; - y2 = t; - + t = x1; x1 = x2; x2 = t; + t = y1; y1 = y2; y2 = t; flip = !flip; } @@ -3322,6 +3356,8 @@ static gint pan_window_layout_update_idle_cb(gpointer data) { gdouble align; + printf("Canvas size is %d x %d\n", width, height); + pixbuf_renderer_set_tiles(PIXBUF_RENDERER(pw->imd->pr), width, height, PAN_TILE_SIZE, PAN_TILE_SIZE, 10, pan_window_request_tile_cb, diff --git a/src/pixbuf-renderer.c b/src/pixbuf-renderer.c index ae7500fa..6701fdbc 100644 --- a/src/pixbuf-renderer.c +++ b/src/pixbuf-renderer.c @@ -1245,10 +1245,10 @@ static gint pr_source_tile_visible(PixbufRenderer *pr, SourceTile *st) if (!st) return FALSE; - x1 = (pr->x_scroll / PR_TILE_SIZE) * PR_TILE_SIZE; - y1 = (pr->y_scroll / PR_TILE_SIZE) * PR_TILE_SIZE; - x2 = ((pr->x_scroll + pr->vis_width) / PR_TILE_SIZE) * PR_TILE_SIZE + PR_TILE_SIZE; - y2 = ((pr->y_scroll + pr->vis_height) / PR_TILE_SIZE) * PR_TILE_SIZE + PR_TILE_SIZE; + x1 = (pr->x_scroll / pr->tile_width) * pr->tile_width; + y1 = (pr->y_scroll / pr->tile_height) * pr->tile_height; + x2 = ((pr->x_scroll + pr->vis_width) / pr->tile_width) * pr->tile_width + pr->tile_width; + y2 = ((pr->y_scroll + pr->vis_height) / pr->tile_height) * pr->tile_height + pr->tile_height; return !((double)st->x * pr->scale > (double)x2 || (double)(st->x + pr->source_tile_width) * pr->scale < (double)x1 || @@ -1733,8 +1733,8 @@ static void pr_tile_free_space(PixbufRenderer *pr, guint space, ImageTile *it) { gint tiles; - tiles = (pr->vis_width / PR_TILE_SIZE + 1) * (pr->vis_width / PR_TILE_SIZE + 1); - tile_max = MAX(tiles * PR_TILE_SIZE * PR_TILE_SIZE * 3, + tiles = (pr->vis_width / pr->tile_width + 1) * (pr->vis_height / pr->tile_height + 1); + tile_max = MAX(tiles * pr->tile_width * pr->tile_height * 3, (gint)((double)pr->tile_cache_max * 1048576.0 * pr->scale)); } else @@ -2021,8 +2021,8 @@ static void pr_tile_expose(PixbufRenderer *pr, ImageTile *it, static gint pr_tile_is_visible(PixbufRenderer *pr, ImageTile *it) { - return (it->x + it->w >= pr->x_scroll && it->x <= pr->x_scroll + pr->window_width - pr->x_offset * 2 && - it->y + it->h >= pr->y_scroll && it->y <= pr->y_scroll + pr->window_height - pr->y_offset * 2); + return (it->x + it->w >= pr->x_scroll && it->x < pr->x_scroll + pr->vis_width && + it->y + it->h >= pr->y_scroll && it->y < pr->y_scroll + pr->vis_height); } /* @@ -2233,7 +2233,12 @@ static gint pr_queue_to_tiles(PixbufRenderer *pr, gint x, gint y, gint w, gint h { ImageTile *it; - it = pr_tile_get(pr, i, j, only_existing); + it = pr_tile_get(pr, i, j, + (only_existing && + i + pr->tile_width < pr->x_scroll && + i > pr->x_scroll + pr->vis_width && + j + pr->tile_height < pr->y_scroll && + j > pr->y_scroll +pr->vis_height)); if (it) { QueueData *qd; -- 2.20.1