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