1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  GThumb
5  *
6  *  Copyright (C) 2001, 2009, 2012 Free Software Foundation, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <glib.h>
23 #include "glib-utils.h"
24 #include "gth-image-task.h"
25 
26 
27 struct _GthImageTaskPrivate {
28 	GthImage *source;
29 	GthImage *destination;
30 };
31 
32 
G_DEFINE_TYPE_WITH_CODE(GthImageTask,gth_image_task,GTH_TYPE_ASYNC_TASK,G_ADD_PRIVATE (GthImageTask))33 G_DEFINE_TYPE_WITH_CODE (GthImageTask,
34 			 gth_image_task,
35 			 GTH_TYPE_ASYNC_TASK,
36 			 G_ADD_PRIVATE (GthImageTask))
37 
38 
39 static void
40 gth_image_task_finalize (GObject *object)
41 {
42 	GthImageTask *self;
43 
44 	g_return_if_fail (GTH_IS_IMAGE_TASK (object));
45 
46 	self = GTH_IMAGE_TASK (object);
47 	_g_object_unref (self->priv->source);
48 	_g_object_unref (self->priv->destination);
49 
50 	G_OBJECT_CLASS (gth_image_task_parent_class)->finalize (object);
51 }
52 
53 
54 static void
gth_image_task_class_init(GthImageTaskClass * class)55 gth_image_task_class_init (GthImageTaskClass *class)
56 {
57 	GObjectClass *object_class;
58 
59 	object_class = G_OBJECT_CLASS (class);
60 	object_class->finalize = gth_image_task_finalize;
61 }
62 
63 
64 static void
gth_image_task_init(GthImageTask * self)65 gth_image_task_init (GthImageTask *self)
66 {
67 	self->priv = gth_image_task_get_instance_private (self);
68 	self->priv->source = NULL;
69 	self->priv->destination = NULL;
70 }
71 
72 
73 GthTask *
gth_image_task_new(const char * description,GthAsyncInitFunc before_func,GthAsyncThreadFunc exec_func,GthAsyncReadyFunc after_func,gpointer user_data,GDestroyNotify user_data_destroy_func)74 gth_image_task_new (const char         *description,
75 		    GthAsyncInitFunc    before_func,
76 		    GthAsyncThreadFunc  exec_func,
77 		    GthAsyncReadyFunc   after_func,
78 		    gpointer            user_data,
79 		    GDestroyNotify      user_data_destroy_func)
80 {
81 	GthImageTask *self;
82 
83 	self = (GthImageTask *) g_object_new (GTH_TYPE_IMAGE_TASK,
84 					      "before-thread", before_func,
85 					      "thread-func", exec_func,
86 					      "after-thread", after_func,
87 					      "user-data", user_data,
88 					      "user-data-destroy-func", user_data_destroy_func,
89 					      "description", description,
90 					      NULL);
91 
92 	return (GthTask *) self;
93 }
94 
95 
96 void
gth_image_task_set_source(GthImageTask * self,GthImage * source)97 gth_image_task_set_source (GthImageTask *self,
98 			   GthImage     *source)
99 {
100 	_g_object_ref (source);
101 	_g_object_unref (self->priv->source);
102 	self->priv->source = source;
103 }
104 
105 
106 void
gth_image_task_set_source_surface(GthImageTask * self,cairo_surface_t * surface)107 gth_image_task_set_source_surface (GthImageTask    *self,
108 				   cairo_surface_t *surface)
109 {
110 	GthImage *image;
111 
112 	image = gth_image_new_for_surface (surface);
113 	gth_image_task_set_source (self, image);
114 
115 	g_object_unref (image);
116 }
117 
118 
119 GthImage *
gth_image_task_get_source(GthImageTask * self)120 gth_image_task_get_source (GthImageTask *self)
121 {
122 	return self->priv->source;
123 }
124 
125 
126 cairo_surface_t *
gth_image_task_get_source_surface(GthImageTask * self)127 gth_image_task_get_source_surface (GthImageTask *self)
128 {
129 	return gth_image_get_cairo_surface (self->priv->source);
130 }
131 
132 
133 void
gth_image_task_set_destination(GthImageTask * self,GthImage * destination)134 gth_image_task_set_destination (GthImageTask *self,
135 				GthImage     *destination)
136 {
137 	_g_object_ref (destination);
138 	_g_object_unref (self->priv->destination);
139 	self->priv->destination = destination;
140 }
141 
142 
143 void
gth_image_task_set_destination_surface(GthImageTask * self,cairo_surface_t * surface)144 gth_image_task_set_destination_surface (GthImageTask    *self,
145 					cairo_surface_t *surface)
146 {
147 	GthImage *image;
148 
149 	image = gth_image_new_for_surface (surface);
150 	gth_image_task_set_destination (self, image);
151 
152 	g_object_unref (image);
153 }
154 
155 
156 GthImage *
gth_image_task_get_destination(GthImageTask * self)157 gth_image_task_get_destination (GthImageTask *self)
158 {
159 	return self->priv->destination;
160 }
161 
162 
163 cairo_surface_t *
gth_image_task_get_destination_surface(GthImageTask * self)164 gth_image_task_get_destination_surface (GthImageTask *self)
165 {
166 	return gth_image_get_cairo_surface (self->priv->destination);
167 }
168 
169 
170 void
gth_image_task_copy_source_to_destination(GthImageTask * self)171 gth_image_task_copy_source_to_destination (GthImageTask *self)
172 {
173 	g_return_if_fail (self->priv->source != NULL);
174 
175 	_g_object_unref (self->priv->destination);
176 	self->priv->destination = gth_image_copy (self->priv->source);
177 }
178