jpeg2000: Factor out band initialization
This commit is contained in:
parent
1b709f23fb
commit
7fb93eae43
@ -195,96 +195,20 @@ void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y,
|
|||||||
|
|
||||||
static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } };
|
static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } };
|
||||||
|
|
||||||
int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
static int init_band(AVCodecContext *avctx,
|
||||||
|
Jpeg2000ResLevel *reslevel,
|
||||||
|
Jpeg2000Component *comp,
|
||||||
Jpeg2000CodingStyle *codsty,
|
Jpeg2000CodingStyle *codsty,
|
||||||
Jpeg2000QuantStyle *qntsty,
|
Jpeg2000QuantStyle *qntsty,
|
||||||
int cbps, int dx, int dy,
|
int bandno, int gbandno, int reslevelno,
|
||||||
AVCodecContext *avctx)
|
int cbps, int dx, int dy)
|
||||||
{
|
{
|
||||||
uint8_t log2_band_prec_width, log2_band_prec_height;
|
|
||||||
int reslevelno, bandno, gbandno = 0, ret, i, j;
|
|
||||||
uint32_t csize;
|
|
||||||
|
|
||||||
if (!codsty->nreslevels2decode) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "nreslevels2decode uninitialized\n");
|
|
||||||
return AVERROR_INVALIDDATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
|
|
||||||
codsty->nreslevels2decode - 1,
|
|
||||||
codsty->transform))
|
|
||||||
return ret;
|
|
||||||
// component size comp->coord is uint16_t so ir cannot overflow
|
|
||||||
csize = (comp->coord[0][1] - comp->coord[0][0]) *
|
|
||||||
(comp->coord[1][1] - comp->coord[1][0]);
|
|
||||||
|
|
||||||
if (codsty->transform == FF_DWT97) {
|
|
||||||
comp->i_data = NULL;
|
|
||||||
comp->f_data = av_malloc_array(csize, sizeof(*comp->f_data));
|
|
||||||
if (!comp->f_data)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
} else {
|
|
||||||
comp->f_data = NULL;
|
|
||||||
comp->i_data = av_malloc_array(csize, sizeof(*comp->i_data));
|
|
||||||
if (!comp->i_data)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
comp->reslevel = av_mallocz_array(codsty->nreslevels, sizeof(*comp->reslevel));
|
|
||||||
if (!comp->reslevel)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
/* LOOP on resolution levels */
|
|
||||||
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
|
|
||||||
int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
|
|
||||||
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
|
|
||||||
|
|
||||||
/* Compute borders for each resolution level.
|
|
||||||
* Computation of trx_0, trx_1, try_0 and try_1.
|
|
||||||
* see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
|
|
||||||
for (i = 0; i < 2; i++)
|
|
||||||
for (j = 0; j < 2; j++)
|
|
||||||
reslevel->coord[i][j] =
|
|
||||||
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j], declvl - 1);
|
|
||||||
// update precincts size: 2^n value
|
|
||||||
reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
|
|
||||||
reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
|
|
||||||
|
|
||||||
/* Number of bands for each resolution level */
|
|
||||||
if (reslevelno == 0)
|
|
||||||
reslevel->nbands = 1;
|
|
||||||
else
|
|
||||||
reslevel->nbands = 3;
|
|
||||||
|
|
||||||
/* Number of precincts wich span the tile for resolution level reslevelno
|
|
||||||
* see B.6 in ISO/IEC 15444-1:2002 eq. B-16
|
|
||||||
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
|
|
||||||
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
|
|
||||||
* for Dcinema profiles in JPEG 2000
|
|
||||||
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
|
|
||||||
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
|
|
||||||
if (reslevel->coord[0][1] == reslevel->coord[0][0])
|
|
||||||
reslevel->num_precincts_x = 0;
|
|
||||||
else
|
|
||||||
reslevel->num_precincts_x =
|
|
||||||
ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
|
|
||||||
reslevel->log2_prec_width) -
|
|
||||||
(reslevel->coord[0][0] >> reslevel->log2_prec_width);
|
|
||||||
|
|
||||||
if (reslevel->coord[1][1] == reslevel->coord[1][0])
|
|
||||||
reslevel->num_precincts_y = 0;
|
|
||||||
else
|
|
||||||
reslevel->num_precincts_y =
|
|
||||||
ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
|
|
||||||
reslevel->log2_prec_height) -
|
|
||||||
(reslevel->coord[1][0] >> reslevel->log2_prec_height);
|
|
||||||
|
|
||||||
reslevel->band = av_mallocz_array(reslevel->nbands, sizeof(*reslevel->band));
|
|
||||||
if (!reslevel->band)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
|
|
||||||
Jpeg2000Band *band = reslevel->band + bandno;
|
Jpeg2000Band *band = reslevel->band + bandno;
|
||||||
|
uint8_t log2_band_prec_width, log2_band_prec_height;
|
||||||
|
int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
|
||||||
int cblkno, precno;
|
int cblkno, precno;
|
||||||
int nb_precincts;
|
int nb_precincts;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
/* TODO: Implementation of quantization step not finished,
|
/* TODO: Implementation of quantization step not finished,
|
||||||
* see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
|
* see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
|
||||||
@ -474,6 +398,102 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
|||||||
cblk->npasses = 0;
|
cblk->npasses = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
||||||
|
Jpeg2000CodingStyle *codsty,
|
||||||
|
Jpeg2000QuantStyle *qntsty,
|
||||||
|
int cbps, int dx, int dy,
|
||||||
|
AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
int reslevelno, bandno, gbandno = 0, ret, i, j;
|
||||||
|
uint32_t csize;
|
||||||
|
|
||||||
|
if (!codsty->nreslevels2decode) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "nreslevels2decode uninitialized\n");
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
|
||||||
|
codsty->nreslevels2decode - 1,
|
||||||
|
codsty->transform))
|
||||||
|
return ret;
|
||||||
|
// component size comp->coord is uint16_t so ir cannot overflow
|
||||||
|
csize = (comp->coord[0][1] - comp->coord[0][0]) *
|
||||||
|
(comp->coord[1][1] - comp->coord[1][0]);
|
||||||
|
|
||||||
|
if (codsty->transform == FF_DWT97) {
|
||||||
|
comp->i_data = NULL;
|
||||||
|
comp->f_data = av_malloc_array(csize, sizeof(*comp->f_data));
|
||||||
|
if (!comp->f_data)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
} else {
|
||||||
|
comp->f_data = NULL;
|
||||||
|
comp->i_data = av_malloc_array(csize, sizeof(*comp->i_data));
|
||||||
|
if (!comp->i_data)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
comp->reslevel = av_mallocz_array(codsty->nreslevels, sizeof(*comp->reslevel));
|
||||||
|
if (!comp->reslevel)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
/* LOOP on resolution levels */
|
||||||
|
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
|
||||||
|
int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
|
||||||
|
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
|
||||||
|
|
||||||
|
/* Compute borders for each resolution level.
|
||||||
|
* Computation of trx_0, trx_1, try_0 and try_1.
|
||||||
|
* see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
reslevel->coord[i][j] =
|
||||||
|
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j], declvl - 1);
|
||||||
|
// update precincts size: 2^n value
|
||||||
|
reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
|
||||||
|
reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
|
||||||
|
|
||||||
|
/* Number of bands for each resolution level */
|
||||||
|
if (reslevelno == 0)
|
||||||
|
reslevel->nbands = 1;
|
||||||
|
else
|
||||||
|
reslevel->nbands = 3;
|
||||||
|
|
||||||
|
/* Number of precincts wich span the tile for resolution level reslevelno
|
||||||
|
* see B.6 in ISO/IEC 15444-1:2002 eq. B-16
|
||||||
|
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
|
||||||
|
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
|
||||||
|
* for Dcinema profiles in JPEG 2000
|
||||||
|
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
|
||||||
|
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
|
||||||
|
if (reslevel->coord[0][1] == reslevel->coord[0][0])
|
||||||
|
reslevel->num_precincts_x = 0;
|
||||||
|
else
|
||||||
|
reslevel->num_precincts_x =
|
||||||
|
ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
|
||||||
|
reslevel->log2_prec_width) -
|
||||||
|
(reslevel->coord[0][0] >> reslevel->log2_prec_width);
|
||||||
|
|
||||||
|
if (reslevel->coord[1][1] == reslevel->coord[1][0])
|
||||||
|
reslevel->num_precincts_y = 0;
|
||||||
|
else
|
||||||
|
reslevel->num_precincts_y =
|
||||||
|
ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
|
||||||
|
reslevel->log2_prec_height) -
|
||||||
|
(reslevel->coord[1][0] >> reslevel->log2_prec_height);
|
||||||
|
|
||||||
|
reslevel->band = av_mallocz_array(reslevel->nbands, sizeof(*reslevel->band));
|
||||||
|
if (!reslevel->band)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) {
|
||||||
|
ret = init_band(avctx, reslevel,
|
||||||
|
comp, codsty, qntsty,
|
||||||
|
bandno, gbandno, reslevelno,
|
||||||
|
cbps, dx, dy);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user