From 0bfffed76e2e2b57d1b02b8e427ab2abd2ed21d2 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 6 Nov 2022 21:48:21 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4458 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/jpeg2000/libjasper/jpc/jpc_enc.c | 107 ++++++++++++----------- 1 file changed, 58 insertions(+), 49 deletions(-) (limited to 'converter/other/jpeg2000') diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c index f7a447e8..175f8ea8 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c @@ -1523,6 +1523,55 @@ encodeTileBody(jpc_enc_t * const encoderP, +static void +quantizeBand(jpc_enc_band_t * const bandP, + jpc_enc_tile_t * const tileP, + jpc_enc_cp_t * const cp, + int const prec, + int const tccp_numgbits, + int * const numgbitsP) { + + if (bandP->data) { + int actualnumbps; + uint_fast32_t y; + jpc_fix_t mxmag; + + for (y = 0, actualnumbps = 0, mxmag = 0; + y < jas_matrix_numrows(bandP->data); + ++y) { + uint_fast32_t x; + + for (x = 0; x < jas_matrix_numcols(bandP->data); ++x) + mxmag = MAX(mxmag, abs(jas_matrix_get(bandP->data, y, x))); + } + if (tileP->intmode) { + actualnumbps = jpc_firstone(mxmag) + 1; + } else { + actualnumbps = jpc_firstone(mxmag) + 1 - JPC_FIX_FRACBITS; + } + *numgbitsP = actualnumbps - (prec - 1 + bandP->analgain); + + if (!tileP->intmode) { + bandP->absstepsize = + jpc_fix_div( + jpc_inttofix(1 << (bandP->analgain + 1)), + bandP->synweight); + } else { + bandP->absstepsize = jpc_inttofix(1); + } + bandP->stepsize = jpc_abstorelstepsize( + bandP->absstepsize, prec + bandP->analgain); + bandP->numbps = tccp_numgbits + JPC_QCX_GETEXPN(bandP->stepsize) - 1; + + if ((!tileP->intmode) && bandP->data) { + quantize(bandP->data, bandP->absstepsize); + } + } else + *numgbitsP = 0; +} + + + static int encodemainbody(jpc_enc_t *enc) { @@ -1549,13 +1598,7 @@ encodemainbody(jpc_enc_t *enc) { jpc_enc_ccp_t *ccps; jpc_enc_tccp_t *tccp; int bandno; - uint_fast32_t x; - uint_fast32_t y; int mingbits; - int actualnumbps; - jpc_fix_t mxmag; - jpc_fix_t mag; - int numgbits; const char * error; cp = enc->cp; @@ -1635,51 +1678,17 @@ encodemainbody(jpc_enc_t *enc) { } endbands = &lvl->bands[lvl->numbands]; for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - ++absbandno; - continue; - } - actualnumbps = 0; - mxmag = 0; - for (y = 0; y < jas_matrix_numrows(band->data); ++y) { - for (x = 0; x < jas_matrix_numcols(band->data); ++x) { - mag = abs(jas_matrix_get(band->data, y, x)); - if (mag > mxmag) { - mxmag = mag; - } - } - } - if (tile->intmode) { - actualnumbps = - jpc_firstone(mxmag) + 1; - } else { - actualnumbps = - jpc_firstone(mxmag) + 1 - JPC_FIX_FRACBITS; - } - numgbits = actualnumbps - (cp->ccps[cmptno].prec - 1 + - band->analgain); - if (numgbits > mingbits) { - mingbits = numgbits; - } - if (!tile->intmode) { - band->absstepsize = - jpc_fix_div( - jpc_inttofix(1 << (band->analgain + 1)), - band->synweight); - } else { - band->absstepsize = jpc_inttofix(1); - } - band->stepsize = jpc_abstorelstepsize( - band->absstepsize, cp->ccps[cmptno].prec + - band->analgain); - band->numbps = cp->tccp.numgbits + - JPC_QCX_GETEXPN(band->stepsize) - 1; - - if ((!tile->intmode) && band->data) { - quantize(band->data, band->absstepsize); - } + int numgbits; + + quantizeBand(band, tile, cp, + cp->ccps[cmptno].prec, + cp->tccp.numgbits, + &numgbits); + + mingbits = MAX(mingbits, numgbits); comp->stepsizes[absbandno] = band->stepsize; + ++absbandno; } } -- cgit 1.4.1