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/cleanup jxrlib #67

Merged
merged 101 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
8624b85
some hacking - compiles and unittests work
ptahmose Jul 23, 2023
2d552aa
somewhat working now
ptahmose Jul 26, 2023
e360f74
update
ptahmose Jul 27, 2023
1bc1e97
update
ptahmose Jul 28, 2023
fb8df02
cleanup unsused files
ptahmose Jul 28, 2023
52ef86b
use stdint
ptahmose Jul 28, 2023
22abeed
remove SAL
ptahmose Jul 28, 2023
f84a7aa
make build on Linux
ptahmose Jul 28, 2023
d8a2e88
cleanup
ptahmose Jul 28, 2023
0b0538a
get rid of min/max
ptahmose Jul 28, 2023
adf00c0
get rid of min/max
ptahmose Jul 28, 2023
3d9e7f5
load4 - make big-endian aware etc.
ptahmose Jul 28, 2023
446afda
fix JXRDECODE_HAS_BUILTIN_BSWAP32
ptahmose Jul 28, 2023
429f5f2
fix
ptahmose Jul 28, 2023
ed60c08
test
ptahmose Jul 28, 2023
aff9620
detect "__builtin_bswap32"
ptahmose Jul 29, 2023
0642563
test (big-endian decoder)
ptahmose Jul 29, 2023
f5dd1b9
cosmetic
ptahmose Jul 29, 2023
e398516
forceinline...
ptahmose Jul 29, 2023
ff45e5e
fix warning
ptahmose Jul 29, 2023
aa6fb35
cosmetic & _rotl
ptahmose Jul 30, 2023
2194581
_rotl ...
ptahmose Jul 30, 2023
d7bb1e1
rotl - use if available
ptahmose Jul 30, 2023
f671e32
remove "special characters", fix segdec.c
ptahmose Jul 30, 2023
aca5a1e
fix problem with "aligned_malloc" (seen on MacOS)
ptahmose Jul 31, 2023
5dac735
use "tagWMPStream", some steps ahead
ptahmose Aug 4, 2023
acf5359
...some steps ahead
ptahmose Aug 5, 2023
13eb9f8
encoding - 1st tentative steps
ptahmose Aug 5, 2023
238090b
adding "heap-based-stream"
ptahmose Aug 5, 2023
831f7c1
introduce "JxrDecode2::CompressedData"
ptahmose Aug 6, 2023
3f072d2
cosmetic
ptahmose Aug 6, 2023
2ad18ef
get rid of "atlbase"
ptahmose Aug 17, 2023
a551829
some cleanup
ptahmose Aug 17, 2023
622a692
get rid of ATL-dependency
ptahmose Aug 18, 2023
f075f21
cleanup
ptahmose Aug 18, 2023
1a82b62
cosmetic & make compile with Mingw
ptahmose Aug 19, 2023
c81d82b
refactor "google-test"-integration
ptahmose Aug 20, 2023
eb13400
refactor googletest integration
ptahmose Aug 20, 2023
e2e4660
fix build errors
ptahmose Aug 20, 2023
1a1477d
cosmetic
ptahmose Aug 20, 2023
49a37a1
finish JPGXR-encode-decode-unittest
ptahmose Aug 20, 2023
cf7afcc
tinkering...
ptahmose Aug 20, 2023
9527164
fix
ptahmose Aug 20, 2023
ab81c74
tentative - get rid of "temp-file-stuff"
ptahmose Aug 21, 2023
a9d5c6b
fix issue with CMake < 3.24
ptahmose Aug 21, 2023
c1911ca
no more "temp files for encoding"
ptahmose Aug 21, 2023
d9424bb
starting with "quality" and some more (WIP)
ptahmose Aug 23, 2023
e653785
add some tests for JPGXR, cosmetic
ptahmose Aug 26, 2023
9d2711b
use good-old rand()
ptahmose Aug 26, 2023
0096cba
update
ptahmose Aug 27, 2023
1f30eaf
fix some clang-warnings
ptahmose Aug 27, 2023
49e5e8b
fix clang warning
ptahmose Aug 27, 2023
0adef49
clang warning
ptahmose Aug 27, 2023
e8a9994
fix some clang warnings
ptahmose Aug 27, 2023
bd9b6d6
get rid of "GUID"
ptahmose Aug 27, 2023
e8be68a
fix
ptahmose Aug 27, 2023
2ef3cb6
remove stdafx
ptahmose Aug 27, 2023
c0255d3
remove includes of stdafx.h
ptahmose Aug 27, 2023
1b91ac0
cosmetic
ptahmose Aug 27, 2023
4db0060
merge of "get rid of GUID"
ptahmose Aug 27, 2023
5635d54
fix
ptahmose Aug 27, 2023
a90f32b
fix
ptahmose Aug 27, 2023
683bb19
remove "printf's"
ptahmose Aug 28, 2023
1e0949c
make gray32float work with jpxr
ptahmose Aug 29, 2023
9a7d9b2
add include / fix build error
ptahmose Aug 29, 2023
2853d5c
cleanup & cosmetic
ptahmose Aug 29, 2023
bd79940
more tests
ptahmose Aug 29, 2023
b87d3f9
cosmetic
ptahmose Aug 30, 2023
3b940f5
cosmetic
ptahmose Aug 30, 2023
1d92fb6
cosmetic
ptahmose Aug 31, 2023
5f8a6c3
deal with BGR48 vs RGB48
ptahmose Sep 7, 2023
75917b9
cosmetic
ptahmose Sep 10, 2023
2682439
cosmetic
ptahmose Sep 10, 2023
3c730bd
cosmetic
ptahmose Sep 10, 2023
5cd2711
fix
ptahmose Sep 10, 2023
da3ce5b
cosmetic
ptahmose Sep 10, 2023
b4e7c16
starting cleanup and finalization
ptahmose Sep 22, 2023
be8a81a
update
ptahmose Sep 22, 2023
40e6404
fix
ptahmose Sep 22, 2023
019d419
rename JxrDecode2 -> JxrDecode
ptahmose Sep 22, 2023
4aadb01
forward C/C++-Compiler to external project
ptahmose Sep 22, 2023
adaa668
Merge branch 'main' into jbl/cleanup_jxrlib
ptahmose Sep 22, 2023
823be68
fix include
ptahmose Sep 22, 2023
f17a62e
fix inline problem (seen on MacOS)
ptahmose Sep 23, 2023
2c53cc0
cosmetic & OSS-license-header
ptahmose Sep 23, 2023
c43b288
cosmetic
ptahmose Sep 23, 2023
8b34c53
cosmetic
ptahmose Sep 23, 2023
a3daeca
typo
ptahmose Sep 23, 2023
ea8fc5f
bump version
ptahmose Sep 23, 2023
44bf0b8
cleanup
ptahmose Sep 23, 2023
acacb2b
documentation
ptahmose Sep 24, 2023
d1424ed
linter
ptahmose Sep 24, 2023
ae0a479
fix CodeQL-issue
ptahmose Sep 24, 2023
2effa77
cosmetic / lint
ptahmose Sep 24, 2023
59663ba
cosmetc - rename
ptahmose Sep 24, 2023
ed9f871
fix valgrind-reported issue
ptahmose Sep 25, 2023
50b7cf9
test
ptahmose Sep 26, 2023
db7b38c
fix memory leak (reported by valgrind) in case of decoder-object cons…
ptahmose Sep 26, 2023
0e8aae9
cosmetic
ptahmose Sep 27, 2023
75d6792
test
ptahmose Sep 27, 2023
efd7f35
Merge branch 'main' into jbl/cleanup_jxrlib
ptahmose Oct 16, 2023
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
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: 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
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
Loading