changeset 32:96ac60a9c0f1

Wed Apr 6 02:43:40 2005 John Ellis <johne@verizon.net> * 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. #####
author gqview
date Wed, 06 Apr 2005 06:49:23 +0000
parents c42544f31030
children a41ecbb26a96
files ChangeLog TODO src/pan-view.c src/pixbuf-renderer.c
diffstat 4 files changed, 97 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Apr 05 09:13:51 2005 +0000
+++ b/ChangeLog	Wed Apr 06 06:49:23 2005 +0000
@@ -1,3 +1,11 @@
+Wed Apr  6 02:43:40 2005  John Ellis  <johne@verizon.net>
+
+	* 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  <johne@verizon.net>
 
 	* pixbuf-renderer.c: Add argument to pr_queue_to_tiles to only redraw
--- a/TODO	Tue Apr 05 09:13:51 2005 +0000
+++ b/TODO	Wed Apr 06 06:49:23 2005 +0000
@@ -34,7 +34,10 @@
    > 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.
--- a/src/pan-view.c	Tue Apr 05 09:13:51 2005 +0000
+++ b/src/pan-view.c	Wed Apr 06 06:49:23 2005 +0000
@@ -435,7 +435,11 @@
 	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 @@
 	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)
 		{
-		pp = p_pix + i * prs + (fx1 * p_step);
-		for (j = fx1; j < fx2; j++)
+		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++)
+		{
+		gint xa, xb;
+
+		if (!middle && y > y2)
 			{
-			gint z1, z2;
-
-			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;
+			slope1 = (gdouble)(y3 - y2);
+			if (slope1) slope1 = (gdouble)(x3 - x2) / slope1;
+			slope1_x = x2;
+			slope1_y = y2;
+
+			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 @@
 		{
 		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 @@
 
 		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 @@
 		{
 		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,
--- a/src/pixbuf-renderer.c	Tue Apr 05 09:13:51 2005 +0000
+++ b/src/pixbuf-renderer.c	Wed Apr 06 06:49:23 2005 +0000
@@ -1245,10 +1245,10 @@
 
 	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 @@
 		{
 		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 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 @@
 			{
 			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;