1 /*
2  * * Copyright (C) 2006-2011 Anders Brander <anders@brander.dk>,
3  * * Anders Kvist <akv@lnxbx.dk> and Klaus Post <klauspost@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19 
20 #ifndef RS_PHOTO_H
21 #define RS_PHOTO_H
22 
23 #include "application.h"
24 #include <glib-object.h>
25 
26 #define RS_TYPE_PHOTO        (rs_photo_get_type ())
27 #define RS_PHOTO(obj)        (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_PHOTO, RS_PHOTO))
28 #define RS_PHOTO_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_PHOTO, RS_PHOTOClass))
29 #define RS_IS_PHOTO(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_PHOTO))
30 #define RS_IS_PHOTO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RS_TYPE_PHOTO))
31 #define RS_PHOTO_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), RS_TYPE_PHOTO, RS_PHOTOClass))
32 
33 typedef struct _RS_PHOTOClass RS_PHOTOClass;
34 
35 struct _RS_PHOTOClass {
36 	GObjectClass parent;
37 };
38 
39 GType rs_photo_get_type (void);
40 
41 /* Please note that this is not a bitmask */
42 enum {
43 	PRIO_U = 0,
44 	PRIO_D = 51,
45 	PRIO_1 = 1,
46 	PRIO_2 = 2,
47 	PRIO_3 = 3,
48 	PRIO_ALL = 255
49 };
50 
51 /**
52  * Allocates a new RS_PHOTO
53  * @return A new RS_PHOTO
54  */
55 extern RS_PHOTO *rs_photo_new(void);
56 
57 /**
58  * Rotates a RS_PHOTO
59  * @param photo A RS_PHOTO
60  * @param quarterturns How many quarters to turn
61  * @param angle The angle in degrees (360 is whole circle) to turn the image
62  */
63 extern void rs_photo_rotate(RS_PHOTO *photo, const gint quarterturns, const gdouble angle);
64 
65 /**
66  * Sets a new crop of a RS_PHOTO
67  * @param photo A RS_PHOTO
68  * @param crop The new crop or NULL to remove previous cropping
69  */
70 extern void rs_photo_set_crop(RS_PHOTO *photo, const RS_RECT *crop);
71 
72 /**
73  * Gets the crop of a RS_PHOTO
74  * @param photo A RS_PHOTO
75  * @return The crop as a RS_RECT or NULL if the photo is uncropped
76  */
77 extern RS_RECT *rs_photo_get_crop(RS_PHOTO *photo);
78 
79 /**
80  * Set the angle of a RS_PHOTO
81  * @param photo A RS_PHOTO
82  * @param angle The new angle
83  * @param relative If set to TRUE, angle will be relative to existing angle
84  */
85 extern void rs_photo_set_angle(RS_PHOTO *photo, gdouble angle, gboolean relative);
86 
87 /**
88  * Get the angle of a RS_PHOTO
89  * @param photo A RS_PHOTO
90  * @return The current angle
91  */
92 extern gdouble rs_photo_get_angle(RS_PHOTO *photo);
93 
94 /**
95  * Get the exposure of a RS_PHOTO
96  * @param photo A RS_PHOTO
97  * @param snapshot A snapshot
98  * @return The current value
99  */
100 extern gdouble rs_photo_get_exposure(RS_PHOTO *photo, const gint snapshot);
101 
102 /**
103  * Get the saturation of a RS_PHOTO
104  * @param photo A RS_PHOTO
105  * @param snapshot A snapshot
106  * @return The current value
107  */
108 extern gdouble rs_photo_get_saturation(RS_PHOTO *photo, const gint snapshot);
109 
110 /**
111  * Get the hue of a RS_PHOTO
112  * @param photo A RS_PHOTO
113  * @param snapshot A snapshot
114  * @return The current value
115  */
116 extern gdouble rs_photo_get_hue(RS_PHOTO *photo, const gint snapshot);
117 
118 /**
119  * Get the contrast of a RS_PHOTO
120  * @param photo A RS_PHOTO
121  * @param snapshot A snapshot
122  * @return The current value
123  */
124 extern gdouble rs_photo_get_contrast(RS_PHOTO *photo, const gint snapshot);
125 
126 /**
127  * Get the warmth of a RS_PHOTO
128  * @param photo A RS_PHOTO
129  * @param snapshot A snapshot
130  * @return The current value
131  */
132 extern gdouble rs_photo_get_warmth(RS_PHOTO *photo, const gint snapshot);
133 
134 /**
135  * Get the tint of a RS_PHOTO
136  * @param photo A RS_PHOTO
137  * @param snapshot A snapshot
138  * @return The current value
139  */
140 extern gdouble rs_photo_get_tint(RS_PHOTO *photo, const gint snapshot);
141 
142 /**
143  * Get the sharpen of a RS_PHOTO
144  * @param photo A RS_PHOTO
145  * @param snapshot A snapshot
146  * @return The current value
147  */
148 extern gdouble rs_photo_get_sharpen(RS_PHOTO *photo, const gint snapshot);
149 
150 /**
151  * Set the exposure of a RS_PHOTO
152  * @param photo A RS_PHOTO
153  * @param snapshot Which snapshot to affect
154  * @param value The new value
155  */
156 extern void rs_photo_set_exposure(RS_PHOTO *photo, const gint snapshot, const gdouble value);
157 
158 /**
159  * Set the saturation of a RS_PHOTO
160  * @param photo A RS_PHOTO
161  * @param snapshot Which snapshot to affect
162  * @param value The new value
163  */
164 extern void rs_photo_set_saturation(RS_PHOTO *photo, const gint snapshot, const gdouble value);
165 
166 /**
167  * Set the hue of a RS_PHOTO
168  * @param photo A RS_PHOTO
169  * @param snapshot Which snapshot to affect
170  * @param value The new value
171  */
172 extern void rs_photo_set_hue(RS_PHOTO *photo, const gint snapshot, const gdouble value);
173 
174 /**
175  * Set the contrast of a RS_PHOTO
176  * @param photo A RS_PHOTO
177  * @param snapshot Which snapshot to affect
178  * @param value The new value
179  */
180 extern void rs_photo_set_contrast(RS_PHOTO *photo, const gint snapshot, const gdouble value);
181 
182 /**
183  * Set the warmth of a RS_PHOTO
184  * @param photo A RS_PHOTO
185  * @param snapshot Which snapshot to affect
186  * @param value The new value
187  */
188 extern void rs_photo_set_warmth(RS_PHOTO *photo, const gint snapshot, const gdouble value);
189 
190 /**
191  * Set the tint of a RS_PHOTO
192  * @param photo A RS_PHOTO
193  * @param snapshot Which snapshot to affect
194  * @param value The new value
195  */
196 extern void rs_photo_set_tint(RS_PHOTO *photo, const gint snapshot, const gdouble value);
197 
198 /**
199  * Set the sharpen of a RS_PHOTO
200  * @param photo A RS_PHOTO
201  * @param snapshot Which snapshot to affect
202  * @param value The new value
203  */
204 extern void rs_photo_set_sharpen(RS_PHOTO *photo, const gint snapshot, const gdouble value);
205 
206 /**
207  * Apply settings to a RS_PHOTO from a RSSettings
208  * @param photo A RS_PHOTO
209  * @param snapshot Which snapshot to affect
210  * @param rs_settings The settings to apply
211  * @param mask A mask for defining which settings to apply
212  */
213 extern void rs_photo_apply_settings(RS_PHOTO *photo, const gint snapshot, RSSettings *settings, RSSettingsMask mask);
214 
215 /**
216  * Apply photo settings to a list of filters from an RSSettings
217  * @param photo A RS_PHOTO
218  * @param filters Which filters to apply the settings to
219  * @param snapshot Which snapshot to affect
220  */
221 extern void rs_photo_apply_to_filters(RS_PHOTO *photo, GList *filters, const gint snapshot);
222 
223 /**
224  * Flips a RS_PHOTO
225  * @param photo A RS_PHOTO
226  */
227 extern void rs_photo_flip(RS_PHOTO *photo);
228 
229 /**
230  * Mirrors a RS_PHOTO
231  * @param photo A RS_PHOTO
232  */
233 extern void rs_photo_mirror(RS_PHOTO *photo);
234 
235 /**
236  * Assign a DCP profile to a photo
237  * @param photo A RS_PHOTO
238  * @param dcp A DCP profile
239  */
240 extern void rs_photo_set_dcp_profile(RS_PHOTO *photo, RSDcpFile *dcp);
241 
242 /**
243  * Get the assigned DCP profile for a RS_PHOTO
244  * @param photo A RS_PHOTO
245  * @return A DCP profile or NULL
246  */
247 extern RSDcpFile *rs_photo_get_dcp_profile(RS_PHOTO *photo);
248 
249 /**
250  * Assign a ICC profile to a photo
251  * @param photo A RS_PHOTO
252  * @param dcp An ICC profile
253  */
254 extern void rs_photo_set_icc_profile(RS_PHOTO *photo, RSIccProfile *icc);
255 
256 /**
257  * Get the assigned ICC profile for a RS_PHOTO
258  * @param photo A RS_PHOTO
259  * @return An ICC profile or NULL
260  */
261 extern RSIccProfile *rs_photo_get_icc_profile(RS_PHOTO *photo);
262 
263 /**
264  * Sets the white balance of a RS_PHOTO using warmth and tint variables
265  * @param photo A RS_PHOTO
266  * @param snapshot Which snapshot to affect
267  * @param warmth
268  * @param tint
269  */
270 extern void rs_photo_set_wb_from_wt(RS_PHOTO *photo, const gint snapshot, const gdouble warmth, const gdouble tint);
271 
272 /**
273  * Sets the white balance of a RS_PHOTO using multipliers
274  * @param photo A RS_PHOTO
275  * @param snapshot Which snapshot to affect
276  * @param mul A pointer to an array of at least 3 multipliers
277  */
278 extern void rs_photo_set_wb_from_mul(RS_PHOTO *photo, const gint snapshot, const gdouble *mul, const gchar *ascii);
279 
280 /**
281  * Sets the white balance by neutralizing the colors provided
282  * @param photo A RS_PHOTO
283  * @param snapshot Which snapshot to affect
284  * @param r The red color
285  * @param g The green color
286  * @param b The blue color
287  */
288 extern void rs_photo_set_wb_from_color(RS_PHOTO *photo, const gint snapshot, const gdouble r, const gdouble g, const gdouble b);
289 
290 /**
291  * Autoadjust white balance of a RS_PHOTO using the greyworld algorithm
292  * @param photo A RS_PHOTO
293  * @param snapshot Which snapshot to affect
294  */
295 extern void rs_photo_set_wb_auto(RS_PHOTO *photo, const gint snapshot);
296 
297 /**
298  * Autoadjust white balance from the in-camera settings
299  * @param photo A RS_PHOTO
300  * @param snapshot Which snapshot to affect
301  * @return TRUE on success, FALSE on error
302  */
303 extern gboolean rs_photo_set_wb_from_camera(RS_PHOTO *photo, const gint snapshot);
304 
305 /**
306  * Get the metadata belonging to the RS_PHOTO
307  * @param photo A RS_PHOTO
308  * @return A RSMetadata, this must be unref'ed
309  */
310 extern RSMetadata *rs_photo_get_metadata(RS_PHOTO *photo);
311 
312 /**
313  * Closes a RS_PHOTO - this basically means saving cache
314  * @param photo A RS_PHOTO
315  */
316 extern void rs_photo_close(RS_PHOTO *photo);
317 
318 /**
319  * Indicate that the lens has changed.
320  * @param photo A RS_PHOTO
321  */
322 extern void rs_photo_lens_updated(RS_PHOTO *photo);
323 
324 /**
325  * Loads a photo in to a RS_PHOTO including metadata
326  * @param filename The filename to load
327  * @return A RS_PHOTO on success, NULL on error
328  */
329 extern RS_PHOTO *
330 rs_photo_load_from_file(const gchar *filename);
331 
332 /**
333  * Loads a photo in to a RS_PHOTO including metadata
334  * @param photo A RS_PHOTO
335  * @param rotated Set to TRUE to get the rotated sizes, FALSE to get the RAW size.
336  * @param width output variable that will be set to the width
337  * @param height output variable that will be set to the height
338  * @return A boolean, TRUE on success, false if no photo has been loaded
339  */
340 extern gboolean
341 rs_photo_get_original_size(RS_PHOTO *photo, gboolean rotated, gint* width, gint* height);
342 
343 extern void
344 rs_photo_rotate_rect_inverse(RS_PHOTO *photo, RS_RECT *coords);
345 
346 #endif /* RS_PHOTO_H */
347