-
Notifications
You must be signed in to change notification settings - Fork 15
/
generate_macros_h
executable file
·326 lines (281 loc) · 6.52 KB
/
generate_macros_h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/bash
# LiquidRescaling Library
# Copyright (C) 2007-2009 Carlo Baldassi (the "Author") <[email protected]>.
# All Rights Reserved.
#
# This library implements the algorithm described in the paper
# "Seam Carving for Content-Aware Image Resizing"
# by Shai Avidan and Ariel Shamir
# which can be found at http://www.faculty.idc.ac.il/arik/imret.pdf
#
# This script is used to generate the file lqr/lqr_carver_macros_priv.h
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3 dated June, 2007.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
NMAX=5
OUTFILE="lqr/lqr_carver_macros_priv.h"
if [ "$1" == "--help" ]
then
echo "Usage: $(basename $0) N_MAX"
echo " default N_MAX = $NMAX"
exit 0
fi
[ -n "$1" ] && { NMAX=$1; shift; }
function fixed1
{
cat <<- EOF
/* LiquidRescaling Library
* Copyright (C) 2007-2009 Carlo Baldassi (the "Author") <[email protected]>.
* All Rights Reserved.
*
* This library implements the algorithm described in the paper
* "Seam Carving for Content-Aware Image Resizing"
* by Shai Avidan and Ariel Shamir
* which can be found at http://www.faculty.idc.ac.il/arik/imret.pdf
*
* This file was automatically generated.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 dated June, 2007.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
*/
/* Macros for update_mmap speedup : without rigidity */
#define DATADOWN(y, x) (r->raw[(y) - 1][(x)])
#define MDOWN(y, x) (r->m[DATADOWN((y), (x))])
#define MMIN01G(y, x) (least = DATADOWN((y), (x)), MDOWN((y), (x)))
#define MMINTESTL(y, x1, x2) (MDOWN((y), (x1)) <= MDOWN((y), (x2)))
#define MMINTESTR(y, x1, x2) (MDOWN((y), (x1)) < MDOWN((y), (x2)))
EOF
}
function pars
{
local A;
for A in $(seq 3 $1)
do
printf ", x%.2i" $A
done
}
function ppars
{
local A;
for A in $(seq 3 $1)
do
#echo -n ", (x${A})"
printf ", (x%.2i)" $A
done
}
function space
{
local A;
for A in $(seq $1 $2)
do
echo -n " "
done
}
function mming
{
local N N1
local TAG="$1"
echo -n "#define MMIN${TAG}01G(y, x01)";
space 1 $[NMAX - 1]
echo " MMIN01G((y), (x01))"
for N in $(seq 2 $NMAX)
do
N1=$[N - 1]
printf "#define MMIN${TAG}%.2iG(y, x01, x02" $N
#echo -n "#define MMIN${TAG}${N}G(y, x1, x2"
pars $N
echo -n ")"
space $N $[NMAX - 1]
printf " MMINTEST${TAG}((y), (x01), (x02)) ? MMIN${TAG}%.2iG((y), (x01)" $N1
ppars $N
printf ") : MMIN${TAG}%.2iG((y), (x02)" $N1
ppars $N
echo ")"
done
echo
}
function seqpars
{
local A
for A in $(seq 1 $1)
do
echo -n ", (x) + "
[ $NMAX -gt 10 -a $A -lt 10 ] && echo -n " "
echo -n "$A"
done
}
function mmin
{
local N
local TAG="$1"
for N in $(seq 1 $NMAX)
do
printf "#define MMIN${TAG}%.2i(y, x) MMIN${TAG}%.2iG((y), (x)" $N $N
seqpars $[N - 1]
echo ")"
done
echo
}
function fixed2
{
cat <<- EOF
/* Macros for update_mmap speedup : with rigidity */
#define MRDOWN(y, x, dx) (r->m[DATADOWN((y), (x))] + r_fact * r->rigidity_map[(dx)])
#define MRSET01(y, x, dx) (mc[(dx)] = MRDOWN((y), (x), (dx)))
EOF
}
function mrset
{
local N N1;
for N in $(seq 2 $NMAX)
do
N1=$[N - 1]
printf "#define MRSET%.2i(y, x, dx) (MRSET%.2i((y), (x), (dx)), MRSET01((y), (x) + " $N $N1
[ $NMAX -gt 10 -a $N1 -lt 10 ] && echo -n " "
echo -n "${N1}, (dx) + "
[ $NMAX -gt 10 -a $N1 -lt 10 ] && echo -n " "
echo "${N1}))"
done
echo
}
function fixed3
{
cat <<- EOF
#define MRMIN01G(y, x, dx) (least = DATADOWN((y), (x)), mc[(dx)])
#define MRMINTESTL(dx1, dx2) (mc[(dx1)] <= mc[(dx2)])
#define MRMINTESTR(dx1, dx2) (mc[(dx1)] < mc[(dx2)])
EOF
}
function rpars
{
local A;
for A in $(seq 3 $1)
do
printf ", x%.2i, dx%.2i" $A $A
done
}
function rppars
{
local A;
for A in $(seq 3 $1)
do
printf ", (x%.2i), (dx%.2i)" $A $A
done
}
function rspace
{
local A;
for A in $(seq $1 $2)
do
echo -n " "
done
}
function mrming
{
local N
local TAG="$1"
echo -n "#define MRMIN${TAG}01G(y, x01, dx01)";
rspace 1 $[NMAX - 1]
echo " MRMIN01G((y), (x01), (dx01))"
for N in $(seq 2 $NMAX)
do
N1=$[N - 1]
printf "#define MRMIN${TAG}%.2iG(y, x01, dx01, x02, dx02" $N
rpars $N
echo -n ")"
rspace $N $[NMAX - 1]
printf " MRMINTEST${TAG}((dx01), (dx02)) ? MRMIN${TAG}%.2iG((y), (x01), (dx01)" $N1
rppars $N
printf ") : MRMIN${TAG}%.2iG((y), (x02), (dx02)" $N1
rppars $N
echo ")"
done
echo
}
function rseqpars
{
local A
for A in $(seq 1 $1)
do
echo -n ", (x) + "
[ $NMAX -gt 10 -a $A -lt 10 ] && echo -n " "
echo -n "$A, (dx) + "
[ $NMAX -gt 10 -a $A -lt 10 ] && echo -n " "
echo -n "$A"
done
}
function mrmin
{
local N
local TAG="$1"
for N in $(seq 1 $NMAX)
do
printf "#define MRMIN${TAG}%.2i(y, x, dx) MRMIN${TAG}%.2iG((y), (x), (dx)" $N $N
rseqpars $[N - 1]
echo ")"
done
echo
}
function mcases
{
local N
echo "#define UPDATE_MMAP_OPTIMISED_CASES \\"
for N in $(seq 1 $NMAX)
do
echo " case $N: \\"
printf " m = r->leftright ? MMINR%.2i(y, x1_min) : MMINL%.2i(y, x1_min); \\\\\n" $N $N
printf " break;"
[ $N -lt $NMAX ] && echo -n " \\"
echo
done
echo
}
function mrcases
{
local N
echo "#define UPDATE_MMAP_OPTIMISED_CASES_RIG \\"
for N in $(seq 1 $NMAX)
do
echo " case $N: \\"
printf " MRSET%.2i(y, x1_min, dx); \\\\\n" $N
printf " m = r->leftright ? MRMINR%.2i(y, x1_min, dx) : MRMINL%.2i(y, x1_min, dx); \\\\\n" $N $N
printf " break;"
[ $N -lt $NMAX ] && echo -n " \\"
echo
done
echo
}
function print_all
{
fixed1
mming L
mming R
mmin L
mmin R
fixed2
mrset
fixed3
mrming L
mrming R
mrmin L
mrmin R
mcases
mrcases
}
print_all > $OUTFILE