From 7da843af20f47a464e8b660ec1d2f4829b6db711 Mon Sep 17 00:00:00 2001 From: hackermd Date: Mon, 12 Feb 2018 19:39:47 -0500 Subject: [PATCH 1/3] Add support for color images --- jpeg_ls/CharLS.py | 4 ++-- jpeg_ls/_CharLS.pyx | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) 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) From 9a0aea3baf6ca92389407087f7ae1efcd695dcec Mon Sep 17 00:00:00 2001 From: hackermd Date: Mon, 12 Feb 2018 19:40:38 -0500 Subject: [PATCH 2/3] Set ``flag_MSVC`` to False by default --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 04c67a4..f1d9751 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: From ca736bac1c59ed4165b85ea719cd51119a027db1 Mon Sep 17 00:00:00 2001 From: hackermd Date: Wed, 7 Mar 2018 11:33:08 -0500 Subject: [PATCH 3/3] Increase version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f1d9751..39ab458 100644 --- a/setup.py +++ b/setup.py @@ -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(),