def _read_openjp2_common(self):
with ExitStack() as stack:<EOL><INDENT>filename = self.filename<EOL>stream = opj2.stream_create_default_file_stream(filename, True)<EOL>stack.callback(opj2.stream_destroy, stream)<EOL>codec = opj2.create_decompress(self._codec_format)<EOL>stack.callback(opj2.destroy_codec, codec)<EOL>opj2.set_error_handler(codec, _ERROR_CALLBACK)<EOL>opj2.set_warning_handler(codec, _WARNING_CALLBACK)<EOL>if self._verbose:<EOL><INDENT>opj2.set_info_handler(codec, _INFO_CALLBACK)<EOL><DEDENT>else:<EOL><INDENT>opj2.set_info_handler(codec, None)<EOL><DEDENT>opj2.setup_decoder(codec, self._dparams)<EOL>raw_image = opj2.read_header(stream, codec)<EOL>stack.callback(opj2.image_destroy, raw_image)<EOL>if self._dparams.nb_tile_to_decode:<EOL><INDENT>opj2.get_decoded_tile(codec, stream, raw_image,<EOL>self._dparams.tile_index)<EOL><DEDENT>else:<EOL><INDENT>opj2.set_decode_area(codec, raw_image,<EOL>self._dparams.DA_x0, self._dparams.DA_y0,<EOL>self._dparams.DA_x1, self._dparams.DA_y1)<EOL>opj2.decode(codec, stream, raw_image)<EOL><DEDENT>opj2.end_decompress(codec, stream)<EOL>image = self._extract_image(raw_image)<EOL><DEDENT>return image<EOL>
Read a JPEG 2000 image using libopenjp2.

Returns
-------
ndarray or lst
    Either the image as an ndarray or a list of ndarrays, each item
    corresponding to one band.