FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
jpeg2000.c
Go to the documentation of this file.
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 /**
24  * @file
25  * JPEG 2000 image encoder and decoder common functions
26  */
27 
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"
33 #include "avcodec.h"
34 #include "jpeg2000.h"
35 
36 #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
37 
38 /* tag tree routines */
39 
40 /* allocate the memory for tag tree */
41 static int32_t tag_tree_size(uint16_t w, uint16_t h)
42 {
43  uint32_t res = 0;
44  while (w > 1 || h > 1) {
45  res += w * h;
46  av_assert0(res + 1 < INT32_MAX);
47  w = (w + 1) >> 1;
48  h = (h + 1) >> 1;
49  }
50  return (int32_t)(res + 1);
51 }
52 
54 {
55  int pw = w, ph = h;
56  Jpeg2000TgtNode *res, *t, *t2;
57  int32_t tt_size;
58 
59  tt_size = tag_tree_size(w, h);
60 
61  t = res = av_mallocz_array(tt_size, sizeof(*t));
62  if (!res)
63  return NULL;
64 
65  while (w > 1 || h > 1) {
66  int i, j;
67  pw = w;
68  ph = h;
69 
70  w = (w + 1) >> 1;
71  h = (h + 1) >> 1;
72  t2 = t + pw * ph;
73 
74  for (i = 0; i < ph; i++)
75  for (j = 0; j < pw; j++)
76  t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
77 
78  t = t2;
79  }
80  t[0].parent = NULL;
81  return res;
82 }
83 
84 static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
85 {
86  int i, siz = tag_tree_size(w, h);
87 
88  for (i = 0; i < siz; i++) {
89  t[i].val = 0;
90  t[i].vis = 0;
91  }
92 }
93 
95 
96 static int getsigctxno(int flag, int bandno)
97 {
98  int h, v, d;
99 
100  h = ((flag & JPEG2000_T1_SIG_E) ? 1 : 0) +
101  ((flag & JPEG2000_T1_SIG_W) ? 1 : 0);
102  v = ((flag & JPEG2000_T1_SIG_N) ? 1 : 0) +
103  ((flag & JPEG2000_T1_SIG_S) ? 1 : 0);
104  d = ((flag & JPEG2000_T1_SIG_NE) ? 1 : 0) +
105  ((flag & JPEG2000_T1_SIG_NW) ? 1 : 0) +
106  ((flag & JPEG2000_T1_SIG_SE) ? 1 : 0) +
107  ((flag & JPEG2000_T1_SIG_SW) ? 1 : 0);
108 
109  if (bandno < 3) {
110  if (bandno == 1)
111  FFSWAP(int, h, v);
112  if (h == 2) return 8;
113  if (h == 1) {
114  if (v >= 1) return 7;
115  if (d >= 1) return 6;
116  return 5;
117  }
118  if (v == 2) return 4;
119  if (v == 1) return 3;
120  if (d >= 2) return 2;
121  if (d == 1) return 1;
122  } else {
123  if (d >= 3) return 8;
124  if (d == 2) {
125  if (h+v >= 1) return 7;
126  return 6;
127  }
128  if (d == 1) {
129  if (h+v >= 2) return 5;
130  if (h+v == 1) return 4;
131  return 3;
132  }
133  if (h+v >= 2) return 2;
134  if (h+v == 1) return 1;
135  }
136  return 0;
137 }
138 
140 
141 static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
142 static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
143 static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
144 
145 static int getsgnctxno(int flag, uint8_t *xorbit)
146 {
147  int vcontrib, hcontrib;
148 
149  hcontrib = contribtab[flag & JPEG2000_T1_SIG_E ? flag & JPEG2000_T1_SGN_E ? 1 : 2 : 0]
150  [flag & JPEG2000_T1_SIG_W ? flag & JPEG2000_T1_SGN_W ? 1 : 2 : 0] + 1;
151  vcontrib = contribtab[flag & JPEG2000_T1_SIG_S ? flag & JPEG2000_T1_SGN_S ? 1 : 2 : 0]
152  [flag & JPEG2000_T1_SIG_N ? flag & JPEG2000_T1_SGN_N ? 1 : 2 : 0] + 1;
153  *xorbit = xorbittab[hcontrib][vcontrib];
154 
155  return ctxlbltab[hcontrib][vcontrib];
156 }
157 
159 {
160  int i, j;
161  for (i = 0; i < 256; i++)
162  for (j = 0; j < 4; j++)
164  for (i = 0; i < 16; i++)
165  for (j = 0; j < 16; j++)
167  getsgnctxno(i + (j << 8), &ff_jpeg2000_xorbit_lut[i][j]);
168 }
169 
171  int negative)
172 {
173  x++;
174  y++;
175  t1->flags[(y) * t1->stride + x] |= JPEG2000_T1_SIG;
176  if (negative) {
177  t1->flags[(y) * t1->stride + x + 1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W;
178  t1->flags[(y) * t1->stride + x - 1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E;
179  t1->flags[(y + 1) * t1->stride + x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N;
180  t1->flags[(y - 1) * t1->stride + x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S;
181  } else {
182  t1->flags[(y) * t1->stride + x + 1] |= JPEG2000_T1_SIG_W;
183  t1->flags[(y) * t1->stride + x - 1] |= JPEG2000_T1_SIG_E;
184  t1->flags[(y + 1) * t1->stride + x] |= JPEG2000_T1_SIG_N;
185  t1->flags[(y - 1) * t1->stride + x] |= JPEG2000_T1_SIG_S;
186  }
187  t1->flags[(y + 1) * t1->stride + x + 1] |= JPEG2000_T1_SIG_NW;
188  t1->flags[(y + 1) * t1->stride + x - 1] |= JPEG2000_T1_SIG_NE;
189  t1->flags[(y - 1) * t1->stride + x + 1] |= JPEG2000_T1_SIG_SW;
190  t1->flags[(y - 1) * t1->stride + x - 1] |= JPEG2000_T1_SIG_SE;
191 }
192 
193 // static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } }; (unused)
194 
196  Jpeg2000CodingStyle *codsty,
197  Jpeg2000QuantStyle *qntsty,
198  int cbps, int dx, int dy,
199  AVCodecContext *avctx)
200 {
201  uint8_t log2_band_prec_width, log2_band_prec_height;
202  int reslevelno, bandno, gbandno = 0, ret, i, j;
203  uint32_t csize;
204 
205  if (codsty->nreslevels2decode <= 0) {
206  av_log(avctx, AV_LOG_ERROR, "nreslevels2decode %d invalid or uninitialized\n", codsty->nreslevels2decode);
207  return AVERROR_INVALIDDATA;
208  }
209 
210  if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
211  codsty->nreslevels2decode - 1,
212  codsty->transform))
213  return ret;
214 
215  if (av_image_check_size(comp->coord[0][1] - comp->coord[0][0],
216  comp->coord[1][1] - comp->coord[1][0], 0, avctx))
217  return AVERROR_INVALIDDATA;
218  csize = (comp->coord[0][1] - comp->coord[0][0]) *
219  (comp->coord[1][1] - comp->coord[1][0]);
220  if (comp->coord[0][1] - comp->coord[0][0] > 32768 ||
221  comp->coord[1][1] - comp->coord[1][0] > 32768) {
222  av_log(avctx, AV_LOG_ERROR, "component size too large\n");
223  return AVERROR_PATCHWELCOME;
224  }
225 
226  if (codsty->transform == FF_DWT97) {
227  csize += AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*comp->f_data);
228  comp->i_data = NULL;
229  comp->f_data = av_mallocz_array(csize, sizeof(*comp->f_data));
230  if (!comp->f_data)
231  return AVERROR(ENOMEM);
232  } else {
233  csize += AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*comp->i_data);
234  comp->f_data = NULL;
235  comp->i_data = av_mallocz_array(csize, sizeof(*comp->i_data));
236  if (!comp->i_data)
237  return AVERROR(ENOMEM);
238  }
239  comp->reslevel = av_mallocz_array(codsty->nreslevels, sizeof(*comp->reslevel));
240  if (!comp->reslevel)
241  return AVERROR(ENOMEM);
242  /* LOOP on resolution levels */
243  for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
244  int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
245  Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
246 
247  /* Compute borders for each resolution level.
248  * Computation of trx_0, trx_1, try_0 and try_1.
249  * see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
250  for (i = 0; i < 2; i++)
251  for (j = 0; j < 2; j++)
252  reslevel->coord[i][j] =
253  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j], declvl - 1);
254  // update precincts size: 2^n value
255  reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
256  reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
257  if (!reslevel->log2_prec_width || !reslevel->log2_prec_height) {
258  return AVERROR_INVALIDDATA;
259  }
260 
261  /* Number of bands for each resolution level */
262  if (reslevelno == 0)
263  reslevel->nbands = 1;
264  else
265  reslevel->nbands = 3;
266 
267  /* Number of precincts which span the tile for resolution level reslevelno
268  * see B.6 in ISO/IEC 15444-1:2002 eq. B-16
269  * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
270  * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
271  * for Dcinema profiles in JPEG 2000
272  * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
273  * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
274  if (reslevel->coord[0][1] == reslevel->coord[0][0])
275  reslevel->num_precincts_x = 0;
276  else
277  reslevel->num_precincts_x =
278  ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
279  reslevel->log2_prec_width) -
280  (reslevel->coord[0][0] >> reslevel->log2_prec_width);
281 
282  if (reslevel->coord[1][1] == reslevel->coord[1][0])
283  reslevel->num_precincts_y = 0;
284  else
285  reslevel->num_precincts_y =
286  ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
287  reslevel->log2_prec_height) -
288  (reslevel->coord[1][0] >> reslevel->log2_prec_height);
289 
290  reslevel->band = av_mallocz_array(reslevel->nbands, sizeof(*reslevel->band));
291  if (!reslevel->band)
292  return AVERROR(ENOMEM);
293 
294  for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
295  Jpeg2000Band *band = reslevel->band + bandno;
296  int cblkno, precno;
297  int nb_precincts;
298 
299  /* TODO: Implementation of quantization step not finished,
300  * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
301  switch (qntsty->quantsty) {
302  uint8_t gain;
303  case JPEG2000_QSTY_NONE:
304  /* TODO: to verify. No quantization in this case */
305  band->f_stepsize = 1;
306  break;
307  case JPEG2000_QSTY_SI:
308  /*TODO: Compute formula to implement. */
309 // numbps = cbps +
310 // lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];
311 // band->f_stepsize = SHL(2048 + qntsty->mant[gbandno],
312 // 2 + numbps - qntsty->expn[gbandno]);
313 // break;
314  case JPEG2000_QSTY_SE:
315  /* Exponent quantization step.
316  * Formula:
317  * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11))
318  * R_b = R_I + log2 (gain_b )
319  * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */
320  gain = cbps;
321  band->f_stepsize = pow(2.0, gain - qntsty->expn[gbandno]);
322  band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0;
323  break;
324  default:
325  band->f_stepsize = 0;
326  av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
327  break;
328  }
329  if (codsty->transform != FF_DWT53) {
330  int lband = 0;
331  switch (bandno + (reslevelno > 0)) {
332  case 1:
333  case 2:
334  band->f_stepsize *= F_LFTG_X * 2;
335  lband = 1;
336  break;
337  case 3:
338  band->f_stepsize *= F_LFTG_X * F_LFTG_X * 4;
339  break;
340  }
341  if (codsty->transform == FF_DWT97) {
342  band->f_stepsize *= pow(F_LFTG_K, 2*(codsty->nreslevels2decode - reslevelno) + lband - 2);
343  }
344  }
345 
346  band->i_stepsize = band->f_stepsize * (1 << 15);
347 
348  /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
349  * If not set output of entropic decoder is not correct. */
350  if (!av_codec_is_encoder(avctx->codec))
351  band->f_stepsize *= 0.5;
352 
353  /* computation of tbx_0, tbx_1, tby_0, tby_1
354  * see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
355  * codeblock width and height is computed for
356  * DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
357  if (reslevelno == 0) {
358  /* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
359  for (i = 0; i < 2; i++)
360  for (j = 0; j < 2; j++)
361  band->coord[i][j] =
362  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j],
363  declvl - 1);
364  log2_band_prec_width = reslevel->log2_prec_width;
365  log2_band_prec_height = reslevel->log2_prec_height;
366  /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
367  band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
368  reslevel->log2_prec_width);
369  band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
370  reslevel->log2_prec_height);
371  } else {
372  /* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
373  /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
374  for (i = 0; i < 2; i++)
375  for (j = 0; j < 2; j++)
376  /* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
377  band->coord[i][j] =
378  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] -
379  (((bandno + 1 >> i) & 1LL) << declvl - 1),
380  declvl);
381  /* TODO: Manage case of 3 band offsets here or
382  * in coding/decoding function? */
383 
384  /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
385  band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
386  reslevel->log2_prec_width - 1);
387  band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
388  reslevel->log2_prec_height - 1);
389 
390  log2_band_prec_width = reslevel->log2_prec_width - 1;
391  log2_band_prec_height = reslevel->log2_prec_height - 1;
392  }
393 
394  if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
395  band->prec = NULL;
396  return AVERROR(ENOMEM);
397  }
398  nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
399  band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
400  if (!band->prec)
401  return AVERROR(ENOMEM);
402 
403  for (precno = 0; precno < nb_precincts; precno++) {
404  Jpeg2000Prec *prec = band->prec + precno;
405  int nb_codeblocks;
406 
407  prec->decoded_layers = 0;
408 
409  /* TODO: Explain formula for JPEG200 DCINEMA. */
410  /* TODO: Verify with previous count of codeblocks per band */
411 
412  /* Compute P_x0 */
413  prec->coord[0][0] = ((band->coord[0][0] >> log2_band_prec_width) + precno % reslevel->num_precincts_x) *
414  (1 << log2_band_prec_width);
415 
416  /* Compute P_y0 */
417  prec->coord[1][0] = ((band->coord[1][0] >> log2_band_prec_height) + precno / reslevel->num_precincts_x) *
418  (1 << log2_band_prec_height);
419 
420  /* Compute P_x1 */
421  prec->coord[0][1] = prec->coord[0][0] +
422  (1 << log2_band_prec_width);
423  prec->coord[0][0] = FFMAX(prec->coord[0][0], band->coord[0][0]);
424  prec->coord[0][1] = FFMIN(prec->coord[0][1], band->coord[0][1]);
425 
426  /* Compute P_y1 */
427  prec->coord[1][1] = prec->coord[1][0] +
428  (1 << log2_band_prec_height);
429  prec->coord[1][0] = FFMAX(prec->coord[1][0], band->coord[1][0]);
430  prec->coord[1][1] = FFMIN(prec->coord[1][1], band->coord[1][1]);
431 
432  prec->nb_codeblocks_width =
433  ff_jpeg2000_ceildivpow2(prec->coord[0][1],
434  band->log2_cblk_width)
435  - (prec->coord[0][0] >> band->log2_cblk_width);
436  prec->nb_codeblocks_height =
437  ff_jpeg2000_ceildivpow2(prec->coord[1][1],
438  band->log2_cblk_height)
439  - (prec->coord[1][0] >> band->log2_cblk_height);
440 
441 
442  /* Tag trees initialization */
443  prec->cblkincl =
445  prec->nb_codeblocks_height);
446  if (!prec->cblkincl)
447  return AVERROR(ENOMEM);
448 
449  prec->zerobits =
451  prec->nb_codeblocks_height);
452  if (!prec->zerobits)
453  return AVERROR(ENOMEM);
454 
455  if (prec->nb_codeblocks_width * (uint64_t)prec->nb_codeblocks_height > INT_MAX) {
456  prec->cblk = NULL;
457  return AVERROR(ENOMEM);
458  }
459  nb_codeblocks = prec->nb_codeblocks_width * prec->nb_codeblocks_height;
460  prec->cblk = av_mallocz_array(nb_codeblocks, sizeof(*prec->cblk));
461  if (!prec->cblk)
462  return AVERROR(ENOMEM);
463  for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
464  Jpeg2000Cblk *cblk = prec->cblk + cblkno;
465  int Cx0, Cy0;
466 
467  /* Compute coordinates of codeblocks */
468  /* Compute Cx0*/
469  Cx0 = ((prec->coord[0][0]) >> band->log2_cblk_width) << band->log2_cblk_width;
470  Cx0 = Cx0 + ((cblkno % prec->nb_codeblocks_width) << band->log2_cblk_width);
471  cblk->coord[0][0] = FFMAX(Cx0, prec->coord[0][0]);
472 
473  /* Compute Cy0*/
474  Cy0 = ((prec->coord[1][0]) >> band->log2_cblk_height) << band->log2_cblk_height;
475  Cy0 = Cy0 + ((cblkno / prec->nb_codeblocks_width) << band->log2_cblk_height);
476  cblk->coord[1][0] = FFMAX(Cy0, prec->coord[1][0]);
477 
478  /* Compute Cx1 */
479  cblk->coord[0][1] = FFMIN(Cx0 + (1 << band->log2_cblk_width),
480  prec->coord[0][1]);
481 
482  /* Compute Cy1 */
483  cblk->coord[1][1] = FFMIN(Cy0 + (1 << band->log2_cblk_height),
484  prec->coord[1][1]);
485  /* Update code-blocks coordinates according sub-band position */
486  if ((bandno + !!reslevelno) & 1) {
487  cblk->coord[0][0] += comp->reslevel[reslevelno-1].coord[0][1] -
488  comp->reslevel[reslevelno-1].coord[0][0];
489  cblk->coord[0][1] += comp->reslevel[reslevelno-1].coord[0][1] -
490  comp->reslevel[reslevelno-1].coord[0][0];
491  }
492  if ((bandno + !!reslevelno) & 2) {
493  cblk->coord[1][0] += comp->reslevel[reslevelno-1].coord[1][1] -
494  comp->reslevel[reslevelno-1].coord[1][0];
495  cblk->coord[1][1] += comp->reslevel[reslevelno-1].coord[1][1] -
496  comp->reslevel[reslevelno-1].coord[1][0];
497  }
498 
499  cblk->zero = 0;
500  cblk->lblock = 3;
501  cblk->length = 0;
502  memset(cblk->lengthinc, 0, sizeof(cblk->lengthinc));
503  cblk->npasses = 0;
504  }
505  }
506  }
507  }
508  return 0;
509 }
510 
512 {
513  int reslevelno, bandno, cblkno, precno;
514  for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
515  Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
516  for (bandno = 0; bandno < rlevel->nbands; bandno++) {
517  Jpeg2000Band *band = rlevel->band + bandno;
518  for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++) {
519  Jpeg2000Prec *prec = band->prec + precno;
522  for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
523  Jpeg2000Cblk *cblk = prec->cblk + cblkno;
524  cblk->length = 0;
525  cblk->lblock = 3;
526  }
527  }
528  }
529  }
530 }
531 
533 {
534  int reslevelno, bandno, precno;
535  for (reslevelno = 0;
536  comp->reslevel && reslevelno < codsty->nreslevels;
537  reslevelno++) {
538  Jpeg2000ResLevel *reslevel;
539 
540  if (!comp->reslevel)
541  continue;
542 
543  reslevel = comp->reslevel + reslevelno;
544  for (bandno = 0; bandno < reslevel->nbands; bandno++) {
546 
547  if (!reslevel->band)
548  continue;
549 
550  band = reslevel->band + bandno;
551  for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
552  if (band->prec) {
553  Jpeg2000Prec *prec = band->prec + precno;
554  av_freep(&prec->zerobits);
555  av_freep(&prec->cblkincl);
556  av_freep(&prec->cblk);
557  }
558  }
559 
560  av_freep(&band->prec);
561  }
562  av_freep(&reslevel->band);
563  }
564 
565  ff_dwt_destroy(&comp->dwt);
566  av_freep(&comp->reslevel);
567  av_freep(&comp->i_data);
568  av_freep(&comp->f_data);
569 }
uint8_t ff_jpeg2000_sgnctxno_lut[16][16]
Definition: jpeg2000.c:139
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1521
float v
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void av_cold ff_jpeg2000_init_tier1_luts(void)
Definition: jpeg2000.c:158
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Definition: jpeg2000.c:532
DWTContext dwt
Definition: jpeg2000.h:208
Jpeg2000TgtNode * cblkincl
Definition: jpeg2000.h:184
misc image utilities
memory handling functions
float * f_data
Definition: jpeg2000.h:209
int nb_codeblocks_width
Definition: jpeg2000.h:181
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
Definition: jpeg2000.h:151
static const int contribtab[3][3]
Definition: jpeg2000.c:141
static const int xorbittab[3][3]
Definition: jpeg2000.c:143
static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
Definition: jpeg2000.c:84
float f_stepsize
Definition: jpeg2000.h:194
static Jpeg2000TgtNode * ff_jpeg2000_tag_tree_init(int w, int h)
Definition: jpeg2000.c:53
Macro definitions for various function/variable attributes.
uint8_t npasses
Definition: jpeg2000.h:164
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:174
#define JPEG2000_T1_SIG_W
Definition: jpeg2000.h:79
uint16_t log2_cblk_width
Definition: jpeg2000.h:192
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t
#define av_cold
Definition: attributes.h:74
Jpeg2000TgtNode * zerobits
Definition: jpeg2000.h:183
Jpeg2000Band * band
Definition: jpeg2000.h:203
uint8_t val
Definition: jpeg2000.h:129
int coord[2][2]
Definition: jpeg2000.h:211
#define JPEG2000_T1_SIG_NE
Definition: jpeg2000.h:81
#define JPEG2000_T1_SIG_SE
Definition: jpeg2000.h:83
static const int ctxlbltab[3][3]
Definition: jpeg2000.c:142
uint16_t flags[6156]
Definition: jpeg2000.h:123
#define av_log(a,...)
int flag
Definition: checkasm.c:76
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
Definition: jpeg2000.h:145
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2], int decomp_levels, int type)
Initialize DWT.
Definition: jpeg2000dwt.c:537
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
Definition: jpeg2000.c:170
#define F_LFTG_X
Definition: jpeg2000dwt.h:34
#define AVERROR(e)
Definition: error.h:43
int nb_codeblocks_height
Definition: jpeg2000.h:182
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
Definition: jpeg2000.h:146
#define t1
Definition: regdef.h:29
simple assert() macros that are a bit more flexible than ISO C assert().
uint8_t zero
Definition: jpeg2000.h:171
Jpeg2000Cblk * cblk
Definition: jpeg2000.h:185
#define FFMAX(a, b)
Definition: common.h:90
Libavcodec external API header.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:266
uint8_t lblock
Definition: jpeg2000.h:170
#define FFMIN(a, b)
Definition: common.h:92
struct Jpeg2000TgtNode * parent
Definition: jpeg2000.h:131
float y
#define JPEG2000_T1_SGN_S
Definition: jpeg2000.h:91
JPEG 2000 structures and defines common to encoder and decoder.
int i_stepsize
Definition: jpeg2000.h:193
void ff_dwt_destroy(DWTContext *s)
Definition: jpeg2000dwt.c:620
int32_t
#define JPEG2000_T1_SIG_N
Definition: jpeg2000.h:77
int coord[2][2]
Definition: jpeg2000.h:200
int coord[2][2]
Definition: jpeg2000.h:177
uint16_t lengthinc[JPEG2000_MAX_PASSES]
Definition: jpeg2000.h:168
static int ff_jpeg2000_ceildivpow2(int a, int b)
Definition: jpeg2000.h:216
int coord[2][2]
Definition: jpeg2000.h:191
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int coord_o[2][2]
Definition: jpeg2000.h:212
int coord[2][2]
Definition: jpeg2000.h:187
main external API structure.
Definition: avcodec.h:1512
uint8_t vis
Definition: jpeg2000.h:130
uint8_t log2_prec_height
Definition: jpeg2000.h:202
uint16_t length
Definition: jpeg2000.h:167
uint8_t nbands
Definition: jpeg2000.h:199
int decoded_layers
Definition: jpeg2000.h:186
#define JPEG2000_T1_SIG_S
Definition: jpeg2000.h:80
Jpeg2000ResLevel * reslevel
Definition: jpeg2000.h:207
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Definition: jpeg2000.c:511
#define JPEG2000_T1_SGN_E
Definition: jpeg2000.h:93
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
Definition: jpeg2000.h:150
uint8_t quantsty
Definition: jpeg2000.h:152
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:280
uint8_t log2_cblk_width
Definition: jpeg2000.h:137
#define F_LFTG_K
Definition: jpeg2000dwt.h:33
uint16_t log2_cblk_height
Definition: jpeg2000.h:192
static int32_t tag_tree_size(uint16_t w, uint16_t h)
Definition: jpeg2000.c:41
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
Definition: jpeg2000.c:195
#define JPEG2000_T1_SIG_SW
Definition: jpeg2000.h:84
#define JPEG2000_T1_SGN_N
Definition: jpeg2000.h:90
static int getsgnctxno(int flag, uint8_t *xorbit)
Definition: jpeg2000.c:145
#define JPEG2000_T1_SIG_E
Definition: jpeg2000.h:78
Jpeg2000Prec * prec
Definition: jpeg2000.h:195
#define JPEG2000_T1_SIG
Definition: jpeg2000.h:96
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:228
#define av_freep(p)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
static int getsigctxno(int flag, int bandno)
Definition: jpeg2000.c:96
uint8_t log2_cblk_height
Definition: jpeg2000.h:137
#define FFSWAP(type, a, b)
Definition: common.h:95
uint8_t ff_jpeg2000_sigctxno_lut[256][4]
Definition: jpeg2000.c:94
uint8_t log2_prec_width
Definition: jpeg2000.h:202
#define JPEG2000_T1_SIG_NW
Definition: jpeg2000.h:82
#define JPEG2000_T1_SGN_W
Definition: jpeg2000.h:92
#define t2
Definition: regdef.h:30
uint8_t ff_jpeg2000_xorbit_lut[16][16]
Definition: jpeg2000.c:139