def _populate_cparams(self, img_array, mct=None, cratios=None, psnr=None,<EOL>cinema2k=None, cinema4k=None, irreversible=None,<EOL>cbsize=None, eph=None, grid_offset=None, modesw=None,<EOL>numres=None, prog=None, psizes=None, sop=None,<EOL>subsam=None, tilesize=None, colorspace=None):
other_args = (mct, cratios, psnr, irreversible, cbsize, eph,<EOL>grid_offset, modesw, numres, prog, psizes, sop, subsam)<EOL>if (((cinema2k is not None or cinema4k is not None) and<EOL>(not all([arg is None for arg in other_args])))):<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>raise IOError(msg)<EOL><DEDENT>if cratios is not None and psnr is not None:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise IOError(msg)<EOL><DEDENT>if version.openjpeg_version_tuple[<NUM_LIT:0>] == <NUM_LIT:1>:<EOL><INDENT>cparams = opj.set_default_encoder_parameters()<EOL><DEDENT>else:<EOL><INDENT>cparams = opj2.set_default_encoder_parameters()<EOL><DEDENT>outfile = self.filename.encode()<EOL>num_pad_bytes = opj2.PATH_LEN - len(outfile)<EOL>outfile += b'<STR_LIT:0>' * num_pad_bytes<EOL>cparams.outfile = outfile<EOL>if self.filename[-<NUM_LIT:4>:].endswith(('<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>cparams.codec_fmt = opj2.CODEC_JP2<EOL><DEDENT>else:<EOL><INDENT>cparams.codec_fmt = opj2.CODEC_J2K<EOL><DEDENT>cparams.tcp_rates[<NUM_LIT:0>] = <NUM_LIT:0><EOL>cparams.tcp_numlayers = <NUM_LIT:1><EOL>cparams.cp_disto_alloc = <NUM_LIT:1><EOL>cparams.irreversible = <NUM_LIT:1> if irreversible else <NUM_LIT:0><EOL>if cinema2k is not None:<EOL><INDENT>self._cparams = cparams<EOL>self._set_cinema_params('<STR_LIT>', cinema2k)<EOL>return<EOL><DEDENT>if cinema4k is not None:<EOL><INDENT>self._cparams = cparams<EOL>self._set_cinema_params('<STR_LIT>', cinema4k)<EOL>return<EOL><DEDENT>if cbsize is not None:<EOL><INDENT>cparams.cblockw_init = cbsize[<NUM_LIT:1>]<EOL>cparams.cblockh_init = cbsize[<NUM_LIT:0>]<EOL><DEDENT>if cratios is not None:<EOL><INDENT>cparams.tcp_numlayers = len(cratios)<EOL>for j, cratio in enumerate(cratios):<EOL><INDENT>cparams.tcp_rates[j] = cratio<EOL><DEDENT>cparams.cp_disto_alloc = <NUM_LIT:1><EOL><DEDENT>cparams.csty |= <NUM_LIT> if sop else <NUM_LIT:0><EOL>cparams.csty |= <NUM_LIT> if eph else <NUM_LIT:0><EOL>if grid_offset is not None:<EOL><INDENT>cparams.image_offset_x0 = grid_offset[<NUM_LIT:1>]<EOL>cparams.image_offset_y0 = grid_offset[<NUM_LIT:0>]<EOL><DEDENT>if modesw is not None:<EOL><INDENT>for shift in range(<NUM_LIT:6>):<EOL><INDENT>power_of_two = <NUM_LIT:1> << shift<EOL>if modesw & power_of_two:<EOL><INDENT>cparams.mode |= power_of_two<EOL><DEDENT><DEDENT><DEDENT>if numres is not None:<EOL><INDENT>cparams.numresolution = numres<EOL><DEDENT>if prog is not None:<EOL><INDENT>cparams.prog_order = core.PROGRESSION_ORDER[prog.upper()]<EOL><DEDENT>if psnr is not None:<EOL><INDENT>cparams.tcp_numlayers = len(psnr)<EOL>for j, snr_layer in enumerate(psnr):<EOL><INDENT>cparams.tcp_distoratio[j] = snr_layer<EOL><DEDENT>cparams.cp_fixed_quality = <NUM_LIT:1><EOL><DEDENT>if psizes is not None:<EOL><INDENT>for j, (prch, prcw) in enumerate(psizes):<EOL><INDENT>cparams.prcw_init[j] = prcw<EOL>cparams.prch_init[j] = prch<EOL><DEDENT>cparams.csty |= <NUM_LIT><EOL>cparams.res_spec = len(psizes)<EOL><DEDENT>if subsam is not None:<EOL><INDENT>cparams.subsampling_dy = subsam[<NUM_LIT:0>]<EOL>cparams.subsampling_dx = subsam[<NUM_LIT:1>]<EOL><DEDENT>if tilesize is not None:<EOL><INDENT>cparams.cp_tdx = tilesize[<NUM_LIT:1>]<EOL>cparams.cp_tdy = tilesize[<NUM_LIT:0>]<EOL>cparams.tile_size_on = opj2.TRUE<EOL><DEDENT>if mct is None:<EOL><INDENT>cparams.tcp_mct = <NUM_LIT:1> if self._colorspace == opj2.CLRSPC_SRGB else <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>if self._colorspace == opj2.CLRSPC_GRAY:<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>raise IOError(msg)<EOL><DEDENT>cparams.tcp_mct = <NUM_LIT:1> if mct else <NUM_LIT:0><EOL><DEDENT>self._validate_compression_params(img_array, cparams, colorspace)<EOL>self._cparams = cparams<EOL>
Directs processing of write method arguments.

        Parameters
        ----------
        img_array : ndarray
            Image data to be written to file.
        kwargs : dictionary
            Non-image keyword inputs provided to write method.