j2k: rename a few inline functions and data tables to match jpeg2000
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 26 May 2013 11:54:32 +0000 (13:54 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 26 May 2013 12:02:44 +0000 (14:02 +0200)
also inlcudes some other cosmetics

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/j2k.c
libavcodec/j2k.h
libavcodec/j2kdec.c
libavcodec/j2kenc.c

index 2e789a2..02b5892 100644 (file)
@@ -103,8 +103,6 @@ static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
     }
 }
 
-uint8_t ff_j2k_nbctxno_lut[256][4];
-
 static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
 {
     int h, v, d;
@@ -150,8 +148,6 @@ static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
     }
 }
 
-uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];
-
 static int getsgnctxno(int flag, uint8_t *xorbit)
 {
     int vcontrib, hcontrib;
@@ -172,10 +168,10 @@ void ff_j2k_init_tier1_luts(void)
     int i, j;
     for (i = 0; i < 256; i++)
         for (j = 0; j < 4; j++)
-            ff_j2k_nbctxno_lut[i][j] = getnbctxno(i, j, 0);
+            ff_jpeg2000_sigctxno_lut[i][j] = getnbctxno(i, j, 0);
     for (i = 0; i < 16; i++)
         for (j = 0; j < 16; j++)
-            ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]);
+            ff_jpeg2000_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_jpeg2000_xorbit_lut[i][j]);
 }
 
 void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative)
@@ -222,7 +218,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
         for (i = 0; i < 2; i++)
             for (j = 0; j < 2; j++)
                 reslevel->coord[i][j] =
-                    ff_j2k_ceildivpow2(comp->coord[i][j], declvl - 1);
+                    ff_jpeg2000_ceildivpow2(comp->coord[i][j], declvl - 1);
 
         if (reslevelno == 0)
             reslevel->nbands = 1;
@@ -232,13 +228,13 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
         if (reslevel->coord[0][1] == reslevel->coord[0][0])
             reslevel->num_precincts_x = 0;
         else
-            reslevel->num_precincts_x = ff_j2k_ceildivpow2(reslevel->coord[0][1], codsty->log2_prec_width)
+            reslevel->num_precincts_x = ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], codsty->log2_prec_width)
                                         - (reslevel->coord[0][0] >> codsty->log2_prec_width);
 
         if (reslevel->coord[1][1] == reslevel->coord[1][0])
             reslevel->num_precincts_y = 0;
         else
-            reslevel->num_precincts_y = ff_j2k_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height)
+            reslevel->num_precincts_y = ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height)
                                         - (reslevel->coord[1][0] >> codsty->log2_prec_height);
 
         reslevel->band = av_malloc(reslevel->nbands * sizeof(Jpeg2000Band));
@@ -265,25 +261,25 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
                 band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height-1);
                 for (i = 0; i < 2; i++)
                     for (j = 0; j < 2; j++)
-                        band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], declvl-1);
+                        band->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], declvl-1);
             } else{
                 band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width);
                 band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height);
 
                 for (i = 0; i < 2; i++)
                     for (j = 0; j < 2; j++)
-                        band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j] - (((bandno+1>>i)&1) << declvl-1), declvl);
+                        band->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j] - (((bandno+1>>i)&1) << declvl-1), declvl);
             }
-            band->cblknx = ff_j2k_ceildiv(band->coord[0][1], band->codeblock_width)  - band->coord[0][0] / band->codeblock_width;
-            band->cblkny = ff_j2k_ceildiv(band->coord[1][1], band->codeblock_height) - band->coord[1][0] / band->codeblock_height;
+            band->cblknx = ff_jpeg2000_ceildiv(band->coord[0][1], band->codeblock_width)  - band->coord[0][0] / band->codeblock_width;
+            band->cblkny = ff_jpeg2000_ceildiv(band->coord[1][1], band->codeblock_height) - band->coord[1][0] / band->codeblock_height;
 
             for (j = 0; j < 2; j++)
-                band->coord[0][j] = ff_j2k_ceildiv(band->coord[0][j], dx);
+                band->coord[0][j] = ff_jpeg2000_ceildiv(band->coord[0][j], dx);
             for (j = 0; j < 2; j++)
-                band->coord[1][j] = ff_j2k_ceildiv(band->coord[1][j], dy);
+                band->coord[1][j] = ff_jpeg2000_ceildiv(band->coord[1][j], dy);
 
-            band->cblknx = ff_j2k_ceildiv(band->cblknx, dx);
-            band->cblkny = ff_j2k_ceildiv(band->cblkny, dy);
+            band->cblknx = ff_jpeg2000_ceildiv(band->cblknx, dx);
+            band->cblkny = ff_jpeg2000_ceildiv(band->cblkny, dy);
 
             band->cblk = av_malloc(sizeof(Jpeg2000Cblk) * band->cblknx * band->cblkny);
             if (!band->cblk)
@@ -304,7 +300,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
             y0 = band->coord[1][0];
             y1 = ((band->coord[1][0] + (1<<codsty->log2_prec_height)) & ~((1<<codsty->log2_prec_height)-1)) - y0;
             yi0 = 0;
-            yi1 = ff_j2k_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height;
+            yi1 = ff_jpeg2000_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height;
             yi1 = FFMIN(yi1, band->cblkny);
             cblkperprech = 1<<(codsty->log2_prec_height - codsty->log2_cblk_height);
             for (precy = 0, precno = 0; precy < reslevel->num_precincts_y; precy++){
@@ -319,7 +315,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
             x0 = band->coord[0][0];
             x1 = ((band->coord[0][0] + (1<<codsty->log2_prec_width)) & ~((1<<codsty->log2_prec_width)-1)) - x0;
             xi0 = 0;
-            xi1 = ff_j2k_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width;
+            xi1 = ff_jpeg2000_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width;
             xi1 = FFMIN(xi1, band->cblknx);
 
             cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width);
index a5f6920..a2afdf4 100644 (file)
@@ -193,12 +193,12 @@ void ff_j2k_printu(uint8_t *tab, int l);
 #endif
 
 /* misc tools */
-static inline int ff_j2k_ceildivpow2(int a, int b)
+static inline int ff_jpeg2000_ceildivpow2(int a, int b)
 {
     return (a + (1 << b) - 1)>> b;
 }
 
-static inline int ff_j2k_ceildiv(int a, int b)
+static inline int ff_jpeg2000_ceildiv(int a, int b)
 {
     return (a + b - 1) / b;
 }
@@ -211,25 +211,29 @@ void ff_j2k_init_tier1_luts(void);
 
 void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative);
 
-extern uint8_t ff_j2k_nbctxno_lut[256][4];
+extern uint8_t ff_jpeg2000_sigctxno_lut[256][4];
 
 static inline int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
 {
-    return ff_j2k_nbctxno_lut[flag&255][bandno];
+    return ff_jpeg2000_sigctxno_lut[flag&255][bandno];
 }
 
-static inline int ff_j2k_getrefctxno(int flag)
+/* Get context label (number in range[14..16]) of a coefficient for magnitude
+ * refinement pass. */
+static inline int ff_jpeg2000_getrefctxno(int flag)
 {
-    static const uint8_t refctxno_lut[2][2] = {{14, 15}, {16, 16}};
+    static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } };
     return refctxno_lut[(flag>>14)&1][(flag & 255) != 0];
 }
 
-extern uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];
+extern uint8_t ff_jpeg2000_sgnctxno_lut[16][16];
+extern uint8_t ff_jpeg2000_xorbit_lut[16][16];
 
-static inline int ff_j2k_getsgnctxno(int flag, int *xorbit)
+/* Get context label (number in range[9..13]) for sign decoding. */
+static inline int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
 {
-    *xorbit = ff_j2k_xorbit_lut[flag&15][(flag>>8)&15];
-    return  ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15];
+    *xorbit = ff_jpeg2000_xorbit_lut[flag&15][(flag>>8)&15];
+    return  ff_jpeg2000_sgnctxno_lut[flag&15][(flag>>8)&15];
 }
 
 int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy);
index c9322a5..9a03d67 100644 (file)
@@ -242,8 +242,8 @@ static int get_siz(Jpeg2000DecoderContext *s)
         s->cdy[i] = bytestream2_get_byteu(&s->g);
     }
 
-    s->numXtiles = ff_j2k_ceildiv(s->width - s->tile_offset_x, s->tile_width);
-    s->numYtiles = ff_j2k_ceildiv(s->height - s->tile_offset_y, s->tile_height);
+    s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
+    s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height);
 
     if(s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile))
         return AVERROR(EINVAL);
@@ -631,7 +631,7 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn
                     int vert_causal_ctx_csty_loc_symbol = vert_causal_ctx_csty_symbol && (x == 3 && y == 3);
                     if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno,
                                       vert_causal_ctx_csty_loc_symbol))){
-                        int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+                        int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
                         if (bpass_csty_symbol)
                              t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
                         else
@@ -657,7 +657,7 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpn
         for (x = 0; x < width; x++)
             for (y = y0; y < height && y < y0+4; y++){
                 if ((t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG){
-                    int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
+                    int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y+1][x+1]);
                     int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf;
                     t1->data[y][x] += t1->data[y][x] < 0 ? -r : r;
                     t1->flags[y+1][x+1] |= JPEG2000_T1_REF;
@@ -694,7 +694,7 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
                                                                                              bandno, 0));
                 }
                 if (dec){
-                    int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+                    int xorbit, ctxno = ff_jpeg2000_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, t1->data[y][x] < 0);
                 }
@@ -810,7 +810,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
 
                 yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
                 y0 = yy0;
-                yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
+                yy1 = FFMIN(ff_jpeg2000_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
                             band->coord[1][1]) - band->coord[1][0] + yy0;
 
                 if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
@@ -822,7 +822,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
                     else
                         xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
                     x0 = xx0;
-                    xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
+                    xx1 = FFMIN(ff_jpeg2000_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
                                 band->coord[0][1]) - band->coord[0][0] + xx0;
 
                     for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){
index d505bb4..b22d4be 100644 (file)
@@ -340,8 +340,8 @@ static int init_tiles(Jpeg2000EncoderContext *s)
     Jpeg2000CodingStyle *codsty = &s->codsty;
     Jpeg2000QuantStyle  *qntsty = &s->qntsty;
 
-    s->numXtiles = ff_j2k_ceildiv(s->width, s->tile_width);
-    s->numYtiles = ff_j2k_ceildiv(s->height, s->tile_height);
+    s->numXtiles = ff_jpeg2000_ceildiv(s->width, s->tile_width);
+    s->numYtiles = ff_jpeg2000_ceildiv(s->height, s->tile_height);
 
     s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(Jpeg2000Tile));
     if (!s->tile)
@@ -364,7 +364,7 @@ static int init_tiles(Jpeg2000EncoderContext *s)
                 if (compno > 0)
                     for (i = 0; i < 2; i++)
                         for (j = 0; j < 2; j++)
-                            comp->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);
+                            comp->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);
 
                 if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], compno?1<<s->chroma_shift[0]:1, compno?1<<s->chroma_shift[1]:1))
                     return ret;
@@ -486,7 +486,7 @@ static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int ban
                     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);
+                        int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
                         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);
@@ -503,7 +503,7 @@ static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nm
         for (x = 0; x < width; x++)
             for (y = y0; y < height && y < y0+4; y++)
                 if ((t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG){
-                    int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
+                    int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y+1][x+1]);
                     *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] |= JPEG2000_T1_REF;
@@ -539,7 +539,7 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
                             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);
+                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
                             *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);
@@ -554,7 +554,7 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
                         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);
+                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
                             *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);
@@ -823,7 +823,7 @@ static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno
                 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
                 yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
                 y0 = yy0;
-                yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
+                yy1 = FFMIN(ff_jpeg2000_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
                             band->coord[1][1]) - band->coord[1][0] + yy0;
 
                 if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
@@ -837,7 +837,7 @@ static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno
                     else
                         xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
                     x0 = xx0;
-                    xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
+                    xx1 = FFMIN(ff_jpeg2000_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
                                 band->coord[0][1]) - band->coord[0][0] + xx0;
 
                     for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){