Skip to content

Commit

Permalink
*** v2.9.0 ***
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubangoTelecom committed Sep 30, 2021
1 parent 3e5815d commit 68c998b
Show file tree
Hide file tree
Showing 30 changed files with 182 additions and 38 deletions.
Binary file modified binaries/android/jniLibs/arm64-v8a/libultimateMRZ_SDK.so
Binary file not shown.
Binary file modified binaries/android/jniLibs/armeabi-v7a/libultimateMRZ_SDK.so
Binary file not shown.
Binary file modified binaries/android/jniLibs/x86/libultimateMRZ_SDK.so
Binary file not shown.
Binary file modified binaries/android/jniLibs/x86_64/libultimateMRZ_SDK.so
Binary file not shown.
Binary file modified binaries/linux/x86_64/benchmark
Binary file not shown.
Binary file modified binaries/linux/x86_64/libultimate_mrz-sdk.so
Binary file not shown.
Binary file modified binaries/linux/x86_64/recognizer
Binary file not shown.
Binary file modified binaries/linux/x86_64/runtimeKey
Binary file not shown.
Binary file modified binaries/raspbian/armv7l/benchmark
Binary file not shown.
Binary file modified binaries/raspbian/armv7l/libultimate_mrz-sdk.so
Binary file not shown.
Binary file modified binaries/raspbian/armv7l/recognizer
Binary file not shown.
Binary file modified binaries/raspbian/armv7l/runtimeKey
Binary file not shown.
Binary file modified binaries/windows/x86_64/benchmark.exe
Binary file not shown.
Binary file modified binaries/windows/x86_64/recognizer.exe
Binary file not shown.
Binary file modified binaries/windows/x86_64/runtimeKey.exe
Binary file not shown.
Binary file modified binaries/windows/x86_64/ultimateMRZ-SDK.dll
Binary file not shown.
Binary file modified binaries/windows/x86_64/ultimateMRZ-SDK.lib
Binary file not shown.
27 changes: 19 additions & 8 deletions c++/ultimateMRZ-SDK-API-PUBLIC.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ultimateMRZ-SDK public header
#include <string>

#define ULTMRZ_SDK_VERSION_MAJOR 2
#define ULTMRZ_SDK_VERSION_MINOR 8
#define ULTMRZ_SDK_VERSION_MICRO 1
#define ULTMRZ_SDK_VERSION_MINOR 9
#define ULTMRZ_SDK_VERSION_MICRO 0

// Windows's symbols export
#if defined(SWIG)
Expand Down Expand Up @@ -223,6 +223,7 @@ namespace ultimateMrzSdk
\param imageHeightInSamples Image height in samples.
\param imageStrideInSamples Image stride in samples. Should be zero unless your the data is strided.
\param imageExifOrientation Image EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html
\returns a \ref UltMrzSdkResult "result"
*/
static UltMrzSdkResult process(
const ULTMRZ_SDK_IMAGE_TYPE imageType,
Expand All @@ -245,6 +246,7 @@ namespace ultimateMrzSdk
\param vStrideInBytes Stride in bytes for the V (chroma) samples.
\param uvPixelStrideInBytes Pixel stride in bytes for the UV (chroma) samples. Should be 1 for planar and 2 for semi-planar formats. Set to 0 for auto-detect.
\param exifOrientation Image EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html
\returns a \ref UltMrzSdkResult "result"
*/
static UltMrzSdkResult process(
const ULTMRZ_SDK_IMAGE_TYPE imageType,
Expand All @@ -260,13 +262,22 @@ namespace ultimateMrzSdk
const int exifOrientation = 1
);

/*! Retrieve EXIF orientation value from JPEG meta-data.
\param jpegMetaDataPtr Pointer to the meta-data.
\param jpegMetaDataSize Size of the meta-data.
\returns Image's EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html.
Available since: 2.9.0
*/
static int exifOrientation(const void* jpegMetaDataPtr, const size_t jpegMetaDataSize);

/*! Build a unique runtime license key associated to this device.
You must \ref init "initialize" the engine before calling this function.
This function doesn't require internet connection.
The runtime key must be activated to obtain a token. The activation procedure is explained at https://www.doubango.org/SDKs/LicenseManager/docs/Activation_use_cases.html.
\param rawInsteadOfJSON Whether to output the runtime key as raw string intead of JSON entry. Requesting raw
string instead of JSON could be helpful for applications without JSON parser to extract the key.
\returns a \ref UltAlprSdkResult "result"
You must \ref init "initialize" the engine before calling this function.
This function doesn't require internet connection.
The runtime key must be activated to obtain a token. The activation procedure is explained at https://www.doubango.org/SDKs/LicenseManager/docs/Activation_use_cases.html.
\param rawInsteadOfJSON Whether to output the runtime key as raw string intead of JSON entry. Requesting raw
string instead of JSON could be helpful for applications without JSON parser to extract the key.
\returns a \ref UltAlprSdkResult "result"
*/
static UltMrzSdkResult requestRuntimeLicenseKey(const bool& rawInsteadOfJSON = false);

Expand Down
5 changes: 5 additions & 0 deletions csharp/UltMrzSdkEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, IntPtr yP
return ret;
}

public static int exifOrientation(IntPtr jpegMetaDataPtr, uint jpegMetaDataSize) {
int ret = ultimateMrzSdkPINVOKE.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
return ret;
}

public static UltMrzSdkResult requestRuntimeLicenseKey(bool rawInsteadOfJSON) {
UltMrzSdkResult ret = new UltMrzSdkResult(ultimateMrzSdkPINVOKE.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
return ret;
Expand Down
3 changes: 3 additions & 0 deletions csharp/ultimateMrzSdkPINVOKE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ static ultimateMrzSdkPINVOKE() {
[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_process__SWIG_5")]
public static extern IntPtr UltMrzSdkEngine_process__SWIG_5(int jarg1, IntPtr jarg2, IntPtr jarg3, IntPtr jarg4, uint jarg5, uint jarg6, uint jarg7, uint jarg8, uint jarg9);

[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_exifOrientation")]
public static extern int UltMrzSdkEngine_exifOrientation(IntPtr jarg1, uint jarg2);

[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0")]
public static extern IntPtr UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(bool jarg1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, java.nio.
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_process__SWIG_5(imageType.swigValue(), yPtr, uPtr, vPtr, widthInSamples, heightInSamples, yStrideInBytes, uStrideInBytes, vStrideInBytes), true);
}

public static int exifOrientation(java.nio.ByteBuffer jpegMetaDataPtr, long jpegMetaDataSize) {
return ultimateMrzSdkJNI.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
}

public static UltMrzSdkResult requestRuntimeLicenseKey(boolean rawInsteadOfJSON) {
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

public interface ultimateMrzSdkConstants {
public final static int ULTMRZ_SDK_VERSION_MAJOR = 2;
public final static int ULTMRZ_SDK_VERSION_MINOR = 3;
public final static int ULTMRZ_SDK_VERSION_MICRO = 4;
public final static int ULTMRZ_SDK_VERSION_MINOR = 9;
public final static int ULTMRZ_SDK_VERSION_MICRO = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ultimateMrzSdkJNI {
public final static native long UltMrzSdkEngine_process__SWIG_3(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9, long jarg10, int jarg11);
public final static native long UltMrzSdkEngine_process__SWIG_4(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9, long jarg10);
public final static native long UltMrzSdkEngine_process__SWIG_5(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9);
public final static native int UltMrzSdkEngine_exifOrientation(java.nio.ByteBuffer jarg1, long jarg2);
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(boolean jarg1);
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_1();
public final static native void delete_UltMrzSdkEngine(long jarg1);
Expand Down
4 changes: 4 additions & 0 deletions java/org/doubango/ultimateMrz/Sdk/UltMrzSdkEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, java.nio.
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_process__SWIG_5(imageType.swigValue(), yPtr, uPtr, vPtr, widthInSamples, heightInSamples, yStrideInBytes, uStrideInBytes, vStrideInBytes), true);
}

public static int exifOrientation(java.nio.ByteBuffer jpegMetaDataPtr, long jpegMetaDataSize) {
return ultimateMrzSdkJNI.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
}

public static UltMrzSdkResult requestRuntimeLicenseKey(boolean rawInsteadOfJSON) {
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

public interface ultimateMrzSdkConstants {
public final static int ULTMRZ_SDK_VERSION_MAJOR = 2;
public final static int ULTMRZ_SDK_VERSION_MINOR = 3;
public final static int ULTMRZ_SDK_VERSION_MICRO = 4;
public final static int ULTMRZ_SDK_VERSION_MINOR = 9;
public final static int ULTMRZ_SDK_VERSION_MICRO = 0;
}
1 change: 1 addition & 0 deletions java/org/doubango/ultimateMrz/Sdk/ultimateMrzSdkJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ultimateMrzSdkJNI {
public final static native long UltMrzSdkEngine_process__SWIG_3(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9, long jarg10, int jarg11);
public final static native long UltMrzSdkEngine_process__SWIG_4(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9, long jarg10);
public final static native long UltMrzSdkEngine_process__SWIG_5(int jarg1, java.nio.ByteBuffer jarg2, java.nio.ByteBuffer jarg3, java.nio.ByteBuffer jarg4, long jarg5, long jarg6, long jarg7, long jarg8, long jarg9);
public final static native int UltMrzSdkEngine_exifOrientation(java.nio.ByteBuffer jarg1, long jarg2);
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(boolean jarg1);
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_1();
public final static native void delete_UltMrzSdkEngine(long jarg1);
Expand Down
41 changes: 40 additions & 1 deletion python/ultimateMRZ-SDK-API-PUBLIC-SWIG_python.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4728,6 +4728,44 @@ SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_process(PyObject *self, PyObject *arg
}


SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_exifOrientation(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
void *arg1 = (void *) 0 ;
size_t arg2 ;
size_t val2 ;
int ecode2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"OO:UltMrzSdkEngine_exifOrientation",&obj0,&obj1)) SWIG_fail;
{
// https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
// char* PyBytes_AsString(PyObject *o)
// Return a pointer to the contents of o. The pointer refers to the internal buffer of o, which consists of len(o) + 1 bytes.
// The last byte in the buffer is always null, regardless of whether there are any other null bytes.
// The data must not be modified in any way, unless the object was just created using PyBytes_FromStringAndSize(NULL, size).
// It must not be deallocated. If o is not a bytes object at all, PyBytes_AsString() returns NULL and raises TypeError.
if (PyBytes_Check(obj0)) {
arg1 = (void *) PyBytes_AsString(obj0);
}
else if (PyString_Check(obj0)) {
arg1 = (void *) PyString_AsString(obj0);
}
}
ecode2 = SWIG_AsVal_size_t(obj1, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "UltMrzSdkEngine_exifOrientation" "', argument " "2"" of type '" "size_t""'");
}
arg2 = static_cast< size_t >(val2);
result = (int)ultimateMrzSdk::UltMrzSdkEngine::exifOrientation((void const *)arg1,arg2);
resultobj = SWIG_From_int(static_cast< int >(result));
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
bool *arg1 = 0 ;
Expand Down Expand Up @@ -4839,6 +4877,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"UltMrzSdkEngine_init", _wrap_UltMrzSdkEngine_init, METH_VARARGS, NULL},
{ (char *)"UltMrzSdkEngine_deInit", _wrap_UltMrzSdkEngine_deInit, METH_VARARGS, NULL},
{ (char *)"UltMrzSdkEngine_process", _wrap_UltMrzSdkEngine_process, METH_VARARGS, NULL},
{ (char *)"UltMrzSdkEngine_exifOrientation", _wrap_UltMrzSdkEngine_exifOrientation, METH_VARARGS, NULL},
{ (char *)"UltMrzSdkEngine_requestRuntimeLicenseKey", _wrap_UltMrzSdkEngine_requestRuntimeLicenseKey, METH_VARARGS, NULL},
{ (char *)"delete_UltMrzSdkEngine", _wrap_delete_UltMrzSdkEngine, METH_VARARGS, NULL},
{ (char *)"UltMrzSdkEngine_swigregister", UltMrzSdkEngine_swigregister, METH_VARARGS, NULL},
Expand Down Expand Up @@ -5583,7 +5622,7 @@ SWIG_init(void) {
SWIG_InstallConstants(d,swig_const_table);

SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MAJOR",SWIG_From_int(static_cast< int >(2)));
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MINOR",SWIG_From_int(static_cast< int >(4)));
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MINOR",SWIG_From_int(static_cast< int >(9)));
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MICRO",SWIG_From_int(static_cast< int >(0)));
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_IMAGE_TYPE_RGB24",SWIG_From_int(static_cast< int >(ultimateMrzSdk::ULTMRZ_SDK_IMAGE_TYPE_RGB24)));
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_IMAGE_TYPE_RGBA32",SWIG_From_int(static_cast< int >(ultimateMrzSdk::ULTMRZ_SDK_IMAGE_TYPE_RGBA32)));
Expand Down
6 changes: 6 additions & 0 deletions python/ultimateMrzSdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def __init__(self, *args, **kwargs): raise AttributeError("No constructor define
if _newclass:deInit = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_deInit)
__swig_getmethods__["process"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_process
if _newclass:process = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_process)
__swig_getmethods__["exifOrientation"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation
if _newclass:exifOrientation = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_exifOrientation)
__swig_getmethods__["requestRuntimeLicenseKey"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey
if _newclass:requestRuntimeLicenseKey = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey)
__swig_destroy__ = _ultimateMrzSdk.delete_UltMrzSdkEngine
Expand All @@ -133,6 +135,10 @@ def UltMrzSdkEngine_process(*args):
return _ultimateMrzSdk.UltMrzSdkEngine_process(*args)
UltMrzSdkEngine_process = _ultimateMrzSdk.UltMrzSdkEngine_process

def UltMrzSdkEngine_exifOrientation(*args):
return _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation(*args)
UltMrzSdkEngine_exifOrientation = _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation

def UltMrzSdkEngine_requestRuntimeLicenseKey(rawInsteadOfJSON=False):
return _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey(rawInsteadOfJSON)
UltMrzSdkEngine_requestRuntimeLicenseKey = _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey
Expand Down
83 changes: 64 additions & 19 deletions samples/c++/recognizer/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@

using namespace ultimateMrzSdk;

struct MrzFile {
int width = 0, height = 0, channels = 0;
stbi_uc* uncompressedDataPtr = nullptr;
void* compressedDataPtr = nullptr;
size_t compressedDataSize = 0;
FILE* filePtr = nullptr;
virtual ~MrzFile() {
if (uncompressedDataPtr) free(uncompressedDataPtr), uncompressedDataPtr = nullptr;
if (compressedDataPtr) free(compressedDataPtr), compressedDataPtr = nullptr;
if (filePtr) fclose(filePtr), filePtr = nullptr;
}
bool isValid() const {
return width > 0 && height > 0 && (channels == 1 || channels == 3 || channels == 4) && uncompressedDataPtr && compressedDataPtr && compressedDataSize > 0;
}
};

static void printUsage(const std::string& message = "");
static bool parseArgs(int argc, char *argv[], std::map<std::string, std::string >& values);
static bool readFile(const std::string& path, MrzFile& file);

// Configuration for MRZ deep learning engine
// More info about JSON configuration entries: https://www.doubango.org/SDKs/mrz/docs/Configuration_options.html
Expand Down Expand Up @@ -141,19 +158,12 @@ int main(int argc, char *argv[])
jsonConfig += "}"; // end-of-config

// Decode the file
FILE* file = nullptr;
if (!file && (file = fopen(pathFileImage.c_str(), "rb")) == nullptr) {
ULTMRZ_SDK_PRINT_ERROR("Can't open %s", pathFileImage.c_str());
return -1;
}

int width, height, channels;
stbi_uc* uncompressedData = stbi_load_from_file(file, &width, &height, &channels, 0);
fclose(file);
if (!uncompressedData || !width || !height || (channels != 1 && channels != 3 && channels != 4)) {
ULTMRZ_SDK_PRINT_ERROR("Invalid file(%s, %d, %d, %d)", pathFileImage.c_str(), width, height, channels);
MrzFile file;
if (!readFile(pathFileImage, file)) {
ULTMRZ_SDK_PRINT_ERROR("Can't process %s", pathFileImage.c_str());
return -1;
}
ULTMRZ_SDK_ASSERT(file.isValid());

// Init
ULTMRZ_SDK_PRINT_INFO("Initialization...");
Expand All @@ -166,10 +176,12 @@ int main(int argc, char *argv[])
// and initialized which means it will be slow. In your application you've to initialize the engine
// once and do all the recognitions you need then, deinitialize it.
ULTMRZ_SDK_ASSERT((result = UltMrzSdkEngine::process(
channels == 4 ? ULTMRZ_SDK_IMAGE_TYPE_RGBA32 : (channels == 1 ? ULTMRZ_SDK_IMAGE_TYPE_Y : ULTMRZ_SDK_IMAGE_TYPE_RGB24),
uncompressedData,
static_cast<size_t>(width),
static_cast<size_t>(height)
file.channels == 4 ? ULTMRZ_SDK_IMAGE_TYPE_RGBA32 : (file.channels == 1 ? ULTMRZ_SDK_IMAGE_TYPE_Y : ULTMRZ_SDK_IMAGE_TYPE_RGB24),
file.uncompressedDataPtr,
static_cast<size_t>(file.width),
static_cast<size_t>(file.height),
0, // stride
UltMrzSdkEngine::exifOrientation(file.compressedDataPtr, file.compressedDataSize)
)).isOK());

// Print result
Expand All @@ -184,9 +196,6 @@ int main(int argc, char *argv[])
ULTMRZ_SDK_PRINT_INFO("result: %s", json_.c_str());
}

// free memory
stbi_image_free(uncompressedData);

// Press any key to terminate
ULTMRZ_SDK_PRINT_INFO("Press any key to terminate !!");
getchar();
Expand Down Expand Up @@ -253,4 +262,40 @@ static bool parseArgs(int argc, char *argv[], std::map<std::string, std::string
}

return true;
}
}

static bool readFile(const std::string& path, MrzFile& file)
{
// Open the file
if ((file.filePtr = fopen(path.c_str(), "rb")) == nullptr) {
ULTMRZ_SDK_PRINT_ERROR("Can't open %s", path.c_str());
return false;
}

// Retrieve file size
struct stat st_;
if (stat(path.c_str(), &st_) != 0) {
ULTMRZ_SDK_PRINT_ERROR("File is empty %s", path.c_str());
}
file.compressedDataSize = static_cast<size_t>(st_.st_size);

// Alloc memory and read data
file.compressedDataPtr = ::malloc(file.compressedDataSize);
if (!file.compressedDataPtr) {
ULTMRZ_SDK_PRINT_ERROR("Failed to alloc mem with size = %zu", file.compressedDataSize);
return false;
}
size_t read_;
if (file.compressedDataSize != (read_ = fread(file.compressedDataPtr, 1, file.compressedDataSize, file.filePtr))) {
ULTMRZ_SDK_PRINT_ERROR("fread(%s) returned %zu instead of %zu", path.c_str(), read_, file.compressedDataSize);
return false;
}

// Decode image
file.uncompressedDataPtr = stbi_load_from_memory(
reinterpret_cast<stbi_uc const *>(file.compressedDataPtr), static_cast<int>(file.compressedDataSize),
&file.width, &file.height, &file.channels, 0
);

return file.isValid();
}
Loading

0 comments on commit 68c998b

Please sign in to comment.