Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ptahmose committed Oct 6, 2024
1 parent 1a43510 commit 5ce7657
Show file tree
Hide file tree
Showing 21 changed files with 3,108 additions and 4 deletions.
53 changes: 53 additions & 0 deletions AppModel/include/app_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,49 @@ extern "C" {

typedef void* Parameter;

enum AppExtensionClassId
{
AppExtensionClassId_Unknown,
AppExtensionClassId_Uint8,
AppExtensionClassId_Int8,
AppExtensionClassId_Uint16,
AppExtensionClassId_Int16,
AppExtensionClassId_Uint32,
AppExtensionClassId_Int32,
AppExtensionClassId_Uint64,
AppExtensionClassId_Int64,
AppExtensionClassId_Double,
AppExtensionClassId_Single,
};

struct IAppExtensionFunctions
{
bool (*pfn_IsNanOrInfDouble)(double d);

bool (*pfn_IsNanOrInfSingle)(float f);

void* (*pfn_GetData)(const Parameter* parameter);

uint8_t* (*pfn_GetUint8s)(const Parameter* parameter);

int8_t* (*pfn_GetInt8s)(const Parameter* parameter);

uint16_t* (*pfn_GetUint16s)(const Parameter* parameter);

int16_t* (*pfn_GetInt16s)(const Parameter* parameter);

uint32_t* (*pfn_GetUint32s)(const Parameter* parameter);

int32_t* (*pfn_GetInt32s)(const Parameter* parameter);

uint64_t* (*pfn_GetUint64s)(const Parameter* parameter);

int64_t* (*pfn_GetInt64s)(const Parameter* parameter);

double* (*pfn_GetDoubles)(const Parameter* parameter);

float* (*pfn_GetSingles)(const Parameter* parameter);

bool (*pfn_IsNumeric)(const Parameter* parameter);

bool (*pfn_IsChar)(const Parameter* parameter);
Expand All @@ -34,6 +73,20 @@ struct IAppExtensionFunctions
char* (*pfn_ConvertToUTF8String)(const Parameter* parameter);

void (*pfn_Free)(void* ptr);

Parameter* (*pfn_CreateNumericMatrixReal)(size_t m, size_t n, enum AppExtensionClassId class_id);

enum AppExtensionClassId (*pfn_GetClassId)(const Parameter* parameter);

size_t (*pfn_GetNumberOfElements)(const Parameter* parameter);

size_t(*pfn_GetNumberOfDimensions)(const Parameter* parameter);

void (*pfn_GetSizeOfDimensions)(const Parameter* parameter, size_t number_of_dimension, size_t* sizes);

Parameter* (*pfn_GetField)(const Parameter* parameter, const char* field_name);

Parameter* (*pfn_CreateNumericArrayReal)(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id); //*
};

#ifdef __cplusplus
Expand Down
226 changes: 225 additions & 1 deletion MatlabMex/app_api_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,71 @@
#include <mex.h>
#include <string.h>

bool matlabMexIsNanOrInfDouble(double value)
{
return mxIsNaN(value) || mxIsInf(value);
}

bool matlabMexIsNanOrInfSingle(float value)
{
return mxIsNaN(value) || mxIsInf(value);
}

void* matlabMexGetData(const Parameter* parameter)
{
return mxGetData((const mxArray*)parameter);
}

uint8_t* matlabMexGetUint8s(const Parameter* parameter)
{
return mxGetUint8s((const mxArray*)parameter);
}

int8_t* matlabMexGetInt8s(const Parameter* parameter)
{
return mxGetInt8s((const mxArray*)parameter);
}

uint16_t* matlabMexGetUint16s(const Parameter* parameter)
{
return mxGetUint16s((const mxArray*)parameter);
}

int16_t* matlabMexGetInt16s(const Parameter* parameter)
{
return mxGetInt16s((const mxArray*)parameter);
}

uint32_t* matlabMexGetUint32s(const Parameter* parameter)
{
return mxGetUint32s((const mxArray*)parameter);
}

int32_t* matlabMexGetInt32s(const Parameter* parameter)
{
return mxGetInt32s((const mxArray*)parameter);
}

uint64_t* matlabMexGetUint64s(const Parameter* parameter)
{
return mxGetUint64s((const mxArray*)parameter);
}

int64_t* matlabMexGetInt64s(const Parameter* parameter)
{
return mxGetInt64s((const mxArray*)parameter);
}

double* matlabMexGetDoubles(const Parameter* parameter)
{
return mxGetDoubles((const mxArray*)parameter);
}

float* matlabMexGetSingles(const Parameter* parameter)
{
return mxGetSingles((const mxArray*)parameter);
}

bool matlabMexIsNumeric(const Parameter* parameter)
{
return mxIsNumeric((const mxArray*)parameter);
Expand Down Expand Up @@ -66,9 +126,166 @@ void matlabFree(void* ptr)
mxFree(ptr);
}

Parameter* matlabCreateNumericMatrixReal(size_t m, size_t n, enum AppExtensionClassId class_id)
{
mxClassID mx_class_id;
switch (class_id)
{
case AppExtensionClassId_Uint8:
mx_class_id = mxUINT8_CLASS;
break;
case AppExtensionClassId_Int8:
mx_class_id = mxINT8_CLASS;
break;
case AppExtensionClassId_Uint16:
mx_class_id = mxUINT16_CLASS;
break;
case AppExtensionClassId_Int16:
mx_class_id = mxINT16_CLASS;
break;
case AppExtensionClassId_Uint32:
mx_class_id = mxUINT32_CLASS;
break;
case AppExtensionClassId_Int32:
mx_class_id = mxINT32_CLASS;
break;
case AppExtensionClassId_Uint64:
mx_class_id = mxUINT64_CLASS;
break;
case AppExtensionClassId_Int64:
mx_class_id = mxINT64_CLASS;
break;
case AppExtensionClassId_Double:
mx_class_id = mxDOUBLE_CLASS;
break;
case AppExtensionClassId_Single:
mx_class_id = mxSINGLE_CLASS;
break;
default:
mx_class_id = mxUNKNOWN_CLASS;
break;
}

return (Parameter*)mxCreateNumericMatrix(m, n, mx_class_id, mxREAL);
}

enum AppExtensionClassId matlabGetClassId(const Parameter* parameter)
{
mxClassID mx_class_id = mxGetClassID((const mxArray*)parameter);
switch (mx_class_id)
{
case mxUINT8_CLASS:
return AppExtensionClassId_Uint8;
case mxINT8_CLASS:
return AppExtensionClassId_Int8;
case mxUINT16_CLASS:
return AppExtensionClassId_Uint16;
case mxINT16_CLASS:
return AppExtensionClassId_Int16;
case mxUINT32_CLASS:
return AppExtensionClassId_Uint32;
case mxINT32_CLASS:
return AppExtensionClassId_Int32;
case mxUINT64_CLASS:
return AppExtensionClassId_Uint64;
case mxINT64_CLASS:
return AppExtensionClassId_Int64;
case mxDOUBLE_CLASS:
return AppExtensionClassId_Double;
case mxSINGLE_CLASS:
return AppExtensionClassId_Single;
default:
return AppExtensionClassId_Unknown;
}
}

size_t matlabGetNumberOfElements(const Parameter* parameter)
{
return mxGetNumberOfElements((const mxArray*)parameter);
}

size_t matlabGetNumberOfDimensions(const Parameter* parameter)
{
return mxGetNumberOfDimensions((const mxArray*)parameter);
}

void matlabGetSizeOfDimensions(const Parameter* parameter, size_t number_of_dimension, size_t* sizes)
{
const size_t* ptr_sizes = mxGetDimensions((const mxArray*)parameter);
for (size_t i = 0; i < number_of_dimension; ++i)
{
sizes[i] = ptr_sizes[i];
}
}

Parameter* matlabGetField(const Parameter* parameter, const char* field_name)
{
if (!matlabMexIsStruct(parameter))
{
return NULL;
}

return (Parameter*)mxGetField((const mxArray*)parameter, 0, field_name);
}

Parameter* matlabCreateNumericArrayReal(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id)
{
mxClassID mx_class_id;
switch (class_id)
{
case AppExtensionClassId_Uint8:
mx_class_id = mxUINT8_CLASS;
break;
case AppExtensionClassId_Int8:
mx_class_id = mxINT8_CLASS;
break;
case AppExtensionClassId_Uint16:
mx_class_id = mxUINT16_CLASS;
break;
case AppExtensionClassId_Int16:
mx_class_id = mxINT16_CLASS;
break;
case AppExtensionClassId_Uint32:
mx_class_id = mxUINT32_CLASS;
break;
case AppExtensionClassId_Int32:
mx_class_id = mxINT32_CLASS;
break;
case AppExtensionClassId_Uint64:
mx_class_id = mxUINT64_CLASS;
break;
case AppExtensionClassId_Int64:
mx_class_id = mxINT64_CLASS;
break;
case AppExtensionClassId_Double:
mx_class_id = mxDOUBLE_CLASS;
break;
case AppExtensionClassId_Single:
mx_class_id = mxSINGLE_CLASS;
break;
default:
mx_class_id = mxUNKNOWN_CLASS;
break;
}

return (Parameter*)mxCreateNumericArray(ndim, dims, mx_class_id, mxREAL);
}

struct IAppExtensionFunctions g_appExtensionFunctions =
{
.pfn_IsNanOrInfDouble = matlabMexIsNanOrInfDouble,
.pfn_IsNanOrInfSingle = matlabMexIsNanOrInfSingle,
.pfn_GetData = matlabMexGetData,
.pfn_GetUint8s = matlabMexGetUint8s,
.pfn_GetInt8s = matlabMexGetInt8s,
.pfn_GetUint16s = matlabMexGetUint16s,
.pfn_GetInt16s = matlabMexGetInt16s,
.pfn_GetUint32s = matlabMexGetUint32s,
.pfn_GetInt32s = matlabMexGetInt32s,
.pfn_GetUint64s = matlabMexGetUint64s,
.pfn_GetInt64s = matlabMexGetInt64s,
.pfn_GetDoubles = matlabMexGetDoubles,
.pfn_GetSingles = matlabMexGetSingles,
.pfn_IsNumeric = matlabMexIsNumeric,
.pfn_IsChar = matlabMexIsChar,
.pfn_IsSparse = matlabMexIsSparse,
Expand All @@ -79,5 +296,12 @@ struct IAppExtensionFunctions g_appExtensionFunctions =
.pfn_CreateStructArray = matlabCreateStructArray,
.pfn_SetFieldByNumber = matlabSetFieldByNumber,
.pfn_ConvertToUTF8String = matlabConvertToUTF8String,
.pfn_Free = matlabFree
.pfn_Free = matlabFree,
.pfn_CreateNumericMatrixReal = matlabCreateNumericMatrixReal,
.pfn_GetClassId = matlabGetClassId,
.pfn_GetNumberOfElements = matlabGetNumberOfElements,
.pfn_GetNumberOfDimensions = matlabGetNumberOfDimensions,
.pfn_GetSizeOfDimensions = matlabGetSizeOfDimensions,
.pfn_GetField = matlabGetField,
.pfn_CreateNumericArrayReal = matlabCreateNumericArrayReal
};
44 changes: 41 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,51 @@ set (libSourceFiles
"src/implementation/inc_libczi.h"
"src/implementation/libraryinfo.h"
"src/implementation/libraryinfo.cpp"
)
"src/implementation/CziReaderManager.h"
"src/implementation/CziReaderManager.cpp"
"src/implementation/CziReader.h"
"src/implementation/CziReader.cpp"
"src/implementation/dbgprint.h"
"src/implementation/dbgprint.cpp"
"src/implementation/CziReaderSbBlkStore.cpp"
"src/implementation/CziReaderSbBlkStore.h"
"src/implementation/CziUtilities.cpp"
"src/implementation/CziUtilities.h"
"src/implementation/include_rapidjson.h"
"src/implementation/argsutils.h"
"src/implementation/argsutils.cpp"
"src/implementation/CziWriter.cpp" "src/implementation/CziWriter.h")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(lib_ENABLE_LOGGING 1)
else()
set(lib_ENABLE_LOGGING 0)
endif()

set(lib_LOGLEVEL 1)


set(lib_VERSION_MAJOR ${MEXCZI_MAJOR})
set(lib_VERSION_MINOR ${MEXCZI_MINOR})
set(lib_VERSION_PATCH ${MEXCZI_PATCH})
set(lib_VERSION_EXT ${MEXCZI_EXT})

configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/lib_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/lib_config.h"
ESCAPE_QUOTES @ONLY)



add_library (lib
${libSourceFiles})

set_target_properties(lib PROPERTIES CXX_STANDARD 17)
target_include_directories(lib PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../AppModel/include")
target_include_directories(lib PRIVATE ${LIBCZI_INCLUDE_DIR})
target_link_libraries(lib PRIVATE libCZIStatic JxrDecodeStatic)
target_include_directories(lib PRIVATE ${LIBCZI_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIR})
target_link_libraries(lib PRIVATE libCZIStatic JxrDecodeStatic)
target_include_directories(lib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # this is necessary so that we can find "lib_config.h" which we created above

if(WIN32)
target_compile_definitions(lib PRIVATE _WIN32API=1)
endif()
13 changes: 13 additions & 0 deletions lib/lib_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#define LIB_ENABLELOGGING @lib_ENABLE_LOGGING@

#define LIB_LOGLEVEL @lib_LOGLEVEL@

#define LIB_VERSION_MAJOR @lib_VERSION_MAJOR@

#define LIB_VERSION_MINOR @lib_VERSION_MINOR@

#define LIB_VERSION_PATCH @lib_VERSION_PATCH@

#define LIB_VERSION_EXT "@lib_VERSION_EXT@"
Loading

0 comments on commit 5ce7657

Please sign in to comment.