FFmpeg  2.6.9
 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][x] |= JPEG2000_T1_SIG;
176  if (negative) {
177  t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W;
178  t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E;
179  t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N;
180  t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S;
181  } else {
182  t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W;
183  t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E;
184  t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N;
185  t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S;
186  }
187  t1->flags[y + 1][x + 1] |= JPEG2000_T1_SIG_NW;
188  t1->flags[y + 1][x - 1] |= JPEG2000_T1_SIG_NE;
189  t1->flags[y - 1][x + 1] |= JPEG2000_T1_SIG_SW;
190  t1->flags[y - 1][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 } };
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] > 32768 ||
221  comp->coord[1][1] > 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  comp->i_data = NULL;
228  comp->f_data = av_mallocz_array(csize, sizeof(*comp->f_data));
229  if (!comp->f_data)
230  return AVERROR(ENOMEM);
231  } else {
232  comp->f_data = NULL;
233  comp->i_data = av_mallocz_array(csize, sizeof(*comp->i_data));
234  if (!comp->i_data)
235  return AVERROR(ENOMEM);
236  }
237  comp->reslevel = av_mallocz_array(codsty->nreslevels, sizeof(*comp->reslevel));
238  if (!comp->reslevel)
239  return AVERROR(ENOMEM);
240  /* LOOP on resolution levels */
241  for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
242  int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
243  Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
244 
245  /* Compute borders for each resolution level.
246  * Computation of trx_0, trx_1, try_0 and try_1.
247  * see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
248  for (i = 0; i < 2; i++)
249  for (j = 0; j < 2; j++)
250  reslevel->coord[i][j] =
251  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j], declvl - 1);
252  // update precincts size: 2^n value
253  reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
254  reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
255 
256  /* Number of bands for each resolution level */
257  if (reslevelno == 0)
258  reslevel->nbands = 1;
259  else
260  reslevel->nbands = 3;
261 
262  /* Number of precincts which span the tile for resolution level reslevelno
263  * see B.6 in ISO/IEC 15444-1:2002 eq. B-16
264  * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
265  * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
266  * for Dcinema profiles in JPEG 2000
267  * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
268  * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
269  if (reslevel->coord[0][1] == reslevel->coord[0][0])
270  reslevel->num_precincts_x = 0;
271  else
272  reslevel->num_precincts_x =
273  ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
274  reslevel->log2_prec_width) -
275  (reslevel->coord[0][0] >> reslevel->log2_prec_width);
276 
277  if (reslevel->coord[1][1] == reslevel->coord[1][0])
278  reslevel->num_precincts_y = 0;
279  else
280  reslevel->num_precincts_y =
281  ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
282  reslevel->log2_prec_height) -
283  (reslevel->coord[1][0] >> reslevel->log2_prec_height);
284 
285  reslevel->band = av_mallocz_array(reslevel->nbands, sizeof(*reslevel->band));
286  if (!reslevel->band)
287  return AVERROR(ENOMEM);
288 
289  for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
290  Jpeg2000Band *band = reslevel->band + bandno;
291  int cblkno, precno;
292  int nb_precincts;
293 
294  /* TODO: Implementation of quantization step not finished,
295  * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
296  switch (qntsty->quantsty) {
297  uint8_t gain;
298  int numbps;
299  case JPEG2000_QSTY_NONE:
300  /* TODO: to verify. No quantization in this case */
301  band->f_stepsize = 1;
302  break;
303  case JPEG2000_QSTY_SI:
304  /*TODO: Compute formula to implement. */
305  numbps = cbps +
306  lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];
307  band->f_stepsize = SHL(2048 + qntsty->mant[gbandno],
308  2 + numbps - qntsty->expn[gbandno]);
309  break;
310  case JPEG2000_QSTY_SE:
311  /* Exponent quantization step.
312  * Formula:
313  * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11))
314  * R_b = R_I + log2 (gain_b )
315  * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */
316  /* TODO/WARN: value of log2 (gain_b ) not taken into account
317  * but it works (compared to OpenJPEG). Why?
318  * Further investigation needed. */
319  gain = cbps;
320  band->f_stepsize = pow(2.0, gain - qntsty->expn[gbandno]);
321  band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0;
322  break;
323  default:
324  band->f_stepsize = 0;
325  av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
326  break;
327  }
328  /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
329  * If not set output of entropic decoder is not correct. */
330  if (!av_codec_is_encoder(avctx->codec))
331  band->f_stepsize *= 0.5;
332 
333  band->i_stepsize = band->f_stepsize * (1 << 15);
334 
335  /* computation of tbx_0, tbx_1, tby_0, tby_1
336  * see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
337  * codeblock width and height is computed for
338  * DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
339  if (reslevelno == 0) {
340  /* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
341  for (i = 0; i < 2; i++)
342  for (j = 0; j < 2; j++)
343  band->coord[i][j] =
344  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] - comp->coord_o[i][0],
345  declvl - 1);
346  log2_band_prec_width = reslevel->log2_prec_width;
347  log2_band_prec_height = reslevel->log2_prec_height;
348  /* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
349  band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
350  reslevel->log2_prec_width);
351  band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
352  reslevel->log2_prec_height);
353  } else {
354  /* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
355  /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
356  for (i = 0; i < 2; i++)
357  for (j = 0; j < 2; j++)
358  /* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
359  band->coord[i][j] =
360  ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] - comp->coord_o[i][0] -
361  (((bandno + 1 >> i) & 1) << declvl - 1),
362  declvl);
363  /* TODO: Manage case of 3 band offsets here or
364  * in coding/decoding function? */
365 
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 - 1);
369  band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
370  reslevel->log2_prec_height - 1);
371 
372  log2_band_prec_width = reslevel->log2_prec_width - 1;
373  log2_band_prec_height = reslevel->log2_prec_height - 1;
374  }
375 
376  for (j = 0; j < 2; j++)
377  band->coord[0][j] = ff_jpeg2000_ceildiv(band->coord[0][j], dx);
378  for (j = 0; j < 2; j++)
379  band->coord[1][j] = ff_jpeg2000_ceildiv(band->coord[1][j], dy);
380 
381  if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
382  band->prec = NULL;
383  return AVERROR(ENOMEM);
384  }
385  nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
386  band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
387  if (!band->prec)
388  return AVERROR(ENOMEM);
389 
390  for (precno = 0; precno < nb_precincts; precno++) {
391  Jpeg2000Prec *prec = band->prec + precno;
392  int nb_codeblocks;
393 
394  /* TODO: Explain formula for JPEG200 DCINEMA. */
395  /* TODO: Verify with previous count of codeblocks per band */
396 
397  /* Compute P_x0 */
398  prec->coord[0][0] = (precno % reslevel->num_precincts_x) *
399  (1 << log2_band_prec_width);
400  prec->coord[0][0] = FFMAX(prec->coord[0][0], band->coord[0][0]);
401 
402  /* Compute P_y0 */
403  prec->coord[1][0] = (precno / reslevel->num_precincts_x) *
404  (1 << log2_band_prec_height);
405  prec->coord[1][0] = FFMAX(prec->coord[1][0], band->coord[1][0]);
406 
407  /* Compute P_x1 */
408  prec->coord[0][1] = prec->coord[0][0] +
409  (1 << log2_band_prec_width);
410  prec->coord[0][1] = FFMIN(prec->coord[0][1], band->coord[0][1]);
411 
412  /* Compute P_y1 */
413  prec->coord[1][1] = prec->coord[1][0] +
414  (1 << log2_band_prec_height);
415  prec->coord[1][1] = FFMIN(prec->coord[1][1], band->coord[1][1]);
416 
417  prec->nb_codeblocks_width =
418  ff_jpeg2000_ceildivpow2(prec->coord[0][1] -
419  prec->coord[0][0],
420  band->log2_cblk_width);
421  prec->nb_codeblocks_height =
422  ff_jpeg2000_ceildivpow2(prec->coord[1][1] -
423  prec->coord[1][0],
424  band->log2_cblk_height);
425 
426  /* Tag trees initialization */
427  prec->cblkincl =
429  prec->nb_codeblocks_height);
430  if (!prec->cblkincl)
431  return AVERROR(ENOMEM);
432 
433  prec->zerobits =
435  prec->nb_codeblocks_height);
436  if (!prec->zerobits)
437  return AVERROR(ENOMEM);
438 
439  if (prec->nb_codeblocks_width * (uint64_t)prec->nb_codeblocks_height > INT_MAX) {
440  prec->cblk = NULL;
441  return AVERROR(ENOMEM);
442  }
443  nb_codeblocks = prec->nb_codeblocks_width * prec->nb_codeblocks_height;
444  prec->cblk = av_mallocz_array(nb_codeblocks, sizeof(*prec->cblk));
445  if (!prec->cblk)
446  return AVERROR(ENOMEM);
447  for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
448  Jpeg2000Cblk *cblk = prec->cblk + cblkno;
449  uint16_t Cx0, Cy0;
450 
451  /* Compute coordinates of codeblocks */
452  /* Compute Cx0*/
453  Cx0 = (prec->coord[0][0] >> band->log2_cblk_width) << band->log2_cblk_width;
454  Cx0 = Cx0 + ((cblkno % prec->nb_codeblocks_width) << band->log2_cblk_width);
455  cblk->coord[0][0] = FFMAX(Cx0, prec->coord[0][0]);
456 
457  /* Compute Cy0*/
458  Cy0 = (prec->coord[1][0] >> band->log2_cblk_height) << band->log2_cblk_height;
459  Cy0 = Cy0 + ((cblkno / prec->nb_codeblocks_width) << band->log2_cblk_height);
460  cblk->coord[1][0] = FFMAX(Cy0, prec->coord[1][0]);
461 
462  /* Compute Cx1 */
463  cblk->coord[0][1] = FFMIN(Cx0 + (1 << band->log2_cblk_width),
464  prec->coord[0][1]);
465 
466  /* Compute Cy1 */
467  cblk->coord[1][1] = FFMIN(Cy0 + (1 << band->log2_cblk_height),
468  prec->coord[1][1]);
469  /* Update code-blocks coordinates according sub-band position */
470  if ((bandno + !!reslevelno) & 1) {
471  cblk->coord[0][0] += comp->reslevel[reslevelno-1].coord[0][1] -
472  comp->reslevel[reslevelno-1].coord[0][0];
473  cblk->coord[0][1] += comp->reslevel[reslevelno-1].coord[0][1] -
474  comp->reslevel[reslevelno-1].coord[0][0];
475  }
476  if ((bandno + !!reslevelno) & 2) {
477  cblk->coord[1][0] += comp->reslevel[reslevelno-1].coord[1][1] -
478  comp->reslevel[reslevelno-1].coord[1][0];
479  cblk->coord[1][1] += comp->reslevel[reslevelno-1].coord[1][1] -
480  comp->reslevel[reslevelno-1].coord[1][0];
481  }
482 
483  cblk->zero = 0;
484  cblk->lblock = 3;
485  cblk->length = 0;
486  cblk->lengthinc = 0;
487  cblk->npasses = 0;
488  }
489  }
490  }
491  }
492  return 0;
493 }
494 
496 {
497  int reslevelno, bandno, cblkno, precno;
498  for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
499  Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
500  for (bandno = 0; bandno < rlevel->nbands; bandno++) {
501  Jpeg2000Band *band = rlevel->band + bandno;
502  for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++) {
503  Jpeg2000Prec *prec = band->prec + precno;
506  for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
507  Jpeg2000Cblk *cblk = prec->cblk + cblkno;
508  cblk->length = 0;
509  cblk->lblock = 3;
510  }
511  }
512  }
513  }
514 }
515 
517 {
518  int reslevelno, bandno, precno;
519  for (reslevelno = 0;
520  comp->reslevel && reslevelno < codsty->nreslevels;
521  reslevelno++) {
522  Jpeg2000ResLevel *reslevel;
523 
524  if (!comp->reslevel)
525  continue;
526 
527  reslevel = comp->reslevel + reslevelno;
528  for (bandno = 0; bandno < reslevel->nbands; bandno++) {
530 
531  if (!reslevel->band)
532  continue;
533 
534  band = reslevel->band + bandno;
535  for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
536  if (band->prec) {
537  Jpeg2000Prec *prec = band->prec + precno;
538  av_freep(&prec->zerobits);
539  av_freep(&prec->cblkincl);
540  av_freep(&prec->cblk);
541  }
542  }
543 
544  av_freep(&band->prec);
545  }
546  av_freep(&reslevel->band);
547  }
548 
549  ff_dwt_destroy(&comp->dwt);
550  av_freep(&comp->reslevel);
551  av_freep(&comp->i_data);
552  av_freep(&comp->f_data);
553 }
uint8_t ff_jpeg2000_sgnctxno_lut[16][16]
Definition: jpeg2000.c:139
uint16_t coord[2][2]
Definition: jpeg2000.h:178
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1248
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
int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2]
Definition: jpeg2000.h:122
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Definition: jpeg2000.c:516
DWTContext dwt
Definition: jpeg2000.h:199
Jpeg2000TgtNode * cblkincl
Definition: jpeg2000.h:176
misc image utilities
memory handling functions
float * f_data
Definition: jpeg2000.h:200
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
Definition: jpeg2000.h:149
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:185
uint16_t nb_codeblocks_height
Definition: jpeg2000.h:174
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:160
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:187
#define JPEG2000_T1_SIG_W
Definition: jpeg2000.h:78
uint16_t log2_cblk_width
Definition: jpeg2000.h:183
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static const uint8_t lut_gain[2][4]
Definition: jpeg2000.c:193
uint8_t
#define av_cold
Definition: attributes.h:74
Jpeg2000TgtNode * zerobits
Definition: jpeg2000.h:175
int ff_jpeg2000_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type)
Initialize DWT.
Definition: jpeg2000dwt.c:497
Jpeg2000Band * band
Definition: jpeg2000.h:194
uint8_t val
Definition: jpeg2000.h:127
#define SHL(a, n)
Definition: jpeg2000.c:36
#define JPEG2000_T1_SIG_NE
Definition: jpeg2000.h:80
uint16_t num_precincts_x
Definition: jpeg2000.h:192
#define JPEG2000_T1_SIG_SE
Definition: jpeg2000.h:82
static const int ctxlbltab[3][3]
Definition: jpeg2000.c:142
#define av_log(a,...)
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
Definition: jpeg2000.h:143
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
Definition: jpeg2000.c:170
#define AVERROR(e)
Definition: error.h:43
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
Definition: jpeg2000.h:144
#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:166
Jpeg2000Cblk * cblk
Definition: jpeg2000.h:177
#define FFMAX(a, b)
Definition: common.h:79
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:241
uint8_t lblock
Definition: jpeg2000.h:165
#define FFMIN(a, b)
Definition: common.h:81
struct Jpeg2000TgtNode * parent
Definition: jpeg2000.h:129
float y
#define JPEG2000_T1_SGN_S
Definition: jpeg2000.h:90
ret
Definition: avfilter.c:974
JPEG 2000 structures and defines common to encoder and decoder.
int i_stepsize
Definition: jpeg2000.h:184
void ff_dwt_destroy(DWTContext *s)
Definition: jpeg2000dwt.c:580
int32_t
uint16_t num_precincts_y
Definition: jpeg2000.h:192
#define JPEG2000_T1_SIG_N
Definition: jpeg2000.h:76
uint16_t lengthinc
Definition: jpeg2000.h:164
static int ff_jpeg2000_ceildivpow2(int a, int b)
Definition: jpeg2000.h:207
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
uint16_t coord[2][2]
Definition: jpeg2000.h:182
uint16_t coord[2][2]
Definition: jpeg2000.h:169
main external API structure.
Definition: avcodec.h:1239
uint8_t vis
Definition: jpeg2000.h:128
uint8_t log2_prec_height
Definition: jpeg2000.h:193
uint16_t length
Definition: jpeg2000.h:163
uint8_t nbands
Definition: jpeg2000.h:190
uint16_t nb_codeblocks_width
Definition: jpeg2000.h:173
uint16_t coord[2][2]
Definition: jpeg2000.h:202
#define JPEG2000_T1_SIG_S
Definition: jpeg2000.h:79
Jpeg2000ResLevel * reslevel
Definition: jpeg2000.h:198
static int ff_jpeg2000_ceildiv(int a, int b)
Definition: jpeg2000.h:212
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Definition: jpeg2000.c:495
#define JPEG2000_T1_SGN_E
Definition: jpeg2000.h:92
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
Definition: jpeg2000.h:148
uint8_t quantsty
Definition: jpeg2000.h:150
common internal and external API header
uint8_t log2_cblk_width
Definition: jpeg2000.h:135
uint16_t coord_o[2][2]
Definition: jpeg2000.h:203
uint16_t log2_cblk_height
Definition: jpeg2000.h:183
static int32_t tag_tree_size(uint16_t w, uint16_t h)
Definition: jpeg2000.c:41
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:83
uint16_t coord[2][2]
Definition: jpeg2000.h:191
#define JPEG2000_T1_SGN_N
Definition: jpeg2000.h:89
static int getsgnctxno(int flag, uint8_t *xorbit)
Definition: jpeg2000.c:145
#define JPEG2000_T1_SIG_E
Definition: jpeg2000.h:77
Jpeg2000Prec * prec
Definition: jpeg2000.h:186
#define JPEG2000_T1_SIG
Definition: jpeg2000.h:95
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:135
#define FFSWAP(type, a, b)
Definition: common.h:84
uint8_t ff_jpeg2000_sigctxno_lut[256][4]
Definition: jpeg2000.c:94
uint8_t log2_prec_width
Definition: jpeg2000.h:193
#define JPEG2000_T1_SIG_NW
Definition: jpeg2000.h:81
#define JPEG2000_T1_SGN_W
Definition: jpeg2000.h:91
#define t2
Definition: regdef.h:30
uint8_t ff_jpeg2000_xorbit_lut[16][16]
Definition: jpeg2000.c:139