Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-megalinter-to-v7
Browse files Browse the repository at this point in the history
  • Loading branch information
ptahmose authored Oct 16, 2023
2 parents c8a531a + 470bae2 commit 9c5e471
Show file tree
Hide file tree
Showing 170 changed files with 8,043 additions and 15,680 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,11 @@ __pycache__/

# BEGIN additions to the stock .gitignore-file

# exclude "cmake-directory"
cmake-build-debug/


# exclude "cmake-build-directory"
/cmake-build-*/

/build
/Src/Build/VS
/cmake-build-debug---wsl
/out/Src/Build/Doxygen/
/out/
/Src/.vscode
Expand Down
2 changes: 2 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DISABLE:
- SPELL # Comment to enable checks of spelling mistakes
DISABLE_ERRORS_LINTERS:
- MARKDOWN_MARKDOWN_LINK_CHECK # Make non-blocking due to network timeouts etc.
DISABLE_LINTERS:
- REPOSITORY_TRIVY # this linter seems currently broken, so we disable it here for now
C_CPPLINT_ARGUMENTS: --verbose=2
CPP_CPPLINT_ARGUMENTS: --verbose=2
SHOW_ELAPSED_TIME: true
Expand Down
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Files: cla_*.txt CMakeLists.txt CMakeSettings.json CODE_OF_CONDUCT.md CONTRIBUTI
Copyright: 2017-2022 Carl Zeiss Microscopy GmbH
License: LGPL-3.0-or-later

Files: Src/JxrDecode/Jxr/*
Files: Src/JxrDecode/jxrlib/*
Copyright: Microsoft Corp.
License: BSD-3-Clause

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html)

project(libCZI
VERSION 0.52.0
VERSION 0.53.0
HOMEPAGE_URL "https://github.com/ZEISS/libczi"
DESCRIPTION "libCZI is an Open Source Cross-Platform C++ library to read and write CZI")

Expand Down
41 changes: 30 additions & 11 deletions Src/CZICmd/SaveBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@
//-----------------------------------------------------------------------------

#if CZICMD_USE_WIC == 1
#include <atlbase.h>
#include <memory>
#include <wincodec.h>

#pragma comment(lib, "Windowscodecs.lib")

using namespace std;

struct COMDeleter
{
template <typename T>
void operator()(T* ptr)
{
if (ptr)
{
ptr->Release();
}
}
};

class CWicSaveBitmap :public ISaveBitmap
{
private:
CComPtr<IWICImagingFactory> cpWicImagingFactory;
unique_ptr<IWICImagingFactory, COMDeleter> cpWicImagingFactory;
public:
CWicSaveBitmap()
{
HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&this->cpWicImagingFactory);
IWICImagingFactory* pWicImagingFactory;
const HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, reinterpret_cast<LPVOID*>(&pWicImagingFactory));
ThrowIfFailed("Creating WICImageFactory", hr);
this->cpWicImagingFactory = unique_ptr<IWICImagingFactory, COMDeleter>(pWicImagingFactory);
}

virtual void Save(const wchar_t* fileName, SaveDataFormat dataFormat, libCZI::IBitmapData* bitmap)
Expand Down Expand Up @@ -59,39 +75,42 @@ class CWicSaveBitmap :public ISaveBitmap
private:
void SaveWithWIC(const wchar_t* filename, const GUID encoder, const WICPixelFormatGUID& wicPixelFmt, libCZI::IBitmapData* bitmap)
{
CComPtr<IWICStream> stream;
IWICStream* stream;
// Create a stream for the encoder
HRESULT hr = this->cpWicImagingFactory->CreateStream(&stream);
ThrowIfFailed("IWICImagingFactory::CreateStream", hr);
const unique_ptr<IWICStream, COMDeleter> up_stream(stream);

// Initialize the stream using the output file path
hr = stream->InitializeFromFilename(filename, GENERIC_WRITE);
hr = up_stream->InitializeFromFilename(filename, GENERIC_WRITE);
ThrowIfFailed("IWICStream::InitializeFromFilename", hr);

this->SaveWithWIC(stream, encoder, wicPixelFmt, bitmap);
this->SaveWithWIC(up_stream.get(), encoder, wicPixelFmt, bitmap);

hr = stream->Commit(STGC_DEFAULT);
hr = up_stream->Commit(STGC_DEFAULT);
ThrowIfFailed("IWICStream::Commit", hr, [](HRESULT ec) {return SUCCEEDED(ec) || ec == E_NOTIMPL; });
}

void SaveWithWIC(IWICStream* destStream, const GUID encoder, const WICPixelFormatGUID& wicPixelFmt, libCZI::IBitmapData* spBitmap)
{
// cf. http://msdn.microsoft.com/en-us/library/windows/desktop/ee719797(v=vs.85).aspx

CComPtr<IWICBitmapEncoder> wicBitmapEncoder;
IWICBitmapEncoder* wicBitmapEncoder;
HRESULT hr = this->cpWicImagingFactory->CreateEncoder(
encoder,
nullptr, // No preferred codec vendor.
&wicBitmapEncoder);
ThrowIfFailed("Creating IWICImagingFactory::CreateEncoder", hr);
unique_ptr<IWICBitmapEncoder, COMDeleter> up_wicBitmapEncoder(wicBitmapEncoder);

// Create encoder to write to image file
hr = wicBitmapEncoder->Initialize(destStream, WICBitmapEncoderNoCache);
ThrowIfFailed("IWICBitmapEncoder::Initialize", hr);

CComPtr<IWICBitmapFrameEncode> frameEncode;
IWICBitmapFrameEncode* frameEncode;
hr = wicBitmapEncoder->CreateNewFrame(&frameEncode, nullptr);
ThrowIfFailed("IWICBitmapEncoder::CreateNewFrame", hr);
unique_ptr<IWICBitmapFrameEncode, COMDeleter> up_frameEncode(frameEncode);

hr = frameEncode->Initialize(nullptr);
ThrowIfFailed("IWICBitmapFrameEncode::CreateNewFrame", hr);
Expand All @@ -112,8 +131,8 @@ class CWicSaveBitmap :public ISaveBitmap
// TODO
}

auto bitmapData = spBitmap->Lock();
hr = frameEncode->WritePixels(spBitmap->GetHeight(), bitmapData.stride, spBitmap->GetHeight() * bitmapData.stride, (BYTE*)bitmapData.ptrDataRoi);
const auto bitmapData = spBitmap->Lock();
hr = frameEncode->WritePixels(spBitmap->GetHeight(), bitmapData.stride, spBitmap->GetHeight() * bitmapData.stride, static_cast<BYTE*>(bitmapData.ptrDataRoi));
spBitmap->Unlock();
ThrowIfFailed("IWICBitmapFrameEncode::WritePixels", hr);

Expand Down
4 changes: 2 additions & 2 deletions Src/CZICmd/cmdlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,9 +1818,9 @@ std::shared_ptr<libCZI::IIndexSet> CCmdLineOptions::GetSceneIndexSet() const
return CCmdLineOptions::TryParseInt32(s, font_height);
}

/*static*/bool CCmdLineOptions::TryParseNewCziFileguid(const std::string& s, GUID* guid)
/*static*/bool CCmdLineOptions::TryParseNewCziFileguid(const std::string& s, libCZI::GUID* guid)
{
GUID g;
libCZI::GUID g;
bool b = TryParseGuid(convertUtf8ToUCS2(s), &g);
if (!b)
{
Expand Down
6 changes: 3 additions & 3 deletions Src/CZICmd/cmdlineoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class CCmdLineOptions
int fontHeight;

bool newCziFileGuidValid;
GUID newCziFileGuid;
libCZI::GUID newCziFileGuid;

std::string bitmapGeneratorClassName;

Expand Down Expand Up @@ -246,7 +246,7 @@ class CCmdLineOptions
std::wstring GetFontNameOrFile() const { return this->fontnameOrFile; }
int GetFontHeight() const { return this->fontHeight; }
bool GetIsFileGuidValid()const { return this->newCziFileGuidValid; }
const GUID& GetFileGuid()const { return this->newCziFileGuid; }
const libCZI::GUID& GetFileGuid()const { return this->newCziFileGuid; }
const std::string& GetBitmapGeneratorClassName()const { return this->bitmapGeneratorClassName; }
const std::map<std::string, std::string>& GetSubBlockKeyValueMetadata()const { return this->sbBlkMetadataKeyValue; }
bool GetHasSubBlockKeyValueMetadata()const { return this->sbBlkMetadataKeyValueValid; }
Expand Down Expand Up @@ -296,7 +296,7 @@ class CCmdLineOptions
static bool TryParseCreateSize(const std::string& s, std::tuple<std::uint32_t, std::uint32_t>* size);
static bool TryParseCreateTileInfo(const std::string& s, CreateTileInfo* create_tile_info);
static bool TryParseFontHeight(const std::string& s, int* font_height);
static bool TryParseNewCziFileguid(const std::string& s, GUID* guid);
static bool TryParseNewCziFileguid(const std::string& s, libCZI::GUID* guid);
static bool TryParseBitmapGenerator(const std::string& s, std::string* generator_class_name);
static bool TryParseSubBlockMetadataKeyValue(const std::string& s, std::map<std::string, std::string>* subblock_metadata_property_bag);
static bool TryParseCompressionOptions(const std::string& s, libCZI::Utils::CompressionOption* compression_option);
Expand Down
2 changes: 1 addition & 1 deletion Src/CZICmd/executeCreateCzi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class CExecuteCreateCzi
// (3) ...both things are not really necessary from a technical point of view, however... consistency-
// checking I'd consider an important feature

auto spWriterInfo = make_shared<CCziWriterInfo>(options.GetIsFileGuidValid() ? options.GetFileGuid() : GUID{ 0,0,0,{ 0,0,0,0,0,0,0,0 } });
auto spWriterInfo = make_shared<CCziWriterInfo>(options.GetIsFileGuidValid() ? options.GetFileGuid() : libCZI::GUID{ 0,0,0,{ 0,0,0,0,0,0,0,0 } });
//spWriterInfo->SetReservedSizeForMetadataSegment(true, 10 * 1024);
//spWriterInfo->SetReservedSizeForSubBlockDirectory(true, 400);
writer->Create(outStream, spWriterInfo);
Expand Down
6 changes: 3 additions & 3 deletions Src/CZICmd/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ const wchar_t* skipWhiteSpaceAndOneOfThese(const wchar_t* s, const wchar_t* char
return s;
}

std::ostream& operator<<(std::ostream& os, const GUID& guid)
std::ostream& operator<<(std::ostream& os, const libCZI::GUID& guid)
{
os << std::uppercase;
os.width(8);
Expand Down Expand Up @@ -361,7 +361,7 @@ std::ostream& operator<<(std::ostream& os, const GUID& guid)
/// \param [in,out] outGuid If non-null, the Guid will be put here if successful.
///
/// \return True if it succeeds, false if it fails.
bool TryParseGuid(const std::wstring& str, GUID* outGuid)
bool TryParseGuid(const std::wstring& str, libCZI::GUID* outGuid)
{
auto strTrimmed = trim(str);
if (strTrimmed.empty() || strTrimmed.length() < 2)
Expand All @@ -377,7 +377,7 @@ bool TryParseGuid(const std::wstring& str, GUID* outGuid)
std::wregex guidRegex(LR"([0-9A-Fa-f]{8}[-]([0-9A-Fa-f]{4}[-]){3}[0-9A-Fa-f]{12})");
if (std::regex_match(strTrimmed, guidRegex))
{
GUID g;
libCZI::GUID g;
uint32_t value;
char sz[9];
for (int i = 0; i < 8; ++i)
Expand Down
5 changes: 3 additions & 2 deletions Src/CZICmd/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include "inc_libCZI.h"


std::string convertToUtf8(const std::wstring& str);
std::wstring convertUtf8ToUCS2(const std::string& str);

Expand All @@ -29,9 +30,9 @@ std::vector<std::string> wrap(const char* text, size_t line_length/* = 72*/);
const wchar_t* skipWhiteSpaceAndOneOfThese(const wchar_t* s, const wchar_t* charToSkipOnce);
const char* skipWhiteSpaceAndOneOfThese(const char* s, const char* charsToSkipOnce);

std::ostream& operator<<(std::ostream& os, const GUID& guid);
std::ostream& operator<<(std::ostream& os, const libCZI::GUID& guid);

bool TryParseGuid(const std::wstring& str, GUID* g);
bool TryParseGuid(const std::wstring& str, libCZI::GUID* g);

/// This is an utility in order to implement a "scope guard" - an object that when gets out-of-scope is executing
/// a functor which may implement any kind of clean-up - akin to a finally-clause in C#. C.f. https://www.heise.de/blog/C-Core-Guidelines-finally-in-C-4133759.html
Expand Down
Loading

0 comments on commit 9c5e471

Please sign in to comment.