Skip to content

Commit

Permalink
Copy attachments from source file to output file (#7)
Browse files Browse the repository at this point in the history
* cleanup

* create new guids for each z layer

* use guid only where necessary

* only activate acquisition tiles if command line parameter is set

* suggestions from code review

* cleanup

* cleanup

* fix linux build, more suggestions from code review

* missing files from previous commit

* suggestions from code review

* version number, documentation

* add changes

* cosmetic - remove some commented out code

* fix linter-issues

* copy attachments

* fix null pointer exception

* suggestions from code review

---------

Co-authored-by: ptahmose <[email protected]>
  • Loading branch information
RobertSchwede and ptahmose authored Aug 21, 2024
1 parent 55462e6 commit 0722536
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules" ${CMAKE_MODULE_PATH})

project ("warpaffine"
VERSION 0.4.0
VERSION 0.5.0
DESCRIPTION "experimental Deskew operation")

option(WARPAFFINE_BUILD_CLANGTIDY "Build with Clang-Tidy" OFF)
Expand Down
3 changes: 2 additions & 1 deletion documentation/version-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ version history {#version_history}
0.3.0 | N/A | initial release
0.3.1 | [3](https://github.com/ZEISS/warpaffine/pull/3) | bugfix for a crash for "CZIs containing a single brick but have an S-index"
0.3.2 | [5](https://github.com/ZEISS/warpaffine/pull/5) | bugfix for a deadlock in rare case
0.4.0 | [6](https://github.com/ZEISS/warpaffine/pull/6) | set re-tiling id of sub-blocks to allow for more sensible stitching of resulting CZI
0.4.0 | [6](https://github.com/ZEISS/warpaffine/pull/6) | set re-tiling id of sub-blocks to allow for more sensible stitching of resulting CZI
0.5.0 | [7](https://github.com/ZEISS/warpaffine/pull/7) | copy attachments from source document
9 changes: 9 additions & 0 deletions libwarpaffine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ int libmain(int argc, char** _argv)
}

auto reader_and_stream = CreateCziReader(app_context);

if (!get<0>(reader_and_stream) || !get<1>(reader_and_stream))
{
return EXIT_FAILURE;
Expand All @@ -494,6 +495,7 @@ int libmain(int argc, char** _argv)
}

auto writer = CreateCziWriter(app_context);

auto brick_source = CreateCziBrickSource(app_context, get<0>(reader_and_stream), get<1>(reader_and_stream));
auto warp_affine_engine = CreateWarpAffineEngine(app_context);

Expand Down Expand Up @@ -533,6 +535,13 @@ int libmain(int argc, char** _argv)
doWarp.DoOperation();
WaitUntilDone(app_context, doWarp);

get<0>(reader_and_stream)->EnumerateAttachments(
[&writer, &reader_and_stream](int index, const libCZI::AttachmentInfo& info) -> bool
{
writer->AddAttachment(get<0>(reader_and_stream)->ReadAttachment(index));
return true;
});

switch (const auto type_of_operation = app_context.GetCommandLineOptions().GetTypeOfOperation())
{
case OperationType::Deskew:
Expand Down
4 changes: 4 additions & 0 deletions libwarpaffine/sliceswriter/ISlicesWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class ICziSlicesWriter
/// Adds a slice (or subblock).
/// \param add_slice_info Information describing the add slice.
virtual void AddSlice(const AddSliceInfo& add_slice_info) = 0;

/// Adds an attachment, i.e. a copy from a source document.
/// \param attachment The attachment to be added.
virtual void AddAttachment(const std::shared_ptr<libCZI::IAttachment>& attachment) = 0;

/// Closes the output CZI-files. The specified metadata object (of the source document) is used
/// to update the metadata of the output CZI-file.
Expand Down
4 changes: 4 additions & 0 deletions libwarpaffine/sliceswriter/NullSlicesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ void NullSlicesWriter::AddSlice(const AddSliceInfo& add_slice_info)
{
}

void NullSlicesWriter::AddAttachment(const std::shared_ptr<libCZI::IAttachment>& attachment)
{
}

void NullSlicesWriter::Close(const std::shared_ptr<libCZI::ICziMetadata>&, const libCZI::ScalingInfo*, const std::function<void(libCZI::IXmlNodeRw*)>&)
{
}
1 change: 1 addition & 0 deletions libwarpaffine/sliceswriter/NullSlicesWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NullSlicesWriter : public ICziSlicesWriter
public:
std::uint32_t GetNumberOfPendingSliceWriteOperations() override;
void AddSlice(const AddSliceInfo& add_slice_info) override;
void AddAttachment(const std::shared_ptr<libCZI::IAttachment>& attachment) override;
void Close(const std::shared_ptr<libCZI::ICziMetadata>& source_metadata,
const libCZI::ScalingInfo* new_scaling_info,
const std::function<void(libCZI::IXmlNodeRw*)>& tweak_metadata_hook) override;
Expand Down
14 changes: 14 additions & 0 deletions libwarpaffine/sliceswriter/SlicesWriterTbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ void CziSlicesWriterTbb::AddSlice(const AddSliceInfo& add_slice_info)
++this->number_of_slicewrite_operations_in_flight_;
}

void CziSlicesWriterTbb::AddAttachment(const std::shared_ptr<libCZI::IAttachment>& attachment)
{
AddAttachmentInfo add_attachment_info;
const auto& attachment_info = attachment->GetAttachmentInfo();
add_attachment_info.contentGuid = attachment_info.contentGuid;
add_attachment_info.SetContentFileType(attachment_info.contentFileType);
add_attachment_info.SetName(attachment_info.name.c_str());
size_t size_of_data;
auto raw_data = attachment->GetRawData(&size_of_data);
add_attachment_info.ptrData = raw_data.get();
add_attachment_info.dataSize = static_cast<uint32_t>(size_of_data);
this->writer_->SyncAddAttachment(add_attachment_info);
}

void CziSlicesWriterTbb::WriteWorker()
{
try
Expand Down
2 changes: 1 addition & 1 deletion libwarpaffine/sliceswriter/SlicesWriterTbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CziSlicesWriterTbb : public ICziSlicesWriter
std::uint32_t GetNumberOfPendingSliceWriteOperations() override;

void AddSlice(const AddSliceInfo& add_slice_info) override;

void AddAttachment(const std::shared_ptr<libCZI::IAttachment>& attachment) override;
void Close(const std::shared_ptr<libCZI::ICziMetadata>& source_metadata,
const libCZI::ScalingInfo* new_scaling_info,
const std::function<void(libCZI::IXmlNodeRw*)>& tweak_metadata_hook) override;
Expand Down

0 comments on commit 0722536

Please sign in to comment.