diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5f6b08b..774443a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -183,7 +183,7 @@ OBJS-$(CONFIG_INDEO3_DECODER)          += indeo3.o
 OBJS-$(CONFIG_INDEO5_DECODER)          += indeo5.o ivi_common.o ivi_dsp.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
-OBJS-$(CONFIG_JPEG2000_DECODER)        += j2kdec.o mqcdec.o mqc.o j2k.o dwtg.o
+OBJS-$(CONFIG_JPEG2000_DECODER)        += j2kdec.o mqcdec.o mqc.o j2k.o dwt.o
 #OBJS-$(CONFIG_JPEG2000_ENCODER)        += j2kenc.o mqcenc.o mqc.o j2k.o dwt.o
 OBJS-$(CONFIG_JPEGLS_DECODER)          += jpeglsdec.o jpegls.o \
                                           mjpegdec.o mjpeg.o

diff --git a/libavcodec/dwtg.c b/libavcodec/dwtg.c
index f8d51e5..2ba9643 100644
--- a/libavcodec/dwtg.c
+++ b/libavcodec/dwtg.c
@@ -316,7 +316,7 @@ static void dwt_decode97(DWTContext *s, int *t)
     }
 }
 
-int ff_dwt_initg(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type)
+int ff_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type)
 {
     int i, j, lev = decomp_levels, maxlen,
         b[2][2];
diff --git a/libavcodec/dwtg.h b/libavcodec/dwtg.h
index 0f1de20..cbfa691 100644
--- a/libavcodec/dwtg.h
+++ b/libavcodec/dwtg.h
@@ -53,7 +53,7 @@ typedef struct {
  * @param decomp_levels number of decomposition levels
  * @param type 0 for DWT 9/7; 1 for DWT 5/3
  */
-int ff_dwt_initg(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type);
+int ff_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type);
 
 int ff_dwt_encode(DWTContext *s, int *t);
 int ff_dwt_decode(DWTContext *s, int *t);
diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c
index 6435a67..9e8e0ad 100644
--- a/libavcodec/j2k.c
+++ b/libavcodec/j2k.c
@@ -105,20 +105,18 @@ 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, int vert_causal_ctx_csty_symbol)
+static int getnbctxno(int flag, int bandno)
 {
     int h, v, d;
 
-   h = ((flag & J2K_T1_SIG_E) ? 1:0)+
+    h = ((flag & J2K_T1_SIG_E) ? 1:0)+
         ((flag & J2K_T1_SIG_W) ? 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);
+    v = ((flag & J2K_T1_SIG_N) ? 1:0)+
+        ((flag & J2K_T1_SIG_S) ? 1:0);
     d = ((flag & J2K_T1_SIG_NE) ? 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);
+        ((flag & J2K_T1_SIG_NW) ? 1:0)+
+        ((flag & J2K_T1_SIG_SE) ? 1:0)+
+        ((flag & J2K_T1_SIG_SW) ? 1:0);
     if (bandno < 3){
             if (bandno == 1)
                 FFSWAP(int, h, v);
@@ -168,7 +166,7 @@ static int getsgnctxno(int flag, uint8_t *xorbit)
     return ctxlbltab[hcontrib][vcontrib];
 }
 
-int ff_j2k_init_tier1_luts(void)
+int ff_j2k_init_tier1_luts()
 {
     int i, j;
     for (i = 0; i < 256; i++)
@@ -205,7 +203,7 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
 {
     int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
 
-    if (ret=ff_dwt_initg(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform))
+    if (ret=ff_dwt_init(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform))
         return ret;
     for (i = 0; i < 2; i++)
         csize *= comp->coord[i][1] - comp->coord[i][0];
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
index bb31545..2f4cb8b 100644
--- a/libavcodec/j2k.h
+++ b/libavcodec/j2k.h
@@ -202,7 +202,7 @@ static inline int ff_j2k_ceildiv(int a, int b)
 J2kTgtNode *ff_j2k_tag_tree_init(int w, int h);
 
 /* TIER-1 routines */
-int ff_j2k_init_tier1_luts(void);
+int ff_j2k_init_tier1_luts();
 
 void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative);
 
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index c0394c3..b482f51 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -303,8 +303,6 @@ static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
     J2kCodingStyle tmp;
     int compno;
 
-
-
     if (s->buf_end - s->buf < 5)
         return AVERROR(EINVAL);
 
@@ -334,7 +332,6 @@ static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
 {
     int compno;
 
-
     if (s->buf_end - s->buf < 2)
         return AVERROR(EINVAL);
 
@@ -595,8 +592,7 @@ 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, int bpass_csty_symbol, 
-                           int vert_causal_ctx_csty_symbol)
+static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno)
 {
     int mask = 3 << (bpno - 1), y0, x, y;
 
@@ -605,13 +601,10 @@ 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))){
-                    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))){
+                    if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno))){
                         int xorbit, ctxno = ff_j2k_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
-                             t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask;
+
+                        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);
                     }
@@ -679,7 +679,17 @@ static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, in
             }
         }
     }
-	
+    
+    if (seg_symbols) {
+        int val;
+        val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+        if (val != 0xa) {
+            av_log(s->avctx, AV_LOG_ERROR,"Segmentation symbol value incorrect: Ox%x\n", val);
+        }
+    }
-    
-
-    
 }
 
 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, clnpass_cnt = 0;
+    int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
 
     for (y = 0; y < height+2; y++)
         memset(t1->flags[y], 0, (width+2)*sizeof(int));
@@ -708,25 +697,14 @@ 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, bpass_csty_symbol && (clnpass_cnt >= 4), 
-                                   vert_causal_ctx_csty_symbol);
+            case 0: decode_sigpass(t1, width, height, bpno+1, bandpos);
                     break;
-            case 1: 
-		    decode_refpass(t1, width, height, bpno+1);
-                    if (bpass_csty_symbol && clnpass_cnt >= 4)
-                        ff_mqc_initdec(&t1->mqc, cblk->data);
+            case 1: decode_refpass(t1, width, height, bpno+1);
                     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);
+            case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
+                                   codsty->cblk_style & J2K_CBLK_SEGSYM);
                     break;
         }
 
@@ -921,7 +899,6 @@ static int decode_codestream(J2kDecoderContext *s)
         oldbuf = s->buf;
 
         if (marker == J2K_SOD){
-	    
             J2kTile *tile = s->tile + s->curtileno;
             if (ret = init_tile(s, s->curtileno))
                 return ret;
@@ -1000,8 +977,6 @@ static int decode_frame(AVCodecContext *avctx,
     AVFrame *picture = data;
     int tileno, ret;
 
-   av_log(s->avctx, AV_LOG_INFO, "start ruby\n");
-  
     s->avctx = avctx;
     av_log(s->avctx, AV_LOG_DEBUG, "start\n");
 
@@ -1041,8 +1016,6 @@ static int decode_frame(AVCodecContext *avctx,
     *data_size = sizeof(AVPicture);
     *picture = s->picture;
 
-	av_log(s->avctx, AV_LOG_INFO, "\nend ruby\n");
-
     return s->buf - s->buf_start;
 }
 
@@ -1067,7 +1040,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
 AVCodec ff_jpeg2000_decoder = {
     "j2k",
-    AVMEDIA_TYPE_VIDEO,
+    CODEC_TYPE_VIDEO,
     CODEC_ID_JPEG2000,
     sizeof(J2kDecoderContext),
     j2kdec_init,
@@ -1078,4 +1051,3 @@ AVCodec ff_jpeg2000_decoder = {
     .pix_fmts =
         (enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_RGB24, -1}
 };
-
