diff --git a/.gitignore b/.gitignore index 2f35030..c10fecb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build/ _build/ pywuffs.egg-info/ __pycache__/ +src/wuffs-unsupported-snapshot.c diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 853ee9b..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "libs/wuffs-mirror-release-c"] - path = libs/wuffs-mirror-release-c - url = https://github.com/google/wuffs-mirror-release-c diff --git a/CMakeLists.txt b/CMakeLists.txt index 42f3831..64f6be9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,18 +5,24 @@ project(pywuffs) set(CMAKE_CXX_STANDARD 14) if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) + set(CMAKE_BUILD_TYPE Release) endif() if(UNIX) - set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++14 -Wall -Wextra -s -fvisibility=hidden -Wl,--strip-all") - set(CMAKE_CXX_FLAGS_DEBUG "-g") - set(CMAKE_CXX_FLAGS_RELEASE "-O3") + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + "-std=c++14 -Wall -Wextra -s -fvisibility=hidden -Wl,--strip-all") + set(CMAKE_CXX_FLAGS_DEBUG "-g") + set(CMAKE_CXX_FLAGS_RELEASE "-O3") elseif(MSVC) - set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "/arch:AVX") + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "/arch:AVX") endif() +file( + DOWNLOAD + https://raw.githubusercontent.com/google/wuffs/13c72db3508d33b9416a22a0ab8a8d4d8d5cd7be/release/c/wuffs-unsupported-snapshot.c + ${CMAKE_SOURCE_DIR}/src/wuffs-unsupported-snapshot.c) + find_package(pybind11 REQUIRED) pybind11_add_module(pywuffs src/wuffs-bindings.cpp) -target_include_directories(pywuffs PRIVATE libs/wuffs-mirror-release-c/release/) diff --git a/MANIFEST.in b/MANIFEST.in index 8c61fe6..c0f0441 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include src/wuffs-aux-image-wrapper.h src/wuffs-aux-json-wrapper.h libs/wuffs-mirror-release-c/release/c/wuffs-v0.3.c +include src/wuffs-aux-image-wrapper.h src/wuffs-aux-json-wrapper.h src/wuffs-unsupported-snapshot.c diff --git a/README.md b/README.md index 6aa0728..c55c066 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ it only provides bindings for image and JSON decoding parts of the [Auxiliary C++ API](https://github.com/google/wuffs/blob/main/doc/note/auxiliary-code.md) as being of the most interest since it provides for "ridiculously fast" decoding of images of some types. -Current version of Wuffs library used in this project is **0.3.3**. +Current version of Wuffs library used in this project is **unsupported snapshot** taken from +[this](https://github.com/google/wuffs/commit/13c72db3508d33b9416a22a0ab8a8d4d8d5cd7be) commit. The primary +rationale for using the snapshot version instead of a stable release is that it provides JPEG decoder. ## Installation diff --git a/libs/wuffs-mirror-release-c b/libs/wuffs-mirror-release-c deleted file mode 160000 index e3f919c..0000000 --- a/libs/wuffs-mirror-release-c +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e3f919ccfe3ef542cfc983a82146070258fb57f8 diff --git a/setup.py b/setup.py index c75c27d..6c94350 100644 --- a/setup.py +++ b/setup.py @@ -32,8 +32,7 @@ def build_extensions(self): ext_modules = [ Pybind11Extension( "pywuffs", - ["src/wuffs-bindings.cpp"], - include_dirs=["libs/wuffs-mirror-release-c/release"] + ["src/wuffs-bindings.cpp"] ), ] diff --git a/src/wuffs-aux-image-wrapper.h b/src/wuffs-aux-image-wrapper.h index 4aa15c9..8dde832 100644 --- a/src/wuffs-aux-image-wrapper.h +++ b/src/wuffs-aux-image-wrapper.h @@ -2,12 +2,13 @@ #include -#include #include #include #include #include +#include "wuffs-unsupported-snapshot.c" + // This API wraps the wuffs_aux API for image decoding. The wrapper is needed // since the wuffs_aux API uses the callback-based approach which doesn't play // well with Python-C++ interop. @@ -127,13 +128,14 @@ struct ImageDecoderConfig { wuffs_aux::DecodeImageArgMaxInclMetadataLength::DefaultValue().repr; std::vector enabled_decoders = { ImageDecoderType::BMP, ImageDecoderType::GIF, ImageDecoderType::NIE, - ImageDecoderType::PNG, ImageDecoderType::TGA, ImageDecoderType::WBMP}; + ImageDecoderType::PNG, ImageDecoderType::TGA, ImageDecoderType::WBMP, + ImageDecoderType::JPEG}; uint32_t pixel_format = wuffs_base__make_pixel_format( static_cast(PixelFormat::BGRA_PREMUL)) .repr; }; -// This structs represents the wuffs_aux::DecodeImageCallbacks::HandleMetadata +// This struct represents the wuffs_aux::DecodeImageCallbacks::HandleMetadata // input struct MetadataEntry { wuffs_base__more_information minfo{}; @@ -252,7 +254,7 @@ const std::string ImageDecoderError::FailedToOpenFile = uint32_t fourcc, wuffs_base__slice_u8 prefix_data, bool prefix_closed) override { if (enabled_decoders_.count(static_cast(fourcc)) == 0) { - return {nullptr, &free}; + return {nullptr}; } return wuffs_aux::DecodeImageCallbacks::SelectDecoder(fourcc, prefix_data, prefix_closed); diff --git a/src/wuffs-aux-json-wrapper.h b/src/wuffs-aux-json-wrapper.h index b07bb28..dd34315 100644 --- a/src/wuffs-aux-json-wrapper.h +++ b/src/wuffs-aux-json-wrapper.h @@ -3,11 +3,12 @@ #include #include -#include #include #include #include +#include "wuffs-unsupported-snapshot.c" + // This API wraps the wuffs_aux API for JSON decoding. The wrapper is needed // since the wuffs_aux API uses the callback-based approach which doesn't play // well with Python-C++ interop. diff --git a/src/wuffs-bindings.cpp b/src/wuffs-bindings.cpp index 806ee10..a15c3a2 100644 --- a/src/wuffs-bindings.cpp +++ b/src/wuffs-bindings.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "wuffs-unsupported-snapshot.c" #include "wuffs-aux-image-wrapper.h" #include "wuffs-aux-json-wrapper.h" diff --git a/test/images/lena.jpeg b/test/images/lena.jpeg new file mode 100644 index 0000000..36e760a Binary files /dev/null and b/test/images/lena.jpeg differ diff --git a/test/test_aux_image_decoder.py b/test/test_aux_image_decoder.py index 4de8917..00934b2 100644 --- a/test/test_aux_image_decoder.py +++ b/test/test_aux_image_decoder.py @@ -13,7 +13,8 @@ (ImageDecoderType.TGA, IMAGES_PATH + "/lena.tga"), (ImageDecoderType.NIE, IMAGES_PATH + "/hippopotamus.nie"), (ImageDecoderType.GIF, IMAGES_PATH + "/lena.gif"), - (ImageDecoderType.WBMP, IMAGES_PATH + "/lena.wbmp") + (ImageDecoderType.WBMP, IMAGES_PATH + "/lena.wbmp"), + (ImageDecoderType.JPEG, IMAGES_PATH + "/lena.jpeg") ] @@ -243,7 +244,7 @@ def test_decode_image_unsupported_image_format(param): @pytest.mark.parametrize("test_image", TEST_IMAGES) def test_decode_image_unsupported_pixel_format(test_image): config = ImageDecoderConfig() - config.pixel_format = PixelFormat.RGB + config.pixel_format = PixelFormat.YCOCGK decoder = ImageDecoder(config) decoding_result = decoder.decode(test_image[1]) assert_not_decoded(decoding_result, ImageDecoderError.UnsupportedPixelFormat)