[FFmpeg-soc] [soc]: r334 - jpeg2000/j2kenc.c
Michael Niedermayer
michaelni at gmx.at
Sun Jul 8 13:20:53 CEST 2007
Hi
On Sat, Jul 07, 2007 at 01:54:31AM +0200, k.nowosad wrote:
> Author: k.nowosad
> Date: Sat Jul 7 01:54:31 2007
> New Revision: 334
>
> Log:
> adds lossy compression with possibility to limit the number of bytes contributed by a single tile by setting maxtilelen field in the encoder context [i'll connect it with api in the nearest future];
[...]
> +static int lut_nmsedec_ref[1<<NMSEDEC_BITS],
> + lut_nmsedec_ref0[1<<NMSEDEC_BITS],
> + lut_nmsedec_sig[1<<NMSEDEC_BITS],
> + lut_nmsedec_sig0[1<<NMSEDEC_BITS];
> +
these can be vertically aligned
[...]
> + tile->mindr = 1e10;
FLOAT_MAX
[...]
>
> +void init_luts()
non static with no prefix
[...]
> +static double getwmsedec(int nmsedec, int bandpos, int lev, int bpno)
> +{
> + static const double dwt_norms[4][10] = {
> + {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
> + {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
> + {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
> + {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}};
> +
> + double t = dwt_norms[bandpos][lev] * (1 << bpno);
> + return t * t * nmsedec / 8192.0;
> +}
as all numbers are integers or fixed point, plesse use int(64_t) instead of
double
[...]
> ff_aec_encode(&t1->aec, ctxno, (t1->data[k][j] < 0 ? 1:0) ^ xorbit);
the ? 1:0 is superflous
[...]
> + if (dr < tile->mindr)
> + tile->mindr = dr;
> + if (dr > tile->maxdr)
> + tile->maxdr = dr;
tile->mindr= FFMIN(tile->mindr, dr);
[..]
> /* tier-2 routines: */
> @@ -946,7 +1041,7 @@ static void encode_packet(J2kEncoderCont
>
> for (pos=0, yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
> for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++, pos++){
> - cblkincl[pos].val = band->cblk[yi * cblknw + xi].npassess == 0 ? 1:0;
> + cblkincl[pos].val = band->cblk[yi * cblknw + xi].ninclpassess == 0 ? 1:0;
superfous ?1:0
[...]
> +static int getcut(J2kCblk *cblk, double threshold)
> +{
> + int passno, res = 0;
> + for (passno = 0; passno < cblk->npassess; passno++){
> + int dr;
> + double dd;
> +
> + dr = cblk->passess[passno].rate
> + - (res ? cblk->passess[res-1].rate:0);
> + dd = cblk->passess[passno].disto
> + - (res ? cblk->passess[res-1].disto:0.0);
> +
> + if (dd >= dr * threshold)
> + res = passno+1;
> + }
> + return res;
> +}
double best= FLOAT_MAX;
for (passno = 0; passno < cblk->npassess; passno++){
double rd= cblk->passess[passno].disto + cblk->passess[passno].rate*threshold;
if(rd < best){
res= passno+1;
best= rd;
}
}
[...]
> +static void rate_control(J2kEncoderContext *s, J2kTile *tile, int tileno)
> +{
> + int i, ok;
> + uint8_t *oldbuf = s->buf;
> + double lo = tile->mindr, hi = tile->maxdr, resthres = lo;
> + for (i = 0; (i < 32); i++){
> + double thres = (lo+hi)/2;
> +
> + ok = 0;
> + s->buf = oldbuf;
> + truncpassess(s, tile, thres);
> + encode_packets(s, tile, tileno);
> +
> + if (s->buf - oldbuf > s->maxtilelen)
> + lo = thres;
> + else{
> + resthres = hi = thres;
> + ok=1;
> + }
> + }
> + if (!ok){
> + s->buf = oldbuf;
> + truncpassess(s, tile, resthres);
> + encode_packets(s, tile, tileno);
> + }
> +}
this seems to do strict CBR, i think using AVFrame.quality factor as
lambda/threshold would make more sense most of the time, that said iam
not against an optional CBR mode which uses max/min_rate
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-soc/attachments/20070708/d62d8eb4/attachment.pgp>
More information about the FFmpeg-soc
mailing list