summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-31 18:02:37 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-31 18:50:53 +0200
commit1bbdf627f65a731be93dbbab386618e5e7ea7fd6 (patch)
tree44999b8eed840e50bf845e308381622caf89761c
parentc7599df4084d717087b3aee36e2ffb632c242d96 (diff)
downloadcv-1bbdf627f65a731be93dbbab386618e5e7ea7fd6.zip
cv-1bbdf627f65a731be93dbbab386618e5e7ea7fd6.tar.gz
cv-1bbdf627f65a731be93dbbab386618e5e7ea7fd6.tar.bz2
roi: Let marked_image always point to a valid pixbuf
Either by having an own backing storage or by being a reference to the input image.
-rw-r--r--roi.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/roi.c b/roi.c
index 213abc4..0b2e372 100644
--- a/roi.c
+++ b/roi.c
@@ -119,8 +119,7 @@ do_roi(struct roi *roi)
calc_roi_interval(roi, match);
g_object_unref(match);
- if (roi->marked_image)
- g_object_unref(roi->marked_image);
+ g_object_unref(roi->marked_image);
roi->marked_image = gdk_pixbuf_copy(roi->image);
mark_matching_pixels(roi, roi->marked_image);
@@ -186,11 +185,9 @@ key_event(GtkWidget *widget, GdkEventKey *event, gpointer userdata)
switch (event->keyval) {
case GDK_KEY_d:
case GDK_KEY_D:
- if (roi->marked_image) {
- g_object_unref(roi->marked_image);
- roi->marked_image = NULL;
- gtk_widget_queue_draw(roi->drawing_area);
- }
+ g_object_unref(roi->marked_image);
+ roi->marked_image = g_object_ref(roi->image);
+ gtk_widget_queue_draw(roi->drawing_area);
break;
case GDK_KEY_q:
case GDK_KEY_Q:
@@ -225,8 +222,7 @@ draw_cb(GtkWidget *widget, cairo_t *cr, gpointer userdata)
{
struct roi *roi = userdata;
- gdk_cairo_set_source_pixbuf(cr, roi->marked_image ?
- roi->marked_image : roi->image, 0, 0);
+ gdk_cairo_set_source_pixbuf(cr, roi->marked_image, 0, 0);
cairo_paint(cr);
if (roi->doing_rubberband)
@@ -249,6 +245,7 @@ main(int argc, char *argv[])
roi.image = gdk_pixbuf_new_from_file(argv[1], NULL);
if (!roi.image)
exit(EXIT_FAILURE);
+ roi.marked_image = g_object_ref(roi.image);
roi.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
roi.drawing_area = gtk_drawing_area_new();
@@ -278,8 +275,7 @@ main(int argc, char *argv[])
gtk_main();
g_object_unref(roi.image);
- if (roi.marked_image)
- g_object_unref(roi.marked_image);
+ g_object_unref(roi.marked_image);
return 0;
}