<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode(codec, stream):
 """Wraps openjp2 library function opj_encode. Encode an image into a JPEG 2000 codestream. Parameters codec : CODEC_TYPE The jpeg2000 codec. stream : STREAM_TYPE_P The stream to which data is written. Raises ------ RuntimeError If the OpenJPEG library routine opj_encode fails. """

    OPENJP2.opj_encode.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
    OPENJP2.opj_encode.restype = check_error

    OPENJP2.opj_encode(codec, stream)