diff --git a/jpeg_ls/CharLS.py b/jpeg_ls/CharLS.py index b500abb..d5e303e 100644 --- a/jpeg_ls/CharLS.py +++ b/jpeg_ls/CharLS.py @@ -1,12 +1,16 @@ -from typing import Union +from io import BytesIO +import math +import os +from typing import Union, Any, BinaryIO, Dict, Tuple import numpy as np import _CharLS -def read(fname): +# Old interface +def read(fname: Union[str, os.PathLike]) -> np.ndarray: """Read image data from JPEG-LS file.""" with open(fname, "rb") as f: arr = np.frombuffer(f.read(), dtype=np.uint8) @@ -14,22 +18,419 @@ def read(fname): return _CharLS.decode(arr) -def write(fname, data_image): +def write(fname: Union[str, os.PathLike], data_image: np.ndarray) -> None: """Write compressed image data to JPEG-LS file.""" - data_buffer = _CharLS.encode(data_image) - + buffer = encode_array(data_image) with open(fname, "wb") as f: - f.write(data_buffer.tobytes()) + f.write(buffer) -def encode(data_image, lossy_error: int = 0, interleave_mode: Union[int, None] = None): +def encode( + data_image: np.ndarray, + lossy_error: int = 0, + interleave_mode: Union[int, None] = None +) -> np.ndarray: """Encode grey-scale image via JPEG-LS using CharLS implementation.""" if data_image.dtype == np.uint16 and np.max(data_image) <= 255: data_image = data_image.astype(np.uint8) - return _CharLS.encode(data_image, lossy_error, interleave_mode) + buffer = encode_array(data_image, lossy_error, interleave_mode) + return np.frombuffer(buffer, dtype="u1") -def decode(data_buffer): +def decode(data_buffer: np.ndarray) -> np.ndarray: """Decode grey-scale image via JPEG-LS using CharLS implementation.""" - return _CharLS.decode(data_buffer) + b = BytesIO(data_buffer.tobytes()) + return jlsread(b) + + +# New interface - encoding functions +def jlswrite( + arr: np.ndarray, + dst: Union[str, os.PathLike, BinaryIO], + *, + lossy_error: int = 0, + interleave_mode: Union[int, None] = None, +) -> None: + """JPEG-LS compress the image data in `arr` and write it to `dst`. + + Parameters + ---------- + arr : numpy.ndarray + An ndarray containing the image data. + dst : str, PathLike[str], BinaryIO + The destination where the compressed image data will be written, one of: + + * :class:`str` | :class:`os.PathLike`: the file path to write to, or + * file-like: a `file-like object + `_ in + 'wb' mode. + lossy_error : int, optional + The absolute value of the allowable error when encoding using + near-lossless, default ``0`` (lossless). For example, if using 8-bit + pixel data then the allowable error for a lossy image may be in the + range (1, 255). + interleave_mode : int, optional + Required for multi-sample (i.e. non-greyscale) image data, the + interleaving mode of `arr`. One of: + + * ``0``: `arr` is ordered R1R2...RnG1G2...GnB1B2...Bn, otherwise known + as colour-by-plane + * ``1``: `arr` is ordered R1...RwG1...GwB1...BwRw+1... + where w is the width of the image, otherwise known as colour-by-line + * ``2``: `arr` is ordered R1G1B1R2G2B2...RnGnBn, otherwise known as + colour-by-pixel + + Having multi-sample pixel data ordered to match ``interleave_mode=0`` + should result in the greatest compression ratio, however most + applications expect the pixel order to be ``interleave_mode=2``. + """ + buffer = encode_array(arr, lossy_error, interleave_mode) + if hasattr(dst, "read"): + dst.write(buffer) + else: + with open(dst, "wb") as f: + f.write(buffer) + + +def encode_array( + arr: np.ndarray, + lossy_error: int = 0, + interleave_mode: Union[int, None] = None, +) -> bytearray: + """Return the image data in `arr` as a JPEG-LS encoded bytearray. + + Parameters + ---------- + arr : numpy.ndarray + An ndarray containing the image data. + lossy_error : int, optional + The absolute value of the allowable error when encoding using + near-lossless, default ``0`` (lossless). For example, if using 8-bit + pixel data then the allowable error for a lossy image may be in the + range (1, 255). + interleave_mode : int, optional + Required for multi-sample (i.e. non-greyscale) image data, the + interleaving mode of `arr`. One of: + + * ``0``: `arr` is ordered R1R2...RnG1G2...GnB1B2...Bn, otherwise known + as colour-by-plane + * ``1``: `arr` is ordered R1...RwG1...GwB1...BwRw+1... + where w is the width of the image, otherwise known as colour-by-line + * ``2``: `arr` is ordered R1G1B1R2G2B2...RnGnBn, otherwise known as + colour-by-pixel + + Having multi-sample pixel data ordered to match ``interleave_mode=0`` + should result in the greatest compression ratio, however most + applications expect the pixel order to be ``interleave_mode=2``. + + Returns + ------- + bytearray + The encoded JPEG-LS codestream. + """ + if arr.dtype == np.uint8: + bytes_per_pixel = 1 + elif arr.dtype == np.uint16: + bytes_per_pixel = 2 + else: + raise ValueError( + f"Invalid ndarray dtype '{arr.dtype}', expecting np.uint8 or np.uint16." + ) + + nr_dims = len(arr.shape) + if nr_dims not in (2, 3): + raise ValueError("Invalid shape - image data must be 2D or 3D") + + if nr_dims == 2: + # Greyscale images should always be interleave mode 0 + interleave_mode = 0 + rows = arr.shape[0] + columns = arr.shape[1] + samples_per_pixel = 1 + else: + # Multi-component images may be interleave mode 0, 1 or 2 + if arr.shape[-1] in (3, 4): + # Colour-by-pixel (R, C, 3) or (R, C, 4) + # Mode 1 and 2 are identical apparently + interleave_mode = 2 if interleave_mode is None else interleave_mode + elif arr.shape[0] in (3, 4): + # Colour-by-plane (3, R, C) or (4, R, C) + interleave_mode = 0 if interleave_mode is None else interleave_mode + elif interleave_mode is None: + raise ValueError( + "Unable to automatically determine an appropriate 'interleave_mode' " + "value, please set it manually" + ) + + if interleave_mode == 0: + samples_per_pixel = arr.shape[0] + rows = arr.shape[1] + columns = arr.shape[2] + else: + rows = arr.shape[0] + columns = arr.shape[1] + samples_per_pixel = arr.shape[2] + + return _CharLS._encode( + arr.tobytes(), # needs data in the correct interleave mode (not a view) + lossy_error, + interleave_mode, + rows, + columns, + samples_per_pixel, + math.ceil(math.log(arr.max() + 1, 2)), + ) + + +def encode_buffer( + src: bytes, + rows: int, + columns: int, + samples_per_pixel: int, + bits_stored: int, + lossy_error: int = 0, + interleave_mode: Union[int, None] = None, + **kwargs: Any, +) -> bytearray: + """Return the image data in `src` as a JPEG-LS encoded bytearray. + + Parameters + ---------- + src : bytes + The image data to be JPEG-LS encoded. + rows : int + The number of rows of pixels in the image. + columns : int + The number of columns of pixels in the image. + samples_per_pixel : int + The number of samples per pixel in the image, otherwise knows as the + number of components or channels. A greyscale image has 1 sample per + pixel while an RGB image will have 3. + bits_stored : int + The bit-depth per pixel, must be in the range (1, 16). + lossy_error : int, optional + The absolute value of the allowable error when encoding using + near-lossless, default ``0`` (lossless). For example, if using 8-bit + pixel data then the allowable error for a lossy image may be in the + range (1, 255). + interleave_mode : int, optional + Required for multi-sample (i.e. non-greyscale) image data, the + interleaving mode of `src`. One of: + + * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn, + otherwise known as colour-by-plane + * ``1``: the pixels in `src` are ordered R1...RwG1...GwB1...BwRw+1... + where w is the width of the image, otherwise known as colour-by-line + * ``2``: the pixels in `src` are ordered R1G1B1R2G2B2...RnGnBn, + otherwise known as colour-by-pixel + + Having multi-sample pixel data ordered to match ``interleave_mode=0`` + should result in the greatest compression ratio, however most + applications expect the pixel order to be ``interleave_mode=2``. + + Returns + ------- + bytearray + The encoded JPEG-LS codestream. + """ + if samples_per_pixel < 1: + raise ValueError( + f"Invalid 'samples_per_pixel' value {samples_per_pixel}: must be " + "greater than 1" + ) + + if not 0 < bits_stored < 17: + raise ValueError( + f"Invalid 'bits_stored' value {bits_stored}: must be in the range (1, 16)" + ) + + if samples_per_pixel == 1: + interleave_mode = 0 + elif interleave_mode not in (0, 1, 2): + # Multi-sample must have the interleave mode specified + raise ValueError( + f"Invalid 'interleave_mode' value {interleave_mode}: must be 0, 1 or 2" + ) + + max_intensity = 2**bits_stored - 1 + if not 0 <= lossy_error <= max_intensity: + raise ValueError( + f"Invalid 'lossy_error' value {lossy_error}: must be in the " + f"range (0, {max_intensity}) for {bits_stored}-bit pixel data" + ) + + if not 1 <= rows <= 65535: + raise ValueError( + f"Invalid 'rows' value {rows}: must be in the range (1, 65535)" + ) + + if not 1 <= columns <= 65535: + raise ValueError( + f"Invalid 'columns' value {columns}: must be in the range (1, 65535)" + ) + + bytes_per_pixel = math.ceil(bits_stored / 8) + + length_src = len(src) + length_expected = rows * columns * samples_per_pixel * bytes_per_pixel + if length_expected != length_src: + raise ValueError( + f"The 'src' length of {length_src} bytes does not match the expected " + "length determined from 'rows', 'columns', 'samples_per_pixel' and " + "'bits_stored'" + ) + + return _CharLS._encode( + src, + lossy_error, + interleave_mode, + rows, + columns, + samples_per_pixel, + bits_stored, + ) + + +def encode_pixel_data(src: bytes, lossy_error: int = 0, **kwargs: Any) -> bytearray: + """Return JPEG-LS encoded pixel data. + + .. note:: + + This function is intended for use with pydicom. If you want to compress + raw encoded image data then use ``encode_buffer`` instead. + + Parameters + ---------- + src : bytes + The image data to be JPEG-LS encoded. + lossy_error : int, optional + The absolute value of the allowable error when encoding using + near-lossless, default ``0`` (lossless). For example, if using 8-bit + pixel data then the allowable error for a lossy image may be in the + range (1, 255). + **kwargs + Required and optional keyword parameters, at a minimum must include: + + * `rows` + * `columns` + * `samples_per_pixel` + * `bits_stored` + + If `samples_per_pixel` > 1 then also requires: + + * `planar_configuration` + + Returns + ------- + bytearray + The encoded JPEG-LS codestream. + """ + interleave_mode = 0 + samples_per_pixel = kwargs.get("samples_per_pixel") + if samples_per_pixel > 1: + planar_configuration = kwargs.get("planar_configuration") + interleave_mode = 0 if planar_configuration else 2 + + return encode_buffer( + src, + kwargs.get("rows"), + kwargs.get("columns"), + samples_per_pixel, + kwargs.get("bits_stored"), + lossy_error, + interleave_mode, + ) + + +# New interface - decoding functions +JLSSourceType = Union[str, os.PathLike, BinaryIO, bytes, bytearray] + + +def jlsread(src: JLSSourceType) -> np.ndarray: + """Return the JPEG-LS codestream in `src` as an ndarray. + + Parameters + ---------- + src : str, PathLike[str], BinaryIO, buffer-like + The source of compressed image data, one of: + + * :class:`str` | :class:`os.PathLike`: the file path to be read, or + * file-like: a `file-like object + `_ in + 'rb' mode. + * buffer-like: a :class:`bytes` or :class:`bytearray` containing the + compressed JPEG-LS codestream. + + Returns + ------- + numpy.ndarray + The decoded image. + """ + if isinstance(src, (bytes, bytearray)): + buffer = src + elif hasattr(src, "read"): + buffer = src.read() + else: + with open(src, "rb") as f: + buffer = f.read() + + im, info = decode_buffer(buffer) + + bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) + arr = np.frombuffer(im, dtype=f"u{bytes_per_pixel}") + rows = info["height"] + columns = info["width"] + samples_per_pixel = info["components"] + + if info["components"] == 3: + if info["interleave_mode"] == 0: + # ILV 0 is colour-by-plane, needs to be reshaped then transposed + # to colour-by-pixel instead + arr = arr.reshape((samples_per_pixel, rows, columns)) + return arr.transpose(1, 2, 0) + + # Colour-by-pixel, just needs to be reshaped + return arr.reshape((rows, columns, samples_per_pixel)) + + return arr.reshape((rows, columns)) + + +def decode_buffer(src: Union[bytes, bytearray]) -> Tuple[bytearray, Dict[str, int]]: + """Decode the JPEG-LS codestream `src` to a bytearray + + Parameters + ---------- + src : bytes | bytearray + The JPEG-LS codestream to be decoded. + + Returns + ------- + tuple[bytearray, dict[str, int]] + The decoded (image data, image metadata). + """ + return _CharLS._decode(src), _CharLS.read_header(src) + + +def decode_pixel_data(src: Union[bytes, bytearray], **kwargs: Any) -> bytearray: + """Decode the JPEG-LS codestream `src` to a bytearray + + .. note:: + + This function is intended to be used with image data from DICOM + datasets. If you are decoding a stand-alone JPEG-LS codestream then + it's recommended you use ``decode_buffer`` instead as this will return + the decoded image data as well as the image metadata necessary for + interpreting the image. + + Parameters + ---------- + src : bytes | bytearray + The JPEG-LS codestream to be decoded. + + Returns + ------- + bytearray + The decoded image data. + """ + return _CharLS._decode(src) diff --git a/jpeg_ls/_CharLS.cpp b/jpeg_ls/_CharLS.cpp index 2b898e1..1472bd1 100644 --- a/jpeg_ls/_CharLS.cpp +++ b/jpeg_ls/_CharLS.cpp @@ -7,18 +7,18 @@ "/home/dean/Coding/src/pyjpegls/lib/charls/include/charls/charls_jpegls_decoder.h", "/home/dean/Coding/src/pyjpegls/lib/charls/include/charls/charls_jpegls_encoder.h", "/home/dean/Coding/src/pyjpegls/lib/charls/include/charls/public_types.h", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include/numpy/arrayscalars.h", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include/numpy/ufuncobject.h", + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h", + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/arrayscalars.h", + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h", + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h", + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ufuncobject.h", "jpeg_ls/define_charls_dll.h" ], "include_dirs": [ "jpeg_ls", "/home/dean/Coding/src/pyjpegls/lib/charls/include", "/home/dean/Coding/src/pyjpegls/lib/charls/src", - "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include" + "/tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/core/include" ], "language": "c++", "name": "_CharLS", @@ -1582,7 +1582,7 @@ typedef struct { /* #### Code section: numeric_typedefs ### */ -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":730 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":731 * # in Cython to enable them only on the right systems. * * ctypedef npy_int8 int8_t # <<<<<<<<<<<<<< @@ -1591,7 +1591,7 @@ typedef struct { */ typedef npy_int8 __pyx_t_5numpy_int8_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":731 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":732 * * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t # <<<<<<<<<<<<<< @@ -1600,7 +1600,7 @@ typedef npy_int8 __pyx_t_5numpy_int8_t; */ typedef npy_int16 __pyx_t_5numpy_int16_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":732 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":733 * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t # <<<<<<<<<<<<<< @@ -1609,7 +1609,7 @@ typedef npy_int16 __pyx_t_5numpy_int16_t; */ typedef npy_int32 __pyx_t_5numpy_int32_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":733 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":734 * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t * ctypedef npy_int64 int64_t # <<<<<<<<<<<<<< @@ -1618,7 +1618,7 @@ typedef npy_int32 __pyx_t_5numpy_int32_t; */ typedef npy_int64 __pyx_t_5numpy_int64_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":737 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":738 * #ctypedef npy_int128 int128_t * * ctypedef npy_uint8 uint8_t # <<<<<<<<<<<<<< @@ -1627,7 +1627,7 @@ typedef npy_int64 __pyx_t_5numpy_int64_t; */ typedef npy_uint8 __pyx_t_5numpy_uint8_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":738 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":739 * * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t # <<<<<<<<<<<<<< @@ -1636,7 +1636,7 @@ typedef npy_uint8 __pyx_t_5numpy_uint8_t; */ typedef npy_uint16 __pyx_t_5numpy_uint16_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":739 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":740 * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t # <<<<<<<<<<<<<< @@ -1645,7 +1645,7 @@ typedef npy_uint16 __pyx_t_5numpy_uint16_t; */ typedef npy_uint32 __pyx_t_5numpy_uint32_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":740 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":741 * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t * ctypedef npy_uint64 uint64_t # <<<<<<<<<<<<<< @@ -1654,7 +1654,7 @@ typedef npy_uint32 __pyx_t_5numpy_uint32_t; */ typedef npy_uint64 __pyx_t_5numpy_uint64_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":744 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":745 * #ctypedef npy_uint128 uint128_t * * ctypedef npy_float32 float32_t # <<<<<<<<<<<<<< @@ -1663,7 +1663,7 @@ typedef npy_uint64 __pyx_t_5numpy_uint64_t; */ typedef npy_float32 __pyx_t_5numpy_float32_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":745 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":746 * * ctypedef npy_float32 float32_t * ctypedef npy_float64 float64_t # <<<<<<<<<<<<<< @@ -1672,43 +1672,61 @@ typedef npy_float32 __pyx_t_5numpy_float32_t; */ typedef npy_float64 __pyx_t_5numpy_float64_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":754 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":755 * # The int types are mapped a bit surprising -- * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t # <<<<<<<<<<<<<< + * ctypedef npy_longlong long_t * ctypedef npy_longlong longlong_t - * */ typedef npy_long __pyx_t_5numpy_int_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":755 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":756 * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t + * ctypedef npy_longlong long_t # <<<<<<<<<<<<<< + * ctypedef npy_longlong longlong_t + * + */ +typedef npy_longlong __pyx_t_5numpy_long_t; + +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":757 + * ctypedef npy_long int_t + * ctypedef npy_longlong long_t * ctypedef npy_longlong longlong_t # <<<<<<<<<<<<<< * * ctypedef npy_ulong uint_t */ typedef npy_longlong __pyx_t_5numpy_longlong_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":757 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":759 * ctypedef npy_longlong longlong_t * * ctypedef npy_ulong uint_t # <<<<<<<<<<<<<< + * ctypedef npy_ulonglong ulong_t * ctypedef npy_ulonglong ulonglong_t - * */ typedef npy_ulong __pyx_t_5numpy_uint_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":758 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":760 + * + * ctypedef npy_ulong uint_t + * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< + * ctypedef npy_ulonglong ulonglong_t * + */ +typedef npy_ulonglong __pyx_t_5numpy_ulong_t; + +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":761 * ctypedef npy_ulong uint_t + * ctypedef npy_ulonglong ulong_t * ctypedef npy_ulonglong ulonglong_t # <<<<<<<<<<<<<< * * ctypedef npy_intp intp_t */ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":760 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":763 * ctypedef npy_ulonglong ulonglong_t * * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< @@ -1717,7 +1735,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; */ typedef npy_intp __pyx_t_5numpy_intp_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":761 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":764 * * ctypedef npy_intp intp_t * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< @@ -1726,7 +1744,7 @@ typedef npy_intp __pyx_t_5numpy_intp_t; */ typedef npy_uintp __pyx_t_5numpy_uintp_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":763 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":766 * ctypedef npy_uintp uintp_t * * ctypedef npy_double float_t # <<<<<<<<<<<<<< @@ -1735,7 +1753,7 @@ typedef npy_uintp __pyx_t_5numpy_uintp_t; */ typedef npy_double __pyx_t_5numpy_float_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":764 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":767 * * ctypedef npy_double float_t * ctypedef npy_double double_t # <<<<<<<<<<<<<< @@ -1744,7 +1762,7 @@ typedef npy_double __pyx_t_5numpy_float_t; */ typedef npy_double __pyx_t_5numpy_double_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":765 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":768 * ctypedef npy_double float_t * ctypedef npy_double double_t * ctypedef npy_longdouble longdouble_t # <<<<<<<<<<<<<< @@ -1781,7 +1799,7 @@ static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(do /*--- Type declarations ---*/ -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":767 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":770 * ctypedef npy_longdouble longdouble_t * * ctypedef npy_cfloat cfloat_t # <<<<<<<<<<<<<< @@ -1790,7 +1808,7 @@ static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(do */ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":768 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":771 * * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< @@ -1799,7 +1817,7 @@ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; */ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":769 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":772 * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t * ctypedef npy_clongdouble clongdouble_t # <<<<<<<<<<<<<< @@ -1808,7 +1826,7 @@ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; */ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":771 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":774 * ctypedef npy_clongdouble clongdouble_t * * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< @@ -1816,21 +1834,6 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; * cdef inline object PyArray_MultiIterNew1(a): */ typedef npy_cdouble __pyx_t_5numpy_complex_t; -struct __pyx_defaults; -typedef struct __pyx_defaults __pyx_defaults; -struct __pyx_defaults1; -typedef struct __pyx_defaults1 __pyx_defaults1; -struct __pyx_defaults2; -typedef struct __pyx_defaults2 __pyx_defaults2; -struct __pyx_defaults { - PyObject *__pyx_arg_lossy_error; -}; -struct __pyx_defaults1 { - PyObject *__pyx_arg_lossy_error; -}; -struct __pyx_defaults2 { - PyObject *__pyx_arg_lossy_error; -}; /* #### Code section: utility_code_proto ### */ /* --- Runtime support code (head) --- */ @@ -2295,43 +2298,6 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); /* PyIntCompare.proto */ static CYTHON_INLINE int __Pyx_PyInt_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); -/* JoinPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - Py_UCS4 max_char); - -/* GetItemInt.proto */ -#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ - (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ - __Pyx_GetItemInt_Generic(o, to_py_func(i)))) -#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, - int is_list, int wraparound, int boundscheck); - -/* RaiseUnboundLocalError.proto */ -static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif - /* GCCDiagnostics.proto */ #if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #define __Pyx_HAS_GCC_DIAGNOSTIC @@ -2347,6 +2313,10 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t /* CIntToPyUnicode.proto */ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char); +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + /* PyIntBinop.proto */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_MultiplyObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); @@ -2778,24 +2748,20 @@ int __pyx_module_is_main__CharLS = 0; /* Implementation of "_CharLS" */ /* #### Code section: global_var ### */ static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_ImportError; /* #### Code section: string_decls ### */ static const char __pyx_k_u[] = "u"; static const char __pyx_k__3[] = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; static const char __pyx_k__5[] = "\000"; -static const char __pyx_k__9[] = "\n"; +static const char __pyx_k__7[] = "\n"; +static const char __pyx_k__8[] = "*"; +static const char __pyx_k__9[] = "."; static const char __pyx_k_np[] = "np"; -static const char __pyx_k_u1[] = "u1"; -static const char __pyx_k__10[] = "*"; -static const char __pyx_k__11[] = "."; -static const char __pyx_k__27[] = "?"; +static const char __pyx_k__21[] = "?"; static const char __pyx_k_arr[] = "arr"; static const char __pyx_k_dst[] = "dst"; static const char __pyx_k_err[] = "err"; static const char __pyx_k_int[] = "int"; -static const char __pyx_k_log[] = "log"; -static const char __pyx_k_max[] = "max"; static const char __pyx_k_msg[] = "msg"; static const char __pyx_k_src[] = "src"; static const char __pyx_k_Dict[] = "Dict"; @@ -2805,54 +2771,44 @@ static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_math[] = "math"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_rows[] = "rows"; -static const char __pyx_k_size[] = "size"; static const char __pyx_k_spec[] = "__spec__"; static const char __pyx_k_test[] = "__test__"; -static const char __pyx_k_with[] = " with "; +static const char __pyx_k_bytes[] = "bytes"; static const char __pyx_k_debug[] = "debug"; static const char __pyx_k_dtype[] = "dtype"; static const char __pyx_k_numpy[] = "numpy"; -static const char __pyx_k_shape[] = "shape"; static const char __pyx_k_strip[] = "strip"; -static const char __pyx_k_uint8[] = "uint8"; static const char __pyx_k_width[] = "width"; static const char __pyx_k_CharLS[] = "_CharLS"; static const char __pyx_k_LOGGER[] = "LOGGER"; static const char __pyx_k_Stride[] = "\n\tStride: "; static const char __pyx_k_decode[] = "_decode"; -static const char __pyx_k_encode[] = "encode"; +static const char __pyx_k_encode[] = "_encode"; static const char __pyx_k_height[] = "height"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_return[] = "return"; static const char __pyx_k_stride[] = "stride"; static const char __pyx_k_typing[] = "typing"; -static const char __pyx_k_uint16[] = "uint16"; static const char __pyx_k_columns[] = "columns"; static const char __pyx_k_logging[] = "logging"; -static const char __pyx_k_ndarray[] = "ndarray"; -static const char __pyx_k_nr_dims[] = "nr_dims"; static const char __pyx_k_reshape[] = "reshape"; static const char __pyx_k_tobytes[] = "tobytes"; static const char __pyx_k_decode_2[] = "decode"; -static const char __pyx_k_int_None[] = "int | None"; -static const char __pyx_k_bit_depth[] = "bit_depth"; static const char __pyx_k_bytearray[] = "bytearray"; static const char __pyx_k_getLogger[] = "getLogger"; static const char __pyx_k_px_Height[] = " px\n\tHeight: "; static const char __pyx_k_transpose[] = "transpose"; -static const char __pyx_k_ValueError[] = "ValueError"; static const char __pyx_k_components[] = "components"; static const char __pyx_k_dst_length[] = "dst_length"; static const char __pyx_k_frombuffer[] = "frombuffer"; -static const char __pyx_k_np_ndarray[] = "np.ndarray"; static const char __pyx_k_src_length[] = "src_length"; static const char __pyx_k_ImportError[] = "ImportError"; +static const char __pyx_k_bits_stored[] = "bits_stored"; static const char __pyx_k_data_buffer[] = "data_buffer"; static const char __pyx_k_lossy_error[] = "lossy_error"; static const char __pyx_k_read_header[] = "read_header"; static const char __pyx_k_Dict_str_int[] = "Dict[str, int]"; static const char __pyx_k_RuntimeError[] = "RuntimeError"; -static const char __pyx_k_encode_array[] = "_encode_array"; static const char __pyx_k_initializing[] = "_initializing"; static const char __pyx_k_is_coroutine[] = "_is_coroutine"; static const char __pyx_k_error_message[] = "error_message"; @@ -2860,19 +2816,13 @@ static const char __pyx_k_px_Components[] = " px\n\tComponents: "; static const char __pyx_k_Decoding_error[] = "Decoding error: "; static const char __pyx_k_Encoding_error[] = "Encoding error: "; static const char __pyx_k_Bits_per_sample[] = "\n\tBits per sample: "; -static const char __pyx_k_Encoding_src_is[] = "Encoding 'src' is "; static const char __pyx_k_bits_per_sample[] = "bits_per_sample"; static const char __pyx_k_bytes_bytearray[] = "bytes | bytearray"; -static const char __pyx_k_bytes_per_pixel[] = " bytes per pixel"; -static const char __pyx_k_bytes_shaped_as[] = " bytes, shaped as "; +static const char __pyx_k_bytes_per_pixel[] = "bytes_per_pixel"; static const char __pyx_k_interleave_mode[] = "interleave_mode"; static const char __pyx_k_jpeg_ls__CharLS[] = "jpeg_ls._CharLS"; -static const char __pyx_k_encode_to_buffer[] = "encode_to_buffer"; -static const char __pyx_k_np_ndarray_bytes[] = "np.ndarray | bytes"; -static const char __pyx_k_bytes_per_pixel_2[] = "bytes_per_pixel"; static const char __pyx_k_compressed_length[] = "compressed_length"; static const char __pyx_k_samples_per_pixel[] = "samples_per_pixel"; -static const char __pyx_k_Invalid_data_shape[] = "Invalid data shape"; static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_decode_from_buffer[] = "decode_from_buffer"; @@ -2881,24 +2831,15 @@ static const char __pyx_k_allowed_lossy_error[] = "allowed_lossy_error"; static const char __pyx_k_jpeg_ls__CharLS_pyx[] = "jpeg_ls/_CharLS.pyx"; static const char __pyx_k_bytes_Interleave_mode[] = " bytes\n\tInterleave mode: "; static const char __pyx_k_colour_transformation[] = "colour_transformation"; -static const char __pyx_k_Invalid_input_data_type[] = "Invalid input data type '"; static const char __pyx_k_Encoding_paramers_are_Width[] = "Encoding paramers are:\n\tWidth: "; -static const char __pyx_k_tuple_bytearray_dict_str_int[] = "tuple[bytearray, dict[str, int]]"; -static const char __pyx_k_expecting_np_uint8_or_np_uint16[] = "', expecting np.uint8 or np.uint16."; static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import"; -static const char __pyx_k_Unable_to_automatically_determin[] = "Unable to automatically determine an appropriate 'interleave_mode' value, please set it manually"; static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import"; /* #### Code section: decls ### */ static PyObject *__pyx_pf_7_CharLS_read_header(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src); /* proto */ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src); /* proto */ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src); /* proto */ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data_buffer); /* proto */ -static PyObject *__pyx_pf_7_CharLS_14__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode); /* proto */ -static PyObject *__pyx_pf_7_CharLS_16__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_7_CharLS_10_encode_array(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode); /* proto */ -static PyObject *__pyx_pf_7_CharLS_18__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_7_CharLS_12encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode); /* proto */ +static PyObject *__pyx_pf_7_CharLS_8_encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode, PyObject *__pyx_v_rows, PyObject *__pyx_v_columns, PyObject *__pyx_v_samples_per_pixel, PyObject *__pyx_v_bits_stored); /* proto */ /* #### Code section: late_includes ### */ /* #### Code section: module_state ### */ typedef struct { @@ -2970,38 +2911,31 @@ typedef struct { PyObject *__pyx_kp_s_Dict_str_int; PyObject *__pyx_kp_u_Encoding_error; PyObject *__pyx_kp_u_Encoding_paramers_are_Width; - PyObject *__pyx_kp_u_Encoding_src_is; PyObject *__pyx_n_s_ImportError; - PyObject *__pyx_kp_u_Invalid_data_shape; - PyObject *__pyx_kp_u_Invalid_input_data_type; PyObject *__pyx_n_s_LOGGER; PyObject *__pyx_n_s_RuntimeError; PyObject *__pyx_kp_u_Stride; - PyObject *__pyx_kp_u_Unable_to_automatically_determin; - PyObject *__pyx_n_s_ValueError; - PyObject *__pyx_n_s__10; - PyObject *__pyx_kp_u__11; - PyObject *__pyx_n_s__27; + PyObject *__pyx_n_s__21; PyObject *__pyx_kp_b__3; PyObject *__pyx_kp_b__5; PyObject *__pyx_kp_u__5; + PyObject *__pyx_kp_u__7; + PyObject *__pyx_n_s__8; PyObject *__pyx_kp_u__9; PyObject *__pyx_n_u_allowed_lossy_error; PyObject *__pyx_n_s_arr; PyObject *__pyx_n_s_asyncio_coroutines; - PyObject *__pyx_n_s_bit_depth; PyObject *__pyx_n_u_bits_per_sample; + PyObject *__pyx_n_s_bits_stored; PyObject *__pyx_n_s_bytearray; + PyObject *__pyx_n_s_bytes; PyObject *__pyx_kp_u_bytes_Interleave_mode; PyObject *__pyx_kp_s_bytes_bytearray; - PyObject *__pyx_kp_u_bytes_per_pixel; - PyObject *__pyx_n_s_bytes_per_pixel_2; - PyObject *__pyx_kp_u_bytes_shaped_as; + PyObject *__pyx_n_s_bytes_per_pixel; PyObject *__pyx_n_s_ceil; PyObject *__pyx_n_s_cline_in_traceback; PyObject *__pyx_n_u_colour_transformation; PyObject *__pyx_n_s_columns; - PyObject *__pyx_n_s_components; PyObject *__pyx_n_u_components; PyObject *__pyx_n_s_compressed_length; PyObject *__pyx_n_s_data_buffer; @@ -3013,11 +2947,8 @@ typedef struct { PyObject *__pyx_n_s_dst_length; PyObject *__pyx_n_s_dtype; PyObject *__pyx_n_s_encode; - PyObject *__pyx_n_s_encode_array; - PyObject *__pyx_n_s_encode_to_buffer; PyObject *__pyx_n_s_err; PyObject *__pyx_n_s_error_message; - PyObject *__pyx_kp_u_expecting_np_uint8_or_np_uint16; PyObject *__pyx_n_s_frombuffer; PyObject *__pyx_n_s_getLogger; PyObject *__pyx_n_u_height; @@ -3025,25 +2956,18 @@ typedef struct { PyObject *__pyx_n_s_info; PyObject *__pyx_n_s_initializing; PyObject *__pyx_n_s_int; - PyObject *__pyx_kp_s_int_None; PyObject *__pyx_n_s_interleave_mode; PyObject *__pyx_n_u_interleave_mode; PyObject *__pyx_n_s_is_coroutine; PyObject *__pyx_kp_u_jpeg_ls__CharLS; PyObject *__pyx_kp_s_jpeg_ls__CharLS_pyx; - PyObject *__pyx_n_s_log; PyObject *__pyx_n_s_logging; PyObject *__pyx_n_s_lossy_error; PyObject *__pyx_n_s_main; PyObject *__pyx_n_s_math; - PyObject *__pyx_n_s_max; PyObject *__pyx_n_s_msg; PyObject *__pyx_n_s_name; - PyObject *__pyx_n_s_ndarray; PyObject *__pyx_n_s_np; - PyObject *__pyx_kp_s_np_ndarray; - PyObject *__pyx_kp_s_np_ndarray_bytes; - PyObject *__pyx_n_s_nr_dims; PyObject *__pyx_n_s_numpy; PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to; PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; @@ -3054,8 +2978,6 @@ typedef struct { PyObject *__pyx_n_s_return; PyObject *__pyx_n_s_rows; PyObject *__pyx_n_s_samples_per_pixel; - PyObject *__pyx_n_s_shape; - PyObject *__pyx_n_s_size; PyObject *__pyx_n_s_spec; PyObject *__pyx_n_s_src; PyObject *__pyx_n_s_src_length; @@ -3064,41 +2986,29 @@ typedef struct { PyObject *__pyx_n_s_test; PyObject *__pyx_n_s_tobytes; PyObject *__pyx_n_s_transpose; - PyObject *__pyx_kp_s_tuple_bytearray_dict_str_int; PyObject *__pyx_n_s_typing; PyObject *__pyx_n_u_u; - PyObject *__pyx_n_u_u1; - PyObject *__pyx_n_s_uint16; - PyObject *__pyx_n_s_uint8; PyObject *__pyx_n_u_width; - PyObject *__pyx_kp_u_with; PyObject *__pyx_int_0; PyObject *__pyx_int_1; PyObject *__pyx_int_2; PyObject *__pyx_int_3; - PyObject *__pyx_int_4; PyObject *__pyx_int_8; PyObject *__pyx_tuple_; PyObject *__pyx_tuple__2; PyObject *__pyx_tuple__4; PyObject *__pyx_tuple__6; - PyObject *__pyx_tuple__7; - PyObject *__pyx_tuple__8; - PyObject *__pyx_tuple__12; + PyObject *__pyx_tuple__10; + PyObject *__pyx_tuple__11; PyObject *__pyx_tuple__13; PyObject *__pyx_tuple__15; PyObject *__pyx_tuple__17; PyObject *__pyx_tuple__19; - PyObject *__pyx_tuple__21; - PyObject *__pyx_tuple__23; - PyObject *__pyx_tuple__25; + PyObject *__pyx_codeobj__12; PyObject *__pyx_codeobj__14; PyObject *__pyx_codeobj__16; PyObject *__pyx_codeobj__18; PyObject *__pyx_codeobj__20; - PyObject *__pyx_codeobj__22; - PyObject *__pyx_codeobj__24; - PyObject *__pyx_codeobj__26; } __pyx_mstate; #if CYTHON_USE_MODULE_STATE @@ -3165,38 +3075,31 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_kp_s_Dict_str_int); Py_CLEAR(clear_module_state->__pyx_kp_u_Encoding_error); Py_CLEAR(clear_module_state->__pyx_kp_u_Encoding_paramers_are_Width); - Py_CLEAR(clear_module_state->__pyx_kp_u_Encoding_src_is); Py_CLEAR(clear_module_state->__pyx_n_s_ImportError); - Py_CLEAR(clear_module_state->__pyx_kp_u_Invalid_data_shape); - Py_CLEAR(clear_module_state->__pyx_kp_u_Invalid_input_data_type); Py_CLEAR(clear_module_state->__pyx_n_s_LOGGER); Py_CLEAR(clear_module_state->__pyx_n_s_RuntimeError); Py_CLEAR(clear_module_state->__pyx_kp_u_Stride); - Py_CLEAR(clear_module_state->__pyx_kp_u_Unable_to_automatically_determin); - Py_CLEAR(clear_module_state->__pyx_n_s_ValueError); - Py_CLEAR(clear_module_state->__pyx_n_s__10); - Py_CLEAR(clear_module_state->__pyx_kp_u__11); - Py_CLEAR(clear_module_state->__pyx_n_s__27); + Py_CLEAR(clear_module_state->__pyx_n_s__21); Py_CLEAR(clear_module_state->__pyx_kp_b__3); Py_CLEAR(clear_module_state->__pyx_kp_b__5); Py_CLEAR(clear_module_state->__pyx_kp_u__5); + Py_CLEAR(clear_module_state->__pyx_kp_u__7); + Py_CLEAR(clear_module_state->__pyx_n_s__8); Py_CLEAR(clear_module_state->__pyx_kp_u__9); Py_CLEAR(clear_module_state->__pyx_n_u_allowed_lossy_error); Py_CLEAR(clear_module_state->__pyx_n_s_arr); Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); - Py_CLEAR(clear_module_state->__pyx_n_s_bit_depth); Py_CLEAR(clear_module_state->__pyx_n_u_bits_per_sample); + Py_CLEAR(clear_module_state->__pyx_n_s_bits_stored); Py_CLEAR(clear_module_state->__pyx_n_s_bytearray); + Py_CLEAR(clear_module_state->__pyx_n_s_bytes); Py_CLEAR(clear_module_state->__pyx_kp_u_bytes_Interleave_mode); Py_CLEAR(clear_module_state->__pyx_kp_s_bytes_bytearray); - Py_CLEAR(clear_module_state->__pyx_kp_u_bytes_per_pixel); - Py_CLEAR(clear_module_state->__pyx_n_s_bytes_per_pixel_2); - Py_CLEAR(clear_module_state->__pyx_kp_u_bytes_shaped_as); + Py_CLEAR(clear_module_state->__pyx_n_s_bytes_per_pixel); Py_CLEAR(clear_module_state->__pyx_n_s_ceil); Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); Py_CLEAR(clear_module_state->__pyx_n_u_colour_transformation); Py_CLEAR(clear_module_state->__pyx_n_s_columns); - Py_CLEAR(clear_module_state->__pyx_n_s_components); Py_CLEAR(clear_module_state->__pyx_n_u_components); Py_CLEAR(clear_module_state->__pyx_n_s_compressed_length); Py_CLEAR(clear_module_state->__pyx_n_s_data_buffer); @@ -3208,11 +3111,8 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_dst_length); Py_CLEAR(clear_module_state->__pyx_n_s_dtype); Py_CLEAR(clear_module_state->__pyx_n_s_encode); - Py_CLEAR(clear_module_state->__pyx_n_s_encode_array); - Py_CLEAR(clear_module_state->__pyx_n_s_encode_to_buffer); Py_CLEAR(clear_module_state->__pyx_n_s_err); Py_CLEAR(clear_module_state->__pyx_n_s_error_message); - Py_CLEAR(clear_module_state->__pyx_kp_u_expecting_np_uint8_or_np_uint16); Py_CLEAR(clear_module_state->__pyx_n_s_frombuffer); Py_CLEAR(clear_module_state->__pyx_n_s_getLogger); Py_CLEAR(clear_module_state->__pyx_n_u_height); @@ -3220,25 +3120,18 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_info); Py_CLEAR(clear_module_state->__pyx_n_s_initializing); Py_CLEAR(clear_module_state->__pyx_n_s_int); - Py_CLEAR(clear_module_state->__pyx_kp_s_int_None); Py_CLEAR(clear_module_state->__pyx_n_s_interleave_mode); Py_CLEAR(clear_module_state->__pyx_n_u_interleave_mode); Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); Py_CLEAR(clear_module_state->__pyx_kp_u_jpeg_ls__CharLS); Py_CLEAR(clear_module_state->__pyx_kp_s_jpeg_ls__CharLS_pyx); - Py_CLEAR(clear_module_state->__pyx_n_s_log); Py_CLEAR(clear_module_state->__pyx_n_s_logging); Py_CLEAR(clear_module_state->__pyx_n_s_lossy_error); Py_CLEAR(clear_module_state->__pyx_n_s_main); Py_CLEAR(clear_module_state->__pyx_n_s_math); - Py_CLEAR(clear_module_state->__pyx_n_s_max); Py_CLEAR(clear_module_state->__pyx_n_s_msg); Py_CLEAR(clear_module_state->__pyx_n_s_name); - Py_CLEAR(clear_module_state->__pyx_n_s_ndarray); Py_CLEAR(clear_module_state->__pyx_n_s_np); - Py_CLEAR(clear_module_state->__pyx_kp_s_np_ndarray); - Py_CLEAR(clear_module_state->__pyx_kp_s_np_ndarray_bytes); - Py_CLEAR(clear_module_state->__pyx_n_s_nr_dims); Py_CLEAR(clear_module_state->__pyx_n_s_numpy); Py_CLEAR(clear_module_state->__pyx_kp_u_numpy_core_multiarray_failed_to); Py_CLEAR(clear_module_state->__pyx_kp_u_numpy_core_umath_failed_to_impor); @@ -3249,8 +3142,6 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_return); Py_CLEAR(clear_module_state->__pyx_n_s_rows); Py_CLEAR(clear_module_state->__pyx_n_s_samples_per_pixel); - Py_CLEAR(clear_module_state->__pyx_n_s_shape); - Py_CLEAR(clear_module_state->__pyx_n_s_size); Py_CLEAR(clear_module_state->__pyx_n_s_spec); Py_CLEAR(clear_module_state->__pyx_n_s_src); Py_CLEAR(clear_module_state->__pyx_n_s_src_length); @@ -3259,41 +3150,29 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_test); Py_CLEAR(clear_module_state->__pyx_n_s_tobytes); Py_CLEAR(clear_module_state->__pyx_n_s_transpose); - Py_CLEAR(clear_module_state->__pyx_kp_s_tuple_bytearray_dict_str_int); Py_CLEAR(clear_module_state->__pyx_n_s_typing); Py_CLEAR(clear_module_state->__pyx_n_u_u); - Py_CLEAR(clear_module_state->__pyx_n_u_u1); - Py_CLEAR(clear_module_state->__pyx_n_s_uint16); - Py_CLEAR(clear_module_state->__pyx_n_s_uint8); Py_CLEAR(clear_module_state->__pyx_n_u_width); - Py_CLEAR(clear_module_state->__pyx_kp_u_with); Py_CLEAR(clear_module_state->__pyx_int_0); Py_CLEAR(clear_module_state->__pyx_int_1); Py_CLEAR(clear_module_state->__pyx_int_2); Py_CLEAR(clear_module_state->__pyx_int_3); - Py_CLEAR(clear_module_state->__pyx_int_4); Py_CLEAR(clear_module_state->__pyx_int_8); Py_CLEAR(clear_module_state->__pyx_tuple_); Py_CLEAR(clear_module_state->__pyx_tuple__2); Py_CLEAR(clear_module_state->__pyx_tuple__4); Py_CLEAR(clear_module_state->__pyx_tuple__6); - Py_CLEAR(clear_module_state->__pyx_tuple__7); - Py_CLEAR(clear_module_state->__pyx_tuple__8); - Py_CLEAR(clear_module_state->__pyx_tuple__12); + Py_CLEAR(clear_module_state->__pyx_tuple__10); + Py_CLEAR(clear_module_state->__pyx_tuple__11); Py_CLEAR(clear_module_state->__pyx_tuple__13); Py_CLEAR(clear_module_state->__pyx_tuple__15); Py_CLEAR(clear_module_state->__pyx_tuple__17); Py_CLEAR(clear_module_state->__pyx_tuple__19); - Py_CLEAR(clear_module_state->__pyx_tuple__21); - Py_CLEAR(clear_module_state->__pyx_tuple__23); - Py_CLEAR(clear_module_state->__pyx_tuple__25); + Py_CLEAR(clear_module_state->__pyx_codeobj__12); Py_CLEAR(clear_module_state->__pyx_codeobj__14); Py_CLEAR(clear_module_state->__pyx_codeobj__16); Py_CLEAR(clear_module_state->__pyx_codeobj__18); Py_CLEAR(clear_module_state->__pyx_codeobj__20); - Py_CLEAR(clear_module_state->__pyx_codeobj__22); - Py_CLEAR(clear_module_state->__pyx_codeobj__24); - Py_CLEAR(clear_module_state->__pyx_codeobj__26); return 0; } #endif @@ -3338,38 +3217,31 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_kp_s_Dict_str_int); Py_VISIT(traverse_module_state->__pyx_kp_u_Encoding_error); Py_VISIT(traverse_module_state->__pyx_kp_u_Encoding_paramers_are_Width); - Py_VISIT(traverse_module_state->__pyx_kp_u_Encoding_src_is); Py_VISIT(traverse_module_state->__pyx_n_s_ImportError); - Py_VISIT(traverse_module_state->__pyx_kp_u_Invalid_data_shape); - Py_VISIT(traverse_module_state->__pyx_kp_u_Invalid_input_data_type); Py_VISIT(traverse_module_state->__pyx_n_s_LOGGER); Py_VISIT(traverse_module_state->__pyx_n_s_RuntimeError); Py_VISIT(traverse_module_state->__pyx_kp_u_Stride); - Py_VISIT(traverse_module_state->__pyx_kp_u_Unable_to_automatically_determin); - Py_VISIT(traverse_module_state->__pyx_n_s_ValueError); - Py_VISIT(traverse_module_state->__pyx_n_s__10); - Py_VISIT(traverse_module_state->__pyx_kp_u__11); - Py_VISIT(traverse_module_state->__pyx_n_s__27); + Py_VISIT(traverse_module_state->__pyx_n_s__21); Py_VISIT(traverse_module_state->__pyx_kp_b__3); Py_VISIT(traverse_module_state->__pyx_kp_b__5); Py_VISIT(traverse_module_state->__pyx_kp_u__5); + Py_VISIT(traverse_module_state->__pyx_kp_u__7); + Py_VISIT(traverse_module_state->__pyx_n_s__8); Py_VISIT(traverse_module_state->__pyx_kp_u__9); Py_VISIT(traverse_module_state->__pyx_n_u_allowed_lossy_error); Py_VISIT(traverse_module_state->__pyx_n_s_arr); Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); - Py_VISIT(traverse_module_state->__pyx_n_s_bit_depth); Py_VISIT(traverse_module_state->__pyx_n_u_bits_per_sample); + Py_VISIT(traverse_module_state->__pyx_n_s_bits_stored); Py_VISIT(traverse_module_state->__pyx_n_s_bytearray); + Py_VISIT(traverse_module_state->__pyx_n_s_bytes); Py_VISIT(traverse_module_state->__pyx_kp_u_bytes_Interleave_mode); Py_VISIT(traverse_module_state->__pyx_kp_s_bytes_bytearray); - Py_VISIT(traverse_module_state->__pyx_kp_u_bytes_per_pixel); - Py_VISIT(traverse_module_state->__pyx_n_s_bytes_per_pixel_2); - Py_VISIT(traverse_module_state->__pyx_kp_u_bytes_shaped_as); + Py_VISIT(traverse_module_state->__pyx_n_s_bytes_per_pixel); Py_VISIT(traverse_module_state->__pyx_n_s_ceil); Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); Py_VISIT(traverse_module_state->__pyx_n_u_colour_transformation); Py_VISIT(traverse_module_state->__pyx_n_s_columns); - Py_VISIT(traverse_module_state->__pyx_n_s_components); Py_VISIT(traverse_module_state->__pyx_n_u_components); Py_VISIT(traverse_module_state->__pyx_n_s_compressed_length); Py_VISIT(traverse_module_state->__pyx_n_s_data_buffer); @@ -3381,11 +3253,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_dst_length); Py_VISIT(traverse_module_state->__pyx_n_s_dtype); Py_VISIT(traverse_module_state->__pyx_n_s_encode); - Py_VISIT(traverse_module_state->__pyx_n_s_encode_array); - Py_VISIT(traverse_module_state->__pyx_n_s_encode_to_buffer); Py_VISIT(traverse_module_state->__pyx_n_s_err); Py_VISIT(traverse_module_state->__pyx_n_s_error_message); - Py_VISIT(traverse_module_state->__pyx_kp_u_expecting_np_uint8_or_np_uint16); Py_VISIT(traverse_module_state->__pyx_n_s_frombuffer); Py_VISIT(traverse_module_state->__pyx_n_s_getLogger); Py_VISIT(traverse_module_state->__pyx_n_u_height); @@ -3393,25 +3262,18 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_info); Py_VISIT(traverse_module_state->__pyx_n_s_initializing); Py_VISIT(traverse_module_state->__pyx_n_s_int); - Py_VISIT(traverse_module_state->__pyx_kp_s_int_None); Py_VISIT(traverse_module_state->__pyx_n_s_interleave_mode); Py_VISIT(traverse_module_state->__pyx_n_u_interleave_mode); Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); Py_VISIT(traverse_module_state->__pyx_kp_u_jpeg_ls__CharLS); Py_VISIT(traverse_module_state->__pyx_kp_s_jpeg_ls__CharLS_pyx); - Py_VISIT(traverse_module_state->__pyx_n_s_log); Py_VISIT(traverse_module_state->__pyx_n_s_logging); Py_VISIT(traverse_module_state->__pyx_n_s_lossy_error); Py_VISIT(traverse_module_state->__pyx_n_s_main); Py_VISIT(traverse_module_state->__pyx_n_s_math); - Py_VISIT(traverse_module_state->__pyx_n_s_max); Py_VISIT(traverse_module_state->__pyx_n_s_msg); Py_VISIT(traverse_module_state->__pyx_n_s_name); - Py_VISIT(traverse_module_state->__pyx_n_s_ndarray); Py_VISIT(traverse_module_state->__pyx_n_s_np); - Py_VISIT(traverse_module_state->__pyx_kp_s_np_ndarray); - Py_VISIT(traverse_module_state->__pyx_kp_s_np_ndarray_bytes); - Py_VISIT(traverse_module_state->__pyx_n_s_nr_dims); Py_VISIT(traverse_module_state->__pyx_n_s_numpy); Py_VISIT(traverse_module_state->__pyx_kp_u_numpy_core_multiarray_failed_to); Py_VISIT(traverse_module_state->__pyx_kp_u_numpy_core_umath_failed_to_impor); @@ -3422,8 +3284,6 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_return); Py_VISIT(traverse_module_state->__pyx_n_s_rows); Py_VISIT(traverse_module_state->__pyx_n_s_samples_per_pixel); - Py_VISIT(traverse_module_state->__pyx_n_s_shape); - Py_VISIT(traverse_module_state->__pyx_n_s_size); Py_VISIT(traverse_module_state->__pyx_n_s_spec); Py_VISIT(traverse_module_state->__pyx_n_s_src); Py_VISIT(traverse_module_state->__pyx_n_s_src_length); @@ -3432,41 +3292,29 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_test); Py_VISIT(traverse_module_state->__pyx_n_s_tobytes); Py_VISIT(traverse_module_state->__pyx_n_s_transpose); - Py_VISIT(traverse_module_state->__pyx_kp_s_tuple_bytearray_dict_str_int); Py_VISIT(traverse_module_state->__pyx_n_s_typing); Py_VISIT(traverse_module_state->__pyx_n_u_u); - Py_VISIT(traverse_module_state->__pyx_n_u_u1); - Py_VISIT(traverse_module_state->__pyx_n_s_uint16); - Py_VISIT(traverse_module_state->__pyx_n_s_uint8); Py_VISIT(traverse_module_state->__pyx_n_u_width); - Py_VISIT(traverse_module_state->__pyx_kp_u_with); Py_VISIT(traverse_module_state->__pyx_int_0); Py_VISIT(traverse_module_state->__pyx_int_1); Py_VISIT(traverse_module_state->__pyx_int_2); Py_VISIT(traverse_module_state->__pyx_int_3); - Py_VISIT(traverse_module_state->__pyx_int_4); Py_VISIT(traverse_module_state->__pyx_int_8); Py_VISIT(traverse_module_state->__pyx_tuple_); Py_VISIT(traverse_module_state->__pyx_tuple__2); Py_VISIT(traverse_module_state->__pyx_tuple__4); Py_VISIT(traverse_module_state->__pyx_tuple__6); - Py_VISIT(traverse_module_state->__pyx_tuple__7); - Py_VISIT(traverse_module_state->__pyx_tuple__8); - Py_VISIT(traverse_module_state->__pyx_tuple__12); + Py_VISIT(traverse_module_state->__pyx_tuple__10); + Py_VISIT(traverse_module_state->__pyx_tuple__11); Py_VISIT(traverse_module_state->__pyx_tuple__13); Py_VISIT(traverse_module_state->__pyx_tuple__15); Py_VISIT(traverse_module_state->__pyx_tuple__17); Py_VISIT(traverse_module_state->__pyx_tuple__19); - Py_VISIT(traverse_module_state->__pyx_tuple__21); - Py_VISIT(traverse_module_state->__pyx_tuple__23); - Py_VISIT(traverse_module_state->__pyx_tuple__25); + Py_VISIT(traverse_module_state->__pyx_codeobj__12); Py_VISIT(traverse_module_state->__pyx_codeobj__14); Py_VISIT(traverse_module_state->__pyx_codeobj__16); Py_VISIT(traverse_module_state->__pyx_codeobj__18); Py_VISIT(traverse_module_state->__pyx_codeobj__20); - Py_VISIT(traverse_module_state->__pyx_codeobj__22); - Py_VISIT(traverse_module_state->__pyx_codeobj__24); - Py_VISIT(traverse_module_state->__pyx_codeobj__26); return 0; } #endif @@ -3539,38 +3387,31 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_kp_s_Dict_str_int __pyx_mstate_global->__pyx_kp_s_Dict_str_int #define __pyx_kp_u_Encoding_error __pyx_mstate_global->__pyx_kp_u_Encoding_error #define __pyx_kp_u_Encoding_paramers_are_Width __pyx_mstate_global->__pyx_kp_u_Encoding_paramers_are_Width -#define __pyx_kp_u_Encoding_src_is __pyx_mstate_global->__pyx_kp_u_Encoding_src_is #define __pyx_n_s_ImportError __pyx_mstate_global->__pyx_n_s_ImportError -#define __pyx_kp_u_Invalid_data_shape __pyx_mstate_global->__pyx_kp_u_Invalid_data_shape -#define __pyx_kp_u_Invalid_input_data_type __pyx_mstate_global->__pyx_kp_u_Invalid_input_data_type #define __pyx_n_s_LOGGER __pyx_mstate_global->__pyx_n_s_LOGGER #define __pyx_n_s_RuntimeError __pyx_mstate_global->__pyx_n_s_RuntimeError #define __pyx_kp_u_Stride __pyx_mstate_global->__pyx_kp_u_Stride -#define __pyx_kp_u_Unable_to_automatically_determin __pyx_mstate_global->__pyx_kp_u_Unable_to_automatically_determin -#define __pyx_n_s_ValueError __pyx_mstate_global->__pyx_n_s_ValueError -#define __pyx_n_s__10 __pyx_mstate_global->__pyx_n_s__10 -#define __pyx_kp_u__11 __pyx_mstate_global->__pyx_kp_u__11 -#define __pyx_n_s__27 __pyx_mstate_global->__pyx_n_s__27 +#define __pyx_n_s__21 __pyx_mstate_global->__pyx_n_s__21 #define __pyx_kp_b__3 __pyx_mstate_global->__pyx_kp_b__3 #define __pyx_kp_b__5 __pyx_mstate_global->__pyx_kp_b__5 #define __pyx_kp_u__5 __pyx_mstate_global->__pyx_kp_u__5 +#define __pyx_kp_u__7 __pyx_mstate_global->__pyx_kp_u__7 +#define __pyx_n_s__8 __pyx_mstate_global->__pyx_n_s__8 #define __pyx_kp_u__9 __pyx_mstate_global->__pyx_kp_u__9 #define __pyx_n_u_allowed_lossy_error __pyx_mstate_global->__pyx_n_u_allowed_lossy_error #define __pyx_n_s_arr __pyx_mstate_global->__pyx_n_s_arr #define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines -#define __pyx_n_s_bit_depth __pyx_mstate_global->__pyx_n_s_bit_depth #define __pyx_n_u_bits_per_sample __pyx_mstate_global->__pyx_n_u_bits_per_sample +#define __pyx_n_s_bits_stored __pyx_mstate_global->__pyx_n_s_bits_stored #define __pyx_n_s_bytearray __pyx_mstate_global->__pyx_n_s_bytearray +#define __pyx_n_s_bytes __pyx_mstate_global->__pyx_n_s_bytes #define __pyx_kp_u_bytes_Interleave_mode __pyx_mstate_global->__pyx_kp_u_bytes_Interleave_mode #define __pyx_kp_s_bytes_bytearray __pyx_mstate_global->__pyx_kp_s_bytes_bytearray -#define __pyx_kp_u_bytes_per_pixel __pyx_mstate_global->__pyx_kp_u_bytes_per_pixel -#define __pyx_n_s_bytes_per_pixel_2 __pyx_mstate_global->__pyx_n_s_bytes_per_pixel_2 -#define __pyx_kp_u_bytes_shaped_as __pyx_mstate_global->__pyx_kp_u_bytes_shaped_as +#define __pyx_n_s_bytes_per_pixel __pyx_mstate_global->__pyx_n_s_bytes_per_pixel #define __pyx_n_s_ceil __pyx_mstate_global->__pyx_n_s_ceil #define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback #define __pyx_n_u_colour_transformation __pyx_mstate_global->__pyx_n_u_colour_transformation #define __pyx_n_s_columns __pyx_mstate_global->__pyx_n_s_columns -#define __pyx_n_s_components __pyx_mstate_global->__pyx_n_s_components #define __pyx_n_u_components __pyx_mstate_global->__pyx_n_u_components #define __pyx_n_s_compressed_length __pyx_mstate_global->__pyx_n_s_compressed_length #define __pyx_n_s_data_buffer __pyx_mstate_global->__pyx_n_s_data_buffer @@ -3582,11 +3423,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_dst_length __pyx_mstate_global->__pyx_n_s_dst_length #define __pyx_n_s_dtype __pyx_mstate_global->__pyx_n_s_dtype #define __pyx_n_s_encode __pyx_mstate_global->__pyx_n_s_encode -#define __pyx_n_s_encode_array __pyx_mstate_global->__pyx_n_s_encode_array -#define __pyx_n_s_encode_to_buffer __pyx_mstate_global->__pyx_n_s_encode_to_buffer #define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err #define __pyx_n_s_error_message __pyx_mstate_global->__pyx_n_s_error_message -#define __pyx_kp_u_expecting_np_uint8_or_np_uint16 __pyx_mstate_global->__pyx_kp_u_expecting_np_uint8_or_np_uint16 #define __pyx_n_s_frombuffer __pyx_mstate_global->__pyx_n_s_frombuffer #define __pyx_n_s_getLogger __pyx_mstate_global->__pyx_n_s_getLogger #define __pyx_n_u_height __pyx_mstate_global->__pyx_n_u_height @@ -3594,25 +3432,18 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_info __pyx_mstate_global->__pyx_n_s_info #define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing #define __pyx_n_s_int __pyx_mstate_global->__pyx_n_s_int -#define __pyx_kp_s_int_None __pyx_mstate_global->__pyx_kp_s_int_None #define __pyx_n_s_interleave_mode __pyx_mstate_global->__pyx_n_s_interleave_mode #define __pyx_n_u_interleave_mode __pyx_mstate_global->__pyx_n_u_interleave_mode #define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine #define __pyx_kp_u_jpeg_ls__CharLS __pyx_mstate_global->__pyx_kp_u_jpeg_ls__CharLS #define __pyx_kp_s_jpeg_ls__CharLS_pyx __pyx_mstate_global->__pyx_kp_s_jpeg_ls__CharLS_pyx -#define __pyx_n_s_log __pyx_mstate_global->__pyx_n_s_log #define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging #define __pyx_n_s_lossy_error __pyx_mstate_global->__pyx_n_s_lossy_error #define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main #define __pyx_n_s_math __pyx_mstate_global->__pyx_n_s_math -#define __pyx_n_s_max __pyx_mstate_global->__pyx_n_s_max #define __pyx_n_s_msg __pyx_mstate_global->__pyx_n_s_msg #define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name -#define __pyx_n_s_ndarray __pyx_mstate_global->__pyx_n_s_ndarray #define __pyx_n_s_np __pyx_mstate_global->__pyx_n_s_np -#define __pyx_kp_s_np_ndarray __pyx_mstate_global->__pyx_kp_s_np_ndarray -#define __pyx_kp_s_np_ndarray_bytes __pyx_mstate_global->__pyx_kp_s_np_ndarray_bytes -#define __pyx_n_s_nr_dims __pyx_mstate_global->__pyx_n_s_nr_dims #define __pyx_n_s_numpy __pyx_mstate_global->__pyx_n_s_numpy #define __pyx_kp_u_numpy_core_multiarray_failed_to __pyx_mstate_global->__pyx_kp_u_numpy_core_multiarray_failed_to #define __pyx_kp_u_numpy_core_umath_failed_to_impor __pyx_mstate_global->__pyx_kp_u_numpy_core_umath_failed_to_impor @@ -3623,8 +3454,6 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_return __pyx_mstate_global->__pyx_n_s_return #define __pyx_n_s_rows __pyx_mstate_global->__pyx_n_s_rows #define __pyx_n_s_samples_per_pixel __pyx_mstate_global->__pyx_n_s_samples_per_pixel -#define __pyx_n_s_shape __pyx_mstate_global->__pyx_n_s_shape -#define __pyx_n_s_size __pyx_mstate_global->__pyx_n_s_size #define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec #define __pyx_n_s_src __pyx_mstate_global->__pyx_n_s_src #define __pyx_n_s_src_length __pyx_mstate_global->__pyx_n_s_src_length @@ -3633,44 +3462,32 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test #define __pyx_n_s_tobytes __pyx_mstate_global->__pyx_n_s_tobytes #define __pyx_n_s_transpose __pyx_mstate_global->__pyx_n_s_transpose -#define __pyx_kp_s_tuple_bytearray_dict_str_int __pyx_mstate_global->__pyx_kp_s_tuple_bytearray_dict_str_int #define __pyx_n_s_typing __pyx_mstate_global->__pyx_n_s_typing #define __pyx_n_u_u __pyx_mstate_global->__pyx_n_u_u -#define __pyx_n_u_u1 __pyx_mstate_global->__pyx_n_u_u1 -#define __pyx_n_s_uint16 __pyx_mstate_global->__pyx_n_s_uint16 -#define __pyx_n_s_uint8 __pyx_mstate_global->__pyx_n_s_uint8 #define __pyx_n_u_width __pyx_mstate_global->__pyx_n_u_width -#define __pyx_kp_u_with __pyx_mstate_global->__pyx_kp_u_with #define __pyx_int_0 __pyx_mstate_global->__pyx_int_0 #define __pyx_int_1 __pyx_mstate_global->__pyx_int_1 #define __pyx_int_2 __pyx_mstate_global->__pyx_int_2 #define __pyx_int_3 __pyx_mstate_global->__pyx_int_3 -#define __pyx_int_4 __pyx_mstate_global->__pyx_int_4 #define __pyx_int_8 __pyx_mstate_global->__pyx_int_8 #define __pyx_tuple_ __pyx_mstate_global->__pyx_tuple_ #define __pyx_tuple__2 __pyx_mstate_global->__pyx_tuple__2 #define __pyx_tuple__4 __pyx_mstate_global->__pyx_tuple__4 #define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6 -#define __pyx_tuple__7 __pyx_mstate_global->__pyx_tuple__7 -#define __pyx_tuple__8 __pyx_mstate_global->__pyx_tuple__8 -#define __pyx_tuple__12 __pyx_mstate_global->__pyx_tuple__12 +#define __pyx_tuple__10 __pyx_mstate_global->__pyx_tuple__10 +#define __pyx_tuple__11 __pyx_mstate_global->__pyx_tuple__11 #define __pyx_tuple__13 __pyx_mstate_global->__pyx_tuple__13 #define __pyx_tuple__15 __pyx_mstate_global->__pyx_tuple__15 #define __pyx_tuple__17 __pyx_mstate_global->__pyx_tuple__17 #define __pyx_tuple__19 __pyx_mstate_global->__pyx_tuple__19 -#define __pyx_tuple__21 __pyx_mstate_global->__pyx_tuple__21 -#define __pyx_tuple__23 __pyx_mstate_global->__pyx_tuple__23 -#define __pyx_tuple__25 __pyx_mstate_global->__pyx_tuple__25 +#define __pyx_codeobj__12 __pyx_mstate_global->__pyx_codeobj__12 #define __pyx_codeobj__14 __pyx_mstate_global->__pyx_codeobj__14 #define __pyx_codeobj__16 __pyx_mstate_global->__pyx_codeobj__16 #define __pyx_codeobj__18 __pyx_mstate_global->__pyx_codeobj__18 #define __pyx_codeobj__20 __pyx_mstate_global->__pyx_codeobj__20 -#define __pyx_codeobj__22 __pyx_mstate_global->__pyx_codeobj__22 -#define __pyx_codeobj__24 __pyx_mstate_global->__pyx_codeobj__24 -#define __pyx_codeobj__26 __pyx_mstate_global->__pyx_codeobj__26 /* #### Code section: module_code ### */ -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":245 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":245 * * @property * cdef inline PyObject* base(self) nogil: # <<<<<<<<<<<<<< @@ -3681,7 +3498,7 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { static CYTHON_INLINE PyObject *__pyx_f_5numpy_7ndarray_4base_base(PyArrayObject *__pyx_v_self) { PyObject *__pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":248 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":248 * """Returns a borrowed reference to the object owning the data/memory. * """ * return PyArray_BASE(self) # <<<<<<<<<<<<<< @@ -3691,7 +3508,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_7ndarray_4base_base(PyArrayObject __pyx_r = PyArray_BASE(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":245 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":245 * * @property * cdef inline PyObject* base(self) nogil: # <<<<<<<<<<<<<< @@ -3704,7 +3521,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_7ndarray_4base_base(PyArrayObject return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":251 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":251 * * @property * cdef inline dtype descr(self): # <<<<<<<<<<<<<< @@ -3718,7 +3535,7 @@ static CYTHON_INLINE PyArray_Descr *__pyx_f_5numpy_7ndarray_5descr_descr(PyArray PyArray_Descr *__pyx_t_1; __Pyx_RefNannySetupContext("descr", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":254 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":254 * """Returns an owned reference to the dtype of the array. * """ * return PyArray_DESCR(self) # <<<<<<<<<<<<<< @@ -3731,7 +3548,7 @@ static CYTHON_INLINE PyArray_Descr *__pyx_f_5numpy_7ndarray_5descr_descr(PyArray __pyx_r = ((PyArray_Descr *)__pyx_t_1); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":251 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":251 * * @property * cdef inline dtype descr(self): # <<<<<<<<<<<<<< @@ -3746,7 +3563,7 @@ static CYTHON_INLINE PyArray_Descr *__pyx_f_5numpy_7ndarray_5descr_descr(PyArray return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":257 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":257 * * @property * cdef inline int ndim(self) nogil: # <<<<<<<<<<<<<< @@ -3757,7 +3574,7 @@ static CYTHON_INLINE PyArray_Descr *__pyx_f_5numpy_7ndarray_5descr_descr(PyArray static CYTHON_INLINE int __pyx_f_5numpy_7ndarray_4ndim_ndim(PyArrayObject *__pyx_v_self) { int __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":260 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":260 * """Returns the number of dimensions in the array. * """ * return PyArray_NDIM(self) # <<<<<<<<<<<<<< @@ -3767,7 +3584,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_7ndarray_4ndim_ndim(PyArrayObject *__pyx __pyx_r = PyArray_NDIM(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":257 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":257 * * @property * cdef inline int ndim(self) nogil: # <<<<<<<<<<<<<< @@ -3780,7 +3597,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_7ndarray_4ndim_ndim(PyArrayObject *__pyx return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":263 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":263 * * @property * cdef inline npy_intp *shape(self) nogil: # <<<<<<<<<<<<<< @@ -3791,7 +3608,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_7ndarray_4ndim_ndim(PyArrayObject *__pyx static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_5shape_shape(PyArrayObject *__pyx_v_self) { npy_intp *__pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":268 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":268 * Can return NULL for 0-dimensional arrays. * """ * return PyArray_DIMS(self) # <<<<<<<<<<<<<< @@ -3801,7 +3618,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_5shape_shape(PyArrayObjec __pyx_r = PyArray_DIMS(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":263 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":263 * * @property * cdef inline npy_intp *shape(self) nogil: # <<<<<<<<<<<<<< @@ -3814,7 +3631,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_5shape_shape(PyArrayObjec return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":271 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":271 * * @property * cdef inline npy_intp *strides(self) nogil: # <<<<<<<<<<<<<< @@ -3825,7 +3642,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_5shape_shape(PyArrayObjec static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_7strides_strides(PyArrayObject *__pyx_v_self) { npy_intp *__pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":275 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":275 * The number of elements matches the number of dimensions of the array (ndim). * """ * return PyArray_STRIDES(self) # <<<<<<<<<<<<<< @@ -3835,7 +3652,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_7strides_strides(PyArrayO __pyx_r = PyArray_STRIDES(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":271 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":271 * * @property * cdef inline npy_intp *strides(self) nogil: # <<<<<<<<<<<<<< @@ -3848,7 +3665,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_7strides_strides(PyArrayO return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":278 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":278 * * @property * cdef inline npy_intp size(self) nogil: # <<<<<<<<<<<<<< @@ -3859,7 +3676,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_7strides_strides(PyArrayO static CYTHON_INLINE npy_intp __pyx_f_5numpy_7ndarray_4size_size(PyArrayObject *__pyx_v_self) { npy_intp __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":281 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":281 * """Returns the total size (in number of elements) of the array. * """ * return PyArray_SIZE(self) # <<<<<<<<<<<<<< @@ -3869,7 +3686,7 @@ static CYTHON_INLINE npy_intp __pyx_f_5numpy_7ndarray_4size_size(PyArrayObject * __pyx_r = PyArray_SIZE(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":278 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":278 * * @property * cdef inline npy_intp size(self) nogil: # <<<<<<<<<<<<<< @@ -3882,7 +3699,7 @@ static CYTHON_INLINE npy_intp __pyx_f_5numpy_7ndarray_4size_size(PyArrayObject * return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":284 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":284 * * @property * cdef inline char* data(self) nogil: # <<<<<<<<<<<<<< @@ -3893,7 +3710,7 @@ static CYTHON_INLINE npy_intp __pyx_f_5numpy_7ndarray_4size_size(PyArrayObject * static CYTHON_INLINE char *__pyx_f_5numpy_7ndarray_4data_data(PyArrayObject *__pyx_v_self) { char *__pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":290 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":290 * of `PyArray_DATA()` instead, which returns a 'void*'. * """ * return PyArray_BYTES(self) # <<<<<<<<<<<<<< @@ -3903,7 +3720,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy_7ndarray_4data_data(PyArrayObject *__p __pyx_r = PyArray_BYTES(__pyx_v_self); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":284 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":284 * * @property * cdef inline char* data(self) nogil: # <<<<<<<<<<<<<< @@ -3916,7 +3733,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy_7ndarray_4data_data(PyArrayObject *__p return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":773 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":776 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -3933,7 +3750,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":774 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":777 * * cdef inline object PyArray_MultiIterNew1(a): * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< @@ -3941,13 +3758,13 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ * cdef inline object PyArray_MultiIterNew2(a, b): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 774, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 777, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":773 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":776 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -3966,7 +3783,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":776 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":779 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -3983,7 +3800,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":777 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":780 * * cdef inline object PyArray_MultiIterNew2(a, b): * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< @@ -3991,13 +3808,13 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ * cdef inline object PyArray_MultiIterNew3(a, b, c): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 777, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 780, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":776 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":779 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -4016,7 +3833,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":779 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":782 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -4033,7 +3850,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":780 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":783 * * cdef inline object PyArray_MultiIterNew3(a, b, c): * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< @@ -4041,13 +3858,13 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ * cdef inline object PyArray_MultiIterNew4(a, b, c, d): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 780, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":779 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":782 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -4066,7 +3883,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":782 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":785 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -4083,7 +3900,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":783 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":786 * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< @@ -4091,13 +3908,13 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 783, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":782 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":785 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -4116,7 +3933,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":785 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":788 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -4133,7 +3950,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":786 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":789 * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< @@ -4141,13 +3958,13 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ * cdef inline tuple PyDataType_SHAPE(dtype d): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 786, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 789, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":785 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":788 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -4166,7 +3983,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":788 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":791 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< @@ -4180,7 +3997,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ int __pyx_t_1; __Pyx_RefNannySetupContext("PyDataType_SHAPE", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":789 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":792 * * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< @@ -4190,7 +4007,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ __pyx_t_1 = PyDataType_HASSUBARRAY(__pyx_v_d); if (__pyx_t_1) { - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":790 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":793 * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): * return d.subarray.shape # <<<<<<<<<<<<<< @@ -4202,7 +4019,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":789 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":792 * * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< @@ -4211,7 +4028,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ */ } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":792 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":795 * return d.subarray.shape * else: * return () # <<<<<<<<<<<<<< @@ -4225,7 +4042,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ goto __pyx_L0; } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":788 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":791 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< @@ -4240,7 +4057,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":968 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":970 * int _import_umath() except -1 * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -4249,12 +4066,8 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ */ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":969 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":971 * * cdef inline void set_array_base(ndarray arr, object base): * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< @@ -4263,16 +4076,16 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_INCREF(__pyx_v_base); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":970 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":972 * cdef inline void set_array_base(ndarray arr, object base): * Py_INCREF(base) # important to do this before stealing the reference below! * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< * * cdef inline object get_array_base(ndarray arr): */ - __pyx_t_1 = PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 970, __pyx_L1_error) + (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":968 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":970 * int _import_umath() except -1 * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -4281,13 +4094,9 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("numpy.set_array_base", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":972 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":974 * PyArray_SetBaseObject(arr, base) * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -4302,7 +4111,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py int __pyx_t_1; __Pyx_RefNannySetupContext("get_array_base", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":973 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":975 * * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< @@ -4311,7 +4120,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py */ __pyx_v_base = PyArray_BASE(__pyx_v_arr); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":974 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":976 * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) * if base is NULL: # <<<<<<<<<<<<<< @@ -4321,7 +4130,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_t_1 = (__pyx_v_base == NULL); if (__pyx_t_1) { - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":975 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":977 * base = PyArray_BASE(arr) * if base is NULL: * return None # <<<<<<<<<<<<<< @@ -4332,7 +4141,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":974 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":976 * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) * if base is NULL: # <<<<<<<<<<<<<< @@ -4341,7 +4150,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py */ } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":976 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":978 * if base is NULL: * return None * return base # <<<<<<<<<<<<<< @@ -4353,7 +4162,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_r = ((PyObject *)__pyx_v_base); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":972 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":974 * PyArray_SetBaseObject(arr, base) * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -4368,7 +4177,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":980 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":982 * # Versions of the import_* functions which are more suitable for * # Cython code. * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< @@ -4392,7 +4201,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_array", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4408,16 +4217,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":982 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":984 * cdef inline int import_array() except -1: * try: * __pyx_import_array() # <<<<<<<<<<<<<< * except Exception: * raise ImportError("numpy.core.multiarray failed to import") */ - __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 982, __pyx_L3_error) + __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 984, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4431,7 +4240,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":983 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":985 * try: * __pyx_import_array() * except Exception: # <<<<<<<<<<<<<< @@ -4441,27 +4250,27 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); if (__pyx_t_4) { __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 983, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 985, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":984 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":986 * __pyx_import_array() * except Exception: * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< * * cdef inline int import_umath() except -1: */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 984, __pyx_L5_except_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 986, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(1, 984, __pyx_L5_except_error) + __PYX_ERR(1, 986, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4477,7 +4286,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":980 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":982 * # Versions of the import_* functions which are more suitable for * # Cython code. * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< @@ -4500,7 +4309,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":986 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":988 * raise ImportError("numpy.core.multiarray failed to import") * * cdef inline int import_umath() except -1: # <<<<<<<<<<<<<< @@ -4524,7 +4333,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_umath", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4540,16 +4349,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":988 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":990 * cdef inline int import_umath() except -1: * try: * _import_umath() # <<<<<<<<<<<<<< * except Exception: * raise ImportError("numpy.core.umath failed to import") */ - __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 988, __pyx_L3_error) + __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 990, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4563,7 +4372,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":989 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":991 * try: * _import_umath() * except Exception: # <<<<<<<<<<<<<< @@ -4573,27 +4382,27 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); if (__pyx_t_4) { __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 989, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 991, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":990 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":992 * _import_umath() * except Exception: * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< * * cdef inline int import_ufunc() except -1: */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 990, __pyx_L5_except_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 992, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(1, 990, __pyx_L5_except_error) + __PYX_ERR(1, 992, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4609,7 +4418,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":986 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":988 * raise ImportError("numpy.core.multiarray failed to import") * * cdef inline int import_umath() except -1: # <<<<<<<<<<<<<< @@ -4632,7 +4441,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":992 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":994 * raise ImportError("numpy.core.umath failed to import") * * cdef inline int import_ufunc() except -1: # <<<<<<<<<<<<<< @@ -4656,7 +4465,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_ufunc", 1); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4672,16 +4481,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":994 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":996 * cdef inline int import_ufunc() except -1: * try: * _import_umath() # <<<<<<<<<<<<<< * except Exception: * raise ImportError("numpy.core.umath failed to import") */ - __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 994, __pyx_L3_error) + __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 996, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4695,7 +4504,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":995 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":997 * try: * _import_umath() * except Exception: # <<<<<<<<<<<<<< @@ -4705,27 +4514,27 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); if (__pyx_t_4) { __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 995, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 997, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":996 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":998 * _import_umath() * except Exception: * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< * * */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 996, __pyx_L5_except_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 998, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(1, 996, __pyx_L5_except_error) + __PYX_ERR(1, 998, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4741,7 +4550,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":992 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":994 * raise ImportError("numpy.core.umath failed to import") * * cdef inline int import_ufunc() except -1: # <<<<<<<<<<<<<< @@ -4764,7 +4573,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":999 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1001 * * * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< @@ -4775,7 +4584,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { int __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1011 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1013 * bool * """ * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< @@ -4785,7 +4594,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_ __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":999 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1001 * * * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< @@ -4798,7 +4607,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1014 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1016 * * * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< @@ -4809,7 +4618,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_ static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { int __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1026 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1028 * bool * """ * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< @@ -4819,7 +4628,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_o __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1014 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1016 * * * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< @@ -4832,7 +4641,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_o return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1029 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1031 * * * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4843,7 +4652,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_o static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { npy_datetime __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1036 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1038 * also needed. That can be found using `get_datetime64_unit`. * """ * return (obj).obval # <<<<<<<<<<<<<< @@ -4853,7 +4662,7 @@ static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject * __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1029 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1031 * * * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4866,7 +4675,7 @@ static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject * return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1039 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1041 * * * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4877,7 +4686,7 @@ static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject * static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { npy_timedelta __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1043 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1045 * returns the int64 value underlying scalar numpy timedelta64 object * """ * return (obj).obval # <<<<<<<<<<<<<< @@ -4887,7 +4696,7 @@ static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1039 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1041 * * * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4900,7 +4709,7 @@ static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject return __pyx_r; } -/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1046 +/* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1048 * * * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< @@ -4911,7 +4720,7 @@ static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { NPY_DATETIMEUNIT __pyx_r; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1050 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1052 * returns the unit part of the dtype for a numpy datetime64 object. * """ * return (obj).obmeta.base # <<<<<<<<<<<<<< @@ -4919,7 +4728,7 @@ static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObjec __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1046 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1048 * * * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< @@ -6073,7 +5882,7 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -6086,7 +5895,7 @@ PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ -PyDoc_STRVAR(__pyx_doc_7_CharLS_4decode_from_buffer, "Decode the JPEG-LS codestream `src` to a bytearray\n\n Parameters\n ----------\n src : bytes | bytearray\n The JPEG-LS codestream to be decoded.\n\n Returns\n -------\n tuple[bytearray, dict[str, int]]\n The decoded (image data, image metadata).\n "); +PyDoc_STRVAR(__pyx_doc_7_CharLS_4decode_from_buffer, "Decode the JPEG-LS codestream `src` to a bytearray\n\n Parameters\n ----------\n src : bytes | bytearray\n The JPEG-LS codestream to be decoded.\n\n Returns\n -------\n bytearray\n The decoded image data.\n "); static PyMethodDef __pyx_mdef_7_CharLS_5decode_from_buffer = {"decode_from_buffer", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_5decode_from_buffer, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_4decode_from_buffer}; static PyObject *__pyx_pw_7_CharLS_5decode_from_buffer(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL @@ -6182,16 +5991,15 @@ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *_ PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("decode_from_buffer", 1); /* "_CharLS.pyx":250 - * The decoded (image data, image metadata). + * The decoded image data. * """ - * return _decode(src), read_header(src) # <<<<<<<<<<<<<< + * return _decode(src) # <<<<<<<<<<<<<< * * */ @@ -6220,46 +6028,15 @@ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *_ __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_read_header); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = NULL; - __pyx_t_4 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_4 = 1; - } - } - #endif - { - PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_src}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1)) __PYX_ERR(0, 250, __pyx_L1_error); - __Pyx_GIVEREF(__pyx_t_2); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error); + if (!(likely(PyByteArray_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytearray", __pyx_t_1))) __PYX_ERR(0, 250, __pyx_L1_error) + __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_r = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; goto __pyx_L0; /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -6269,7 +6046,6 @@ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *_ __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("_CharLS.decode_from_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -6868,80 +6644,22 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P /* "_CharLS.pyx":288 * * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, - */ - -static PyObject *__pyx_pf_7_CharLS_14__defaults__(CYTHON_UNUSED PyObject *__pyx_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__defaults__", 1); - __Pyx_XDECREF(__pyx_r); - - /* "_CharLS.pyx":291 - * src: np.ndarray | bytes, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> bytearray: - * """Return the image data in `arr` as a JPEG-LS encoded bytearray. - */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_lossy_error); - __Pyx_GIVEREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_lossy_error); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_lossy_error)) __PYX_ERR(0, 288, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None)) __PYX_ERR(0, 288, __pyx_L1_error); - - /* "_CharLS.pyx":288 - * - * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, + * def _encode( # <<<<<<<<<<<<<< + * src: bytes, + * lossy_error: int, */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1)) __PYX_ERR(0, 288, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, Py_None)) __PYX_ERR(0, 288, __pyx_L1_error); - __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_CharLS.__defaults__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} /* Python wrapper */ -static PyObject *__pyx_pw_7_CharLS_9encode_to_buffer(PyObject *__pyx_self, +static PyObject *__pyx_pw_7_CharLS_9_encode(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ -PyDoc_STRVAR(__pyx_doc_7_CharLS_8encode_to_buffer, "Return the image data in `arr` as a JPEG-LS encoded bytearray.\n\n Parameters\n ----------\n arr : numpy.ndarray\n An ndarray containing the image data.\n lossy_error : int, optional\n The absolute value of the allowable error when encoding using\n near-lossless, default ``0`` (lossless). For example, if using 8-bit\n pixel data then the allowable error for a lossy image may be in the\n range (1, 255).\n interleave_mode : int, optional\n The interleaving mode for multi-component (i.e. non-greyscale) images,\n default ``0``. One of\n\n * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn\n * ``1``: the pixels in `src` are ordered R1...RwG1...GwB1...BwRw+1...\n where w is the width of the image (i.e. the data is ordered line by line)\n * ``2``: the pixels in `src` are ordered R1G1B1R2G2B2...RnGnBn\n\n It's recommended that the pixel data in `src` be ordered to match an\n interleaving mode of ``0`` as this should result in the greatest\n compression ratio.\n\n Returns\n -------\n bytearray\n The encoded JPEG-LS codestream.\n "); -static PyMethodDef __pyx_mdef_7_CharLS_9encode_to_buffer = {"encode_to_buffer", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_9encode_to_buffer, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_8encode_to_buffer}; -static PyObject *__pyx_pw_7_CharLS_9encode_to_buffer(PyObject *__pyx_self, +PyDoc_STRVAR(__pyx_doc_7_CharLS_8_encode, "Return the image data in `src` as a JPEG-LS encoded bytearray.\n\n Parameters\n ----------\n src : bytes\n The image data to be JPEG-LS encoded.\n lossy_error : int\n The absolute value of the allowable error when encoding using\n near-lossless, default ``0`` (lossless). For example, if using 8-bit\n pixel data then the allowable error for a lossy image may be in the\n range (1, 255).\n interleave_mode : int\n Required for multi-sample (i.e. non-greyscale) image data, the\n interleaving mode of `src`. One of:\n\n * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn,\n otherwise known as colour-by-plane\n * ``1``: the pixels in `src` are ordered R1...RwG1...GwB1...BwRw+1...\n where w is the width of the image, otherwise known as colour-by-line\n * ``2``: the pixels in `src` are ordered R1G1B1R2G2B2...RnGnBn,\n otherwise known as colour-by-pixel\n rows : int\n The number of rows of pixels in the image.\n columns : int\n The number of columns of pixels in the image.\n samples_per_pixel : int\n The number of samples per pixel in the image, otherwise knows as the\n number of components or channels. A greyscale image has 1 sample per\n pixel while an RGB image will have 3.\n bits_stored : int\n The bit-depth per pixel, must be in the range (1, 16).\n\n Returns\n -------\n bytearray\n The encoded JPEG-LS codestream.\n "); +static PyMethodDef __pyx_mdef_7_CharLS_9_encode = {"_encode", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_9_encode, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_8_encode}; +static PyObject *__pyx_pw_7_CharLS_9_encode(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else @@ -6951,17 +6669,21 @@ PyObject *__pyx_args, PyObject *__pyx_kwds PyObject *__pyx_v_src = 0; PyObject *__pyx_v_lossy_error = 0; PyObject *__pyx_v_interleave_mode = 0; + PyObject *__pyx_v_rows = 0; + PyObject *__pyx_v_columns = 0; + PyObject *__pyx_v_samples_per_pixel = 0; + PyObject *__pyx_v_bits_stored = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject* values[3] = {0,0,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("encode_to_buffer (wrapper)", 0); + __Pyx_RefNannySetupContext("_encode (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); @@ -6971,21 +6693,18 @@ PyObject *__pyx_args, PyObject *__pyx_kwds #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { - PyObject **__pyx_pyargnames[] = {&__pyx_n_s_src,&__pyx_n_s_lossy_error,&__pyx_n_s_interleave_mode,0}; - __pyx_defaults *__pyx_dynamic_args = __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self); - values[1] = __Pyx_Arg_NewRef_FASTCALL(__pyx_dynamic_args->__pyx_arg_lossy_error); - - /* "_CharLS.pyx":291 - * src: np.ndarray | bytes, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> bytearray: - * """Return the image data in `arr` as a JPEG-LS encoded bytearray. - */ - values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None)); + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_src,&__pyx_n_s_lossy_error,&__pyx_n_s_interleave_mode,&__pyx_n_s_rows,&__pyx_n_s_columns,&__pyx_n_s_samples_per_pixel,&__pyx_n_s_bits_stored,0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { + case 7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3); + CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); @@ -7006,41 +6725,91 @@ PyObject *__pyx_args, PyObject *__pyx_kwds else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lossy_error); - if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lossy_error)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 1); __PYX_ERR(0, 288, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_interleave_mode); - if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_interleave_mode)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 2); __PYX_ERR(0, 288, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_rows)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[3]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 3); __PYX_ERR(0, 288, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (likely((values[4] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_columns)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[4]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 4); __PYX_ERR(0, 288, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 5: + if (likely((values[5] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samples_per_pixel)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[5]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 5); __PYX_ERR(0, 288, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 6: + if (likely((values[6] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_bits_stored)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[6]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, 6); __PYX_ERR(0, 288, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "encode_to_buffer") < 0)) __PYX_ERR(0, 288, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_encode") < 0)) __PYX_ERR(0, 288, __pyx_L3_error) } + } else if (unlikely(__pyx_nargs != 7)) { + goto __pyx_L5_argtuple_error; } else { - switch (__pyx_nargs) { - case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_src = values[0]; + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3); + values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4); + values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5); + values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6); + } + __pyx_v_src = ((PyObject*)values[0]); __pyx_v_lossy_error = ((PyObject*)values[1]); - __pyx_v_interleave_mode = values[2]; + __pyx_v_interleave_mode = ((PyObject*)values[2]); + __pyx_v_rows = ((PyObject*)values[3]); + __pyx_v_columns = ((PyObject*)values[4]); + __pyx_v_samples_per_pixel = ((PyObject*)values[5]); + __pyx_v_bits_stored = ((PyObject*)values[6]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("encode_to_buffer", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 288, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_encode", 1, 7, 7, __pyx_nargs); __PYX_ERR(0, 288, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -7050,20 +6819,18 @@ PyObject *__pyx_args, PyObject *__pyx_kwds __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } - __Pyx_AddTraceback("_CharLS.encode_to_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_CharLS._encode", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_src), (&PyBytes_Type), 0, "src", 1))) __PYX_ERR(0, 289, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lossy_error), (&PyInt_Type), 0, "lossy_error", 1))) __PYX_ERR(0, 290, __pyx_L1_error) - __pyx_r = __pyx_pf_7_CharLS_8encode_to_buffer(__pyx_self, __pyx_v_src, __pyx_v_lossy_error, __pyx_v_interleave_mode); - - /* "_CharLS.pyx":288 - * - * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, - */ + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_interleave_mode), (&PyInt_Type), 0, "interleave_mode", 1))) __PYX_ERR(0, 291, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_rows), (&PyInt_Type), 0, "rows", 1))) __PYX_ERR(0, 292, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_columns), (&PyInt_Type), 0, "columns", 1))) __PYX_ERR(0, 293, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samples_per_pixel), (&PyInt_Type), 0, "samples_per_pixel", 1))) __PYX_ERR(0, 294, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bits_stored), (&PyInt_Type), 0, "bits_stored", 1))) __PYX_ERR(0, 295, __pyx_L1_error) + __pyx_r = __pyx_pf_7_CharLS_8_encode(__pyx_self, __pyx_v_src, __pyx_v_lossy_error, __pyx_v_interleave_mode, __pyx_v_rows, __pyx_v_columns, __pyx_v_samples_per_pixel, __pyx_v_bits_stored); /* function exit code */ goto __pyx_L0; @@ -7080,2257 +6847,1320 @@ PyObject *__pyx_args, PyObject *__pyx_kwds return __pyx_r; } -static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode) { +static PyObject *__pyx_pf_7_CharLS_8_encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_src, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode, PyObject *__pyx_v_rows, PyObject *__pyx_v_columns, PyObject *__pyx_v_samples_per_pixel, PyObject *__pyx_v_bits_stored) { + struct JlsParameters __pyx_v_info; + PyObject *__pyx_v_src_length = NULL; + PyObject *__pyx_v_dst = NULL; + size_t __pyx_v_compressed_length; + PyObject *__pyx_v_error_message = NULL; + enum charls::jpegls_errc __pyx_v_err; + PyObject *__pyx_v_msg = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + struct JlsParameters __pyx_t_1; + long __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + long __pyx_t_10; + Py_ssize_t __pyx_t_11; + Py_UCS4 __pyx_t_12; + char *__pyx_t_13; + char *__pyx_t_14; + size_t __pyx_t_15; + char *__pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("encode_to_buffer", 1); + __Pyx_RefNannySetupContext("_encode", 1); - /* "_CharLS.pyx":322 + /* "_CharLS.pyx":334 * The encoded JPEG-LS codestream. * """ - * if isinstance(src, np.ndarray): # <<<<<<<<<<<<<< - * return _encode_array(src, lossy_error, interleave_mode) - * + * cdef JlsParameters info = build_parameters() # <<<<<<<<<<<<<< + * info.height = rows + * info.width = columns */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ndarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = PyObject_IsInstance(__pyx_v_src, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { + __pyx_t_1 = __pyx_f_7_CharLS_build_parameters(); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L1_error) + __pyx_v_info = __pyx_t_1; - /* "_CharLS.pyx":323 + /* "_CharLS.pyx":335 * """ - * if isinstance(src, np.ndarray): - * return _encode_array(src, lossy_error, interleave_mode) # <<<<<<<<<<<<<< + * cdef JlsParameters info = build_parameters() + * info.height = rows # <<<<<<<<<<<<<< + * info.width = columns + * info.components = samples_per_pixel + */ + __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_v_rows); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_v_info.height = __pyx_t_2; + + /* "_CharLS.pyx":336 + * cdef JlsParameters info = build_parameters() + * info.height = rows + * info.width = columns # <<<<<<<<<<<<<< + * info.components = samples_per_pixel + * info.interleaveMode = interleave_mode + */ + __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_v_columns); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 336, __pyx_L1_error) + __pyx_v_info.width = __pyx_t_2; + + /* "_CharLS.pyx":337 + * info.height = rows + * info.width = columns + * info.components = samples_per_pixel # <<<<<<<<<<<<<< + * info.interleaveMode = interleave_mode + * info.allowedLossyError = lossy_error + */ + __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_v_samples_per_pixel); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 337, __pyx_L1_error) + __pyx_v_info.components = __pyx_t_2; + + /* "_CharLS.pyx":338 + * info.width = columns + * info.components = samples_per_pixel + * info.interleaveMode = interleave_mode # <<<<<<<<<<<<<< + * info.allowedLossyError = lossy_error * - * # Check we have the required encoding parameters */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_encode_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_5 = 1; - } - } - #endif - { - PyObject *__pyx_callargs[4] = {__pyx_t_4, __pyx_v_src, __pyx_v_lossy_error, __pyx_v_interleave_mode}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_5, 3+__pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - if (!(likely(PyByteArray_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytearray", __pyx_t_2))) __PYX_ERR(0, 323, __pyx_L1_error) - __pyx_r = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_interleave_mode); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 338, __pyx_L1_error) + __pyx_v_info.interleaveMode = ((enum charls::interleave_mode)((int)__pyx_t_3)); - /* "_CharLS.pyx":322 - * The encoded JPEG-LS codestream. - * """ - * if isinstance(src, np.ndarray): # <<<<<<<<<<<<<< - * return _encode_array(src, lossy_error, interleave_mode) + /* "_CharLS.pyx":339 + * info.components = samples_per_pixel + * info.interleaveMode = interleave_mode + * info.allowedLossyError = lossy_error # <<<<<<<<<<<<<< + * + * info.stride = info.width * math.ceil(bits_stored / 8) + */ + __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_v_lossy_error); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 339, __pyx_L1_error) + __pyx_v_info.allowedLossyError = __pyx_t_2; + + /* "_CharLS.pyx":341 + * info.allowedLossyError = lossy_error * + * info.stride = info.width * math.ceil(bits_stored / 8) # <<<<<<<<<<<<<< + * if interleave_mode != 0: + * info.stride = info.stride * info.components */ + __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_math); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ceil); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_v_bits_stored, __pyx_int_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + __pyx_t_3 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_3 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_3, 1+__pyx_t_3); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } + __pyx_t_7 = PyNumber_Multiply(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_t_7); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_info.stride = __pyx_t_2; - /* "_CharLS.pyx":288 + /* "_CharLS.pyx":342 * + * info.stride = info.width * math.ceil(bits_stored / 8) + * if interleave_mode != 0: # <<<<<<<<<<<<<< + * info.stride = info.stride * info.components * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, */ + __pyx_t_7 = PyObject_RichCompare(__pyx_v_interleave_mode, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 342, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 342, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_9) { - /* function exit code */ - __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_CharLS.encode_to_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "_CharLS.pyx":343 + * info.stride = info.width * math.ceil(bits_stored / 8) + * if interleave_mode != 0: + * info.stride = info.stride * info.components # <<<<<<<<<<<<<< + * + * info.bitsPerSample = 2 if bits_stored < 2 else bits_stored + */ + __pyx_v_info.stride = (__pyx_v_info.stride * __pyx_v_info.components); -/* "_CharLS.pyx":334 + /* "_CharLS.pyx":342 * + * info.stride = info.width * math.ceil(bits_stored / 8) + * if interleave_mode != 0: # <<<<<<<<<<<<<< + * info.stride = info.stride * info.components * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, */ + } -static PyObject *__pyx_pf_7_CharLS_16__defaults__(CYTHON_UNUSED PyObject *__pyx_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__defaults__", 1); - __Pyx_XDECREF(__pyx_r); - - /* "_CharLS.pyx":337 - * arr: np.ndarray, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> bytearray: - * if arr.dtype == np.uint8: - */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__Pyx_CyFunction_Defaults(__pyx_defaults1, __pyx_self)->__pyx_arg_lossy_error); - __Pyx_GIVEREF(__Pyx_CyFunction_Defaults(__pyx_defaults1, __pyx_self)->__pyx_arg_lossy_error); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __Pyx_CyFunction_Defaults(__pyx_defaults1, __pyx_self)->__pyx_arg_lossy_error)) __PYX_ERR(0, 334, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None)) __PYX_ERR(0, 334, __pyx_L1_error); - - /* "_CharLS.pyx":334 + /* "_CharLS.pyx":345 + * info.stride = info.stride * info.components * + * info.bitsPerSample = 2 if bits_stored < 2 else bits_stored # <<<<<<<<<<<<<< * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, + * LOGGER.debug( */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, Py_None)) __PYX_ERR(0, 334, __pyx_L1_error); - __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_CharLS.__defaults__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_7_CharLS_11_encode_array(PyObject *__pyx_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -); /*proto*/ -static PyMethodDef __pyx_mdef_7_CharLS_11_encode_array = {"_encode_array", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_11_encode_array, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_7_CharLS_11_encode_array(PyObject *__pyx_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -) { - PyObject *__pyx_v_arr = 0; - PyObject *__pyx_v_lossy_error = 0; - PyObject *__pyx_v_interleave_mode = 0; - #if !CYTHON_METH_FASTCALL - CYTHON_UNUSED Py_ssize_t __pyx_nargs; - #endif - CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject* values[3] = {0,0,0}; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_encode_array (wrapper)", 0); - #if !CYTHON_METH_FASTCALL - #if CYTHON_ASSUME_SAFE_MACROS - __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); - #else - __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; - #endif - #endif - __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); - { - PyObject **__pyx_pyargnames[] = {&__pyx_n_s_arr,&__pyx_n_s_lossy_error,&__pyx_n_s_interleave_mode,0}; - __pyx_defaults1 *__pyx_dynamic_args = __Pyx_CyFunction_Defaults(__pyx_defaults1, __pyx_self); - values[1] = __Pyx_Arg_NewRef_FASTCALL(__pyx_dynamic_args->__pyx_arg_lossy_error); - - /* "_CharLS.pyx":337 - * arr: np.ndarray, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> bytearray: - * if arr.dtype == np.uint8: - */ - values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None)); - if (__pyx_kwds) { - Py_ssize_t kw_args; - switch (__pyx_nargs) { - case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); - switch (__pyx_nargs) { - case 0: - if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_arr)) != 0)) { - (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); - kw_args--; - } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L3_error) - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lossy_error); - if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_interleave_mode); - if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_encode_array") < 0)) __PYX_ERR(0, 334, __pyx_L3_error) - } - } else { - switch (__pyx_nargs) { - case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_arr = values[0]; - __pyx_v_lossy_error = ((PyObject*)values[1]); - __pyx_v_interleave_mode = values[2]; - } - goto __pyx_L6_skip; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_encode_array", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 334, __pyx_L3_error) - __pyx_L6_skip:; - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - { - Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); - } + __pyx_t_7 = PyObject_RichCompare(__pyx_v_bits_stored, __pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 345, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_9) { + __pyx_t_2 = 2; + } else { + __pyx_t_10 = __Pyx_PyInt_As_long(__pyx_v_bits_stored); if (unlikely((__pyx_t_10 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_2 = __pyx_t_10; } - __Pyx_AddTraceback("_CharLS._encode_array", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lossy_error), (&PyInt_Type), 0, "lossy_error", 1))) __PYX_ERR(0, 336, __pyx_L1_error) - __pyx_r = __pyx_pf_7_CharLS_10_encode_array(__pyx_self, __pyx_v_arr, __pyx_v_lossy_error, __pyx_v_interleave_mode); + __pyx_v_info.bitsPerSample = __pyx_t_2; - /* "_CharLS.pyx":334 - * + /* "_CharLS.pyx":347 + * info.bitsPerSample = 2 if bits_stored < 2 else bits_stored * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, + * LOGGER.debug( # <<<<<<<<<<<<<< + * "Encoding paramers are:\n" + * f"\tWidth: {info.width} px\n" */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - { - Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); - } - } - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_7_CharLS_10_encode_array(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode) { - PyObject *__pyx_v_bytes_per_pixel = NULL; - PyObject *__pyx_v_src_length = NULL; - Py_ssize_t __pyx_v_nr_dims; - PyObject *__pyx_v_rows = NULL; - PyObject *__pyx_v_columns = NULL; - PyObject *__pyx_v_components = NULL; - struct JlsParameters __pyx_v_info; - PyObject *__pyx_v_bit_depth = NULL; - PyObject *__pyx_v_dst = NULL; - size_t __pyx_v_compressed_length; - PyObject *__pyx_v_error_message = NULL; - PyObject *__pyx_v_src = NULL; - enum charls::jpegls_errc __pyx_v_err; - PyObject *__pyx_v_msg = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - Py_UCS4 __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; - struct JlsParameters __pyx_t_11; - long __pyx_t_12; - long __pyx_t_13; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - char *__pyx_t_16; - char *__pyx_t_17; - size_t __pyx_t_18; - char *__pyx_t_19; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_encode_array", 0); - __Pyx_INCREF(__pyx_v_interleave_mode); - - /* "_CharLS.pyx":339 - * interleave_mode: int | None = None, - * ) -> bytearray: - * if arr.dtype == np.uint8: # <<<<<<<<<<<<<< - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: + /* "_CharLS.pyx":348 + * + * LOGGER.debug( + * "Encoding paramers are:\n" # <<<<<<<<<<<<<< + * f"\tWidth: {info.width} px\n" + * f"\tHeight: {info.height} px\n" */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_uint8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "_CharLS.pyx":340 - * ) -> bytearray: - * if arr.dtype == np.uint8: - * bytes_per_pixel = 1 # <<<<<<<<<<<<<< - * elif arr.dtype == np.uint16: - * bytes_per_pixel = 2 - */ - __Pyx_INCREF(__pyx_int_1); - __pyx_v_bytes_per_pixel = __pyx_int_1; - - /* "_CharLS.pyx":339 - * interleave_mode: int | None = None, - * ) -> bytearray: - * if arr.dtype == np.uint8: # <<<<<<<<<<<<<< - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: - */ - goto __pyx_L3; - } + __pyx_t_5 = PyTuple_New(15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_11 = 0; + __pyx_t_12 = 127; + __Pyx_INCREF(__pyx_kp_u_Encoding_paramers_are_Width); + __pyx_t_11 += 31; + __Pyx_GIVEREF(__pyx_kp_u_Encoding_paramers_are_Width); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Encoding_paramers_are_Width); - /* "_CharLS.pyx":341 - * if arr.dtype == np.uint8: - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: # <<<<<<<<<<<<<< - * bytes_per_pixel = 2 - * else: + /* "_CharLS.pyx":349 + * LOGGER.debug( + * "Encoding paramers are:\n" + * f"\tWidth: {info.width} px\n" # <<<<<<<<<<<<<< + * f"\tHeight: {info.height} px\n" + * f"\tComponents: {info.components}\n" */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_uint16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(__pyx_t_4)) { + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.width, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_px_Height); + __pyx_t_11 += 13; + __Pyx_GIVEREF(__pyx_kp_u_px_Height); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_px_Height); - /* "_CharLS.pyx":342 - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: - * bytes_per_pixel = 2 # <<<<<<<<<<<<<< - * else: - * raise ValueError( + /* "_CharLS.pyx":350 + * "Encoding paramers are:\n" + * f"\tWidth: {info.width} px\n" + * f"\tHeight: {info.height} px\n" # <<<<<<<<<<<<<< + * f"\tComponents: {info.components}\n" + * f"\tBits per sample: {info.bitsPerSample}\n" */ - __Pyx_INCREF(__pyx_int_2); - __pyx_v_bytes_per_pixel = __pyx_int_2; + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.height, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_px_Components); + __pyx_t_11 += 17; + __Pyx_GIVEREF(__pyx_kp_u_px_Components); + PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u_px_Components); - /* "_CharLS.pyx":341 - * if arr.dtype == np.uint8: - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: # <<<<<<<<<<<<<< - * bytes_per_pixel = 2 - * else: + /* "_CharLS.pyx":351 + * f"\tWidth: {info.width} px\n" + * f"\tHeight: {info.height} px\n" + * f"\tComponents: {info.components}\n" # <<<<<<<<<<<<<< + * f"\tBits per sample: {info.bitsPerSample}\n" + * f"\tStride: {info.stride} bytes\n" */ - goto __pyx_L3; - } + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.components, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_Bits_per_sample); + __pyx_t_11 += 19; + __Pyx_GIVEREF(__pyx_kp_u_Bits_per_sample); + PyTuple_SET_ITEM(__pyx_t_5, 6, __pyx_kp_u_Bits_per_sample); - /* "_CharLS.pyx":344 - * bytes_per_pixel = 2 - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * f"Invalid input data type '{arr.dtype}', expecting np.uint8 or np.uint16." - * ) + /* "_CharLS.pyx":352 + * f"\tHeight: {info.height} px\n" + * f"\tComponents: {info.components}\n" + * f"\tBits per sample: {info.bitsPerSample}\n" # <<<<<<<<<<<<<< + * f"\tStride: {info.stride} bytes\n" + * f"\tInterleave mode: {info.interleaveMode}\n" */ - /*else*/ { - - /* "_CharLS.pyx":345 - * else: - * raise ValueError( - * f"Invalid input data type '{arr.dtype}', expecting np.uint8 or np.uint16." # <<<<<<<<<<<<<< - * ) - * - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = 0; - __pyx_t_6 = 127; - __Pyx_INCREF(__pyx_kp_u_Invalid_input_data_type); - __pyx_t_5 += 25; - __Pyx_GIVEREF(__pyx_kp_u_Invalid_input_data_type); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Invalid_input_data_type); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_kp_u_expecting_np_uint8_or_np_uint16); - __pyx_t_5 += 35; - __Pyx_GIVEREF(__pyx_kp_u_expecting_np_uint8_or_np_uint16); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_expecting_np_uint8_or_np_uint16); - __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.bitsPerSample, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 7, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_Stride); + __pyx_t_11 += 10; + __Pyx_GIVEREF(__pyx_kp_u_Stride); + PyTuple_SET_ITEM(__pyx_t_5, 8, __pyx_kp_u_Stride); - /* "_CharLS.pyx":344 - * bytes_per_pixel = 2 - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * f"Invalid input data type '{arr.dtype}', expecting np.uint8 or np.uint16." - * ) + /* "_CharLS.pyx":353 + * f"\tComponents: {info.components}\n" + * f"\tBits per sample: {info.bitsPerSample}\n" + * f"\tStride: {info.stride} bytes\n" # <<<<<<<<<<<<<< + * f"\tInterleave mode: {info.interleaveMode}\n" + * f"\tAllowed lossy error: {info.allowedLossyError}\n" */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 344, __pyx_L1_error) - } - __pyx_L3:; - - /* "_CharLS.pyx":348 - * ) - * - * src_length = arr.size * bytes_per_pixel # <<<<<<<<<<<<<< - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_src_length = __pyx_t_2; - __pyx_t_2 = 0; - - /* "_CharLS.pyx":349 - * - * src_length = arr.size * bytes_per_pixel - * nr_dims = len(arr.shape) # <<<<<<<<<<<<<< - * if nr_dims not in (2, 3): - * raise ValueError("Invalid data shape") - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_nr_dims = __pyx_t_5; - - /* "_CharLS.pyx":350 - * src_length = arr.size * bytes_per_pixel - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): # <<<<<<<<<<<<<< - * raise ValueError("Invalid data shape") - * - */ - switch (__pyx_v_nr_dims) { - case 2: - case 3: - __pyx_t_4 = 0; - break; - default: - __pyx_t_4 = 1; - break; - } - __pyx_t_7 = __pyx_t_4; - if (unlikely(__pyx_t_7)) { - - /* "_CharLS.pyx":351 - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): - * raise ValueError("Invalid data shape") # <<<<<<<<<<<<<< - * - * LOGGER.debug( - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 351, __pyx_L1_error) - - /* "_CharLS.pyx":350 - * src_length = arr.size * bytes_per_pixel - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): # <<<<<<<<<<<<<< - * raise ValueError("Invalid data shape") - * - */ - } - - /* "_CharLS.pyx":353 - * raise ValueError("Invalid data shape") - * - * LOGGER.debug( # <<<<<<<<<<<<<< - * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " - * f"{bytes_per_pixel} bytes per pixel" - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.stride, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 9, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_bytes_Interleave_mode); + __pyx_t_11 += 25; + __Pyx_GIVEREF(__pyx_kp_u_bytes_Interleave_mode); + PyTuple_SET_ITEM(__pyx_t_5, 10, __pyx_kp_u_bytes_Interleave_mode); /* "_CharLS.pyx":354 - * - * LOGGER.debug( - * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " # <<<<<<<<<<<<<< - * f"{bytes_per_pixel} bytes per pixel" + * f"\tBits per sample: {info.bitsPerSample}\n" + * f"\tStride: {info.stride} bytes\n" + * f"\tInterleave mode: {info.interleaveMode}\n" # <<<<<<<<<<<<<< + * f"\tAllowed lossy error: {info.allowedLossyError}\n" * ) */ - __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = 0; - __pyx_t_6 = 127; - __Pyx_INCREF(__pyx_kp_u_Encoding_src_is); - __pyx_t_5 += 18; - __Pyx_GIVEREF(__pyx_kp_u_Encoding_src_is); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Encoding_src_is); - __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_v_src_length, __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_bytes_shaped_as); - __pyx_t_5 += 18; - __Pyx_GIVEREF(__pyx_kp_u_bytes_shaped_as); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_bytes_shaped_as); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_8, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_INCREF(__pyx_kp_u_with); - __pyx_t_5 += 6; - __Pyx_GIVEREF(__pyx_kp_u_with); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_with); + __pyx_t_6 = __Pyx_PyUnicode_From_int(((int)__pyx_v_info.interleaveMode), 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 11, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_Allowed_lossy_error); + __pyx_t_11 += 23; + __Pyx_GIVEREF(__pyx_kp_u_Allowed_lossy_error); + PyTuple_SET_ITEM(__pyx_t_5, 12, __pyx_kp_u_Allowed_lossy_error); /* "_CharLS.pyx":355 - * LOGGER.debug( - * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " - * f"{bytes_per_pixel} bytes per pixel" # <<<<<<<<<<<<<< + * f"\tStride: {info.stride} bytes\n" + * f"\tInterleave mode: {info.interleaveMode}\n" + * f"\tAllowed lossy error: {info.allowedLossyError}\n" # <<<<<<<<<<<<<< * ) * */ - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_bytes_per_pixel, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_INCREF(__pyx_kp_u_bytes_per_pixel); - __pyx_t_5 += 16; - __Pyx_GIVEREF(__pyx_kp_u_bytes_per_pixel); - PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_kp_u_bytes_per_pixel); + __pyx_t_6 = __Pyx_PyUnicode_From_long(__pyx_v_info.allowedLossyError, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 13, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u__7); + __pyx_t_11 += 1; + __Pyx_GIVEREF(__pyx_kp_u__7); + PyTuple_SET_ITEM(__pyx_t_5, 14, __pyx_kp_u__7); - /* "_CharLS.pyx":354 + /* "_CharLS.pyx":348 * * LOGGER.debug( - * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " # <<<<<<<<<<<<<< - * f"{bytes_per_pixel} bytes per pixel" - * ) + * "Encoding paramers are:\n" # <<<<<<<<<<<<<< + * f"\tWidth: {info.width} px\n" + * f"\tHeight: {info.height} px\n" */ - __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_3, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_10 = 0; + __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_5, 15, __pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_3 = 0; #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_10 = 1; + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_3 = 1; } } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_9}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_6}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_3, 1+__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "_CharLS.pyx":358 - * ) + /* "_CharLS.pyx":359 * - * if nr_dims == 2: # <<<<<<<<<<<<<< - * # Greyscale images should always be interleave mode 0 - * interleave_mode = 0 - */ - __pyx_t_7 = (__pyx_v_nr_dims == 2); - if (__pyx_t_7) { - - /* "_CharLS.pyx":360 - * if nr_dims == 2: - * # Greyscale images should always be interleave mode 0 - * interleave_mode = 0 # <<<<<<<<<<<<<< - * rows = arr.shape[0] - * columns = arr.shape[1] - */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF_SET(__pyx_v_interleave_mode, __pyx_int_0); - - /* "_CharLS.pyx":361 - * # Greyscale images should always be interleave mode 0 - * interleave_mode = 0 - * rows = arr.shape[0] # <<<<<<<<<<<<<< - * columns = arr.shape[1] - * else: - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_rows = __pyx_t_1; - __pyx_t_1 = 0; - - /* "_CharLS.pyx":362 - * interleave_mode = 0 - * rows = arr.shape[0] - * columns = arr.shape[1] # <<<<<<<<<<<<<< - * else: - * # Multi-component images may be interleave mode 0, 1 or 2 - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_columns = __pyx_t_2; - __pyx_t_2 = 0; - - /* "_CharLS.pyx":358 - * ) + * # Destination for the compressed data - start out twice the length of raw + * src_length = len(src) # <<<<<<<<<<<<<< + * dst = bytearray(b"\x00" * src_length * 2) * - * if nr_dims == 2: # <<<<<<<<<<<<<< - * # Greyscale images should always be interleave mode 0 - * interleave_mode = 0 */ - goto __pyx_L5; - } + __pyx_t_11 = __Pyx_PyBytes_GET_SIZE(__pyx_v_src); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 359, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_src_length = __pyx_t_7; + __pyx_t_7 = 0; - /* "_CharLS.pyx":365 - * else: - * # Multi-component images may be interleave mode 0, 1 or 2 - * if arr.shape[-1] in (3, 4): # <<<<<<<<<<<<<< - * # Colour-by-pixel (R, C, 3) or (R, C, 4) - * interleave_mode = 1 if interleave_mode is None else interleave_mode + /* "_CharLS.pyx":360 + * # Destination for the compressed data - start out twice the length of raw + * src_length = len(src) + * dst = bytearray(b"\x00" * src_length * 2) # <<<<<<<<<<<<<< + * + * # Number of bytes of compressed data */ - /*else*/ { - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_1, __pyx_int_3, 3, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 365, __pyx_L1_error) - if (!__pyx_t_4) { - } else { - __pyx_t_7 = __pyx_t_4; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_4 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_1, __pyx_int_4, 4, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 365, __pyx_L1_error) - __pyx_t_7 = __pyx_t_4; - __pyx_L7_bool_binop_done:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __pyx_t_7; - if (__pyx_t_4) { - - /* "_CharLS.pyx":367 - * if arr.shape[-1] in (3, 4): - * # Colour-by-pixel (R, C, 3) or (R, C, 4) - * interleave_mode = 1 if interleave_mode is None else interleave_mode # <<<<<<<<<<<<<< - * elif arr.shape[0] in (3, 4): - * # Colour-by-plane (3, R, C) or (4, R, C) - */ - __pyx_t_4 = (__pyx_v_interleave_mode == Py_None); - if (__pyx_t_4) { - __Pyx_INCREF(__pyx_int_1); - __pyx_t_1 = __pyx_int_1; - } else { - __Pyx_INCREF(__pyx_v_interleave_mode); - __pyx_t_1 = __pyx_v_interleave_mode; - } - __Pyx_DECREF_SET(__pyx_v_interleave_mode, __pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_7 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_src_length); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyInt_MultiplyObjC(__pyx_t_7, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_dst = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; - /* "_CharLS.pyx":365 - * else: - * # Multi-component images may be interleave mode 0, 1 or 2 - * if arr.shape[-1] in (3, 4): # <<<<<<<<<<<<<< - * # Colour-by-pixel (R, C, 3) or (R, C, 4) - * interleave_mode = 1 if interleave_mode is None else interleave_mode + /* "_CharLS.pyx":363 + * + * # Number of bytes of compressed data + * cdef size_t compressed_length = 0 # <<<<<<<<<<<<<< + * + * # Error strings are defined in jpegls_error.cpp */ - goto __pyx_L6; - } + __pyx_v_compressed_length = 0; - /* "_CharLS.pyx":368 - * # Colour-by-pixel (R, C, 3) or (R, C, 4) - * interleave_mode = 1 if interleave_mode is None else interleave_mode - * elif arr.shape[0] in (3, 4): # <<<<<<<<<<<<<< - * # Colour-by-plane (3, R, C) or (4, R, C) - * interleave_mode = 0 if interleave_mode is None else interleave_mode + /* "_CharLS.pyx":367 + * # Error strings are defined in jpegls_error.cpp + * # As of v2.4.2 the longest string is ~114 chars, so give it a 256 buffer + * error_message = bytearray(b"\x00" * 256) # <<<<<<<<<<<<<< + * + * cdef JLS_ERROR err */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_2, __pyx_int_3, 3, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 368, __pyx_L1_error) - if (!__pyx_t_7) { - } else { - __pyx_t_4 = __pyx_t_7; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_2, __pyx_int_4, 4, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 368, __pyx_L1_error) - __pyx_t_4 = __pyx_t_7; - __pyx_L9_bool_binop_done:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __pyx_t_4; - if (__pyx_t_7) { - - /* "_CharLS.pyx":370 - * elif arr.shape[0] in (3, 4): - * # Colour-by-plane (3, R, C) or (4, R, C) - * interleave_mode = 0 if interleave_mode is None else interleave_mode # <<<<<<<<<<<<<< - * elif interleave_mode is None: - * raise ValueError( - */ - __pyx_t_7 = (__pyx_v_interleave_mode == Py_None); - if (__pyx_t_7) { - __Pyx_INCREF(__pyx_int_0); - __pyx_t_2 = __pyx_int_0; - } else { - __Pyx_INCREF(__pyx_v_interleave_mode); - __pyx_t_2 = __pyx_v_interleave_mode; - } - __Pyx_DECREF_SET(__pyx_v_interleave_mode, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_error_message = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; - /* "_CharLS.pyx":368 - * # Colour-by-pixel (R, C, 3) or (R, C, 4) - * interleave_mode = 1 if interleave_mode is None else interleave_mode - * elif arr.shape[0] in (3, 4): # <<<<<<<<<<<<<< - * # Colour-by-plane (3, R, C) or (4, R, C) - * interleave_mode = 0 if interleave_mode is None else interleave_mode + /* "_CharLS.pyx":371 + * cdef JLS_ERROR err + * err = JpegLsEncode( + * dst, # <<<<<<<<<<<<<< + * len(dst), + * &compressed_length, */ - goto __pyx_L6; - } + __pyx_t_13 = __Pyx_PyObject_AsWritableString(__pyx_v_dst); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 371, __pyx_L1_error) - /* "_CharLS.pyx":371 - * # Colour-by-plane (3, R, C) or (4, R, C) - * interleave_mode = 0 if interleave_mode is None else interleave_mode - * elif interleave_mode is None: # <<<<<<<<<<<<<< - * raise ValueError( - * "Unable to automatically determine an appropriate 'interleave_mode' " + /* "_CharLS.pyx":372 + * err = JpegLsEncode( + * dst, + * len(dst), # <<<<<<<<<<<<<< + * &compressed_length, + * src, */ - __pyx_t_7 = (__pyx_v_interleave_mode == Py_None); - if (unlikely(__pyx_t_7)) { + __pyx_t_11 = __Pyx_PyByteArray_GET_SIZE(__pyx_v_dst); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 372, __pyx_L1_error) - /* "_CharLS.pyx":372 - * interleave_mode = 0 if interleave_mode is None else interleave_mode - * elif interleave_mode is None: - * raise ValueError( # <<<<<<<<<<<<<< - * "Unable to automatically determine an appropriate 'interleave_mode' " - * "value, please set it manually" + /* "_CharLS.pyx":374 + * len(dst), + * &compressed_length, + * src, # <<<<<<<<<<<<<< + * src_length, + * &info, */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 372, __pyx_L1_error) + __pyx_t_14 = __Pyx_PyBytes_AsWritableString(__pyx_v_src); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 374, __pyx_L1_error) - /* "_CharLS.pyx":371 - * # Colour-by-plane (3, R, C) or (4, R, C) - * interleave_mode = 0 if interleave_mode is None else interleave_mode - * elif interleave_mode is None: # <<<<<<<<<<<<<< - * raise ValueError( - * "Unable to automatically determine an appropriate 'interleave_mode' " + /* "_CharLS.pyx":375 + * &compressed_length, + * src, + * src_length, # <<<<<<<<<<<<<< + * &info, + * error_message */ - } - __pyx_L6:; + __pyx_t_15 = __Pyx_PyInt_As_size_t(__pyx_v_src_length); if (unlikely((__pyx_t_15 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 375, __pyx_L1_error) - /* "_CharLS.pyx":377 - * ) + /* "_CharLS.pyx":377 + * src_length, + * &info, + * error_message # <<<<<<<<<<<<<< + * ) * - * if interleave_mode == 0: # <<<<<<<<<<<<<< - * components = arr.shape[0] - * rows = arr.shape[1] */ - __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_interleave_mode, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 377, __pyx_L1_error) - if (__pyx_t_7) { + __pyx_t_16 = __Pyx_PyObject_AsWritableString(__pyx_v_error_message); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 377, __pyx_L1_error) - /* "_CharLS.pyx":378 + /* "_CharLS.pyx":370 * - * if interleave_mode == 0: - * components = arr.shape[0] # <<<<<<<<<<<<<< - * rows = arr.shape[1] - * columns = arr.shape[2] + * cdef JLS_ERROR err + * err = JpegLsEncode( # <<<<<<<<<<<<<< + * dst, + * len(dst), */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_components = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_v_err = JpegLsEncode(((char *)__pyx_t_13), __pyx_t_11, (&__pyx_v_compressed_length), ((char *)__pyx_t_14), __pyx_t_15, (&__pyx_v_info), ((char *)__pyx_t_16)); - /* "_CharLS.pyx":379 - * if interleave_mode == 0: - * components = arr.shape[0] - * rows = arr.shape[1] # <<<<<<<<<<<<<< - * columns = arr.shape[2] - * else: + /* "_CharLS.pyx":380 + * ) + * + * if err != 0: # <<<<<<<<<<<<<< + * msg = error_message.decode("ascii").strip("\0") + * raise RuntimeError(f"Encoding error: {msg}") */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_rows = __pyx_t_2; - __pyx_t_2 = 0; - - /* "_CharLS.pyx":380 - * components = arr.shape[0] - * rows = arr.shape[1] - * columns = arr.shape[2] # <<<<<<<<<<<<<< - * else: - * rows = arr.shape[0] - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_columns = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_9 = (((int)__pyx_v_err) != 0); + if (unlikely(__pyx_t_9)) { - /* "_CharLS.pyx":377 - * ) + /* "_CharLS.pyx":381 + * + * if err != 0: + * msg = error_message.decode("ascii").strip("\0") # <<<<<<<<<<<<<< + * raise RuntimeError(f"Encoding error: {msg}") * - * if interleave_mode == 0: # <<<<<<<<<<<<<< - * components = arr.shape[0] - * rows = arr.shape[1] */ - goto __pyx_L11; + __pyx_t_4 = __Pyx_decode_bytearray(__pyx_v_error_message, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_3 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_3 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_kp_u__5}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_3, 1+__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } + __pyx_v_msg = __pyx_t_7; + __pyx_t_7 = 0; /* "_CharLS.pyx":382 - * columns = arr.shape[2] - * else: - * rows = arr.shape[0] # <<<<<<<<<<<<<< - * columns = arr.shape[1] - * components = arr.shape[2] - */ - /*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_rows = __pyx_t_2; - __pyx_t_2 = 0; - - /* "_CharLS.pyx":383 - * else: - * rows = arr.shape[0] - * columns = arr.shape[1] # <<<<<<<<<<<<<< - * components = arr.shape[2] + * if err != 0: + * msg = error_message.decode("ascii").strip("\0") + * raise RuntimeError(f"Encoding error: {msg}") # <<<<<<<<<<<<<< * + * return dst[:compressed_length] */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_columns = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_msg, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Encoding_error, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 382, __pyx_L1_error) - /* "_CharLS.pyx":384 - * rows = arr.shape[0] - * columns = arr.shape[1] - * components = arr.shape[2] # <<<<<<<<<<<<<< + /* "_CharLS.pyx":380 + * ) * - * cdef JlsParameters info = build_parameters() + * if err != 0: # <<<<<<<<<<<<<< + * msg = error_message.decode("ascii").strip("\0") + * raise RuntimeError(f"Encoding error: {msg}") */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_components = __pyx_t_2; - __pyx_t_2 = 0; - } - __pyx_L11:; } - __pyx_L5:; - /* "_CharLS.pyx":386 - * components = arr.shape[2] + /* "_CharLS.pyx":384 + * raise RuntimeError(f"Encoding error: {msg}") * - * cdef JlsParameters info = build_parameters() # <<<<<<<<<<<<<< - * info.height = rows - * info.width = columns + * return dst[:compressed_length] # <<<<<<<<<<<<<< */ - __pyx_t_11 = __pyx_f_7_CharLS_build_parameters(); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 386, __pyx_L1_error) - __pyx_v_info = __pyx_t_11; + __Pyx_XDECREF(__pyx_r); + __pyx_t_7 = PySequence_GetSlice(__pyx_v_dst, 0, __pyx_v_compressed_length); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_r = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + goto __pyx_L0; - /* "_CharLS.pyx":387 + /* "_CharLS.pyx":288 * - * cdef JlsParameters info = build_parameters() - * info.height = rows # <<<<<<<<<<<<<< - * info.width = columns - * info.components = components if nr_dims == 3 else 1 + * + * def _encode( # <<<<<<<<<<<<<< + * src: bytes, + * lossy_error: int, */ - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_v_rows); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 387, __pyx_L1_error) - __pyx_v_info.height = __pyx_t_12; - /* "_CharLS.pyx":388 - * cdef JlsParameters info = build_parameters() - * info.height = rows - * info.width = columns # <<<<<<<<<<<<<< - * info.components = components if nr_dims == 3 else 1 - * info.interleaveMode = interleave_mode - */ - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_v_columns); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 388, __pyx_L1_error) - __pyx_v_info.width = __pyx_t_12; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_CharLS._encode", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_src_length); + __Pyx_XDECREF(__pyx_v_dst); + __Pyx_XDECREF(__pyx_v_error_message); + __Pyx_XDECREF(__pyx_v_msg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_CharLS.pyx":389 - * info.height = rows - * info.width = columns - * info.components = components if nr_dims == 3 else 1 # <<<<<<<<<<<<<< - * info.interleaveMode = interleave_mode - * info.allowedLossyError = lossy_error - */ - __pyx_t_7 = (__pyx_v_nr_dims == 3); - if (__pyx_t_7) { - if (unlikely(!__pyx_v_components)) { __Pyx_RaiseUnboundLocalError("components"); __PYX_ERR(0, 389, __pyx_L1_error) } - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_v_components); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 389, __pyx_L1_error) - __pyx_t_12 = __pyx_t_13; - } else { - __pyx_t_12 = 1; - } - __pyx_v_info.components = __pyx_t_12; +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ - /* "_CharLS.pyx":390 - * info.width = columns - * info.components = components if nr_dims == 3 else 1 - * info.interleaveMode = interleave_mode # <<<<<<<<<<<<<< - * info.allowedLossyError = lossy_error - * - */ - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_interleave_mode); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 390, __pyx_L1_error) - __pyx_v_info.interleaveMode = ((enum charls::interleave_mode)((int)__pyx_t_10)); +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_Allowed_lossy_error, __pyx_k_Allowed_lossy_error, sizeof(__pyx_k_Allowed_lossy_error), 0, 1, 0, 0}, + {&__pyx_kp_u_Bits_per_sample, __pyx_k_Bits_per_sample, sizeof(__pyx_k_Bits_per_sample), 0, 1, 0, 0}, + {&__pyx_n_s_CharLS, __pyx_k_CharLS, sizeof(__pyx_k_CharLS), 0, 0, 1, 1}, + {&__pyx_kp_u_Decoding_error, __pyx_k_Decoding_error, sizeof(__pyx_k_Decoding_error), 0, 1, 0, 0}, + {&__pyx_n_s_Dict, __pyx_k_Dict, sizeof(__pyx_k_Dict), 0, 0, 1, 1}, + {&__pyx_kp_s_Dict_str_int, __pyx_k_Dict_str_int, sizeof(__pyx_k_Dict_str_int), 0, 0, 1, 0}, + {&__pyx_kp_u_Encoding_error, __pyx_k_Encoding_error, sizeof(__pyx_k_Encoding_error), 0, 1, 0, 0}, + {&__pyx_kp_u_Encoding_paramers_are_Width, __pyx_k_Encoding_paramers_are_Width, sizeof(__pyx_k_Encoding_paramers_are_Width), 0, 1, 0, 0}, + {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1}, + {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, + {&__pyx_kp_u_Stride, __pyx_k_Stride, sizeof(__pyx_k_Stride), 0, 1, 0, 0}, + {&__pyx_n_s__21, __pyx_k__21, sizeof(__pyx_k__21), 0, 0, 1, 1}, + {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0}, + {&__pyx_kp_b__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 0, 0}, + {&__pyx_kp_u__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0, 0}, + {&__pyx_kp_u__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 1, 0, 0}, + {&__pyx_n_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 1}, + {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0}, + {&__pyx_n_u_allowed_lossy_error, __pyx_k_allowed_lossy_error, sizeof(__pyx_k_allowed_lossy_error), 0, 1, 0, 1}, + {&__pyx_n_s_arr, __pyx_k_arr, sizeof(__pyx_k_arr), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_u_bits_per_sample, __pyx_k_bits_per_sample, sizeof(__pyx_k_bits_per_sample), 0, 1, 0, 1}, + {&__pyx_n_s_bits_stored, __pyx_k_bits_stored, sizeof(__pyx_k_bits_stored), 0, 0, 1, 1}, + {&__pyx_n_s_bytearray, __pyx_k_bytearray, sizeof(__pyx_k_bytearray), 0, 0, 1, 1}, + {&__pyx_n_s_bytes, __pyx_k_bytes, sizeof(__pyx_k_bytes), 0, 0, 1, 1}, + {&__pyx_kp_u_bytes_Interleave_mode, __pyx_k_bytes_Interleave_mode, sizeof(__pyx_k_bytes_Interleave_mode), 0, 1, 0, 0}, + {&__pyx_kp_s_bytes_bytearray, __pyx_k_bytes_bytearray, sizeof(__pyx_k_bytes_bytearray), 0, 0, 1, 0}, + {&__pyx_n_s_bytes_per_pixel, __pyx_k_bytes_per_pixel, sizeof(__pyx_k_bytes_per_pixel), 0, 0, 1, 1}, + {&__pyx_n_s_ceil, __pyx_k_ceil, sizeof(__pyx_k_ceil), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_u_colour_transformation, __pyx_k_colour_transformation, sizeof(__pyx_k_colour_transformation), 0, 1, 0, 1}, + {&__pyx_n_s_columns, __pyx_k_columns, sizeof(__pyx_k_columns), 0, 0, 1, 1}, + {&__pyx_n_u_components, __pyx_k_components, sizeof(__pyx_k_components), 0, 1, 0, 1}, + {&__pyx_n_s_compressed_length, __pyx_k_compressed_length, sizeof(__pyx_k_compressed_length), 0, 0, 1, 1}, + {&__pyx_n_s_data_buffer, __pyx_k_data_buffer, sizeof(__pyx_k_data_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, + {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1}, + {&__pyx_n_s_decode_2, __pyx_k_decode_2, sizeof(__pyx_k_decode_2), 0, 0, 1, 1}, + {&__pyx_n_s_decode_from_buffer, __pyx_k_decode_from_buffer, sizeof(__pyx_k_decode_from_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_dst, __pyx_k_dst, sizeof(__pyx_k_dst), 0, 0, 1, 1}, + {&__pyx_n_s_dst_length, __pyx_k_dst_length, sizeof(__pyx_k_dst_length), 0, 0, 1, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error_message, __pyx_k_error_message, sizeof(__pyx_k_error_message), 0, 0, 1, 1}, + {&__pyx_n_s_frombuffer, __pyx_k_frombuffer, sizeof(__pyx_k_frombuffer), 0, 0, 1, 1}, + {&__pyx_n_s_getLogger, __pyx_k_getLogger, sizeof(__pyx_k_getLogger), 0, 0, 1, 1}, + {&__pyx_n_u_height, __pyx_k_height, sizeof(__pyx_k_height), 0, 1, 0, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_int, __pyx_k_int, sizeof(__pyx_k_int), 0, 0, 1, 1}, + {&__pyx_n_s_interleave_mode, __pyx_k_interleave_mode, sizeof(__pyx_k_interleave_mode), 0, 0, 1, 1}, + {&__pyx_n_u_interleave_mode, __pyx_k_interleave_mode, sizeof(__pyx_k_interleave_mode), 0, 1, 0, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_jpeg_ls__CharLS, __pyx_k_jpeg_ls__CharLS, sizeof(__pyx_k_jpeg_ls__CharLS), 0, 1, 0, 0}, + {&__pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_k_jpeg_ls__CharLS_pyx, sizeof(__pyx_k_jpeg_ls__CharLS_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_lossy_error, __pyx_k_lossy_error, sizeof(__pyx_k_lossy_error), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1}, + {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, + {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, + {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, + {&__pyx_kp_u_px_Components, __pyx_k_px_Components, sizeof(__pyx_k_px_Components), 0, 1, 0, 0}, + {&__pyx_kp_u_px_Height, __pyx_k_px_Height, sizeof(__pyx_k_px_Height), 0, 1, 0, 0}, + {&__pyx_n_s_read_header, __pyx_k_read_header, sizeof(__pyx_k_read_header), 0, 0, 1, 1}, + {&__pyx_n_s_reshape, __pyx_k_reshape, sizeof(__pyx_k_reshape), 0, 0, 1, 1}, + {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, + {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1}, + {&__pyx_n_s_samples_per_pixel, __pyx_k_samples_per_pixel, sizeof(__pyx_k_samples_per_pixel), 0, 0, 1, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_n_s_src, __pyx_k_src, sizeof(__pyx_k_src), 0, 0, 1, 1}, + {&__pyx_n_s_src_length, __pyx_k_src_length, sizeof(__pyx_k_src_length), 0, 0, 1, 1}, + {&__pyx_n_u_stride, __pyx_k_stride, sizeof(__pyx_k_stride), 0, 1, 0, 1}, + {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_tobytes, __pyx_k_tobytes, sizeof(__pyx_k_tobytes), 0, 0, 1, 1}, + {&__pyx_n_s_transpose, __pyx_k_transpose, sizeof(__pyx_k_transpose), 0, 0, 1, 1}, + {&__pyx_n_s_typing, __pyx_k_typing, sizeof(__pyx_k_typing), 0, 0, 1, 1}, + {&__pyx_n_u_u, __pyx_k_u, sizeof(__pyx_k_u), 0, 1, 0, 1}, + {&__pyx_n_u_width, __pyx_k_width, sizeof(__pyx_k_width), 0, 1, 0, 1}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 986, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: cached_constants ### */ - /* "_CharLS.pyx":391 - * info.components = components if nr_dims == 3 else 1 - * info.interleaveMode = interleave_mode - * info.allowedLossyError = lossy_error # <<<<<<<<<<<<<< - * - * if nr_dims == 2: - */ - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_v_lossy_error); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 391, __pyx_L1_error) - __pyx_v_info.allowedLossyError = __pyx_t_12; +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "_CharLS.pyx":393 - * info.allowedLossyError = lossy_error + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":986 + * __pyx_import_array() + * except Exception: + * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< * - * if nr_dims == 2: # <<<<<<<<<<<<<< - * info.stride = info.width * bytes_per_pixel - * else: + * cdef inline int import_umath() except -1: */ - __pyx_t_7 = (__pyx_v_nr_dims == 2); - if (__pyx_t_7) { + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 986, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); - /* "_CharLS.pyx":394 + /* "../../../../../tmp/pip-build-env-d9gli68i/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":992 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< * - * if nr_dims == 2: - * info.stride = info.width * bytes_per_pixel # <<<<<<<<<<<<<< - * else: - * if interleave_mode == 0: + * cdef inline int import_ufunc() except -1: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_info.stride = __pyx_t_12; + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 992, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); - /* "_CharLS.pyx":393 - * info.allowedLossyError = lossy_error + /* "_CharLS.pyx":158 + * # Error strings are defined in jpegls_error.cpp + * # As of v2.4.2 the longest string is ~114 chars, so give it a 256 buffer + * err_msg = bytearray(b"\x00" * 256) # <<<<<<<<<<<<<< + * cdef char *error_message = err_msg * - * if nr_dims == 2: # <<<<<<<<<<<<<< - * info.stride = info.width * bytes_per_pixel - * else: */ - goto __pyx_L12; - } + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_b__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); - /* "_CharLS.pyx":396 - * info.stride = info.width * bytes_per_pixel - * else: - * if interleave_mode == 0: # <<<<<<<<<<<<<< - * info.stride = info.width * bytes_per_pixel - * else: + /* "_CharLS.pyx":280 + * # to colour-by-pixel instead + * arr = arr.reshape((samples_per_pixel, rows, columns)) + * return arr.transpose(1, 2, 0) # <<<<<<<<<<<<<< + * + * # Colour-by-pixel, just needs to be reshaped */ - /*else*/ { - __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_interleave_mode, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 396, __pyx_L1_error) - if (__pyx_t_7) { + __pyx_tuple__6 = PyTuple_Pack(3, __pyx_int_1, __pyx_int_2, __pyx_int_0); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); - /* "_CharLS.pyx":397 - * else: - * if interleave_mode == 0: - * info.stride = info.width * bytes_per_pixel # <<<<<<<<<<<<<< - * else: - * info.stride = info.width * bytes_per_pixel * info.components + /* "_CharLS.pyx":11 + * + * + * LOGGER = logging.getLogger("jpeg_ls._CharLS") # <<<<<<<<<<<<<< + * + * */ - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_t_2); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_info.stride = __pyx_t_12; + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_jpeg_ls__CharLS); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); - /* "_CharLS.pyx":396 - * info.stride = info.width * bytes_per_pixel - * else: - * if interleave_mode == 0: # <<<<<<<<<<<<<< - * info.stride = info.width * bytes_per_pixel - * else: + /* "_CharLS.pyx":177 + * + * + * def read_header(src: bytes | bytearray) -> Dict[str, int]: # <<<<<<<<<<<<<< + * """Return a dict containing information about the JPEG-LS file.""" + * # info: JlsParameters */ - goto __pyx_L13; - } + __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_src, __pyx_n_s_info); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_read_header, 177, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 177, __pyx_L1_error) - /* "_CharLS.pyx":399 - * info.stride = info.width * bytes_per_pixel - * else: - * info.stride = info.width * bytes_per_pixel * info.components # <<<<<<<<<<<<<< + /* "_CharLS.pyx":193 + * * + * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream `src` to a bytearray * */ - /*else*/ { - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_info.components); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_t_9); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_info.stride = __pyx_t_12; - } - __pyx_L13:; - } - __pyx_L12:; + __pyx_tuple__13 = PyTuple_Pack(8, __pyx_n_s_src, __pyx_n_s_info, __pyx_n_s_bytes_per_pixel, __pyx_n_s_dst_length, __pyx_n_s_dst, __pyx_n_s_error_message, __pyx_n_s_err, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode, 193, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 193, __pyx_L1_error) - /* "_CharLS.pyx":402 + /* "_CharLS.pyx":237 * * - * bit_depth = math.ceil(math.log(arr.max() + 1, 2)) # <<<<<<<<<<<<<< - * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth + * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_math); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ceil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_math); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_max); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #endif - { - PyObject *__pyx_callargs[2] = {__pyx_t_15, NULL}; - __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_14, __pyx_callargs+1-__pyx_t_10, 0+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __pyx_t_14 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_10 = 1; - } - } - #endif - { - PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_t_14, __pyx_int_2}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __pyx_t_8 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_10 = 1; - } - } - #endif - { - PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_2}; - __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __pyx_v_bit_depth = __pyx_t_9; - __pyx_t_9 = 0; + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_n_s_src); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_from_buffer, 237, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 237, __pyx_L1_error) - /* "_CharLS.pyx":403 + /* "_CharLS.pyx":253 * - * bit_depth = math.ceil(math.log(arr.max() + 1, 2)) - * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth # <<<<<<<<<<<<<< * - * LOGGER.debug( - */ - __pyx_t_9 = PyObject_RichCompare(__pyx_v_bit_depth, __pyx_int_1, Py_LE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 403, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_7) { - __pyx_t_12 = 2; - } else { - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_v_bit_depth); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 403, __pyx_L1_error) - __pyx_t_12 = __pyx_t_13; - } - __pyx_v_info.bitsPerSample = __pyx_t_12; - - /* "_CharLS.pyx":405 - * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth + * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream in the ndarray `data_buffer` * - * LOGGER.debug( # <<<<<<<<<<<<<< - * "Encoding paramers are:\n" - * f"\tWidth: {info.width} px\n" */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_tuple__17 = PyTuple_Pack(8, __pyx_n_s_data_buffer, __pyx_n_s_src, __pyx_n_s_info, __pyx_n_s_bytes_per_pixel, __pyx_n_s_arr, __pyx_n_s_rows, __pyx_n_s_columns, __pyx_n_s_samples_per_pixel); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_2, 253, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 253, __pyx_L1_error) - /* "_CharLS.pyx":406 + /* "_CharLS.pyx":288 * - * LOGGER.debug( - * "Encoding paramers are:\n" # <<<<<<<<<<<<<< - * f"\tWidth: {info.width} px\n" - * f"\tHeight: {info.height} px\n" + * + * def _encode( # <<<<<<<<<<<<<< + * src: bytes, + * lossy_error: int, */ - __pyx_t_1 = PyTuple_New(15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 406, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = 0; - __pyx_t_6 = 127; - __Pyx_INCREF(__pyx_kp_u_Encoding_paramers_are_Width); - __pyx_t_5 += 31; - __Pyx_GIVEREF(__pyx_kp_u_Encoding_paramers_are_Width); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Encoding_paramers_are_Width); + __pyx_tuple__19 = PyTuple_Pack(14, __pyx_n_s_src, __pyx_n_s_lossy_error, __pyx_n_s_interleave_mode, __pyx_n_s_rows, __pyx_n_s_columns, __pyx_n_s_samples_per_pixel, __pyx_n_s_bits_stored, __pyx_n_s_info, __pyx_n_s_src_length, __pyx_n_s_dst, __pyx_n_s_compressed_length, __pyx_n_s_error_message, __pyx_n_s_err, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(7, 0, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode, 288, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 288, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ - /* "_CharLS.pyx":407 - * LOGGER.debug( - * "Encoding paramers are:\n" - * f"\tWidth: {info.width} px\n" # <<<<<<<<<<<<<< - * f"\tHeight: {info.height} px\n" - * f"\tComponents: {info.components}\n" - */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.width, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_px_Height); - __pyx_t_5 += 13; - __Pyx_GIVEREF(__pyx_kp_u_px_Height); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_px_Height); +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ - /* "_CharLS.pyx":408 - * "Encoding paramers are:\n" - * f"\tWidth: {info.width} px\n" - * f"\tHeight: {info.height} px\n" # <<<<<<<<<<<<<< - * f"\tComponents: {info.components}\n" - * f"\tBits per sample: {info.bitsPerSample}\n" +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + /* NumpyImportArray.init */ + /* + * Cython has automatically inserted a call to _import_array since + * you didn't include one when you cimported numpy. To disable this + * add the line + * numpy._import_array */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.height, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_px_Components); - __pyx_t_5 += 17; - __Pyx_GIVEREF(__pyx_kp_u_px_Components); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_px_Components); +#ifdef NPY_FEATURE_VERSION +#ifndef NO_IMPORT_ARRAY +if (unlikely(_import_array() == -1)) { + PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import " + "(auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; " + "use 'numpy._import_array' to disable if you are certain you don't need it)."); +} +#endif +#endif - /* "_CharLS.pyx":409 - * f"\tWidth: {info.width} px\n" - * f"\tHeight: {info.height} px\n" - * f"\tComponents: {info.components}\n" # <<<<<<<<<<<<<< - * f"\tBits per sample: {info.bitsPerSample}\n" - * f"\tStride: {info.stride} bytes\n" - */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.components, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_Bits_per_sample); - __pyx_t_5 += 19; - __Pyx_GIVEREF(__pyx_kp_u_Bits_per_sample); - PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_Bits_per_sample); +if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1, __pyx_L1_error) - /* "_CharLS.pyx":410 - * f"\tHeight: {info.height} px\n" - * f"\tComponents: {info.components}\n" - * f"\tBits per sample: {info.bitsPerSample}\n" # <<<<<<<<<<<<<< - * f"\tStride: {info.stride} bytes\n" - * f"\tInterleave mode: {info.interleaveMode}\n" - */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.bitsPerSample, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_Stride); - __pyx_t_5 += 10; - __Pyx_GIVEREF(__pyx_kp_u_Stride); - PyTuple_SET_ITEM(__pyx_t_1, 8, __pyx_kp_u_Stride); + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_module ### */ - /* "_CharLS.pyx":411 - * f"\tComponents: {info.components}\n" - * f"\tBits per sample: {info.bitsPerSample}\n" - * f"\tStride: {info.stride} bytes\n" # <<<<<<<<<<<<<< - * f"\tInterleave mode: {info.interleaveMode}\n" - * f"\tAllowed lossy error: {info.allowedLossyError}\n" - */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.stride, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 411, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 9, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_bytes_Interleave_mode); - __pyx_t_5 += 25; - __Pyx_GIVEREF(__pyx_kp_u_bytes_Interleave_mode); - PyTuple_SET_ITEM(__pyx_t_1, 10, __pyx_kp_u_bytes_Interleave_mode); +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ - /* "_CharLS.pyx":412 - * f"\tBits per sample: {info.bitsPerSample}\n" - * f"\tStride: {info.stride} bytes\n" - * f"\tInterleave mode: {info.interleaveMode}\n" # <<<<<<<<<<<<<< - * f"\tAllowed lossy error: {info.allowedLossyError}\n" - * ) - */ - __pyx_t_8 = __Pyx_PyUnicode_From_int(((int)__pyx_v_info.interleaveMode), 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 11, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u_Allowed_lossy_error); - __pyx_t_5 += 23; - __Pyx_GIVEREF(__pyx_kp_u_Allowed_lossy_error); - PyTuple_SET_ITEM(__pyx_t_1, 12, __pyx_kp_u_Allowed_lossy_error); +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} - /* "_CharLS.pyx":413 - * f"\tStride: {info.stride} bytes\n" - * f"\tInterleave mode: {info.interleaveMode}\n" - * f"\tAllowed lossy error: {info.allowedLossyError}\n" # <<<<<<<<<<<<<< - * ) - * - */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.allowedLossyError, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 13, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u__9); - __pyx_t_5 += 1; - __Pyx_GIVEREF(__pyx_kp_u__9); - PyTuple_SET_ITEM(__pyx_t_1, 14, __pyx_kp_u__9); +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} - /* "_CharLS.pyx":406 - * - * LOGGER.debug( - * "Encoding paramers are:\n" # <<<<<<<<<<<<<< - * f"\tWidth: {info.width} px\n" - * f"\tHeight: {info.height} px\n" - */ - __pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_1, 15, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 406, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_10 = 1; - } - } +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType_3_0_8(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyTypeObject), + #elif CYTHON_COMPILING_IN_LIMITED_API + sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyTypeObject), + #else + sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyHeapTypeObject), #endif - { - PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_t_8}; - __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_5numpy_dtype = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArray_Descr),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(1, 202, __pyx_L1_error) + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayIterObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(1, 225, __pyx_L1_error) + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayMultiIterObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(1, 229, __pyx_L1_error) + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(1, 238, __pyx_L1_error) + __pyx_ptype_5numpy_generic = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_generic) __PYX_ERR(1, 812, __pyx_L1_error) + __pyx_ptype_5numpy_number = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "number", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_number) __PYX_ERR(1, 814, __pyx_L1_error) + __pyx_ptype_5numpy_integer = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_integer) __PYX_ERR(1, 816, __pyx_L1_error) + __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(1, 818, __pyx_L1_error) + __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(1, 820, __pyx_L1_error) + __pyx_ptype_5numpy_inexact = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(1, 822, __pyx_L1_error) + __pyx_ptype_5numpy_floating = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_floating) __PYX_ERR(1, 824, __pyx_L1_error) + __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(1, 826, __pyx_L1_error) + __pyx_ptype_5numpy_flexible = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(1, 828, __pyx_L1_error) + __pyx_ptype_5numpy_character = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "character", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_character) __PYX_ERR(1, 830, __pyx_L1_error) + __pyx_ptype_5numpy_ufunc = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyUFuncObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(1, 868, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_RefNannyFinishContext(); + return -1; +} - /* "_CharLS.pyx":417 - * - * # Destination for the compressed data - start out twice the length of raw - * dst = bytearray(b"\x00" * src_length * 2) # <<<<<<<<<<<<<< - * - * # Number of bytes of compressed data - */ - __pyx_t_9 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_src_length); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 417, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyInt_MultiplyObjC(__pyx_t_9, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 417, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 417, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dst = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} - /* "_CharLS.pyx":420 - * - * # Number of bytes of compressed data - * cdef size_t compressed_length = 0 # <<<<<<<<<<<<<< - * - * # Error strings are defined in jpegls_error.cpp - */ - __pyx_v_compressed_length = 0; +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} - /* "_CharLS.pyx":424 - * # Error strings are defined in jpegls_error.cpp - * # As of v2.4.2 the longest string is ~114 chars, so give it a 256 buffer - * error_message = bytearray(b"\x00" * 256) # <<<<<<<<<<<<<< - * - * # We need a contiguous buffer in the correct interleave mode (i.e. not - */ - __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_v_error_message = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; - /* "_CharLS.pyx":428 - * # We need a contiguous buffer in the correct interleave mode (i.e. not - * # just a re-view via ndarray.transpose()) - * src = arr.tobytes() # <<<<<<<<<<<<<< - * - * cdef JLS_ERROR err - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_tobytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_10 = 1; - } - } +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec__CharLS(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec__CharLS}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; - __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_10, 0+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_v_src = __pyx_t_9; - __pyx_t_9 = 0; - - /* "_CharLS.pyx":432 - * cdef JLS_ERROR err - * err = JpegLsEncode( - * dst, # <<<<<<<<<<<<<< - * len(dst), - * &compressed_length, - */ - __pyx_t_16 = __Pyx_PyObject_AsWritableString(__pyx_v_dst); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 432, __pyx_L1_error) - - /* "_CharLS.pyx":433 - * err = JpegLsEncode( - * dst, - * len(dst), # <<<<<<<<<<<<<< - * &compressed_length, - * src, - */ - __pyx_t_5 = __Pyx_PyByteArray_GET_SIZE(__pyx_v_dst); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 433, __pyx_L1_error) - - /* "_CharLS.pyx":435 - * len(dst), - * &compressed_length, - * src, # <<<<<<<<<<<<<< - * src_length, - * &info, - */ - __pyx_t_17 = __Pyx_PyObject_AsWritableString(__pyx_v_src); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L1_error) - - /* "_CharLS.pyx":436 - * &compressed_length, - * src, - * src_length, # <<<<<<<<<<<<<< - * &info, - * error_message - */ - __pyx_t_18 = __Pyx_PyInt_As_size_t(__pyx_v_src_length); if (unlikely((__pyx_t_18 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 436, __pyx_L1_error) - - /* "_CharLS.pyx":438 - * src_length, - * &info, - * error_message # <<<<<<<<<<<<<< - * ) - * - */ - __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_error_message); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error) + PyModuleDef_HEAD_INIT, + "_CharLS", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif - /* "_CharLS.pyx":431 - * - * cdef JLS_ERROR err - * err = JpegLsEncode( # <<<<<<<<<<<<<< - * dst, - * len(dst), - */ - __pyx_v_err = JpegLsEncode(((char *)__pyx_t_16), __pyx_t_5, (&__pyx_v_compressed_length), ((char *)__pyx_t_17), __pyx_t_18, (&__pyx_v_info), ((char *)__pyx_t_19)); +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif - /* "_CharLS.pyx":441 - * ) - * - * if err != 0: # <<<<<<<<<<<<<< - * msg = error_message.decode("ascii").strip("\0") - * raise RuntimeError(f"Encoding error: {msg}") - */ - __pyx_t_7 = (((int)__pyx_v_err) != 0); - if (unlikely(__pyx_t_7)) { - /* "_CharLS.pyx":442 - * - * if err != 0: - * msg = error_message.decode("ascii").strip("\0") # <<<<<<<<<<<<<< - * raise RuntimeError(f"Encoding error: {msg}") - * - */ - __pyx_t_2 = __Pyx_decode_bytearray(__pyx_v_error_message, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_strip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_10 = 0; - #if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_10 = 1; - } - } +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC init_CharLS(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC init_CharLS(void) +#else +__Pyx_PyMODINIT_FUNC PyInit__CharLS(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit__CharLS(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_u__5}; - __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; } - __pyx_v_msg = __pyx_t_9; - __pyx_t_9 = 0; - - /* "_CharLS.pyx":443 - * if err != 0: - * msg = error_message.decode("ascii").strip("\0") - * raise RuntimeError(f"Encoding error: {msg}") # <<<<<<<<<<<<<< - * - * return dst[:compressed_length] - */ - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_msg, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Encoding_error, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_Raise(__pyx_t_9, 0, 0, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 443, __pyx_L1_error) - - /* "_CharLS.pyx":441 - * ) - * - * if err != 0: # <<<<<<<<<<<<<< - * msg = error_message.decode("ascii").strip("\0") - * raise RuntimeError(f"Encoding error: {msg}") - */ - } - - /* "_CharLS.pyx":445 - * raise RuntimeError(f"Encoding error: {msg}") - * - * return dst[:compressed_length] # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_9 = PySequence_GetSlice(__pyx_v_dst, 0, __pyx_v_compressed_length); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_r = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; - goto __pyx_L0; - - /* "_CharLS.pyx":334 - * - * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_AddTraceback("_CharLS._encode_array", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bytes_per_pixel); - __Pyx_XDECREF(__pyx_v_src_length); - __Pyx_XDECREF(__pyx_v_rows); - __Pyx_XDECREF(__pyx_v_columns); - __Pyx_XDECREF(__pyx_v_components); - __Pyx_XDECREF(__pyx_v_bit_depth); - __Pyx_XDECREF(__pyx_v_dst); - __Pyx_XDECREF(__pyx_v_error_message); - __Pyx_XDECREF(__pyx_v_src); - __Pyx_XDECREF(__pyx_v_msg); - __Pyx_XDECREF(__pyx_v_interleave_mode); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - -static PyObject *__pyx_pf_7_CharLS_18__defaults__(CYTHON_UNUSED PyObject *__pyx_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__defaults__", 1); - __Pyx_XDECREF(__pyx_r); - - /* "_CharLS.pyx":451 - * arr: np.ndarray, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> np.ndarray: - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__Pyx_CyFunction_Defaults(__pyx_defaults2, __pyx_self)->__pyx_arg_lossy_error); - __Pyx_GIVEREF(__Pyx_CyFunction_Defaults(__pyx_defaults2, __pyx_self)->__pyx_arg_lossy_error); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __Pyx_CyFunction_Defaults(__pyx_defaults2, __pyx_self)->__pyx_arg_lossy_error)) __PYX_ERR(0, 448, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None)) __PYX_ERR(0, 448, __pyx_L1_error); - - /* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1)) __PYX_ERR(0, 448, __pyx_L1_error); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, Py_None)) __PYX_ERR(0, 448, __pyx_L1_error); - __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_CharLS.__defaults__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; + return 0; } - -/* Python wrapper */ -static PyObject *__pyx_pw_7_CharLS_13encode(PyObject *__pyx_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -); /*proto*/ -PyDoc_STRVAR(__pyx_doc_7_CharLS_12encode, "Return the image data in `arr` as a JPEG-LS encoded 1D ndarray."); -static PyMethodDef __pyx_mdef_7_CharLS_13encode = {"encode", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_13encode, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_12encode}; -static PyObject *__pyx_pw_7_CharLS_13encode(PyObject *__pyx_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) #else -PyObject *__pyx_args, PyObject *__pyx_kwds +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); #endif -) { - PyObject *__pyx_v_arr = 0; - PyObject *__pyx_v_lossy_error = 0; - PyObject *__pyx_v_interleave_mode = 0; - #if !CYTHON_METH_FASTCALL - CYTHON_UNUSED Py_ssize_t __pyx_nargs; - #endif - CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject* values[3] = {0,0,0}; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("encode (wrapper)", 0); - #if !CYTHON_METH_FASTCALL - #if CYTHON_ASSUME_SAFE_MACROS - __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); - #else - __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; - #endif - #endif - __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); - { - PyObject **__pyx_pyargnames[] = {&__pyx_n_s_arr,&__pyx_n_s_lossy_error,&__pyx_n_s_interleave_mode,0}; - __pyx_defaults2 *__pyx_dynamic_args = __Pyx_CyFunction_Defaults(__pyx_defaults2, __pyx_self); - values[1] = __Pyx_Arg_NewRef_FASTCALL(__pyx_dynamic_args->__pyx_arg_lossy_error); - - /* "_CharLS.pyx":451 - * arr: np.ndarray, - * lossy_error: int = 0, - * interleave_mode: int | None = None, # <<<<<<<<<<<<<< - * ) -> np.ndarray: - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - */ - values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None)); - if (__pyx_kwds) { - Py_ssize_t kw_args; - switch (__pyx_nargs) { - case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); - switch (__pyx_nargs) { - case 0: - if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_arr)) != 0)) { - (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); - kw_args--; - } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 448, __pyx_L3_error) - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lossy_error); - if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 448, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_interleave_mode); - if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 448, __pyx_L3_error) } - } - if (unlikely(kw_args > 0)) { - const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "encode") < 0)) __PYX_ERR(0, 448, __pyx_L3_error) - } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); } else { - switch (__pyx_nargs) { - case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_arr = values[0]; - __pyx_v_lossy_error = ((PyObject*)values[1]); - __pyx_v_interleave_mode = values[2]; - } - goto __pyx_L6_skip; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("encode", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 448, __pyx_L3_error) - __pyx_L6_skip:; - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - { - Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); - } - } - __Pyx_AddTraceback("_CharLS.encode", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lossy_error), (&PyInt_Type), 0, "lossy_error", 1))) __PYX_ERR(0, 450, __pyx_L1_error) - __pyx_r = __pyx_pf_7_CharLS_12encode(__pyx_self, __pyx_v_arr, __pyx_v_lossy_error, __pyx_v_interleave_mode); - - /* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - { - Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + result = -1; } - } - __Pyx_RefNannyFinishContext(); - return __pyx_r; + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; } -static PyObject *__pyx_pf_7_CharLS_12encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave_mode) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations + +static CYTHON_SMALL_CODE int __pyx_pymod_exec__CharLS(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("encode", 1); - - /* "_CharLS.pyx":454 - * ) -> np.ndarray: - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer( # <<<<<<<<<<<<<< - * encode_to_buffer(arr, lossy_error, interleave_mode), - * dtype="u1", - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "_CharLS.pyx":455 - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer( - * encode_to_buffer(arr, lossy_error, interleave_mode), # <<<<<<<<<<<<<< - * dtype="u1", - * ) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_encode_to_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; - } + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module '_CharLS' has already been imported. Re-initialisation is not supported."); + return -1; } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("_CharLS", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) { - PyObject *__pyx_callargs[4] = {__pyx_t_4, __pyx_v_arr, __pyx_v_lossy_error, __pyx_v_interleave_mode}; - __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 3+__pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "_CharLS" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; } - - /* "_CharLS.pyx":454 - * ) -> np.ndarray: - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer( # <<<<<<<<<<<<<< - * encode_to_buffer(arr, lossy_error, interleave_mode), - * dtype="u1", - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1)) __PYX_ERR(0, 454, __pyx_L1_error); - __pyx_t_1 = 0; - - /* "_CharLS.pyx":456 - * return np.frombuffer( - * encode_to_buffer(arr, lossy_error, interleave_mode), - * dtype="u1", # <<<<<<<<<<<<<< - * ) - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_n_u_u1) < 0) __PYX_ERR(0, 456, __pyx_L1_error) - - /* "_CharLS.pyx":454 - * ) -> np.ndarray: - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer( # <<<<<<<<<<<<<< - * encode_to_buffer(arr, lossy_error, interleave_mode), - * dtype="u1", - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - - /* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_CharLS.encode", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); } - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - #define CYTHON_SMALL_CODE __attribute__((cold)) -#else - #define CYTHON_SMALL_CODE -#endif #endif -/* #### Code section: pystring_table ### */ - -static int __Pyx_CreateStringTabAndInitStrings(void) { - __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_Allowed_lossy_error, __pyx_k_Allowed_lossy_error, sizeof(__pyx_k_Allowed_lossy_error), 0, 1, 0, 0}, - {&__pyx_kp_u_Bits_per_sample, __pyx_k_Bits_per_sample, sizeof(__pyx_k_Bits_per_sample), 0, 1, 0, 0}, - {&__pyx_n_s_CharLS, __pyx_k_CharLS, sizeof(__pyx_k_CharLS), 0, 0, 1, 1}, - {&__pyx_kp_u_Decoding_error, __pyx_k_Decoding_error, sizeof(__pyx_k_Decoding_error), 0, 1, 0, 0}, - {&__pyx_n_s_Dict, __pyx_k_Dict, sizeof(__pyx_k_Dict), 0, 0, 1, 1}, - {&__pyx_kp_s_Dict_str_int, __pyx_k_Dict_str_int, sizeof(__pyx_k_Dict_str_int), 0, 0, 1, 0}, - {&__pyx_kp_u_Encoding_error, __pyx_k_Encoding_error, sizeof(__pyx_k_Encoding_error), 0, 1, 0, 0}, - {&__pyx_kp_u_Encoding_paramers_are_Width, __pyx_k_Encoding_paramers_are_Width, sizeof(__pyx_k_Encoding_paramers_are_Width), 0, 1, 0, 0}, - {&__pyx_kp_u_Encoding_src_is, __pyx_k_Encoding_src_is, sizeof(__pyx_k_Encoding_src_is), 0, 1, 0, 0}, - {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1}, - {&__pyx_kp_u_Invalid_data_shape, __pyx_k_Invalid_data_shape, sizeof(__pyx_k_Invalid_data_shape), 0, 1, 0, 0}, - {&__pyx_kp_u_Invalid_input_data_type, __pyx_k_Invalid_input_data_type, sizeof(__pyx_k_Invalid_input_data_type), 0, 1, 0, 0}, - {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, - {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, - {&__pyx_kp_u_Stride, __pyx_k_Stride, sizeof(__pyx_k_Stride), 0, 1, 0, 0}, - {&__pyx_kp_u_Unable_to_automatically_determin, __pyx_k_Unable_to_automatically_determin, sizeof(__pyx_k_Unable_to_automatically_determin), 0, 1, 0, 0}, - {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_n_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 1}, - {&__pyx_kp_u__11, __pyx_k__11, sizeof(__pyx_k__11), 0, 1, 0, 0}, - {&__pyx_n_s__27, __pyx_k__27, sizeof(__pyx_k__27), 0, 0, 1, 1}, - {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0}, - {&__pyx_kp_b__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 0, 0}, - {&__pyx_kp_u__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0, 0}, - {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0}, - {&__pyx_n_u_allowed_lossy_error, __pyx_k_allowed_lossy_error, sizeof(__pyx_k_allowed_lossy_error), 0, 1, 0, 1}, - {&__pyx_n_s_arr, __pyx_k_arr, sizeof(__pyx_k_arr), 0, 0, 1, 1}, - {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, - {&__pyx_n_s_bit_depth, __pyx_k_bit_depth, sizeof(__pyx_k_bit_depth), 0, 0, 1, 1}, - {&__pyx_n_u_bits_per_sample, __pyx_k_bits_per_sample, sizeof(__pyx_k_bits_per_sample), 0, 1, 0, 1}, - {&__pyx_n_s_bytearray, __pyx_k_bytearray, sizeof(__pyx_k_bytearray), 0, 0, 1, 1}, - {&__pyx_kp_u_bytes_Interleave_mode, __pyx_k_bytes_Interleave_mode, sizeof(__pyx_k_bytes_Interleave_mode), 0, 1, 0, 0}, - {&__pyx_kp_s_bytes_bytearray, __pyx_k_bytes_bytearray, sizeof(__pyx_k_bytes_bytearray), 0, 0, 1, 0}, - {&__pyx_kp_u_bytes_per_pixel, __pyx_k_bytes_per_pixel, sizeof(__pyx_k_bytes_per_pixel), 0, 1, 0, 0}, - {&__pyx_n_s_bytes_per_pixel_2, __pyx_k_bytes_per_pixel_2, sizeof(__pyx_k_bytes_per_pixel_2), 0, 0, 1, 1}, - {&__pyx_kp_u_bytes_shaped_as, __pyx_k_bytes_shaped_as, sizeof(__pyx_k_bytes_shaped_as), 0, 1, 0, 0}, - {&__pyx_n_s_ceil, __pyx_k_ceil, sizeof(__pyx_k_ceil), 0, 0, 1, 1}, - {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, - {&__pyx_n_u_colour_transformation, __pyx_k_colour_transformation, sizeof(__pyx_k_colour_transformation), 0, 1, 0, 1}, - {&__pyx_n_s_columns, __pyx_k_columns, sizeof(__pyx_k_columns), 0, 0, 1, 1}, - {&__pyx_n_s_components, __pyx_k_components, sizeof(__pyx_k_components), 0, 0, 1, 1}, - {&__pyx_n_u_components, __pyx_k_components, sizeof(__pyx_k_components), 0, 1, 0, 1}, - {&__pyx_n_s_compressed_length, __pyx_k_compressed_length, sizeof(__pyx_k_compressed_length), 0, 0, 1, 1}, - {&__pyx_n_s_data_buffer, __pyx_k_data_buffer, sizeof(__pyx_k_data_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, - {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1}, - {&__pyx_n_s_decode_2, __pyx_k_decode_2, sizeof(__pyx_k_decode_2), 0, 0, 1, 1}, - {&__pyx_n_s_decode_from_buffer, __pyx_k_decode_from_buffer, sizeof(__pyx_k_decode_from_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_dst, __pyx_k_dst, sizeof(__pyx_k_dst), 0, 0, 1, 1}, - {&__pyx_n_s_dst_length, __pyx_k_dst_length, sizeof(__pyx_k_dst_length), 0, 0, 1, 1}, - {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, - {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, - {&__pyx_n_s_encode_array, __pyx_k_encode_array, sizeof(__pyx_k_encode_array), 0, 0, 1, 1}, - {&__pyx_n_s_encode_to_buffer, __pyx_k_encode_to_buffer, sizeof(__pyx_k_encode_to_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, - {&__pyx_n_s_error_message, __pyx_k_error_message, sizeof(__pyx_k_error_message), 0, 0, 1, 1}, - {&__pyx_kp_u_expecting_np_uint8_or_np_uint16, __pyx_k_expecting_np_uint8_or_np_uint16, sizeof(__pyx_k_expecting_np_uint8_or_np_uint16), 0, 1, 0, 0}, - {&__pyx_n_s_frombuffer, __pyx_k_frombuffer, sizeof(__pyx_k_frombuffer), 0, 0, 1, 1}, - {&__pyx_n_s_getLogger, __pyx_k_getLogger, sizeof(__pyx_k_getLogger), 0, 0, 1, 1}, - {&__pyx_n_u_height, __pyx_k_height, sizeof(__pyx_k_height), 0, 1, 0, 1}, - {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, - {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1}, - {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, - {&__pyx_n_s_int, __pyx_k_int, sizeof(__pyx_k_int), 0, 0, 1, 1}, - {&__pyx_kp_s_int_None, __pyx_k_int_None, sizeof(__pyx_k_int_None), 0, 0, 1, 0}, - {&__pyx_n_s_interleave_mode, __pyx_k_interleave_mode, sizeof(__pyx_k_interleave_mode), 0, 0, 1, 1}, - {&__pyx_n_u_interleave_mode, __pyx_k_interleave_mode, sizeof(__pyx_k_interleave_mode), 0, 1, 0, 1}, - {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, - {&__pyx_kp_u_jpeg_ls__CharLS, __pyx_k_jpeg_ls__CharLS, sizeof(__pyx_k_jpeg_ls__CharLS), 0, 1, 0, 0}, - {&__pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_k_jpeg_ls__CharLS_pyx, sizeof(__pyx_k_jpeg_ls__CharLS_pyx), 0, 0, 1, 0}, - {&__pyx_n_s_log, __pyx_k_log, sizeof(__pyx_k_log), 0, 0, 1, 1}, - {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, - {&__pyx_n_s_lossy_error, __pyx_k_lossy_error, sizeof(__pyx_k_lossy_error), 0, 0, 1, 1}, - {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, - {&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1}, - {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, - {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1}, - {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, - {&__pyx_n_s_ndarray, __pyx_k_ndarray, sizeof(__pyx_k_ndarray), 0, 0, 1, 1}, - {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, - {&__pyx_kp_s_np_ndarray, __pyx_k_np_ndarray, sizeof(__pyx_k_np_ndarray), 0, 0, 1, 0}, - {&__pyx_kp_s_np_ndarray_bytes, __pyx_k_np_ndarray_bytes, sizeof(__pyx_k_np_ndarray_bytes), 0, 0, 1, 0}, - {&__pyx_n_s_nr_dims, __pyx_k_nr_dims, sizeof(__pyx_k_nr_dims), 0, 0, 1, 1}, - {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, - {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, - {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, - {&__pyx_kp_u_px_Components, __pyx_k_px_Components, sizeof(__pyx_k_px_Components), 0, 1, 0, 0}, - {&__pyx_kp_u_px_Height, __pyx_k_px_Height, sizeof(__pyx_k_px_Height), 0, 1, 0, 0}, - {&__pyx_n_s_read_header, __pyx_k_read_header, sizeof(__pyx_k_read_header), 0, 0, 1, 1}, - {&__pyx_n_s_reshape, __pyx_k_reshape, sizeof(__pyx_k_reshape), 0, 0, 1, 1}, - {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, - {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1}, - {&__pyx_n_s_samples_per_pixel, __pyx_k_samples_per_pixel, sizeof(__pyx_k_samples_per_pixel), 0, 0, 1, 1}, - {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, - {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, - {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, - {&__pyx_n_s_src, __pyx_k_src, sizeof(__pyx_k_src), 0, 0, 1, 1}, - {&__pyx_n_s_src_length, __pyx_k_src_length, sizeof(__pyx_k_src_length), 0, 0, 1, 1}, - {&__pyx_n_u_stride, __pyx_k_stride, sizeof(__pyx_k_stride), 0, 1, 0, 1}, - {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1}, - {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, - {&__pyx_n_s_tobytes, __pyx_k_tobytes, sizeof(__pyx_k_tobytes), 0, 0, 1, 1}, - {&__pyx_n_s_transpose, __pyx_k_transpose, sizeof(__pyx_k_transpose), 0, 0, 1, 1}, - {&__pyx_kp_s_tuple_bytearray_dict_str_int, __pyx_k_tuple_bytearray_dict_str_int, sizeof(__pyx_k_tuple_bytearray_dict_str_int), 0, 0, 1, 0}, - {&__pyx_n_s_typing, __pyx_k_typing, sizeof(__pyx_k_typing), 0, 0, 1, 1}, - {&__pyx_n_u_u, __pyx_k_u, sizeof(__pyx_k_u), 0, 1, 0, 1}, - {&__pyx_n_u_u1, __pyx_k_u1, sizeof(__pyx_k_u1), 0, 1, 0, 1}, - {&__pyx_n_s_uint16, __pyx_k_uint16, sizeof(__pyx_k_uint16), 0, 0, 1, 1}, - {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1}, - {&__pyx_n_u_width, __pyx_k_width, sizeof(__pyx_k_width), 0, 1, 0, 1}, - {&__pyx_kp_u_with, __pyx_k_with, sizeof(__pyx_k_with), 0, 1, 0, 0}, - {0, 0, 0, 0, 0, 0, 0} - }; - return __Pyx_InitStrings(__pyx_string_tab); -} -/* #### Code section: cached_builtins ### */ -static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 172, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 344, __pyx_L1_error) - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 984, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} -/* #### Code section: cached_constants ### */ - -static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__CharLS(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main__CharLS) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "_CharLS")) { + if (unlikely((PyDict_SetItemString(modules, "_CharLS", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + (void)__Pyx_modinit_type_init_code(); + if (unlikely((__Pyx_modinit_type_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":984 - * __pyx_import_array() - * except Exception: - * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< + /* "_CharLS.pyx":3 + * # cython: language_level=3 * - * cdef inline int import_umath() except -1: + * import logging # <<<<<<<<<<<<<< + * import math + * from typing import Dict */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple_); - __Pyx_GIVEREF(__pyx_tuple_); + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":990 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + /* "_CharLS.pyx":4 * - * cdef inline int import_ufunc() except -1: - */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - - /* "_CharLS.pyx":158 - * # Error strings are defined in jpegls_error.cpp - * # As of v2.4.2 the longest string is ~114 chars, so give it a 256 buffer - * err_msg = bytearray(b"\x00" * 256) # <<<<<<<<<<<<<< - * cdef char *error_message = err_msg + * import logging + * import math # <<<<<<<<<<<<<< + * from typing import Dict * */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_b__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_math, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_math, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "_CharLS.pyx":280 - * # to colour-by-pixel instead - * arr = arr.reshape((samples_per_pixel, rows, columns)) - * return arr.transpose(1, 2, 0) # <<<<<<<<<<<<<< + /* "_CharLS.pyx":5 + * import logging + * import math + * from typing import Dict # <<<<<<<<<<<<<< * - * # Colour-by-pixel, just needs to be reshaped + * import numpy as np */ - __pyx_tuple__6 = PyTuple_Pack(3, __pyx_int_1, __pyx_int_2, __pyx_int_0); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_Dict); + __Pyx_GIVEREF(__pyx_n_s_Dict); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Dict)) __PYX_ERR(0, 5, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_typing, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_Dict, __pyx_t_2) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":351 - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): - * raise ValueError("Invalid data shape") # <<<<<<<<<<<<<< + /* "_CharLS.pyx":7 + * from typing import Dict + * + * import numpy as np # <<<<<<<<<<<<<< + * cimport numpy as cnp * - * LOGGER.debug( - */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_Invalid_data_shape); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); - - /* "_CharLS.pyx":372 - * interleave_mode = 0 if interleave_mode is None else interleave_mode - * elif interleave_mode is None: - * raise ValueError( # <<<<<<<<<<<<<< - * "Unable to automatically determine an appropriate 'interleave_mode' " - * "value, please set it manually" */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_u_Unable_to_automatically_determin); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_t_3 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_3) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_CharLS.pyx":11 * @@ -9339,9 +8169,16 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { * * */ - __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_u_jpeg_ls__CharLS); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_logging); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_3) < 0) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_CharLS.pyx":177 * @@ -9350,10 +8187,16 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { * """Return a dict containing information about the JPEG-LS file.""" * # info: JlsParameters */ - __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_src, __pyx_n_s_info); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); - __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_read_header, 177, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 177, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 177, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_kp_s_Dict_str_int) < 0) __PYX_ERR(0, 177, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_1read_header, 0, __pyx_n_s_read_header, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_header, __pyx_t_2) < 0) __PYX_ERR(0, 177, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "_CharLS.pyx":193 * @@ -9362,22 +8205,34 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __pyx_tuple__15 = PyTuple_Pack(8, __pyx_n_s_src, __pyx_n_s_info, __pyx_n_s_bytes_per_pixel_2, __pyx_n_s_dst_length, __pyx_n_s_dst, __pyx_n_s_error_message, __pyx_n_s_err, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); - __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode, 193, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 193, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 193, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 193, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_3_decode, 0, __pyx_n_s_decode, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode, __pyx_t_3) < 0) __PYX_ERR(0, 193, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __pyx_tuple__17 = PyTuple_Pack(1, __pyx_n_s_src); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); - __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_from_buffer, 237, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 237, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 237, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 237, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_5decode_from_buffer, 0, __pyx_n_s_decode_from_buffer, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode_from_buffer, __pyx_t_2) < 0) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "_CharLS.pyx":253 * @@ -9386,968 +8241,285 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { * """Decode the JPEG-LS codestream in the ndarray `data_buffer` * */ - __pyx_tuple__19 = PyTuple_Pack(8, __pyx_n_s_data_buffer, __pyx_n_s_src, __pyx_n_s_info, __pyx_n_s_bytes_per_pixel_2, __pyx_n_s_arr, __pyx_n_s_rows, __pyx_n_s_columns, __pyx_n_s_samples_per_pixel); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); - __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_2, 253, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 253, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_7decode, 0, __pyx_n_s_decode_2, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode_2, __pyx_t_2) < 0) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "_CharLS.pyx":288 * * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, + * def _encode( # <<<<<<<<<<<<<< + * src: bytes, + * lossy_error: int, */ - __pyx_tuple__21 = PyTuple_Pack(3, __pyx_n_s_src, __pyx_n_s_lossy_error, __pyx_n_s_interleave_mode); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode_to_buffer, 288, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(0, 288, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_src, __pyx_n_s_bytes) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_lossy_error, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_interleave_mode, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_rows, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_columns, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_samples_per_pixel, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_bits_stored, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_9_encode, 0, __pyx_n_s_encode, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_encode, __pyx_t_3) < 0) __PYX_ERR(0, 288, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":334 - * + /* "_CharLS.pyx":1 + * # cython: language_level=3 # <<<<<<<<<<<<<< * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, + * import logging */ - __pyx_tuple__23 = PyTuple_Pack(17, __pyx_n_s_arr, __pyx_n_s_lossy_error, __pyx_n_s_interleave_mode, __pyx_n_s_bytes_per_pixel_2, __pyx_n_s_src_length, __pyx_n_s_nr_dims, __pyx_n_s_rows, __pyx_n_s_columns, __pyx_n_s_components, __pyx_n_s_info, __pyx_n_s_bit_depth, __pyx_n_s_dst, __pyx_n_s_compressed_length, __pyx_n_s_error_message, __pyx_n_s_src, __pyx_n_s_err, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode_array, 334, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 334, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - __pyx_tuple__25 = PyTuple_Pack(3, __pyx_n_s_arr, __pyx_n_s_lossy_error, __pyx_n_s_interleave_mode); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); - __pyx_codeobj__26 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__25, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode, 448, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__26)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} -/* #### Code section: init_constants ### */ + /*--- Wrapped vars code ---*/ -static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { - if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error) - return 0; + goto __pyx_L0; __pyx_L1_error:; - return -1; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init _CharLS", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init _CharLS"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif } -/* #### Code section: init_globals ### */ - -static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - /* NumpyImportArray.init */ - /* - * Cython has automatically inserted a call to _import_array since - * you didn't include one when you cimported numpy. To disable this - * add the line - * numpy._import_array +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful */ -#ifdef NPY_FEATURE_VERSION -#ifndef NO_IMPORT_ARRAY -if (unlikely(_import_array() == -1)) { - PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import " - "(auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; " - "use 'numpy._import_array' to disable if you are certain you don't need it)."); -} -#endif +#pragma warning( disable : 4127 ) #endif -if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} -/* #### Code section: init_module ### */ -static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ +/* #### Code section: utility_code_def ### */ -static int __Pyx_modinit_global_init_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); - /*--- Global init code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; } +#endif -static int __Pyx_modinit_variable_export_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); - /*--- Variable export code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; } +#endif -static int __Pyx_modinit_type_init_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); - /*--- Type init code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif } - -static int __Pyx_modinit_type_import_code(void) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); - /*--- Type import code ---*/ - __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType_3_0_8(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", - #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyTypeObject), - #elif CYTHON_COMPILING_IN_LIMITED_API - sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyTypeObject), - #else - sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyHeapTypeObject), - #endif - __Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_5numpy_dtype = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArray_Descr),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(1, 202, __pyx_L1_error) - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayIterObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(1, 225, __pyx_L1_error) - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayMultiIterObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(1, 229, __pyx_L1_error) - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyArrayObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(1, 238, __pyx_L1_error) - __pyx_ptype_5numpy_generic = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_generic) __PYX_ERR(1, 809, __pyx_L1_error) - __pyx_ptype_5numpy_number = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "number", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_number) __PYX_ERR(1, 811, __pyx_L1_error) - __pyx_ptype_5numpy_integer = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_integer) __PYX_ERR(1, 813, __pyx_L1_error) - __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(1, 815, __pyx_L1_error) - __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(1, 817, __pyx_L1_error) - __pyx_ptype_5numpy_inexact = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(1, 819, __pyx_L1_error) - __pyx_ptype_5numpy_floating = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_floating) __PYX_ERR(1, 821, __pyx_L1_error) - __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(1, 823, __pyx_L1_error) - __pyx_ptype_5numpy_flexible = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(1, 825, __pyx_L1_error) - __pyx_ptype_5numpy_character = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "character", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyObject),__Pyx_ImportType_CheckSize_Warn_3_0_8); if (!__pyx_ptype_5numpy_character) __PYX_ERR(1, 827, __pyx_L1_error) - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType_3_0_8(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_8(PyUFuncObject),__Pyx_ImportType_CheckSize_Ignore_3_0_8); if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(1, 866, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_modinit_variable_import_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); - /*--- Variable import code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; -} - -static int __Pyx_modinit_function_import_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); - /*--- Function import code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif } - - -#if PY_MAJOR_VERSION >= 3 -#if CYTHON_PEP489_MULTI_PHASE_INIT -static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ -static int __pyx_pymod_exec__CharLS(PyObject* module); /*proto*/ -static PyModuleDef_Slot __pyx_moduledef_slots[] = { - {Py_mod_create, (void*)__pyx_pymod_create}, - {Py_mod_exec, (void*)__pyx_pymod_exec__CharLS}, - {0, NULL} -}; #endif -#ifdef __cplusplus -namespace { - struct PyModuleDef __pyx_moduledef = - #else - static struct PyModuleDef __pyx_moduledef = - #endif - { - PyModuleDef_HEAD_INIT, - "_CharLS", - 0, /* m_doc */ - #if CYTHON_PEP489_MULTI_PHASE_INIT - 0, /* m_size */ - #elif CYTHON_USE_MODULE_STATE - sizeof(__pyx_mstate), /* m_size */ - #else - -1, /* m_size */ - #endif - __pyx_methods /* m_methods */, - #if CYTHON_PEP489_MULTI_PHASE_INIT - __pyx_moduledef_slots, /* m_slots */ - #else - NULL, /* m_reload */ - #endif - #if CYTHON_USE_MODULE_STATE - __pyx_m_traverse, /* m_traverse */ - __pyx_m_clear, /* m_clear */ - NULL /* m_free */ - #else - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ - #endif - }; - #ifdef __cplusplus -} /* anonymous namespace */ +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif + return PyObject_GetAttr(obj, attr_name); +} #endif -#ifndef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#elif PY_MAJOR_VERSION < 3 -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" void -#else -#define __Pyx_PyMODINIT_FUNC void +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} #endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; #else -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * -#else -#define __Pyx_PyMODINIT_FUNC PyObject * +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } #endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; #endif +} - -#if PY_MAJOR_VERSION < 3 -__Pyx_PyMODINIT_FUNC init_CharLS(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC init_CharLS(void) +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); #else -__Pyx_PyMODINIT_FUNC PyInit__CharLS(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC PyInit__CharLS(void) -#if CYTHON_PEP489_MULTI_PHASE_INIT -{ - return PyModuleDef_Init(&__pyx_moduledef); -} -static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { - #if PY_VERSION_HEX >= 0x030700A1 - static PY_INT64_T main_interpreter_id = -1; - PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); - if (main_interpreter_id == -1) { - main_interpreter_id = current_id; - return (unlikely(current_id == -1)) ? -1 : 0; - } else if (unlikely(main_interpreter_id != current_id)) - #else - static PyInterpreterState *main_interpreter = NULL; - PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; - if (!main_interpreter) { - main_interpreter = current_interpreter; - } else if (unlikely(main_interpreter != current_interpreter)) - #endif - { - PyErr_SetString( - PyExc_ImportError, - "Interpreter change detected - this module can only be loaded into one interpreter per process."); - return -1; + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif } - return 0; + return result; } -#if CYTHON_COMPILING_IN_LIMITED_API -static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) -#else -static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) -#endif + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) { - PyObject *value = PyObject_GetAttrString(spec, from_name); - int result = 0; - if (likely(value)) { - if (allow_none || value != Py_None) { -#if CYTHON_COMPILING_IN_LIMITED_API - result = PyModule_AddObject(module, to_name, value); -#else - result = PyDict_SetItemString(moddict, to_name, value); -#endif - } - Py_DECREF(value); - } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - result = -1; + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; } - return result; -} -static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { - PyObject *module = NULL, *moddict, *modname; - CYTHON_UNUSED_VAR(def); - if (__Pyx_check_single_interpreter()) - return NULL; - if (__pyx_m) - return __Pyx_NewRef(__pyx_m); - modname = PyObject_GetAttrString(spec, "name"); - if (unlikely(!modname)) goto bad; - module = PyModule_NewObject(modname); - Py_DECREF(modname); - if (unlikely(!module)) goto bad; -#if CYTHON_COMPILING_IN_LIMITED_API - moddict = module; -#else - moddict = PyModule_GetDict(module); - if (unlikely(!moddict)) goto bad; -#endif - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; - return module; -bad: - Py_XDECREF(module); - return NULL; -} - - -static CYTHON_SMALL_CODE int __pyx_pymod_exec__CharLS(PyObject *__pyx_pyinit_module) -#endif -#endif -{ - int stringtab_initialized = 0; - #if CYTHON_USE_MODULE_STATE - int pystate_addmodule_run = 0; - #endif - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannyDeclarations - #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m) { - if (__pyx_m == __pyx_pyinit_module) return 0; - PyErr_SetString(PyExc_RuntimeError, "Module '_CharLS' has already been imported. Re-initialisation is not supported."); - return -1; - } - #elif PY_MAJOR_VERSION >= 3 - if (__pyx_m) return __Pyx_NewRef(__pyx_m); - #endif - /*--- Module creation code ---*/ - #if CYTHON_PEP489_MULTI_PHASE_INIT - __pyx_m = __pyx_pyinit_module; - Py_INCREF(__pyx_m); - #else - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4("_CharLS", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) - #elif CYTHON_USE_MODULE_STATE - __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) - { - int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); - __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "_CharLS" pseudovariable */ - if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) - pystate_addmodule_run = 1; - } - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #endif - CYTHON_UNUSED_VAR(__pyx_t_1); - __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) - Py_INCREF(__pyx_d); - __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #if CYTHON_REFNANNY -__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); -if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); -} -#endif - __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__CharLS(void)", 0); - if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #ifdef __Pxy_PyFrame_Initialize_Offsets - __Pxy_PyFrame_Initialize_Offsets(); - #endif - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) - #ifdef __Pyx_CyFunction_USED - if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_Coroutine_USED - if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_AsyncGen_USED - if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_StopAsyncIteration_USED - if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - PyEval_InitThreads(); - #endif - /*--- Initialize various global constants etc. ---*/ - if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - stringtab_initialized = 1; - if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) - if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - if (__pyx_module_is_main__CharLS) { - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - } - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) - if (!PyDict_GetItemString(modules, "_CharLS")) { - if (unlikely((PyDict_SetItemString(modules, "_CharLS", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) - } - } - #endif - /*--- Builtin init code ---*/ - if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - /*--- Constants init code ---*/ - if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - /*--- Global type/function init code ---*/ - (void)__Pyx_modinit_global_init_code(); - (void)__Pyx_modinit_variable_export_code(); - (void)__Pyx_modinit_function_export_code(); - (void)__Pyx_modinit_type_init_code(); - if (unlikely((__Pyx_modinit_type_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) - (void)__Pyx_modinit_variable_import_code(); - (void)__Pyx_modinit_function_import_code(); - /*--- Execution code ---*/ - #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - - /* "_CharLS.pyx":3 - * # cython: language_level=3 - * - * import logging # <<<<<<<<<<<<<< - * import math - * from typing import Dict - */ - __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":4 - * - * import logging - * import math # <<<<<<<<<<<<<< - * from typing import Dict - * - */ - __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_math, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_math, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":5 - * import logging - * import math - * from typing import Dict # <<<<<<<<<<<<<< - * - * import numpy as np - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_Dict); - __Pyx_GIVEREF(__pyx_n_s_Dict); - if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Dict)) __PYX_ERR(0, 5, __pyx_L1_error); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_typing, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_Dict, __pyx_t_2) < 0) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":7 - * from typing import Dict - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as cnp - * - */ - __pyx_t_3 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_3) < 0) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":11 - * - * - * LOGGER = logging.getLogger("jpeg_ls._CharLS") # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_logging); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_3) < 0) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":177 - * - * - * def read_header(src: bytes | bytearray) -> Dict[str, int]: # <<<<<<<<<<<<<< - * """Return a dict containing information about the JPEG-LS file.""" - * # info: JlsParameters - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 177, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_kp_s_Dict_str_int) < 0) __PYX_ERR(0, 177, __pyx_L1_error) - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_1read_header, 0, __pyx_n_s_read_header, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_header, __pyx_t_2) < 0) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":193 - * - * - * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` to a bytearray - * - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 193, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 193, __pyx_L1_error) - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_3_decode, 0, __pyx_n_s_decode, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode, __pyx_t_3) < 0) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":237 - * - * - * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` to a bytearray - * - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_src, __pyx_kp_s_bytes_bytearray) < 0) __PYX_ERR(0, 237, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_kp_s_tuple_bytearray_dict_str_int) < 0) __PYX_ERR(0, 237, __pyx_L1_error) - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_5decode_from_buffer, 0, __pyx_n_s_decode_from_buffer, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode_from_buffer, __pyx_t_2) < 0) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":253 - * - * - * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream in the ndarray `data_buffer` - * - */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_7decode, 0, __pyx_n_s_decode_2, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_decode_2, __pyx_t_2) < 0) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":288 - * - * - * def encode_to_buffer( # <<<<<<<<<<<<<< - * src: np.ndarray | bytes, - * lossy_error: int = 0, - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_src, __pyx_kp_s_np_ndarray_bytes) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_lossy_error, __pyx_n_s_int) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_interleave_mode, __pyx_kp_s_int_None) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_9encode_to_buffer, 0, __pyx_n_s_encode_to_buffer, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__22)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (!__Pyx_CyFunction_InitDefaults(__pyx_t_3, sizeof(__pyx_defaults), 1)) __PYX_ERR(0, 288, __pyx_L1_error) - - /* "_CharLS.pyx":290 - * def encode_to_buffer( - * src: np.ndarray | bytes, - * lossy_error: int = 0, # <<<<<<<<<<<<<< - * interleave_mode: int | None = None, - * ) -> bytearray: - */ - if (!(likely(__Pyx_Py3Int_CheckExact(__pyx_int_0)) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_int_0))) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_INCREF(__pyx_int_0); - __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_t_3)->__pyx_arg_lossy_error = ((PyObject*)__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_CyFunction_SetDefaultsGetter(__pyx_t_3, __pyx_pf_7_CharLS_14__defaults__); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_encode_to_buffer, __pyx_t_3) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":334 - * - * - * def _encode_array( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_arr, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 334, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_lossy_error, __pyx_n_s_int) < 0) __PYX_ERR(0, 334, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_interleave_mode, __pyx_kp_s_int_None) < 0) __PYX_ERR(0, 334, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 334, __pyx_L1_error) - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_11_encode_array, 0, __pyx_n_s_encode_array, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (!__Pyx_CyFunction_InitDefaults(__pyx_t_2, sizeof(__pyx_defaults1), 1)) __PYX_ERR(0, 334, __pyx_L1_error) - - /* "_CharLS.pyx":336 - * def _encode_array( - * arr: np.ndarray, - * lossy_error: int = 0, # <<<<<<<<<<<<<< - * interleave_mode: int | None = None, - * ) -> bytearray: - */ - if (!(likely(__Pyx_Py3Int_CheckExact(__pyx_int_0)) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_int_0))) __PYX_ERR(0, 336, __pyx_L1_error) - __Pyx_INCREF(__pyx_int_0); - __Pyx_CyFunction_Defaults(__pyx_defaults1, __pyx_t_2)->__pyx_arg_lossy_error = ((PyObject*)__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_CyFunction_SetDefaultsGetter(__pyx_t_2, __pyx_pf_7_CharLS_16__defaults__); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_encode_array, __pyx_t_2) < 0) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "_CharLS.pyx":448 - * - * - * def encode( # <<<<<<<<<<<<<< - * arr: np.ndarray, - * lossy_error: int = 0, - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_arr, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 448, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_lossy_error, __pyx_n_s_int) < 0) __PYX_ERR(0, 448, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_interleave_mode, __pyx_kp_s_int_None) < 0) __PYX_ERR(0, 448, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 448, __pyx_L1_error) - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_13encode, 0, __pyx_n_s_encode, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__26)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (!__Pyx_CyFunction_InitDefaults(__pyx_t_3, sizeof(__pyx_defaults2), 1)) __PYX_ERR(0, 448, __pyx_L1_error) - - /* "_CharLS.pyx":450 - * def encode( - * arr: np.ndarray, - * lossy_error: int = 0, # <<<<<<<<<<<<<< - * interleave_mode: int | None = None, - * ) -> np.ndarray: - */ - if (!(likely(__Pyx_Py3Int_CheckExact(__pyx_int_0)) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_int_0))) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_INCREF(__pyx_int_0); - __Pyx_CyFunction_Defaults(__pyx_defaults2, __pyx_t_3)->__pyx_arg_lossy_error = ((PyObject*)__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_CyFunction_SetDefaultsGetter(__pyx_t_3, __pyx_pf_7_CharLS_18__defaults__); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_encode, __pyx_t_3) < 0) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_CharLS.pyx":1 - * # cython: language_level=3 # <<<<<<<<<<<<<< - * - * import logging - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /*--- Wrapped vars code ---*/ - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - if (__pyx_m) { - if (__pyx_d && stringtab_initialized) { - __Pyx_AddTraceback("init _CharLS", __pyx_clineno, __pyx_lineno, __pyx_filename); - } - #if !CYTHON_USE_MODULE_STATE - Py_CLEAR(__pyx_m); - #else - Py_DECREF(__pyx_m); - if (pystate_addmodule_run) { - PyObject *tp, *value, *tb; - PyErr_Fetch(&tp, &value, &tb); - PyState_RemoveModule(&__pyx_moduledef); - PyErr_Restore(tp, value, tb); - } - #endif - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init _CharLS"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if CYTHON_PEP489_MULTI_PHASE_INIT - return (__pyx_m != NULL) ? 0 : -1; - #elif PY_MAJOR_VERSION >= 3 - return __pyx_m; - #else - return; - #endif -} -/* #### Code section: cleanup_globals ### */ -/* #### Code section: cleanup_module ### */ -/* #### Code section: main_method ### */ -/* #### Code section: utility_code_pragmas ### */ -#ifdef _MSC_VER -#pragma warning( push ) -/* Warning 4127: conditional expression is constant - * Cython uses constant conditional expressions to allow in inline functions to be optimized at - * compile-time, so this warning is not useful - */ -#pragma warning( disable : 4127 ) -#endif - - - -/* #### Code section: utility_code_def ### */ - -/* --- Runtime support code --- */ -/* Refnanny */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule(modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, "RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif - -/* PyErrExceptionMatches */ -#if CYTHON_FAST_THREAD_STATE -static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { - Py_ssize_t i, n; - n = PyTuple_GET_SIZE(tuple); -#if PY_MAJOR_VERSION >= 3 - for (i=0; i= 0x030C00A6 - PyObject *current_exception = tstate->current_exception; - if (unlikely(!current_exception)) return 0; - exc_type = (PyObject*) Py_TYPE(current_exception); - if (exc_type == err) return 1; -#else - exc_type = tstate->curexc_type; - if (exc_type == err) return 1; - if (unlikely(!exc_type)) return 0; -#endif - #if CYTHON_AVOID_BORROWED_REFS - Py_INCREF(exc_type); - #endif - if (unlikely(PyTuple_Check(err))) { - result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); - } else { - result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); - } - #if CYTHON_AVOID_BORROWED_REFS - Py_DECREF(exc_type); - #endif - return result; -} -#endif - -/* PyErrFetchRestore */ -#if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { -#if PY_VERSION_HEX >= 0x030C00A6 - PyObject *tmp_value; - assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); - if (value) { - #if CYTHON_COMPILING_IN_CPYTHON - if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) - #endif - PyException_SetTraceback(value, tb); - } - tmp_value = tstate->current_exception; - tstate->current_exception = value; - Py_XDECREF(tmp_value); - Py_XDECREF(type); - Py_XDECREF(tb); -#else - PyObject *tmp_type, *tmp_value, *tmp_tb; - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { -#if PY_VERSION_HEX >= 0x030C00A6 - PyObject* exc_value; - exc_value = tstate->current_exception; - tstate->current_exception = 0; - *value = exc_value; - *type = NULL; - *tb = NULL; - if (exc_value) { - *type = (PyObject*) Py_TYPE(exc_value); - Py_INCREF(*type); - #if CYTHON_COMPILING_IN_CPYTHON - *tb = ((PyBaseExceptionObject*) exc_value)->traceback; - Py_XINCREF(*tb); - #else - *tb = PyException_GetTraceback(exc_value); - #endif - } -#else - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#endif -} -#endif - -/* PyObjectGetAttrStr */ -#if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro)) - return tp->tp_getattro(obj, attr_name); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_getattr)) - return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); -#endif - return PyObject_GetAttr(obj, attr_name); -} -#endif - -/* PyObjectGetAttrStrNoError */ -#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 -static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) - __Pyx_PyErr_Clear(); -} -#endif -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { - PyObject *result; -#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 - (void) PyObject_GetOptionalAttr(obj, attr_name, &result); - return result; -#else -#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { - return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); - } -#endif - result = __Pyx_PyObject_GetAttrStr(obj, attr_name); - if (unlikely(!result)) { - __Pyx_PyObject_GetAttrStr_ClearAttributeError(); - } - return result; -#endif -} - -/* GetBuiltinName */ -static PyObject *__Pyx_GetBuiltinName(PyObject *name) { - PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); - if (unlikely(!result) && !PyErr_Occurred()) { - PyErr_Format(PyExc_NameError, -#if PY_MAJOR_VERSION >= 3 - "name '%U' is not defined", name); -#else - "name '%.200s' is not defined", PyString_AS_STRING(name)); -#endif - } - return result; -} - -/* GetTopmostException */ -#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE -static _PyErr_StackItem * -__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) -{ - _PyErr_StackItem *exc_info = tstate->exc_info; - while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && - exc_info->previous_item != NULL) - { - exc_info = exc_info->previous_item; - } - return exc_info; + return exc_info; } #endif @@ -11370,1078 +9542,712 @@ static void __Pyx_RaiseArgtupleInvalid( num_expected = num_max; more_or_less = "at most"; } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -/* RaiseUnexpectedTypeError */ -static int -__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj) -{ - __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); - PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME, - expected, obj_type_name); - __Pyx_DECREF_TypeName(obj_type_name); - return 0; -} - -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { -#if CYTHON_COMPILING_IN_CPYTHON - dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); -#else - dictptr = _PyObject_GetDictPtr(obj); -#endif - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - PyObject *result; -#if !CYTHON_AVOID_BORROWED_REFS -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 - result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#elif CYTHON_COMPILING_IN_LIMITED_API - if (unlikely(!__pyx_m)) { - return NULL; - } - result = PyObject_GetAttr(__pyx_m, name); - if (likely(result)) { - return result; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - -/* ArgTypeTest */ -static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) -{ - __Pyx_TypeName type_name; - __Pyx_TypeName obj_type_name; - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - else if (exact) { - #if PY_MAJOR_VERSION == 2 - if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; - #endif - } - else { - if (likely(__Pyx_TypeCheck(obj, type))) return 1; - } - type_name = __Pyx_PyType_GetName(type); - obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); - PyErr_Format(PyExc_TypeError, - "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME - ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name); - __Pyx_DECREF_TypeName(type_name); - __Pyx_DECREF_TypeName(obj_type_name); - return 0; -} - -/* IsLittleEndian */ -static CYTHON_INLINE int __Pyx_Is_Little_Endian(void) -{ - union { - uint32_t u32; - uint8_t u8[4]; - } S; - S.u32 = 0x01020304; - return S.u8[0] == 4; -} - -/* BufferFormatCheck */ -static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, - __Pyx_BufFmt_StackElem* stack, - __Pyx_TypeInfo* type) { - stack[0].field = &ctx->root; - stack[0].parent_offset = 0; - ctx->root.type = type; - ctx->root.name = "buffer dtype"; - ctx->root.offset = 0; - ctx->head = stack; - ctx->head->field = &ctx->root; - ctx->fmt_offset = 0; - ctx->head->parent_offset = 0; - ctx->new_packmode = '@'; - ctx->enc_packmode = '@'; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ctx->is_complex = 0; - ctx->is_valid_array = 0; - ctx->struct_alignment = 0; - while (type->typegroup == 'S') { - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = 0; - type = type->fields->type; - } -} -static int __Pyx_BufFmt_ParseNumber(const char** ts) { - int count; - const char* t = *ts; - if (*t < '0' || *t > '9') { - return -1; - } else { - count = *t++ - '0'; - while (*t >= '0' && *t <= '9') { - count *= 10; - count += *t++ - '0'; - } - } - *ts = t; - return count; -} -static int __Pyx_BufFmt_ExpectNumber(const char **ts) { - int number = __Pyx_BufFmt_ParseNumber(ts); - if (number == -1) - PyErr_Format(PyExc_ValueError,\ - "Does not understand character buffer dtype format string ('%c')", **ts); - return number; -} -static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { - PyErr_Format(PyExc_ValueError, - "Unexpected format string character: '%c'", ch); -} -static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { - switch (ch) { - case '?': return "'bool'"; - case 'c': return "'char'"; - case 'b': return "'signed char'"; - case 'B': return "'unsigned char'"; - case 'h': return "'short'"; - case 'H': return "'unsigned short'"; - case 'i': return "'int'"; - case 'I': return "'unsigned int'"; - case 'l': return "'long'"; - case 'L': return "'unsigned long'"; - case 'q': return "'long long'"; - case 'Q': return "'unsigned long long'"; - case 'f': return (is_complex ? "'complex float'" : "'float'"); - case 'd': return (is_complex ? "'complex double'" : "'double'"); - case 'g': return (is_complex ? "'complex long double'" : "'long double'"); - case 'T': return "a struct"; - case 'O': return "Python object"; - case 'P': return "a pointer"; - case 's': case 'p': return "a string"; - case 0: return "end"; - default: return "unparsable format string"; - } -} -static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return 2; - case 'i': case 'I': case 'l': case 'L': return 4; - case 'q': case 'Q': return 8; - case 'f': return (is_complex ? 8 : 4); - case 'd': return (is_complex ? 16 : 8); - case 'g': { - PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); - return 0; - } - case 'O': case 'P': return sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} -static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(short); - case 'i': case 'I': return sizeof(int); - case 'l': case 'L': return sizeof(long); - #ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(PY_LONG_LONG); - #endif - case 'f': return sizeof(float) * (is_complex ? 2 : 1); - case 'd': return sizeof(double) * (is_complex ? 2 : 1); - case 'g': return sizeof(long double) * (is_complex ? 2 : 1); - case 'O': case 'P': return sizeof(void*); - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; + if (exact) { + more_or_less = "exactly"; } - } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); } -typedef struct { char c; short x; } __Pyx_st_short; -typedef struct { char c; int x; } __Pyx_st_int; -typedef struct { char c; long x; } __Pyx_st_long; -typedef struct { char c; float x; } __Pyx_st_float; -typedef struct { char c; double x; } __Pyx_st_double; -typedef struct { char c; long double x; } __Pyx_st_longdouble; -typedef struct { char c; void *x; } __Pyx_st_void_p; -#ifdef HAVE_LONG_LONG -typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong; -#endif -static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { - CYTHON_UNUSED_VAR(is_complex); - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); - case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); - case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); -#ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG); -#endif - case 'f': return sizeof(__Pyx_st_float) - sizeof(float); - case 'd': return sizeof(__Pyx_st_double) - sizeof(double); - case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); - case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } + +/* RaiseUnexpectedTypeError */ +static int +__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj) +{ + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME, + expected, obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; } -/* These are for computing the padding at the end of the struct to align - on the first member of the struct. This will probably the same as above, - but we don't have any guarantees. - */ -typedef struct { short x; char c; } __Pyx_pad_short; -typedef struct { int x; char c; } __Pyx_pad_int; -typedef struct { long x; char c; } __Pyx_pad_long; -typedef struct { float x; char c; } __Pyx_pad_float; -typedef struct { double x; char c; } __Pyx_pad_double; -typedef struct { long double x; char c; } __Pyx_pad_longdouble; -typedef struct { void *x; char c; } __Pyx_pad_void_p; -#ifdef HAVE_LONG_LONG -typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong; -#endif -static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, int is_complex) { - CYTHON_UNUSED_VAR(is_complex); - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short); - case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int); - case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long); -#ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG); -#endif - case 'f': return sizeof(__Pyx_pad_float) - sizeof(float); - case 'd': return sizeof(__Pyx_pad_double) - sizeof(double); - case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double); - case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; } -static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { - switch (ch) { - case 'c': - return 'H'; - case 'b': case 'h': case 'i': - case 'l': case 'q': case 's': case 'p': - return 'I'; - case '?': case 'B': case 'H': case 'I': case 'L': case 'Q': - return 'U'; - case 'f': case 'd': case 'g': - return (is_complex ? 'C' : 'R'); - case 'O': - return 'O'; - case 'P': - return 'P'; - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif } - } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; } -static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { - if (ctx->head == NULL || ctx->head->field == &ctx->root) { - const char* expected; - const char* quote; - if (ctx->head == NULL) { - expected = "end"; - quote = ""; - } else { - expected = ctx->head->field->type->name; - quote = "'"; - } - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected %s%s%s but got %s", - quote, expected, quote, - __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); - } else { - __Pyx_StructField* field = ctx->head->field; - __Pyx_StructField* parent = (ctx->head - 1)->field; - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", - field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), - parent->type->name, field->name); - } +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); } -static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { - char group; - size_t size, offset, arraysize = 1; - if (ctx->enc_type == 0) return 0; - if (ctx->head->field->type->arraysize[0]) { - int i, ndim = 0; - if (ctx->enc_type == 's' || ctx->enc_type == 'p') { - ctx->is_valid_array = ctx->head->field->type->ndim == 1; - ndim = 1; - if (ctx->enc_count != ctx->head->field->type->arraysize[0]) { - PyErr_Format(PyExc_ValueError, - "Expected a dimension of size %zu, got %zu", - ctx->head->field->type->arraysize[0], ctx->enc_count); - return -1; - } - } - if (!ctx->is_valid_array) { - PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d", - ctx->head->field->type->ndim, ndim); - return -1; - } - for (i = 0; i < ctx->head->field->type->ndim; i++) { - arraysize *= ctx->head->field->type->arraysize[i]; - } - ctx->is_valid_array = 0; - ctx->enc_count = 1; - } - group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); - do { - __Pyx_StructField* field = ctx->head->field; - __Pyx_TypeInfo* type = field->type; - if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') { - size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); - } else { - size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); - } - if (ctx->enc_packmode == '@') { - size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); - size_t align_mod_offset; - if (align_at == 0) return -1; - align_mod_offset = ctx->fmt_offset % align_at; - if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; - if (ctx->struct_alignment == 0) - ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type, - ctx->is_complex); - } - if (type->size != size || type->typegroup != group) { - if (type->typegroup == 'C' && type->fields != NULL) { - size_t parent_offset = ctx->head->parent_offset + field->offset; - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = parent_offset; - continue; - } - if ((type->typegroup == 'H' || group == 'H') && type->size == size) { - } else { - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - } - offset = ctx->head->parent_offset + field->offset; - if (ctx->fmt_offset != offset) { - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected", - (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); - return -1; +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; } - ctx->fmt_offset += size; - if (arraysize) - ctx->fmt_offset += (arraysize - 1) * size; - --ctx->enc_count; - while (1) { - if (field == &ctx->root) { - ctx->head = NULL; - if (ctx->enc_count != 0) { - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - break; - } - ctx->head->field = ++field; - if (field->type == NULL) { - --ctx->head; - field = ctx->head->field; - continue; - } else if (field->type->typegroup == 'S') { - size_t parent_offset = ctx->head->parent_offset + field->offset; - if (field->type->fields->type == NULL) continue; - field = field->type->fields; - ++ctx->head; - ctx->head->field = field; - ctx->head->parent_offset = parent_offset; - break; - } else { - break; - } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; } - } while (ctx->enc_count); - ctx->enc_type = 0; - ctx->is_complex = 0; - return 0; + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); } -static int -__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) { - const char *ts = *tsp; - int i = 0, number, ndim; - ++ts; - if (ctx->new_count != 1) { - PyErr_SetString(PyExc_ValueError, - "Cannot handle repeated arrays in format string"); - return -1; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return -1; - ndim = ctx->head->field->type->ndim; - while (*ts && *ts != ')') { - switch (*ts) { - case ' ': case '\f': case '\r': case '\n': case '\t': case '\v': continue; - default: break; - } - number = __Pyx_BufFmt_ExpectNumber(&ts); - if (number == -1) return -1; - if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) { - PyErr_Format(PyExc_ValueError, - "Expected a dimension of size %zu, got %d", - ctx->head->field->type->arraysize[i], number); - return -1; - } - if (*ts != ',' && *ts != ')') { - PyErr_Format(PyExc_ValueError, - "Expected a comma in format string, got '%c'", *ts); - return -1; - } - if (*ts == ',') ts++; - i++; + __Pyx_TypeName type_name; + __Pyx_TypeName obj_type_name; + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; } - if (i != ndim) { - PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d", - ctx->head->field->type->ndim, i); - return -1; + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif } - if (!*ts) { - PyErr_SetString(PyExc_ValueError, - "Unexpected end of format string, expected ')'"); - return -1; + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; } - ctx->is_valid_array = 1; - ctx->new_count = 1; - *tsp = ++ts; + type_name = __Pyx_PyType_GetName(type); + obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME + ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name); + __Pyx_DECREF_TypeName(type_name); + __Pyx_DECREF_TypeName(obj_type_name); return 0; } -static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { - int got_Z = 0; - while (1) { - switch(*ts) { - case 0: - if (ctx->enc_type != 0 && ctx->head == NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - if (ctx->head != NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - return ts; - case ' ': - case '\r': - case '\n': - ++ts; - break; - case '<': - if (!__Pyx_Is_Little_Endian()) { - PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); - return NULL; - } - ctx->new_packmode = '='; - ++ts; - break; - case '>': - case '!': - if (__Pyx_Is_Little_Endian()) { - PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); - return NULL; - } - ctx->new_packmode = '='; - ++ts; - break; - case '=': - case '@': - case '^': - ctx->new_packmode = *ts++; - break; - case 'T': - { - const char* ts_after_sub; - size_t i, struct_count = ctx->new_count; - size_t struct_alignment = ctx->struct_alignment; - ctx->new_count = 1; - ++ts; - if (*ts != '{') { - PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_type = 0; - ctx->enc_count = 0; - ctx->struct_alignment = 0; - ++ts; - ts_after_sub = ts; - for (i = 0; i != struct_count; ++i) { - ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); - if (!ts_after_sub) return NULL; - } - ts = ts_after_sub; - if (struct_alignment) ctx->struct_alignment = struct_alignment; - } - break; - case '}': - { - size_t alignment = ctx->struct_alignment; - ++ts; - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_type = 0; - if (alignment && ctx->fmt_offset % alignment) { - ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment); - } - } - return ts; - case 'x': - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->fmt_offset += ctx->new_count; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ctx->enc_packmode = ctx->new_packmode; - ++ts; - break; - case 'Z': - got_Z = 1; - ++ts; - if (*ts != 'f' && *ts != 'd' && *ts != 'g') { - __Pyx_BufFmt_RaiseUnexpectedChar('Z'); - return NULL; - } - CYTHON_FALLTHROUGH; - case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': - case 'l': case 'L': case 'q': case 'Q': - case 'f': case 'd': case 'g': - case 'O': case 'p': - if ((ctx->enc_type == *ts) && (got_Z == ctx->is_complex) && - (ctx->enc_packmode == ctx->new_packmode) && (!ctx->is_valid_array)) { - ctx->enc_count += ctx->new_count; - ctx->new_count = 1; - got_Z = 0; - ++ts; - break; - } - CYTHON_FALLTHROUGH; - case 's': - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_count = ctx->new_count; - ctx->enc_packmode = ctx->new_packmode; - ctx->enc_type = *ts; - ctx->is_complex = got_Z; - ++ts; - ctx->new_count = 1; - got_Z = 0; - break; - case ':': - ++ts; - while(*ts != ':') ++ts; - ++ts; - break; - case '(': - if (__pyx_buffmt_parse_array(ctx, &ts) < 0) return NULL; - break; - default: - { - int number = __Pyx_BufFmt_ExpectNumber(&ts); - if (number == -1) return NULL; - ctx->new_count = (size_t)number; + +/* IsLittleEndian */ +static CYTHON_INLINE int __Pyx_Is_Little_Endian(void) +{ + union { + uint32_t u32; + uint8_t u8[4]; + } S; + S.u32 = 0x01020304; + return S.u8[0] == 4; +} + +/* BufferFormatCheck */ +static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, + __Pyx_BufFmt_StackElem* stack, + __Pyx_TypeInfo* type) { + stack[0].field = &ctx->root; + stack[0].parent_offset = 0; + ctx->root.type = type; + ctx->root.name = "buffer dtype"; + ctx->root.offset = 0; + ctx->head = stack; + ctx->head->field = &ctx->root; + ctx->fmt_offset = 0; + ctx->head->parent_offset = 0; + ctx->new_packmode = '@'; + ctx->enc_packmode = '@'; + ctx->new_count = 1; + ctx->enc_count = 0; + ctx->enc_type = 0; + ctx->is_complex = 0; + ctx->is_valid_array = 0; + ctx->struct_alignment = 0; + while (type->typegroup == 'S') { + ++ctx->head; + ctx->head->field = type->fields; + ctx->head->parent_offset = 0; + type = type->fields->type; + } +} +static int __Pyx_BufFmt_ParseNumber(const char** ts) { + int count; + const char* t = *ts; + if (*t < '0' || *t > '9') { + return -1; + } else { + count = *t++ - '0'; + while (*t >= '0' && *t <= '9') { + count *= 10; + count += *t++ - '0'; } } - } + *ts = t; + return count; } - -/* BufferGetAndValidate */ - static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { - if (unlikely(info->buf == NULL)) return; - if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; - __Pyx_ReleaseBuffer(info); +static int __Pyx_BufFmt_ExpectNumber(const char **ts) { + int number = __Pyx_BufFmt_ParseNumber(ts); + if (number == -1) + PyErr_Format(PyExc_ValueError,\ + "Does not understand character buffer dtype format string ('%c')", **ts); + return number; } -static void __Pyx_ZeroBuffer(Py_buffer* buf) { - buf->buf = NULL; - buf->obj = NULL; - buf->strides = __Pyx_zeros; - buf->shape = __Pyx_zeros; - buf->suboffsets = __Pyx_minusones; +static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { + PyErr_Format(PyExc_ValueError, + "Unexpected format string character: '%c'", ch); } -static int __Pyx__GetBufferAndValidate( - Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, - int nd, int cast, __Pyx_BufFmt_StackElem* stack) -{ - buf->buf = NULL; - if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) { - __Pyx_ZeroBuffer(buf); - return -1; - } - if (unlikely(buf->ndim != nd)) { - PyErr_Format(PyExc_ValueError, - "Buffer has wrong number of dimensions (expected %d, got %d)", - nd, buf->ndim); - goto fail; - } - if (!cast) { - __Pyx_BufFmt_Context ctx; - __Pyx_BufFmt_Init(&ctx, stack, dtype); - if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; - } - if (unlikely((size_t)buf->itemsize != dtype->size)) { - PyErr_Format(PyExc_ValueError, - "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", - buf->itemsize, (buf->itemsize > 1) ? "s" : "", - dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); - goto fail; +static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { + switch (ch) { + case '?': return "'bool'"; + case 'c': return "'char'"; + case 'b': return "'signed char'"; + case 'B': return "'unsigned char'"; + case 'h': return "'short'"; + case 'H': return "'unsigned short'"; + case 'i': return "'int'"; + case 'I': return "'unsigned int'"; + case 'l': return "'long'"; + case 'L': return "'unsigned long'"; + case 'q': return "'long long'"; + case 'Q': return "'unsigned long long'"; + case 'f': return (is_complex ? "'complex float'" : "'float'"); + case 'd': return (is_complex ? "'complex double'" : "'double'"); + case 'g': return (is_complex ? "'complex long double'" : "'long double'"); + case 'T': return "a struct"; + case 'O': return "Python object"; + case 'P': return "a pointer"; + case 's': case 'p': return "a string"; + case 0: return "end"; + default: return "unparsable format string"; } - if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; - return 0; -fail:; - __Pyx_SafeReleaseBuffer(buf); - return -1; } - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_TrueDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { - CYTHON_MAYBE_UNUSED_VAR(intval); - CYTHON_MAYBE_UNUSED_VAR(inplace); - CYTHON_UNUSED_VAR(zerodivision_check); - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long a = PyInt_AS_LONG(op1); - - if (8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53))) { - return PyFloat_FromDouble((double)a / (double)b); - } - return PyInt_Type.tp_as_number->nb_true_divide(op1, op2); +static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { + switch (ch) { + case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; + case 'h': case 'H': return 2; + case 'i': case 'I': case 'l': case 'L': return 4; + case 'q': case 'Q': return 8; + case 'f': return (is_complex ? 8 : 4); + case 'd': return (is_complex ? 16 : 8); + case 'g': { + PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); + return 0; } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; - if (unlikely(__Pyx_PyLong_IsZero(op1))) { - } - if (likely(__Pyx_PyLong_IsCompact(op1))) { - a = __Pyx_PyLong_CompactValue(op1); - } else { - const digit* digits = __Pyx_PyLong_Digits(op1); - const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1); - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_true_divide(op1, op2); - } - } - if ((8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53))) - || __Pyx_PyLong_DigitCount(op1) <= 52 / PyLong_SHIFT) { - return PyFloat_FromDouble((double)a / (double)b); - } - return PyLong_Type.tp_as_number->nb_true_divide(op1, op2); - return PyLong_FromLong(x); - + case 'O': case 'P': return sizeof(void*); + default: + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; } +} +static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { + switch (ch) { + case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; + case 'h': case 'H': return sizeof(short); + case 'i': case 'I': return sizeof(int); + case 'l': case 'L': return sizeof(long); + #ifdef HAVE_LONG_LONG + case 'q': case 'Q': return sizeof(PY_LONG_LONG); #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; -#if CYTHON_COMPILING_IN_LIMITED_API - double a = __pyx_PyFloat_AsDouble(op1); -#else - double a = PyFloat_AS_DOUBLE(op1); + case 'f': return sizeof(float) * (is_complex ? 2 : 1); + case 'd': return sizeof(double) * (is_complex ? 2 : 1); + case 'g': return sizeof(long double) * (is_complex ? 2 : 1); + case 'O': case 'P': return sizeof(void*); + default: { + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } + } +} +typedef struct { char c; short x; } __Pyx_st_short; +typedef struct { char c; int x; } __Pyx_st_int; +typedef struct { char c; long x; } __Pyx_st_long; +typedef struct { char c; float x; } __Pyx_st_float; +typedef struct { char c; double x; } __Pyx_st_double; +typedef struct { char c; long double x; } __Pyx_st_longdouble; +typedef struct { char c; void *x; } __Pyx_st_void_p; +#ifdef HAVE_LONG_LONG +typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong; +#endif +static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { + CYTHON_UNUSED_VAR(is_complex); + switch (ch) { + case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; + case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); + case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); + case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); +#ifdef HAVE_LONG_LONG + case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG); +#endif + case 'f': return sizeof(__Pyx_st_float) - sizeof(float); + case 'd': return sizeof(__Pyx_st_double) - sizeof(double); + case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); + case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); + default: + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } +} +/* These are for computing the padding at the end of the struct to align + on the first member of the struct. This will probably the same as above, + but we don't have any guarantees. + */ +typedef struct { short x; char c; } __Pyx_pad_short; +typedef struct { int x; char c; } __Pyx_pad_int; +typedef struct { long x; char c; } __Pyx_pad_long; +typedef struct { float x; char c; } __Pyx_pad_float; +typedef struct { double x; char c; } __Pyx_pad_double; +typedef struct { long double x; char c; } __Pyx_pad_longdouble; +typedef struct { void *x; char c; } __Pyx_pad_void_p; +#ifdef HAVE_LONG_LONG +typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong; +#endif +static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, int is_complex) { + CYTHON_UNUSED_VAR(is_complex); + switch (ch) { + case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; + case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short); + case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int); + case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long); +#ifdef HAVE_LONG_LONG + case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG); #endif - double result; - - PyFPE_START_PROTECT("divide", return NULL) - result = ((double)a) / (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); + case 'f': return sizeof(__Pyx_pad_float) - sizeof(float); + case 'd': return sizeof(__Pyx_pad_double) - sizeof(double); + case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double); + case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*); + default: + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; } - return (inplace ? PyNumber_InPlaceTrueDivide : PyNumber_TrueDivide)(op1, op2); } -#endif - -/* DictGetItem */ - #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY -static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { - PyObject *value; - value = PyDict_GetItemWithError(d, key); - if (unlikely(!value)) { - if (!PyErr_Occurred()) { - if (unlikely(PyTuple_Check(key))) { - PyObject* args = PyTuple_Pack(1, key); - if (likely(args)) { - PyErr_SetObject(PyExc_KeyError, args); - Py_DECREF(args); - } - } else { - PyErr_SetObject(PyExc_KeyError, key); - } - } - return NULL; +static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { + switch (ch) { + case 'c': + return 'H'; + case 'b': case 'h': case 'i': + case 'l': case 'q': case 's': case 'p': + return 'I'; + case '?': case 'B': case 'H': case 'I': case 'L': case 'Q': + return 'U'; + case 'f': case 'd': case 'g': + return (is_complex ? 'C' : 'R'); + case 'O': + return 'O'; + case 'P': + return 'P'; + default: { + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; } - Py_INCREF(value); - return value; + } } -#endif - -/* PyIntCompare */ - static CYTHON_INLINE int __Pyx_PyInt_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace) { - CYTHON_MAYBE_UNUSED_VAR(intval); - CYTHON_UNUSED_VAR(inplace); - if (op1 == op2) { - return 1; - } - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long a = PyInt_AS_LONG(op1); - return (a == b); +static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { + if (ctx->head == NULL || ctx->head->field == &ctx->root) { + const char* expected; + const char* quote; + if (ctx->head == NULL) { + expected = "end"; + quote = ""; + } else { + expected = ctx->head->field->type->name; + quote = "'"; } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - int unequal; - unsigned long uintval; - Py_ssize_t size = __Pyx_PyLong_DigitCount(op1); - const digit* digits = __Pyx_PyLong_Digits(op1); - if (intval == 0) { - return (__Pyx_PyLong_IsZero(op1) == 1); - } else if (intval < 0) { - if (__Pyx_PyLong_IsNonNeg(op1)) - return 0; - intval = -intval; - } else { - if (__Pyx_PyLong_IsNeg(op1)) - return 0; + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch, expected %s%s%s but got %s", + quote, expected, quote, + __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); + } else { + __Pyx_StructField* field = ctx->head->field; + __Pyx_StructField* parent = (ctx->head - 1)->field; + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", + field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), + parent->type->name, field->name); + } +} +static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { + char group; + size_t size, offset, arraysize = 1; + if (ctx->enc_type == 0) return 0; + if (ctx->head->field->type->arraysize[0]) { + int i, ndim = 0; + if (ctx->enc_type == 's' || ctx->enc_type == 'p') { + ctx->is_valid_array = ctx->head->field->type->ndim == 1; + ndim = 1; + if (ctx->enc_count != ctx->head->field->type->arraysize[0]) { + PyErr_Format(PyExc_ValueError, + "Expected a dimension of size %zu, got %zu", + ctx->head->field->type->arraysize[0], ctx->enc_count); + return -1; } - uintval = (unsigned long) intval; -#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 4)) { - unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 3)) { - unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 2)) { - unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 1)) { - unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif - unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); - return (unequal == 0); } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; -#if CYTHON_COMPILING_IN_LIMITED_API - double a = __pyx_PyFloat_AsDouble(op1); -#else - double a = PyFloat_AS_DOUBLE(op1); -#endif - return ((double)a == (double)b); + if (!ctx->is_valid_array) { + PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d", + ctx->head->field->type->ndim, ndim); + return -1; } - return __Pyx_PyObject_IsTrueAndDecref( - PyObject_RichCompare(op1, op2, Py_EQ)); -} - -/* JoinPyUnicode */ - static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - Py_UCS4 max_char) { -#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - PyObject *result_uval; - int result_ukind, kind_shift; - Py_ssize_t i, char_pos; - void *result_udata; - CYTHON_MAYBE_UNUSED_VAR(max_char); -#if CYTHON_PEP393_ENABLED - result_uval = PyUnicode_New(result_ulength, max_char); - if (unlikely(!result_uval)) return NULL; - result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; - kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1; - result_udata = PyUnicode_DATA(result_uval); -#else - result_uval = PyUnicode_FromUnicode(NULL, result_ulength); - if (unlikely(!result_uval)) return NULL; - result_ukind = sizeof(Py_UNICODE); - kind_shift = (result_ukind == 4) ? 2 : result_ukind - 1; - result_udata = PyUnicode_AS_UNICODE(result_uval); -#endif - assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0); - char_pos = 0; - for (i=0; i < value_count; i++) { - int ukind; - Py_ssize_t ulength; - void *udata; - PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); - if (unlikely(__Pyx_PyUnicode_READY(uval))) - goto bad; - ulength = __Pyx_PyUnicode_GET_LENGTH(uval); - if (unlikely(!ulength)) - continue; - if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos)) - goto overflow; - ukind = __Pyx_PyUnicode_KIND(uval); - udata = __Pyx_PyUnicode_DATA(uval); - if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { - memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift)); - } else { - #if PY_VERSION_HEX >= 0x030d0000 - if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad; - #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) - _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); - #else - Py_ssize_t j; - for (j=0; j < ulength; j++) { - Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); - __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); - } - #endif + for (i = 0; i < ctx->head->field->type->ndim; i++) { + arraysize *= ctx->head->field->type->arraysize[i]; + } + ctx->is_valid_array = 0; + ctx->enc_count = 1; + } + group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); + do { + __Pyx_StructField* field = ctx->head->field; + __Pyx_TypeInfo* type = field->type; + if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') { + size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); + } else { + size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); + } + if (ctx->enc_packmode == '@') { + size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); + size_t align_mod_offset; + if (align_at == 0) return -1; + align_mod_offset = ctx->fmt_offset % align_at; + if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; + if (ctx->struct_alignment == 0) + ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type, + ctx->is_complex); + } + if (type->size != size || type->typegroup != group) { + if (type->typegroup == 'C' && type->fields != NULL) { + size_t parent_offset = ctx->head->parent_offset + field->offset; + ++ctx->head; + ctx->head->field = type->fields; + ctx->head->parent_offset = parent_offset; + continue; + } + if ((type->typegroup == 'H' || group == 'H') && type->size == size) { + } else { + __Pyx_BufFmt_RaiseExpected(ctx); + return -1; + } + } + offset = ctx->head->parent_offset + field->offset; + if (ctx->fmt_offset != offset) { + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected", + (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); + return -1; + } + ctx->fmt_offset += size; + if (arraysize) + ctx->fmt_offset += (arraysize - 1) * size; + --ctx->enc_count; + while (1) { + if (field == &ctx->root) { + ctx->head = NULL; + if (ctx->enc_count != 0) { + __Pyx_BufFmt_RaiseExpected(ctx); + return -1; } - char_pos += ulength; + break; + } + ctx->head->field = ++field; + if (field->type == NULL) { + --ctx->head; + field = ctx->head->field; + continue; + } else if (field->type->typegroup == 'S') { + size_t parent_offset = ctx->head->parent_offset + field->offset; + if (field->type->fields->type == NULL) continue; + field = field->type->fields; + ++ctx->head; + ctx->head->field = field; + ctx->head->parent_offset = parent_offset; + break; + } else { + break; + } } - return result_uval; -overflow: - PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); -bad: - Py_DECREF(result_uval); - return NULL; -#else - CYTHON_UNUSED_VAR(max_char); - CYTHON_UNUSED_VAR(result_ulength); - CYTHON_UNUSED_VAR(value_count); - return PyUnicode_Join(__pyx_empty_unicode, value_tuple); -#endif -} - -/* GetItemInt */ - static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (unlikely(!j)) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; + } while (ctx->enc_count); + ctx->enc_type = 0; + ctx->is_complex = 0; + return 0; } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyList_GET_SIZE(o); +static int +__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) +{ + const char *ts = *tsp; + int i = 0, number, ndim; + ++ts; + if (ctx->new_count != 1) { + PyErr_SetString(PyExc_ValueError, + "Cannot handle repeated arrays in format string"); + return -1; } - if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return -1; + ndim = ctx->head->field->type->ndim; + while (*ts && *ts != ')') { + switch (*ts) { + case ' ': case '\f': case '\r': case '\n': case '\t': case '\v': continue; + default: break; + } + number = __Pyx_BufFmt_ExpectNumber(&ts); + if (number == -1) return -1; + if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) { + PyErr_Format(PyExc_ValueError, + "Expected a dimension of size %zu, got %d", + ctx->head->field->type->arraysize[i], number); + return -1; + } + if (*ts != ',' && *ts != ')') { + PyErr_Format(PyExc_ValueError, + "Expected a comma in format string, got '%c'", *ts); + return -1; + } + if (*ts == ',') ts++; + i++; } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyTuple_GET_SIZE(o); + if (i != ndim) { + PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d", + ctx->head->field->type->ndim, i); + return -1; } - if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; + if (!*ts) { + PyErr_SetString(PyExc_ValueError, + "Unexpected end of format string, expected ')'"); + return -1; } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif + ctx->is_valid_array = 1; + ctx->new_count = 1; + *tsp = ++ts; + return 0; } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS - if (is_list || PyList_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; +static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { + int got_Z = 0; + while (1) { + switch(*ts) { + case 0: + if (ctx->enc_type != 0 && ctx->head == NULL) { + __Pyx_BufFmt_RaiseExpected(ctx); + return NULL; } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + if (ctx->head != NULL) { + __Pyx_BufFmt_RaiseExpected(ctx); + return NULL; } - } else { - PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping; - PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence; - if (mm && mm->mp_subscript) { - PyObject *r, *key = PyInt_FromSsize_t(i); - if (unlikely(!key)) return NULL; - r = mm->mp_subscript(o, key); - Py_DECREF(key); - return r; + return ts; + case ' ': + case '\r': + case '\n': + ++ts; + break; + case '<': + if (!__Pyx_Is_Little_Endian()) { + PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); + return NULL; } - if (likely(sm && sm->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) { - Py_ssize_t l = sm->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (!PyErr_ExceptionMatches(PyExc_OverflowError)) - return NULL; - PyErr_Clear(); - } - } - return sm->sq_item(o, i); + ctx->new_packmode = '='; + ++ts; + break; + case '>': + case '!': + if (__Pyx_Is_Little_Endian()) { + PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); + return NULL; + } + ctx->new_packmode = '='; + ++ts; + break; + case '=': + case '@': + case '^': + ctx->new_packmode = *ts++; + break; + case 'T': + { + const char* ts_after_sub; + size_t i, struct_count = ctx->new_count; + size_t struct_alignment = ctx->struct_alignment; + ctx->new_count = 1; + ++ts; + if (*ts != '{') { + PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); + return NULL; + } + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->enc_type = 0; + ctx->enc_count = 0; + ctx->struct_alignment = 0; + ++ts; + ts_after_sub = ts; + for (i = 0; i != struct_count; ++i) { + ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); + if (!ts_after_sub) return NULL; + } + ts = ts_after_sub; + if (struct_alignment) ctx->struct_alignment = struct_alignment; + } + break; + case '}': + { + size_t alignment = ctx->struct_alignment; + ++ts; + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->enc_type = 0; + if (alignment && ctx->fmt_offset % alignment) { + ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment); + } + } + return ts; + case 'x': + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->fmt_offset += ctx->new_count; + ctx->new_count = 1; + ctx->enc_count = 0; + ctx->enc_type = 0; + ctx->enc_packmode = ctx->new_packmode; + ++ts; + break; + case 'Z': + got_Z = 1; + ++ts; + if (*ts != 'f' && *ts != 'd' && *ts != 'g') { + __Pyx_BufFmt_RaiseUnexpectedChar('Z'); + return NULL; + } + CYTHON_FALLTHROUGH; + case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': + case 'l': case 'L': case 'q': case 'Q': + case 'f': case 'd': case 'g': + case 'O': case 'p': + if ((ctx->enc_type == *ts) && (got_Z == ctx->is_complex) && + (ctx->enc_packmode == ctx->new_packmode) && (!ctx->is_valid_array)) { + ctx->enc_count += ctx->new_count; + ctx->new_count = 1; + got_Z = 0; + ++ts; + break; + } + CYTHON_FALLTHROUGH; + case 's': + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->enc_count = ctx->new_count; + ctx->enc_packmode = ctx->new_packmode; + ctx->enc_type = *ts; + ctx->is_complex = got_Z; + ++ts; + ctx->new_count = 1; + got_Z = 0; + break; + case ':': + ++ts; + while(*ts != ':') ++ts; + ++ts; + break; + case '(': + if (__pyx_buffmt_parse_array(ctx, &ts) < 0) return NULL; + break; + default: + { + int number = __Pyx_BufFmt_ExpectNumber(&ts); + if (number == -1) return NULL; + ctx->new_count = (size_t)number; } } -#else - if (is_list || !PyMapping_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); + } +} + +/* BufferGetAndValidate */ + static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { + if (unlikely(info->buf == NULL)) return; + if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; + __Pyx_ReleaseBuffer(info); +} +static void __Pyx_ZeroBuffer(Py_buffer* buf) { + buf->buf = NULL; + buf->obj = NULL; + buf->strides = __Pyx_zeros; + buf->shape = __Pyx_zeros; + buf->suboffsets = __Pyx_minusones; } - -/* RaiseUnboundLocalError */ - static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { - PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +static int __Pyx__GetBufferAndValidate( + Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, + int nd, int cast, __Pyx_BufFmt_StackElem* stack) +{ + buf->buf = NULL; + if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) { + __Pyx_ZeroBuffer(buf); + return -1; + } + if (unlikely(buf->ndim != nd)) { + PyErr_Format(PyExc_ValueError, + "Buffer has wrong number of dimensions (expected %d, got %d)", + nd, buf->ndim); + goto fail; + } + if (!cast) { + __Pyx_BufFmt_Context ctx; + __Pyx_BufFmt_Init(&ctx, stack, dtype); + if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; + } + if (unlikely((size_t)buf->itemsize != dtype->size)) { + PyErr_Format(PyExc_ValueError, + "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", + buf->itemsize, (buf->itemsize > 1) ? "s" : "", + dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); + goto fail; + } + if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; + return 0; +fail:; + __Pyx_SafeReleaseBuffer(buf); + return -1; } /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { +static PyObject* __Pyx_PyInt_TrueDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { CYTHON_MAYBE_UNUSED_VAR(intval); CYTHON_MAYBE_UNUSED_VAR(inplace); CYTHON_UNUSED_VAR(zerodivision_check); #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(op1))) { const long b = intval; - long x; long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a + (unsigned long)b); - if (likely((x^a) >= 0 || (x^b) >= 0)) - return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_add(op1, op2); + if (8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53))) { + return PyFloat_FromDouble((double)a / (double)b); + } + return PyInt_Type.tp_as_number->nb_true_divide(op1, op2); } #endif #if CYTHON_USE_PYLONG_INTERNALS if (likely(PyLong_CheckExact(op1))) { const long b = intval; long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif if (unlikely(__Pyx_PyLong_IsZero(op1))) { - return __Pyx_NewRef(op2); } if (likely(__Pyx_PyLong_IsCompact(op1))) { a = __Pyx_PyLong_CompactValue(op1); @@ -12450,82 +10256,50 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1); switch (size) { case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) { a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) { a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) { a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) { a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) { a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) { a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; - #ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; - #endif } CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_add(op1, op2); + default: return PyLong_Type.tp_as_number->nb_true_divide(op1, op2); } } - x = a + b; + if ((8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53))) + || __Pyx_PyLong_DigitCount(op1) <= 52 / PyLong_SHIFT) { + return PyFloat_FromDouble((double)a / (double)b); + } + return PyLong_Type.tp_as_number->nb_true_divide(op1, op2); return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla + llb; - return PyLong_FromLongLong(llx); -#endif - } #endif @@ -12538,15 +10312,111 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, #endif double result; - PyFPE_START_PROTECT("add", return NULL) - result = ((double)a) + (double)b; + PyFPE_START_PROTECT("divide", return NULL) + result = ((double)a) / (double)b; PyFPE_END_PROTECT(result) return PyFloat_FromDouble(result); } - return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); + return (inplace ? PyNumber_InPlaceTrueDivide : PyNumber_TrueDivide)(op1, op2); +} +#endif + +/* DictGetItem */ + #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; } #endif +/* PyIntCompare */ + static CYTHON_INLINE int __Pyx_PyInt_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace) { + CYTHON_MAYBE_UNUSED_VAR(intval); + CYTHON_UNUSED_VAR(inplace); + if (op1 == op2) { + return 1; + } + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long a = PyInt_AS_LONG(op1); + return (a == b); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = __Pyx_PyLong_DigitCount(op1); + const digit* digits = __Pyx_PyLong_Digits(op1); + if (intval == 0) { + return (__Pyx_PyLong_IsZero(op1) == 1); + } else if (intval < 0) { + if (__Pyx_PyLong_IsNonNeg(op1)) + return 0; + intval = -intval; + } else { + if (__Pyx_PyLong_IsNeg(op1)) + return 0; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + return (unequal == 0); + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; +#if CYTHON_COMPILING_IN_LIMITED_API + double a = __pyx_PyFloat_AsDouble(op1); +#else + double a = PyFloat_AS_DOUBLE(op1); +#endif + return ((double)a == (double)b); + } + return __Pyx_PyObject_IsTrueAndDecref( + PyObject_RichCompare(op1, op2, Py_EQ)); +} + /* CIntToDigits */ static const char DIGIT_PAIRS_10[2*10*10+1] = { "00010203040506070809" @@ -12795,6 +10665,75 @@ static const char DIGITS_HEX[2*16+1] = { return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); } +/* JoinPyUnicode */ + static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind, kind_shift; + Py_ssize_t i, char_pos; + void *result_udata; + CYTHON_MAYBE_UNUSED_VAR(max_char); +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + kind_shift = (result_ukind == 4) ? 2 : result_ukind - 1; + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0); + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift)); + } else { + #if PY_VERSION_HEX >= 0x030d0000 + if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad; + #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + CYTHON_UNUSED_VAR(max_char); + CYTHON_UNUSED_VAR(result_ulength); + CYTHON_UNUSED_VAR(value_count); + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#endif +} + /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_MultiplyObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { @@ -13158,7 +11097,7 @@ static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject * #endif static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { #if PY_MAJOR_VERSION < 3 - PyObject *module, *from_list, *star = __pyx_n_s__10; + PyObject *module, *from_list, *star = __pyx_n_s__8; CYTHON_UNUSED_VAR(parts_tuple); from_list = PyList_New(1); if (unlikely(!from_list)) @@ -13221,7 +11160,7 @@ static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) if (unlikely(!module_name_str)) { goto modbad; } module_name = PyUnicode_FromString(module_name_str); if (unlikely(!module_name)) { goto modbad; } - module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__11); + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__9); if (unlikely(!module_dot)) { goto modbad; } full_name = PyUnicode_Concat(module_dot, name); if (unlikely(!full_name)) { goto modbad; } @@ -16194,7 +14133,7 @@ __Pyx_PyType_GetName(PyTypeObject* tp) if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { PyErr_Clear(); Py_XDECREF(name); - name = __Pyx_NewRef(__pyx_n_s__27); + name = __Pyx_NewRef(__pyx_n_s__21); } return name; } diff --git a/jpeg_ls/_CharLS.pyx b/jpeg_ls/_CharLS.pyx index dd54ca3..652dc01 100644 --- a/jpeg_ls/_CharLS.pyx +++ b/jpeg_ls/_CharLS.pyx @@ -234,7 +234,7 @@ def _decode(src: bytes | bytearray) -> bytearray: return dst -def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: +def decode_from_buffer(src: bytes | bytearray) -> bytearray: """Decode the JPEG-LS codestream `src` to a bytearray Parameters @@ -244,10 +244,10 @@ def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int Returns ------- - tuple[bytearray, dict[str, int]] - The decoded (image data, image metadata). + bytearray + The decoded image data. """ - return _decode(src), read_header(src) + return _decode(src) def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): @@ -285,101 +285,64 @@ def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): return arr.reshape((rows, columns)) -def encode_to_buffer( - arr: np.ndarray, - lossy_error: int = 0, - interleave_mode: int | None = None, +def _encode( + src: bytes, + lossy_error: int, + interleave_mode: int, + rows: int, + columns: int, + samples_per_pixel: int, + bits_stored: int, ) -> bytearray: - """Return the image data in `arr` as a JPEG-LS encoded bytearray. + """Return the image data in `src` as a JPEG-LS encoded bytearray. Parameters ---------- - arr : numpy.ndarray - An ndarray containing the image data. - lossy_error : int, optional + src : bytes + The image data to be JPEG-LS encoded. + lossy_error : int The absolute value of the allowable error when encoding using near-lossless, default ``0`` (lossless). For example, if using 8-bit pixel data then the allowable error for a lossy image may be in the range (1, 255). - interleave_mode : int, optional - The interleaving mode for multi-component (i.e. non-greyscale) images, - default ``0``. One of + interleave_mode : int + Required for multi-sample (i.e. non-greyscale) image data, the + interleaving mode of `src`. One of: - * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn + * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn, + otherwise known as colour-by-plane * ``1``: the pixels in `src` are ordered R1...RwG1...GwB1...BwRw+1... - where w is the width of the image (i.e. the data is ordered line by line) - * ``2``: the pixels in `src` are ordered R1G1B1R2G2B2...RnGnBn - - Having multi-component pixel data ordered to match ``interleave_mode=0`` - should result in the greatest compression ratio, however most - applications expect the pixel order to be ``interleave_mode=2``. + where w is the width of the image, otherwise known as colour-by-line + * ``2``: the pixels in `src` are ordered R1G1B1R2G2B2...RnGnBn, + otherwise known as colour-by-pixel + rows : int + The number of rows of pixels in the image. + columns : int + The number of columns of pixels in the image. + samples_per_pixel : int + The number of samples per pixel in the image, otherwise knows as the + number of components or channels. A greyscale image has 1 sample per + pixel while an RGB image will have 3. + bits_stored : int + The bit-depth per pixel, must be in the range (1, 16). Returns ------- bytearray The encoded JPEG-LS codestream. """ - if arr.dtype == np.uint8: - bytes_per_pixel = 1 - elif arr.dtype == np.uint16: - bytes_per_pixel = 2 - else: - raise ValueError( - f"Invalid input data type '{arr.dtype}', expecting np.uint8 or np.uint16." - ) - - src_length = arr.size * bytes_per_pixel - nr_dims = len(arr.shape) - if nr_dims not in (2, 3): - raise ValueError("Invalid data shape") - - LOGGER.debug( - f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " - f"{bytes_per_pixel} bytes per pixel" - ) - - if nr_dims == 2: - # Greyscale images should always be interleave mode 0 - interleave_mode = 0 - rows = arr.shape[0] - columns = arr.shape[1] - else: - # Multi-component images may be interleave mode 0, 1 or 2 - if arr.shape[-1] in (3, 4): - # Colour-by-pixel (R, C, 3) or (R, C, 4) - # Mode 1 and 2 are identical apparently - interleave_mode = 2 if interleave_mode is None else interleave_mode - elif arr.shape[0] in (3, 4): - # Colour-by-plane (3, R, C) or (4, R, C) - interleave_mode = 0 if interleave_mode is None else interleave_mode - elif interleave_mode is None: - raise ValueError( - "Unable to automatically determine an appropriate 'interleave_mode' " - "value, please set it manually" - ) - - if interleave_mode == 0: - components = arr.shape[0] - rows = arr.shape[1] - columns = arr.shape[2] - else: - rows = arr.shape[0] - columns = arr.shape[1] - components = arr.shape[2] - cdef JlsParameters info = build_parameters() info.height = rows info.width = columns - info.components = components if nr_dims == 3 else 1 + info.components = samples_per_pixel info.interleaveMode = interleave_mode info.allowedLossyError = lossy_error - info.stride = info.width * bytes_per_pixel + info.stride = info.width * math.ceil(bits_stored / 8) if interleave_mode != 0: info.stride = info.stride * info.components - bit_depth = math.ceil(math.log(arr.max() + 1, 2)) - info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth + info.bitsPerSample = 2 if bits_stored < 2 else bits_stored LOGGER.debug( "Encoding paramers are:\n" @@ -393,6 +356,7 @@ def encode_to_buffer( ) # Destination for the compressed data - start out twice the length of raw + src_length = len(src) dst = bytearray(b"\x00" * src_length * 2) # Number of bytes of compressed data @@ -402,10 +366,6 @@ def encode_to_buffer( # As of v2.4.2 the longest string is ~114 chars, so give it a 256 buffer error_message = bytearray(b"\x00" * 256) - # We need a contiguous buffer in the correct interleave mode (i.e. not - # just a re-view via ndarray.transpose()) - src = arr.tobytes() - cdef JLS_ERROR err err = JpegLsEncode( dst, @@ -422,15 +382,3 @@ def encode_to_buffer( raise RuntimeError(f"Encoding error: {msg}") return dst[:compressed_length] - - -def encode( - arr: np.ndarray, - lossy_error: int = 0, - interleave_mode: int | None = None, -) -> np.ndarray: - """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - return np.frombuffer( - encode_to_buffer(arr, lossy_error, interleave_mode), - dtype="u1", - ) diff --git a/jpeg_ls/__init__.py b/jpeg_ls/__init__.py index 4e1ed0d..ca80f83 100644 --- a/jpeg_ls/__init__.py +++ b/jpeg_ls/__init__.py @@ -1,10 +1,22 @@ import logging -from .CharLS import encode, decode, write, read # noqa: F401 -from _CharLS import encode_to_buffer, decode_from_buffer # noqa: F401 +from .CharLS import ( + encode, + decode, + write, + read, + jlswrite, + encode_array, + encode_buffer, + encode_pixel_data, + jlsread, + decode_buffer, + decode_pixel_data, +) +from _CharLS import decode_from_buffer # noqa: F401 -__version__ = "1.1.0" +__version__ = "1.2.0" # Setup default logging diff --git a/jpeg_ls/tests/test_decode.py b/jpeg_ls/tests/test_decode.py index 4e3be0d..da679a2 100644 --- a/jpeg_ls/tests/test_decode.py +++ b/jpeg_ls/tests/test_decode.py @@ -1,9 +1,17 @@ + +import math from pathlib import Path import pytest import numpy as np -from jpeg_ls import decode, read +from jpeg_ls import ( + decode, + read, + jlsread, + decode_buffer, + decode_pixel_data, +) from _CharLS import read_header, decode_from_buffer DATA = Path(__file__).parent / "jlsimV100" @@ -85,8 +93,9 @@ def test_T8C0E0(self, TEST8): def test_T8C0E3(self, TEST8): # TEST8 in colour mode 0, lossy # 3 component, 3 scans, ILV 0, lossy - arr = read(DATA / "T8C0E0.JLS") + arr = read(DATA / "T8C0E3.JLS") assert arr.shape == (256, 256, 3) + assert not np.array_equal(arr, TEST8) assert np.allclose(arr, TEST8, atol=3) def test_T8C1E0(self, TEST8): @@ -97,6 +106,7 @@ def test_T8C1E0(self, TEST8): def test_T8C1E3(self, TEST8): # TEST8 in colour mode 1, lossy arr = read(DATA / "T8C1E3.JLS") + assert not np.array_equal(arr, TEST8) assert np.allclose(arr, TEST8, atol=3) def test_T8C2E0(self, TEST8): @@ -107,6 +117,7 @@ def test_T8C2E0(self, TEST8): def test_T8C2E3(self, TEST8): # TEST8 in colour mode 2, lossy arr = read(DATA / "T8C2E3.JLS") + assert not np.array_equal(arr, TEST8) assert np.allclose(arr, TEST8, atol=3) def test_T8NDE0(self, TEST8BS2): @@ -156,6 +167,340 @@ def test_decode_failure(self): read(DATA / "T8SSE0.JLS") +class TestJLSRead: + """Tests for jlsread()""" + + def test_T8C0E0(self, TEST8): + # TEST8 in colour mode 0, lossless + # 3 component, 3 scans, ILV 0, lossless + arr = jlsread(DATA / "T8C0E0.JLS") + assert arr.shape == (256, 256, 3) + assert np.array_equal(arr, TEST8) + + def test_T8C0E3(self, TEST8): + # TEST8 in colour mode 0, lossy + # 3 component, 3 scans, ILV 0, lossy + arr = jlsread(DATA / "T8C0E3.JLS") + assert arr.shape == (256, 256, 3) + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8C1E0(self, TEST8): + # TEST8 in colour mode 1, lossless + arr = jlsread(DATA / "T8C1E0.JLS") + assert np.array_equal(arr, TEST8) + + def test_T8C1E3(self, TEST8): + # TEST8 in colour mode 1, lossy + arr = jlsread(DATA / "T8C1E3.JLS") + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8C2E0(self, TEST8): + # TEST8 in colour mode 2, lossless + arr = jlsread(DATA / "T8C2E0.JLS") + assert np.array_equal(arr, TEST8) + + def test_T8C2E3(self, TEST8): + # TEST8 in colour mode 2, lossy + arr = jlsread(DATA / "T8C2E3.JLS") + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8NDE0(self, TEST8BS2): + # TEST8 lossless, non-default parameters + arr = jlsread(DATA / "T8NDE0.JLS") + assert np.array_equal(arr, TEST8BS2) + + def test_T8NDE3(self, TEST8BS2): + # TEST8 lossy, non-default parameters + arr = jlsread(DATA / "T8NDE3.JLS") + assert np.allclose(arr, TEST8BS2, atol=3) + + @pytest.mark.xfail + def test_T8SSE0(self, TEST8): + # The JPEG-LS stream is encoded with a parameter value that is not + # supported by the CharLS decoder + # Uses non-default T1, T2, T3 and RESET values (T1=T2=T3=9, RESET=31) + # TEST8 lossless + arr = jlsread(DATA / "T8SSE0.JLS") + assert np.array_equal(arr, TEST8) + + @pytest.mark.xfail + def test_T8SSE3(self, TEST8): + # The JPEG-LS stream is encoded with a parameter value that is not + # supported by the CharLS decoder + # Uses non-default T1, T2, T3 and RESET values (T1=T2=T3=9, RESET=31) + # TEST8 lossy + arr = jlsread(DATA / "T8SSE3.JLS") + assert np.allclose(arr, TEST8, atol=3) + + def test_T16E0(self, TEST16): + # TEST16 lossless + arr = jlsread(DATA / "T16E0.JLS") + assert np.array_equal(arr, TEST16) + + def test_T16E3(self, TEST16): + # TEST16 lossy + arr = jlsread(DATA / "T16E3.JLS") + assert np.allclose(arr, TEST16, atol=3) + + def test_decode_failure(self): + msg = ( + "The JPEG-LS stream is encoded with a parameter value that is not " + "supported by the CharLS decoder" + ) + with pytest.raises(RuntimeError, match=msg): + jlsread(DATA / "T8SSE0.JLS") + + +def as_array(im, info): + bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) + arr = np.frombuffer(im, dtype=f"u{bytes_per_pixel}") + rows = info["height"] + columns = info["width"] + samples_per_pixel = info["components"] + + if info["components"] == 3: + if info["interleave_mode"] == 0: + # ILV 0 is colour-by-plane, needs to be reshaped then transposed + # to colour-by-pixel instead + arr = arr.reshape((samples_per_pixel, rows, columns)) + return arr.transpose(1, 2, 0) + + # Colour-by-pixel, just needs to be reshaped + return arr.reshape((rows, columns, samples_per_pixel)) + + return arr.reshape((rows, columns)) + + +class TestDecodeBuffer: + """Tests for decode_buffer()""" + + def test_T8C0E0(self, TEST8): + # TEST8 in colour mode 0, lossless + # 3 component, 3 scans, ILV 0, lossless + with open(DATA / "T8C0E0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 256 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST8) + + def test_T8C0E3(self, TEST8): + # TEST8 in colour mode 0, lossy + # 3 component, 3 scans, ILV 0, lossy + with open(DATA / "T8C0E3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 256 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8C1E0(self, TEST8): + # TEST8 in colour mode 1, lossless + with open(DATA / "T8C1E0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 768 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 1 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST8) + + def test_T8C1E3(self, TEST8): + # TEST8 in colour mode 1, lossy + with open(DATA / "T8C1E3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 768 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 1 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8C2E0(self, TEST8): + # TEST8 in colour mode 2, lossless + with open(DATA / "T8C2E0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 768 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 2 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST8) + + def test_T8C2E3(self, TEST8): + # TEST8 in colour mode 2, lossy + with open(DATA / "T8C2E3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 3 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 768 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 2 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T8NDE0(self, TEST8BS2): + # TEST8 lossless, non-default parameters + with open(DATA / "T8NDE0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 128 + assert info["width"] == 128 + assert info["components"] == 1 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 128 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST8BS2) + + def test_T8NDE3(self, TEST8BS2): + # TEST8 lossy, non-default parameters + with open(DATA / "T8NDE3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 128 + assert info["width"] == 128 + assert info["components"] == 1 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 128 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST8BS2) + assert np.allclose(arr, TEST8BS2, atol=3) + + @pytest.mark.xfail + def test_T8SSE0(self, TEST8): + # The JPEG-LS stream is encoded with a parameter value that is not + # supported by the CharLS decoder + # Uses non-default T1, T2, T3 and RESET values (T1=T2=T3=9, RESET=31) + # TEST8 lossless + with open(DATA / "T8SSE0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 128 + assert info["width"] == 128 + assert info["components"] == 1 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 128 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST8) + + @pytest.mark.xfail + def test_T8SSE3(self, TEST8): + # The JPEG-LS stream is encoded with a parameter value that is not + # supported by the CharLS decoder + # Uses non-default T1, T2, T3 and RESET values (T1=T2=T3=9, RESET=31) + # TEST8 lossy + with open(DATA / "T8SSE3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 128 + assert info["width"] == 128 + assert info["components"] == 1 + assert info["bits_per_sample"] == 8 + assert info["stride"] == 128 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST8) + assert np.allclose(arr, TEST8, atol=3) + + def test_T16E0(self, TEST16): + # TEST16 lossless + with open(DATA / "T16E0.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 1 + assert info["bits_per_sample"] == 12 + assert info["stride"] == 512 + assert info["allowed_lossy_error"] == 0 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + assert np.array_equal(as_array(im, info), TEST16) + + def test_T16E3(self, TEST16): + # TEST16 lossy + with open(DATA / "T16E3.JLS", "rb") as f: + im, info = decode_buffer(f.read()) + + assert info["height"] == 256 + assert info["width"] == 256 + assert info["components"] == 1 + assert info["bits_per_sample"] == 12 + assert info["stride"] == 512 + assert info["allowed_lossy_error"] == 3 + assert info["interleave_mode"] == 0 + assert info["colour_transformation"] == 0 + + arr = as_array(im, info) + assert not np.array_equal(arr, TEST16) + assert np.allclose(arr, TEST16, atol=3) + + def test_decode_failure(self): + msg = ( + "The JPEG-LS stream is encoded with a parameter value that is not " + "supported by the CharLS decoder" + ) + with pytest.raises(RuntimeError, match=msg): + with open(DATA / "T8SSE0.JLS", "rb") as f: + decode_buffer(f.read()) + + def test_decode(TEST8): """Test decode()""" with open(DATA / "T8C1E0.JLS", "rb") as f: @@ -165,11 +510,30 @@ def test_decode(TEST8): def test_decode_buffer(TEST8): with open(DATA / "T8C1E0.JLS", "rb") as f: - buffer, info = decode_from_buffer(f.read()) - bytes_per_sample = info["bits_per_sample"] // 8 - arr = np.frombuffer(buffer, dtype=f"u{bytes_per_sample}") - arr = arr.reshape(info["height"], info["width"], info["components"]) - assert np.array_equal(arr, TEST8) + im = decode_from_buffer(f.read()) + + info = { + "height": 256, + "width": 256, + "components": 3, + "bits_per_sample": 8, + "interleave_mode": 2, + } + assert np.array_equal(as_array(im, info), TEST8) + + +def test_decode_pixel_data(TEST8): + with open(DATA / "T8C2E0.JLS", "rb") as f: + im = decode_pixel_data(f.read()) + + info = { + "height": 256, + "width": 256, + "components": 3, + "bits_per_sample": 8, + "interleave_mode": 2, + } + assert np.array_equal(as_array(im, info), TEST8) class TestReadHeader: diff --git a/jpeg_ls/tests/test_encode.py b/jpeg_ls/tests/test_encode.py index c4c41d2..c6b5f83 100644 --- a/jpeg_ls/tests/test_encode.py +++ b/jpeg_ls/tests/test_encode.py @@ -1,11 +1,22 @@ -from tempfile import TemporaryDirectory + +import math from pathlib import Path +from tempfile import TemporaryDirectory import pytest import numpy as np -from jpeg_ls import decode, encode, write, read -from _CharLS import encode_to_buffer, decode_from_buffer +from jpeg_ls import ( + decode, + encode, + write, + jlswrite, + encode_array, + encode_buffer, + encode_pixel_data, + jlsread, + decode_buffer, +) DATA = Path(__file__).parent / "jlsimV100" @@ -74,11 +85,11 @@ def TEST16(): return arr.reshape((256, 256)).astype("