From cf39d0042fcaf37b7aeee952ff0a2f5c4d5b8a48 Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 08:48:35 +0100 Subject: [PATCH 1/6] Do not overwrite OriginalCompressionMethod anymore --- czicompress/lib/src/copyczi.cpp | 10 ++---- czicompress/tests/test_copyoperation.cpp | 41 +++++++++--------------- 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/czicompress/lib/src/copyczi.cpp b/czicompress/lib/src/copyczi.cpp index ee6a2e4..c3853ac 100644 --- a/czicompress/lib/src/copyczi.cpp +++ b/czicompress/lib/src/copyczi.cpp @@ -378,12 +378,7 @@ std::shared_ptr CopyCziAndCompress::ModifyMetadata( auto metadata_src = metadata_segment->CreateMetaFromMetadataSegment(); const auto metadata_builder = libCZI::CreateMetadataBuilderFromXml(metadata_src->GetXml()); - metadata_builder->GetRootNode() - ->GetOrCreateChildNode("Metadata/Information/Image/OriginalCompressionMethod") - ->SetValue(this->compression_option_.first == libCZI::CompressionMode::Zstd0 ? "Zstd0" - : this->compression_option_.first == libCZI::CompressionMode::Zstd1 ? "Zstd1" - : "unknown"); - metadata_builder->GetRootNode()->GetOrCreateChildNode("Metadata/Information/Image/OriginalEncodingQuality")->SetValue("100"); + metadata_builder->GetRootNode()->GetOrCreateChildNode("Metadata/Information/Image/CurrentCompressionParameters")->SetValue("Lossless: True"); return metadata_builder; } @@ -411,8 +406,7 @@ std::shared_ptr CopyCziAndDecompress::ModifyMetadat auto metadata_src = metadata_segment->CreateMetaFromMetadataSegment(); const auto metadata_builder = libCZI::CreateMetadataBuilderFromXml(metadata_src->GetXml()); - metadata_builder->GetRootNode()->GetOrCreateChildNode("Metadata/Information/Image/OriginalCompressionMethod")->SetValue("Uncompressed"); - metadata_builder->GetRootNode()->GetOrCreateChildNode("Metadata/Information/Image/OriginalEncodingQuality")->SetValue("100"); + metadata_builder->GetRootNode()->GetOrCreateChildNode("Metadata/Information/Image/CurrentCompressionParameters")->SetValue(""); return metadata_builder; } diff --git a/czicompress/tests/test_copyoperation.cpp b/czicompress/tests/test_copyoperation.cpp index a6547c4..2757621 100644 --- a/czicompress/tests/test_copyoperation.cpp +++ b/czicompress/tests/test_copyoperation.cpp @@ -247,18 +247,14 @@ TEST_CASE("copyczi.2: run compression on simple synthetic document changes compr auto metadata_segment = reader_compressed_document->ReadMetadataSegment(); auto metadata = metadata_segment->CreateMetaFromMetadataSegment(); - auto compression_method = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalCompressionMethod"); - std::wstring compression_method_string; - bool success = compression_method->TryGetValue(&compression_method_string); - REQUIRE(success == true); - REQUIRE(compression_method_string == std::wstring(L"Zstd1")); - - std::wstring compression_level; - auto encoding_quality = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalEncodingQuality"); - std::wstring encoding_quality_string; - success = encoding_quality->TryGetValue(&encoding_quality_string); - REQUIRE(success == true); - REQUIRE(encoding_quality_string == std::wstring(L"100")); + auto first_subblock = reader_compressed_document->ReadSubBlock(0); + auto compression_method = first_subblock->GetSubBlockInfo().GetCompressionMode(); + REQUIRE(compression_method == libCZI::CompressionMode::Zstd1); + + auto compression_parameters = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/CurrentCompressionParameters"); + std::wstring compression_parameters_string; + bool success = compression_parameters->TryGetValue(&compression_parameters_string); + REQUIRE(compression_parameters_string == std::wstring(L"Lossless: True")); } @@ -331,17 +327,12 @@ TEST_CASE("copyczi.3: run decompression on simple synthetically compressed docum auto metadata_segment = reader_decompressed_document->ReadMetadataSegment(); auto metadata = metadata_segment->CreateMetaFromMetadataSegment(); - auto compression_method = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalCompressionMethod"); - auto xml = metadata->GetXml(); - std::wstring compression_method_string; - bool success = compression_method->TryGetValue(&compression_method_string); - REQUIRE(success == true); - REQUIRE(compression_method_string == std::wstring(L"Uncompressed")); - - std::wstring compression_level; - auto encoding_quality = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalEncodingQuality"); - std::wstring encoding_quality_string; - success = encoding_quality->TryGetValue(&encoding_quality_string); - REQUIRE(success == true); - REQUIRE(encoding_quality_string == std::wstring(L"100")); + auto first_subblock = reader_decompressed_document->ReadSubBlock(0); + auto compression_method = first_subblock->GetSubBlockInfo().GetCompressionMode(); + REQUIRE(compression_method == libCZI::CompressionMode::UnCompressed); + + auto compression_parameters = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/CurrentCompressionParameters"); + std::wstring compression_parameters_string; + bool success = compression_parameters->TryGetValue(&compression_parameters_string); + REQUIRE(success == false); // in case of uncompressed, the metadata is empty, i.e. , so getting its value fails. } From fb299313a8d7b30596c3135f4b43bcef54fa43f1 Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 09:14:56 +0100 Subject: [PATCH 2/6] Increase version number and remove alpha --- czicompress/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/czicompress/CMakeLists.txt b/czicompress/CMakeLists.txt index 0fb46c2..1d0f3f2 100644 --- a/czicompress/CMakeLists.txt +++ b/czicompress/CMakeLists.txt @@ -9,9 +9,8 @@ cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (htt # Note that the CMake-variables _VERSION_MAJOR, _VERSION_MINOR, ... are defined by this statement, # which are used in the build (so that - if changing the name here, change also the usage of those variables). project ("czicompress" - VERSION 0.5.1) + VERSION 0.5.2) -set(czicompress_VERSION_PATCH_FLAGS "-alpha") set(czicompress_VERSION_TWEAK_FLAGS "") if(WIN32) From f0ba934fcdfa69862b57baeb7da797938bfa09ca Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 10:09:29 +0100 Subject: [PATCH 3/6] Remove VersionSuffix for correct version number calculation --- czicompress/CMakeLists.txt | 1 + czishrink/Directory.Build.props | 1 - czishrink/upgrade-libczicompressc.ps1 | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/czicompress/CMakeLists.txt b/czicompress/CMakeLists.txt index 1d0f3f2..5b2991a 100644 --- a/czicompress/CMakeLists.txt +++ b/czicompress/CMakeLists.txt @@ -11,6 +11,7 @@ cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (htt project ("czicompress" VERSION 0.5.2) +set(czicompress_VERSION_PATCH_FLAGS "") set(czicompress_VERSION_TWEAK_FLAGS "") if(WIN32) diff --git a/czishrink/Directory.Build.props b/czishrink/Directory.Build.props index d154d14..16aaa31 100644 --- a/czishrink/Directory.Build.props +++ b/czishrink/Directory.Build.props @@ -11,6 +11,5 @@ true 1.0.0 - alpha.46 diff --git a/czishrink/upgrade-libczicompressc.ps1 b/czishrink/upgrade-libczicompressc.ps1 index 09da8d8..fa0cf4e 100644 --- a/czishrink/upgrade-libczicompressc.ps1 +++ b/czishrink/upgrade-libczicompressc.ps1 @@ -296,15 +296,15 @@ $NewVersionTuple="($($NewFileVersion.Major), $($NewFileVersion.Minor))" $AlteredSourceCode = $SourceCode -replace '^( *\(int Major, int Minor\) expected = ).*?;$',('$1' + $NewVersionTuple + ";") Set-Content -Path netczicompress/Models/PInvokeFileProcessor.cs -Value $AlteredSourceCode -# Increment VersionSuffix -Write-Output "INFO: Incrementing VersionSuffix in Directory.Build.props" +# Increment VersionPrefix +Write-Output "INFO: Incrementing VersionPrefix in Directory.Build.props" $file = Get-Item "Directory.Build.props" $xml = [xml](Get-Content -Path $file.FullName) -$versionElement = $xml.SelectSingleNode('//VersionSuffix') +$versionElement = $xml.SelectSingleNode('//VersionPrefix') $VersionTokens = $versionElement.'#text'.split(".") $versionElement.'#comment' = $BranchName $VersionTokens[1] = [string]([int]($VersionTokens.split(".")[1]) + 1) -$versionElement.'#text' = "$($VersionTokens[0]).$($VersionTokens[1])" +$versionElement.'#text' = "$($VersionTokens[0]).$($VersionTokens[1]).$($VersionTokens[2])" $xml.Save($file.FullName) # Git commit everything From 2bd5563ab015b11544e5cecf8a21a56f433ccc5f Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 11:00:30 +0100 Subject: [PATCH 4/6] Resolve code review comments --- czicompress/tests/test_copyoperation.cpp | 36 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/czicompress/tests/test_copyoperation.cpp b/czicompress/tests/test_copyoperation.cpp index 2757621..1818ea7 100644 --- a/czicompress/tests/test_copyoperation.cpp +++ b/czicompress/tests/test_copyoperation.cpp @@ -23,6 +23,23 @@ static int CheckSizeAndCastToInt(const uint32_t size) return static_cast(size); } +static void CheckOriginalCompressionMetadata(std::shared_ptr metadata) +{ + auto original_compression_method = + metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalCompressionMethod"); + std::wstring original_compression_method_string; + bool metadata_node_found = original_compression_method->TryGetValue(&original_compression_method_string); + REQUIRE(metadata_node_found == true); + REQUIRE(original_compression_method_string == std::wstring(L"JpegXr")); + + auto original_compression_parameters = + metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/OriginalCompressionParameters"); + std::wstring original_compression_parameters_string; + metadata_node_found = original_compression_parameters->TryGetValue(&original_compression_parameters_string); + REQUIRE(metadata_node_found == true); + REQUIRE(original_compression_parameters_string == std::wstring(L"Lossless: False, Quality: 77")); +} + /// Creates a CZI with four subblock of size 2x2 of pixeltype "Gray8" in a /// mosaic arrangement. The arrangement is as follows: /// +--+--+ @@ -126,6 +143,12 @@ static tuple, size_t> CreateCziWithFourSubblockInMosaicArrangem const libCZI::PrepareMetadataInfo prepare_metadata_info; auto metaDataBuilder = writer->GetPreparedMetadata(prepare_metadata_info); + metaDataBuilder->GetRootNode() + ->GetOrCreateChildNode("Metadata/Information/Image/OriginalCompressionMethod") + ->SetValue("JpegXr"); + metaDataBuilder->GetRootNode() + ->GetOrCreateChildNode("Metadata/Information/Image/OriginalCompressionParameters") + ->SetValue("Lossless: False, Quality: 77"); // NOLINTNEXTLINE: uninitialized struct is OK b/o Clear() libCZI::WriteMetadataInfo write_metadata_info; @@ -253,8 +276,11 @@ TEST_CASE("copyczi.2: run compression on simple synthetic document changes compr auto compression_parameters = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/CurrentCompressionParameters"); std::wstring compression_parameters_string; - bool success = compression_parameters->TryGetValue(&compression_parameters_string); + bool metadata_node_found = compression_parameters->TryGetValue(&compression_parameters_string); + REQUIRE(metadata_node_found == true); REQUIRE(compression_parameters_string == std::wstring(L"Lossless: True")); + + CheckOriginalCompressionMetadata(metadata); } @@ -333,6 +359,10 @@ TEST_CASE("copyczi.3: run decompression on simple synthetically compressed docum auto compression_parameters = metadata->GetChildNodeReadonly("ImageDocument/Metadata/Information/Image/CurrentCompressionParameters"); std::wstring compression_parameters_string; - bool success = compression_parameters->TryGetValue(&compression_parameters_string); - REQUIRE(success == false); // in case of uncompressed, the metadata is empty, i.e. , so getting its value fails. + bool metadata_node_found = compression_parameters->TryGetValue(&compression_parameters_string); + + // in case of uncompressed, the metadata is empty, i.e. , so getting its value fails. + REQUIRE(metadata_node_found == false); + + CheckOriginalCompressionMetadata(metadata); } From e8d9572b0f0510ec89f26f9fe690f15f02ac36e4 Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 11:39:13 +0100 Subject: [PATCH 5/6] Adjust github workflow to new version number --- .github/workflows/czishrink_dotnet.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/czishrink_dotnet.yml b/.github/workflows/czishrink_dotnet.yml index 67f43d7..7101722 100644 --- a/.github/workflows/czishrink_dotnet.yml +++ b/.github/workflows/czishrink_dotnet.yml @@ -51,16 +51,16 @@ jobs: id: getversion run: | $xml = [xml](Get-Content -Path "Directory.Build.props") - $version = $xml.SelectSingleNode('//VersionPrefix').'#text' + "-" + $xml.SelectSingleNode('//VersionSuffix').'#text' + $version = $xml.SelectSingleNode('//VersionPrefix').'#text' "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append shell: pwsh - name: Add build ID to version in Directory.Build.props run: | - Write-Output "Add build ID ${{ github.run_id }} to VersionSuffix in Directory.Build.props" + Write-Output "Add build ID ${{ github.run_id }} to VersionPrefix in Directory.Build.props" $file = Get-Item "Directory.Build.props" $xml = [xml](Get-Content -Path $file.FullName) - $versionElement = $xml.SelectSingleNode('//VersionSuffix') + $versionElement = $xml.SelectSingleNode('//VersionPrefix') $versionElement.'#text' += '+${{ github.run_id }}' $xml.Save($file.FullName) shell: pwsh From 01bf66b5253e4fe54adcb978ad58d2eea88022f9 Mon Sep 17 00:00:00 2001 From: "Widmann, Christian" Date: Fri, 10 Nov 2023 12:05:17 +0100 Subject: [PATCH 6/6] Fix broken netczicompress unit tests querying the version --- .../netczicompressTests/Models/ProgramNameAndVersionTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs b/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs index 1c15d3f..ad1d3ed 100644 --- a/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs +++ b/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs @@ -18,7 +18,7 @@ public void ToString_WhenCalled_ReturnsExpected() var actual = new ProgramNameAndVersion().ToString(); // ASSERT - var re = new Regex(@"^CZI Shrink 1\.0\.0-alpha\.[1-9]\d\d*(\+\d+)?$"); + var re = new Regex(@"^CZI Shrink 1\.0\.0(\+\d+)?$"); re.IsMatch(actual).Should().BeTrue(); } @@ -39,7 +39,7 @@ public void Version_WhenCalled_ReturnsExpected() var actual = new ProgramNameAndVersion().Version; // ASSERT - var re = new Regex(@"^1\.0\.0-alpha\.[1-9]\d\d*(\+\d+)?$"); + var re = new Regex(@"^1\.0\.0(\+\d+)?$"); re.IsMatch(actual).Should().BeTrue(); } }