GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/jpeg2000dwt.c Lines: 345 356 96.9 %
Date: 2019-11-22 03:34:36 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/avassert.h"
29
#include "libavutil/common.h"
30
#include "libavutil/mem.h"
31
#include "jpeg2000dwt.h"
32
#include "internal.h"
33
34
/* Defines for 9/7 DWT lifting parameters.
35
 * Parameters are in float. */
36
#define F_LFTG_ALPHA  1.586134342059924f
37
#define F_LFTG_BETA   0.052980118572961f
38
#define F_LFTG_GAMMA  0.882911075530934f
39
#define F_LFTG_DELTA  0.443506852043971f
40
41
/* Lifting parameters in integer format.
42
 * Computed as param = (float param) * (1 << 16) */
43
#define I_LFTG_ALPHA  103949ll
44
#define I_LFTG_BETA     3472ll
45
#define I_LFTG_GAMMA   57862ll
46
#define I_LFTG_DELTA   29066ll
47
#define I_LFTG_K       80621ll
48
#define I_LFTG_X       53274ll
49
#define I_PRESHIFT 8
50
51
2335465
static inline void extend53(int *p, int i0, int i1)
52
{
53
2335465
    p[i0 - 1] = p[i0 + 1];
54
2335465
    p[i1]     = p[i1 - 2];
55
2335465
    p[i0 - 2] = p[i0 + 2];
56
2335465
    p[i1 + 1] = p[i1 - 3];
57
2335465
}
58
59
53036
static inline void extend97_float(float *p, int i0, int i1)
60
{
61
    int i;
62
63
265180
    for (i = 1; i <= 4; i++) {
64
212144
        p[i0 - i]     = p[i0 + i];
65
212144
        p[i1 + i - 1] = p[i1 - i - 1];
66
    }
67
53036
}
68
69
2387782
static inline void extend97_int(int32_t *p, int i0, int i1)
70
{
71
    int i;
72
73
11938910
    for (i = 1; i <= 4; i++) {
74
9551128
        p[i0 - i]     = p[i0 + i];
75
9551128
        p[i1 + i - 1] = p[i1 - i - 1];
76
    }
77
2387782
}
78
79
1161290
static void sd_1d53(int *p, int i0, int i1)
80
{
81
    int i;
82
83
1161290
    if (i1 <= i0 + 1) {
84
5058
        if (i0 == 1)
85
64
            p[1] <<= 1;
86
5058
        return;
87
    }
88
89
1156232
    extend53(p, i0, i1);
90
91
63558433
    for (i = ((i0+1)>>1) - 1; i < (i1+1)>>1; i++)
92
62402201
        p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1;
93
62402201
    for (i = ((i0+1)>>1); i < (i1+1)>>1; i++)
94
61245969
        p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2;
95
}
96
97
1970
static void dwt_encode53(DWTContext *s, int *t)
98
{
99
    int lev,
100
1970
        w = s->linelen[s->ndeclevels-1][0];
101
1970
    int *line = s->i_linebuf;
102
1970
    line += 3;
103
104
14008
    for (lev = s->ndeclevels-1; lev >= 0; lev--){
105
12038
        int lh = s->linelen[lev][0],
106
12038
            lv = s->linelen[lev][1],
107
12038
            mh = s->mod[lev][0],
108
12038
            mv = s->mod[lev][1],
109
            lp;
110
        int *l;
111
112
        // VER_SD
113
12038
        l = line + mv;
114
648914
        for (lp = 0; lp < lh; lp++) {
115
636876
            int i, j = 0;
116
117
61878273
            for (i = 0; i < lv; i++)
118
61241397
                l[i] = t[w*i + lp];
119
120
636876
            sd_1d53(line, mv, mv + lv);
121
122
            // copy back and deinterleave
123
31262592
            for (i =   mv; i < lv; i+=2, j++)
124
30625716
                t[w*j + lp] = l[i];
125
31252557
            for (i = 1-mv; i < lv; i+=2, j++)
126
30615681
                t[w*j + lp] = l[i];
127
        }
128
129
        // HOR_SD
130
12038
        l = line + mh;
131
536452
        for (lp = 0; lp < lv; lp++){
132
524414
            int i, j = 0;
133
134
61765811
            for (i = 0; i < lh; i++)
135
61241397
                l[i] = t[w*lp + i];
136
137
524414
            sd_1d53(line, mh, mh + lh);
138
139
            // copy back and deinterleave
140
31149643
            for (i =   mh; i < lh; i+=2, j++)
141
30625229
                t[w*lp + j] = l[i];
142
31140582
            for (i = 1-mh; i < lh; i+=2, j++)
143
30616168
                t[w*lp + j] = l[i];
144
        }
145
    }
146
1970
}
147
6290
static void sd_1d97_float(float *p, int i0, int i1)
148
{
149
    int i;
150
151
6290
    if (i1 <= i0 + 1) {
152
108
        if (i0 == 1)
153
64
            p[1] *= F_LFTG_X * 2;
154
        else
155
44
            p[0] *= F_LFTG_K;
156
108
        return;
157
    }
158
159
6182
    extend97_float(p, i0, i1);
160
6182
    i0++; i1++;
161
162
220697
    for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
163
214515
        p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]);
164
214515
    for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
165
208333
        p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]);
166
208333
    for (i = (i0>>1) - 1; i < (i1>>1); i++)
167
202151
        p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]);
168
202151
    for (i = (i0>>1); i < (i1>>1); i++)
169
195969
        p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]);
170
}
171
172
20
static void dwt_encode97_float(DWTContext *s, float *t)
173
{
174
    int lev,
175
20
        w = s->linelen[s->ndeclevels-1][0];
176
20
    float *line = s->f_linebuf;
177
20
    line += 5;
178
179
358
    for (lev = s->ndeclevels-1; lev >= 0; lev--){
180
338
        int lh = s->linelen[lev][0],
181
338
            lv = s->linelen[lev][1],
182
338
            mh = s->mod[lev][0],
183
338
            mv = s->mod[lev][1],
184
            lp;
185
        float *l;
186
187
        // HOR_SD
188
338
        l = line + mh;
189
3952
        for (lp = 0; lp < lv; lp++){
190
3614
            int i, j = 0;
191
192
199661
            for (i = 0; i < lh; i++)
193
196047
                l[i] = t[w*lp + i];
194
195
3614
            sd_1d97_float(line, mh, mh + lh);
196
197
            // copy back and deinterleave
198
101593
            for (i =   mh; i < lh; i+=2, j++)
199
97979
                t[w*lp + j] = l[i];
200
101682
            for (i = 1-mh; i < lh; i+=2, j++)
201
98068
                t[w*lp + j] = l[i];
202
        }
203
204
        // VER_SD
205
338
        l = line + mv;
206
3014
        for (lp = 0; lp < lh; lp++) {
207
2676
            int i, j = 0;
208
209
198723
            for (i = 0; i < lv; i++)
210
196047
                l[i] = t[w*i + lp];
211
212
2676
            sd_1d97_float(line, mv, mv + lv);
213
214
            // copy back and deinterleave
215
100692
            for (i =   mv; i < lv; i+=2, j++)
216
98016
                t[w*j + lp] = l[i];
217
100707
            for (i = 1-mv; i < lv; i+=2, j++)
218
98031
                t[w*j + lp] = l[i];
219
        }
220
    }
221
20
}
222
223
1161290
static void sd_1d97_int(int *p, int i0, int i1)
224
{
225
    int i;
226
227
1161290
    if (i1 <= i0 + 1) {
228
5058
        if (i0 == 1)
229
64
            p[1] = (p[1] * I_LFTG_X + (1<<14)) >> 15;
230
        else
231
4994
            p[0] = (p[0] * I_LFTG_K + (1<<15)) >> 16;
232
5058
        return;
233
    }
234
235
1156232
    extend97_int(p, i0, i1);
236
1156232
    i0++; i1++;
237
238
65870897
    for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
239
64714665
        p[2 * i + 1] -= (I_LFTG_ALPHA * (p[2 * i]     + p[2 * i + 2]) + (1 << 15)) >> 16;
240
64714665
    for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
241
63558433
        p[2 * i]     -= (I_LFTG_BETA  * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
242
63558433
    for (i = (i0>>1) - 1; i < (i1>>1); i++)
243
62402201
        p[2 * i + 1] += (I_LFTG_GAMMA * (p[2 * i]     + p[2 * i + 2]) + (1 << 15)) >> 16;
244
62402201
    for (i = (i0>>1); i < (i1>>1); i++)
245
61245969
        p[2 * i]     += (I_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
246
}
247
248
1970
static void dwt_encode97_int(DWTContext *s, int *t)
249
{
250
    int lev;
251
1970
    int w = s->linelen[s->ndeclevels-1][0];
252
1970
    int h = s->linelen[s->ndeclevels-1][1];
253
    int i;
254
1970
    int *line = s->i_linebuf;
255
1970
    line += 5;
256
257
45942503
    for (i = 0; i < w * h; i++)
258
45940533
        t[i] *= 1 << I_PRESHIFT;
259
260
14008
    for (lev = s->ndeclevels-1; lev >= 0; lev--){
261
12038
        int lh = s->linelen[lev][0],
262
12038
            lv = s->linelen[lev][1],
263
12038
            mh = s->mod[lev][0],
264
12038
            mv = s->mod[lev][1],
265
            lp;
266
        int *l;
267
268
        // VER_SD
269
12038
        l = line + mv;
270
648914
        for (lp = 0; lp < lh; lp++) {
271
636876
            int i, j = 0;
272
273
61878273
            for (i = 0; i < lv; i++)
274
61241397
                l[i] = t[w*i + lp];
275
276
636876
            sd_1d97_int(line, mv, mv + lv);
277
278
            // copy back and deinterleave
279
31262592
            for (i =   mv; i < lv; i+=2, j++)
280
30625716
                t[w*j + lp] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16;
281
31252557
            for (i = 1-mv; i < lv; i+=2, j++)
282
30615681
                t[w*j + lp] = l[i];
283
        }
284
285
        // HOR_SD
286
12038
        l = line + mh;
287
536452
        for (lp = 0; lp < lv; lp++){
288
524414
            int i, j = 0;
289
290
61765811
            for (i = 0; i < lh; i++)
291
61241397
                l[i] = t[w*lp + i];
292
293
524414
            sd_1d97_int(line, mh, mh + lh);
294
295
            // copy back and deinterleave
296
31149643
            for (i =   mh; i < lh; i+=2, j++)
297
30625229
                t[w*lp + j] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16;
298
31140582
            for (i = 1-mh; i < lh; i+=2, j++)
299
30616168
                t[w*lp + j] = l[i];
300
        }
301
302
    }
303
304
45942503
    for (i = 0; i < w * h; i++)
305
45940533
        t[i] = (t[i] + ((1<<I_PRESHIFT)>>1)) >> I_PRESHIFT;
306
1970
}
307
308
1184390
static void sr_1d53(unsigned *p, int i0, int i1)
309
{
310
    int i;
311
312
1184390
    if (i1 <= i0 + 1) {
313
5157
        if (i0 == 1)
314
64
            p[1] = (int)p[1] >> 1;
315
5157
        return;
316
    }
317
318
1179233
    extend53(p, i0, i1);
319
320
64810976
    for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
321
63631743
        p[2 * i] -= (int)(p[2 * i - 1] + p[2 * i + 1] + 2) >> 2;
322
63631743
    for (i = (i0 >> 1); i < (i1 >> 1); i++)
323
62452510
        p[2 * i + 1] += (int)(p[2 * i] + p[2 * i + 2]) >> 1;
324
}
325
326
2009
static void dwt_decode53(DWTContext *s, int *t)
327
{
328
    int lev;
329
2009
    int w     = s->linelen[s->ndeclevels - 1][0];
330
2009
    int32_t *line = s->i_linebuf;
331
2009
    line += 3;
332
333
14281
    for (lev = 0; lev < s->ndeclevels; lev++) {
334
12272
        int lh = s->linelen[lev][0],
335
12272
            lv = s->linelen[lev][1],
336
12272
            mh = s->mod[lev][0],
337
12272
            mv = s->mod[lev][1],
338
            lp;
339
        int *l;
340
341
        // HOR_SD
342
12272
        l = line + mh;
343
547102
        for (lp = 0; lp < lv; lp++) {
344
534830
            int i, j = 0;
345
            // copy with interleaving
346
31770604
            for (i = mh; i < lh; i += 2, j++)
347
31235774
                l[i] = t[w * lp + j];
348
31761360
            for (i = 1 - mh; i < lh; i += 2, j++)
349
31226530
                l[i] = t[w * lp + j];
350
351
534830
            sr_1d53(line, mh, mh + lh);
352
353
62997134
            for (i = 0; i < lh; i++)
354
62462304
                t[w * lp + i] = l[i];
355
        }
356
357
        // VER_SD
358
12272
        l = line + mv;
359
661832
        for (lp = 0; lp < lh; lp++) {
360
649560
            int i, j = 0;
361
            // copy with interleaving
362
31885830
            for (i = mv; i < lv; i += 2, j++)
363
31236270
                l[i] = t[w * j + lp];
364
31875594
            for (i = 1 - mv; i < lv; i += 2, j++)
365
31226034
                l[i] = t[w * j + lp];
366
367
649560
            sr_1d53(line, mv, mv + lv);
368
369
63111864
            for (i = 0; i < lv; i++)
370
62462304
                t[w * i + lp] = l[i];
371
        }
372
    }
373
2009
}
374
375
46962
static void sr_1d97_float(float *p, int i0, int i1)
376
{
377
    int i;
378
379
46962
    if (i1 <= i0 + 1) {
380
108
        if (i0 == 1)
381
64
            p[1] *= F_LFTG_K/2;
382
        else
383
44
            p[0] *= F_LFTG_X;
384
108
        return;
385
    }
386
387
46854
    extend97_float(p, i0, i1);
388
389
12954085
    for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
390
12907231
        p[2 * i]     -= F_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]);
391
    /* step 4 */
392
12907231
    for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
393
12860377
        p[2 * i + 1] -= F_LFTG_GAMMA * (p[2 * i]     + p[2 * i + 2]);
394
    /*step 5*/
395
12860377
    for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
396
12813523
        p[2 * i]     += F_LFTG_BETA  * (p[2 * i - 1] + p[2 * i + 1]);
397
    /* step 6 */
398
12813523
    for (i = (i0 >> 1); i < (i1 >> 1); i++)
399
12766669
        p[2 * i + 1] += F_LFTG_ALPHA * (p[2 * i]     + p[2 * i + 2]);
400
}
401
402
28
static void dwt_decode97_float(DWTContext *s, float *t)
403
{
404
    int lev;
405
28
    int w       = s->linelen[s->ndeclevels - 1][0];
406
28
    float *line = s->f_linebuf;
407
28
    float *data = t;
408
    /* position at index O of line range [0-5,w+5] cf. extend function */
409
28
    line += 5;
410
411
406
    for (lev = 0; lev < s->ndeclevels; lev++) {
412
378
        int lh = s->linelen[lev][0],
413
378
            lv = s->linelen[lev][1],
414
378
            mh = s->mod[lev][0],
415
378
            mv = s->mod[lev][1],
416
            lp;
417
        float *l;
418
        // HOR_SD
419
378
        l = line + mh;
420
12920
        for (lp = 0; lp < lv; lp++) {
421
12542
            int i, j = 0;
422
            // copy with interleaving
423
6395833
            for (i = mh; i < lh; i += 2, j++)
424
6383291
                l[i] = data[w * lp + j];
425
6395922
            for (i = 1 - mh; i < lh; i += 2, j++)
426
6383380
                l[i] = data[w * lp + j];
427
428
12542
            sr_1d97_float(line, mh, mh + lh);
429
430
12779213
            for (i = 0; i < lh; i++)
431
12766671
                data[w * lp + i] = l[i];
432
        }
433
434
        // VER_SD
435
378
        l = line + mv;
436
34798
        for (lp = 0; lp < lh; lp++) {
437
34420
            int i, j = 0;
438
            // copy with interleaving
439
6417748
            for (i = mv; i < lv; i += 2, j++)
440
6383328
                l[i] = data[w * j + lp];
441
6417763
            for (i = 1 - mv; i < lv; i += 2, j++)
442
6383343
                l[i] = data[w * j + lp];
443
444
34420
            sr_1d97_float(line, mv, mv + lv);
445
446
12801091
            for (i = 0; i < lv; i++)
447
12766671
                data[w * i + lp] = l[i];
448
        }
449
    }
450
28
}
451
452
1236707
static void sr_1d97_int(int32_t *p, int i0, int i1)
453
{
454
    int i;
455
456
1236707
    if (i1 <= i0 + 1) {
457
5157
        if (i0 == 1)
458
64
            p[1] = (p[1] * I_LFTG_K + (1<<16)) >> 17;
459
        else
460
5093
            p[0] = (p[0] * I_LFTG_X + (1<<15)) >> 16;
461
5157
        return;
462
    }
463
464
1231550
    extend97_int(p, i0, i1);
465
466
92237070
    for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
467
91005520
        p[2 * i]     -= (I_LFTG_DELTA * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
468
    /* step 4 */
469
91005520
    for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
470
89773970
        p[2 * i + 1] -= (I_LFTG_GAMMA * (p[2 * i]     + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
471
    /*step 5*/
472
89773970
    for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
473
88542420
        p[2 * i]     += (I_LFTG_BETA  * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
474
    /* step 6 */
475
88542420
    for (i = (i0 >> 1); i < (i1 >> 1); i++)
476
87310870
        p[2 * i + 1] += (I_LFTG_ALPHA * (p[2 * i]     + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
477
}
478
479
2018
static void dwt_decode97_int(DWTContext *s, int32_t *t)
480
{
481
    int lev;
482
2018
    int w       = s->linelen[s->ndeclevels - 1][0];
483
2018
    int h       = s->linelen[s->ndeclevels - 1][1];
484
    int i;
485
2018
    int32_t *line = s->i_linebuf;
486
2018
    int32_t *data = t;
487
    /* position at index O of line range [0-5,w+5] cf. extend function */
488
2018
    line += 5;
489
490
65520803
    for (i = 0; i < w * h; i++)
491
65518785
        data[i] *= 1LL << I_PRESHIFT;
492
493
14335
    for (lev = 0; lev < s->ndeclevels; lev++) {
494
12317
        int lh = s->linelen[lev][0],
495
12317
            lv = s->linelen[lev][1],
496
12317
            mh = s->mod[lev][0],
497
12317
            mv = s->mod[lev][1],
498
            lp;
499
        int32_t *l;
500
        // HOR_SD
501
12317
        l = line + mh;
502
565984
        for (lp = 0; lp < lv; lp++) {
503
553667
            int i, j = 0;
504
            // rescale with interleaving
505
44219161
            for (i = mh; i < lh; i += 2, j++)
506
43665494
                l[i] = ((data[w * lp + j] * I_LFTG_K) + (1 << 15)) >> 16;
507
44209917
            for (i = 1 - mh; i < lh; i += 2, j++)
508
43656250
                l[i] = data[w * lp + j];
509
510
553667
            sr_1d97_int(line, mh, mh + lh);
511
512
87875411
            for (i = 0; i < lh; i++)
513
87321744
                data[w * lp + i] = l[i];
514
        }
515
516
        // VER_SD
517
12317
        l = line + mv;
518
695357
        for (lp = 0; lp < lh; lp++) {
519
683040
            int i, j = 0;
520
            // rescale with interleaving
521
44350110
            for (i = mv; i < lv; i += 2, j++)
522
43667070
                l[i] = ((data[w * j + lp] * I_LFTG_K) + (1 << 15)) >> 16;
523
44337714
            for (i = 1 - mv; i < lv; i += 2, j++)
524
43654674
                l[i] = data[w * j + lp];
525
526
683040
            sr_1d97_int(line, mv, mv + lv);
527
528
88004784
            for (i = 0; i < lv; i++)
529
87321744
                data[w * i + lp] = l[i];
530
        }
531
    }
532
533
65520803
    for (i = 0; i < w * h; i++)
534
65518785
        data[i] = (data[i] + ((1LL<<I_PRESHIFT)>>1)) >> I_PRESHIFT;
535
2018
}
536
537
4133
int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2],
538
                         int decomp_levels, int type)
539
{
540
4133
    int i, j, lev = decomp_levels, maxlen,
541
        b[2][2];
542
543
4133
    s->ndeclevels = decomp_levels;
544
4133
    s->type       = type;
545
546
12399
    for (i = 0; i < 2; i++)
547
24798
        for (j = 0; j < 2; j++)
548
16532
            b[i][j] = border[i][j];
549
550
4133
    maxlen = FFMAX(b[0][1] - b[0][0],
551
                   b[1][1] - b[1][0]);
552
29568
    while (--lev >= 0)
553
76305
        for (i = 0; i < 2; i++) {
554
50870
            s->linelen[lev][i] = b[i][1] - b[i][0];
555
50870
            s->mod[lev][i]     = b[i][0] & 1;
556
152610
            for (j = 0; j < 2; j++)
557
101740
                b[i][j] = (b[i][j] + 1) >> 1;
558
        }
559

4133
    switch (type) {
560
28
    case FF_DWT97:
561
28
        s->f_linebuf = av_malloc_array((maxlen + 12), sizeof(*s->f_linebuf));
562
28
        if (!s->f_linebuf)
563
            return AVERROR(ENOMEM);
564
28
        break;
565
2057
     case FF_DWT97_INT:
566
2057
        s->i_linebuf = av_malloc_array((maxlen + 12), sizeof(*s->i_linebuf));
567
2057
        if (!s->i_linebuf)
568
            return AVERROR(ENOMEM);
569
2057
        break;
570
2048
    case FF_DWT53:
571
2048
        s->i_linebuf = av_malloc_array((maxlen +  6), sizeof(*s->i_linebuf));
572
2048
        if (!s->i_linebuf)
573
            return AVERROR(ENOMEM);
574
2048
        break;
575
    default:
576
        return -1;
577
    }
578
4133
    return 0;
579
}
580
581
3960
int ff_dwt_encode(DWTContext *s, void *t)
582
{
583
3960
    if (s->ndeclevels == 0)
584
        return 0;
585
586

3960
    switch(s->type){
587
20
        case FF_DWT97:
588
20
            dwt_encode97_float(s, t); break;
589
1970
        case FF_DWT97_INT:
590
1970
            dwt_encode97_int(s, t); break;
591
1970
        case FF_DWT53:
592
1970
            dwt_encode53(s, t); break;
593
        default:
594
            return -1;
595
    }
596
3960
    return 0;
597
}
598
599
4055
int ff_dwt_decode(DWTContext *s, void *t)
600
{
601
4055
    if (s->ndeclevels == 0)
602
        return 0;
603
604

4055
    switch (s->type) {
605
28
    case FF_DWT97:
606
28
        dwt_decode97_float(s, t);
607
28
        break;
608
2018
    case FF_DWT97_INT:
609
2018
        dwt_decode97_int(s, t);
610
2018
        break;
611
2009
    case FF_DWT53:
612
2009
        dwt_decode53(s, t);
613
2009
        break;
614
    default:
615
        return -1;
616
    }
617
4055
    return 0;
618
}
619
620
4133
void ff_dwt_destroy(DWTContext *s)
621
{
622
4133
    av_freep(&s->f_linebuf);
623
4133
    av_freep(&s->i_linebuf);
624
4133
}