Removed trailing whitespaces
[liblqr.git] / lqr / lqr_carver_list.c
blob2f1fe5d46c7dbb0bc469a2bea2d18caddcc2162b
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/>
23 #include <glib.h>
25 #include <lqr/lqr_all.h>
27 #ifdef __LQR_DEBUG__
28 #include <assert.h>
29 #endif /* __LQR_DEBUG__ */
32 /**** CARVER LIST FUNCTIONS ****/
34 LqrCarverList *
35 lqr_carver_list_append (LqrCarverList * list, LqrCarver * r)
37 LqrCarverList * prev = NULL;
38 LqrCarverList * now = list;
39 while (now != NULL)
41 prev = now;
42 now = now->next;
44 TRY_N_N (now = g_try_new(LqrCarverList, 1));
45 now->next = NULL;
46 now->current = r;
47 if (prev)
49 prev->next = now;
51 if (list == NULL)
53 return now;
55 else
57 return list;
61 void
62 lqr_carver_list_destroy(LqrCarverList * list)
64 LqrCarverList * now = list;
65 if (now != NULL)
67 lqr_carver_list_destroy(now->next);
68 lqr_carver_list_destroy(now->current->attached_list);
69 lqr_carver_destroy(now->current);
73 LQR_PUBLIC
74 LqrCarverList *
75 lqr_carver_list_start (LqrCarver *r)
77 return r->attached_list;
80 LQR_PUBLIC
81 LqrCarverList *
82 lqr_carver_list_next (LqrCarverList * list)
84 TRY_N_N (list);
85 return list->next;
88 LQR_PUBLIC
89 LqrCarver *
90 lqr_carver_list_current (LqrCarverList * list)
92 TRY_N_N (list);
93 return list->current;
96 LQR_PUBLIC
97 LqrRetVal
98 lqr_carver_list_foreach (LqrCarverList * list, LqrCarverFunc func, LqrDataTok data)
100 LqrCarverList * now = list;
101 if (now != NULL)
103 CATCH (func(now->current, data));
104 return lqr_carver_list_foreach (now->next, func, data);
106 return LQR_OK;
109 LQR_PUBLIC
110 LqrRetVal
111 lqr_carver_list_foreach_recursive (LqrCarverList * list, LqrCarverFunc func, LqrDataTok data)
113 LqrCarverList * now = list;
114 if (now != NULL)
116 CATCH (func(now->current, data));
117 CATCH (lqr_carver_list_foreach (now->current->attached_list, func, data));
118 return lqr_carver_list_foreach (now->next, func, data);
120 return LQR_OK;