~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to core/libs/3rdparty/lqr/lqr_vmap.c

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LiquidRescaling Library
 
2
 * Copyright (C) 2007-2009 Carlo Baldassi (the "Author") <carlobaldassi@gmail.com>.
 
3
 * All Rights Reserved.
 
4
 *
 
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
 
9
 *
 
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.
 
13
 
 
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.
 
18
 
 
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/>
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#  include <config.h>
 
25
#endif
 
26
 
 
27
#include <lqr/lqr_all.h>
 
28
 
 
29
#ifdef __LQR_DEBUG__
 
30
#include <assert.h>
 
31
#endif /* __LQR_DEBUG__ */
 
32
 
 
33
/**** SEAMS BUFFER FUNCTIONS ****/
 
34
 
 
35
/* LQR_PUBLIC */
 
36
LqrVMap *
 
37
lqr_vmap_new(gint *buffer, gint width, gint height, gint depth, gint orientation)
 
38
{
 
39
    LqrVMap *vmap;
 
40
 
 
41
    LQR_TRY_N_N(vmap = g_try_new(LqrVMap, 1));
 
42
    vmap->buffer = buffer;
 
43
    vmap->width = width;
 
44
    vmap->height = height;
 
45
    vmap->orientation = orientation;
 
46
    vmap->depth = depth;
 
47
    return vmap;
 
48
}
 
49
 
 
50
/* LQR_PUBLIC */
 
51
void
 
52
lqr_vmap_destroy(LqrVMap *vmap)
 
53
{
 
54
    g_free(vmap->buffer);
 
55
    g_free(vmap);
 
56
}
 
57
 
 
58
/* LQR_PUBLIC */
 
59
gint *
 
60
lqr_vmap_get_data(LqrVMap *vmap)
 
61
{
 
62
    return vmap->buffer;
 
63
}
 
64
 
 
65
/* LQR_PUBLIC */
 
66
gint
 
67
lqr_vmap_get_width(LqrVMap *vmap)
 
68
{
 
69
    return vmap->width;
 
70
}
 
71
 
 
72
/* LQR_PUBLIC */
 
73
gint
 
74
lqr_vmap_get_height(LqrVMap *vmap)
 
75
{
 
76
    return vmap->height;
 
77
}
 
78
 
 
79
/* LQR_PUBLIC */
 
80
gint
 
81
lqr_vmap_get_depth(LqrVMap *vmap)
 
82
{
 
83
    return vmap->depth;
 
84
}
 
85
 
 
86
/* LQR_PUBLIC */
 
87
gint
 
88
lqr_vmap_get_orientation(LqrVMap *vmap)
 
89
{
 
90
    return vmap->orientation;
 
91
}
 
92
 
 
93
/* dump the visibility level of the image */
 
94
/* LQR_PUBLIC */
 
95
LqrVMap *
 
96
lqr_vmap_dump(LqrCarver *r)
 
97
{
 
98
    LqrVMap *vmap;
 
99
    gint w, h, w1, x, y, z0, vs;
 
100
    gint *buffer;
 
101
    gint depth;
 
102
 
 
103
    /* save current size */
 
104
    w1 = r->w;
 
105
 
 
106
    /* temporarily set the size to the original */
 
107
    lqr_carver_set_width(r, r->w_start);
 
108
 
 
109
    w = lqr_carver_get_width(r);
 
110
    h = lqr_carver_get_height(r);
 
111
    depth = r->w0 - r->w_start;
 
112
 
 
113
    LQR_TRY_N_N(buffer = g_try_new(gint, w * h));
 
114
 
 
115
    lqr_cursor_reset(r->c);
 
116
    for (y = 0; y < r->h; y++) {
 
117
        for (x = 0; x < r->w; x++) {
 
118
            vs = r->vs[r->c->now];
 
119
            if (!r->transposed) {
 
120
                z0 = y * r->w + x;
 
121
            } else {
 
122
                z0 = x * r->h + y;
 
123
            }
 
124
            if (vs == 0) {
 
125
                buffer[z0] = 0;
 
126
            } else {
 
127
                buffer[z0] = vs - depth;
 
128
            }
 
129
            lqr_cursor_next(r->c);
 
130
        }
 
131
    }
 
132
 
 
133
    /* recover size */
 
134
    lqr_carver_set_width(r, w1);
 
135
    lqr_cursor_reset(r->c);
 
136
 
 
137
    LQR_TRY_N_N(vmap = lqr_vmap_new(buffer, w, h, depth, r->transposed));
 
138
 
 
139
    return vmap;
 
140
}
 
141
 
 
142
/* dump the visibility level of the image */
 
143
/* LQR_PUBLIC */
 
144
LqrRetVal
 
145
lqr_vmap_internal_dump(LqrCarver *r)
 
146
{
 
147
    LqrVMap *vmap;
 
148
    gint w, h, w1, x, y, z0, vs;
 
149
    gint *buffer;
 
150
    gint depth;
 
151
 
 
152
    LQR_CATCH_CANC(r);
 
153
 
 
154
    /* save current size */
 
155
    w1 = r->w;
 
156
 
 
157
    /* temporarily set the size to the original */
 
158
    lqr_carver_set_width(r, r->w_start);
 
159
 
 
160
    w = lqr_carver_get_width(r);
 
161
    h = lqr_carver_get_height(r);
 
162
    depth = r->w0 - r->w_start;
 
163
 
 
164
    LQR_CATCH_MEM(buffer = g_try_new(gint, w * h));
 
165
 
 
166
    lqr_cursor_reset(r->c);
 
167
    for (y = 0; y < r->h; y++) {
 
168
        for (x = 0; x < r->w; x++) {
 
169
            vs = r->vs[r->c->now];
 
170
            if (!r->transposed) {
 
171
                z0 = y * r->w + x;
 
172
            } else {
 
173
                z0 = x * r->h + y;
 
174
            }
 
175
            if (vs == 0) {
 
176
                buffer[z0] = 0;
 
177
            } else {
 
178
                buffer[z0] = vs - depth;
 
179
            }
 
180
            lqr_cursor_next(r->c);
 
181
        }
 
182
    }
 
183
 
 
184
    /* recover size */
 
185
    lqr_carver_set_width(r, w1);
 
186
    lqr_cursor_reset(r->c);
 
187
 
 
188
    LQR_CATCH_MEM(vmap = lqr_vmap_new(buffer, w, h, depth, r->transposed));
 
189
 
 
190
    LQR_CATCH_MEM(r->flushed_vs = lqr_vmap_list_append(r->flushed_vs, vmap));
 
191
 
 
192
    return LQR_OK;
 
193
}
 
194
 
 
195
/* LQR_PUBLIC */
 
196
LqrRetVal
 
197
lqr_vmap_load(LqrCarver *r, LqrVMap *vmap)
 
198
{
 
199
    gint w, h;
 
200
    gint x, y, z0, z1;
 
201
 
 
202
    w = vmap->width;
 
203
    h = vmap->height;
 
204
 
 
205
    LQR_CATCH_CANC(r);
 
206
    LQR_CATCH_F(!r->active);
 
207
 
 
208
    if (!r->transposed) {
 
209
        LQR_CATCH_F((r->w_start == w) && (r->h_start == h));
 
210
    } else {
 
211
        LQR_CATCH_F((r->w_start == h) && (r->h_start == w));
 
212
    }
 
213
 
 
214
    LQR_CATCH(lqr_carver_flatten(r));
 
215
 
 
216
    if (vmap->orientation != r->transposed) {
 
217
        LQR_CATCH(lqr_carver_transpose(r));
 
218
    }
 
219
 
 
220
    for (y = 0; y < r->h; y++) {
 
221
        for (x = 0; x < r->w; x++) {
 
222
            if (!r->transposed) {
 
223
                z0 = y * r->w + x;
 
224
            } else {
 
225
                z0 = x * r->h + y;
 
226
            }
 
227
            z1 = y * r->w + x;
 
228
 
 
229
            r->vs[z1] = vmap->buffer[z0];
 
230
        }
 
231
    }
 
232
 
 
233
    LQR_CATCH(lqr_carver_inflate(r, vmap->depth));
 
234
 
 
235
    lqr_cursor_reset(r->c);
 
236
 
 
237
    lqr_carver_set_enl_step(r, 2.0);
 
238
 
 
239
    return LQR_OK;
 
240
}