1 /* LiquidRescaling Library
2 * Copyright (C) 2007-2009 Carlo Baldassi (the "Author") <carlobaldassi@gmail.com>.
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 <lqr/lqr_all.h>
27 #endif /* __LQR_DEBUG__ */
30 /**** SEAMS BUFFER FUNCTIONS ****/
34 lqr_vmap_new (gint
* buffer
, gint width
, gint height
, gint depth
, gint orientation
)
38 TRY_N_N (vmap
= g_try_new(LqrVMap
, 1));
39 vmap
->buffer
= buffer
;
41 vmap
->height
= height
;
42 vmap
->orientation
= orientation
;
49 lqr_vmap_destroy (LqrVMap
* vmap
)
51 g_free (vmap
->buffer
);
57 lqr_vmap_get_data (LqrVMap
*vmap
)
64 lqr_vmap_get_width (LqrVMap
*vmap
)
71 lqr_vmap_get_height (LqrVMap
*vmap
)
78 lqr_vmap_get_depth (LqrVMap
*vmap
)
85 lqr_vmap_get_orientation (LqrVMap
*vmap
)
87 return vmap
->orientation
;
90 /* dump the visibility level of the image */
93 lqr_vmap_dump (LqrCarver
* r
)
96 gint w
, h
, w1
, x
, y
, z0
, vs
;
100 /* save current size */
103 /* temporarily set the size to the original */
104 lqr_carver_set_width (r
, r
->w_start
);
106 w
= lqr_carver_get_width (r
);
107 h
= lqr_carver_get_height (r
);
108 depth
= r
->w0
- r
->w_start
;
110 TRY_N_N (buffer
= g_try_new (gint
, w
* h
));
112 lqr_cursor_reset (r
->c
);
113 for (y
= 0; y
< r
->h
; y
++)
115 for (x
= 0; x
< r
->w
; x
++)
117 vs
= r
->vs
[r
->c
->now
];
132 buffer
[z0
] = vs
- depth
;
134 lqr_cursor_next (r
->c
);
139 lqr_carver_set_width (r
, w1
);
140 lqr_cursor_reset (r
->c
);
142 TRY_N_N (vmap
= lqr_vmap_new(buffer
, w
, h
, depth
, r
->transposed
));
149 /* dump the visibility level of the image */
152 lqr_vmap_internal_dump (LqrCarver
* r
)
155 gint w
, h
, w1
, x
, y
, z0
, vs
;
161 /* save current size */
164 /* temporarily set the size to the original */
165 lqr_carver_set_width (r
, r
->w_start
);
167 w
= lqr_carver_get_width (r
);
168 h
= lqr_carver_get_height (r
);
169 depth
= r
->w0
- r
->w_start
;
171 CATCH_MEM (buffer
= g_try_new (gint
, w
* h
));
173 lqr_cursor_reset (r
->c
);
174 for (y
= 0; y
< r
->h
; y
++)
176 for (x
= 0; x
< r
->w
; x
++)
178 vs
= r
->vs
[r
->c
->now
];
193 buffer
[z0
] = vs
- depth
;
195 lqr_cursor_next (r
->c
);
200 lqr_carver_set_width (r
, w1
);
201 lqr_cursor_reset (r
->c
);
203 CATCH_MEM (vmap
= lqr_vmap_new(buffer
, w
, h
, depth
, r
->transposed
));
205 CATCH_MEM (r
->flushed_vs
= lqr_vmap_list_append(r
->flushed_vs
, vmap
));
213 lqr_vmap_load (LqrCarver
*r
, LqrVMap
*vmap
)
222 CATCH_F (!r
->active
);
226 CATCH_F ((r
->w_start
== w
) && (r
->h_start
== h
));
230 CATCH_F ((r
->w_start
== h
) && (r
->h_start
== w
));
233 CATCH (lqr_carver_flatten(r
));
235 if (vmap
->orientation
!= r
->transposed
)
237 CATCH (lqr_carver_transpose (r
));
240 for (y
= 0; y
< r
->h
; y
++)
242 for (x
= 0; x
< r
->w
; x
++)
254 r
->vs
[z1
] = vmap
->buffer
[z0
];
258 CATCH (lqr_carver_inflate(r
, vmap
->depth
));
260 lqr_cursor_reset (r
->c
);
262 lqr_carver_set_enl_step(r
, 2.0);