Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not overwrite OriginalCompressionMethod anymore in czicompress #12

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/czishrink_dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions czicompress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (htt
# Note that the CMake-variables <Projectname>_VERSION_MAJOR, <Projectname>_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_PATCH_FLAGS "")
set(czicompress_VERSION_TWEAK_FLAGS "")

if(WIN32)
Expand Down
10 changes: 2 additions & 8 deletions czicompress/lib/src/copyczi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,7 @@ std::shared_ptr<libCZI::ICziMetadataBuilder> 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;
}
Expand Down Expand Up @@ -411,8 +406,7 @@ std::shared_ptr<libCZI::ICziMetadataBuilder> 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;
}
Expand Down
71 changes: 46 additions & 25 deletions czicompress/tests/test_copyoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ static int CheckSizeAndCastToInt(const uint32_t size)
return static_cast<int>(size);
}

static void CheckOriginalCompressionMetadata(std::shared_ptr<libCZI::ICziMetadata> 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:
/// +--+--+
Expand Down Expand Up @@ -126,6 +143,12 @@ static tuple<shared_ptr<void>, 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;
Expand Down Expand Up @@ -247,18 +270,17 @@ 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");
chriwiz marked this conversation as resolved.
Show resolved Hide resolved
std::wstring 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);
}


Expand Down Expand Up @@ -331,17 +353,16 @@ 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 metadata_node_found = compression_parameters->TryGetValue(&compression_parameters_string);

// in case of uncompressed, the metadata is empty, i.e. <CurrentCompressionParameters />, so getting its value fails.
REQUIRE(metadata_node_found == false);

CheckOriginalCompressionMetadata(metadata);
}
1 change: 0 additions & 1 deletion czishrink/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- Version -->
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha.46<!--feature/add-czishrink--></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}
}
8 changes: 4 additions & 4 deletions czishrink/upgrade-libczicompressc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down