[FFmpeg-soc] [soc]: r1206 - in jpeg2000: j2k.c j2k.h j2kdec.c j2kenc.c

k.nowosad subversion at mplayerhq.hu
Mon Aug 27 17:21:27 CEST 2007


Author: k.nowosad
Date: Mon Aug 27 17:21:27 2007
New Revision: 1206

Log:
simplified tier-1 encoding 


Modified:
   jpeg2000/j2k.c
   jpeg2000/j2k.h
   jpeg2000/j2kdec.c
   jpeg2000/j2kenc.c

Modified: jpeg2000/j2k.c
==============================================================================
--- jpeg2000/j2k.c	(original)
+++ jpeg2000/j2k.c	Mon Aug 27 17:21:27 2007
@@ -176,11 +176,11 @@ void ff_j2k_init_tier1_luts()
             ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]);
 }
 
-void ff_j2k_set_significant(J2kT1Context *t1, int x, int y)
+void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative)
 {
     x++; y++;
     t1->flags[y][x] |= J2K_T1_SIG;
-    if (t1->data[y-1][x-1] < 0){
+    if (negative){
         t1->flags[y][x+1] |= J2K_T1_SIG_W | J2K_T1_SGN_W;
         t1->flags[y][x-1] |= J2K_T1_SIG_E | J2K_T1_SGN_E;
         t1->flags[y+1][x] |= J2K_T1_SIG_N | J2K_T1_SGN_N;

Modified: jpeg2000/j2k.h
==============================================================================
--- jpeg2000/j2k.h	(original)
+++ jpeg2000/j2k.h	Mon Aug 27 17:21:27 2007
@@ -85,6 +85,8 @@ enum J2kQuantsty{ ///< quantization styl
 #define J2K_T1_SIG    0x2000
 #define J2K_T1_REF    0x4000
 
+#define J2K_T1_SGN    0x8000
+
 typedef struct {
     int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
     int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
@@ -188,7 +190,7 @@ J2kTgtNode *ff_j2k_tag_tree_init(int w, 
 /* TIER-1 routines */
 void ff_j2k_init_tier1_luts();
 
-void ff_j2k_set_significant(J2kT1Context *t1, int x, int y);
+void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative);
 
 extern uint8_t ff_j2k_nbctxno_lut[256][4];
 
@@ -200,7 +202,7 @@ static inline int ff_j2k_getnbctxno(int 
 static inline int ff_j2k_getrefctxno(int flag)
 {
     static const uint8_t refctxno_lut[2][2] = {{14, 15}, {16, 16}};
-    return refctxno_lut[flag>>14][(flag & 255) != 0];
+    return refctxno_lut[(flag>>14)&1][(flag & 255) != 0];
 }
 
 extern uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];

Modified: jpeg2000/j2kdec.c
==============================================================================
--- jpeg2000/j2kdec.c	(original)
+++ jpeg2000/j2kdec.c	Mon Aug 27 17:21:27 2007
@@ -581,7 +581,7 @@ static void decode_sigpass(J2kT1Context 
 
                         t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask;
 
-                        ff_j2k_set_significant(t1, x, y);
+                        ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
                     }
                     t1->flags[y+1][x+1] |= J2K_T1_VIS;
                 }
@@ -638,7 +638,7 @@ static void decode_clnpass(J2kT1Context 
                 if (dec){
                     int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
                     t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask;
-                    ff_j2k_set_significant(t1, x, y);
+                    ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
                 }
                 dec = 0;
                 t1->flags[y+1][x+1] &= ~J2K_T1_VIS;

Modified: jpeg2000/j2kenc.c
==============================================================================
--- jpeg2000/j2kenc.c	(original)
+++ jpeg2000/j2kenc.c	Mon Aug 27 17:21:27 2007
@@ -442,14 +442,14 @@ static void encode_sigpass(J2kT1Context 
             for (y = y0; y < height && y < y0+4; y++){
                 if (!(t1->flags[y+1][x+1] & J2K_T1_SIG) && (t1->flags[y+1][x+1] & J2K_T1_SIG_NB)){
                     int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno),
-                        bit = abs(t1->data[y][x]) & mask ? 1 : 0;
+                        bit = t1->data[y][x] & mask ? 1 : 0;
                     ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, bit);
                     if (bit){
                         int xorbit;
                         int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
-                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->data[y][x] < 0) ^ xorbit);
-                        *nmsedec += getnmsedec_sig(abs(t1->data[y][x]), bpno + NMSEDEC_FRACBITS);
-                        ff_j2k_set_significant(t1, x, y);
+                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+                        *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+                        ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
                     }
                     t1->flags[y+1][x+1] |= J2K_T1_VIS;
                 }
@@ -464,8 +464,8 @@ static void encode_refpass(J2kT1Context 
             for (y = y0; y < height && y < y0+4; y++)
                 if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
                     int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
-                    *nmsedec += getnmsedec_ref(abs(t1->data[y][x]), bpno + NMSEDEC_FRACBITS);
-                    ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, abs(t1->data[y][x]) & mask ? 1:0);
+                    *nmsedec += getnmsedec_ref(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+                    ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
                     t1->flags[y+1][x+1] |= J2K_T1_REF;
                 }
 }
@@ -484,7 +484,7 @@ static void encode_clnpass(J2kT1Context 
                 // aggregation mode
                 int rlen;
                 for (rlen = 0; rlen < 4; rlen++)
-                    if (abs(t1->data[y0+rlen][x]) & mask)
+                    if (t1->data[y0+rlen][x] & mask)
                         break;
                 ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL, rlen != 4);
                 if (rlen == 4)
@@ -495,13 +495,13 @@ static void encode_clnpass(J2kT1Context 
                     if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
                         int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno);
                         if (y > y0 + rlen)
-                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, abs(t1->data[y][x]) & mask ? 1:0);
-                        if (abs(t1->data[y][x]) & mask){ // newly significant
+                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
+                        if (t1->data[y][x] & mask){ // newly significant
                             int xorbit;
                             int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
-                            *nmsedec += getnmsedec_sig(abs(t1->data[y][x]), bpno + NMSEDEC_FRACBITS);
-                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->data[y][x] < 0) ^ xorbit);
-                            ff_j2k_set_significant(t1, x, y);
+                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+                            ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
                         }
                     }
                     t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
@@ -511,13 +511,13 @@ static void encode_clnpass(J2kT1Context 
                 for (y = y0; y < y0 + 4 && y < height; y++){
                     if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
                         int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno);
-                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, abs(t1->data[y][x]) & mask ? 1:0);
-                        if (abs(t1->data[y][x]) & mask){ // newly significant
+                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
+                        if (t1->data[y][x] & mask){ // newly significant
                             int xorbit;
                             int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
-                            *nmsedec += getnmsedec_sig(abs(t1->data[y][x]), bpno + NMSEDEC_FRACBITS);
-                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->data[y][x] < 0) ^ xorbit);
-                            ff_j2k_set_significant(t1, x, y);
+                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+                            ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
                         }
                     }
                     t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
@@ -536,8 +536,13 @@ static void encode_cblk(J2kEncoderContex
         memset(t1->flags[y], 0, (width+2)*sizeof(int));
 
     for (y = 0; y < height; y++){
-        for (x = 0; x < width; x++)
-            max = FFMAX(max, abs(t1->data[y][x]));
+        for (x = 0; x < width; x++){
+            if (t1->data[y][x] < 0){
+                t1->flags[y+1][x+1] |= J2K_T1_SGN;
+                t1->data[y][x] = -t1->data[y][x];
+            }
+            max = FFMAX(max, t1->data[y][x]);
+        }
     }
 
     if (max == 0){



More information about the FFmpeg-soc mailing list