From 30d77d9700a1ceb8b70871a97ea1542f2c62c9d5 Mon Sep 17 00:00:00 2001 From: scaramallion Date: Mon, 5 Feb 2024 14:53:23 +1100 Subject: [PATCH] Fixes for decoding ILV0 and encoding multi-component --- jpeg_ls/CharLS.py | 7 +- jpeg_ls/_CharLS.cpp | 3392 +++++++++++++++++++++++----------- jpeg_ls/_CharLS.pyx | 115 +- jpeg_ls/tests/test_decode.py | 23 +- jpeg_ls/tests/test_encode.py | 44 +- pyproject.toml | 2 +- 6 files changed, 2412 insertions(+), 1171 deletions(-) diff --git a/jpeg_ls/CharLS.py b/jpeg_ls/CharLS.py index 2e5dd42..b500abb 100644 --- a/jpeg_ls/CharLS.py +++ b/jpeg_ls/CharLS.py @@ -1,3 +1,6 @@ + +from typing import Union + import numpy as np import _CharLS @@ -19,12 +22,12 @@ def write(fname, data_image): f.write(data_buffer.tobytes()) -def encode(data_image): +def encode(data_image, lossy_error: int = 0, interleave_mode: Union[int, None] = None): """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) + return _CharLS.encode(data_image, lossy_error, interleave_mode) def decode(data_buffer): diff --git a/jpeg_ls/_CharLS.cpp b/jpeg_ls/_CharLS.cpp index 90cb791..2b898e1 100644 --- a/jpeg_ls/_CharLS.cpp +++ b/jpeg_ls/_CharLS.cpp @@ -7,31 +7,31 @@ "/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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h", - "/tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/arrayscalars.h", - "/tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h", - "/tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h", - "/tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ufuncobject.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", "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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/core/include" + "/tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/core/include" ], "language": "c++", "name": "_CharLS", "sources": [ "jpeg_ls/_CharLS.pyx", + "lib/charls/src/version.cpp", + "lib/charls/src/charls_jpegls_decoder.cpp", "lib/charls/src/jpeg_stream_writer.cpp", "lib/charls/src/jpegls_error.cpp", "lib/charls/src/jpegls.cpp", - "lib/charls/src/version.cpp", - "lib/charls/src/validate_spiff_header.cpp", "lib/charls/src/jpeg_stream_reader.cpp", "lib/charls/src/charls_jpegls_encoder.cpp", - "lib/charls/src/charls_jpegls_decoder.cpp" + "lib/charls/src/validate_spiff_header.cpp" ] }, "module_name": "_CharLS" @@ -1582,7 +1582,7 @@ typedef struct { /* #### Code section: numeric_typedefs ### */ -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":731 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":730 * # 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":732 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":731 * * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":733 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":732 * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":734 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":733 * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":738 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":737 * #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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":739 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":738 * * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":740 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":739 * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":741 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":740 * 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":745 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":744 * #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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":746 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":745 * * ctypedef npy_float32 float32_t * ctypedef npy_float64 float64_t # <<<<<<<<<<<<<< @@ -1672,61 +1672,43 @@ typedef npy_float32 __pyx_t_5numpy_float32_t; */ typedef npy_float64 __pyx_t_5numpy_float64_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":755 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":754 * # 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":756 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":755 * # 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-8rseg12z/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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":759 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":757 * 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-8rseg12z/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 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":758 * - */ -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -/* "../../../../../tmp/pip-build-env-8rseg12z/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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":763 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":760 * ctypedef npy_ulonglong ulonglong_t * * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< @@ -1735,7 +1717,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; */ typedef npy_intp __pyx_t_5numpy_intp_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":764 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":761 * * ctypedef npy_intp intp_t * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< @@ -1744,7 +1726,7 @@ typedef npy_intp __pyx_t_5numpy_intp_t; */ typedef npy_uintp __pyx_t_5numpy_uintp_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":766 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":763 * ctypedef npy_uintp uintp_t * * ctypedef npy_double float_t # <<<<<<<<<<<<<< @@ -1753,7 +1735,7 @@ typedef npy_uintp __pyx_t_5numpy_uintp_t; */ typedef npy_double __pyx_t_5numpy_float_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":767 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":764 * * ctypedef npy_double float_t * ctypedef npy_double double_t # <<<<<<<<<<<<<< @@ -1762,7 +1744,7 @@ typedef npy_double __pyx_t_5numpy_float_t; */ typedef npy_double __pyx_t_5numpy_double_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":768 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":765 * ctypedef npy_double float_t * ctypedef npy_double double_t * ctypedef npy_longdouble longdouble_t # <<<<<<<<<<<<<< @@ -1799,7 +1781,7 @@ static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(do /*--- Type declarations ---*/ -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":770 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":767 * ctypedef npy_longdouble longdouble_t * * ctypedef npy_cfloat cfloat_t # <<<<<<<<<<<<<< @@ -1808,7 +1790,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":771 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":768 * * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< @@ -1817,7 +1799,7 @@ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; */ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":772 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":769 * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t * ctypedef npy_clongdouble clongdouble_t # <<<<<<<<<<<<<< @@ -1826,7 +1808,7 @@ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; */ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":774 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":771 * ctypedef npy_clongdouble clongdouble_t * * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< @@ -1836,9 +1818,18 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; 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; - PyObject *__pyx_arg_interleave; +}; +struct __pyx_defaults1 { + PyObject *__pyx_arg_lossy_error; +}; +struct __pyx_defaults2 { + PyObject *__pyx_arg_lossy_error; }; /* #### Code section: utility_code_proto ### */ @@ -2330,6 +2321,9 @@ 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); @@ -2361,9 +2355,6 @@ static PyObject* __Pyx_PyInt_MultiplyObjC(PyObject *op1, PyObject *op2, long int (inplace ? PyNumber_InPlaceMultiply(op1, op2) : PyNumber_Multiply(op1, op2)) #endif -/* ExtTypeTest.proto */ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); - /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto_3_0_8 #define __PYX_HAVE_RT_ImportType_proto_3_0_8 @@ -2793,12 +2784,12 @@ static PyObject *__pyx_builtin_ImportError; 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__8[] = "\n"; -static const char __pyx_k__9[] = "*"; +static const char __pyx_k__9[] = "\n"; 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__24[] = "?"; +static const char __pyx_k__10[] = "*"; +static const char __pyx_k__11[] = "."; +static const char __pyx_k__27[] = "?"; static const char __pyx_k_arr[] = "arr"; static const char __pyx_k_dst[] = "dst"; static const char __pyx_k_err[] = "err"; @@ -2813,6 +2804,7 @@ static const char __pyx_k_info[] = "info"; 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__"; @@ -2835,20 +2827,23 @@ 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_interleave[] = "interleave"; 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"; @@ -2857,6 +2852,7 @@ 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"; @@ -2872,8 +2868,10 @@ static const char __pyx_k_bytes_shaped_as[] = " bytes, shaped as "; 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"; @@ -2885,18 +2883,22 @@ 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_Invalid_interleave_value_must_be[] = "Invalid 'interleave' value, must be 0, 1 or 2"; +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_12__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave); /* proto */ -static PyObject *__pyx_pf_7_CharLS_10encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr); /* 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 */ /* #### Code section: late_includes ### */ /* #### Code section: module_state ### */ typedef struct { @@ -2972,18 +2974,18 @@ typedef struct { PyObject *__pyx_n_s_ImportError; PyObject *__pyx_kp_u_Invalid_data_shape; PyObject *__pyx_kp_u_Invalid_input_data_type; - PyObject *__pyx_kp_u_Invalid_interleave_value_must_be; 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_kp_u__10; - PyObject *__pyx_n_s__24; + PyObject *__pyx_n_s__10; + PyObject *__pyx_kp_u__11; + PyObject *__pyx_n_s__27; PyObject *__pyx_kp_b__3; PyObject *__pyx_kp_b__5; PyObject *__pyx_kp_u__5; - PyObject *__pyx_kp_u__8; - PyObject *__pyx_n_s__9; + PyObject *__pyx_kp_u__9; PyObject *__pyx_n_u_allowed_lossy_error; PyObject *__pyx_n_s_arr; PyObject *__pyx_n_s_asyncio_coroutines; @@ -2998,6 +3000,8 @@ typedef struct { 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; @@ -3009,6 +3013,7 @@ 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; @@ -3020,7 +3025,8 @@ typedef struct { PyObject *__pyx_n_s_info; PyObject *__pyx_n_s_initializing; PyObject *__pyx_n_s_int; - PyObject *__pyx_n_s_interleave; + 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; @@ -3033,8 +3039,10 @@ typedef struct { 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; @@ -3044,6 +3052,8 @@ typedef struct { PyObject *__pyx_n_s_read_header; PyObject *__pyx_n_s_reshape; 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; @@ -3053,6 +3063,8 @@ typedef struct { PyObject *__pyx_n_s_strip; 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; @@ -3064,25 +3076,29 @@ typedef struct { 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__11; + PyObject *__pyx_tuple__8; PyObject *__pyx_tuple__12; - PyObject *__pyx_tuple__14; - PyObject *__pyx_tuple__16; - PyObject *__pyx_tuple__18; - PyObject *__pyx_tuple__20; - PyObject *__pyx_tuple__22; - PyObject *__pyx_codeobj__13; - PyObject *__pyx_codeobj__15; - PyObject *__pyx_codeobj__17; - PyObject *__pyx_codeobj__19; - PyObject *__pyx_codeobj__21; - PyObject *__pyx_codeobj__23; + 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__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 @@ -3153,18 +3169,18 @@ static int __pyx_m_clear(PyObject *m) { 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_kp_u_Invalid_interleave_value_must_be); 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_kp_u__10); - Py_CLEAR(clear_module_state->__pyx_n_s__24); + 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_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__8); - Py_CLEAR(clear_module_state->__pyx_n_s__9); + 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); @@ -3179,6 +3195,8 @@ static int __pyx_m_clear(PyObject *m) { 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); @@ -3190,6 +3208,7 @@ 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); @@ -3201,7 +3220,8 @@ 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_n_s_interleave); + 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); @@ -3214,8 +3234,10 @@ static int __pyx_m_clear(PyObject *m) { 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); @@ -3225,6 +3247,8 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_read_header); Py_CLEAR(clear_module_state->__pyx_n_s_reshape); 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); @@ -3234,6 +3258,8 @@ static int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_n_s_strip); 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); @@ -3245,25 +3271,29 @@ static int __pyx_m_clear(PyObject *m) { 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__11); + Py_CLEAR(clear_module_state->__pyx_tuple__8); Py_CLEAR(clear_module_state->__pyx_tuple__12); - Py_CLEAR(clear_module_state->__pyx_tuple__14); - Py_CLEAR(clear_module_state->__pyx_tuple__16); - Py_CLEAR(clear_module_state->__pyx_tuple__18); - Py_CLEAR(clear_module_state->__pyx_tuple__20); - Py_CLEAR(clear_module_state->__pyx_tuple__22); - Py_CLEAR(clear_module_state->__pyx_codeobj__13); - Py_CLEAR(clear_module_state->__pyx_codeobj__15); - Py_CLEAR(clear_module_state->__pyx_codeobj__17); - Py_CLEAR(clear_module_state->__pyx_codeobj__19); - Py_CLEAR(clear_module_state->__pyx_codeobj__21); - Py_CLEAR(clear_module_state->__pyx_codeobj__23); + 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__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 @@ -3312,18 +3342,18 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { 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_kp_u_Invalid_interleave_value_must_be); 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_kp_u__10); - Py_VISIT(traverse_module_state->__pyx_n_s__24); + 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_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__8); - Py_VISIT(traverse_module_state->__pyx_n_s__9); + 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); @@ -3338,6 +3368,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { 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); @@ -3349,6 +3381,7 @@ 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); @@ -3360,7 +3393,8 @@ 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_n_s_interleave); + 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); @@ -3373,8 +3407,10 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { 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); @@ -3384,6 +3420,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_read_header); Py_VISIT(traverse_module_state->__pyx_n_s_reshape); 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); @@ -3393,6 +3431,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { Py_VISIT(traverse_module_state->__pyx_n_s_strip); 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); @@ -3404,25 +3444,29 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { 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__11); + Py_VISIT(traverse_module_state->__pyx_tuple__8); Py_VISIT(traverse_module_state->__pyx_tuple__12); - Py_VISIT(traverse_module_state->__pyx_tuple__14); - Py_VISIT(traverse_module_state->__pyx_tuple__16); - Py_VISIT(traverse_module_state->__pyx_tuple__18); - Py_VISIT(traverse_module_state->__pyx_tuple__20); - Py_VISIT(traverse_module_state->__pyx_tuple__22); - Py_VISIT(traverse_module_state->__pyx_codeobj__13); - Py_VISIT(traverse_module_state->__pyx_codeobj__15); - Py_VISIT(traverse_module_state->__pyx_codeobj__17); - Py_VISIT(traverse_module_state->__pyx_codeobj__19); - Py_VISIT(traverse_module_state->__pyx_codeobj__21); - Py_VISIT(traverse_module_state->__pyx_codeobj__23); + 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__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 @@ -3499,18 +3543,18 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #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_kp_u_Invalid_interleave_value_must_be __pyx_mstate_global->__pyx_kp_u_Invalid_interleave_value_must_be #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_kp_u__10 __pyx_mstate_global->__pyx_kp_u__10 -#define __pyx_n_s__24 __pyx_mstate_global->__pyx_n_s__24 +#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_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__8 __pyx_mstate_global->__pyx_kp_u__8 -#define __pyx_n_s__9 __pyx_mstate_global->__pyx_n_s__9 +#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 @@ -3525,6 +3569,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #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 @@ -3536,6 +3582,7 @@ 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 @@ -3547,7 +3594,8 @@ 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_n_s_interleave __pyx_mstate_global->__pyx_n_s_interleave +#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 @@ -3560,8 +3608,10 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #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 @@ -3571,6 +3621,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_read_header __pyx_mstate_global->__pyx_n_s_read_header #define __pyx_n_s_reshape __pyx_mstate_global->__pyx_n_s_reshape #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 @@ -3580,6 +3632,8 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #define __pyx_n_s_strip __pyx_mstate_global->__pyx_n_s_strip #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 @@ -3591,28 +3645,32 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #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__11 __pyx_mstate_global->__pyx_tuple__11 +#define __pyx_tuple__8 __pyx_mstate_global->__pyx_tuple__8 #define __pyx_tuple__12 __pyx_mstate_global->__pyx_tuple__12 -#define __pyx_tuple__14 __pyx_mstate_global->__pyx_tuple__14 -#define __pyx_tuple__16 __pyx_mstate_global->__pyx_tuple__16 -#define __pyx_tuple__18 __pyx_mstate_global->__pyx_tuple__18 -#define __pyx_tuple__20 __pyx_mstate_global->__pyx_tuple__20 -#define __pyx_tuple__22 __pyx_mstate_global->__pyx_tuple__22 -#define __pyx_codeobj__13 __pyx_mstate_global->__pyx_codeobj__13 -#define __pyx_codeobj__15 __pyx_mstate_global->__pyx_codeobj__15 -#define __pyx_codeobj__17 __pyx_mstate_global->__pyx_codeobj__17 -#define __pyx_codeobj__19 __pyx_mstate_global->__pyx_codeobj__19 -#define __pyx_codeobj__21 __pyx_mstate_global->__pyx_codeobj__21 -#define __pyx_codeobj__23 __pyx_mstate_global->__pyx_codeobj__23 +#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__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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":245 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":245 * * @property * cdef inline PyObject* base(self) nogil: # <<<<<<<<<<<<<< @@ -3623,7 +3681,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":248 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":248 * """Returns a borrowed reference to the object owning the data/memory. * """ * return PyArray_BASE(self) # <<<<<<<<<<<<<< @@ -3633,7 +3691,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":245 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":245 * * @property * cdef inline PyObject* base(self) nogil: # <<<<<<<<<<<<<< @@ -3646,7 +3704,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_7ndarray_4base_base(PyArrayObject return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":251 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":251 * * @property * cdef inline dtype descr(self): # <<<<<<<<<<<<<< @@ -3660,7 +3718,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":254 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":254 * """Returns an owned reference to the dtype of the array. * """ * return PyArray_DESCR(self) # <<<<<<<<<<<<<< @@ -3673,7 +3731,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":251 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":251 * * @property * cdef inline dtype descr(self): # <<<<<<<<<<<<<< @@ -3688,7 +3746,7 @@ static CYTHON_INLINE PyArray_Descr *__pyx_f_5numpy_7ndarray_5descr_descr(PyArray return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":257 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":257 * * @property * cdef inline int ndim(self) nogil: # <<<<<<<<<<<<<< @@ -3699,7 +3757,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":260 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":260 * """Returns the number of dimensions in the array. * """ * return PyArray_NDIM(self) # <<<<<<<<<<<<<< @@ -3709,7 +3767,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":257 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":257 * * @property * cdef inline int ndim(self) nogil: # <<<<<<<<<<<<<< @@ -3722,7 +3780,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_7ndarray_4ndim_ndim(PyArrayObject *__pyx return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":263 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":263 * * @property * cdef inline npy_intp *shape(self) nogil: # <<<<<<<<<<<<<< @@ -3733,7 +3791,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":268 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":268 * Can return NULL for 0-dimensional arrays. * """ * return PyArray_DIMS(self) # <<<<<<<<<<<<<< @@ -3743,7 +3801,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":263 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":263 * * @property * cdef inline npy_intp *shape(self) nogil: # <<<<<<<<<<<<<< @@ -3756,7 +3814,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_5shape_shape(PyArrayObjec return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":271 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":271 * * @property * cdef inline npy_intp *strides(self) nogil: # <<<<<<<<<<<<<< @@ -3767,7 +3825,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":275 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/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) # <<<<<<<<<<<<<< @@ -3777,7 +3835,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":271 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":271 * * @property * cdef inline npy_intp *strides(self) nogil: # <<<<<<<<<<<<<< @@ -3790,7 +3848,7 @@ static CYTHON_INLINE npy_intp *__pyx_f_5numpy_7ndarray_7strides_strides(PyArrayO return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":278 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":278 * * @property * cdef inline npy_intp size(self) nogil: # <<<<<<<<<<<<<< @@ -3801,7 +3859,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":281 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":281 * """Returns the total size (in number of elements) of the array. * """ * return PyArray_SIZE(self) # <<<<<<<<<<<<<< @@ -3811,7 +3869,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":278 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":278 * * @property * cdef inline npy_intp size(self) nogil: # <<<<<<<<<<<<<< @@ -3824,7 +3882,7 @@ static CYTHON_INLINE npy_intp __pyx_f_5numpy_7ndarray_4size_size(PyArrayObject * return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":284 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":284 * * @property * cdef inline char* data(self) nogil: # <<<<<<<<<<<<<< @@ -3835,7 +3893,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":290 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":290 * of `PyArray_DATA()` instead, which returns a 'void*'. * """ * return PyArray_BYTES(self) # <<<<<<<<<<<<<< @@ -3845,7 +3903,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":284 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":284 * * @property * cdef inline char* data(self) nogil: # <<<<<<<<<<<<<< @@ -3858,7 +3916,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy_7ndarray_4data_data(PyArrayObject *__p return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":776 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":773 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -3875,7 +3933,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":777 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":774 * * cdef inline object PyArray_MultiIterNew1(a): * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< @@ -3883,13 +3941,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, 777, __pyx_L1_error) + __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 774, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":776 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":773 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -3908,7 +3966,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":779 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":776 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -3925,7 +3983,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":780 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":777 * * cdef inline object PyArray_MultiIterNew2(a, b): * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< @@ -3933,13 +3991,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, 780, __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, 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":779 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":776 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -3958,7 +4016,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":782 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":779 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -3975,7 +4033,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":783 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":780 * * cdef inline object PyArray_MultiIterNew3(a, b, c): * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< @@ -3983,13 +4041,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, 783, __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, 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":782 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":779 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -4008,7 +4066,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":785 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":782 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -4025,7 +4083,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":786 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":783 * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< @@ -4033,13 +4091,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, 786, __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, 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":785 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":782 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -4058,7 +4116,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":788 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":785 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -4075,7 +4133,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":789 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":786 * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< @@ -4083,13 +4141,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, 789, __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, 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":788 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":785 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -4108,7 +4166,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":791 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":788 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< @@ -4122,7 +4180,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":792 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":789 * * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< @@ -4132,7 +4190,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":793 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":790 * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): * return d.subarray.shape # <<<<<<<<<<<<<< @@ -4144,7 +4202,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":792 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":789 * * cdef inline tuple PyDataType_SHAPE(dtype d): * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< @@ -4153,7 +4211,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ */ } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":795 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":792 * return d.subarray.shape * else: * return () # <<<<<<<<<<<<<< @@ -4167,7 +4225,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ goto __pyx_L0; } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":791 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":788 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< @@ -4182,7 +4240,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":970 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":968 * int _import_umath() except -1 * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -4191,8 +4249,12 @@ 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":971 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":969 * * cdef inline void set_array_base(ndarray arr, object base): * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< @@ -4201,16 +4263,16 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_INCREF(__pyx_v_base); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":972 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":970 * 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): */ - (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); + __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) - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":970 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":968 * int _import_umath() except -1 * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -4219,9 +4281,13 @@ 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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":974 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":972 * PyArray_SetBaseObject(arr, base) * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -4236,7 +4302,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":975 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":973 * * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< @@ -4245,7 +4311,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":976 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":974 * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) * if base is NULL: # <<<<<<<<<<<<<< @@ -4255,7 +4321,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":977 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":975 * base = PyArray_BASE(arr) * if base is NULL: * return None # <<<<<<<<<<<<<< @@ -4266,7 +4332,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":976 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":974 * cdef inline object get_array_base(ndarray arr): * base = PyArray_BASE(arr) * if base is NULL: # <<<<<<<<<<<<<< @@ -4275,7 +4341,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py */ } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":978 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":976 * if base is NULL: * return None * return base # <<<<<<<<<<<<<< @@ -4287,7 +4353,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":974 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":972 * PyArray_SetBaseObject(arr, base) * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -4302,7 +4368,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":982 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":980 * # Versions of the import_* functions which are more suitable for * # Cython code. * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< @@ -4326,7 +4392,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_array", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4342,16 +4408,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":984 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":982 * 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, 984, __pyx_L3_error) + __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 982, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4365,7 +4431,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":985 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":983 * try: * __pyx_import_array() * except Exception: # <<<<<<<<<<<<<< @@ -4375,27 +4441,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, 985, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 983, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":986 + /* "../../../../../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") # <<<<<<<<<<<<<< * * 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, 986, __pyx_L5_except_error) + __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_GOTREF(__pyx_t_8); __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(1, 986, __pyx_L5_except_error) + __PYX_ERR(1, 984, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":983 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":981 * # Cython code. * cdef inline int import_array() except -1: * try: # <<<<<<<<<<<<<< @@ -4411,7 +4477,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":982 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":980 * # Versions of the import_* functions which are more suitable for * # Cython code. * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< @@ -4434,7 +4500,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":988 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":986 * raise ImportError("numpy.core.multiarray failed to import") * * cdef inline int import_umath() except -1: # <<<<<<<<<<<<<< @@ -4458,7 +4524,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_umath", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4474,16 +4540,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":990 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":988 * 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, 990, __pyx_L3_error) + __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 988, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4497,7 +4563,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":991 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":989 * try: * _import_umath() * except Exception: # <<<<<<<<<<<<<< @@ -4507,27 +4573,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, 991, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 989, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":992 + /* "../../../../../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") # <<<<<<<<<<<<<< * * 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, 992, __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, 990, __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, 992, __pyx_L5_except_error) + __PYX_ERR(1, 990, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":989 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":987 * * cdef inline int import_umath() except -1: * try: # <<<<<<<<<<<<<< @@ -4543,7 +4609,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":988 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":986 * raise ImportError("numpy.core.multiarray failed to import") * * cdef inline int import_umath() except -1: # <<<<<<<<<<<<<< @@ -4566,7 +4632,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":994 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":992 * raise ImportError("numpy.core.umath failed to import") * * cdef inline int import_ufunc() except -1: # <<<<<<<<<<<<<< @@ -4590,7 +4656,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("import_ufunc", 1); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4606,16 +4672,16 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":996 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":994 * 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, 996, __pyx_L3_error) + __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 994, __pyx_L3_error) - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4629,7 +4695,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { goto __pyx_L8_try_end; __pyx_L3_error:; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":997 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":995 * try: * _import_umath() * except Exception: # <<<<<<<<<<<<<< @@ -4639,27 +4705,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, 997, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 995, __pyx_L5_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_7); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":998 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":996 * _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, 998, __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, 996, __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, 998, __pyx_L5_except_error) + __PYX_ERR(1, 996, __pyx_L5_except_error) } goto __pyx_L5_except_error; - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":995 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":993 * * cdef inline int import_ufunc() except -1: * try: # <<<<<<<<<<<<<< @@ -4675,7 +4741,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { __pyx_L8_try_end:; } - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":994 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":992 * raise ImportError("numpy.core.umath failed to import") * * cdef inline int import_ufunc() except -1: # <<<<<<<<<<<<<< @@ -4698,7 +4764,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) { return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1001 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":999 * * * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< @@ -4709,7 +4775,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1013 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1011 * bool * """ * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< @@ -4719,7 +4785,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1001 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":999 * * * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< @@ -4732,7 +4798,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_ return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1016 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1014 * * * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< @@ -4743,7 +4809,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1028 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1026 * bool * """ * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< @@ -4753,7 +4819,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1016 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1014 * * * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< @@ -4766,7 +4832,7 @@ static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_o return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1031 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1029 * * * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4777,7 +4843,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1038 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1036 * also needed. That can be found using `get_datetime64_unit`. * """ * return (obj).obval # <<<<<<<<<<<<<< @@ -4787,7 +4853,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1031 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1029 * * * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4800,7 +4866,7 @@ static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject * return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1041 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1039 * * * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4811,7 +4877,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1045 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1043 * returns the int64 value underlying scalar numpy timedelta64 object * """ * return (obj).obval # <<<<<<<<<<<<<< @@ -4821,7 +4887,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1041 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1039 * * * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< @@ -4834,7 +4900,7 @@ static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject return __pyx_r; } -/* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1048 +/* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1046 * * * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< @@ -4845,7 +4911,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1052 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1050 * returns the unit part of the dtype for a numpy datetime64 object. * """ * return (obj).obmeta.base # <<<<<<<<<<<<<< @@ -4853,7 +4919,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-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":1048 + /* "../../../../../tmp/pip-build-env-1lkp0ni_/overlay/lib/python3.12/site-packages/numpy/__init__.cython-30.pxd":1046 * * * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< @@ -4866,7 +4932,7 @@ static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObjec return __pyx_r; } -/* "_CharLS.pyx":97 +/* "_CharLS.pyx":100 * * * cdef JlsParameters build_parameters(): # <<<<<<<<<<<<<< @@ -4880,7 +4946,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { struct JlsParameters __pyx_v_info; struct JlsParameters __pyx_r; - /* "_CharLS.pyx":100 + /* "_CharLS.pyx":103 * * cdef JpegLSPresetCodingParameters info_custom * info_custom.MaximumSampleValue = 0 # <<<<<<<<<<<<<< @@ -4889,7 +4955,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info_custom.MaximumSampleValue = 0; - /* "_CharLS.pyx":101 + /* "_CharLS.pyx":104 * cdef JpegLSPresetCodingParameters info_custom * info_custom.MaximumSampleValue = 0 * info_custom.Threshold1 = 0 # <<<<<<<<<<<<<< @@ -4898,7 +4964,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info_custom.Threshold1 = 0; - /* "_CharLS.pyx":102 + /* "_CharLS.pyx":105 * info_custom.MaximumSampleValue = 0 * info_custom.Threshold1 = 0 * info_custom.Threshold2 = 0 # <<<<<<<<<<<<<< @@ -4907,7 +4973,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info_custom.Threshold2 = 0; - /* "_CharLS.pyx":103 + /* "_CharLS.pyx":106 * info_custom.Threshold1 = 0 * info_custom.Threshold2 = 0 * info_custom.Threshold3 = 0 # <<<<<<<<<<<<<< @@ -4916,7 +4982,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info_custom.Threshold3 = 0; - /* "_CharLS.pyx":104 + /* "_CharLS.pyx":107 * info_custom.Threshold2 = 0 * info_custom.Threshold3 = 0 * info_custom.ResetValue = 0 # <<<<<<<<<<<<<< @@ -4925,7 +4991,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info_custom.ResetValue = 0; - /* "_CharLS.pyx":107 + /* "_CharLS.pyx":110 * * cdef JfifParameters jfif * jfif.version = 0 # <<<<<<<<<<<<<< @@ -4934,7 +5000,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.version = 0; - /* "_CharLS.pyx":108 + /* "_CharLS.pyx":111 * cdef JfifParameters jfif * jfif.version = 0 * jfif.units = 0 # <<<<<<<<<<<<<< @@ -4943,7 +5009,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.units = 0; - /* "_CharLS.pyx":109 + /* "_CharLS.pyx":112 * jfif.version = 0 * jfif.units = 0 * jfif.Xdensity = 0 # <<<<<<<<<<<<<< @@ -4952,7 +5018,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.Xdensity = 0; - /* "_CharLS.pyx":110 + /* "_CharLS.pyx":113 * jfif.units = 0 * jfif.Xdensity = 0 * jfif.Ydensity = 0 # <<<<<<<<<<<<<< @@ -4961,7 +5027,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.Ydensity = 0; - /* "_CharLS.pyx":111 + /* "_CharLS.pyx":114 * jfif.Xdensity = 0 * jfif.Ydensity = 0 * jfif.Xthumbnail = 0 # <<<<<<<<<<<<<< @@ -4970,7 +5036,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.Xthumbnail = 0; - /* "_CharLS.pyx":112 + /* "_CharLS.pyx":115 * jfif.Ydensity = 0 * jfif.Xthumbnail = 0 * jfif.Ythumbnail = 0 # <<<<<<<<<<<<<< @@ -4979,7 +5045,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_jfif.Ythumbnail = 0; - /* "_CharLS.pyx":116 + /* "_CharLS.pyx":119 * cdef JlsParameters info * * info.width = 0 # <<<<<<<<<<<<<< @@ -4988,7 +5054,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.width = 0; - /* "_CharLS.pyx":117 + /* "_CharLS.pyx":120 * * info.width = 0 * info.height = 0 # <<<<<<<<<<<<<< @@ -4997,7 +5063,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.height = 0; - /* "_CharLS.pyx":118 + /* "_CharLS.pyx":121 * info.width = 0 * info.height = 0 * info.bitsPerSample = 0 # <<<<<<<<<<<<<< @@ -5006,7 +5072,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.bitsPerSample = 0; - /* "_CharLS.pyx":119 + /* "_CharLS.pyx":122 * info.height = 0 * info.bitsPerSample = 0 * info.stride = 0 # <<<<<<<<<<<<<< @@ -5015,7 +5081,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.stride = 0; - /* "_CharLS.pyx":121 + /* "_CharLS.pyx":124 * info.stride = 0 * # number of components (RGB = 3, RGBA = 4, monochrome = 1; * info.components = 1 # <<<<<<<<<<<<<< @@ -5024,26 +5090,26 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.components = 1; - /* "_CharLS.pyx":123 + /* "_CharLS.pyx":126 * info.components = 1 * # 0 means lossless * info.allowedLossyError = 0 # <<<<<<<<<<<<<< * # For monochrome images, always use ILV_NONE. - * info.interleaveMode = 0 + * info.interleaveMode = 0 */ __pyx_v_info.allowedLossyError = 0; - /* "_CharLS.pyx":125 + /* "_CharLS.pyx":128 * info.allowedLossyError = 0 * # For monochrome images, always use ILV_NONE. - * info.interleaveMode = 0 # <<<<<<<<<<<<<< + * info.interleaveMode = 0 # <<<<<<<<<<<<<< * # 0 means no color transform * info.colorTransformation = 0 */ __pyx_v_info.interleaveMode = ((enum charls::interleave_mode)0); - /* "_CharLS.pyx":127 - * info.interleaveMode = 0 + /* "_CharLS.pyx":130 + * info.interleaveMode = 0 * # 0 means no color transform * info.colorTransformation = 0 # <<<<<<<<<<<<<< * info.outputBgr = 0 # when set to true, CharLS will reverse the normal RGB @@ -5051,7 +5117,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.colorTransformation = ((enum charls::color_transformation)0); - /* "_CharLS.pyx":128 + /* "_CharLS.pyx":131 * # 0 means no color transform * info.colorTransformation = 0 * info.outputBgr = 0 # when set to true, CharLS will reverse the normal RGB # <<<<<<<<<<<<<< @@ -5060,7 +5126,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.outputBgr = 0; - /* "_CharLS.pyx":129 + /* "_CharLS.pyx":132 * info.colorTransformation = 0 * info.outputBgr = 0 # when set to true, CharLS will reverse the normal RGB * info.custom = info_custom # <<<<<<<<<<<<<< @@ -5069,18 +5135,18 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { */ __pyx_v_info.custom = __pyx_v_info_custom; - /* "_CharLS.pyx":130 + /* "_CharLS.pyx":133 * info.outputBgr = 0 # when set to true, CharLS will reverse the normal RGB * info.custom = info_custom * info.jfif = jfif # <<<<<<<<<<<<<< * - * # Done. + * return info */ __pyx_v_info.jfif = __pyx_v_jfif; - /* "_CharLS.pyx":133 + /* "_CharLS.pyx":135 + * info.jfif = jfif * - * # Done. * return info # <<<<<<<<<<<<<< * * @@ -5088,7 +5154,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { __pyx_r = __pyx_v_info; goto __pyx_L0; - /* "_CharLS.pyx":97 + /* "_CharLS.pyx":100 * * * cdef JlsParameters build_parameters(): # <<<<<<<<<<<<<< @@ -5101,7 +5167,7 @@ static struct JlsParameters __pyx_f_7_CharLS_build_parameters(void) { return __pyx_r; } -/* "_CharLS.pyx":136 +/* "_CharLS.pyx":138 * * * cdef JlsParameters _read_header(bytes buffer): # <<<<<<<<<<<<<< @@ -5133,7 +5199,7 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_read_header", 1); - /* "_CharLS.pyx":145 + /* "_CharLS.pyx":147 * """ * # Size of input image, point to buffer. * cdef int size_buffer = len(buffer) # <<<<<<<<<<<<<< @@ -5142,22 +5208,22 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff */ if (unlikely(__pyx_v_buffer == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 145, __pyx_L1_error) + __PYX_ERR(0, 147, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyBytes_GET_SIZE(__pyx_v_buffer); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 145, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_GET_SIZE(__pyx_v_buffer); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 147, __pyx_L1_error) __pyx_v_size_buffer = __pyx_t_1; - /* "_CharLS.pyx":148 + /* "_CharLS.pyx":150 * * # Setup parameter structure. * cdef JlsParameters info = build_parameters() # <<<<<<<<<<<<<< * * # Pointers to input and output data. */ - __pyx_t_2 = __pyx_f_7_CharLS_build_parameters(); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __pyx_f_7_CharLS_build_parameters(); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 150, __pyx_L1_error) __pyx_v_info = __pyx_t_2; - /* "_CharLS.pyx":151 + /* "_CharLS.pyx":153 * * # Pointers to input and output data. * cdef char* data_buffer_ptr = buffer # <<<<<<<<<<<<<< @@ -5166,12 +5232,12 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff */ if (unlikely(__pyx_v_buffer == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 151, __pyx_L1_error) + __PYX_ERR(0, 153, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_buffer); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 151, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_buffer); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 153, __pyx_L1_error) __pyx_v_data_buffer_ptr = ((char *)__pyx_t_3); - /* "_CharLS.pyx":152 + /* "_CharLS.pyx":154 * # Pointers to input and output data. * cdef char* data_buffer_ptr = buffer * cdef JlsParameters* info_ptr = &info # <<<<<<<<<<<<<< @@ -5180,29 +5246,29 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff */ __pyx_v_info_ptr = (&__pyx_v_info); - /* "_CharLS.pyx":156 + /* "_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 * */ - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_err_msg = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "_CharLS.pyx":157 + /* "_CharLS.pyx":159 * # 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 # <<<<<<<<<<<<<< * * # Read the header. */ - __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_err_msg); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_err_msg); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 159, __pyx_L1_error) __pyx_v_error_message = ((char *)__pyx_t_3); - /* "_CharLS.pyx":161 + /* "_CharLS.pyx":163 * # Read the header. * cdef JLS_ERROR err * err = JpegLsReadHeader( # <<<<<<<<<<<<<< @@ -5211,7 +5277,7 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff */ __pyx_v_err = JpegLsReadHeader(__pyx_v_data_buffer_ptr, __pyx_v_size_buffer, __pyx_v_info_ptr, __pyx_v_error_message); - /* "_CharLS.pyx":168 + /* "_CharLS.pyx":170 * ) * * if err != 0: # <<<<<<<<<<<<<< @@ -5221,16 +5287,16 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff __pyx_t_5 = (((int)__pyx_v_err) != 0); if (unlikely(__pyx_t_5)) { - /* "_CharLS.pyx":169 + /* "_CharLS.pyx":171 * * if err != 0: * error = err_msg.decode("ascii").strip("\0") # <<<<<<<<<<<<<< * raise RuntimeError(f"Decoding error: {error}") * */ - __pyx_t_6 = __Pyx_decode_bytearray(__pyx_v_err_msg, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_6 = __Pyx_decode_bytearray(__pyx_v_err_msg, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_strip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_strip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -5251,33 +5317,33 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_kp_u__5}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 169, __pyx_L1_error) + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __pyx_v_error = __pyx_t_4; __pyx_t_4 = 0; - /* "_CharLS.pyx":170 + /* "_CharLS.pyx":172 * if err != 0: * error = err_msg.decode("ascii").strip("\0") * raise RuntimeError(f"Decoding error: {error}") # <<<<<<<<<<<<<< * * return info */ - __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_error, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_error, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Decoding_error, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Decoding_error, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 170, __pyx_L1_error) + __PYX_ERR(0, 172, __pyx_L1_error) - /* "_CharLS.pyx":168 + /* "_CharLS.pyx":170 * ) * * if err != 0: # <<<<<<<<<<<<<< @@ -5286,7 +5352,7 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff */ } - /* "_CharLS.pyx":172 + /* "_CharLS.pyx":174 * raise RuntimeError(f"Decoding error: {error}") * * return info # <<<<<<<<<<<<<< @@ -5296,7 +5362,7 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff __pyx_r = __pyx_v_info; goto __pyx_L0; - /* "_CharLS.pyx":136 + /* "_CharLS.pyx":138 * * * cdef JlsParameters _read_header(bytes buffer): # <<<<<<<<<<<<<< @@ -5318,7 +5384,7 @@ static struct JlsParameters __pyx_f_7_CharLS__read_header(PyObject *__pyx_v_buff return __pyx_r; } -/* "_CharLS.pyx":175 +/* "_CharLS.pyx":177 * * * def read_header(src: bytes | bytearray) -> Dict[str, int]: # <<<<<<<<<<<<<< @@ -5380,12 +5446,12 @@ PyObject *__pyx_args, PyObject *__pyx_kwds (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 175, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 177, __pyx_L3_error) else goto __pyx_L5_argtuple_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, "read_header") < 0)) __PYX_ERR(0, 175, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "read_header") < 0)) __PYX_ERR(0, 177, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; @@ -5396,7 +5462,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("read_header", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 175, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("read_header", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 177, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -5435,20 +5501,20 @@ static PyObject *__pyx_pf_7_CharLS_read_header(CYTHON_UNUSED PyObject *__pyx_sel int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_header", 1); - /* "_CharLS.pyx":178 + /* "_CharLS.pyx":180 * """Return a dict containing information about the JPEG-LS file.""" * # info: JlsParameters * info = _read_header(bytes(src)) # <<<<<<<<<<<<<< * return { * "width": info.width, */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_src); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 178, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_src); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_7_CharLS__read_header(((PyObject*)__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 178, __pyx_L1_error) + __pyx_t_2 = __pyx_f_7_CharLS__read_header(((PyObject*)__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_info = __pyx_t_2; - /* "_CharLS.pyx":179 + /* "_CharLS.pyx":181 * # info: JlsParameters * info = _read_header(bytes(src)) * return { # <<<<<<<<<<<<<< @@ -5457,108 +5523,108 @@ static PyObject *__pyx_pf_7_CharLS_read_header(CYTHON_UNUSED PyObject *__pyx_sel */ __Pyx_XDECREF(__pyx_r); - /* "_CharLS.pyx":180 + /* "_CharLS.pyx":182 * info = _read_header(bytes(src)) * return { * "width": info.width, # <<<<<<<<<<<<<< * "height": info.height, * "bits_per_sample": info.bitsPerSample, */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_width, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_width, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":181 + /* "_CharLS.pyx":183 * return { * "width": info.width, * "height": info.height, # <<<<<<<<<<<<<< * "bits_per_sample": info.bitsPerSample, * "stride": info.stride, */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.height); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 181, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.height); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_height, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_height, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":182 + /* "_CharLS.pyx":184 * "width": info.width, * "height": info.height, * "bits_per_sample": info.bitsPerSample, # <<<<<<<<<<<<<< * "stride": info.stride, * "components": info.components, */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.bitsPerSample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.bitsPerSample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_bits_per_sample, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_bits_per_sample, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":183 + /* "_CharLS.pyx":185 * "height": info.height, * "bits_per_sample": info.bitsPerSample, * "stride": info.stride, # <<<<<<<<<<<<<< * "components": info.components, * "allowed_lossy_error": info.allowedLossyError, */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.stride); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.stride); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_stride, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_stride, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":184 + /* "_CharLS.pyx":186 * "bits_per_sample": info.bitsPerSample, * "stride": info.stride, * "components": info.components, # <<<<<<<<<<<<<< * "allowed_lossy_error": info.allowedLossyError, * "interleave_mode": info.interleaveMode, */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.components); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.components); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_components, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_components, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":185 + /* "_CharLS.pyx":187 * "stride": info.stride, * "components": info.components, * "allowed_lossy_error": info.allowedLossyError, # <<<<<<<<<<<<<< * "interleave_mode": info.interleaveMode, * "colour_transformation": info.colorTransformation, */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.allowedLossyError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_info.allowedLossyError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_allowed_lossy_error, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_allowed_lossy_error, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":186 + /* "_CharLS.pyx":188 * "components": info.components, * "allowed_lossy_error": info.allowedLossyError, * "interleave_mode": info.interleaveMode, # <<<<<<<<<<<<<< * "colour_transformation": info.colorTransformation, * } */ - __pyx_t_3 = __Pyx_PyInt_From_enum__charls_3a__3a_interleave_mode(__pyx_v_info.interleaveMode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 186, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_enum__charls_3a__3a_interleave_mode(__pyx_v_info.interleaveMode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_interleave_mode, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_interleave_mode, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "_CharLS.pyx":187 + /* "_CharLS.pyx":189 * "allowed_lossy_error": info.allowedLossyError, * "interleave_mode": info.interleaveMode, * "colour_transformation": info.colorTransformation, # <<<<<<<<<<<<<< * } * */ - __pyx_t_3 = __Pyx_PyInt_From_enum__charls_3a__3a_color_transformation(__pyx_v_info.colorTransformation); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_enum__charls_3a__3a_color_transformation(__pyx_v_info.colorTransformation); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 189, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_colour_transformation, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_colour_transformation, __pyx_t_3) < 0) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; - /* "_CharLS.pyx":175 + /* "_CharLS.pyx":177 * * * def read_header(src: bytes | bytearray) -> Dict[str, int]: # <<<<<<<<<<<<<< @@ -5578,11 +5644,11 @@ static PyObject *__pyx_pf_7_CharLS_read_header(CYTHON_UNUSED PyObject *__pyx_sel return __pyx_r; } -/* "_CharLS.pyx":191 +/* "_CharLS.pyx":193 * * * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -5594,7 +5660,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_2_decode, "Decode the JPEG-LS codestream `src`\n\n Parameters\n ----------\n src : bytes\n The JPEG-LS codestream to be decoded.\n\n Returns\n -------\n bytearray\n The decoded image data.\n "); +PyDoc_STRVAR(__pyx_doc_7_CharLS_2_decode, "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_3_decode = {"_decode", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_3_decode, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_2_decode}; static PyObject *__pyx_pw_7_CharLS_3_decode(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL @@ -5640,12 +5706,12 @@ PyObject *__pyx_args, PyObject *__pyx_kwds (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 191, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 193, __pyx_L3_error) else goto __pyx_L5_argtuple_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, "_decode") < 0)) __PYX_ERR(0, 191, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_decode") < 0)) __PYX_ERR(0, 193, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; @@ -5656,7 +5722,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_decode", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 191, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_decode", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 193, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -5711,7 +5777,7 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_RefNannySetupContext("_decode", 0); __Pyx_INCREF(__pyx_v_src); - /* "_CharLS.pyx":204 + /* "_CharLS.pyx":206 * The decoded image data. * """ * if isinstance(src, bytearray): # <<<<<<<<<<<<<< @@ -5721,19 +5787,19 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_1 = PyByteArray_Check(__pyx_v_src); if (__pyx_t_1) { - /* "_CharLS.pyx":205 + /* "_CharLS.pyx":207 * """ * if isinstance(src, bytearray): * src = bytes(src) # <<<<<<<<<<<<<< * * info = _read_header(src) */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_src); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_src); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 207, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_src, __pyx_t_2); __pyx_t_2 = 0; - /* "_CharLS.pyx":204 + /* "_CharLS.pyx":206 * The decoded image data. * """ * if isinstance(src, bytearray): # <<<<<<<<<<<<<< @@ -5742,30 +5808,30 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, */ } - /* "_CharLS.pyx":207 + /* "_CharLS.pyx":209 * src = bytes(src) * * info = _read_header(src) # <<<<<<<<<<<<<< * * bytes_per_pixel = math.ceil(info.bitsPerSample / 8) */ - if (!(likely(PyBytes_CheckExact(__pyx_v_src))||((__pyx_v_src) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_v_src))) __PYX_ERR(0, 207, __pyx_L1_error) - __pyx_t_3 = __pyx_f_7_CharLS__read_header(((PyObject*)__pyx_v_src)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 207, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_v_src))||((__pyx_v_src) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytes", __pyx_v_src))) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_3 = __pyx_f_7_CharLS__read_header(((PyObject*)__pyx_v_src)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 209, __pyx_L1_error) __pyx_v_info = __pyx_t_3; - /* "_CharLS.pyx":209 + /* "_CharLS.pyx":211 * info = _read_header(src) * * bytes_per_pixel = math.ceil(info.bitsPerSample / 8) # <<<<<<<<<<<<<< * dst_length = info.width * info.height * info.components * bytes_per_pixel * dst = bytearray(b"\x00" * dst_length) */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_math); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_math); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ceil); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ceil); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyFloat_FromDouble((((double)__pyx_v_info.bitsPerSample) / 8.0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_4 = PyFloat_FromDouble((((double)__pyx_v_info.bitsPerSample) / 8.0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = NULL; __pyx_t_7 = 0; @@ -5786,101 +5852,101 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_v_bytes_per_pixel = __pyx_t_2; __pyx_t_2 = 0; - /* "_CharLS.pyx":210 + /* "_CharLS.pyx":212 * * bytes_per_pixel = math.ceil(info.bitsPerSample / 8) * dst_length = info.width * info.height * info.components * bytes_per_pixel # <<<<<<<<<<<<<< * dst = bytearray(b"\x00" * dst_length) * */ - __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_info.width * __pyx_v_info.height) * __pyx_v_info.components)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_info.width * __pyx_v_info.height) * __pyx_v_info.components)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 210, __pyx_L1_error) + __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_v_bytes_per_pixel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_dst_length = __pyx_t_5; __pyx_t_5 = 0; - /* "_CharLS.pyx":211 + /* "_CharLS.pyx":213 * bytes_per_pixel = math.ceil(info.bitsPerSample / 8) * dst_length = info.width * info.height * info.components * bytes_per_pixel * dst = bytearray(b"\x00" * dst_length) # <<<<<<<<<<<<<< * * # Error strings are defined in jpegls_error.cpp */ - __pyx_t_5 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_dst_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_5 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_dst_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_dst = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "_CharLS.pyx":215 + /* "_CharLS.pyx":217 * # 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) # <<<<<<<<<<<<<< * * # Decode compressed data. */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_error_message = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "_CharLS.pyx":220 + /* "_CharLS.pyx":222 * cdef JLS_ERROR err * err = JpegLsDecode( * dst, # <<<<<<<<<<<<<< * dst_length, * src, */ - __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_dst); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_dst); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) - /* "_CharLS.pyx":221 + /* "_CharLS.pyx":223 * err = JpegLsDecode( * dst, * dst_length, # <<<<<<<<<<<<<< * src, * len(src), */ - __pyx_t_9 = __Pyx_PyInt_As_size_t(__pyx_v_dst_length); if (unlikely((__pyx_t_9 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_As_size_t(__pyx_v_dst_length); if (unlikely((__pyx_t_9 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L1_error) - /* "_CharLS.pyx":222 + /* "_CharLS.pyx":224 * dst, * dst_length, * src, # <<<<<<<<<<<<<< * len(src), * &info, */ - __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_src); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_src); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 224, __pyx_L1_error) - /* "_CharLS.pyx":223 + /* "_CharLS.pyx":225 * dst_length, * src, * len(src), # <<<<<<<<<<<<<< * &info, * error_message */ - __pyx_t_11 = PyObject_Length(__pyx_v_src); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_11 = PyObject_Length(__pyx_v_src); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 225, __pyx_L1_error) - /* "_CharLS.pyx":225 + /* "_CharLS.pyx":227 * len(src), * &info, * error_message # <<<<<<<<<<<<<< * ) * */ - __pyx_t_12 = __Pyx_PyObject_AsWritableString(__pyx_v_error_message); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 225, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyObject_AsWritableString(__pyx_v_error_message); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 227, __pyx_L1_error) - /* "_CharLS.pyx":219 + /* "_CharLS.pyx":221 * # Decode compressed data. * cdef JLS_ERROR err * err = JpegLsDecode( # <<<<<<<<<<<<<< @@ -5889,7 +5955,7 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, */ __pyx_v_err = JpegLsDecode(((char *)__pyx_t_8), __pyx_t_9, ((char *)__pyx_t_10), __pyx_t_11, (&__pyx_v_info), ((char *)__pyx_t_12)); - /* "_CharLS.pyx":228 + /* "_CharLS.pyx":230 * ) * * if err != 0: # <<<<<<<<<<<<<< @@ -5899,16 +5965,16 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_1 = (((int)__pyx_v_err) != 0); if (unlikely(__pyx_t_1)) { - /* "_CharLS.pyx":229 + /* "_CharLS.pyx":231 * * if err != 0: * msg = error_message.decode("ascii").strip("\0") # <<<<<<<<<<<<<< * raise RuntimeError(f"Decoding error: {msg}") * */ - __pyx_t_5 = __Pyx_decode_bytearray(__pyx_v_error_message, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 229, __pyx_L1_error) + __pyx_t_5 = __Pyx_decode_bytearray(__pyx_v_error_message, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 229, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = NULL; @@ -5929,33 +5995,33 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_kp_u__5}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_v_msg = __pyx_t_2; __pyx_t_2 = 0; - /* "_CharLS.pyx":230 + /* "_CharLS.pyx":232 * if err != 0: * msg = error_message.decode("ascii").strip("\0") * raise RuntimeError(f"Decoding error: {msg}") # <<<<<<<<<<<<<< * * return dst */ - __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_msg, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_msg, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Decoding_error, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Decoding_error, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 230, __pyx_L1_error) + __PYX_ERR(0, 232, __pyx_L1_error) - /* "_CharLS.pyx":228 + /* "_CharLS.pyx":230 * ) * * if err != 0: # <<<<<<<<<<<<<< @@ -5964,7 +6030,7 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, */ } - /* "_CharLS.pyx":232 + /* "_CharLS.pyx":234 * raise RuntimeError(f"Decoding error: {msg}") * * return dst # <<<<<<<<<<<<<< @@ -5976,11 +6042,11 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, __pyx_r = __pyx_v_dst; goto __pyx_L0; - /* "_CharLS.pyx":191 + /* "_CharLS.pyx":193 * * * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -6004,11 +6070,11 @@ static PyObject *__pyx_pf_7_CharLS_2_decode(CYTHON_UNUSED PyObject *__pyx_self, return __pyx_r; } -/* "_CharLS.pyx":235 +/* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -6020,7 +6086,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`\n\n Parameters\n ----------\n src : bytes\n The JPEG-LS codestream to be decoded.\n\n Returns\n -------\n bytearray\n The decoded image data.\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 tuple[bytearray, dict[str, int]]\n The decoded (image data, image metadata).\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 @@ -6066,12 +6132,12 @@ PyObject *__pyx_args, PyObject *__pyx_kwds (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 235, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L3_error) else goto __pyx_L5_argtuple_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, "decode_from_buffer") < 0)) __PYX_ERR(0, 235, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "decode_from_buffer") < 0)) __PYX_ERR(0, 237, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; @@ -6082,7 +6148,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("decode_from_buffer", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 235, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("decode_from_buffer", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 237, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -6116,20 +6182,21 @@ 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":248 - * The decoded image data. + /* "_CharLS.pyx":250 + * The decoded (image data, image metadata). * """ - * return _decode(src) # <<<<<<<<<<<<<< + * return _decode(src), read_header(src) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; __pyx_t_4 = 0; @@ -6149,20 +6216,51 @@ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *_ PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_src}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 250, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - if (!(likely(PyByteArray_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("bytearray", __pyx_t_1))) __PYX_ERR(0, 248, __pyx_L1_error) - __pyx_r = ((PyObject*)__pyx_t_1); + __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); __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; goto __pyx_L0; - /* "_CharLS.pyx":235 + /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream `src` to a bytearray * */ @@ -6171,6 +6269,7 @@ 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:; @@ -6179,11 +6278,11 @@ static PyObject *__pyx_pf_7_CharLS_4decode_from_buffer(CYTHON_UNUSED PyObject *_ return __pyx_r; } -/* "_CharLS.pyx":251 +/* "_CharLS.pyx":253 * * * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream in the ndarray `data_buffer` * */ @@ -6195,7 +6294,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_6decode, "Decode the JPEG-LS codestream `src`\n\n Parameters\n ----------\n data_buffer : numpy.ndarray\n The JPEG-LS codestream to be decoded as 1 dimensional ndarray of uint8.\n\n Returns\n -------\n numpy.ndarray\n The decoded image.\n "); +PyDoc_STRVAR(__pyx_doc_7_CharLS_6decode, "Decode the JPEG-LS codestream in the ndarray `data_buffer`\n\n Parameters\n ----------\n data_buffer : numpy.ndarray\n The JPEG-LS codestream to be decoded as 1 dimensional ndarray of uint8.\n\n Returns\n -------\n numpy.ndarray\n The decoded image.\n "); static PyMethodDef __pyx_mdef_7_CharLS_7decode = {"decode", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_7decode, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_6decode}; static PyObject *__pyx_pw_7_CharLS_7decode(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL @@ -6241,12 +6340,12 @@ PyObject *__pyx_args, PyObject *__pyx_kwds (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 253, __pyx_L3_error) else goto __pyx_L5_argtuple_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, "decode") < 0)) __PYX_ERR(0, 251, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "decode") < 0)) __PYX_ERR(0, 253, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; @@ -6257,7 +6356,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("decode", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 251, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("decode", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 253, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -6271,7 +6370,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data_buffer), __pyx_ptype_5numpy_ndarray, 1, "data_buffer", 0))) __PYX_ERR(0, 251, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data_buffer), __pyx_ptype_5numpy_ndarray, 1, "data_buffer", 0))) __PYX_ERR(0, 253, __pyx_L1_error) __pyx_r = __pyx_pf_7_CharLS_6decode(__pyx_self, __pyx_v_data_buffer); /* function exit code */ @@ -6294,6 +6393,9 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P PyObject *__pyx_v_info = NULL; PyObject *__pyx_v_bytes_per_pixel = NULL; PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_v_rows = NULL; + PyObject *__pyx_v_columns = NULL; + PyObject *__pyx_v_samples_per_pixel = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_data_buffer; __Pyx_Buffer __pyx_pybuffer_data_buffer; PyObject *__pyx_r = NULL; @@ -6315,18 +6417,18 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P __pyx_pybuffernd_data_buffer.rcbuffer = &__pyx_pybuffer_data_buffer; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_data_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 251, __pyx_L1_error) + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_data_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 253, __pyx_L1_error) } __pyx_pybuffernd_data_buffer.diminfo[0].strides = __pyx_pybuffernd_data_buffer.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data_buffer.diminfo[0].shape = __pyx_pybuffernd_data_buffer.rcbuffer->pybuffer.shape[0]; - /* "_CharLS.pyx":265 + /* "_CharLS.pyx":266 + * The decoded image. * """ - * * src = data_buffer.tobytes() # <<<<<<<<<<<<<< * * info = read_header(src) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_data_buffer), __pyx_n_s_tobytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 265, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_data_buffer), __pyx_n_s_tobytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; __pyx_t_4 = 0; @@ -6346,21 +6448,21 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_v_src = __pyx_t_1; __pyx_t_1 = 0; - /* "_CharLS.pyx":267 + /* "_CharLS.pyx":268 * src = data_buffer.tobytes() * * info = read_header(src) # <<<<<<<<<<<<<< * bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_header); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_header); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; __pyx_t_4 = 0; @@ -6380,28 +6482,28 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_src}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 267, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_v_info = __pyx_t_1; __pyx_t_1 = 0; - /* "_CharLS.pyx":268 + /* "_CharLS.pyx":269 * * info = read_header(src) * bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) # <<<<<<<<<<<<<< * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") - * + * rows = info["height"] */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_math); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_math); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ceil); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ceil); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_bits_per_sample); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_bits_per_sample); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyInt_TrueDivideObjC(__pyx_t_2, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_TrueDivideObjC(__pyx_t_2, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; @@ -6423,26 +6525,26 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_v_bytes_per_pixel = __pyx_t_1; __pyx_t_1 = 0; - /* "_CharLS.pyx":269 + /* "_CharLS.pyx":270 * info = read_header(src) * bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") # <<<<<<<<<<<<<< - * - * if info["components"] == 3: + * rows = info["height"] + * columns = info["width"] */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_decode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_decode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = NULL; __pyx_t_4 = 0; @@ -6462,25 +6564,25 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_src}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1)) __PYX_ERR(0, 270, __pyx_L1_error); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_bytes_per_pixel, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_bytes_per_pixel, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_n_u_u, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_n_u_u, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 269, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -6489,133 +6591,246 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P __pyx_t_6 = 0; /* "_CharLS.pyx":271 + * bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) + * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") + * rows = info["height"] # <<<<<<<<<<<<<< + * columns = info["width"] + * samples_per_pixel = info["components"] + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_height); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_rows = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_CharLS.pyx":272 * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") + * rows = info["height"] + * columns = info["width"] # <<<<<<<<<<<<<< + * samples_per_pixel = info["components"] * - * if info["components"] == 3: # <<<<<<<<<<<<<< - * return arr.reshape((info["height"], info["width"], 3)) + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_width); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 272, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_columns = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_CharLS.pyx":273 + * rows = info["height"] + * columns = info["width"] + * samples_per_pixel = info["components"] # <<<<<<<<<<<<<< + * + * if info["components"] == 3: + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_components); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_samples_per_pixel = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_CharLS.pyx":275 + * 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 */ - __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_components); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 271, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_components); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_6, __pyx_int_3, 3, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 271, __pyx_L1_error) + __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_6, __pyx_int_3, 3, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 275, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_7) { - /* "_CharLS.pyx":272 + /* "_CharLS.pyx":276 + * + * 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 + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_interleave_mode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 276, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_6, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 276, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_7) { + + /* "_CharLS.pyx":279 + * # 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) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_reshape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_samples_per_pixel); + __Pyx_GIVEREF(__pyx_v_samples_per_pixel); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_samples_per_pixel)) __PYX_ERR(0, 279, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_rows); + __Pyx_GIVEREF(__pyx_v_rows); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_rows)) __PYX_ERR(0, 279, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_columns); + __Pyx_GIVEREF(__pyx_v_columns); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_columns)) __PYX_ERR(0, 279, __pyx_L1_error); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(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); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_4 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF_SET(__pyx_v_arr, __pyx_t_6); + __pyx_t_6 = 0; + + /* "_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 + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_transpose); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_CharLS.pyx":276 * * if info["components"] == 3: - * return arr.reshape((info["height"], info["width"], 3)) # <<<<<<<<<<<<<< + * if info["interleave_mode"] == 0: # <<<<<<<<<<<<<< + * # ILV 0 is colour-by-plane, needs to be reshaped then transposed + * # to colour-by-pixel instead + */ + } + + /* "_CharLS.pyx":283 * - * return arr.reshape((info["height"], info["width"])) + * # Colour-by-pixel, just needs to be reshaped + * return arr.reshape((rows, columns, samples_per_pixel)) # <<<<<<<<<<<<<< + * + * return arr.reshape((rows, columns)) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_reshape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_height); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 272, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_reshape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 283, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5)) __PYX_ERR(0, 272, __pyx_L1_error); - __Pyx_GIVEREF(__pyx_t_3); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error); - __Pyx_INCREF(__pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_3)) __PYX_ERR(0, 272, __pyx_L1_error); - __pyx_t_5 = 0; - __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_rows); + __Pyx_GIVEREF(__pyx_v_rows); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_rows)) __PYX_ERR(0, 283, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_columns); + __Pyx_GIVEREF(__pyx_v_columns); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_columns)) __PYX_ERR(0, 283, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_samples_per_pixel); + __Pyx_GIVEREF(__pyx_v_samples_per_pixel); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_samples_per_pixel)) __PYX_ERR(0, 283, __pyx_L1_error); __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); + __Pyx_DECREF_SET(__pyx_t_6, function); __pyx_t_4 = 1; } } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_2}; - __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); + PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "_CharLS.pyx":271 - * arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") + /* "_CharLS.pyx":275 + * samples_per_pixel = info["components"] * * if info["components"] == 3: # <<<<<<<<<<<<<< - * return arr.reshape((info["height"], info["width"], 3)) - * + * if info["interleave_mode"] == 0: + * # ILV 0 is colour-by-plane, needs to be reshaped then transposed */ } - /* "_CharLS.pyx":274 - * return arr.reshape((info["height"], info["width"], 3)) + /* "_CharLS.pyx":285 + * return arr.reshape((rows, columns, samples_per_pixel)) * - * return arr.reshape((info["height"], info["width"])) # <<<<<<<<<<<<<< + * return arr.reshape((rows, columns)) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_reshape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_info, __pyx_n_u_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 274, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_reshape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2)) __PYX_ERR(0, 274, __pyx_L1_error); - __Pyx_GIVEREF(__pyx_t_3); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3)) __PYX_ERR(0, 274, __pyx_L1_error); - __pyx_t_2 = 0; - __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_rows); + __Pyx_GIVEREF(__pyx_v_rows); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_rows)) __PYX_ERR(0, 285, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_columns); + __Pyx_GIVEREF(__pyx_v_columns); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_columns)) __PYX_ERR(0, 285, __pyx_L1_error); __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); + __Pyx_DECREF_SET(__pyx_t_6, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5}; - __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "_CharLS.pyx":251 + /* "_CharLS.pyx":253 * * * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream in the ndarray `data_buffer` * */ @@ -6642,20 +6857,23 @@ static PyObject *__pyx_pf_7_CharLS_6decode(CYTHON_UNUSED PyObject *__pyx_self, P __Pyx_XDECREF(__pyx_v_info); __Pyx_XDECREF(__pyx_v_bytes_per_pixel); __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_rows); + __Pyx_XDECREF(__pyx_v_columns); + __Pyx_XDECREF(__pyx_v_samples_per_pixel); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_CharLS.pyx":277 +/* "_CharLS.pyx":288 * * - * def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) -> bytearray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded buffer. - * + * def encode_to_buffer( # <<<<<<<<<<<<<< + * src: np.ndarray | bytes, + * lossy_error: int = 0, */ -static PyObject *__pyx_pf_7_CharLS_12__defaults__(CYTHON_UNUSED PyObject *__pyx_self) { +static PyObject *__pyx_pf_7_CharLS_14__defaults__(CYTHON_UNUSED PyObject *__pyx_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -6665,21 +6883,37 @@ static PyObject *__pyx_pf_7_CharLS_12__defaults__(CYTHON_UNUSED PyObject *__pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__defaults__", 1); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_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. + */ + __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, 277, __pyx_L1_error); - __Pyx_INCREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_interleave); - __Pyx_GIVEREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_interleave); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_interleave)) __PYX_ERR(0, 277, __pyx_L1_error); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 277, __pyx_L1_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, + */ + __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, 277, __pyx_L1_error); + 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, 277, __pyx_L1_error); + 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; @@ -6705,7 +6939,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_8encode_to_buffer, "Return the image data in `arr` as a JPEG-LS encoded buffer.\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 : int, optional\n The interleaving mode for multi-component images, default ``0``. One of\n\n * ``0``: pixels are ordered R1R2...RnG1G2...GnB1B2...Bn\n * ``1``: pixels are ordered R1...RwG1...GwB1...BwRw+1... where w is the\n width of the image (i.e. the data is ordered line by line)\n * ``2``: pixels are ordered R1G1B1R2G2B2...RnGnBn\n\n Returns\n -------\n bytearray\n The encoded JPEG-LS codestream.\n "); +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, #if CYTHON_METH_FASTCALL @@ -6714,9 +6948,9 @@ PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { - PyObject *__pyx_v_arr = 0; + PyObject *__pyx_v_src = 0; PyObject *__pyx_v_lossy_error = 0; - PyObject *__pyx_v_interleave = 0; + PyObject *__pyx_v_interleave_mode = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif @@ -6737,10 +6971,18 @@ PyObject *__pyx_args, PyObject *__pyx_kwds #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,0}; + 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); - values[2] = __Pyx_Arg_NewRef_FASTCALL(__pyx_dynamic_args->__pyx_arg_interleave); + + /* "_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)); if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { @@ -6756,30 +6998,30 @@ PyObject *__pyx_args, PyObject *__pyx_kwds 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)) { + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_src)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 277, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 288, __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, 277, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __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); + 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, 277, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __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, 277, __pyx_L3_error) + 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) } } else { switch (__pyx_nargs) { @@ -6792,13 +7034,13 @@ PyObject *__pyx_args, PyObject *__pyx_kwds default: goto __pyx_L5_argtuple_error; } } - __pyx_v_arr = values[0]; + __pyx_v_src = values[0]; __pyx_v_lossy_error = ((PyObject*)values[1]); - __pyx_v_interleave = ((PyObject*)values[2]); + __pyx_v_interleave_mode = values[2]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("encode_to_buffer", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 277, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("encode_to_buffer", 0, 1, 3, __pyx_nargs); __PYX_ERR(0, 288, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -6812,9 +7054,16 @@ PyObject *__pyx_args, PyObject *__pyx_kwds __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, 277, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_interleave), (&PyInt_Type), 0, "interleave", 1))) __PYX_ERR(0, 277, __pyx_L1_error) - __pyx_r = __pyx_pf_7_CharLS_8encode_to_buffer(__pyx_self, __pyx_v_arr, __pyx_v_lossy_error, __pyx_v_interleave); + 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, + */ /* function exit code */ goto __pyx_L0; @@ -6831,106 +7080,423 @@ 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_arr, PyObject *__pyx_v_lossy_error, PyObject *__pyx_v_interleave) { - PyObject *__pyx_v_bytes_per_pixel = NULL; - PyObject *__pyx_v_src_length = NULL; - Py_ssize_t __pyx_v_nr_dims; - 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; - enum charls::jpegls_errc __pyx_v_err; - PyObject *__pyx_v_msg = NULL; +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) { 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; - PyObject *__pyx_t_11 = NULL; - struct JlsParameters __pyx_t_12; - long __pyx_t_13; - long __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - char *__pyx_t_17; - size_t __pyx_t_18; - char *__pyx_t_19; + int __pyx_t_3; + 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_to_buffer", 1); - /* "_CharLS.pyx":302 + /* "_CharLS.pyx":322 * The encoded JPEG-LS codestream. * """ - * if arr.dtype == np.uint8: # <<<<<<<<<<<<<< - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: + * if isinstance(src, np.ndarray): # <<<<<<<<<<<<<< + * return _encode_array(src, lossy_error, interleave_mode) + * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __pyx_L1_error) + __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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 302, __pyx_L1_error) + __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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_uint8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 302, __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, 302, __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, 302, __pyx_L1_error) + __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_4) { - - /* "_CharLS.pyx":303 - * """ - * 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; + if (__pyx_t_3) { - /* "_CharLS.pyx":302 - * The encoded JPEG-LS codestream. + /* "_CharLS.pyx":323 * """ - * if arr.dtype == np.uint8: # <<<<<<<<<<<<<< - * bytes_per_pixel = 1 - * elif arr.dtype == np.uint16: + * if isinstance(src, np.ndarray): + * return _encode_array(src, lossy_error, interleave_mode) # <<<<<<<<<<<<<< + * + * # 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; + + /* "_CharLS.pyx":322 + * The encoded JPEG-LS codestream. + * """ + * if isinstance(src, np.ndarray): # <<<<<<<<<<<<<< + * return _encode_array(src, lossy_error, interleave_mode) + * */ - goto __pyx_L3; } - /* "_CharLS.pyx":304 + /* "_CharLS.pyx":288 + * + * + * def encode_to_buffer( # <<<<<<<<<<<<<< + * src: np.ndarray | bytes, + * lossy_error: int = 0, + */ + + /* 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":334 + * + * + * 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 + * + * + * def _encode_array( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, + */ + __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_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); + + /* "_CharLS.pyx":334 + * + * + * def _encode_array( # <<<<<<<<<<<<<< + * 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]); + } + } + __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: + */ + __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; + } + + /* "_CharLS.pyx":341 * if arr.dtype == np.uint8: * bytes_per_pixel = 1 * elif arr.dtype == np.uint16: # <<<<<<<<<<<<<< * bytes_per_pixel = 2 * else: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error) + __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, 304, __pyx_L1_error) + __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, 304, __pyx_L1_error) + __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, 304, __pyx_L1_error) + __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, 304, __pyx_L1_error) + __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)) { - /* "_CharLS.pyx":305 + /* "_CharLS.pyx":342 * bytes_per_pixel = 1 * elif arr.dtype == np.uint16: * bytes_per_pixel = 2 # <<<<<<<<<<<<<< @@ -6940,7 +7506,7 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __Pyx_INCREF(__pyx_int_2); __pyx_v_bytes_per_pixel = __pyx_int_2; - /* "_CharLS.pyx":304 + /* "_CharLS.pyx":341 * if arr.dtype == np.uint8: * bytes_per_pixel = 1 * elif arr.dtype == np.uint16: # <<<<<<<<<<<<<< @@ -6950,7 +7516,7 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p goto __pyx_L3; } - /* "_CharLS.pyx":307 + /* "_CharLS.pyx":344 * bytes_per_pixel = 2 * else: * raise ValueError( # <<<<<<<<<<<<<< @@ -6959,14 +7525,14 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p */ /*else*/ { - /* "_CharLS.pyx":308 + /* "_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, 308, __pyx_L1_error) + __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; @@ -6974,9 +7540,9 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __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, 308, __pyx_L1_error) + __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, 308, __pyx_L1_error) + __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; @@ -6988,55 +7554,55 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __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, 308, __pyx_L1_error) + __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; - /* "_CharLS.pyx":307 + /* "_CharLS.pyx":344 * bytes_per_pixel = 2 * else: * raise ValueError( # <<<<<<<<<<<<<< * f"Invalid input data type '{arr.dtype}', expecting np.uint8 or np.uint16." * ) */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) + __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, 307, __pyx_L1_error) + __PYX_ERR(0, 344, __pyx_L1_error) } __pyx_L3:; - /* "_CharLS.pyx":311 + /* "_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, 311, __pyx_L1_error) + __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, 311, __pyx_L1_error) + __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":312 + /* "_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, 312, __pyx_L1_error) + __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, 312, __pyx_L1_error) + __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":313 + /* "_CharLS.pyx":350 * src_length = arr.size * bytes_per_pixel * nr_dims = len(arr.shape) * if nr_dims not in (2, 3): # <<<<<<<<<<<<<< @@ -7055,20 +7621,20 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __pyx_t_7 = __pyx_t_4; if (unlikely(__pyx_t_7)) { - /* "_CharLS.pyx":314 + /* "_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__6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error) + __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, 314, __pyx_L1_error) + __PYX_ERR(0, 351, __pyx_L1_error) - /* "_CharLS.pyx":313 + /* "_CharLS.pyx":350 * src_length = arr.size * bytes_per_pixel * nr_dims = len(arr.shape) * if nr_dims not in (2, 3): # <<<<<<<<<<<<<< @@ -7077,27 +7643,27 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p */ } - /* "_CharLS.pyx":316 + /* "_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, 316, __pyx_L1_error) + __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, 316, __pyx_L1_error) + __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; - /* "_CharLS.pyx":317 + /* "_CharLS.pyx":354 * * LOGGER.debug( * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " # <<<<<<<<<<<<<< * f"{bytes_per_pixel} bytes per pixel" * ) */ - __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error) + __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; @@ -7105,7 +7671,7 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __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, 317, __pyx_L1_error) + __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); @@ -7116,9 +7682,9 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __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, 317, __pyx_L1_error) + __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, 317, __pyx_L1_error) + __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; @@ -7131,14 +7697,14 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __Pyx_GIVEREF(__pyx_kp_u_with); PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_with); - /* "_CharLS.pyx":318 + /* "_CharLS.pyx":355 * LOGGER.debug( * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " * f"{bytes_per_pixel} bytes per pixel" # <<<<<<<<<<<<<< * ) * */ - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_bytes_per_pixel, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 318, __pyx_L1_error) + __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); @@ -7150,14 +7716,14 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __Pyx_GIVEREF(__pyx_kp_u_bytes_per_pixel); PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_kp_u_bytes_per_pixel); - /* "_CharLS.pyx":317 + /* "_CharLS.pyx":354 * * LOGGER.debug( * f"Encoding 'src' is {src_length} bytes, shaped as {arr.shape} with " # <<<<<<<<<<<<<< * f"{bytes_per_pixel} bytes per pixel" * ) */ - __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_3, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 317, __pyx_L1_error) + __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; @@ -7179,211 +7745,537 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __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, 316, __pyx_L1_error) + 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; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "_CharLS.pyx":321 + /* "_CharLS.pyx":358 * ) * - * if interleave not in (0, 1, 2): # <<<<<<<<<<<<<< - * raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") + * 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 + * ) * + * if nr_dims == 2: # <<<<<<<<<<<<<< + * # Greyscale images should always be interleave mode 0 + * interleave_mode = 0 */ - __Pyx_INCREF(__pyx_v_interleave); - __pyx_t_11 = __pyx_v_interleave; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_11, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 321, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - } else { - __pyx_t_7 = __pyx_t_4; - goto __pyx_L6_bool_binop_done; + goto __pyx_L5; } - __pyx_t_2 = PyObject_RichCompare(__pyx_t_11, __pyx_int_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 321, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - } else { + + /* "_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 + */ + /*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; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_2 = PyObject_RichCompare(__pyx_t_11, __pyx_int_2, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 321, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __pyx_t_4; - __pyx_L6_bool_binop_done:; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_4 = __pyx_t_7; - if (unlikely(__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":322 - * - * if interleave not in (0, 1, 2): - * raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") # <<<<<<<<<<<<<< - * - * cdef JlsParameters info = build_parameters() + /* "_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; + + /* "_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 */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 322, __pyx_L1_error) + goto __pyx_L6; + } + + /* "_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 + */ + __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_Raise(__pyx_t_2, 0, 0, 0); + __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_ERR(0, 322, __pyx_L1_error) + __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; - /* "_CharLS.pyx":321 - * ) + /* "_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 + */ + goto __pyx_L6; + } + + /* "_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' " + */ + __pyx_t_7 = (__pyx_v_interleave_mode == Py_None); + if (unlikely(__pyx_t_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_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) + + /* "_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' " + */ + } + __pyx_L6:; + + /* "_CharLS.pyx":377 + * ) * - * if interleave not in (0, 1, 2): # <<<<<<<<<<<<<< - * raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") + * 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) { + + /* "_CharLS.pyx":378 * + * if interleave_mode == 0: + * components = arr.shape[0] # <<<<<<<<<<<<<< + * rows = arr.shape[1] + * columns = arr.shape[2] */ - } + __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; + + /* "_CharLS.pyx":379 + * if interleave_mode == 0: + * components = arr.shape[0] + * rows = arr.shape[1] # <<<<<<<<<<<<<< + * columns = 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, 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; - /* "_CharLS.pyx":324 - * raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") + /* "_CharLS.pyx":377 + * ) * - * cdef JlsParameters info = build_parameters() # <<<<<<<<<<<<<< - * info.height = arr.shape[0] - * info.width = arr.shape[1] + * if interleave_mode == 0: # <<<<<<<<<<<<<< + * components = arr.shape[0] + * rows = arr.shape[1] + */ + goto __pyx_L11; + } + + /* "_CharLS.pyx":382 + * columns = arr.shape[2] + * else: + * rows = arr.shape[0] # <<<<<<<<<<<<<< + * columns = arr.shape[1] + * components = arr.shape[2] */ - __pyx_t_12 = __pyx_f_7_CharLS_build_parameters(); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 324, __pyx_L1_error) - __pyx_v_info = __pyx_t_12; + /*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] + * + */ + __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; - /* "_CharLS.pyx":325 + /* "_CharLS.pyx":384 + * rows = arr.shape[0] + * columns = arr.shape[1] + * components = arr.shape[2] # <<<<<<<<<<<<<< * * cdef JlsParameters info = build_parameters() - * info.height = arr.shape[0] # <<<<<<<<<<<<<< - * info.width = arr.shape[1] - * info.components = arr.shape[2] if nr_dims == 3 else 1 */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __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, 325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 325, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_info.height = __pyx_t_13; + __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":326 + /* "_CharLS.pyx":386 + * components = arr.shape[2] + * + * cdef JlsParameters info = build_parameters() # <<<<<<<<<<<<<< + * info.height = rows + * info.width = columns + */ + __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; + + /* "_CharLS.pyx":387 + * * cdef JlsParameters info = build_parameters() - * info.height = arr.shape[0] - * info.width = arr.shape[1] # <<<<<<<<<<<<<< - * info.components = arr.shape[2] if nr_dims == 3 else 1 - * info.interleaveMode = interleave + * info.height = rows # <<<<<<<<<<<<<< + * info.width = columns + * info.components = components if nr_dims == 3 else 1 */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 326, __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, 326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_t_2); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 326, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_info.width = __pyx_t_13; + __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":327 - * info.height = arr.shape[0] - * info.width = arr.shape[1] - * info.components = arr.shape[2] if nr_dims == 3 else 1 # <<<<<<<<<<<<<< - * info.interleaveMode = interleave + /* "_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; + + /* "_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_4 = (__pyx_v_nr_dims == 3); - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __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, 327, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_14 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_14 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 327, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_13 = __pyx_t_14; + __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_13 = 1; + __pyx_t_12 = 1; } - __pyx_v_info.components = __pyx_t_13; + __pyx_v_info.components = __pyx_t_12; - /* "_CharLS.pyx":328 - * info.width = arr.shape[1] - * info.components = arr.shape[2] if nr_dims == 3 else 1 - * info.interleaveMode = interleave # <<<<<<<<<<<<<< + /* "_CharLS.pyx":390 + * info.width = columns + * info.components = components if nr_dims == 3 else 1 + * info.interleaveMode = interleave_mode # <<<<<<<<<<<<<< * info.allowedLossyError = lossy_error - * info.stride = info.width * bytes_per_pixel + * */ - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_interleave); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 328, __pyx_L1_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)); - /* "_CharLS.pyx":329 - * info.components = arr.shape[2] if nr_dims == 3 else 1 - * info.interleaveMode = interleave + /* "_CharLS.pyx":391 + * info.components = components if nr_dims == 3 else 1 + * info.interleaveMode = interleave_mode * info.allowedLossyError = lossy_error # <<<<<<<<<<<<<< - * info.stride = info.width * bytes_per_pixel * + * if nr_dims == 2: */ - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_v_lossy_error); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 329, __pyx_L1_error) - __pyx_v_info.allowedLossyError = __pyx_t_13; + __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; - /* "_CharLS.pyx":330 - * info.interleaveMode = interleave + /* "_CharLS.pyx":393 * info.allowedLossyError = lossy_error - * info.stride = info.width * bytes_per_pixel # <<<<<<<<<<<<<< * - * bit_depth = math.ceil(math.log(arr.max() + 1, 2)) + * if nr_dims == 2: # <<<<<<<<<<<<<< + * info.stride = info.width * bytes_per_pixel + * else: */ - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_info.width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 330, __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, 330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_t_2); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 330, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_info.stride = __pyx_t_13; + __pyx_t_7 = (__pyx_v_nr_dims == 2); + if (__pyx_t_7) { + + /* "_CharLS.pyx":394 + * + * if nr_dims == 2: + * info.stride = info.width * bytes_per_pixel # <<<<<<<<<<<<<< + * else: + * if interleave_mode == 0: + */ + __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; + + /* "_CharLS.pyx":393 + * info.allowedLossyError = lossy_error + * + * if nr_dims == 2: # <<<<<<<<<<<<<< + * info.stride = info.width * bytes_per_pixel + * else: + */ + goto __pyx_L12; + } + + /* "_CharLS.pyx":396 + * info.stride = info.width * bytes_per_pixel + * else: + * if interleave_mode == 0: # <<<<<<<<<<<<<< + * info.stride = info.width * bytes_per_pixel + * else: + */ + /*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) { + + /* "_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 + */ + __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; + + /* "_CharLS.pyx":396 + * info.stride = info.width * bytes_per_pixel + * else: + * if interleave_mode == 0: # <<<<<<<<<<<<<< + * info.stride = info.width * bytes_per_pixel + * else: + */ + goto __pyx_L13; + } + + /* "_CharLS.pyx":399 + * info.stride = info.width * bytes_per_pixel + * else: + * info.stride = info.width * bytes_per_pixel * info.components # <<<<<<<<<<<<<< + * + * + */ + /*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:; - /* "_CharLS.pyx":332 - * info.stride = info.width * bytes_per_pixel + /* "_CharLS.pyx":402 + * * * bit_depth = math.ceil(math.log(arr.max() + 1, 2)) # <<<<<<<<<<<<<< * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth * */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_math); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error) + __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_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ceil); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_math); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) + __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, 332, __pyx_L1_error) + __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_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_max); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_16 = NULL; + __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_15))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15); - __Pyx_INCREF(__pyx_t_16); + 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_15, function); + __Pyx_DECREF_SET(__pyx_t_14, function); __pyx_t_10 = 1; } } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_16, NULL}; - __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_10, 0+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) + 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_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } - __pyx_t_15 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); + __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; @@ -7400,267 +8292,267 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p } #endif { - PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_t_15, __pyx_int_2}; - __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10); + 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_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __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_9))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + 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_9); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); + __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_10 = 1; } } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_1}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); + 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; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - __pyx_v_bit_depth = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_bit_depth = __pyx_t_9; + __pyx_t_9 = 0; - /* "_CharLS.pyx":333 + /* "_CharLS.pyx":403 * * bit_depth = math.ceil(math.log(arr.max() + 1, 2)) * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth # <<<<<<<<<<<<<< * * LOGGER.debug( */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_bit_depth, __pyx_int_1, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 333, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - __pyx_t_13 = 2; + __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_14 = __Pyx_PyInt_As_long(__pyx_v_bit_depth); if (unlikely((__pyx_t_14 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 333, __pyx_L1_error) - __pyx_t_13 = __pyx_t_14; + __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_13; + __pyx_v_info.bitsPerSample = __pyx_t_12; - /* "_CharLS.pyx":335 + /* "_CharLS.pyx":405 * info.bitsPerSample = 2 if bit_depth <= 1 else bit_depth * * LOGGER.debug( # <<<<<<<<<<<<<< * "Encoding paramers are:\n" * f"\tWidth: {info.width} px\n" */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 335, __pyx_L1_error) + __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_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __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; - /* "_CharLS.pyx":336 + /* "_CharLS.pyx":406 * * LOGGER.debug( * "Encoding paramers are:\n" # <<<<<<<<<<<<<< * f"\tWidth: {info.width} px\n" * f"\tHeight: {info.height} px\n" */ - __pyx_t_9 = PyTuple_New(15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); + __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_9, 0, __pyx_kp_u_Encoding_paramers_are_Width); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Encoding_paramers_are_Width); - /* "_CharLS.pyx":337 + /* "_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, 337, __pyx_L1_error) + __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_9, 1, __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_9, 2, __pyx_kp_u_px_Height); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_px_Height); - /* "_CharLS.pyx":338 + /* "_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" */ - __pyx_t_8 = __Pyx_PyUnicode_From_long(__pyx_v_info.height, 0, ' ', 'd'); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 338, __pyx_L1_error) + __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_9, 3, __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_9, 4, __pyx_kp_u_px_Components); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_px_Components); - /* "_CharLS.pyx":339 + /* "_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, 339, __pyx_L1_error) + __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_9, 5, __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_9, 6, __pyx_kp_u_Bits_per_sample); + PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_Bits_per_sample); - /* "_CharLS.pyx":340 + /* "_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, 340, __pyx_L1_error) + __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_9, 7, __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_9, 8, __pyx_kp_u_Stride); + PyTuple_SET_ITEM(__pyx_t_1, 8, __pyx_kp_u_Stride); - /* "_CharLS.pyx":341 + /* "_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, 341, __pyx_L1_error) + __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_9, 9, __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_9, 10, __pyx_kp_u_bytes_Interleave_mode); + PyTuple_SET_ITEM(__pyx_t_1, 10, __pyx_kp_u_bytes_Interleave_mode); - /* "_CharLS.pyx":342 + /* "_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, 342, __pyx_L1_error) + __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_9, 11, __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_9, 12, __pyx_kp_u_Allowed_lossy_error); + PyTuple_SET_ITEM(__pyx_t_1, 12, __pyx_kp_u_Allowed_lossy_error); - /* "_CharLS.pyx":343 + /* "_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, 343, __pyx_L1_error) + __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_9, 13, __pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_1, 13, __pyx_t_8); __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_kp_u__8); + __Pyx_INCREF(__pyx_kp_u__9); __pyx_t_5 += 1; - __Pyx_GIVEREF(__pyx_kp_u__8); - PyTuple_SET_ITEM(__pyx_t_9, 14, __pyx_kp_u__8); + __Pyx_GIVEREF(__pyx_kp_u__9); + PyTuple_SET_ITEM(__pyx_t_1, 14, __pyx_kp_u__9); - /* "_CharLS.pyx":336 + /* "_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_9, 15, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 336, __pyx_L1_error) + __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_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; + __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_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); + 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_1, function); + __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_10 = 1; } } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + 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_2)) __PYX_ERR(0, 335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "_CharLS.pyx":347 + /* "_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_2 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_src_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) + __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_t_1 = __Pyx_PyInt_MultiplyObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __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_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_dst = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_v_dst = ((PyObject*)__pyx_t_9); + __pyx_t_9 = 0; - /* "_CharLS.pyx":350 + /* "_CharLS.pyx":420 * * # Number of bytes of compressed data * cdef size_t compressed_length = 0 # <<<<<<<<<<<<<< @@ -7669,102 +8561,136 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p */ __pyx_v_compressed_length = 0; - /* "_CharLS.pyx":354 + /* "_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_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error) + __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_v_error_message = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; + __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; + } + } + #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":358 + /* "_CharLS.pyx":432 * cdef JLS_ERROR err * err = JpegLsEncode( * dst, # <<<<<<<<<<<<<< * len(dst), * &compressed_length, */ - __pyx_t_17 = __Pyx_PyObject_AsWritableString(__pyx_v_dst); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 358, __pyx_L1_error) + __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":359 + /* "_CharLS.pyx":433 * err = JpegLsEncode( * dst, * len(dst), # <<<<<<<<<<<<<< * &compressed_length, - * cnp.PyArray_DATA(arr), + * src, */ - __pyx_t_5 = __Pyx_PyByteArray_GET_SIZE(__pyx_v_dst); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 359, __pyx_L1_error) + __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":361 + /* "_CharLS.pyx":435 * len(dst), * &compressed_length, - * cnp.PyArray_DATA(arr), # <<<<<<<<<<<<<< + * src, # <<<<<<<<<<<<<< * src_length, * &info, */ - if (!(likely(((__pyx_v_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_arr, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 361, __pyx_L1_error) + __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":362 + /* "_CharLS.pyx":436 * &compressed_length, - * cnp.PyArray_DATA(arr), + * 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, 362, __pyx_L1_error) + __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":364 + /* "_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, 364, __pyx_L1_error) + __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_error_message); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error) - /* "_CharLS.pyx":357 + /* "_CharLS.pyx":431 * * cdef JLS_ERROR err * err = JpegLsEncode( # <<<<<<<<<<<<<< * dst, * len(dst), */ - __pyx_v_err = JpegLsEncode(((char *)__pyx_t_17), __pyx_t_5, (&__pyx_v_compressed_length), ((char *)PyArray_DATA(((PyArrayObject *)__pyx_v_arr))), __pyx_t_18, (&__pyx_v_info), ((char *)__pyx_t_19)); + __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)); - /* "_CharLS.pyx":367 + /* "_CharLS.pyx":441 * ) * * if err != 0: # <<<<<<<<<<<<<< * msg = error_message.decode("ascii").strip("\0") * raise RuntimeError(f"Encoding error: {msg}") */ - __pyx_t_4 = (((int)__pyx_v_err) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_t_7 = (((int)__pyx_v_err) != 0); + if (unlikely(__pyx_t_7)) { - /* "_CharLS.pyx":368 + /* "_CharLS.pyx":442 * * if err != 0: * msg = error_message.decode("ascii").strip("\0") # <<<<<<<<<<<<<< * raise RuntimeError(f"Encoding error: {msg}") * */ - __pyx_t_1 = __Pyx_decode_bytearray(__pyx_v_error_message, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_strip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 368, __pyx_L1_error) + __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_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; + __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_1 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_1)) { + __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_1); + __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); __pyx_t_10 = 1; @@ -7772,36 +8698,36 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_kp_u__5}; - __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + 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; } - __pyx_v_msg = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_msg = __pyx_t_9; + __pyx_t_9 = 0; - /* "_CharLS.pyx":369 + /* "_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_2 = __Pyx_PyObject_FormatSimple(__pyx_v_msg, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Encoding_error, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 369, __pyx_L1_error) + __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_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __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_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 369, __pyx_L1_error) + __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":367 + /* "_CharLS.pyx":441 * ) * * if err != 0: # <<<<<<<<<<<<<< @@ -7810,7 +8736,7 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p */ } - /* "_CharLS.pyx":371 + /* "_CharLS.pyx":445 * raise RuntimeError(f"Encoding error: {msg}") * * return dst[:compressed_length] # <<<<<<<<<<<<<< @@ -7818,18 +8744,18 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PySequence_GetSlice(__pyx_v_dst, 0, __pyx_v_compressed_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; + __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":277 - * + /* "_CharLS.pyx":334 * - * def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) -> bytearray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded buffer. * + * def _encode_array( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, */ /* function exit code */ @@ -7839,42 +8765,104 @@ static PyObject *__pyx_pf_7_CharLS_8encode_to_buffer(CYTHON_UNUSED PyObject *__p __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_AddTraceback("_CharLS.encode_to_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __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":374 +/* "_CharLS.pyx":448 * * - * def encode(arr: np.ndarray) -> np.ndarray: # <<<<<<<<<<<<<< + * 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.""" - * return np.frombuffer(encode_to_buffer(arr), dtype="u1") */ + __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; +} /* Python wrapper */ -static PyObject *__pyx_pw_7_CharLS_11encode(PyObject *__pyx_self, +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_10encode, "Return the image data in `arr` as a JPEG-LS encoded 1D ndarray."); -static PyMethodDef __pyx_mdef_7_CharLS_11encode = {"encode", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7_CharLS_11encode, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7_CharLS_10encode}; -static PyObject *__pyx_pw_7_CharLS_11encode(PyObject *__pyx_self, +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 #else @@ -7882,11 +8870,13 @@ 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[1] = {0}; + PyObject* values[3] = {0,0,0}; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -7902,10 +8892,25 @@ PyObject *__pyx_args, PyObject *__pyx_kwds #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { - PyObject **__pyx_pyargnames[] = {&__pyx_n_s_arr,0}; + 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; @@ -7918,23 +8923,45 @@ PyObject *__pyx_args, PyObject *__pyx_kwds (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 374, __pyx_L3_error) + 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, 374, __pyx_L3_error) + 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) } - } else if (unlikely(__pyx_nargs != 1)) { - goto __pyx_L5_argtuple_error; } else { - values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + 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", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 374, __pyx_L3_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:; @@ -7948,9 +8975,22 @@ PyObject *__pyx_args, PyObject *__pyx_kwds __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7_CharLS_10encode(__pyx_self, __pyx_v_arr); + 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) { @@ -7961,7 +9001,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds return __pyx_r; } -static PyObject *__pyx_pf_7_CharLS_10encode(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_arr) { +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 PyObject *__pyx_t_1 = NULL; @@ -7974,18 +9014,28 @@ static PyObject *__pyx_pf_7_CharLS_10encode(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_clineno = 0; __Pyx_RefNannySetupContext("encode", 1); - /* "_CharLS.pyx":376 - * def encode(arr: np.ndarray) -> np.ndarray: + /* "_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), dtype="u1") # <<<<<<<<<<<<<< + * 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, 376, __pyx_L1_error) + __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, 376, __pyx_L1_error) + __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; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_encode_to_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 376, __pyx_L1_error) + + /* "_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; @@ -8002,22 +9052,45 @@ static PyObject *__pyx_pf_7_CharLS_10encode(CYTHON_UNUSED PyObject *__pyx_self, } #endif { - PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_arr}; - __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + 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, 376, __pyx_L1_error) + 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; } - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 376, __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_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, 376, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1)) __PYX_ERR(0, 454, __pyx_L1_error); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error) + + /* "_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, 376, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 376, __pyx_L1_error) + 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; @@ -8026,12 +9099,12 @@ static PyObject *__pyx_pf_7_CharLS_10encode(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_4 = 0; goto __pyx_L0; - /* "_CharLS.pyx":374 + /* "_CharLS.pyx":448 * * - * def encode(arr: np.ndarray) -> np.ndarray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer(encode_to_buffer(arr), dtype="u1") + * def encode( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, */ /* function exit code */ @@ -8076,18 +9149,18 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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_kp_u_Invalid_interleave_value_must_be, __pyx_k_Invalid_interleave_value_must_be, sizeof(__pyx_k_Invalid_interleave_value_must_be), 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_kp_u__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 1, 0, 0}, - {&__pyx_n_s__24, __pyx_k__24, sizeof(__pyx_k__24), 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__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 1, 0, 0}, - {&__pyx_n_s__9, __pyx_k__9, sizeof(__pyx_k__9), 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}, @@ -8102,6 +9175,8 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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}, @@ -8113,6 +9188,7 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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}, @@ -8124,7 +9200,8 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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, __pyx_k_interleave, sizeof(__pyx_k_interleave), 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}, @@ -8137,8 +9214,10 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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}, @@ -8148,6 +9227,8 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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}, @@ -8157,6 +9238,8 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { {&__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}, @@ -8170,9 +9253,9 @@ static int __Pyx_CreateStringTabAndInitStrings(void) { } /* #### 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, 170, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 307, __pyx_L1_error) - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 986, __pyx_L1_error) + __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; @@ -8183,61 +9266,72 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":986 + /* "../../../../../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") # <<<<<<<<<<<<<< * * cdef inline int import_umath() except -1: */ - __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_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_); - /* "../../../../../tmp/pip-build-env-8rseg12z/overlay/lib/python3.8/site-packages/numpy/__init__.cython-30.pxd":992 + /* "../../../../../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") # <<<<<<<<<<<<<< * * 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, 992, __pyx_L1_error) + __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":156 + /* "_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 * */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_b__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 156, __pyx_L1_error) + __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":314 - * nr_dims = len(arr.shape) - * if nr_dims not in (2, 3): - * raise ValueError("Invalid data shape") # <<<<<<<<<<<<<< + /* "_CharLS.pyx":280 + * # to colour-by-pixel instead + * arr = arr.reshape((samples_per_pixel, rows, columns)) + * return arr.transpose(1, 2, 0) # <<<<<<<<<<<<<< * - * LOGGER.debug( + * # Colour-by-pixel, just needs to be reshaped */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_Invalid_data_shape); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 314, __pyx_L1_error) + __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":322 - * - * if interleave not in (0, 1, 2): - * raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") # <<<<<<<<<<<<<< + /* "_CharLS.pyx":351 + * nr_dims = len(arr.shape) + * if nr_dims not in (2, 3): + * raise ValueError("Invalid data shape") # <<<<<<<<<<<<<< * - * cdef JlsParameters info = build_parameters() + * LOGGER.debug( */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_Invalid_interleave_value_must_be); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 322, __pyx_L1_error) + __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); + /* "_CharLS.pyx":11 * * @@ -8245,81 +9339,93 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { * * */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_u_jpeg_ls__CharLS); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); + __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); - /* "_CharLS.pyx":175 + /* "_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_tuple__12 = PyTuple_Pack(2, __pyx_n_s_src, __pyx_n_s_info); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); - __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_read_header, 175, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 175, __pyx_L1_error) + __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) - /* "_CharLS.pyx":191 + /* "_CharLS.pyx":193 * * * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __pyx_tuple__14 = 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__14)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); - __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode, 191, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 191, __pyx_L1_error) + __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) - /* "_CharLS.pyx":235 + /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: # <<<<<<<<<<<<<< + * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_n_s_src); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 235, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); - __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_from_buffer, 235, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 235, __pyx_L1_error) + __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) - /* "_CharLS.pyx":251 + /* "_CharLS.pyx":253 * * * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream in the ndarray `data_buffer` * */ - __pyx_tuple__18 = PyTuple_Pack(5, __pyx_n_s_data_buffer, __pyx_n_s_src, __pyx_n_s_info, __pyx_n_s_bytes_per_pixel_2, __pyx_n_s_arr); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); - __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_decode_2, 251, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 251, __pyx_L1_error) + __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) - /* "_CharLS.pyx":277 + /* "_CharLS.pyx":288 + * * + * def encode_to_buffer( # <<<<<<<<<<<<<< + * src: np.ndarray | bytes, + * lossy_error: int = 0, + */ + __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) + + /* "_CharLS.pyx":334 * - * def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) -> bytearray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded buffer. * + * def _encode_array( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, */ - __pyx_tuple__20 = PyTuple_Pack(13, __pyx_n_s_arr, __pyx_n_s_lossy_error, __pyx_n_s_interleave, __pyx_n_s_bytes_per_pixel_2, __pyx_n_s_src_length, __pyx_n_s_nr_dims, __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_err, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 277, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); - __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode_to_buffer, 277, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 277, __pyx_L1_error) + __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) - /* "_CharLS.pyx":374 + /* "_CharLS.pyx":448 * * - * def encode(arr: np.ndarray) -> np.ndarray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer(encode_to_buffer(arr), dtype="u1") + * def encode( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_n_s_arr); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); - __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_jpeg_ls__CharLS_pyx, __pyx_n_s_encode, 374, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 374, __pyx_L1_error) + __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:; @@ -8334,6 +9440,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { __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; __pyx_L1_error:; @@ -8433,17 +9540,17 @@ static int __Pyx_modinit_type_import_code(void) { __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_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; @@ -8817,135 +9924,189 @@ if (!__Pyx_RefNanny) { __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__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) + __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":175 + /* "_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, 175, __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, 175, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_kp_s_Dict_str_int) < 0) __PYX_ERR(0, 175, __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__13)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L1_error) + 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, 175, __pyx_L1_error) + 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":191 + /* "_CharLS.pyx":193 * * * def _decode(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """Decode the JPEG-LS codestream `src` to a bytearray * */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __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, 191, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 191, __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__15)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 191, __pyx_L1_error) + 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, 191, __pyx_L1_error) + 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":235 + /* "_CharLS.pyx":237 * * - * def decode_from_buffer(src: bytes | bytearray) -> bytearray: # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * 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, 235, __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, 235, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 235, __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__17)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error) + 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, 235, __pyx_L1_error) + 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":251 + /* "_CharLS.pyx":253 * * * def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): # <<<<<<<<<<<<<< - * """Decode the JPEG-LS codestream `src` + * """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__19)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __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__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, 251, __pyx_L1_error) + 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":277 - * + /* "_CharLS.pyx":288 * - * def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) -> bytearray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded buffer. * + * 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, 277, __pyx_L1_error) + __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_arr, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 277, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_lossy_error, __pyx_n_s_int) < 0) __PYX_ERR(0, 277, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_interleave, __pyx_n_s_int) < 0) __PYX_ERR(0, 277, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_bytearray) < 0) __PYX_ERR(0, 277, __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__21)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 277, __pyx_L1_error) + 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), 2)) __PYX_ERR(0, 277, __pyx_L1_error) - if (!(likely(__Pyx_Py3Int_CheckExact(__pyx_int_0)) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_int_0))) __PYX_ERR(0, 277, __pyx_L1_error) + 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); - if (!(likely(__Pyx_Py3Int_CheckExact(__pyx_int_0)) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_int_0))) __PYX_ERR(0, 277, __pyx_L1_error) - __Pyx_INCREF(__pyx_int_0); - __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_t_3)->__pyx_arg_interleave = ((PyObject*)__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_CyFunction_SetDefaultsGetter(__pyx_t_3, __pyx_pf_7_CharLS_12__defaults__); + __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, 277, __pyx_L1_error) + 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":374 + /* "_CharLS.pyx":334 * * - * def encode(arr: np.ndarray) -> np.ndarray: # <<<<<<<<<<<<<< - * """Return the image data in `arr` as a JPEG-LS encoded 1D ndarray.""" - * return np.frombuffer(encode_to_buffer(arr), dtype="u1") + * def _encode_array( # <<<<<<<<<<<<<< + * arr: np.ndarray, + * lossy_error: int = 0, */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error) + __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, 374, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_return, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 374, __pyx_L1_error) - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7_CharLS_11encode, 0, __pyx_n_s_encode, NULL, __pyx_n_s_CharLS, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) + 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, __pyx_t_2) < 0) __PYX_ERR(0, 374, __pyx_L1_error) + 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_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __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 ---*/ @@ -11248,6 +12409,11 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } +/* RaiseUnboundLocalError */ + static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { @@ -11776,26 +12942,6 @@ static PyObject* __Pyx_PyInt_MultiplyObjC(PyObject *op1, PyObject *op2, long int } #endif -/* ExtTypeTest */ - static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - __Pyx_TypeName obj_type_name; - __Pyx_TypeName type_name; - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(__Pyx_TypeCheck(obj, type))) - return 1; - obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); - type_name = __Pyx_PyType_GetName(type); - PyErr_Format(PyExc_TypeError, - "Cannot convert " __Pyx_FMT_TYPENAME " to " __Pyx_FMT_TYPENAME, - obj_type_name, type_name); - __Pyx_DECREF_TypeName(obj_type_name); - __Pyx_DECREF_TypeName(type_name); - return 0; -} - /* TypeImport */ #ifndef __PYX_HAVE_RT_ImportType_3_0_8 #define __PYX_HAVE_RT_ImportType_3_0_8 @@ -12012,7 +13158,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__9; + PyObject *module, *from_list, *star = __pyx_n_s__10; CYTHON_UNUSED_VAR(parts_tuple); from_list = PyList_New(1); if (unlikely(!from_list)) @@ -12075,7 +13221,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__10); + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__11); if (unlikely(!module_dot)) { goto modbad; } full_name = PyUnicode_Concat(module_dot, name); if (unlikely(!full_name)) { goto modbad; } @@ -15048,7 +16194,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__24); + name = __Pyx_NewRef(__pyx_n_s__27); } return name; } diff --git a/jpeg_ls/_CharLS.pyx b/jpeg_ls/_CharLS.pyx index 84f3870..056dfeb 100644 --- a/jpeg_ls/_CharLS.pyx +++ b/jpeg_ls/_CharLS.pyx @@ -14,11 +14,12 @@ LOGGER = logging.getLogger("jpeg_ls._CharLS") cdef extern from "define_charls_dll.h": pass + cdef extern from "charls/public_types.h": cdef enum JLS_ERROR "charls::jpegls_errc": pass - cdef enum interleave_mode "charls::interleave_mode": + cdef enum c_interleave_mode "charls::interleave_mode": CHARLS_INTERLEAVE_MODE_NONE = 0 CHARLS_INTERLEAVE_MODE_LINE = 1 CHARLS_INTERLEAVE_MODE_SAMPLE = 2 @@ -52,19 +53,20 @@ cdef extern from "charls/public_types.h": long height # Bits per sample (sample precision (2, 16)) long bitsPerSample - # Number of bytes from one row of pixels to the next + # Number of bytes from one row of pixels to the next in memory long stride # Number of components, 1 for monochrome, 3 for RGB (1, 255) long components # The allowed lossy error, 0 for lossless long allowedLossyError # The order of color components in the compressed stream - interleave_mode interleaveMode + c_interleave_mode interleaveMode color_transformation colorTransformation char outputBgr JpegLSPresetCodingParameters custom JfifParameters jfif + cdef extern from "charls/charls_jpegls_decoder.h": cdef JLS_ERROR JpegLsReadHeader( void* source, @@ -82,6 +84,7 @@ cdef extern from "charls/charls_jpegls_decoder.h": char* error_message ) + cdef extern from "charls/charls_jpegls_encoder.h": cdef JLS_ERROR JpegLsEncode( void* dst, @@ -122,14 +125,13 @@ cdef JlsParameters build_parameters(): # 0 means lossless info.allowedLossyError = 0 # For monochrome images, always use ILV_NONE. - info.interleaveMode = 0 + info.interleaveMode = 0 # 0 means no color transform info.colorTransformation = 0 info.outputBgr = 0 # when set to true, CharLS will reverse the normal RGB info.custom = info_custom info.jfif = jfif - # Done. return info @@ -232,7 +234,7 @@ def _decode(src: bytes | bytearray) -> bytearray: return dst -def decode_from_buffer(src: bytes | bytearray) -> bytearray: +def decode_from_buffer(src: bytes | bytearray) -> tuple[bytearray, dict[str, int]]: """Decode the JPEG-LS codestream `src` to a bytearray Parameters @@ -242,10 +244,10 @@ def decode_from_buffer(src: bytes | bytearray) -> bytearray: Returns ------- - bytearray - The decoded image data. + tuple[bytearray, dict[str, int]] + The decoded (image data, image metadata). """ - return _decode(src) + return _decode(src), read_header(src) def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): @@ -266,14 +268,28 @@ def decode(cnp.ndarray[cnp.uint8_t, ndim=1] data_buffer): info = read_header(src) bytes_per_pixel = math.ceil(info["bits_per_sample"] / 8) arr = np.frombuffer(_decode(src), dtype=f"u{bytes_per_pixel}") + rows = info["height"] + columns = info["width"] + samples_per_pixel = info["components"] if info["components"] == 3: - return arr.reshape((info["height"], info["width"], 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((info["height"], info["width"])) + return arr.reshape((rows, columns)) -def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) -> bytearray: +def encode_to_buffer( + 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. Parameters @@ -285,13 +301,18 @@ def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) 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 : int, optional - The interleaving mode for multi-component images, default ``0``. One of + interleave_mode : int, optional + The interleaving mode for multi-component (i.e. non-greyscale) images, + default ``0``. One of - * ``0``: pixels are ordered R1R2...RnG1G2...GnB1B2...Bn - * ``1``: pixels 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``: pixels are ordered R1G1B1R2G2B2...RnGnBn + * ``0``: the pixels in `src` are ordered R1R2...RnG1G2...GnB1B2...Bn + * ``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 + + It's recommended that the pixel data in `src` be ordered to match an + interleaving mode of ``0`` as this should result in the greatest + compression ratio. Returns ------- @@ -317,16 +338,45 @@ def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) f"{bytes_per_pixel} bytes per pixel" ) - if interleave not in (0, 1, 2): - raise ValueError("Invalid 'interleave' value, must be 0, 1 or 2") + 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 = arr.shape[0] - info.width = arr.shape[1] - info.components = arr.shape[2] if nr_dims == 3 else 1 - info.interleaveMode = interleave + info.height = rows + info.width = columns + info.components = components if nr_dims == 3 else 1 + info.interleaveMode = interleave_mode info.allowedLossyError = lossy_error + info.stride = info.width * bytes_per_pixel + 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 @@ -352,12 +402,16 @@ def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) # 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, len(dst), &compressed_length, - cnp.PyArray_DATA(arr), + src, src_length, &info, error_message @@ -370,6 +424,13 @@ def encode_to_buffer(arr: np.ndarray, lossy_error: int = 0, interleave: int = 0) return dst[:compressed_length] -def encode(arr: np.ndarray) -> np.ndarray: +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), dtype="u1") + return np.frombuffer( + encode_to_buffer(arr, lossy_error, interleave_mode), + dtype="u1", + ) diff --git a/jpeg_ls/tests/test_decode.py b/jpeg_ls/tests/test_decode.py index 88af214..4e3be0d 100644 --- a/jpeg_ls/tests/test_decode.py +++ b/jpeg_ls/tests/test_decode.py @@ -75,20 +75,18 @@ def TEST16(): class TestRead: """Tests for read()""" - @pytest.mark.xfail - def test_T8C0E0(self): - # Decodes, but the output is weird + def test_T8C0E0(self, TEST8): # TEST8 in colour mode 0, lossless + # 3 component, 3 scans, ILV 0, lossless arr = read(DATA / "T8C0E0.JLS") - assert arr.shape == (256, 256) + assert arr.shape == (256, 256, 3) assert np.array_equal(arr, TEST8) - @pytest.mark.xfail - def test_T8C0E3(self): - # Decodes, but the output is weird + def test_T8C0E3(self, TEST8): # TEST8 in colour mode 0, lossy + # 3 component, 3 scans, ILV 0, lossy arr = read(DATA / "T8C0E0.JLS") - assert arr.shape == (256, 256) + assert arr.shape == (256, 256, 3) assert np.allclose(arr, TEST8, atol=3) def test_T8C1E0(self, TEST8): @@ -125,6 +123,7 @@ def test_T8NDE3(self, TEST8BS2): 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 = read(DATA / "T8SSE0.JLS") assert np.array_equal(arr, TEST8) @@ -133,6 +132,7 @@ def test_T8SSE0(self, TEST8): 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 = read(DATA / "T8SSE3.JLS") assert np.allclose(arr, TEST8, atol=3) @@ -165,9 +165,10 @@ def test_decode(TEST8): def test_decode_buffer(TEST8): with open(DATA / "T8C1E0.JLS", "rb") as f: - buffer = decode_from_buffer(f.read()) - arr = np.frombuffer(buffer, dtype="u1") - arr = arr.reshape(256, 256, 3) + 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) diff --git a/jpeg_ls/tests/test_encode.py b/jpeg_ls/tests/test_encode.py index 38be6ca..f1ee21f 100644 --- a/jpeg_ls/tests/test_encode.py +++ b/jpeg_ls/tests/test_encode.py @@ -3,6 +3,7 @@ import pytest import numpy as np +import matplotlib.pyplot as plt from jpeg_ls import decode, encode, write, read from _CharLS import encode_to_buffer, decode_from_buffer @@ -88,7 +89,7 @@ def test_invalid_nr_components_raises(self): "[1, 255]" ) with pytest.raises(Exception, match=msg): - encode(np.empty((2, 2, 256), dtype="u1")) + encode(np.empty((3, 2, 256), dtype="u1"), interleave_mode=1) def test_invalid_shape_raises(self): msg = "Invalid data shape" @@ -98,13 +99,40 @@ def test_invalid_shape_raises(self): with pytest.raises(Exception, match=msg): encode(np.empty((2, 2, 2, 2), dtype="u1")) - def test_TEST8(self, TEST8): - buffer = encode(TEST8) - assert isinstance(buffer, np.ndarray) # weird choice + def test_TEST8_ILV0(self, TEST8): + # 3 component, ILV 0 + # Convert from colour-by-pixel to colour-by-plane + arr = TEST8.transpose(2, 0, 1) + assert arr.shape == (3, 256, 256) + buffer = encode(arr, interleave_mode=0) + with open("ilv0.jls", "wb") as f: + f.write(buffer) + assert isinstance(buffer, np.ndarray) + arr = decode(buffer) + assert np.array_equal(arr, TEST8) + + def test_TEST8_ILV1(self, TEST8): + # 3 component, ILV 1 + assert TEST8.shape == (256, 256, 3) + buffer = encode(TEST8, interleave_mode=1) + with open("ilv1.jls", "wb") as f: + f.write(buffer) + assert isinstance(buffer, np.ndarray) + arr = decode(buffer) + assert np.array_equal(arr, TEST8) + + def test_TEST8_ILV2(self, TEST8): + # 3 component, ILV 2 + assert TEST8.shape == (256, 256, 3) + buffer = encode(TEST8, interleave_mode=2) + with open("ilv2.jls", "wb") as f: + f.write(buffer) + assert isinstance(buffer, np.ndarray) arr = decode(buffer) assert np.array_equal(arr, TEST8) def test_TEST8R(self, TEST8R): + # 1 component, ILV 0 buffer = encode(TEST8R) assert isinstance(buffer, np.ndarray) assert buffer.shape[0] < TEST8R.shape[0] * TEST8R.shape[1] @@ -145,7 +173,7 @@ def test_TEST16(self, TEST16): class TestEncodeBytes: def test_invalid_lossy_raises(self, TEST8): msg = ( - "Encoding error: The near lossless argument is outside the range" "[0, 255]" + r"Encoding error: The near lossless argument is outside the range \[0, 255\]" ) with pytest.raises(RuntimeError, match=msg): encode_to_buffer(TEST8, lossy_error=-1) @@ -156,14 +184,16 @@ def test_invalid_lossy_raises(self, TEST8): def test_TEST8_lossy(self, TEST8): buffer = encode_to_buffer(TEST8, lossy_error=5) assert isinstance(buffer, bytearray) - arr = np.frombuffer(decode_from_buffer(buffer), dtype="u1") + data, info = decode_from_buffer(buffer) + arr = np.frombuffer(data, dtype="u1") arr = arr.reshape(TEST8.shape) assert np.allclose(arr, TEST8, atol=5) def test_TEST8R_lossy(self, TEST8R): buffer = encode_to_buffer(TEST8R, lossy_error=3) assert isinstance(buffer, bytearray) - arr = np.frombuffer(decode_from_buffer(buffer), dtype="u1") + data, info = decode_from_buffer(buffer) + arr = np.frombuffer(data, dtype="u1") arr = arr.reshape(TEST8R.shape) assert np.allclose(arr, TEST8R, atol=3) diff --git a/pyproject.toml b/pyproject.toml index 5651712..0fd08ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ license = {text = "MIT"} name = "pyjpegls" readme = "readme.md" requires-python = ">=3.8" -version = "1.1.0" +version = "1.2.0" [project.urls] documentation = "https://pydicom.github.io/pydicom"