diff --git a/jpeg_ls/CharLS.py b/jpeg_ls/CharLS.py index 4451643..babb74a 100644 --- a/jpeg_ls/CharLS.py +++ b/jpeg_ls/CharLS.py @@ -38,7 +38,7 @@ def write(fname, data_image): def encode(data_image): """ - Encode grey-scale image via JPEG-LS using CharLS implementation. + Encode image via JPEG-LS using CharLS implementation. """ if data_image.dtype == np.uint16 and np.max(data_image) <= 255: @@ -52,7 +52,7 @@ def encode(data_image): def decode(data_buffer): """ - Decode grey-scale image via JPEG-LS using CharLS implementation. + Decode image via JPEG-LS using CharLS implementation. """ data_image = _CharLS.decode(data_buffer) diff --git a/jpeg_ls/_CharLS.pyx b/jpeg_ls/_CharLS.pyx index 0d7531a..d0cf56f 100644 --- a/jpeg_ls/_CharLS.pyx +++ b/jpeg_ls/_CharLS.pyx @@ -106,7 +106,7 @@ cdef JlsParameters build_parameters(): def encode(data_image): """ - Encode grey-scale image via JPEG-LS using CharLS implementation. + Encode image via JPEG-LS using CharLS implementation. """ data_image = np.asarray(data_image) @@ -131,7 +131,7 @@ def encode(data_image): else: num_bands = data_image.shape[2] - if num_bands != 1: + if num_bands > 3: raise Exception('Invalid number of bands %s' % num_bands) @@ -148,15 +148,19 @@ def encode(data_image): info.width = num_samples info.height = num_lines info.components = num_bands - info.ilv = 0 + if num_bands == 1: + info.ilv = 0 + else: + info.ilv = 1 + - info.bytesperline = num_samples * Bpp + info.bytesperline = num_bands * num_samples * Bpp info.bitspersample = max_bits info.allowedlossyerror = 0 # Buffer to store compressed data results. - cdef size_t size_buffer = num_samples*num_lines*Bpp*2 + cdef size_t size_buffer = num_bands*num_samples*num_lines*Bpp*2 data_buffer = np.zeros(size_buffer, dtype=np.uint8) cdef char* data_buffer_ptr = np.PyArray_DATA(data_buffer) @@ -169,7 +173,7 @@ def encode(data_image): cdef size_t* size_work_ptr = &size_work # Call encoder function. - cdef size_t size_data = num_samples*num_lines*Bpp + cdef size_t size_data = num_bands*num_samples*num_lines*Bpp cdef JLS_ERROR err err = JpegLsEncode(data_buffer_ptr, size_buffer, size_work_ptr, data_image_ptr, size_data, info_ptr) diff --git a/setup.py b/setup.py index 04c67a4..39ab458 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ extra_link_args = [] -flag_MSVC = True # Set this flag to True if using Visual Studio. +flag_MSVC = False # Set this flag to True if using Visual Studio. if flag_MSVC: extra_compile_args = ['/EHsc'] else: @@ -37,7 +37,7 @@ extra_link_args=extra_link_args) # Do it. -version = '1.0.2' +version = '1.1.0' setup(name='CharPyLS', packages=find_packages(),