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

Jbl/1036970 lax check for duplicate subblocks #2

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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.4.1)
VERSION 0.5.0)

set(czicompress_VERSION_PATCH_FLAGS "-alpha")
set(czicompress_VERSION_TWEAK_FLAGS "")
Expand All @@ -29,7 +29,7 @@ include(FetchContent)
FetchContent_Declare(
libczi
GIT_REPOSITORY https://github.com/ZEISS/libczi.git
GIT_TAG c9954d58759ef6dd7d7c6a53c163ea8349855392
GIT_TAG 05bc1ebdca520ba2c5bfc3b9fcde76c548e98545
)

if(NOT libCZI_POPULATED)
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ Clicking on these artifacts will download a ZIP file with the executable. The ex
Start the executable from the command line, providing the required command line arguments.

```
Usage: czicompress [OPTIONS]
Usage: czicompress.exe [OPTIONS]

version: 0.4.2.0
ptahmose marked this conversation as resolved.
Show resolved Hide resolved

Options:
-h,--help Print this help message and exit
Expand All @@ -72,6 +74,13 @@ Options:
Specify compression parameters. The default is
'zstd1:ExplicitLevel=1;PreProcess=HiLoByteUnpack'.

-w,--overwrite If the output file exists, try to overwrite it.

--ignore_duplicate_subblocks BOOLEAN
If this option is enabled, the operation will ignore if
duplicate subblocks are encountered in the source document.
Otherwise, an error will be reported. The default is 'on'.


Copies the content of a CZI-file into another CZI-file changing the compression
of the image data.
Expand Down
10 changes: 6 additions & 4 deletions app/CZIcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ int main(int argc, char** argv)

// Create an "output-stream-object"
const auto output_stream =
libCZI::CreateOutputStreamForFile(utils::utf8::WidenUtf8(command_line_options.GetOutputFileName()).c_str(), false);
libCZI::CreateOutputStreamForFile(utils::utf8::WidenUtf8(command_line_options.GetOutputFileName()).c_str(), command_line_options.GetOverwriteExistingFile());

// create the "CZI-writer"-object
const auto writer = libCZI::CreateCZIWriter();
// create (and configure) the "CZI-writer"-object
libCZI::CZIWriterOptions czi_writer_options;
czi_writer_options.allow_duplicate_subblocks = command_line_options.GetIgnoreDuplicateSubblocks();
const auto writer = libCZI::CreateCZIWriter(&czi_writer_options);

// GUID_NULL here means that a new Guid is created
const auto czi_writer_info = std::make_shared<libCZI::CCziWriterInfo>(GUID{0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto czi_writer_info = std::make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}});
ptahmose marked this conversation as resolved.
Show resolved Hide resolved

// TODO(JBL): it might be desirable to make reservations for the
// subblock-directory-/attachments-directory-/metadata-segment
Expand Down
6 changes: 4 additions & 2 deletions capi/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ class FileProcessor final
open_options.ignore_sizem_for_pyramid_subblocks = true;
reader->Open(stream, &open_options);

// create the "CZI-writer"-object
// create (and configure) the "CZI-writer"-object
const std::string output_string(output_path);
const auto output_stream = libCZI::CreateOutputStreamForFile(utils::utf8::WidenUtf8(output_string).c_str(), false);

libCZI::CZIWriterOptions czi_writer_options;
ptahmose marked this conversation as resolved.
Show resolved Hide resolved
czi_writer_options.allow_duplicate_subblocks = true;
const auto writer = libCZI::CreateCZIWriter();
ptahmose marked this conversation as resolved.
Show resolved Hide resolved

// GUID_NULL here means that a new Guid is created
const auto czi_writer_info = std::make_shared<libCZI::CCziWriterInfo>(GUID{0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto czi_writer_info = std::make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}});

// TODO(JBL): it might be desirable to make reservations for the
// subblock-directory-/attachments-directory-/metadata-segment
Expand Down
13 changes: 12 additions & 1 deletion lib/include/commandlineoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class CommandLineOptions
std::string output_filename_;
CompressionStrategy compression_strategy_{CompressionStrategy::kInvalid};
libCZI::Utils::CompressionOption compression_option_;

bool overwrite_existing_file_{false};
bool ignore_duplicate_subblocks_{true};
public:
/// Values that represent the result of the "Parse"-operation.
enum class ParseResult
Expand Down Expand Up @@ -91,6 +92,16 @@ class CommandLineOptions
/// \returns The compression option.
const libCZI::Utils::CompressionOption& GetCompressionOption() const { return this->compression_option_; }

/// Gets a boolean indicating whether when creating the output file, it is to be overwritten if it already exists.
///
/// \returns True if an existing file is to be overwritten (if it exists); false otherwise.
bool GetOverwriteExistingFile() const { return this->overwrite_existing_file_; }

/// Gets a boolean indicating whether the CZIWriter object should be configured to ignore duplicate subblocks.
///
/// \returns True if duplicate subblocks are to be ignore (with the CZIWriter object); false otherwise.
ptahmose marked this conversation as resolved.
Show resolved Hide resolved
bool GetIgnoreDuplicateSubblocks() const { return this->ignore_duplicate_subblocks_; }

private:
static std::string GetFooterText();
};
28 changes: 26 additions & 2 deletions lib/src/commandlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class CustomFormatter : public CLI::Formatter
usage << result_from_stock_implementation << endl
<< " version: " << CZICOMPRESS_VERSION_MAJOR << "." << CZICOMPRESS_VERSION_MINOR << "." << CZICOMPRESS_VERSION_PATCH;
std::string tweak(CZICOMPRESS_VERSION_TWEAK);
if (!tweak.empty()) {
usage << "." << tweak;
if (!tweak.empty())
{
usage << "." << tweak;
}
usage << endl;
return usage.str();
Expand Down Expand Up @@ -144,6 +145,18 @@ CommandLineOptions::ParseResult CommandLineOptions::Parse(int argc, const char*
string source_filename; // NOLINT(misc-const-correctness)
string destination_filename; // NOLINT(misc-const-correctness)
string compression_options_text; // NOLINT(misc-const-correctness)
bool overwrite_existing_file{false};
bool ignore_duplicate_subblocks{false};

// specify the string-to-enum-mapping for a boolean option
std::map<std::string, bool> map_string_to_boolean{
ptahmose marked this conversation as resolved.
Show resolved Hide resolved
{"0", false},
{"false", false},
{"no", false},
{"1", true},
{"true", true},
{"yes", true},
};

// specify the string-to-enum-mapping for "command"
const std::map<std::string, Command> map_string_to_command{{"compress", Command::kCompress}, {"decompress", Command::kDecompress}};
Expand Down Expand Up @@ -188,6 +201,14 @@ CommandLineOptions::ParseResult CommandLineOptions::Parse(int argc, const char*
->option_text("COMPRESSION_OPTIONS")
->default_val(CommandLineOptions::kDefaultCompressionOptions);

app.add_flag("-w,--overwrite", overwrite_existing_file, "If the output file exists, try to overwrite it.");
app.add_option("--ignore_duplicate_subblocks", ignore_duplicate_subblocks,
"If this option is enabled, the operation will ignore if duplicate subblocks are encountered in the source document. "
"Otherwise, an error will be reported. The default is 'on'.")
->option_text("BOOLEAN")
->default_val(true)
->transform(CLI::CheckedTransformer(map_string_to_boolean, CLI::ignore_case));

const auto formatter = make_shared<CustomFormatter>();
app.formatter(formatter);
app.footer(CommandLineOptions::GetFooterText());
Expand Down Expand Up @@ -217,6 +238,9 @@ CommandLineOptions::ParseResult CommandLineOptions::Parse(int argc, const char*
this->compression_option_ = libCZI::Utils::ParseCompressionOptions(compression_options_text);
}

this->overwrite_existing_file_ = overwrite_existing_file;
this->ignore_duplicate_subblocks_ = ignore_duplicate_subblocks;

return CommandLineOptions::ParseResult::kOk;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/test_copyoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static tuple<shared_ptr<void>, size_t> CreateCziWithFourSubblockInMosaicArrangem
auto writer = libCZI::CreateCZIWriter();
auto outStream = make_shared<CMemOutputStream>(0);

auto spWriterInfo = make_shared<libCZI::CCziWriterInfo>(GUID{0x1234567, 0x89ab, 0xcdef, {1, 2, 3, 4, 5, 6, 7, 8}}, // NOLINT
auto spWriterInfo = make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0x1234567, 0x89ab, 0xcdef, {1, 2, 3, 4, 5, 6, 7, 8}}, // NOLINT
libCZI::CDimBounds{{libCZI::DimensionIndex::C, 0, 1}}, // set a bounds for C
0, 3); // set a bounds M : 0<=m<=0
writer->Create(outStream, spWriterInfo);
Expand Down Expand Up @@ -162,7 +162,7 @@ TEST_CASE("copyczi.1: run compression on simple synthetic document", "[copyczi]"
// create a CZI-writer object on a new memory stream
auto writer = libCZI::CreateCZIWriter();
const auto memory_backed_stream_destination_document = make_shared<CMemInputOutputStream>(0);
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
writer->Create(memory_backed_stream_destination_document, writer_info);

// act
Expand Down Expand Up @@ -218,7 +218,7 @@ TEST_CASE("copyczi.2: run compression on simple synthetic document changes compr
// create a CZI-writer object on a new memory stream
auto writer = libCZI::CreateCZIWriter();
const auto memory_backed_stream_destination_document = make_shared<CMemInputOutputStream>(0);
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
writer->Create(memory_backed_stream_destination_document, writer_info);

// act
Expand Down Expand Up @@ -280,7 +280,7 @@ TEST_CASE("copyczi.3: run decompression on simple synthetically compressed docum
// create a CZI-writer object on a new memory stream
auto writer = libCZI::CreateCZIWriter();
const auto memory_backed_stream_destination_document = make_shared<CMemInputOutputStream>(0);
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto writer_info = make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
writer->Create(memory_backed_stream_destination_document, writer_info);

// act
Expand Down Expand Up @@ -309,7 +309,7 @@ TEST_CASE("copyczi.3: run decompression on simple synthetically compressed docum
// create a CZI-writer object on a new memory stream
auto writer_2 = libCZI::CreateCZIWriter();
const auto memory_backed_stream_destination_document_2 = make_shared<CMemInputOutputStream>(0);
const auto writer_info_2 = make_shared<libCZI::CCziWriterInfo>(GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
const auto writer_info_2 = make_shared<libCZI::CCziWriterInfo>(libCZI::GUID{0x0, 0x0, 0x0, {0, 0, 0, 0, 0, 0, 0, 0}});
writer_2->Create(memory_backed_stream_destination_document_2, writer_info_2);

// act
Expand Down