mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
jpeg2000: Use separate fields for int and float codepaths
Split stepsize and data into int and float variants. Eliminates a number of casts and simplifies spotting errors. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
parent
a458b91cf4
commit
5bf208f659
@ -217,9 +217,17 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
|||||||
csize = (comp->coord[0][1] - comp->coord[0][0]) *
|
csize = (comp->coord[0][1] - comp->coord[0][0]) *
|
||||||
(comp->coord[1][1] - comp->coord[1][0]);
|
(comp->coord[1][1] - comp->coord[1][0]);
|
||||||
|
|
||||||
comp->data = av_malloc_array(csize, sizeof(*comp->data));
|
if (codsty->transform == FF_DWT97) {
|
||||||
if (!comp->data)
|
comp->i_data = NULL;
|
||||||
return AVERROR(ENOMEM);
|
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_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel));
|
comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel));
|
||||||
if (!comp->reslevel)
|
if (!comp->reslevel)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -290,8 +298,8 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
|||||||
/*TODO: Compute formula to implement. */
|
/*TODO: Compute formula to implement. */
|
||||||
numbps = cbps +
|
numbps = cbps +
|
||||||
lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];
|
lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];
|
||||||
band->stepsize = (float)SHL(2048 + qntsty->mant[gbandno],
|
band->f_stepsize = SHL(2048 + qntsty->mant[gbandno],
|
||||||
2 + numbps - qntsty->expn[gbandno]);
|
2 + numbps - qntsty->expn[gbandno]);
|
||||||
break;
|
break;
|
||||||
case JPEG2000_QSTY_SE:
|
case JPEG2000_QSTY_SE:
|
||||||
/* Exponent quantization step.
|
/* Exponent quantization step.
|
||||||
@ -303,20 +311,20 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
|
|||||||
* but it works (compared to OpenJPEG). Why?
|
* but it works (compared to OpenJPEG). Why?
|
||||||
* Further investigation needed. */
|
* Further investigation needed. */
|
||||||
gain = cbps;
|
gain = cbps;
|
||||||
band->stepsize = pow(2.0, gain - qntsty->expn[gbandno]);
|
band->f_stepsize = pow(2.0, gain - qntsty->expn[gbandno]);
|
||||||
band->stepsize *= (float)qntsty->mant[gbandno] / 2048.0 + 1.0;
|
band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
band->stepsize = 0;
|
band->f_stepsize = 0;
|
||||||
av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
|
av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
|
/* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
|
||||||
* If not set output of entropic decoder is not correct. */
|
* If not set output of entropic decoder is not correct. */
|
||||||
band->stepsize *= 0.5;
|
if (!av_codec_is_encoder(avctx->codec))
|
||||||
/* BITEXACT computing case --> convert to int */
|
band->f_stepsize *= 0.5;
|
||||||
if (avctx->flags & CODEC_FLAG_BITEXACT)
|
|
||||||
band->stepsize = (int32_t)(band->stepsize * (1 << 16));
|
band->i_stepsize = band->f_stepsize * (1 << 16);
|
||||||
|
|
||||||
/* computation of tbx_0, tbx_1, tby_0, tby_1
|
/* 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
|
* see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
|
||||||
@ -491,5 +499,6 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
|
|||||||
|
|
||||||
ff_dwt_destroy(&comp->dwt);
|
ff_dwt_destroy(&comp->dwt);
|
||||||
av_freep(&comp->reslevel);
|
av_freep(&comp->reslevel);
|
||||||
av_freep(&comp->data);
|
av_freep(&comp->i_data);
|
||||||
|
av_freep(&comp->f_data);
|
||||||
}
|
}
|
||||||
|
@ -178,12 +178,11 @@ typedef struct Jpeg2000Prec {
|
|||||||
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
|
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
|
||||||
} Jpeg2000Prec; // precinct
|
} Jpeg2000Prec; // precinct
|
||||||
|
|
||||||
/* TODO: stepsize can be float or integer depending on
|
|
||||||
* reversible or irreversible transformation. */
|
|
||||||
typedef struct Jpeg2000Band {
|
typedef struct Jpeg2000Band {
|
||||||
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
|
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
|
||||||
uint16_t log2_cblk_width, log2_cblk_height;
|
uint16_t log2_cblk_width, log2_cblk_height;
|
||||||
float stepsize; // quantization stepsize
|
int i_stepsize; // quantization stepsize
|
||||||
|
float f_stepsize; // quantization stepsize
|
||||||
Jpeg2000Prec *prec;
|
Jpeg2000Prec *prec;
|
||||||
} Jpeg2000Band; // subband
|
} Jpeg2000Band; // subband
|
||||||
|
|
||||||
@ -195,13 +194,11 @@ typedef struct Jpeg2000ResLevel {
|
|||||||
Jpeg2000Band *band;
|
Jpeg2000Band *band;
|
||||||
} Jpeg2000ResLevel; // resolution level
|
} Jpeg2000ResLevel; // resolution level
|
||||||
|
|
||||||
/* TODO: data can be float of integer depending of reversible/irreversible
|
|
||||||
* transformation.
|
|
||||||
*/
|
|
||||||
typedef struct Jpeg2000Component {
|
typedef struct Jpeg2000Component {
|
||||||
Jpeg2000ResLevel *reslevel;
|
Jpeg2000ResLevel *reslevel;
|
||||||
DWTContext dwt;
|
DWTContext dwt;
|
||||||
float *data;
|
float *f_data;
|
||||||
|
int *i_data;
|
||||||
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- can be reduced with lowres option
|
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- can be reduced with lowres option
|
||||||
uint16_t coord_o[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- original values from jpeg2000 headers
|
uint16_t coord_o[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- original values from jpeg2000 headers
|
||||||
} Jpeg2000Component;
|
} Jpeg2000Component;
|
||||||
|
@ -990,11 +990,11 @@ static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk,
|
|||||||
Jpeg2000T1Context *t1, Jpeg2000Band *band)
|
Jpeg2000T1Context *t1, Jpeg2000Band *band)
|
||||||
{
|
{
|
||||||
int i, j, idx;
|
int i, j, idx;
|
||||||
float *datap = &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x];
|
float *datap = &comp->f_data[(comp->coord[0][1] - comp->coord[0][0]) * y + x];
|
||||||
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
|
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
|
||||||
for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
|
for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
|
||||||
idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i;
|
idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i;
|
||||||
datap[idx] = (float)(t1->data[j][i]) * ((float)band->stepsize);
|
datap[idx] = (float)(t1->data[j][i]) * band->f_stepsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1004,13 +1004,12 @@ static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
|
|||||||
Jpeg2000T1Context *t1, Jpeg2000Band *band)
|
Jpeg2000T1Context *t1, Jpeg2000Band *band)
|
||||||
{
|
{
|
||||||
int i, j, idx;
|
int i, j, idx;
|
||||||
int32_t *datap =
|
int32_t *datap = &comp->i_data[(comp->coord[0][1] - comp->coord[0][0]) * y + x];
|
||||||
(int32_t *) &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x];
|
|
||||||
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
|
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
|
||||||
for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
|
for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
|
||||||
idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i;
|
idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i;
|
||||||
datap[idx] =
|
datap[idx] =
|
||||||
((int32_t)(t1->data[j][i]) * ((int32_t)band->stepsize) + (1 << 15)) >> 16;
|
((int32_t)(t1->data[j][i]) * band->i_stepsize + (1 << 15)) >> 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1037,9 +1036,9 @@ static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
|
|||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
if (tile->codsty[0].transform == FF_DWT97)
|
if (tile->codsty[0].transform == FF_DWT97)
|
||||||
srcf[i] = tile->comp[i].data;
|
srcf[i] = tile->comp[i].f_data;
|
||||||
else
|
else
|
||||||
src[i] = (int32_t *)tile->comp[i].data;
|
src [i] = tile->comp[i].i_data;
|
||||||
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
|
csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
|
||||||
@ -1129,21 +1128,23 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
|||||||
} /* end reslevel */
|
} /* end reslevel */
|
||||||
|
|
||||||
/* inverse DWT */
|
/* inverse DWT */
|
||||||
ff_dwt_decode(&comp->dwt, comp->data);
|
ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data);
|
||||||
} /*end comp */
|
} /*end comp */
|
||||||
|
|
||||||
/* inverse MCT transformation */
|
/* inverse MCT transformation */
|
||||||
if (tile->codsty[0].mct)
|
if (tile->codsty[0].mct)
|
||||||
mct_decode(s, tile);
|
mct_decode(s, tile);
|
||||||
|
|
||||||
if (s->avctx->pix_fmt == AV_PIX_FMT_BGRA) // RGBA -> BGRA
|
if (s->avctx->pix_fmt == AV_PIX_FMT_BGRA) { // RGBA -> BGRA
|
||||||
FFSWAP(float *, tile->comp[0].data, tile->comp[2].data);
|
FFSWAP(float *, tile->comp[0].f_data, tile->comp[2].f_data);
|
||||||
|
FFSWAP(int *, tile->comp[0].i_data, tile->comp[2].i_data);
|
||||||
|
}
|
||||||
|
|
||||||
if (s->precision <= 8) {
|
if (s->precision <= 8) {
|
||||||
for (compno = 0; compno < s->ncomponents; compno++) {
|
for (compno = 0; compno < s->ncomponents; compno++) {
|
||||||
Jpeg2000Component *comp = tile->comp + compno;
|
Jpeg2000Component *comp = tile->comp + compno;
|
||||||
float *datap = comp->data;
|
float *datap = comp->f_data;
|
||||||
int32_t *i_datap = (int32_t *) comp->data;
|
int32_t *i_datap = comp->i_data;
|
||||||
y = tile->comp[compno].coord[1][0] - s->image_offset_y;
|
y = tile->comp[compno].coord[1][0] - s->image_offset_y;
|
||||||
line = picture->data[0] + y * picture->linesize[0];
|
line = picture->data[0] + y * picture->linesize[0];
|
||||||
for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
|
for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
|
||||||
@ -1171,8 +1172,8 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
|||||||
} else {
|
} else {
|
||||||
for (compno = 0; compno < s->ncomponents; compno++) {
|
for (compno = 0; compno < s->ncomponents; compno++) {
|
||||||
Jpeg2000Component *comp = tile->comp + compno;
|
Jpeg2000Component *comp = tile->comp + compno;
|
||||||
float *datap = comp->data;
|
float *datap = comp->f_data;
|
||||||
int32_t *i_datap = (int32_t *) comp->data;
|
int32_t *i_datap = comp->i_data;
|
||||||
uint16_t *linel;
|
uint16_t *linel;
|
||||||
|
|
||||||
y = tile->comp[compno].coord[1][0] - s->image_offset_y;
|
y = tile->comp[compno].coord[1][0] - s->image_offset_y;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user