Skip to content

Commit

Permalink
Do not overwrite OriginalCompressionMethod anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
chriwiz committed Nov 10, 2023
1 parent 10ca8ba commit 94c3965
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
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
41 changes: 16 additions & 25 deletions czicompress/tests/test_copyoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}


Expand Down Expand Up @@ -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. <CurrentCompressionParameters />, so getting its value fails.
}

0 comments on commit 94c3965

Please sign in to comment.