FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/jpeg2000dwt.c
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 345 356 96.9%
Branches: 208 216 96.3%

Line Branch Exec Source
1 /*
2 * Discrete wavelet transform
3 * Copyright (c) 2007 Kamil Nowosad
4 * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Discrete wavelet transform
26 */
27
28 #include "libavutil/common.h"
29 #include "libavutil/mem.h"
30 #include "jpeg2000dwt.h"
31 #include "internal.h"
32
33 /* Defines for 9/7 DWT lifting parameters.
34 * Parameters are in float. */
35 #define F_LFTG_ALPHA 1.586134342059924f
36 #define F_LFTG_BETA 0.052980118572961f
37 #define F_LFTG_GAMMA 0.882911075530934f
38 #define F_LFTG_DELTA 0.443506852043971f
39
40 /* Lifting parameters in integer format.
41 * Computed as param = (float param) * (1 << 16) */
42 #define I_LFTG_ALPHA 103949ll
43 #define I_LFTG_BETA 3472ll
44 #define I_LFTG_GAMMA 57862ll
45 #define I_LFTG_DELTA 29066ll
46 #define I_LFTG_K 80621ll
47 #define I_LFTG_X 53274ll
48 #define I_PRESHIFT 8
49
50 2335465 static inline void extend53(int *p, int i0, int i1)
51 {
52 2335465 p[i0 - 1] = p[i0 + 1];
53 2335465 p[i1] = p[i1 - 2];
54 2335465 p[i0 - 2] = p[i0 + 2];
55 2335465 p[i1 + 1] = p[i1 - 3];
56 2335465 }
57
58 53036 static inline void extend97_float(float *p, int i0, int i1)
59 {
60 int i;
61
62
2/2
✓ Branch 0 taken 212144 times.
✓ Branch 1 taken 53036 times.
265180 for (i = 1; i <= 4; i++) {
63 212144 p[i0 - i] = p[i0 + i];
64 212144 p[i1 + i - 1] = p[i1 - i - 1];
65 }
66 53036 }
67
68 2387782 static inline void extend97_int(int32_t *p, int i0, int i1)
69 {
70 int i;
71
72
2/2
✓ Branch 0 taken 9551128 times.
✓ Branch 1 taken 2387782 times.
11938910 for (i = 1; i <= 4; i++) {
73 9551128 p[i0 - i] = p[i0 + i];
74 9551128 p[i1 + i - 1] = p[i1 - i - 1];
75 }
76 2387782 }
77
78 1161290 static void sd_1d53(int *p, int i0, int i1)
79 {
80 int i;
81
82
2/2
✓ Branch 0 taken 5058 times.
✓ Branch 1 taken 1156232 times.
1161290 if (i1 <= i0 + 1) {
83
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 4994 times.
5058 if (i0 == 1)
84 64 p[1] <<= 1;
85 5058 return;
86 }
87
88 1156232 extend53(p, i0, i1);
89
90
2/2
✓ Branch 0 taken 62402201 times.
✓ Branch 1 taken 1156232 times.
63558433 for (i = ((i0+1)>>1) - 1; i < (i1+1)>>1; i++)
91 62402201 p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1;
92
2/2
✓ Branch 0 taken 61245969 times.
✓ Branch 1 taken 1156232 times.
62402201 for (i = ((i0+1)>>1); i < (i1+1)>>1; i++)
93 61245969 p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2;
94 }
95
96 1970 static void dwt_encode53(DWTContext *s, int *t)
97 {
98 int lev,
99 1970 w = s->linelen[s->ndeclevels-1][0];
100 1970 int *line = s->i_linebuf;
101 1970 line += 3;
102
103
2/2
✓ Branch 0 taken 12038 times.
✓ Branch 1 taken 1970 times.
14008 for (lev = s->ndeclevels-1; lev >= 0; lev--){
104 12038 int lh = s->linelen[lev][0],
105 12038 lv = s->linelen[lev][1],
106 12038 mh = s->mod[lev][0],
107 12038 mv = s->mod[lev][1],
108 lp;
109 int *l;
110
111 // VER_SD
112 12038 l = line + mv;
113
2/2
✓ Branch 0 taken 636876 times.
✓ Branch 1 taken 12038 times.
648914 for (lp = 0; lp < lh; lp++) {
114 636876 int i, j = 0;
115
116
2/2
✓ Branch 0 taken 61241397 times.
✓ Branch 1 taken 636876 times.
61878273 for (i = 0; i < lv; i++)
117 61241397 l[i] = t[w*i + lp];
118
119 636876 sd_1d53(line, mv, mv + lv);
120
121 // copy back and deinterleave
122
2/2
✓ Branch 0 taken 30625716 times.
✓ Branch 1 taken 636876 times.
31262592 for (i = mv; i < lv; i+=2, j++)
123 30625716 t[w*j + lp] = l[i];
124
2/2
✓ Branch 0 taken 30615681 times.
✓ Branch 1 taken 636876 times.
31252557 for (i = 1-mv; i < lv; i+=2, j++)
125 30615681 t[w*j + lp] = l[i];
126 }
127
128 // HOR_SD
129 12038 l = line + mh;
130
2/2
✓ Branch 0 taken 524414 times.
✓ Branch 1 taken 12038 times.
536452 for (lp = 0; lp < lv; lp++){
131 524414 int i, j = 0;
132
133
2/2
✓ Branch 0 taken 61241397 times.
✓ Branch 1 taken 524414 times.
61765811 for (i = 0; i < lh; i++)
134 61241397 l[i] = t[w*lp + i];
135
136 524414 sd_1d53(line, mh, mh + lh);
137
138 // copy back and deinterleave
139
2/2
✓ Branch 0 taken 30625229 times.
✓ Branch 1 taken 524414 times.
31149643 for (i = mh; i < lh; i+=2, j++)
140 30625229 t[w*lp + j] = l[i];
141
2/2
✓ Branch 0 taken 30616168 times.
✓ Branch 1 taken 524414 times.
31140582 for (i = 1-mh; i < lh; i+=2, j++)
142 30616168 t[w*lp + j] = l[i];
143 }
144 }
145 1970 }
146 6290 static void sd_1d97_float(float *p, int i0, int i1)
147 {
148 int i;
149
150
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 6182 times.
6290 if (i1 <= i0 + 1) {
151
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 44 times.
108 if (i0 == 1)
152 64 p[1] *= F_LFTG_X * 2;
153 else
154 44 p[0] *= F_LFTG_K;
155 108 return;
156 }
157
158 6182 extend97_float(p, i0, i1);
159 6182 i0++; i1++;
160
161
2/2
✓ Branch 0 taken 214515 times.
✓ Branch 1 taken 6182 times.
220697 for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
162 214515 p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]);
163
2/2
✓ Branch 0 taken 208333 times.
✓ Branch 1 taken 6182 times.
214515 for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
164 208333 p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]);
165
2/2
✓ Branch 0 taken 202151 times.
✓ Branch 1 taken 6182 times.
208333 for (i = (i0>>1) - 1; i < (i1>>1); i++)
166 202151 p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]);
167
2/2
✓ Branch 0 taken 195969 times.
✓ Branch 1 taken 6182 times.
202151 for (i = (i0>>1); i < (i1>>1); i++)
168 195969 p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]);
169 }
170
171 20 static void dwt_encode97_float(DWTContext *s, float *t)
172 {
173 int lev,
174 20 w = s->linelen[s->ndeclevels-1][0];
175 20 float *line = s->f_linebuf;
176 20 line += 5;
177
178
2/2
✓ Branch 0 taken 338 times.
✓ Branch 1 taken 20 times.
358 for (lev = s->ndeclevels-1; lev >= 0; lev--){
179 338 int lh = s->linelen[lev][0],
180 338 lv = s->linelen[lev][1],
181 338 mh = s->mod[lev][0],
182 338 mv = s->mod[lev][1],
183 lp;
184 float *l;
185
186 // HOR_SD
187 338 l = line + mh;
188
2/2
✓ Branch 0 taken 3614 times.
✓ Branch 1 taken 338 times.
3952 for (lp = 0; lp < lv; lp++){
189 3614 int i, j = 0;
190
191
2/2
✓ Branch 0 taken 196047 times.
✓ Branch 1 taken 3614 times.
199661 for (i = 0; i < lh; i++)
192 196047 l[i] = t[w*lp + i];
193
194 3614 sd_1d97_float(line, mh, mh + lh);
195
196 // copy back and deinterleave
197
2/2
✓ Branch 0 taken 97979 times.
✓ Branch 1 taken 3614 times.
101593 for (i = mh; i < lh; i+=2, j++)
198 97979 t[w*lp + j] = l[i];
199
2/2
✓ Branch 0 taken 98068 times.
✓ Branch 1 taken 3614 times.
101682 for (i = 1-mh; i < lh; i+=2, j++)
200 98068 t[w*lp + j] = l[i];
201 }
202
203 // VER_SD
204 338 l = line + mv;
205
2/2
✓ Branch 0 taken 2676 times.
✓ Branch 1 taken 338 times.
3014 for (lp = 0; lp < lh; lp++) {
206 2676 int i, j = 0;
207
208
2/2
✓ Branch 0 taken 196047 times.
✓ Branch 1 taken 2676 times.
198723 for (i = 0; i < lv; i++)
209 196047 l[i] = t[w*i + lp];
210
211 2676 sd_1d97_float(line, mv, mv + lv);
212
213 // copy back and deinterleave
214
2/2
✓ Branch 0 taken 98016 times.
✓ Branch 1 taken 2676 times.
100692 for (i = mv; i < lv; i+=2, j++)
215 98016 t[w*j + lp] = l[i];
216
2/2
✓ Branch 0 taken 98031 times.
✓ Branch 1 taken 2676 times.
100707 for (i = 1-mv; i < lv; i+=2, j++)
217 98031 t[w*j + lp] = l[i];
218 }
219 }
220 20 }
221
222 1161290 static void sd_1d97_int(int *p, int i0, int i1)
223 {
224 int i;
225
226
2/2
✓ Branch 0 taken 5058 times.
✓ Branch 1 taken 1156232 times.
1161290 if (i1 <= i0 + 1) {
227
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 4994 times.
5058 if (i0 == 1)
228 64 p[1] = (p[1] * I_LFTG_X + (1<<14)) >> 15;
229 else
230 4994 p[0] = (p[0] * I_LFTG_K + (1<<15)) >> 16;
231 5058 return;
232 }
233
234 1156232 extend97_int(p, i0, i1);
235 1156232 i0++; i1++;
236
237
2/2
✓ Branch 0 taken 64714665 times.
✓ Branch 1 taken 1156232 times.
65870897 for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
238 64714665 p[2 * i + 1] -= (I_LFTG_ALPHA * (p[2 * i] + p[2 * i + 2]) + (1 << 15)) >> 16;
239
2/2
✓ Branch 0 taken 63558433 times.
✓ Branch 1 taken 1156232 times.
64714665 for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
240 63558433 p[2 * i] -= (I_LFTG_BETA * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
241
2/2
✓ Branch 0 taken 62402201 times.
✓ Branch 1 taken 1156232 times.
63558433 for (i = (i0>>1) - 1; i < (i1>>1); i++)
242 62402201 p[2 * i + 1] += (I_LFTG_GAMMA * (p[2 * i] + p[2 * i + 2]) + (1 << 15)) >> 16;
243
2/2
✓ Branch 0 taken 61245969 times.
✓ Branch 1 taken 1156232 times.
62402201 for (i = (i0>>1); i < (i1>>1); i++)
244 61245969 p[2 * i] += (I_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
245 }
246
247 1970 static void dwt_encode97_int(DWTContext *s, int *t)
248 {
249 int lev;
250 1970 int w = s->linelen[s->ndeclevels-1][0];
251 1970 int h = s->linelen[s->ndeclevels-1][1];
252 int i;
253 1970 int *line = s->i_linebuf;
254 1970 line += 5;
255
256
2/2
✓ Branch 0 taken 45940533 times.
✓ Branch 1 taken 1970 times.
45942503 for (i = 0; i < w * h; i++)
257 45940533 t[i] *= 1 << I_PRESHIFT;
258
259
2/2
✓ Branch 0 taken 12038 times.
✓ Branch 1 taken 1970 times.
14008 for (lev = s->ndeclevels-1; lev >= 0; lev--){
260 12038 int lh = s->linelen[lev][0],
261 12038 lv = s->linelen[lev][1],
262 12038 mh = s->mod[lev][0],
263 12038 mv = s->mod[lev][1],
264 lp;
265 int *l;
266
267 // VER_SD
268 12038 l = line + mv;
269
2/2
✓ Branch 0 taken 636876 times.
✓ Branch 1 taken 12038 times.
648914 for (lp = 0; lp < lh; lp++) {
270 636876 int i, j = 0;
271
272
2/2
✓ Branch 0 taken 61241397 times.
✓ Branch 1 taken 636876 times.
61878273 for (i = 0; i < lv; i++)
273 61241397 l[i] = t[w*i + lp];
274
275 636876 sd_1d97_int(line, mv, mv + lv);
276
277 // copy back and deinterleave
278
2/2
✓ Branch 0 taken 30625716 times.
✓ Branch 1 taken 636876 times.
31262592 for (i = mv; i < lv; i+=2, j++)
279 30625716 t[w*j + lp] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16;
280
2/2
✓ Branch 0 taken 30615681 times.
✓ Branch 1 taken 636876 times.
31252557 for (i = 1-mv; i < lv; i+=2, j++)
281 30615681 t[w*j + lp] = l[i];
282 }
283
284 // HOR_SD
285 12038 l = line + mh;
286
2/2
✓ Branch 0 taken 524414 times.
✓ Branch 1 taken 12038 times.
536452 for (lp = 0; lp < lv; lp++){
287 524414 int i, j = 0;
288
289
2/2
✓ Branch 0 taken 61241397 times.
✓ Branch 1 taken 524414 times.
61765811 for (i = 0; i < lh; i++)
290 61241397 l[i] = t[w*lp + i];
291
292 524414 sd_1d97_int(line, mh, mh + lh);
293
294 // copy back and deinterleave
295
2/2
✓ Branch 0 taken 30625229 times.
✓ Branch 1 taken 524414 times.
31149643 for (i = mh; i < lh; i+=2, j++)
296 30625229 t[w*lp + j] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16;
297
2/2
✓ Branch 0 taken 30616168 times.
✓ Branch 1 taken 524414 times.
31140582 for (i = 1-mh; i < lh; i+=2, j++)
298 30616168 t[w*lp + j] = l[i];
299 }
300
301 }
302
303
2/2
✓ Branch 0 taken 45940533 times.
✓ Branch 1 taken 1970 times.
45942503 for (i = 0; i < w * h; i++)
304 45940533 t[i] = (t[i] + ((1<<I_PRESHIFT)>>1)) >> I_PRESHIFT;
305 1970 }
306
307 1184390 static void sr_1d53(unsigned *p, int i0, int i1)
308 {
309 int i;
310
311
2/2
✓ Branch 0 taken 5157 times.
✓ Branch 1 taken 1179233 times.
1184390 if (i1 <= i0 + 1) {
312
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 5093 times.
5157 if (i0 == 1)
313 64 p[1] = (int)p[1] >> 1;
314 5157 return;
315 }
316
317 1179233 extend53(p, i0, i1);
318
319
2/2
✓ Branch 0 taken 63631743 times.
✓ Branch 1 taken 1179233 times.
64810976 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
320 63631743 p[2 * i] -= (int)(p[2 * i - 1] + p[2 * i + 1] + 2) >> 2;
321
2/2
✓ Branch 0 taken 62452510 times.
✓ Branch 1 taken 1179233 times.
63631743 for (i = (i0 >> 1); i < (i1 >> 1); i++)
322 62452510 p[2 * i + 1] += (int)(p[2 * i] + p[2 * i + 2]) >> 1;
323 }
324
325 2009 static void dwt_decode53(DWTContext *s, int *t)
326 {
327 int lev;
328 2009 int w = s->linelen[s->ndeclevels - 1][0];
329 2009 int32_t *line = s->i_linebuf;
330 2009 line += 3;
331
332
2/2
✓ Branch 0 taken 12272 times.
✓ Branch 1 taken 2009 times.
14281 for (lev = 0; lev < s->ndeclevels; lev++) {
333 12272 int lh = s->linelen[lev][0],
334 12272 lv = s->linelen[lev][1],
335 12272 mh = s->mod[lev][0],
336 12272 mv = s->mod[lev][1],
337 lp;
338 int *l;
339
340 // HOR_SD
341 12272 l = line + mh;
342
2/2
✓ Branch 0 taken 534830 times.
✓ Branch 1 taken 12272 times.
547102 for (lp = 0; lp < lv; lp++) {
343 534830 int i, j = 0;
344 // copy with interleaving
345
2/2
✓ Branch 0 taken 31235774 times.
✓ Branch 1 taken 534830 times.
31770604 for (i = mh; i < lh; i += 2, j++)
346 31235774 l[i] = t[w * lp + j];
347
2/2
✓ Branch 0 taken 31226530 times.
✓ Branch 1 taken 534830 times.
31761360 for (i = 1 - mh; i < lh; i += 2, j++)
348 31226530 l[i] = t[w * lp + j];
349
350 534830 sr_1d53(line, mh, mh + lh);
351
352
2/2
✓ Branch 0 taken 62462304 times.
✓ Branch 1 taken 534830 times.
62997134 for (i = 0; i < lh; i++)
353 62462304 t[w * lp + i] = l[i];
354 }
355
356 // VER_SD
357 12272 l = line + mv;
358
2/2
✓ Branch 0 taken 649560 times.
✓ Branch 1 taken 12272 times.
661832 for (lp = 0; lp < lh; lp++) {
359 649560 int i, j = 0;
360 // copy with interleaving
361
2/2
✓ Branch 0 taken 31236270 times.
✓ Branch 1 taken 649560 times.
31885830 for (i = mv; i < lv; i += 2, j++)
362 31236270 l[i] = t[w * j + lp];
363
2/2
✓ Branch 0 taken 31226034 times.
✓ Branch 1 taken 649560 times.
31875594 for (i = 1 - mv; i < lv; i += 2, j++)
364 31226034 l[i] = t[w * j + lp];
365
366 649560 sr_1d53(line, mv, mv + lv);
367
368
2/2
✓ Branch 0 taken 62462304 times.
✓ Branch 1 taken 649560 times.
63111864 for (i = 0; i < lv; i++)
369 62462304 t[w * i + lp] = l[i];
370 }
371 }
372 2009 }
373
374 46962 static void sr_1d97_float(float *p, int i0, int i1)
375 {
376 int i;
377
378
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 46854 times.
46962 if (i1 <= i0 + 1) {
379
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 44 times.
108 if (i0 == 1)
380 64 p[1] *= F_LFTG_K/2;
381 else
382 44 p[0] *= F_LFTG_X;
383 108 return;
384 }
385
386 46854 extend97_float(p, i0, i1);
387
388
2/2
✓ Branch 0 taken 12907231 times.
✓ Branch 1 taken 46854 times.
12954085 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
389 12907231 p[2 * i] -= F_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]);
390 /* step 4 */
391
2/2
✓ Branch 0 taken 12860377 times.
✓ Branch 1 taken 46854 times.
12907231 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
392 12860377 p[2 * i + 1] -= F_LFTG_GAMMA * (p[2 * i] + p[2 * i + 2]);
393 /*step 5*/
394
2/2
✓ Branch 0 taken 12813523 times.
✓ Branch 1 taken 46854 times.
12860377 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
395 12813523 p[2 * i] += F_LFTG_BETA * (p[2 * i - 1] + p[2 * i + 1]);
396 /* step 6 */
397
2/2
✓ Branch 0 taken 12766669 times.
✓ Branch 1 taken 46854 times.
12813523 for (i = (i0 >> 1); i < (i1 >> 1); i++)
398 12766669 p[2 * i + 1] += F_LFTG_ALPHA * (p[2 * i] + p[2 * i + 2]);
399 }
400
401 28 static void dwt_decode97_float(DWTContext *s, float *t)
402 {
403 int lev;
404 28 int w = s->linelen[s->ndeclevels - 1][0];
405 28 float *line = s->f_linebuf;
406 28 float *data = t;
407 /* position at index O of line range [0-5,w+5] cf. extend function */
408 28 line += 5;
409
410
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 28 times.
406 for (lev = 0; lev < s->ndeclevels; lev++) {
411 378 int lh = s->linelen[lev][0],
412 378 lv = s->linelen[lev][1],
413 378 mh = s->mod[lev][0],
414 378 mv = s->mod[lev][1],
415 lp;
416 float *l;
417 // HOR_SD
418 378 l = line + mh;
419
2/2
✓ Branch 0 taken 12542 times.
✓ Branch 1 taken 378 times.
12920 for (lp = 0; lp < lv; lp++) {
420 12542 int i, j = 0;
421 // copy with interleaving
422
2/2
✓ Branch 0 taken 6383291 times.
✓ Branch 1 taken 12542 times.
6395833 for (i = mh; i < lh; i += 2, j++)
423 6383291 l[i] = data[w * lp + j];
424
2/2
✓ Branch 0 taken 6383380 times.
✓ Branch 1 taken 12542 times.
6395922 for (i = 1 - mh; i < lh; i += 2, j++)
425 6383380 l[i] = data[w * lp + j];
426
427 12542 sr_1d97_float(line, mh, mh + lh);
428
429
2/2
✓ Branch 0 taken 12766671 times.
✓ Branch 1 taken 12542 times.
12779213 for (i = 0; i < lh; i++)
430 12766671 data[w * lp + i] = l[i];
431 }
432
433 // VER_SD
434 378 l = line + mv;
435
2/2
✓ Branch 0 taken 34420 times.
✓ Branch 1 taken 378 times.
34798 for (lp = 0; lp < lh; lp++) {
436 34420 int i, j = 0;
437 // copy with interleaving
438
2/2
✓ Branch 0 taken 6383328 times.
✓ Branch 1 taken 34420 times.
6417748 for (i = mv; i < lv; i += 2, j++)
439 6383328 l[i] = data[w * j + lp];
440
2/2
✓ Branch 0 taken 6383343 times.
✓ Branch 1 taken 34420 times.
6417763 for (i = 1 - mv; i < lv; i += 2, j++)
441 6383343 l[i] = data[w * j + lp];
442
443 34420 sr_1d97_float(line, mv, mv + lv);
444
445
2/2
✓ Branch 0 taken 12766671 times.
✓ Branch 1 taken 34420 times.
12801091 for (i = 0; i < lv; i++)
446 12766671 data[w * i + lp] = l[i];
447 }
448 }
449 28 }
450
451 1236707 static void sr_1d97_int(int32_t *p, int i0, int i1)
452 {
453 int i;
454
455
2/2
✓ Branch 0 taken 5157 times.
✓ Branch 1 taken 1231550 times.
1236707 if (i1 <= i0 + 1) {
456
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 5093 times.
5157 if (i0 == 1)
457 64 p[1] = (p[1] * I_LFTG_K + (1<<16)) >> 17;
458 else
459 5093 p[0] = (p[0] * I_LFTG_X + (1<<15)) >> 16;
460 5157 return;
461 }
462
463 1231550 extend97_int(p, i0, i1);
464
465
2/2
✓ Branch 0 taken 91005520 times.
✓ Branch 1 taken 1231550 times.
92237070 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
466 91005520 p[2 * i] -= (I_LFTG_DELTA * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
467 /* step 4 */
468
2/2
✓ Branch 0 taken 89773970 times.
✓ Branch 1 taken 1231550 times.
91005520 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
469 89773970 p[2 * i + 1] -= (I_LFTG_GAMMA * (p[2 * i] + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
470 /*step 5*/
471
2/2
✓ Branch 0 taken 88542420 times.
✓ Branch 1 taken 1231550 times.
89773970 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
472 88542420 p[2 * i] += (I_LFTG_BETA * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
473 /* step 6 */
474
2/2
✓ Branch 0 taken 87310870 times.
✓ Branch 1 taken 1231550 times.
88542420 for (i = (i0 >> 1); i < (i1 >> 1); i++)
475 87310870 p[2 * i + 1] += (I_LFTG_ALPHA * (p[2 * i] + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
476 }
477
478 2018 static void dwt_decode97_int(DWTContext *s, int32_t *t)
479 {
480 int lev;
481 2018 int w = s->linelen[s->ndeclevels - 1][0];
482 2018 int h = s->linelen[s->ndeclevels - 1][1];
483 int i;
484 2018 int32_t *line = s->i_linebuf;
485 2018 int32_t *data = t;
486 /* position at index O of line range [0-5,w+5] cf. extend function */
487 2018 line += 5;
488
489
2/2
✓ Branch 0 taken 65518785 times.
✓ Branch 1 taken 2018 times.
65520803 for (i = 0; i < w * h; i++)
490 65518785 data[i] *= 1LL << I_PRESHIFT;
491
492
2/2
✓ Branch 0 taken 12317 times.
✓ Branch 1 taken 2018 times.
14335 for (lev = 0; lev < s->ndeclevels; lev++) {
493 12317 int lh = s->linelen[lev][0],
494 12317 lv = s->linelen[lev][1],
495 12317 mh = s->mod[lev][0],
496 12317 mv = s->mod[lev][1],
497 lp;
498 int32_t *l;
499 // HOR_SD
500 12317 l = line + mh;
501
2/2
✓ Branch 0 taken 553667 times.
✓ Branch 1 taken 12317 times.
565984 for (lp = 0; lp < lv; lp++) {
502 553667 int i, j = 0;
503 // rescale with interleaving
504
2/2
✓ Branch 0 taken 43665494 times.
✓ Branch 1 taken 553667 times.
44219161 for (i = mh; i < lh; i += 2, j++)
505 43665494 l[i] = ((data[w * lp + j] * I_LFTG_K) + (1 << 15)) >> 16;
506
2/2
✓ Branch 0 taken 43656250 times.
✓ Branch 1 taken 553667 times.
44209917 for (i = 1 - mh; i < lh; i += 2, j++)
507 43656250 l[i] = data[w * lp + j];
508
509 553667 sr_1d97_int(line, mh, mh + lh);
510
511
2/2
✓ Branch 0 taken 87321744 times.
✓ Branch 1 taken 553667 times.
87875411 for (i = 0; i < lh; i++)
512 87321744 data[w * lp + i] = l[i];
513 }
514
515 // VER_SD
516 12317 l = line + mv;
517
2/2
✓ Branch 0 taken 683040 times.
✓ Branch 1 taken 12317 times.
695357 for (lp = 0; lp < lh; lp++) {
518 683040 int i, j = 0;
519 // rescale with interleaving
520
2/2
✓ Branch 0 taken 43667070 times.
✓ Branch 1 taken 683040 times.
44350110 for (i = mv; i < lv; i += 2, j++)
521 43667070 l[i] = ((data[w * j + lp] * I_LFTG_K) + (1 << 15)) >> 16;
522
2/2
✓ Branch 0 taken 43654674 times.
✓ Branch 1 taken 683040 times.
44337714 for (i = 1 - mv; i < lv; i += 2, j++)
523 43654674 l[i] = data[w * j + lp];
524
525 683040 sr_1d97_int(line, mv, mv + lv);
526
527
2/2
✓ Branch 0 taken 87321744 times.
✓ Branch 1 taken 683040 times.
88004784 for (i = 0; i < lv; i++)
528 87321744 data[w * i + lp] = l[i];
529 }
530 }
531
532
2/2
✓ Branch 0 taken 65518785 times.
✓ Branch 1 taken 2018 times.
65520803 for (i = 0; i < w * h; i++)
533 65518785 data[i] = (data[i] + ((1LL<<I_PRESHIFT)>>1)) >> I_PRESHIFT;
534 2018 }
535
536 4133 int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2],
537 int decomp_levels, int type)
538 {
539 4133 int i, j, lev = decomp_levels, maxlen,
540 b[2][2];
541
542 4133 s->ndeclevels = decomp_levels;
543 4133 s->type = type;
544
545
2/2
✓ Branch 0 taken 8266 times.
✓ Branch 1 taken 4133 times.
12399 for (i = 0; i < 2; i++)
546
2/2
✓ Branch 0 taken 16532 times.
✓ Branch 1 taken 8266 times.
24798 for (j = 0; j < 2; j++)
547 16532 b[i][j] = border[i][j];
548
549 4133 maxlen = FFMAX(b[0][1] - b[0][0],
550 b[1][1] - b[1][0]);
551
2/2
✓ Branch 0 taken 25435 times.
✓ Branch 1 taken 4133 times.
29568 while (--lev >= 0)
552
2/2
✓ Branch 0 taken 50870 times.
✓ Branch 1 taken 25435 times.
76305 for (i = 0; i < 2; i++) {
553 50870 s->linelen[lev][i] = b[i][1] - b[i][0];
554 50870 s->mod[lev][i] = b[i][0] & 1;
555
2/2
✓ Branch 0 taken 101740 times.
✓ Branch 1 taken 50870 times.
152610 for (j = 0; j < 2; j++)
556 101740 b[i][j] = (b[i][j] + 1) >> 1;
557 }
558
3/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2057 times.
✓ Branch 2 taken 2048 times.
✗ Branch 3 not taken.
4133 switch (type) {
559 28 case FF_DWT97:
560 28 s->f_linebuf = av_malloc_array((maxlen + 12), sizeof(*s->f_linebuf));
561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (!s->f_linebuf)
562 return AVERROR(ENOMEM);
563 28 break;
564 2057 case FF_DWT97_INT:
565 2057 s->i_linebuf = av_malloc_array((maxlen + 12), sizeof(*s->i_linebuf));
566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2057 times.
2057 if (!s->i_linebuf)
567 return AVERROR(ENOMEM);
568 2057 break;
569 2048 case FF_DWT53:
570 2048 s->i_linebuf = av_malloc_array((maxlen + 6), sizeof(*s->i_linebuf));
571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if (!s->i_linebuf)
572 return AVERROR(ENOMEM);
573 2048 break;
574 default:
575 return -1;
576 }
577 4133 return 0;
578 }
579
580 3960 int ff_dwt_encode(DWTContext *s, void *t)
581 {
582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3960 times.
3960 if (s->ndeclevels == 0)
583 return 0;
584
585
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1970 times.
✓ Branch 2 taken 1970 times.
✗ Branch 3 not taken.
3960 switch(s->type){
586 20 case FF_DWT97:
587 20 dwt_encode97_float(s, t); break;
588 1970 case FF_DWT97_INT:
589 1970 dwt_encode97_int(s, t); break;
590 1970 case FF_DWT53:
591 1970 dwt_encode53(s, t); break;
592 default:
593 return -1;
594 }
595 3960 return 0;
596 }
597
598 4055 int ff_dwt_decode(DWTContext *s, void *t)
599 {
600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4055 times.
4055 if (s->ndeclevels == 0)
601 return 0;
602
603
3/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2018 times.
✓ Branch 2 taken 2009 times.
✗ Branch 3 not taken.
4055 switch (s->type) {
604 28 case FF_DWT97:
605 28 dwt_decode97_float(s, t);
606 28 break;
607 2018 case FF_DWT97_INT:
608 2018 dwt_decode97_int(s, t);
609 2018 break;
610 2009 case FF_DWT53:
611 2009 dwt_decode53(s, t);
612 2009 break;
613 default:
614 return -1;
615 }
616 4055 return 0;
617 }
618
619 4133 void ff_dwt_destroy(DWTContext *s)
620 {
621 4133 av_freep(&s->f_linebuf);
622 4133 av_freep(&s->i_linebuf);
623 4133 }
624