+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_INT32 *nmsedec,
+ OPJ_UINT32 cblksty)
+{
+ OPJ_UINT32 i, k;
+ const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
+ OPJ_UINT32 agg, runlen;
+
+ opj_mqc_t *mqc = t1->mqc; /* MQC component */
+
+ const OPJ_UINT32 agg_mask = (cblksty & J2K_CCP_CBLKSTY_VSC) ?
+ ~(T1_SIGMA_15 | T1_SIGMA_16 | T1_SIGMA_17 | T1_CHI_5) :
+ ~0U;
+
+ *nmsedec = 0;
+#ifdef DEBUG_ENC_CLN
+ printf("enc_clnpass: bpno=%d\n", bpno);
+#endif
+ for (k = 0; k < (t1->h & ~3U); k += 4) {
+#ifdef DEBUG_ENC_CLN
+ printf(" k=%d\n", k);
+#endif
+ for (i = 0; i < t1->w; ++i) {
+#ifdef DEBUG_ENC_CLN
+ printf(" i=%d\n", i);
+#endif
+ agg = !(T1_FLAGS(i, k) & agg_mask);
+#ifdef DEBUG_ENC_CLN
+ printf(" agg=%d\n", agg);
+#endif
+ if (agg) {
+ for (runlen = 0; runlen < 4; ++runlen) {
+ if (opj_int_abs(t1->data[((k + runlen)*t1->data_stride) + i]) & one) {
+ break;
+ }
+ }
+ opj_mqc_setcurctx(mqc, T1_CTXNO_AGG);
+ opj_mqc_encode(mqc, runlen != 4);
+ if (runlen == 4) {
+ continue;
+ }
+ opj_mqc_setcurctx(mqc, T1_CTXNO_UNI);
+ opj_mqc_encode(mqc, runlen >> 1);
+ opj_mqc_encode(mqc, runlen & 1);
+ } else {
+ runlen = 0;
+ }
+ opj_t1_enc_clnpass_step(
+ t1,
+ &T1_FLAGS(i, k),
+ &t1->data[((k + runlen) * t1->data_stride) + i],
+ bpno,
+ one,
+ nmsedec,
+ agg,
+ runlen,
+ 4U,
+ cblksty);
+ }
+ }
+ if (k < t1->h) {
+ agg = 0;
+ runlen = 0;
+#ifdef DEBUG_ENC_CLN
+ printf(" k=%d\n", k);
+#endif
+ for (i = 0; i < t1->w; ++i) {
+#ifdef DEBUG_ENC_CLN
+ printf(" i=%d\n", i);
+ printf(" agg=%d\n", agg);
+#endif
+ opj_t1_enc_clnpass_step(
+ t1,
+ &T1_FLAGS(i, k),
+ &t1->data[((k + runlen) * t1->data_stride) + i],
+ bpno,
+ one,
+ nmsedec,
+ agg,
+ runlen,
+ t1->h - k,
+ cblksty);
+ }
+ }
+}
+
+#define opj_t1_dec_clnpass_internal(t1, bpno, cblksty, w, h, flags_stride) \
+{ \
+ OPJ_INT32 one, half, oneplushalf, agg, vsc; \
+ OPJ_UINT32 runlen; \
+ OPJ_UINT32 i, j, k; \
+ OPJ_INT32 segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; \
+ \
+ opj_mqc_t *mqc = t1->mqc; /* MQC component */ \
+ \
+ one = 1 << bpno; \
+ half = one >> 1; \
+ oneplushalf = one | half; \
+ if (cblksty & J2K_CCP_CBLKSTY_VSC) { \
+ opj_flag_t *flagsp1 = &t1->flags[flags_stride + 1]; \
+ const OPJ_UINT32 agg_mask = ~(T1_SIGMA_15 | T1_SIGMA_16 | T1_SIGMA_17 | T1_CHI_5); \
+ for (k = 0; k < h; k += 4) { \
+ for (i = 0; i < w; ++i) { \
+ opj_flag_t *flagsp2 = flagsp1 + i; \
+ if (k + 3 < h) { \
+ agg = !(*flagsp2 & agg_mask); \
+ } else { \
+ agg = 0; \
+ } \
+ if (agg) { \
+ opj_mqc_setcurctx(mqc, T1_CTXNO_AGG); \
+ if (!opj_mqc_decode(mqc)) { \
+ continue; \
+ } \
+ opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); \
+ runlen = opj_mqc_decode(mqc); \
+ runlen = (runlen << 1) | opj_mqc_decode(mqc); \
+ } else { \
+ runlen = 0; \
+ } \
+ for (j = k + runlen; j < k + 4 && j < h; ++j) { \
+ vsc = (j == k + 3 || j == h - 1) ? 1 : 0; \
+ opj_t1_dec_clnpass_step_vsc( \
+ t1, \
+ flagsp2, \
+ &t1->data[(j * w) + i], \
+ oneplushalf, \
+ agg && (j == k + runlen), \
+ vsc, j - k); \
+ } \
+ *flagsp2 &= ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \
+ } \
+ flagsp1 += flags_stride; \
+ } \
+ } else { \
+ OPJ_INT32 *data1 = t1->data; \
+ opj_flag_t *flagsp1 = &t1->flags[flags_stride + 1]; \
+ for (k = 0; k < (h & ~3u); k += 4) { \
+ for (i = 0; i < w; ++i) { \
+ OPJ_INT32 *data2 = data1 + i; \
+ opj_flag_t *flagsp2 = flagsp1 + i; \
+ if (*flagsp2 == 0) { \
+ opj_mqc_setcurctx(mqc, T1_CTXNO_AGG); \
+ if (!opj_mqc_decode(mqc)) { \
+ continue; \
+ } \
+ opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); \
+ runlen = opj_mqc_decode(mqc); \
+ runlen = (runlen << 1) | opj_mqc_decode(mqc); \
+ data2 += runlen * w; \
+ for (j = runlen; j < 4; ++j) { \
+ if (j == runlen) { \
+ opj_t1_dec_clnpass_step_partial(t1, flagsp2, data2, oneplushalf, j); \
+ } else { \
+ opj_t1_dec_clnpass_step(t1, flagsp2, data2, oneplushalf, j); \
+ } \
+ data2 += w; \
+ } \
+ } else { \
+ if (!(*flagsp2 & ((T1_SIGMA_THIS | T1_PI_THIS) << (0 * 3U)))) {\
+ opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flagsp2, data2, oneplushalf, 0U, flags_stride); \
+ } \
+ data2 += w; \
+ if (!(*flagsp2 & ((T1_SIGMA_THIS | T1_PI_THIS) << (1 * 3U)))) {\
+ opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flagsp2, data2, oneplushalf, 1U, flags_stride); \
+ } \
+ data2 += w; \
+ if (!(*flagsp2 & ((T1_SIGMA_THIS | T1_PI_THIS) << (2 * 3U)))) {\
+ opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flagsp2, data2, oneplushalf, 2U, flags_stride); \
+ } \
+ data2 += w; \
+ if (!(*flagsp2 & ((T1_SIGMA_THIS | T1_PI_THIS) << (3 * 3U)))) {\
+ opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flagsp2, data2, oneplushalf, 3U, flags_stride); \
+ } \
+ data2 += w; \
+ } \
+ *flagsp2 &= ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \
+ } \
+ data1 += w << 2; \
+ flagsp1 += flags_stride; \
+ } \
+ for (i = 0; i < w; ++i) { \
+ OPJ_INT32 *data2 = data1 + i; \
+ opj_flag_t *flagsp2 = flagsp1 + i; \
+ for (j = k; j < h; ++j) { \
+ opj_t1_dec_clnpass_step(t1, flagsp2, data2, oneplushalf, j - k); \
+ data2 += w; \
+ } \
+ *flagsp2 &= ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \
+ } \
+ } \
+ \
+ if (segsym) { \
+ OPJ_UINT32 v = 0; \
+ opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); \
+ v = opj_mqc_decode(mqc); \
+ v = (v << 1) | opj_mqc_decode(mqc); \
+ v = (v << 1) | opj_mqc_decode(mqc); \
+ v = (v << 1) | opj_mqc_decode(mqc); \
+ /* \
+ if (v!=0xa) { \
+ opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); \
+ } \
+ */ \
+ } \
+}
+
+static void opj_t1_dec_clnpass_64x64(
+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_INT32 cblksty)