#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <string.h>
+#include <math.h>
+#include <stdlib.h>
#include "icons/icons.h"
gdouble mpp_easting, mpp_northing;
guint width, height;
+ GdkPixbuf *scaled;
+ guint32 scaled_width, scaled_height;
+
gint click_x, click_y;
};
vgl->pixbuf = NULL;
vgl->click_x = -1;
vgl->click_y = -1;
+ vgl->scaled = NULL;
+ vgl->scaled_width = 0;
+ vgl->scaled_height = 0;
return vgl;
}
VikViewport *vp = VIK_VIEWPORT(data);
struct UTM utm_middle;
gdouble xmpp = vik_viewport_get_xmpp(vp), ympp = vik_viewport_get_ympp(vp);
+ GdkPixbuf *pixbuf = vgl->pixbuf;
+ guint layer_width = vgl->width;
+ guint layer_height = vgl->height;
+
vik_coord_to_utm ( vik_viewport_get_center ( vp ), &utm_middle );
- if ( xmpp == vgl->mpp_easting && ympp == vgl->mpp_northing )
+ /* scale the pixbuf if it doesn't match our dimensions */
+ if ( xmpp != vgl->mpp_easting || ympp != vgl->mpp_northing )
{
- guint width = vik_viewport_get_width(vp), height = vik_viewport_get_height(vp);
- gint32 x, y;
- vgl->corner.zone = utm_middle.zone;
- vgl->corner.letter = utm_middle.letter;
- VikCoord corner_coord;
- vik_coord_load_from_utm ( &corner_coord, vik_viewport_get_coord_mode(vp), &(vgl->corner) );
- vik_viewport_coord_to_screen ( vp, &corner_coord, &x, &y );
- if ( (x < 0 || x < width) && (y < 0 || y < height) && x+vgl->width > 0 && y+vgl->height > 0 )
- vik_viewport_draw_pixbuf ( vp, vgl->pixbuf, 0, 0, x, y, vgl->width, vgl->height ); /* todo: draw only what we need to. */
+ layer_width = round(vgl->width * vgl->mpp_easting / xmpp);
+ layer_height = round(vgl->height * vgl->mpp_northing / ympp);
+
+ /* rescale if necessary */
+ if (layer_width == vgl->scaled_width && layer_height == vgl->scaled_height && vgl->scaled != NULL)
+ pixbuf = vgl->scaled;
+ else
+ {
+ pixbuf = gdk_pixbuf_scale_simple(
+ vgl->pixbuf,
+ layer_width,
+ layer_height,
+ GDK_INTERP_BILINEAR
+ );
+
+ if (vgl->scaled != NULL)
+ g_object_unref(vgl->scaled);
+
+ vgl->scaled = pixbuf;
+ vgl->scaled_width = layer_width;
+ vgl->scaled_height = layer_height;
+ }
}
+
+ guint width = vik_viewport_get_width(vp), height = vik_viewport_get_height(vp);
+ gint32 x, y;
+ vgl->corner.zone = utm_middle.zone;
+ vgl->corner.letter = utm_middle.letter;
+ VikCoord corner_coord;
+ vik_coord_load_from_utm ( &corner_coord, vik_viewport_get_coord_mode(vp), &(vgl->corner) );
+ vik_viewport_coord_to_screen ( vp, &corner_coord, &x, &y );
+ if ( (x < 0 || x < width) && (y < 0 || y < height) && x+layer_width > 0 && y+layer_height > 0 )
+ vik_viewport_draw_pixbuf ( vp, pixbuf, 0, 0, x, y, layer_width, layer_height ); /* todo: draw only what we need to. */
}
}
{
if ( vgl->image != NULL )
g_free ( vgl->image );
+ if ( vgl->scaled != NULL )
+ g_object_unref ( vgl->scaled );
}
VikGeorefLayer *georef_layer_create ( VikViewport *vp )
if ( vgl->pixbuf )
g_object_unref ( G_OBJECT(vgl->pixbuf) );
+ if ( vgl->scaled )
+ {
+ g_object_unref ( G_OBJECT(vgl->scaled) );
+ vgl->scaled = NULL;
+ }
vgl->pixbuf = gdk_pixbuf_new_from_file ( vgl->image, &gx );
{
if ( vgl->image )
g_free ( vgl->image );
+ if ( vgl->scaled )
+ {
+ g_object_unref ( vgl->scaled );
+ vgl->scaled = NULL;
+ }
if ( image == NULL )
vgl->image = NULL;
vgl->image = g_strdup ( image );
else
{
gchar *buffer = g_malloc ( 1024 * sizeof(gchar) );
- if ( world_file_read_line ( buffer, 1024, f, pass_along[0], TRUE ) && world_file_read_line ( buffer, 1024, f, pass_along[1], TRUE )
- && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE ) && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE )
+ if ( world_file_read_line ( buffer, 1024, f, pass_along[0], TRUE ) && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE)
+ && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE ) && world_file_read_line ( buffer, 1024, f, pass_along[1], TRUE)
&& world_file_read_line ( buffer, 1024, f, pass_along[2], TRUE ) && world_file_read_line ( buffer, 1024, f, pass_along[3], TRUE ) )
{
g_free ( buffer );
gtk_box_pack_start ( GTK_BOX(wfp_hbox), wfp_button, FALSE, FALSE, 3 );
ce_label = gtk_label_new ( _("Corner pixel easting:") );
- ce_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 1500000.0, 1, 5, 5 ), 1, 4 );
+ ce_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 1500000.0, 1, 5, 0 ), 1, 4 );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET(ce_spin), _("the UTM \"easting\" value of the upper-right corner pixel of the map") );
cn_label = gtk_label_new ( _("Corner pixel northing:") );
- cn_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 9000000.0, 1, 5, 5 ), 1, 4 );
+ cn_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 9000000.0, 1, 5, 0 ), 1, 4 );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET(cn_spin), _("the UTM \"northing\" value of the upper-right corner pixel of the map") );
xlabel = gtk_label_new ( _("X (easting) scale (mpp): "));
ylabel = gtk_label_new ( _("Y (northing) scale (mpp): "));
- xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
- yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
+ xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET(xspin), _("the scale of the map in the X direction (meters per pixel)") );
+ yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET(yspin), _("the scale of the map in the Y direction (meters per pixel)") );
imagelabel = gtk_label_new ( _("Map Image:") );
- imageentry = vik_file_entry_new ();
+ imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN);
if (*vgl)
{