You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
Merge commit '570fcaf3326aef9313b10863e2f6e6ae664d9dae'
* commit '570fcaf3326aef9313b10863e2f6e6ae664d9dae': jpeg2000: Factor out prec init Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
This commit is contained in:
@@ -253,76 +253,15 @@ static void init_band_stepsize(AVCodecContext *avctx,
|
|||||||
band->f_stepsize *= 0.5;
|
band->f_stepsize *= 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_band(AVCodecContext *avctx,
|
static int init_prec(Jpeg2000Band *band,
|
||||||
Jpeg2000ResLevel *reslevel,
|
Jpeg2000ResLevel *reslevel,
|
||||||
Jpeg2000Component *comp,
|
Jpeg2000Component *comp,
|
||||||
Jpeg2000CodingStyle *codsty,
|
int precno, int bandno, int reslevelno,
|
||||||
Jpeg2000QuantStyle *qntsty,
|
int log2_band_prec_width,
|
||||||
int bandno, int gbandno, int reslevelno,
|
int log2_band_prec_height)
|
||||||
int cbps, int dx, int dy)
|
|
||||||
{
|
{
|
||||||
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 nb_precincts;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
init_band_stepsize(avctx, band, codsty, qntsty, bandno, gbandno, reslevelno, cbps);
|
|
||||||
|
|
||||||
/* computation of tbx_0, tbx_1, tby_0, tby_1
|
|
||||||
* see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
|
|
||||||
* codeblock width and height is computed for
|
|
||||||
* DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
|
|
||||||
if (reslevelno == 0) {
|
|
||||||
/* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
|
|
||||||
for (i = 0; i < 2; i++)
|
|
||||||
for (j = 0; j < 2; j++)
|
|
||||||
band->coord[i][j] =
|
|
||||||
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j],
|
|
||||||
declvl - 1);
|
|
||||||
log2_band_prec_width = reslevel->log2_prec_width;
|
|
||||||
log2_band_prec_height = reslevel->log2_prec_height;
|
|
||||||
/* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
|
|
||||||
band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
|
|
||||||
reslevel->log2_prec_width);
|
|
||||||
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
|
|
||||||
reslevel->log2_prec_height);
|
|
||||||
} else {
|
|
||||||
/* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
|
|
||||||
/* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
|
|
||||||
for (i = 0; i < 2; i++)
|
|
||||||
for (j = 0; j < 2; j++)
|
|
||||||
/* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
|
|
||||||
band->coord[i][j] =
|
|
||||||
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] -
|
|
||||||
(((bandno + 1 >> i) & 1LL) << declvl - 1),
|
|
||||||
declvl);
|
|
||||||
/* TODO: Manage case of 3 band offsets here or
|
|
||||||
* in coding/decoding function? */
|
|
||||||
|
|
||||||
/* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
|
|
||||||
band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
|
|
||||||
reslevel->log2_prec_width - 1);
|
|
||||||
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
|
|
||||||
reslevel->log2_prec_height - 1);
|
|
||||||
|
|
||||||
log2_band_prec_width = reslevel->log2_prec_width - 1;
|
|
||||||
log2_band_prec_height = reslevel->log2_prec_height - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
|
|
||||||
band->prec = NULL;
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
|
|
||||||
band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
|
|
||||||
if (!band->prec)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
for (precno = 0; precno < nb_precincts; precno++) {
|
|
||||||
Jpeg2000Prec *prec = band->prec + precno;
|
Jpeg2000Prec *prec = band->prec + precno;
|
||||||
int nb_codeblocks;
|
int nb_codeblocks, cblkno;
|
||||||
|
|
||||||
prec->decoded_layers = 0;
|
prec->decoded_layers = 0;
|
||||||
|
|
||||||
@@ -422,6 +361,83 @@ static int init_band(AVCodecContext *avctx,
|
|||||||
memset(cblk->lengthinc, 0, sizeof(cblk->lengthinc));
|
memset(cblk->lengthinc, 0, sizeof(cblk->lengthinc));
|
||||||
cblk->npasses = 0;
|
cblk->npasses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_band(AVCodecContext *avctx,
|
||||||
|
Jpeg2000ResLevel *reslevel,
|
||||||
|
Jpeg2000Component *comp,
|
||||||
|
Jpeg2000CodingStyle *codsty,
|
||||||
|
Jpeg2000QuantStyle *qntsty,
|
||||||
|
int bandno, int gbandno, int reslevelno,
|
||||||
|
int cbps, int dx, int dy)
|
||||||
|
{
|
||||||
|
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 precno;
|
||||||
|
int nb_precincts;
|
||||||
|
int i, j, ret;
|
||||||
|
|
||||||
|
init_band_stepsize(avctx, band, codsty, qntsty, bandno, gbandno, reslevelno, cbps);
|
||||||
|
|
||||||
|
/* computation of tbx_0, tbx_1, tby_0, tby_1
|
||||||
|
* see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
|
||||||
|
* codeblock width and height is computed for
|
||||||
|
* DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
|
||||||
|
if (reslevelno == 0) {
|
||||||
|
/* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
band->coord[i][j] =
|
||||||
|
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j],
|
||||||
|
declvl - 1);
|
||||||
|
log2_band_prec_width = reslevel->log2_prec_width;
|
||||||
|
log2_band_prec_height = reslevel->log2_prec_height;
|
||||||
|
/* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
|
||||||
|
band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
|
||||||
|
reslevel->log2_prec_width);
|
||||||
|
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
|
||||||
|
reslevel->log2_prec_height);
|
||||||
|
} else {
|
||||||
|
/* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
|
||||||
|
/* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
/* Formula example for tbx_0 = ceildiv((tcx_0 - 2 ^ (declvl - 1) * x0_b) / declvl) */
|
||||||
|
band->coord[i][j] =
|
||||||
|
ff_jpeg2000_ceildivpow2(comp->coord_o[i][j] -
|
||||||
|
(((bandno + 1 >> i) & 1LL) << declvl - 1),
|
||||||
|
declvl);
|
||||||
|
/* TODO: Manage case of 3 band offsets here or
|
||||||
|
* in coding/decoding function? */
|
||||||
|
|
||||||
|
/* see ISO/IEC 15444-1:2002 eq. B-17 and eq. B-15 */
|
||||||
|
band->log2_cblk_width = FFMIN(codsty->log2_cblk_width,
|
||||||
|
reslevel->log2_prec_width - 1);
|
||||||
|
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
|
||||||
|
reslevel->log2_prec_height - 1);
|
||||||
|
|
||||||
|
log2_band_prec_width = reslevel->log2_prec_width - 1;
|
||||||
|
log2_band_prec_height = reslevel->log2_prec_height - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
|
||||||
|
band->prec = NULL;
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
|
||||||
|
band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
|
||||||
|
if (!band->prec)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
for (precno = 0; precno < nb_precincts; precno++) {
|
||||||
|
ret = init_prec(band, reslevel, comp,
|
||||||
|
precno, bandno, reslevelno,
|
||||||
|
log2_band_prec_width, log2_band_prec_height);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user