You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

497 lines
20KB

  1. /*
  2. * JPEG 2000 encoder and decoder common functions
  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. * JPEG 2000 image encoder and decoder common functions
  24. * @file
  25. * @author Kamil Nowosad
  26. */
  27. #include "libavutil/avassert.h"
  28. #include "libavutil/common.h"
  29. #include "libavutil/mem.h"
  30. #include "avcodec.h"
  31. #include "j2k.h"
  32. #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
  33. /* tag tree routines */
  34. /* allocate the memory for tag tree */
  35. static int tag_tree_size(int w, int h)
  36. {
  37. int res = 0;
  38. while (w > 1 || h > 1) {
  39. res += w * h;
  40. w = (w + 1) >> 1;
  41. h = (h + 1) >> 1;
  42. }
  43. return res + 1;
  44. }
  45. Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h)
  46. {
  47. int pw = w, ph = h;
  48. Jpeg2000TgtNode *res, *t, *t2;
  49. int32_t tt_size;
  50. tt_size = tag_tree_size(w, h);
  51. t = res = av_mallocz_array(tt_size, sizeof(*t));
  52. if (!res)
  53. return NULL;
  54. while (w > 1 || h > 1) {
  55. int i, j;
  56. pw = w;
  57. ph = h;
  58. w = (w + 1) >> 1;
  59. h = (h + 1) >> 1;
  60. t2 = t + pw * ph;
  61. for (i = 0; i < ph; i++)
  62. for (j = 0; j < pw; j++)
  63. t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
  64. t = t2;
  65. }
  66. t[0].parent = NULL;
  67. return res;
  68. }
  69. static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
  70. {
  71. int i, siz = tag_tree_size(w, h);
  72. for (i = 0; i < siz; i++) {
  73. t[i].val = 0;
  74. t[i].vis = 0;
  75. }
  76. }
  77. static int getsigctxno(int flag, int bandno)
  78. {
  79. int h, v, d;
  80. h = ((flag & JPEG2000_T1_SIG_E) ? 1 : 0) +
  81. ((flag & JPEG2000_T1_SIG_W) ? 1 : 0);
  82. v = ((flag & JPEG2000_T1_SIG_N) ? 1 : 0) +
  83. ((flag & JPEG2000_T1_SIG_S) ? 1 : 0);
  84. d = ((flag & JPEG2000_T1_SIG_NE) ? 1 : 0) +
  85. ((flag & JPEG2000_T1_SIG_NW) ? 1 : 0) +
  86. ((flag & JPEG2000_T1_SIG_SE) ? 1 : 0) +
  87. ((flag & JPEG2000_T1_SIG_SW) ? 1 : 0);
  88. if (bandno < 3) {
  89. if (bandno == 1)
  90. FFSWAP(int, h, v);
  91. if (h == 2) return 8;
  92. if (h == 1) {
  93. if (v >= 1) return 7;
  94. if (d >= 1) return 6;
  95. return 5;
  96. }
  97. if (v == 2) return 4;
  98. if (v == 1) return 3;
  99. if (d >= 2) return 2;
  100. if (d == 1) return 1;
  101. } else {
  102. if (d >= 3) return 8;
  103. if (d == 2) {
  104. if (h+v >= 1) return 7;
  105. return 6;
  106. }
  107. if (d == 1) {
  108. if (h+v >= 2) return 5;
  109. if (h+v == 1) return 4;
  110. return 3;
  111. }
  112. if (h+v >= 2) return 2;
  113. if (h+v == 1) return 1;
  114. }
  115. return 0;
  116. }
  117. static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
  118. static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
  119. static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
  120. static int getsgnctxno(int flag, uint8_t *xorbit)
  121. {
  122. int vcontrib, hcontrib;
  123. hcontrib = contribtab[flag & JPEG2000_T1_SIG_E ? flag & JPEG2000_T1_SGN_E ? 1 : 2 : 0]
  124. [flag & JPEG2000_T1_SIG_W ? flag & JPEG2000_T1_SGN_W ? 1 : 2 : 0] + 1;
  125. vcontrib = contribtab[flag & JPEG2000_T1_SIG_S ? flag & JPEG2000_T1_SGN_S ? 1 : 2 : 0]
  126. [flag & JPEG2000_T1_SIG_N ? flag & JPEG2000_T1_SGN_N ? 1 : 2 : 0] + 1;
  127. *xorbit = xorbittab[hcontrib][vcontrib];
  128. return ctxlbltab[hcontrib][vcontrib];
  129. }
  130. void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y,
  131. int negative)
  132. {
  133. x++;
  134. y++;
  135. t1->flags[y][x] |= JPEG2000_T1_SIG;
  136. if (negative) {
  137. t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W;
  138. t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E;
  139. t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N;
  140. t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S;
  141. } else {
  142. t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W;
  143. t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E;
  144. t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N;
  145. t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S;
  146. }
  147. t1->flags[y + 1][x + 1] |= JPEG2000_T1_SIG_NW;
  148. t1->flags[y + 1][x - 1] |= JPEG2000_T1_SIG_NE;
  149. t1->flags[y - 1][x + 1] |= JPEG2000_T1_SIG_SW;
  150. t1->flags[y - 1][x - 1] |= JPEG2000_T1_SIG_SE;
  151. }
  152. int ff_j2k_init_component(Jpeg2000Component *comp,
  153. Jpeg2000CodingStyle *codsty,
  154. Jpeg2000QuantStyle *qntsty,
  155. int cbps, int dx, int dy)
  156. {
  157. uint8_t log2_band_prec_width, log2_band_prec_height;
  158. int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
  159. if (ret=ff_j2k_dwt_init(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform))
  160. return ret;
  161. for (i = 0; i < 2; i++)
  162. csize *= comp->coord[i][1] - comp->coord[i][0];
  163. comp->data = av_malloc_array(csize, sizeof(*comp->data));
  164. if (!comp->data)
  165. return AVERROR(ENOMEM);
  166. comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel));
  167. if (!comp->reslevel)
  168. return AVERROR(ENOMEM);
  169. /* LOOP on resolution levels */
  170. for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
  171. int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
  172. Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
  173. /* Compute borders for each resolution level.
  174. * Computation of trx_0, trx_1, try_0 and try_1.
  175. * see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
  176. for (i = 0; i < 2; i++)
  177. for (j = 0; j < 2; j++)
  178. reslevel->coord[i][j] =
  179. ff_jpeg2000_ceildivpow2(comp->coord[i][j], declvl - 1);
  180. // update precincts size: 2^n value
  181. reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
  182. reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
  183. /* Number of bands for each resolution level */
  184. if (reslevelno == 0)
  185. reslevel->nbands = 1;
  186. else
  187. reslevel->nbands = 3;
  188. /* Number of precincts wich span the tile for resolution level reslevelno
  189. * see B.6 in ISO/IEC 15444-1:2002 eq. B-16
  190. * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
  191. * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
  192. * for Dcinema profiles in JPEG 2000
  193. * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
  194. * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
  195. if (reslevel->coord[0][1] == reslevel->coord[0][0])
  196. reslevel->num_precincts_x = 0;
  197. else
  198. reslevel->num_precincts_x =
  199. ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
  200. reslevel->log2_prec_width) -
  201. (reslevel->coord[0][0] >> reslevel->log2_prec_width);
  202. if (reslevel->coord[1][1] == reslevel->coord[1][0])
  203. reslevel->num_precincts_y = 0;
  204. else
  205. reslevel->num_precincts_y =
  206. ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
  207. reslevel->log2_prec_height) -
  208. (reslevel->coord[1][0] >> reslevel->log2_prec_height);
  209. reslevel->band = av_malloc_array(reslevel->nbands, sizeof(*reslevel->band));
  210. if (!reslevel->band)
  211. return AVERROR(ENOMEM);
  212. for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
  213. Jpeg2000Band *band = reslevel->band + bandno;
  214. int precx, precy;
  215. int x0, y0, x1, y1;
  216. int xi0, yi0, xi1, yi1;
  217. int cblkperprecw, cblkperprech;
  218. int cblkno, precno;
  219. int nb_precincts;
  220. if (qntsty->quantsty != JPEG2000_QSTY_NONE) {
  221. static const uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}};
  222. int numbps;
  223. numbps = cbps + lut_gain[codsty->transform][bandno + reslevelno>0];
  224. band->stepsize = SHL(2048 + qntsty->mant[gbandno], 2 + numbps - qntsty->expn[gbandno]);
  225. } else
  226. band->stepsize = 1 << 13;
  227. if (reslevelno == 0) {
  228. /* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
  229. for (i = 0; i < 2; i++)
  230. for (j = 0; j < 2; j++)
  231. band->coord[i][j] =
  232. ff_jpeg2000_ceildivpow2(comp->coord[i][j] - comp->coord[i][0],
  233. declvl - 1);
  234. log2_band_prec_width = reslevel->log2_prec_width;
  235. log2_band_prec_height = reslevel->log2_prec_height;
  236. /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
  237. band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
  238. reslevel->log2_prec_width);
  239. band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
  240. reslevel->log2_prec_height);
  241. } else {
  242. /* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
  243. /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
  244. for (i = 0; i < 2; i++)
  245. for (j = 0; j < 2; j++)
  246. /* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
  247. band->coord[i][j] =
  248. ff_jpeg2000_ceildivpow2(comp->coord[i][j] - comp->coord[i][0] -
  249. (((bandno + 1 >> i) & 1) << declvl - 1),
  250. declvl);
  251. /* TODO: Manage case of 3 band offsets here or
  252. * in coding/decoding function? */
  253. /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
  254. band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
  255. reslevel->log2_prec_width - 1);
  256. band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
  257. reslevel->log2_prec_height - 1);
  258. log2_band_prec_width = reslevel->log2_prec_width - 1;
  259. log2_band_prec_height = reslevel->log2_prec_height - 1;
  260. }
  261. band->cblknx = ff_jpeg2000_ceildivpow2(band->coord[0][1], band->log2_cblk_width) - (band->coord[0][0] >> band->log2_cblk_width);
  262. band->cblkny = ff_jpeg2000_ceildivpow2(band->coord[1][1], band->log2_cblk_height) - (band->coord[1][0] >> band->log2_cblk_height);
  263. for (j = 0; j < 2; j++)
  264. band->coord[0][j] = ff_jpeg2000_ceildiv(band->coord[0][j], dx);
  265. for (j = 0; j < 2; j++)
  266. band->coord[1][j] = ff_jpeg2000_ceildiv(band->coord[1][j], dy);
  267. band->cblknx = ff_jpeg2000_ceildiv(band->cblknx, dx);
  268. band->cblkny = ff_jpeg2000_ceildiv(band->cblkny, dy);
  269. band->cblk = av_malloc_array(band->cblknx *
  270. band->cblkny,
  271. sizeof(*band->cblk));
  272. if (!band->cblk)
  273. return AVERROR(ENOMEM);
  274. band->prec = av_malloc_array(reslevel->num_precincts_x *
  275. reslevel->num_precincts_y,
  276. sizeof(*band->prec));
  277. if (!band->prec)
  278. return AVERROR(ENOMEM);
  279. nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
  280. y0 = band->coord[1][0];
  281. y1 = ((band->coord[1][0] + (1<<reslevel->log2_prec_height)) & ~((1<<reslevel->log2_prec_height)-1)) - y0;
  282. yi0 = 0;
  283. yi1 = ff_jpeg2000_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height;
  284. yi1 = FFMIN(yi1, band->cblkny);
  285. cblkperprech = 1<<(reslevel->log2_prec_height - codsty->log2_cblk_height);
  286. for (precy = 0, precno = 0; precy < reslevel->num_precincts_y; precy++) {
  287. for (precx = 0; precx < reslevel->num_precincts_x; precx++, precno++) {
  288. band->prec[precno].yi0 = yi0;
  289. band->prec[precno].yi1 = yi1;
  290. }
  291. yi1 += cblkperprech;
  292. yi0 = yi1 - cblkperprech;
  293. yi1 = FFMIN(yi1, band->cblkny);
  294. }
  295. x0 = band->coord[0][0];
  296. x1 = ((band->coord[0][0] + (1<<reslevel->log2_prec_width)) & ~((1<<reslevel->log2_prec_width)-1)) - x0;
  297. xi0 = 0;
  298. xi1 = ff_jpeg2000_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width;
  299. xi1 = FFMIN(xi1, band->cblknx);
  300. cblkperprecw = 1<<(reslevel->log2_prec_width - codsty->log2_cblk_width);
  301. for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++) {
  302. for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0) {
  303. Jpeg2000Prec *prec = band->prec + precno;
  304. prec->xi0 = xi0;
  305. prec->xi1 = xi1;
  306. }
  307. xi1 += cblkperprecw;
  308. xi0 = xi1 - cblkperprecw;
  309. xi1 = FFMIN(xi1, band->cblknx);
  310. }
  311. for (precno = 0; precno < nb_precincts; precno++) {
  312. Jpeg2000Prec *prec = band->prec + precno;
  313. /* TODO: Explain formula for JPEG200 DCINEMA. */
  314. /* TODO: Verify with previous count of codeblocks per band */
  315. /* Compute P_x0 */
  316. prec->coord[0][0] = (precno % reslevel->num_precincts_x) *
  317. (1 << log2_band_prec_width);
  318. prec->coord[0][0] = FFMAX(prec->coord[0][0], band->coord[0][0]);
  319. /* Compute P_y0 */
  320. prec->coord[1][0] = (precno / reslevel->num_precincts_x) *
  321. (1 << log2_band_prec_height);
  322. prec->coord[1][0] = FFMAX(prec->coord[1][0], band->coord[1][0]);
  323. /* Compute P_x1 */
  324. prec->coord[0][1] = prec->coord[0][0] +
  325. (1 << log2_band_prec_width);
  326. prec->coord[0][1] = FFMIN(prec->coord[0][1], band->coord[0][1]);
  327. /* Compute P_y1 */
  328. prec->coord[1][1] = prec->coord[1][0] +
  329. (1 << log2_band_prec_height);
  330. prec->coord[1][1] = FFMIN(prec->coord[1][1], band->coord[1][1]);
  331. prec->nb_codeblocks_width =
  332. ff_jpeg2000_ceildivpow2(prec->coord[0][1] -
  333. prec->coord[0][0],
  334. band->log2_cblk_width);
  335. prec->nb_codeblocks_height =
  336. ff_jpeg2000_ceildivpow2(prec->coord[1][1] -
  337. prec->coord[1][0],
  338. band->log2_cblk_height);
  339. /* Tag trees initialization */
  340. prec->cblkincl =
  341. ff_j2k_tag_tree_init(prec->nb_codeblocks_width,
  342. prec->nb_codeblocks_height);
  343. if (!prec->cblkincl)
  344. return AVERROR(ENOMEM);
  345. prec->zerobits =
  346. ff_j2k_tag_tree_init(prec->nb_codeblocks_width,
  347. prec->nb_codeblocks_height);
  348. if (!prec->zerobits)
  349. return AVERROR(ENOMEM);
  350. // prec->cblk = av_malloc_array(prec->nb_codeblocks_width *
  351. // prec->nb_codeblocks_height,
  352. // sizeof(*prec->cblk));
  353. prec->cblk = band->cblk;
  354. av_assert0(nb_precincts == 1);
  355. if (!prec->cblk)
  356. return AVERROR(ENOMEM);
  357. for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
  358. Jpeg2000Cblk *cblk = prec->cblk + cblkno;
  359. uint16_t Cx0, Cy0;
  360. /* Compute coordinates of codeblocks */
  361. /* Compute Cx0*/
  362. Cx0 = (prec->coord[0][0] >> band->log2_cblk_width) << band->log2_cblk_width;
  363. Cx0 = Cx0 + ((cblkno % prec->nb_codeblocks_width) << band->log2_cblk_width);
  364. cblk->coord[0][0] = FFMAX(Cx0, prec->coord[0][0]);
  365. /* Compute Cy0*/
  366. Cy0 = (prec->coord[1][0] >> band->log2_cblk_height) << band->log2_cblk_height;
  367. Cy0 = Cy0 + ((cblkno / prec->nb_codeblocks_width) << band->log2_cblk_height);
  368. cblk->coord[1][0] = FFMAX(Cy0, prec->coord[1][0]);
  369. /* Compute Cx1 */
  370. cblk->coord[0][1] = FFMIN(Cx0 + (1 << band->log2_cblk_width),
  371. prec->coord[0][1]);
  372. /* Compute Cy1 */
  373. cblk->coord[1][1] = FFMIN(Cy0 + (1 << band->log2_cblk_height),
  374. prec->coord[1][1]);
  375. if((bandno + !!reslevelno) & 1) {
  376. cblk->coord[0][0] += comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
  377. cblk->coord[0][1] += comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
  378. }
  379. if((bandno + !!reslevelno) & 2) {
  380. cblk->coord[1][0] += comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
  381. cblk->coord[1][1] += comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
  382. }
  383. cblk->zero = 0;
  384. cblk->lblock = 3;
  385. cblk->length = 0;
  386. cblk->lengthinc = 0;
  387. cblk->npasses = 0;
  388. }
  389. }
  390. }
  391. }
  392. return 0;
  393. }
  394. void ff_j2k_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
  395. {
  396. int reslevelno, bandno, cblkno, precno;
  397. for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
  398. Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
  399. for (bandno = 0; bandno < rlevel->nbands; bandno++) {
  400. Jpeg2000Band *band = rlevel->band + bandno;
  401. for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++) {
  402. Jpeg2000Prec *prec = band->prec + precno;
  403. tag_tree_zero(prec->zerobits, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
  404. tag_tree_zero(prec->cblkincl, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
  405. }
  406. for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++) {
  407. Jpeg2000Cblk *cblk = band->cblk + cblkno;
  408. cblk->length = 0;
  409. cblk->lblock = 3;
  410. }
  411. }
  412. }
  413. }
  414. void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
  415. {
  416. int reslevelno, bandno, precno;
  417. for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
  418. Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
  419. for (bandno = 0; bandno < reslevel->nbands; bandno++) {
  420. Jpeg2000Band *band = reslevel->band + bandno;
  421. for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
  422. Jpeg2000Prec *prec = band->prec + precno;
  423. av_freep(&prec->zerobits);
  424. av_freep(&prec->cblkincl);
  425. }
  426. av_freep(&band->cblk);
  427. av_freep(&band->prec);
  428. }
  429. av_freep(&reslevel->band);
  430. }
  431. ff_j2k_dwt_destroy(&comp->dwt);
  432. av_freep(&comp->reslevel);
  433. av_freep(&comp->data);
  434. }