- int i, j;
- int w, h;
- int passno;
- int bpno, passtype;
- int max;
- int nmsedec;
- double cumwmsedec = 0;
- char type = T1_TYPE_MQ;
-
- w = cblk->x1 - cblk->x0;
- h = cblk->y1 - cblk->y0;
-
- max = 0;
- for (j = 0; j < h; j++) {
- for (i = 0; i < w; i++) {
- max = int_max(max, int_abs(t1_data[j][i]));
- }
- }
-
- cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
-
- for (i = 0; i < sizeof(t1_flags) / sizeof(int); i++)
- ((int *) t1_flags)[i] = 0;
- bpno = cblk->numbps - 1;
- passtype = 2;
-
- mqc_resetstates();
- mqc_setstate(T1_CTXNO_UNI, 0, 46);
- mqc_setstate(T1_CTXNO_AGG, 0, 3);
- mqc_setstate(T1_CTXNO_ZC, 0, 4);
- mqc_init_enc(cblk->data);
-
- for (passno = 0; bpno >= 0; passno++) {
- tcd_pass_t *pass = &cblk->passes[passno];
- int correction = 3;
- type = ((bpno < (cblk->numbps - 4)) && (passtype < 2)
- && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
- T1_TYPE_MQ;
-
- switch (passtype) {
- case 0:
- t1_enc_sigpass(w, h, bpno, orient, &nmsedec, type, cblksty);
- break;
- case 1:
- t1_enc_refpass(w, h, bpno, &nmsedec, type, cblksty);
- break;
- case 2:
- t1_enc_clnpass(w, h, bpno, orient, &nmsedec, cblksty);
- /* code switch SEGMARK (i.e. SEGSYM) */
- if (cblksty & J2K_CCP_CBLKSTY_SEGSYM)
- mqc_segmark_enc();
- break;
- }
-
- cumwmsedec += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); //mod fixed_quality
- tile->distotile += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); //add antonin quality
-
-
- /* Code switch "RESTART" (i.e. TERMALL) */
- if ((cblksty & J2K_CCP_CBLKSTY_TERMALL)
- && !((passtype == 2) && (bpno - 1 < 0))) {
- if (type == T1_TYPE_RAW) {
- mqc_flush();
- correction = 1;
- /* correction = mqc_bypass_flush_enc(); */
- } else { /* correction = mqc_restart_enc(); */
- mqc_flush();
- correction = 1;
- }
- pass->term = 1;
- } else {
- if (((bpno < (cblk->numbps - 4) && (passtype > 0))
- || ((bpno == (cblk->numbps - 4)) && (passtype == 2)))
- && (cblksty & J2K_CCP_CBLKSTY_LAZY)) {
- if (type == T1_TYPE_RAW) {
- mqc_flush();
- correction = 1;
- /* correction = mqc_bypass_flush_enc(); */
- } else { /* correction = mqc_restart_enc(); */
- mqc_flush();
- correction = 1;