+/* Returns whether the pass (bpno, passtype) is terminated */
+static int opj_t1_enc_is_term_pass(opj_tcd_cblk_enc_t* cblk,
+ OPJ_UINT32 cblksty,
+ OPJ_INT32 bpno,
+ OPJ_UINT32 passtype)
+{
+ /* Is it the last cleanup pass ? */
+ if (passtype == 2 && bpno == 0) {
+ return OPJ_TRUE;
+ }
+
+ if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
+ return OPJ_TRUE;
+ }
+
+ if ((cblksty & J2K_CCP_CBLKSTY_LAZY)) {
+ /* For bypass arithmetic bypass, terminate the 4th cleanup pass */
+ if ((bpno == ((OPJ_INT32)cblk->numbps - 4)) && (passtype == 2)) {
+ return OPJ_TRUE;
+ }
+ /* and beyond terminate all the magnitude refinement passes (in raw) */
+ /* and cleanup passes (in MQC) */
+ if ((bpno < ((OPJ_INT32)(cblk->numbps) - 4)) && (passtype > 0)) {
+ return OPJ_TRUE;
+ }
+ }
+
+ return OPJ_FALSE;
+}
+
+