def _populate_dparams(self, rlevel, tile=None, area=None):
        """Populate decompression structure with appropriate input parameters.

        Parameters
        ----------
        rlevel : int
            Factor by which to rlevel output resolution.
        area : tuple
            Specifies decoding image area,
            (first_row, first_col, last_row, last_col)
        tile : int
            Number of tile to decode.
        """
        if opj2.OPENJP2 is not None:
            dparam = opj2.set_default_decoder_parameters()
        else:
            dparam = opj.DecompressionParametersType()
            opj.set_default_decoder_parameters(ctypes.byref(dparam))

        infile = self.filename.encode()
        nelts = opj2.PATH_LEN - len(infile)
        infile += b'0' * nelts
        dparam.infile = infile

        # Return raw codestream components instead of "interpolating" the
        # colormap?
        dparam.flags |= 1 if self.ignore_pclr_cmap_cdef else 0

        dparam.decod_format = self._codec_format
        dparam.cp_layer = self._layer

        # Must check the specified rlevel against the maximum.
        if rlevel != 0:
            # Must check the specified rlevel against the maximum.
            max_rlevel = self.codestream.segment[2].num_res
            if rlevel == -1:
                # -1 is shorthand for the largest rlevel
                rlevel = max_rlevel
            elif rlevel < -1 or rlevel > max_rlevel:
                msg = ("rlevel must be in the range [-1, {max_rlevel}] "
                       "for this image.")
                msg = msg.format(max_rlevel=max_rlevel)
                raise IOError(msg)

        dparam.cp_reduce = rlevel

        if area is not None:
            if area[0] < 0 or area[1] < 0 or area[2] <= 0 or area[3] <= 0:
                msg = ("The upper left corner coordinates must be nonnegative "
                       "and the lower right corner coordinates must be "
                       "positive.  The specified upper left and lower right "
                       "coordinates are ({y0}, {x0}) and ({y1}, {x1}).")
                msg = msg.format(x0=area[1], y0=area[0],
                                 x1=area[3], y1=area[2])
                raise IOError(msg)
            dparam.DA_y0 = area[0]
            dparam.DA_x0 = area[1]
            dparam.DA_y1 = area[2]
            dparam.DA_x1 = area[3]

        if tile is not None:
            dparam.tile_index = tile
            dparam.nb_tile_to_decode = 1

        self._dparams = dparam
def _populate_dparams ( self , rlevel , tile = None , area = None ) : if opj2 . OPENJP2 is not None : dparam = opj2 . set_default_decoder_parameters ( ) else : dparam = opj . DecompressionParametersType ( ) opj . set_default_decoder_parameters ( ctypes . byref ( dparam ) ) infile = self . filename . encode ( ) nelts = opj2 . PATH_LEN - len ( infile ) infile += b'0' * nelts dparam . infile = infile dparam . flags |= 1 if self . ignore_pclr_cmap_cdef else 0 dparam . decod_format = self . _codec_format dparam . cp_layer = self . _layer if rlevel != 0 : max_rlevel = self . codestream . segment [ 2 ] . num_res if rlevel == - 1 : rlevel = max_rlevel elif rlevel < - 1 or rlevel > max_rlevel : msg = ( "rlevel must be in the range [-1, {max_rlevel}] " "for this image." ) msg = msg . format ( max_rlevel = max_rlevel ) raise IOError ( msg ) dparam . cp_reduce = rlevel if area is not None : if area [ 0 ] < 0 or area [ 1 ] < 0 or area [ 2 ] <= 0 or area [ 3 ] <= 0 : msg = ( "The upper left corner coordinates must be nonnegative " "and the lower right corner coordinates must be " "positive.  The specified upper left and lower right " "coordinates are ({y0}, {x0}) and ({y1}, {x1})." ) msg = msg . format ( x0 = area [ 1 ] , y0 = area [ 0 ] , x1 = area [ 3 ] , y1 = area [ 2 ] ) raise IOError ( msg ) dparam . DA_y0 = area [ 0 ] dparam . DA_x0 = area [ 1 ] dparam . DA_y1 = area [ 2 ] dparam . DA_x1 = area [ 3 ] if tile is not None : dparam . tile_index = tile dparam . nb_tile_to_decode = 1 self . _dparams = dparam
Populate decompression structure with appropriate input parameters.

        Parameters
        ----------
        rlevel : int
            Factor by which to rlevel output resolution.
        area : tuple
            Specifies decoding image area,
            (first_row, first_col, last_row, last_col)
        tile : int
            Number of tile to decode.