Skip to content

Adding experimental "chunked compression"#172

Merged
ptahmose merged 91 commits into
ZEISS:mainfrom
ptahmose:jbl/chunked_compression_experimental
Jul 10, 2026
Merged

Adding experimental "chunked compression"#172
ptahmose merged 91 commits into
ZEISS:mainfrom
ptahmose:jbl/chunked_compression_experimental

Conversation

@ptahmose

@ptahmose ptahmose commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds experimental support for a new chunked CZI subblock compression format.

The new format stores compressed subblock pixel data as a compact chunked header followed by independently compressed data chunks. It is exposed as CompressionMode::ChunkedExtensible and currently supports Zstd and LZ4 as per-chunk codecs. The format also records per-chunk compressed/decompressed sizes and optional Hi/Lo-byte packing preprocessing information.

The implementation includes:

  • chunked-compression header creation and parsing
  • chunked compression with Zstd or LZ4 chunk codecs
  • chunked decompression through the normal bitmap/subblock decode path
  • integration with CreateBitmapFromSubBlock and reader/accessor workflows
  • compression-option parsing for the informal chunked: option syntax
  • CMake gating behind experimental build options
  • unit coverage for header parsing, encode/decode roundtrips, reader integration, and malformed-size handling

This feature is intentionally experimental. It is disabled by default and only available when LIBCZI_BUILD_EXPERIMENTAL_CHUNKED_COMPRESSION is enabled, or through the global experimental policy LIBCZI_BUILD_ENABLE_EXPERIMENTAL_FUNCTIONALITY=ON.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Test coverage was added for the new experimental chunked-compression path, including:

  • chunked-compression header creation/parsing
  • Zstd and LZ4 chunk codec roundtrips
  • Gray8, Gray16, BGR24, and BGR48 encode/decode scenarios
  • Hi/Lo-byte packing preprocessing
  • multi-chunk payloads and final short chunks
  • reader integration for CompressionMode::ChunkedExtensible
  • malformed/truncated payload and size-mismatch behavior

Validated through the libCZI unit-test suite.

Checklist:

  • I followed the Contributing Guidelines.
  • I did a self-review.
  • I commented my code, particularly in hard-to-understand areas.
  • I updated the documentation.
  • I updated the version of libCZI following Versioning of libCZI depending on the type of change
    • Bug fix -> PATCH
    • New feature -> MINOR
    • Breaking change -> MAJOR
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

ptahmose and others added 19 commits June 22, 2026 14:09
Refactor bitmap creation logic to modularize decoding from compressed data, introducing new internal helpers and a public API (CreateBitmapFromSubBlockData) for direct bitmap creation from raw data and metadata. Update unit test CMake integration to use gtest_discover_tests when not cross-compiling. Switch CLI11 include to single-header. Improves modularity, testability, and API flexibility.
Introduce AttachmentStatistics struct and GetAttachmentStatistics() method to IAttachmentRepository and its implementations. Provide attachment count retrieval in CCZIReader, CCziReaderWriter, and CCziAttachmentsDirectory. Update headers and source files to support querying attachment statistics.
Changed Codecov flags from ${{matrix.OS}} to ${{matrix.os}} to resolve a case-sensitivity issue with the matrix variable in the workflow configuration.
Bump project version to 0.68.0 in CMakeLists.txt. Add version_history.md entry for v0.68.0, highlighting improved CMake packaging, better downstream build integration, and minor API additions (see PR ZEISS#170).
Refactored switch statement formatting for clarity. Added null checks for options pointer in JpgXr and Zstd0 cases, defaulting to true for mismatch handling if options is null.
Add preprocessor checks to select appropriate bitmap copy or conversion routines depending on host endianness and pixel type. Ensures correct pixel data handling on both big-endian and little-endian systems.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The cmake.yml workflow was updated to set -DLIBCZI_BUILD_UNITTESTS=OFF, preventing unit tests from being built or run during the build process. This change may improve build speed or reflect that tests are not required in this environment.
Introduced chunked compression and decompression with support for Zstd and LZ4 codecs. Added new source files for chunked compression logic, header creation/parsing, and a dedicated decoder. Implemented shared utilities for argument validation. The chunked header format is extensible and supports optional preprocessing (hi-lo byte packing). Updated CMakeLists.txt to include new files. All new code is LGPL-3.0-or-later licensed.
Comprehensive tests for chunked compression were added:
- New `test_chunkedcompression.cpp` covers encoding/decoding for Gray8, Gray16, Bgr24, Bgr48, roundtrip tests, and hi-lo-byte-packing for both Zstd and LZ4 codecs.
- Header parsing, creation, and error handling tests added to `test_ZstdCompress.cpp`.
- Compression option parsing tests added to `test_Utilities.cpp`.
- `test_reader.cpp` extended with helpers and tests for handling chunked-compressed subblocks with size mismatches and resolution protocol.
- CMake updated to include new test file.

These changes improve test coverage for chunked compression, edge cases, and error handling.
@ptahmose ptahmose added the cla Contributor License Agreement sent to Admin label Jun 24, 2026
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.48789% with 214 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.91%. Comparing base (11cbdc2) to head (7c1fe01).

Files with missing lines Patch % Lines
Src/libCZI/chunkedCompress.cpp 82.94% 139 Missing ⚠️
Src/libCZI/decoder_chunkedcompression.cpp 80.00% 31 Missing ⚠️
Src/libCZI/utilities.cpp 76.47% 20 Missing ⚠️
Src/libCZI/compresscommon.cpp 52.94% 16 Missing ⚠️
Src/libCZI/libCZI_Site.cpp 50.00% 4 Missing ⚠️
Src/libCZI/DimCoordinate.cpp 33.33% 2 Missing ⚠️
Src/libCZI/CreateBitmap.cpp 90.00% 1 Missing ⚠️
Src/libCZI/libCZI_Utilities.cpp 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #172      +/-   ##
==========================================
+ Coverage   66.63%   67.91%   +1.27%     
==========================================
  Files          96       99       +3     
  Lines       12402    13467    +1065     
==========================================
+ Hits         8264     9146     +882     
- Misses       4138     4321     +183     
Flag Coverage Δ
windows-latest 67.91% <81.48%> (+1.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Replaced uint32_t with int32_t for CHUNKEDCOMPRESSION_CODEC CompressParameter to ensure type consistency. Added missing "inc_libCZI_Config.h" include and cleaned up include formatting in decoder_chunkedcompression.cpp. No functional changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an experimental “chunked compression” format (encoding + decoding) and wires it through libCZI’s codec selection and bitmap-creation pipeline, alongside a couple of API additions and CMake/test infrastructure updates.

Changes:

  • Add chunked-compression encoder/decoder (zstd-based, optional LZ4 codec) and expose it via CompressionMode::ChunkedExtensible and ImageDecoderType::ChunkedCompression.
  • Add new public APIs: CreateBitmapFromSubBlockData(...) and IAttachmentRepository::GetAttachmentStatistics().
  • Improve CTest/GTest integration (gtest_discover_tests), update CLI11, and extend CI/CMake configuration for the new functionality.

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
Src/libCZIAPI_UnitTests/CMakeLists.txt Switch unit test registration to gtest_discover_tests (with cross-compile fallback).
Src/libCZI/zstdCompress.cpp Refactor shared compression argument validation into CompressionUtilities.
Src/libCZI/utilities.h Add parsing helpers and Utilities::ContainsToken declaration.
Src/libCZI/utilities.cpp Implement new parsing helpers and Utilities::ContainsToken.
Src/libCZI/libCZI.h Add new bitmap creation API and new attachment statistics API surface; extend bitmap options for chunked mismatch handling.
Src/libCZI/libCZI_Utilities.h Add string keys for chunked compression options.
Src/libCZI/libCZI_Utilities.cpp Extend compression-option parsing to support chunked compression and parameters.
Src/libCZI/libCZI_Site.h Add ImageDecoderType::ChunkedCompression.
Src/libCZI/libCZI_Site.cpp Lazily instantiate and return the chunked-compression decoder.
Src/libCZI/libCZI_Pixels.h Add CompressionMode::ChunkedExtensible.
Src/libCZI/libCZI_Config.h.in Add build-time macro for experimental chunked-compression availability.
Src/libCZI/libCZI_compress.h Add chunked compression APIs and ChunkedCompressionHeaderHelper.
Src/libCZI/DimCoordinate.cpp Replace local int parsing with shared Utilities::TryParseInt32.
Src/libCZI/decoder_zstd.cpp Use shared Utilities::ContainsToken for decoder options.
Src/libCZI/decoder_chunkedcompression.h New: chunked-compression decoder interface.
Src/libCZI/decoder_chunkedcompression.cpp New: chunked-compression decoding + size mismatch resolution.
Src/libCZI/CziUtils.cpp Map CompressionMode::ChunkedExtensible to/from integer values.
Src/libCZI/CziReaderWriter.h Add GetAttachmentStatistics() implementation hook.
Src/libCZI/CziReaderWriter.cpp Implement GetAttachmentStatistics() for reader/writer.
Src/libCZI/CZIReader.h Add GetAttachmentStatistics() to reader.
Src/libCZI/CZIReader.cpp Implement GetAttachmentStatistics() for reader.
Src/libCZI/CziAttachmentsDirectory.h Add GetAttachmentCount() helper.
Src/libCZI/CziAttachmentsDirectory.cpp Implement GetAttachmentCount().
Src/libCZI/CreateBitmap.cpp Add chunked decode path; add new CreateBitmapFromSubBlockData(...) API.
Src/libCZI/compresscommon.h New: common compression argument validation utilities.
Src/libCZI/compresscommon.cpp New: implementation of compression argument validation utilities.
Src/libCZI/CMakeLists.txt Add new sources; add optional LZ4 FetchContent/external linkage; define availability macro.
Src/libCZI/chunkedCompress.cpp New: chunked compression encoder + header creation/parsing utilities.
Src/libCZI_UnitTests/test_ZstdCompress.cpp Add header-walk/parse/create tests for chunked header helper.
Src/libCZI_UnitTests/test_Utilities.cpp Add tests for parsing chunked compression options.
Src/libCZI_UnitTests/test_readerwriter.cpp Add tests for attachment statistics API and not-operational behavior.
Src/libCZI_UnitTests/test_reader.cpp Add tests for CreateBitmapFromSubBlockData and chunked mismatch handling.
Src/libCZI_UnitTests/test_chunkedcompression.cpp New: end-to-end tests for chunked compress/decode (zstd + LZ4).
Src/libCZI_UnitTests/CMakeLists.txt Add new test file; switch to gtest_discover_tests (with cross-compile fallback).
Src/CZICmd/cmdlineoptions.cpp Update CLI11 include usage.
Src/CZICmd/CMakeLists.txt Bump CLI11 dependency version.
docs/source/pages/version_history.md Add version-history entry describing this PR.
CMakeLists.txt Add experimental build options; bump project version.
cmake/patch_cmake_minimum_version.cmake New: helper to patch FetchContent deps’ cmake_minimum_required() for CMake 4.x warnings.
.github/workflows/cmake.yml Adjust workflow flags casing and disable unit tests for arm64-windows-static build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Src/libCZI/chunkedCompress.cpp Outdated
Comment thread Src/libCZI/utilities.cpp
Comment thread Src/libCZI/decoder_chunkedcompression.cpp Outdated
Comment thread Src/libCZI/decoder_chunkedcompression.cpp Outdated
Comment thread Src/libCZI/decoder_chunkedcompression.cpp Outdated
Comment thread Src/libCZI/CreateBitmap.cpp Outdated
Comment thread Src/libCZI/libCZI_compress.h
Comment thread Src/libCZI/libCZI_compress.h
Comment thread CMakeLists.txt
Comment thread Src/libCZI_UnitTests/test_reader.cpp
ptahmose added 3 commits June 25, 2026 00:36
Introduced LZ4 compression as an optional build feature via CMake. Updated CI pipeline to install LZ4 dependencies on all platforms. Replaced the experimental chunked compression macro with a new LZ4 availability macro. Updated source and config files to use the new macro and enable LZ4-based compression and decompression when available.
Changed liblz4-dev installation from vcpkg to apt-get in cmake.yml. Now, only azure-storage-blobs-cpp and azure-identity-cpp are installed via vcpkg, improving package management consistency.
Replaced apt-get installation of liblz4-dev with vcpkg installation of lz4, grouping it with other Azure SDK dependencies for consistency.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 4 comments.

Comment thread Src/libCZI/chunkedCompress.cpp
Comment thread Src/libCZI/utilities.cpp Outdated
Comment thread Src/libCZI/utilities.cpp Outdated
Comment thread Src/libCZI/decoder_chunkedcompression.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 2 comments.

Comment thread Src/libCZI/chunkedCompress.cpp Outdated
Comment thread Src/libCZI/decoder_chunkedcompression.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 3 comments.

Comment thread Src/libCZI/chunkedCompress.cpp
Comment thread Src/libCZI/chunkedCompress.cpp
Comment thread Src/libCZI/libCZI_Config.h.in

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 2 comments.

Comment thread Src/libCZI/compresscommon.cpp
Comment thread Src/libCZI/libCZI_Config.h.in
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 3 comments.

Comment thread Src/libCZI/chunkedCompress.cpp
Comment thread Src/libCZI/decoder_chunkedcompression.cpp
Comment thread Src/libCZI/decoder_chunkedcompression.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 3 comments.

Comment thread Src/libCZI/chunkedCompress.cpp
Comment thread Src/libCZI/utilities.cpp
Comment thread Src/libCZI/libCZI_Config.h.in
ptahmose and others added 5 commits July 10, 2026 11:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Unknown chunk IDs in the compression header now trigger an invalid_argument exception instead of being ignored. This change aligns with documentation and includes comments and a TODO regarding future forward compatibility.
Added detailed documentation for the experimental chunked compression mode, including a new page with format and usage details. Updated build and API docs to describe enabling and using the feature. Adjusted Doxyfile to define the feature macro when enabled. Updated the documentation index to reference the new content.
@ptahmose ptahmose marked this pull request as ready for review July 10, 2026 10:31

@ReneBoeckelmann ReneBoeckelmann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ptahmose ptahmose merged commit 3ec0807 into ZEISS:main Jul 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla Contributor License Agreement sent to Admin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants