Release 0.3
[liblqr.git] / lqr / lqr_progress.c
blobf62c9c836cf6389860b4be7dc0f445ed4d58da88
1 /* LiquidRescaling Library
2 * Copyright (C) 2007-2009 Carlo Baldassi (the "Author") <carlobaldassi@gmail.com>.
3 * All Rights Reserved.
5 * This library implements the algorithm described in the paper
6 * "Seam Carving for Content-Aware Image Resizing"
7 * by Shai Avidan and Ariel Shamir
8 * which can be found at http://www.faculty.idc.ac.il/arik/imret.pdf
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; version 3 dated June, 2007.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>
24 #include <string.h>
25 #include <glib.h>
27 #include <lqr/lqr_base.h>
28 #include <lqr/lqr_progress.h>
30 LQR_PUBLIC
31 LqrProgress *
32 lqr_progress_new(void)
34 LqrProgress * progress;
35 TRY_N_N(progress = g_try_new0(LqrProgress, 1));
37 lqr_progress_set_init_width_message(progress, "Resizing width...");
38 lqr_progress_set_init_height_message(progress, "Resizing height...");
39 lqr_progress_set_end_width_message(progress, "done");
40 lqr_progress_set_end_height_message(progress, "done");
41 lqr_progress_set_update_step(progress, 0.02);
43 return progress;
46 LqrRetVal
47 lqr_progress_init(LqrProgress * p, const gchar * message)
49 CATCH_F (p != NULL);
50 if (p->init)
52 return p->init(message);
54 else
56 return LQR_OK;
60 LqrRetVal
61 lqr_progress_update(LqrProgress * p, gdouble percentage)
63 CATCH_F (p != NULL);
64 if (p->update)
66 return p->update(percentage);
68 else
70 return LQR_OK;
74 LqrRetVal
75 lqr_progress_end(LqrProgress * p, const gchar * message)
77 CATCH_F (p != NULL);
78 if (p->end)
80 return p->end(message);
82 else
84 return LQR_OK;
88 LQR_PUBLIC
89 LqrRetVal
90 lqr_progress_set_init(LqrProgress * p, LqrProgressFuncInit init_func)
92 p->init = init_func;
93 return LQR_OK;
96 LQR_PUBLIC
97 LqrRetVal
98 lqr_progress_set_update(LqrProgress * p, LqrProgressFuncUpdate update_func)
100 p->update = update_func;
101 return LQR_OK;
104 LQR_PUBLIC
105 LqrRetVal
106 lqr_progress_set_end(LqrProgress * p, LqrProgressFuncEnd end_func)
108 p->end = end_func;
109 return LQR_OK;
112 LQR_PUBLIC
113 LqrRetVal
114 lqr_progress_set_update_step (LqrProgress *p, gfloat update_step)
116 p->update_step = update_step;
117 return LQR_OK;
120 LQR_PUBLIC
121 LqrRetVal
122 lqr_progress_set_init_width_message(LqrProgress *p, const gchar * message)
124 CATCH_F (p);
125 strncpy(p->init_width_message, message, LQR_PROGRESS_MAX_MESSAGE_LENGTH);
126 return LQR_OK;
129 LQR_PUBLIC
130 LqrRetVal
131 lqr_progress_set_init_height_message(LqrProgress *p, const gchar * message)
133 CATCH_F (p != NULL);
134 strncpy(p->init_height_message, message, LQR_PROGRESS_MAX_MESSAGE_LENGTH);
135 return LQR_OK;
138 LQR_PUBLIC
139 LqrRetVal
140 lqr_progress_set_end_width_message(LqrProgress *p, const gchar * message)
142 CATCH_F (p != NULL);
143 strncpy(p->end_width_message, message, LQR_PROGRESS_MAX_MESSAGE_LENGTH);
144 return LQR_OK;
147 LQR_PUBLIC
148 LqrRetVal
149 lqr_progress_set_end_height_message(LqrProgress *p, const gchar * message)
151 CATCH_F (p != NULL);
152 strncpy(p->end_height_message, message, LQR_PROGRESS_MAX_MESSAGE_LENGTH);
153 return LQR_OK;