From fe7f37ed6e52b9c993b2b0503513710e842f81c1 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 28 Jul 2009 18:24:08 +0200 Subject: [PATCH] Fixed bug about raster dimensions. --- configure.ac | 2 +- docs/reference/libgtkgis-decl.txt | 2 +- docs/reference/libgtkgis-undocumented.txt | 2 +- docs/reference/tmpl/geometryraster.sgml | 2 ++ src/geometryraster.c | 15 ++++++++-- src/geometryraster.h | 6 +++- src/gtkgis.c | 32 ++------------------- src/layersource.c | 35 ++++++++++++++++------- 8 files changed, 49 insertions(+), 47 deletions(-) diff --git a/configure.ac b/configure.ac index 3706415..0140d9d 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_PATH_PROG(GDAL_CONFIG, "gdal-config", "", $PATH) # Checks for libraries. PKG_CHECK_MODULES([GTKGIS], [gtk+-2.0 >= 2.10.0 libxml-2.0 >= 2.7.0 - goocanvas >= 0.13]) + goocanvas >= 0.15]) AC_SUBST(GTKGIS_CFLAGS) AC_SUBST(GTKGIS_LIBS) diff --git a/docs/reference/libgtkgis-decl.txt b/docs/reference/libgtkgis-decl.txt index 7405e27..220354b 100644 --- a/docs/reference/libgtkgis-decl.txt +++ b/docs/reference/libgtkgis-decl.txt @@ -928,5 +928,5 @@ void gtk_gis_geometry_raster_new_from_pixbuf GtkGisGeometry * -GdkPixbuf *pixbuf, gdouble x, gdouble y +GdkPixbuf *pixbuf, gdouble x, gdouble y, gdouble pixsize_x, gdouble pixsize_y diff --git a/docs/reference/libgtkgis-undocumented.txt b/docs/reference/libgtkgis-undocumented.txt index c6a1297..e0b7ac7 100644 --- a/docs/reference/libgtkgis-undocumented.txt +++ b/docs/reference/libgtkgis-undocumented.txt @@ -107,7 +107,7 @@ gtk_gis_geometry_polygon_add_line_from_list gtk_gis_geometry_polygon_get_type gtk_gis_geometry_polygon_remove_line gtk_gis_geometry_raster_get_type -gtk_gis_geometry_raster_new_from_pixbuf (x, y, x, y) +gtk_gis_geometry_raster_new_from_pixbuf (x, y, x, y, pixsize_x, pixsize_y) gtk_gis_geometry_set_editable gtk_gis_get_layer_by_name gtk_gis_get_legend diff --git a/docs/reference/tmpl/geometryraster.sgml b/docs/reference/tmpl/geometryraster.sgml index cc09811..033791a 100644 --- a/docs/reference/tmpl/geometryraster.sgml +++ b/docs/reference/tmpl/geometryraster.sgml @@ -86,6 +86,8 @@ GtkGisGeometryRaster @pixbuf: @x: @y: +@pixsize_x: +@pixsize_y: @Returns: diff --git a/src/geometryraster.c b/src/geometryraster.c index 61dab7f..630c524 100644 --- a/src/geometryraster.c +++ b/src/geometryraster.c @@ -52,6 +52,8 @@ struct _GtkGisGeometryRasterPrivate gdouble x; gdouble y; + gdouble width; + gdouble height; }; G_DEFINE_TYPE (GtkGisGeometryRaster, gtk_gis_geometry_raster, TYPE_GTK_GIS_GEOMETRY) @@ -83,13 +85,17 @@ gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry_raster) * @pixbuf: a #GdkPixbuf object from which to create the new #GtkGisGeometryRaster object. * @x: * @y: + * @width: + * @height: * * Creates a new #GtkGisGeometryRaster object. * * Returns: the newly created #GtkGisGeometryRaster object. */ GtkGisGeometry -*gtk_gis_geometry_raster_new_from_pixbuf (GdkPixbuf *pixbuf, gdouble x, gdouble y) +*gtk_gis_geometry_raster_new_from_pixbuf (GdkPixbuf *pixbuf, + gdouble x, gdouble y, + gdouble width, gdouble height) { GtkGisGeometry *raster; GtkGisGeometryRasterPrivate *priv; @@ -101,6 +107,8 @@ GtkGisGeometry priv->pixbuf = pixbuf; priv->x = x; priv->y = y; + priv->width = width; + priv->height = height; return raster; } @@ -113,10 +121,13 @@ static GooCanvasItem GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (GTK_GIS_GEOMETRY_RASTER (raster)); if (priv->pixbuf != NULL) - {g_fprintf(stderr,"geometry %f %f\n",priv->x,priv->y); + { item = goo_canvas_image_new (NULL, priv->pixbuf, priv->x, priv->y, + "width", priv->width, + "height", priv->height, + "scale-to-fit", TRUE, NULL); } diff --git a/src/geometryraster.h b/src/geometryraster.h index bfd4c77..523f533 100644 --- a/src/geometryraster.h +++ b/src/geometryraster.h @@ -51,7 +51,11 @@ struct _GtkGisGeometryRasterClass GType gtk_gis_geometry_raster_get_type (void) G_GNUC_CONST; -GtkGisGeometry *gtk_gis_geometry_raster_new_from_pixbuf (GdkPixbuf *pixbuf, gdouble x, gdouble y); +GtkGisGeometry *gtk_gis_geometry_raster_new_from_pixbuf (GdkPixbuf *pixbuf, + gdouble x, + gdouble y, + gdouble width, + gdouble height); G_END_DECLS diff --git a/src/gtkgis.c b/src/gtkgis.c index 186ceac..742a347 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -617,7 +617,6 @@ gtk_gis_zoom_to_max (GtkGis *gtkgis) extent_width = priv->extent->max_x - priv->extent->min_x; extent_height = priv->extent->max_y - priv->extent->min_y; -g_fprintf(stderr,"extent_width %f extent_height %f\n",extent_width,extent_height); ratio = widget_width / widget_height; @@ -637,32 +636,6 @@ g_fprintf(stderr,"extent_width %f extent_height %f\n",extent_width,extent_height priv->extent->max_x += plus; } - /*if (extent_width > extent_height) - { - plus = (((widget_height * extent_width) / widget_width) - extent_height) / 2; - if (plus < 0) plus *= -1; - priv->extent->min_y -= plus; - priv->extent->max_y += plus; - } - else - { - if (widget_width > widget_height) - { - plus = (((widget_width * extent_height) / widget_height) - extent_width) / 2; - if (plus < 0) plus *= -1; - priv->extent->min_x -= plus; - priv->extent->max_x += plus; - } - else - { - plus = (((widget_height * extent_width) / widget_width) - extent_height) / 2; - if (plus < 0) plus *= -1; - priv->extent->min_y -= plus; - priv->extent->max_y += plus; - } - }*/ -g_fprintf(stderr,"plus %f\n",plus); - goo_canvas_set_bounds (GOO_CANVAS (priv->canvas), priv->extent->min_x, priv->extent->min_y, @@ -671,13 +644,12 @@ g_fprintf(stderr,"plus %f\n",plus); extx = priv->extent->max_x - priv->extent->min_x; exty = priv->extent->max_y - priv->extent->min_y; -g_fprintf(stderr,"extx %f exty %f\n",extx,exty); } scale->x = widget_width / extx; scale->y = widget_height / exty; scale->xy = (scale->x + scale->y) / 2; -g_fprintf(stderr,"scale_x %f scale_y %f scale_xy %f\n",scale->x,scale->y,scale->xy); + gtk_gis_set_scale (gtkgis, scale); } @@ -1007,7 +979,7 @@ gtk_gis_motion_notify_event (GtkWidget *widget, y = (gint)event->y; state = event->state; } - +/*g_fprintf (stderr, "cursor at %fx%f\n", (x / priv->scale->xy) + priv->extent->min_x, (y / priv->scale->xy) + priv->extent->min_y);*/ if (state & GDK_BUTTON1_MASK && priv->sel_start != NULL) { diff --git a/src/layersource.c b/src/layersource.c index 42f43c6..9661939 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -441,8 +441,10 @@ static GList gdouble x; gdouble y; - gdouble width; - gdouble height; + gdouble pixbuf_width; + gdouble pixbuf_height; + gint raster_width; + gint raster_height; gint i; @@ -498,13 +500,24 @@ static GList 0, 0); } + nXSize = GDALGetRasterXSize (priv->dataset); + nYSize = GDALGetRasterYSize (priv->dataset); + x = adfGeoTransform[0]; y = fixy - adfGeoTransform[3]; - width = GDALGetRasterXSize (priv->dataset); - height = GDALGetRasterYSize (priv->dataset); - - pixbuf_size = width * height; - pixbuf_data = (guint8 *) g_malloc (sizeof (guint8) * pixbuf_size * 3); + pixbuf_width = nXSize; + pixbuf_height = nYSize; + raster_width = adfGeoTransform[0] + + nXSize * adfGeoTransform[1] + + nYSize * adfGeoTransform[2]; + raster_width = ABS (raster_width - x); + raster_height = y + + nXSize * adfGeoTransform[4] + + nYSize * adfGeoTransform[5]; + raster_height = ABS (raster_height - y); + + pixbuf_size = pixbuf_width * pixbuf_height; + pixbuf_data = (guint8 *)g_malloc (sizeof (guint8) * pixbuf_size * 3); for (i = 0; i < pixbuf_size; i++) { @@ -517,13 +530,13 @@ static GList GDK_COLORSPACE_RGB, FALSE, 8, - (int)width, - (int)height, - (int)width * 3, + (int)pixbuf_width, + (int)pixbuf_height, + (int)pixbuf_width * 3, NULL, NULL); - geometry = gtk_gis_geometry_raster_new_from_pixbuf (pixbuf, x, y); + geometry = gtk_gis_geometry_raster_new_from_pixbuf (pixbuf, x, y, raster_width, raster_height); if (geometry != NULL) { -- 2.49.0