#include "announcements.h"
#include "gtkcompass.h"
#include "dialogs.h"
+#include "image-cache.h"
#define DEBUG_MAP_TIME 1
/** The backing pixmap of map_widget. */
static GdkPixmap *map_pixmap;
+/* Tile cache, this might need some adjustment */
+#define MAP_CACHE_MAX (64)
+static ImageCache *map_ic;
+
/** The "base tile" is the upper-left tile in the pixmap. */
guint _base_tilex = -5;
guint _base_tiley = -5;
map_widget=gtk_drawing_area_new();
map_timer=g_timer_new();
+map_ic=image_cache_new(MAP_CACHE_MAX);
g_debug("World size: %u", WORLD_SIZE_UNITS);
#ifdef WITH_GL
* this method, but I guess it's not general-purpose enough.
*/
static void
-map_pixbuf_scale_inplace(GdkPixbuf * pixbuf, guint ratio_p2, guint src_x, guint src_y)
+map_pixbuf_scale_inplace(GdkPixbuf *pixbuf, guint ratio_p2, guint src_x, guint src_y)
{
guint dest_x = 0, dest_y = 0, dest_dim = TILE_SIZE_PIXELS;
guint rowstride = gdk_pixbuf_get_rowstride(pixbuf);
GdkPixbuf *mpixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha(pixbuf),
8, TILE_SIZE_PIXELS, TILE_SIZE_PIXELS);
+g_debug("TRIM!!");
gdk_pixbuf_copy_area(pixbuf,
(gdk_pixbuf_get_width(pixbuf) - TILE_SIZE_PIXELS) / 2,
(gdk_pixbuf_get_height(pixbuf) - TILE_SIZE_PIXELS) / 2,
return map_pixmap;
}
-
static GdkPixbuf *
map_tile_load(guint tilex, guint tiley, gint zoff, gboolean download)
{
GdkPixbuf *pixbuf;
GError *error = NULL;
gchar buffer[BUFFER_SIZE];
+gchar key[BUFFER_SIZE];
struct stat tstat;
gint se;
g_snprintf(buffer, sizeof(buffer), "%s/%u/%u/%u.jpg", _curr_repo->cache_dir, _zoom + zoff, (tilex >> zoff), (tiley >> zoff));
+g_snprintf(key, sizeof(key), "%s/%u/%u/%u", _curr_repo->cache_dir, _zoom + zoff, (tilex >> zoff), (tiley >> zoff));
-pixbuf=gdk_pixbuf_new_from_file(buffer, &error);
-if (error || !pixbuf) {
+pixbuf=image_cache_get(map_ic, key, buffer);
+if (!pixbuf) {
g_unlink(buffer);
if (_auto_download && _curr_repo->type != REPOTYPE_NONE && !((_zoom + zoff - (_curr_repo->double_size ? 1 : 0)) % _curr_repo->dl_zoom_steps)) {
if (download)
map_initiate_download(tilex >> zoff, tiley >> zoff, _zoom + zoff, -INITIAL_DOWNLOAD_RETRIES);
}
-
return NULL;
}
+g_object_ref(pixbuf);
+
+#if 0
+/* Check if we need to trim. */
+if (gdk_pixbuf_get_width(pixbuf) != TILE_SIZE_PIXELS || gdk_pixbuf_get_height(pixbuf) != TILE_SIZE_PIXELS)
+ pixbuf=pixbuf_trim(pixbuf);
+#endif
+
/* Check tile age, if file date is ower a week old, redownload if autodownload enabled */
se=stat(buffer, &tstat);
if (se==0) {
if (download) {
g_debug("Tile: %s is old, re-downloading\n", buffer);
map_initiate_download(tilex >> zoff, tiley >> zoff, _zoom + zoff, -INITIAL_DOWNLOAD_RETRIES);
+ image_cache_invalidate(map_ic, key);
}
}
}
if (!fast_fail)
fast_fail=TRUE;
} else {
- /* Check if we need to trim. */
- if (gdk_pixbuf_get_width(pixbuf) != TILE_SIZE_PIXELS || gdk_pixbuf_get_height(pixbuf) != TILE_SIZE_PIXELS)
- pixbuf = pixbuf_trim(pixbuf);
-
/* Check if we need to blit. */
if (zoff) {
map_pixbuf_scale_inplace(pixbuf, zoff,
- (tilex - ((tilex >> zoff) << zoff)) << (TILE_SIZE_P2 - zoff),
- (tiley - ((tiley >> zoff) << zoff)) << (TILE_SIZE_P2 - zoff));
+ (tilex - ((tilex >> zoff) << zoff)) << (TILE_SIZE_P2 - zoff),
+ (tiley - ((tiley >> zoff) << zoff)) << (TILE_SIZE_P2 - zoff));
+ image_cache_invalidate_by_image(map_ic, pixbuf);
}
}
}
nzoom=_zoom+zdir;
if ((nzoom >= 0) && (nzoom < map_max_zoom - 1)) {
+ image_cache_clear(map_ic);
map_set_zoom(nzoom);
}
return nzoom;