[FFmpeg-soc] [soc]: r444 - jpeg2000/j2kenc.c

k.nowosad subversion at mplayerhq.hu
Mon Jul 16 11:02:45 CEST 2007


Author: k.nowosad
Date: Mon Jul 16 11:02:45 2007
New Revision: 444

Log:
corrected codestream truncation routines


Modified:
   jpeg2000/j2kenc.c

Modified: jpeg2000/j2kenc.c
==============================================================================
--- jpeg2000/j2kenc.c	(original)
+++ jpeg2000/j2kenc.c	Mon Jul 16 11:02:45 2007
@@ -33,7 +33,8 @@
 
 #define NMSEDEC_BITS 7
 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
-#define WMSEDEC_SHIFT 13
+#define WMSEDEC_SHIFT 13 ///< must be >= 13
+#define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
 
 static int lut_nmsedec_ref [1<<NMSEDEC_BITS],
            lut_nmsedec_ref0[1<<NMSEDEC_BITS],
@@ -117,6 +118,8 @@ typedef struct {
     uint8_t *buf_end;
     int bit_index;
 
+    int64_t lambda;
+
     J2kTile *tile;
 } J2kEncoderContext;
 
@@ -1109,7 +1112,7 @@ static void encode_packets(J2kEncoderCon
     av_log(s->avctx, AV_LOG_DEBUG, "after tier2\n");
 }
 
-static int getcut(J2kCblk *cblk, int64_t threshold)
+static int getcut(J2kCblk *cblk, int64_t lambda)
 {
     int passno, res = 0;
     for (passno = 0; passno < cblk->npassess; passno++){
@@ -1121,13 +1124,13 @@ static int getcut(J2kCblk *cblk, int64_t
         dd = cblk->passess[passno].disto
            - (res ? cblk->passess[res-1].disto:0.0);
 
-        if (dd >= dr * threshold)
+        if (dd >= dr * lambda)
             res = passno+1;
     }
     return res;
 }
 
-static void truncpassess(J2kEncoderContext *s, J2kTile *tile, int64_t threshold)
+static void truncpassess(J2kEncoderContext *s, J2kTile *tile)
 {
     int compno, reslevelno, bandno, cblkno;
     for (compno = 0; compno < s->ncomponents; compno++){
@@ -1142,7 +1145,7 @@ static void truncpassess(J2kEncoderConte
                 for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
                     J2kCblk *cblk = band->cblk + cblkno;
 
-                    cblk->ninclpassess = getcut(cblk, threshold);
+                    cblk->ninclpassess = getcut(cblk, s->lambda);
                 }
             }
         }
@@ -1205,8 +1208,7 @@ static void encode_tile(J2kEncoderContex
     }
 
     av_log(s->avctx, AV_LOG_DEBUG, "rate control\n");
-    truncpassess(s, tile, tile->mindr +
-            (tile->maxdr - tile->mindr) * s->picture->quality / (FF_LAMBDA_MAX-1));
+    truncpassess(s, tile);
     encode_packets(s, tile, tileno);
     av_log(s->avctx, AV_LOG_DEBUG, "after rate control\n");
 }
@@ -1261,7 +1263,7 @@ static int encode_frame(AVCodecContext *
     s->Ysiz = avctx->height;
 
     s->nguardbits = 1;
-    s->picture->quality = FFMAX(--s->picture->quality, 0);
+    s->lambda = s->picture->quality * LAMBDA_SCALE;
 
     // TODO: other pixel formats
     for (i = 0; i < 3; i++)



More information about the FFmpeg-soc mailing list