[FFmpeg-cvslog] j2k[c/h] j2kdec.c: Implement 2 code block styles
Rukhsana Ruby
git at videolan.org
Tue May 24 02:02:38 CEST 2011
ffmpeg | branch: master | Rukhsana Ruby <rukhsana.afroz at gmail.com> | Mon May 23 23:56:20 2011 +0200| [88e9397ef1e8c854e00b329cc866f88d046893d9] | committer: Michael Niedermayer
j2k[c/h] j2kdec.c: Implement 2 code block styles
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=88e9397ef1e8c854e00b329cc866f88d046893d9
---
libavcodec/j2k.c | 16 +++++++++-------
libavcodec/j2k.h | 2 +-
libavcodec/j2kdec.c | 30 +++++++++++++++++++++++-------
3 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c
index a58167b..33a7e31 100644
--- a/libavcodec/j2k.c
+++ b/libavcodec/j2k.c
@@ -105,18 +105,20 @@ static void tag_tree_zero(J2kTgtNode *t, int w, int h)
uint8_t ff_j2k_nbctxno_lut[256][4];
-static int getnbctxno(int flag, int bandno)
+static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
{
int h, v, d;
h = ((flag & J2K_T1_SIG_E) ? 1:0)+
((flag & J2K_T1_SIG_W) ? 1:0);
- v = ((flag & J2K_T1_SIG_N) ? 1:0)+
- ((flag & J2K_T1_SIG_S) ? 1:0);
+ v = ((flag & J2K_T1_SIG_N) ? 1:0);
+ if (!vert_causal_ctx_csty_symbol)
+ v = v + ((flag & J2K_T1_SIG_S) ? 1:0);
d = ((flag & J2K_T1_SIG_NE) ? 1:0)+
- ((flag & J2K_T1_SIG_NW) ? 1:0)+
- ((flag & J2K_T1_SIG_SE) ? 1:0)+
- ((flag & J2K_T1_SIG_SW) ? 1:0);
+ ((flag & J2K_T1_SIG_NW) ? 1:0);
+ if (!vert_causal_ctx_csty_symbol)
+ d = d + ((flag & J2K_T1_SIG_SE) ? 1:0)+
+ ((flag & J2K_T1_SIG_SW) ? 1:0);
if (bandno < 3){
if (bandno == 1)
FFSWAP(int, h, v);
@@ -171,7 +173,7 @@ 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);
+ ff_j2k_nbctxno_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]);
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
index 3a41b53..85d5cd0 100644
--- a/libavcodec/j2k.h
+++ b/libavcodec/j2k.h
@@ -208,7 +208,7 @@ void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative);
extern uint8_t ff_j2k_nbctxno_lut[256][4];
-static inline int ff_j2k_getnbctxno(int flag, int bandno)
+static inline int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
{
return ff_j2k_nbctxno_lut[flag&255][bandno];
}
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index 112c0ff..f2ece81 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -592,7 +592,8 @@ static int decode_packets(J2kDecoderContext *s, J2kTile *tile)
}
/* TIER-1 routines */
-static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno)
+static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno, int bpass_csty_symbol,
+ int vert_causal_ctx_csty_symbol)
{
int mask = 3 << (bpno - 1), y0, x, y;
@@ -601,10 +602,15 @@ static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, in
for (y = y0; y < height && y < y0+4; y++){
if ((t1->flags[y+1][x+1] & J2K_T1_SIG_NB)
&& !(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
- if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno))){
+ 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);
-
- t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask;
+ if (bpass_csty_symbol)
+ t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
+ else
+ 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);
}
@@ -658,7 +664,8 @@ static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, in
for (y = y0 + runlen; y < y0 + 4 && y < height; y++){
if (!dec){
if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)))
- dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno));
+ dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1],
+ bandno, 0));
}
if (dec){
int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
@@ -685,7 +692,7 @@ static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, in
static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Context *t1, J2kCblk *cblk,
int width, int height, int bandpos)
{
- int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
+ int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
for (y = 0; y < height+2; y++)
memset(t1->flags[y], 0, (width+2)*sizeof(int));
@@ -697,14 +704,23 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
cblk->data[cblk->length] = 0xff;
cblk->data[cblk->length+1] = 0xff;
+ int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
+ int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
+
while(passno--){
switch(pass_t){
- case 0: decode_sigpass(t1, width, height, bpno+1, bandpos);
+ case 0: decode_sigpass(t1, width, height, bpno+1, bandpos,
+ bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
break;
case 1: decode_refpass(t1, width, height, bpno+1);
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
break;
case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
codsty->cblk_style & J2K_CBLK_SEGSYM);
+ clnpass_cnt = clnpass_cnt + 1;
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
break;
}
More information about the ffmpeg-cvslog
mailing list