2 * JPEG 2000 encoder and decoder common functions
3 * Copyright (c) 2007 Kamil Nowosad
4 * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
6 * This file is part of FFmpeg.
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.
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.
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
25 * JPEG 2000 image encoder and decoder common functions
28 #include "libavutil/attributes.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/common.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/mem.h"
37 #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
39 /* tag tree routines */
41 /* allocate the memory for tag tree */
42 int32_t ff_tag_tree_size(int w, int h)
45 while (w > 1 || h > 1) {
46 res += w * (int64_t)h;
47 av_assert0(res + 1 < INT32_MAX);
51 return (int32_t)(res + 1);
54 static Jpeg2000TgtNode *ff_jpeg2000_tag_tree_init(int w, int h)
57 Jpeg2000TgtNode *res, *t, *t2;
60 tt_size = ff_tag_tree_size(w, h);
62 t = res = av_mallocz_array(tt_size, sizeof(*t));
66 while (w > 1 || h > 1) {
75 for (i = 0; i < ph; i++)
76 for (j = 0; j < pw; j++)
77 t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
85 void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
87 int i, siz = ff_tag_tree_size(w, h);
89 for (i = 0; i < siz; i++) {
96 uint8_t ff_jpeg2000_sigctxno_lut[256][4];
98 static int getsigctxno(int flag, int bandno)
102 h = ((flag & JPEG2000_T1_SIG_E) ? 1 : 0) +
103 ((flag & JPEG2000_T1_SIG_W) ? 1 : 0);
104 v = ((flag & JPEG2000_T1_SIG_N) ? 1 : 0) +
105 ((flag & JPEG2000_T1_SIG_S) ? 1 : 0);
106 d = ((flag & JPEG2000_T1_SIG_NE) ? 1 : 0) +
107 ((flag & JPEG2000_T1_SIG_NW) ? 1 : 0) +
108 ((flag & JPEG2000_T1_SIG_SE) ? 1 : 0) +
109 ((flag & JPEG2000_T1_SIG_SW) ? 1 : 0);
114 if (h == 2) return 8;
116 if (v >= 1) return 7;
117 if (d >= 1) return 6;
120 if (v == 2) return 4;
121 if (v == 1) return 3;
122 if (d >= 2) return 2;
123 if (d == 1) return 1;
125 if (d >= 3) return 8;
127 if (h+v >= 1) return 7;
131 if (h+v >= 2) return 5;
132 if (h+v == 1) return 4;
135 if (h+v >= 2) return 2;
136 if (h+v == 1) return 1;
141 uint8_t ff_jpeg2000_sgnctxno_lut[16][16], ff_jpeg2000_xorbit_lut[16][16];
143 static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
144 static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
145 static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
147 static int getsgnctxno(int flag, uint8_t *xorbit)
149 int vcontrib, hcontrib;
151 hcontrib = contribtab[flag & JPEG2000_T1_SIG_E ? flag & JPEG2000_T1_SGN_E ? 1 : 2 : 0]
152 [flag & JPEG2000_T1_SIG_W ? flag & JPEG2000_T1_SGN_W ? 1 : 2 : 0] + 1;
153 vcontrib = contribtab[flag & JPEG2000_T1_SIG_S ? flag & JPEG2000_T1_SGN_S ? 1 : 2 : 0]
154 [flag & JPEG2000_T1_SIG_N ? flag & JPEG2000_T1_SGN_N ? 1 : 2 : 0] + 1;
155 *xorbit = xorbittab[hcontrib][vcontrib];
157 return ctxlbltab[hcontrib][vcontrib];
160 void av_cold ff_jpeg2000_init_tier1_luts(void)
163 for (i = 0; i < 256; i++)
164 for (j = 0; j < 4; j++)
165 ff_jpeg2000_sigctxno_lut[i][j] = getsigctxno(i, j);
166 for (i = 0; i < 16; i++)
167 for (j = 0; j < 16; j++)
168 ff_jpeg2000_sgnctxno_lut[i][j] =
169 getsgnctxno(i + (j << 8), &ff_jpeg2000_xorbit_lut[i][j]);
172 void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y,
177 t1->flags[(y) * t1->stride + x] |= JPEG2000_T1_SIG;
179 t1->flags[(y) * t1->stride + x + 1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W;
180 t1->flags[(y) * t1->stride + x - 1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E;
181 t1->flags[(y + 1) * t1->stride + x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N;
182 t1->flags[(y - 1) * t1->stride + x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S;
184 t1->flags[(y) * t1->stride + x + 1] |= JPEG2000_T1_SIG_W;
185 t1->flags[(y) * t1->stride + x - 1] |= JPEG2000_T1_SIG_E;
186 t1->flags[(y + 1) * t1->stride + x] |= JPEG2000_T1_SIG_N;
187 t1->flags[(y - 1) * t1->stride + x] |= JPEG2000_T1_SIG_S;
189 t1->flags[(y + 1) * t1->stride + x + 1] |= JPEG2000_T1_SIG_NW;
190 t1->flags[(y + 1) * t1->stride + x - 1] |= JPEG2000_T1_SIG_NE;
191 t1->flags[(y - 1) * t1->stride + x + 1] |= JPEG2000_T1_SIG_SW;
192 t1->flags[(y - 1) * t1->stride + x - 1] |= JPEG2000_T1_SIG_SE;
195 // static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } }; (unused)
197 static void init_band_stepsize(AVCodecContext *avctx,
199 Jpeg2000CodingStyle *codsty,
200 Jpeg2000QuantStyle *qntsty,
201 int bandno, int gbandno, int reslevelno,
204 /* TODO: Implementation of quantization step not finished,
205 * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
206 switch (qntsty->quantsty) {
208 case JPEG2000_QSTY_NONE:
209 /* TODO: to verify. No quantization in this case */
210 band->f_stepsize = 1;
212 case JPEG2000_QSTY_SI:
213 /*TODO: Compute formula to implement. */
215 // lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];
216 // band->f_stepsize = SHL(2048 + qntsty->mant[gbandno],
217 // 2 + numbps - qntsty->expn[gbandno]);
219 case JPEG2000_QSTY_SE:
220 /* Exponent quantization step.
222 * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11))
223 * R_b = R_I + log2 (gain_b )
224 * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */
226 band->f_stepsize = ff_exp2fi(gain - qntsty->expn[gbandno]);
227 band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0;
230 band->f_stepsize = 0;
231 av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
234 if (codsty->transform != FF_DWT53) {
236 switch (bandno + (reslevelno > 0)) {
239 band->f_stepsize *= F_LFTG_X * 2;
243 band->f_stepsize *= F_LFTG_X * F_LFTG_X * 4;
246 if (codsty->transform == FF_DWT97) {
247 band->f_stepsize *= pow(F_LFTG_K, 2*(codsty->nreslevels2decode - reslevelno) + lband - 2);
251 if (band->f_stepsize > (INT_MAX >> 15)) {
252 band->f_stepsize = 0;
253 av_log(avctx, AV_LOG_ERROR, "stepsize out of range\n");
256 band->i_stepsize = band->f_stepsize * (1 << 15);
258 /* FIXME: In OpenJPEG code stepsize = stepsize * 0.5. Why?
259 * If not set output of entropic decoder is not correct. */
260 if (!av_codec_is_encoder(avctx->codec))
261 band->f_stepsize *= 0.5;
264 static int init_prec(Jpeg2000Band *band,
265 Jpeg2000ResLevel *reslevel,
266 Jpeg2000Component *comp,
267 int precno, int bandno, int reslevelno,
268 int log2_band_prec_width,
269 int log2_band_prec_height)
271 Jpeg2000Prec *prec = band->prec + precno;
272 int nb_codeblocks, cblkno;
274 prec->decoded_layers = 0;
276 /* TODO: Explain formula for JPEG200 DCINEMA. */
277 /* TODO: Verify with previous count of codeblocks per band */
280 prec->coord[0][0] = ((reslevel->coord[0][0] >> reslevel->log2_prec_width) + precno % reslevel->num_precincts_x) *
281 (1 << log2_band_prec_width);
284 prec->coord[1][0] = ((reslevel->coord[1][0] >> reslevel->log2_prec_height) + precno / reslevel->num_precincts_x) *
285 (1 << log2_band_prec_height);
288 prec->coord[0][1] = prec->coord[0][0] +
289 (1 << log2_band_prec_width);
290 prec->coord[0][0] = FFMAX(prec->coord[0][0], band->coord[0][0]);
291 prec->coord[0][1] = FFMIN(prec->coord[0][1], band->coord[0][1]);
294 prec->coord[1][1] = prec->coord[1][0] +
295 (1 << log2_band_prec_height);
296 prec->coord[1][0] = FFMAX(prec->coord[1][0], band->coord[1][0]);
297 prec->coord[1][1] = FFMIN(prec->coord[1][1], band->coord[1][1]);
299 prec->nb_codeblocks_width =
300 ff_jpeg2000_ceildivpow2(prec->coord[0][1],
301 band->log2_cblk_width)
302 - (prec->coord[0][0] >> band->log2_cblk_width);
303 prec->nb_codeblocks_height =
304 ff_jpeg2000_ceildivpow2(prec->coord[1][1],
305 band->log2_cblk_height)
306 - (prec->coord[1][0] >> band->log2_cblk_height);
309 /* Tag trees initialization */
311 ff_jpeg2000_tag_tree_init(prec->nb_codeblocks_width,
312 prec->nb_codeblocks_height);
314 return AVERROR(ENOMEM);
317 ff_jpeg2000_tag_tree_init(prec->nb_codeblocks_width,
318 prec->nb_codeblocks_height);
320 return AVERROR(ENOMEM);
322 if (prec->nb_codeblocks_width * (uint64_t)prec->nb_codeblocks_height > INT_MAX) {
324 return AVERROR(ENOMEM);
326 nb_codeblocks = prec->nb_codeblocks_width * prec->nb_codeblocks_height;
327 prec->cblk = av_mallocz_array(nb_codeblocks, sizeof(*prec->cblk));
329 return AVERROR(ENOMEM);
330 for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
331 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
334 /* Compute coordinates of codeblocks */
336 Cx0 = ((prec->coord[0][0]) >> band->log2_cblk_width) << band->log2_cblk_width;
337 Cx0 = Cx0 + ((cblkno % prec->nb_codeblocks_width) << band->log2_cblk_width);
338 cblk->coord[0][0] = FFMAX(Cx0, prec->coord[0][0]);
341 Cy0 = ((prec->coord[1][0]) >> band->log2_cblk_height) << band->log2_cblk_height;
342 Cy0 = Cy0 + ((cblkno / prec->nb_codeblocks_width) << band->log2_cblk_height);
343 cblk->coord[1][0] = FFMAX(Cy0, prec->coord[1][0]);
346 cblk->coord[0][1] = FFMIN(Cx0 + (1 << band->log2_cblk_width),
350 cblk->coord[1][1] = FFMIN(Cy0 + (1 << band->log2_cblk_height),
352 /* Update code-blocks coordinates according sub-band position */
353 if ((bandno + !!reslevelno) & 1) {
354 cblk->coord[0][0] += comp->reslevel[reslevelno-1].coord[0][1] -
355 comp->reslevel[reslevelno-1].coord[0][0];
356 cblk->coord[0][1] += comp->reslevel[reslevelno-1].coord[0][1] -
357 comp->reslevel[reslevelno-1].coord[0][0];
359 if ((bandno + !!reslevelno) & 2) {
360 cblk->coord[1][0] += comp->reslevel[reslevelno-1].coord[1][1] -
361 comp->reslevel[reslevelno-1].coord[1][0];
362 cblk->coord[1][1] += comp->reslevel[reslevelno-1].coord[1][1] -
363 comp->reslevel[reslevelno-1].coord[1][0];
374 static int init_band(AVCodecContext *avctx,
375 Jpeg2000ResLevel *reslevel,
376 Jpeg2000Component *comp,
377 Jpeg2000CodingStyle *codsty,
378 Jpeg2000QuantStyle *qntsty,
379 int bandno, int gbandno, int reslevelno,
380 int cbps, int dx, int dy)
382 Jpeg2000Band *band = reslevel->band + bandno;
383 uint8_t log2_band_prec_width, log2_band_prec_height;
384 int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
389 init_band_stepsize(avctx, band, codsty, qntsty, bandno, gbandno, reslevelno, cbps);
391 /* computation of tbx_0, tbx_1, tby_0, tby_1
392 * see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
393 * codeblock width and height is computed for
394 * DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
395 if (reslevelno == 0) {
396 /* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
397 for (i = 0; i < 2; i++)
398 for (j = 0; j < 2; j++)
400 ff_jpeg2000_ceildivpow2(comp->coord_o[i][j],
402 log2_band_prec_width = reslevel->log2_prec_width;
403 log2_band_prec_height = reslevel->log2_prec_height;
404 /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
405 band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
406 reslevel->log2_prec_width);
407 band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
408 reslevel->log2_prec_height);
410 /* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
411 /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
412 for (i = 0; i < 2; i++)
413 for (j = 0; j < 2; j++)
414 /* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
416 ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] -
417 (((bandno + 1 >> i) & 1LL) << declvl - 1),
419 /* TODO: Manage case of 3 band offsets here or
420 * in coding/decoding function? */
422 /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
423 band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
424 reslevel->log2_prec_width - 1);
425 band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
426 reslevel->log2_prec_height - 1);
428 log2_band_prec_width = reslevel->log2_prec_width - 1;
429 log2_band_prec_height = reslevel->log2_prec_height - 1;
432 if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
434 return AVERROR(ENOMEM);
436 nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
437 band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
439 return AVERROR(ENOMEM);
441 for (precno = 0; precno < nb_precincts; precno++) {
442 ret = init_prec(band, reslevel, comp,
443 precno, bandno, reslevelno,
444 log2_band_prec_width, log2_band_prec_height);
452 int ff_jpeg2000_init_component(Jpeg2000Component *comp,
453 Jpeg2000CodingStyle *codsty,
454 Jpeg2000QuantStyle *qntsty,
455 int cbps, int dx, int dy,
456 AVCodecContext *avctx)
458 int reslevelno, bandno, gbandno = 0, ret, i, j;
461 if (codsty->nreslevels2decode <= 0) {
462 av_log(avctx, AV_LOG_ERROR, "nreslevels2decode %d invalid or uninitialized\n", codsty->nreslevels2decode);
463 return AVERROR_INVALIDDATA;
466 if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
467 codsty->nreslevels2decode - 1,
471 if (av_image_check_size(comp->coord[0][1] - comp->coord[0][0],
472 comp->coord[1][1] - comp->coord[1][0], 0, avctx))
473 return AVERROR_INVALIDDATA;
474 csize = (comp->coord[0][1] - comp->coord[0][0]) *
475 (comp->coord[1][1] - comp->coord[1][0]);
476 if (comp->coord[0][1] - comp->coord[0][0] > 32768 ||
477 comp->coord[1][1] - comp->coord[1][0] > 32768) {
478 av_log(avctx, AV_LOG_ERROR, "component size too large\n");
479 return AVERROR_PATCHWELCOME;
482 if (codsty->transform == FF_DWT97) {
483 csize += AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*comp->f_data);
485 comp->f_data = av_mallocz_array(csize, sizeof(*comp->f_data));
487 return AVERROR(ENOMEM);
489 csize += AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*comp->i_data);
491 comp->i_data = av_mallocz_array(csize, sizeof(*comp->i_data));
493 return AVERROR(ENOMEM);
495 comp->reslevel = av_mallocz_array(codsty->nreslevels, sizeof(*comp->reslevel));
497 return AVERROR(ENOMEM);
498 /* LOOP on resolution levels */
499 for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
500 int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
501 Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
503 /* Compute borders for each resolution level.
504 * Computation of trx_0, trx_1, try_0 and try_1.
505 * see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
506 for (i = 0; i < 2; i++)
507 for (j = 0; j < 2; j++)
508 reslevel->coord[i][j] =
509 ff_jpeg2000_ceildivpow2(comp->coord_o[i][j], declvl - 1);
510 // update precincts size: 2^n value
511 reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
512 reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
514 /* Number of bands for each resolution level */
516 reslevel->nbands = 1;
518 reslevel->nbands = 3;
520 /* Number of precincts which span the tile for resolution level reslevelno
521 * see B.6 in ISO/IEC 15444-1:2002 eq. B-16
522 * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
523 * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
524 * for Dcinema profiles in JPEG 2000
525 * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
526 * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
527 if (reslevel->coord[0][1] == reslevel->coord[0][0])
528 reslevel->num_precincts_x = 0;
530 reslevel->num_precincts_x =
531 ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
532 reslevel->log2_prec_width) -
533 (reslevel->coord[0][0] >> reslevel->log2_prec_width);
535 if (reslevel->coord[1][1] == reslevel->coord[1][0])
536 reslevel->num_precincts_y = 0;
538 reslevel->num_precincts_y =
539 ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
540 reslevel->log2_prec_height) -
541 (reslevel->coord[1][0] >> reslevel->log2_prec_height);
543 reslevel->band = av_mallocz_array(reslevel->nbands, sizeof(*reslevel->band));
545 return AVERROR(ENOMEM);
547 if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y * reslevel->nbands > avctx->max_pixels / sizeof(*reslevel->band->prec))
548 return AVERROR(ENOMEM);
550 for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
551 ret = init_band(avctx, reslevel,
552 comp, codsty, qntsty,
553 bandno, gbandno, reslevelno,
562 void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
564 int reslevelno, bandno, cblkno, precno;
565 for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
566 Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
567 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
568 Jpeg2000Band *band = rlevel->band + bandno;
569 for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++) {
570 Jpeg2000Prec *prec = band->prec + precno;
571 ff_tag_tree_zero(prec->zerobits, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
572 ff_tag_tree_zero(prec->cblkincl, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
573 for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
574 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
583 void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
585 int reslevelno, bandno, precno;
587 comp->reslevel && reslevelno < codsty->nreslevels;
589 Jpeg2000ResLevel *reslevel;
594 reslevel = comp->reslevel + reslevelno;
595 for (bandno = 0; bandno < reslevel->nbands; bandno++) {
601 band = reslevel->band + bandno;
602 for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
604 Jpeg2000Prec *prec = band->prec + precno;
605 int nb_code_blocks = prec->nb_codeblocks_height * prec->nb_codeblocks_width;
607 av_freep(&prec->zerobits);
608 av_freep(&prec->cblkincl);
611 for (cblkno = 0; cblkno < nb_code_blocks; cblkno ++) {
612 Jpeg2000Cblk *cblk = &prec->cblk[cblkno];
613 av_freep(&cblk->data);
614 av_freep(&cblk->passes);
615 av_freep(&cblk->lengthinc);
616 av_freep(&cblk->data_start);
618 av_freep(&prec->cblk);
623 av_freep(&band->prec);
625 av_freep(&reslevel->band);
628 ff_dwt_destroy(&comp->dwt);
629 av_freep(&comp->reslevel);
630 av_freep(&comp->i_data);
631 av_freep(&comp->f_data);