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

code cosmetic #6

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required (VERSION 3.11)

set(MEXCZI_MAJOR 0)
set(MEXCZI_MINOR 2)
set(MEXCZI_PATCH 0)
set(MEXCZI_PATCH 1)
set(MEXCZI_EXT "alpha")

if(WIN32)
Expand Down
1 change: 1 addition & 0 deletions MEXlibCZI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(mexoctaveSourceFiles
"src/func_addsubblock.cpp"
"src/func_closecziwriter.h"
"src/func_closecziwriter.cpp"
"src/include_rapidjson.h"
)

add_library (MEXlibCZI SHARED
Expand Down
980 changes: 489 additions & 491 deletions MEXlibCZI/src/CziReader.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MEXlibCZI/src/CziUtilities.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "CziUtilities.h"
#include <rapidjson/document.h>
#include "include_rapidjson.h"
#include "utils.h"

using namespace libCZI;
Expand Down
4 changes: 3 additions & 1 deletion MEXlibCZI/src/CziUtilities.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include "inc_libczi.h"
#include <bitset>
#include <tuple>

#include <rapidjson/document.h>
#include "include_rapidjson.h"

struct ChannelDisplaySettingsValidity
{
Expand Down
6 changes: 3 additions & 3 deletions MEXlibCZI/src/CziWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void CziWriter::AddSubBlockUncompressed(
if (!subblock_metadata_xml.empty())
{
add_sub_block_info_strided_bitmap.ptrSbBlkMetadata = subblock_metadata_xml.c_str();
add_sub_block_info_strided_bitmap.sbBlkMetadataSize = subblock_metadata_xml.size();
add_sub_block_info_strided_bitmap.sbBlkMetadataSize = static_cast<std::uint32_t>(subblock_metadata_xml.size());
}

libCZI::ScopedBitmapLockerSP bitmap_locker(bitmap_data);
Expand Down Expand Up @@ -139,12 +139,12 @@ void CziWriter::AddSubBlockCompressed(
addInfo.physicalHeight = add_sub_block_info_base.physicalHeight;
addInfo.PixelType = add_sub_block_info_base.PixelType;
addInfo.ptrData = compressed_data->GetPtr();
addInfo.dataSize = compressed_data->GetSizeOfData();
addInfo.dataSize = static_cast<uint32_t>(compressed_data->GetSizeOfData());

if (!subblock_metadata_xml.empty())
{
addInfo.ptrSbBlkMetadata = subblock_metadata_xml.c_str();
addInfo.sbBlkMetadataSize = subblock_metadata_xml.size();
addInfo.sbBlkMetadataSize = static_cast<uint32_t>(subblock_metadata_xml.size());
}

addInfo.SetCompressionMode(compression_mode);
Expand Down
4 changes: 2 additions & 2 deletions MEXlibCZI/src/argsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ using namespace libCZI;
{
planeCoordinate = CDimCoordinate::Parse(argStr.c_str());
}
catch (libCZI::LibCZIStringParseException& libExcp)
catch (libCZI::LibCZIStringParseException&)
{
return false;
}
catch (exception& excp)
catch (exception&)
{
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions MEXlibCZI/src/func_addsubblock.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "func_open.h"
#include "libraryInfo.h"
#include "CziWriterManager.h"
#include <vector>
#include <limits>
#include <memory>
#include <optional>

Expand Down Expand Up @@ -131,6 +131,11 @@ void MexFunction_AddSubBlock_Execute(MatlabArgs* args)
}
}

if (array_info.dimensions[1] > (numeric_limits<int>::max)() || array_info.dimensions[0] > (numeric_limits<int>::max)())
{
throw invalid_argument("Array dimensions are too large");
}

std::shared_ptr<CziWriter> writer = ::Utils::GetWriterOrThrow(id);
libCZI::AddSubBlockInfoBase add_sub_block_info_base;
add_sub_block_info_base.Clear();
Expand All @@ -139,8 +144,8 @@ void MexFunction_AddSubBlock_Execute(MatlabArgs* args)
add_sub_block_info_base.y = rect.y;
add_sub_block_info_base.logicalWidth = rect.w;
add_sub_block_info_base.logicalHeight = rect.h;
add_sub_block_info_base.physicalWidth = array_info.dimensions[1];
add_sub_block_info_base.physicalHeight = array_info.dimensions[0];
add_sub_block_info_base.physicalWidth = static_cast<int>(array_info.dimensions[1]);
add_sub_block_info_base.physicalHeight = static_cast<int>(array_info.dimensions[0]);
add_sub_block_info_base.PixelType = pixel_type;
add_sub_block_info_base.mIndex = m_index.value_or(0);
add_sub_block_info_base.mIndexValid = m_index.has_value();
Expand Down
5 changes: 3 additions & 2 deletions MEXlibCZI/src/func_getsubblockbitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ void MexFunction_GetSubBlockBitmap_Execute(MatlabArgs* args)
auto* out = reader->GetSubBlockImage(blkNo);
args->plhs[0] = out;
}
catch (exception& excp)
catch (exception& exception)
{
VDBGPRINT((CDbg::Level::Warn, "MexFunction_GetSubBlockBitmap_Execute: GetSubBlockImage failed -> %s.", excp.what()));
(void)exception; // suppress "unreferenced local variable" warning
VDBGPRINT((CDbg::Level::Warn, "MexFunction_GetSubBlockBitmap_Execute: GetSubBlockImage failed -> %s.", exception.what()));
throw;
}
}
5 changes: 3 additions & 2 deletions MEXlibCZI/src/func_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ void MexFunction_Open_Execute(MatlabArgs* args)
VDBGPRINT((CDbg::Level::Trace, "MexFunction_Open_Execute: attempt to open file \"%s\".", filename.get()));
reader->Open(filename.get());
}
catch (exception& excp)
catch (exception& exception)
{
VDBGPRINT((CDbg::Level::Warn, "MexFunction_Open_Execute: Open failed -> %s.", excp.what()));
(void)exception; // suppress "unreferenced local variable" warning
VDBGPRINT((CDbg::Level::Warn, "MexFunction_Open_Execute: Open failed -> %s.", exception.what()));
CziReaderManager::GetInstance().RemoveInstance(id);
throw;
}
Expand Down
6 changes: 6 additions & 0 deletions MEXlibCZI/src/include_rapidjson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define RAPIDJSON_HAS_STDSTRING 1

#include "rapidjson/rapidjson.h"
#include "rapidjson/document.h"
30 changes: 29 additions & 1 deletion MEXlibCZI/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "utils.h"
#include <codecvt>
#include <locale>
#include <limits>
#include <cstdarg>
#include "CziReaderManager.h"
#include "CziWriterManager.h"
#include "mexapi.h"
#include "dbgprint.h"
#if _WIN32
#include <Windows.h>
#endif

using namespace std;

Expand Down Expand Up @@ -58,9 +62,28 @@ using namespace std;

/*static*/std::wstring Utils::convertUtf8ToWchar_t(const char* sz)
{
#if _WIN32
// Get the size of the wide char string we need.
int len = MultiByteToWideChar(CP_UTF8, 0, sz, -1, nullptr, 0);
if (len == 0)
{
return L"";
}

// Create a wstring to hold the result.
std::wstring conv(len, 0);

// Perform the actual conversion.
MultiByteToWideChar(CP_UTF8, 0, sz, -1, conv.data(), len);

// Remove the extra null terminator added by MultiByteToWideChar
conv.resize(len - 1);
return conv;
#else
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8conv;
std::wstring conv = utf8conv.from_bytes(sz);
return conv;
#endif
}

/*static*/std::shared_ptr<CziReader> Utils::GetReaderOrThrow(int id)
Expand Down Expand Up @@ -191,6 +214,11 @@ class Converters
throw invalid_argument("array must be at most 3-dimensional");
}

if (array_info.dimensions[1] > (numeric_limits<uint32_t>::max)() || array_info.dimensions[0] > (numeric_limits<uint32_t>::max)())
{
throw invalid_argument("array dimensions are too large");
}

static constexpr struct ConversionInfo
{
mxClassID mx_class;
Expand All @@ -210,7 +238,7 @@ class Converters
{
if (conversionInfo.mx_class == array_info.class_id && conversionInfo.has_3rd_dimension == has_3rd_dimension)
{
auto bitmapData = make_shared<Bitmap>(pixel_type, array_info.dimensions[1], array_info.dimensions[0]);
auto bitmapData = make_shared<Bitmap>(pixel_type, static_cast<std::uint32_t>(array_info.dimensions[1]), static_cast<std::uint32_t>(array_info.dimensions[0]));
conversionInfo.conversion_function(array_info, bitmapData.get());
return bitmapData;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/rapidJSON.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ExternalProject_Add(
rapidjson
PREFIX "vendor/rapidjson"
GIT_REPOSITORY "https://github.com/Tencent/rapidjson.git"
GIT_TAG f54b0e47a08782a6131cc3d60f94d038fa6e0a51
GIT_TAG 815e6e7e7e14be44a6c15d9aefed232ff064cad0
TIMEOUT 10
CMAKE_ARGS
-DRAPIDJSON_BUILD_TESTS=OFF
Expand Down
Loading