Mercurial > geeqie.yaz
comparison src/pixbuf-renderer.c @ 1643:704ab52b3ac5
fixed problems with floor/ceil
- introduce macros ROUND_DOWN, ROUND_UP
- fixed incorrect usage of floor/ceil functions on int arguments
patch by Yuriy Kaminskiy
author | nadvornik |
---|---|
date | Wed, 17 Jun 2009 18:19:11 +0000 |
parents | 368b31e37674 |
children | 51820482c7e5 |
comparison
equal
deleted
inserted
replaced
1642:a78ac3a4c32e | 1643:704ab52b3ac5 |
---|---|
76 | 76 |
77 /* when scaling image to below this size, use nearest pixel for scaling | 77 /* when scaling image to below this size, use nearest pixel for scaling |
78 * (below about 4, the other scale types become slow generating their conversion tables) | 78 * (below about 4, the other scale types become slow generating their conversion tables) |
79 */ | 79 */ |
80 #define PR_MIN_SCALE_SIZE 8 | 80 #define PR_MIN_SCALE_SIZE 8 |
81 | |
82 /* round A up/down to integer count of B */ | |
83 #define ROUND_UP(A,B) ((gint)(((A)+(B)-1)/(B))*(B)) | |
84 #define ROUND_DOWN(A,B) ((gint)(((A))/(B))*(B)) | |
81 | 85 |
82 typedef enum { | 86 typedef enum { |
83 TILE_RENDER_NONE = 0, /* do nothing */ | 87 TILE_RENDER_NONE = 0, /* do nothing */ |
84 TILE_RENDER_AREA, /* render an area of the tile */ | 88 TILE_RENDER_AREA, /* render an area of the tile */ |
85 TILE_RENDER_ALL /* render the whole tile */ | 89 TILE_RENDER_ALL /* render the whole tile */ |
1466 { | 1470 { |
1467 gint x1, y1, x2, y2; | 1471 gint x1, y1, x2, y2; |
1468 | 1472 |
1469 if (!st) return FALSE; | 1473 if (!st) return FALSE; |
1470 | 1474 |
1471 x1 = (pr->x_scroll / pr->tile_width) * pr->tile_width; | 1475 x1 = ROUND_DOWN(pr->x_scroll, pr->tile_width); |
1472 y1 = (pr->y_scroll / pr->tile_height) * pr->tile_height; | 1476 y1 = ROUND_DOWN(pr->y_scroll, pr->tile_height); |
1473 x2 = ((pr->x_scroll + pr->vis_width) / pr->tile_width) * pr->tile_width + pr->tile_width; | 1477 x2 = ROUND_UP(pr->x_scroll + pr->vis_width, pr->tile_width); |
1474 y2 = ((pr->y_scroll + pr->vis_height) / pr->tile_height) * pr->tile_height + pr->tile_height; | 1478 y2 = ROUND_UP(pr->y_scroll + pr->vis_height, pr->tile_height); |
1475 | 1479 |
1476 return !((gdouble)st->x * pr->scale > (gdouble)x2 || | 1480 return !((gdouble)st->x * pr->scale > (gdouble)x2 || |
1477 (gdouble)(st->x + pr->source_tile_width) * pr->scale < (gdouble)x1 || | 1481 (gdouble)(st->x + pr->source_tile_width) * pr->scale < (gdouble)x1 || |
1478 (gdouble)st->y * pr->scale > (gdouble)y2 || | 1482 (gdouble)st->y * pr->scale > (gdouble)y2 || |
1479 (gdouble)(st->y + pr->source_tile_height) * pr->scale < (gdouble)y1); | 1483 (gdouble)(st->y + pr->source_tile_height) * pr->scale < (gdouble)y1); |
1531 st = g_new0(SourceTile, 1); | 1535 st = g_new0(SourceTile, 1); |
1532 st->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, | 1536 st->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, |
1533 pr->source_tile_width, pr->source_tile_height); | 1537 pr->source_tile_width, pr->source_tile_height); |
1534 } | 1538 } |
1535 | 1539 |
1536 st->x = (x / pr->source_tile_width) * pr->source_tile_width; | 1540 st->x = ROUND_DOWN(x, pr->source_tile_width); |
1537 st->y = (y / pr->source_tile_height) * pr->source_tile_height; | 1541 st->y = ROUND_DOWN(y, pr->source_tile_height); |
1538 st->blank = TRUE; | 1542 st->blank = TRUE; |
1539 | 1543 |
1540 pr->source_tiles = g_list_prepend(pr->source_tiles, st); | 1544 pr->source_tiles = g_list_prepend(pr->source_tiles, st); |
1541 | 1545 |
1542 return st; | 1546 return st; |
1597 if (x < 0) x = 0; | 1601 if (x < 0) x = 0; |
1598 if (y < 0) y = 0; | 1602 if (y < 0) y = 0; |
1599 if (w > pr->image_width) w = pr->image_width; | 1603 if (w > pr->image_width) w = pr->image_width; |
1600 if (h > pr->image_height) h = pr->image_height; | 1604 if (h > pr->image_height) h = pr->image_height; |
1601 | 1605 |
1602 sx = (x / pr->source_tile_width) * pr->source_tile_width; | 1606 sx = ROUND_DOWN(x, pr->source_tile_width); |
1603 sy = (y / pr->source_tile_height) * pr->source_tile_height; | 1607 sy = ROUND_DOWN(y, pr->source_tile_height); |
1604 | 1608 |
1605 for (x1 = sx; x1 < x + w; x1+= pr->source_tile_width) | 1609 for (x1 = sx; x1 < x + w; x1+= pr->source_tile_width) |
1606 { | 1610 { |
1607 for (y1 = sy; y1 < y + h; y1 += pr->source_tile_height) | 1611 for (y1 = sy; y1 < y + h; y1 += pr->source_tile_height) |
1608 { | 1612 { |
2017 { | 2021 { |
2018 gint x1, x2; | 2022 gint x1, x2; |
2019 gint y1, y2; | 2023 gint y1, y2; |
2020 GList *work; | 2024 GList *work; |
2021 | 2025 |
2022 x1 = (gint)floor(x / pr->tile_width) * pr->tile_width; | 2026 x1 = ROUND_DOWN(x, pr->tile_width); |
2023 x2 = (gint)ceil((x + w) / pr->tile_width) * pr->tile_width; | 2027 x2 = ROUND_UP(x + w, pr->tile_width); |
2024 | 2028 |
2025 y1 = (gint)floor(y / pr->tile_height) * pr->tile_height; | 2029 y1 = ROUND_DOWN(y, pr->tile_height); |
2026 y2 = (gint)ceil((y + h) / pr->tile_height) * pr->tile_height; | 2030 y2 = ROUND_UP(y + h, pr->tile_height); |
2027 | 2031 |
2028 work = pr->tiles; | 2032 work = pr->tiles; |
2029 while (work) | 2033 while (work) |
2030 { | 2034 { |
2031 ImageTile *it; | 2035 ImageTile *it; |
3013 gint x1, x2; | 3017 gint x1, x2; |
3014 gint y1, y2; | 3018 gint y1, y2; |
3015 | 3019 |
3016 if (clamp && !pr_clamp_to_visible(pr, &x, &y, &w, &h)) return FALSE; | 3020 if (clamp && !pr_clamp_to_visible(pr, &x, &y, &w, &h)) return FALSE; |
3017 | 3021 |
3018 x1 = (gint)floor(x / pr->tile_width) * pr->tile_width; | 3022 x1 = ROUND_DOWN(x, pr->tile_width); |
3019 x2 = (gint)ceil((x + w) / pr->tile_width) * pr->tile_width; | 3023 x2 = ROUND_UP(x + w, pr->tile_width); |
3020 | 3024 |
3021 y1 = (gint)floor(y / pr->tile_height) * pr->tile_height; | 3025 y1 = ROUND_DOWN(y, pr->tile_height); |
3022 y2 = (gint)ceil((y + h) / pr->tile_height) * pr->tile_height; | 3026 y2 = ROUND_UP(y + h, pr->tile_height); |
3023 | 3027 |
3024 for (j = y1; j <= y2; j += pr->tile_height) | 3028 for (j = y1; j <= y2; j += pr->tile_height) |
3025 { | 3029 { |
3026 for (i = x1; i <= x2; i += pr->tile_width) | 3030 for (i = x1; i <= x2; i += pr->tile_width) |
3027 { | 3031 { |