Skip to content

Commit 68c998b

Browse files
*** v2.9.0 ***
Fix issue #62 -> Add C++ function to the API to retrieve EXIF orientation value. https://www.doubango.org/SDKs/mrz/docs/cpp-api.html#_CPPv4N14ultimateMrzSdk15UltMrzSdkEngine15exifOrientationEPKvK6size_t
1 parent 3e5815d commit 68c998b

30 files changed

+182
-38
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

binaries/linux/x86_64/benchmark

0 Bytes
Binary file not shown.
28 KB
Binary file not shown.

binaries/linux/x86_64/recognizer

4.47 KB
Binary file not shown.

binaries/linux/x86_64/runtimeKey

0 Bytes
Binary file not shown.

binaries/raspbian/armv7l/benchmark

0 Bytes
Binary file not shown.
Binary file not shown.

binaries/raspbian/armv7l/recognizer

304 Bytes
Binary file not shown.

binaries/raspbian/armv7l/runtimeKey

0 Bytes
Binary file not shown.

binaries/windows/x86_64/benchmark.exe

0 Bytes
Binary file not shown.
10 KB
Binary file not shown.
0 Bytes
Binary file not shown.
22 KB
Binary file not shown.
1.28 KB
Binary file not shown.

c++/ultimateMRZ-SDK-API-PUBLIC.h

+19-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ultimateMRZ-SDK public header
1414
#include <string>
1515

1616
#define ULTMRZ_SDK_VERSION_MAJOR 2
17-
#define ULTMRZ_SDK_VERSION_MINOR 8
18-
#define ULTMRZ_SDK_VERSION_MICRO 1
17+
#define ULTMRZ_SDK_VERSION_MINOR 9
18+
#define ULTMRZ_SDK_VERSION_MICRO 0
1919

2020
// Windows's symbols export
2121
#if defined(SWIG)
@@ -223,6 +223,7 @@ namespace ultimateMrzSdk
223223
\param imageHeightInSamples Image height in samples.
224224
\param imageStrideInSamples Image stride in samples. Should be zero unless your the data is strided.
225225
\param imageExifOrientation Image EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html
226+
\returns a \ref UltMrzSdkResult "result"
226227
*/
227228
static UltMrzSdkResult process(
228229
const ULTMRZ_SDK_IMAGE_TYPE imageType,
@@ -245,6 +246,7 @@ namespace ultimateMrzSdk
245246
\param vStrideInBytes Stride in bytes for the V (chroma) samples.
246247
\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.
247248
\param exifOrientation Image EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html
249+
\returns a \ref UltMrzSdkResult "result"
248250
*/
249251
static UltMrzSdkResult process(
250252
const ULTMRZ_SDK_IMAGE_TYPE imageType,
@@ -260,13 +262,22 @@ namespace ultimateMrzSdk
260262
const int exifOrientation = 1
261263
);
262264

265+
/*! Retrieve EXIF orientation value from JPEG meta-data.
266+
\param jpegMetaDataPtr Pointer to the meta-data.
267+
\param jpegMetaDataSize Size of the meta-data.
268+
\returns Image's EXIF/JPEG orientation. Must be within [1, 8]. More information at https://www.impulseadventure.com/photo/exif-orientation.html.
269+
270+
Available since: 2.9.0
271+
*/
272+
static int exifOrientation(const void* jpegMetaDataPtr, const size_t jpegMetaDataSize);
273+
263274
/*! Build a unique runtime license key associated to this device.
264-
You must \ref init "initialize" the engine before calling this function.
265-
This function doesn't require internet connection.
266-
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.
267-
\param rawInsteadOfJSON Whether to output the runtime key as raw string intead of JSON entry. Requesting raw
268-
string instead of JSON could be helpful for applications without JSON parser to extract the key.
269-
\returns a \ref UltAlprSdkResult "result"
275+
You must \ref init "initialize" the engine before calling this function.
276+
This function doesn't require internet connection.
277+
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.
278+
\param rawInsteadOfJSON Whether to output the runtime key as raw string intead of JSON entry. Requesting raw
279+
string instead of JSON could be helpful for applications without JSON parser to extract the key.
280+
\returns a \ref UltAlprSdkResult "result"
270281
*/
271282
static UltMrzSdkResult requestRuntimeLicenseKey(const bool& rawInsteadOfJSON = false);
272283

csharp/UltMrzSdkEngine.cs

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, IntPtr yP
8686
return ret;
8787
}
8888

89+
public static int exifOrientation(IntPtr jpegMetaDataPtr, uint jpegMetaDataSize) {
90+
int ret = ultimateMrzSdkPINVOKE.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
91+
return ret;
92+
}
93+
8994
public static UltMrzSdkResult requestRuntimeLicenseKey(bool rawInsteadOfJSON) {
9095
UltMrzSdkResult ret = new UltMrzSdkResult(ultimateMrzSdkPINVOKE.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
9196
return ret;

csharp/ultimateMrzSdkPINVOKE.cs

+3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ static ultimateMrzSdkPINVOKE() {
255255
[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_process__SWIG_5")]
256256
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);
257257

258+
[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_exifOrientation")]
259+
public static extern int UltMrzSdkEngine_exifOrientation(IntPtr jarg1, uint jarg2);
260+
258261
[DllImport("ultimateMRZ-SDK", EntryPoint="CSharp_UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0")]
259262
public static extern IntPtr UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(bool jarg1);
260263

java/android/org/doubango/ultimateMrz/Sdk/UltMrzSdkEngine.java

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, java.nio.
7171
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_process__SWIG_5(imageType.swigValue(), yPtr, uPtr, vPtr, widthInSamples, heightInSamples, yStrideInBytes, uStrideInBytes, vStrideInBytes), true);
7272
}
7373

74+
public static int exifOrientation(java.nio.ByteBuffer jpegMetaDataPtr, long jpegMetaDataSize) {
75+
return ultimateMrzSdkJNI.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
76+
}
77+
7478
public static UltMrzSdkResult requestRuntimeLicenseKey(boolean rawInsteadOfJSON) {
7579
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
7680
}

java/android/org/doubango/ultimateMrz/Sdk/ultimateMrzSdkConstants.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
public interface ultimateMrzSdkConstants {
1212
public final static int ULTMRZ_SDK_VERSION_MAJOR = 2;
13-
public final static int ULTMRZ_SDK_VERSION_MINOR = 3;
14-
public final static int ULTMRZ_SDK_VERSION_MICRO = 4;
13+
public final static int ULTMRZ_SDK_VERSION_MINOR = 9;
14+
public final static int ULTMRZ_SDK_VERSION_MICRO = 0;
1515
}

java/android/org/doubango/ultimateMrz/Sdk/ultimateMrzSdkJNI.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ultimateMrzSdkJNI {
3333
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);
3434
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);
3535
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);
36+
public final static native int UltMrzSdkEngine_exifOrientation(java.nio.ByteBuffer jarg1, long jarg2);
3637
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(boolean jarg1);
3738
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_1();
3839
public final static native void delete_UltMrzSdkEngine(long jarg1);

java/org/doubango/ultimateMrz/Sdk/UltMrzSdkEngine.java

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static UltMrzSdkResult process(ULTMRZ_SDK_IMAGE_TYPE imageType, java.nio.
7171
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_process__SWIG_5(imageType.swigValue(), yPtr, uPtr, vPtr, widthInSamples, heightInSamples, yStrideInBytes, uStrideInBytes, vStrideInBytes), true);
7272
}
7373

74+
public static int exifOrientation(java.nio.ByteBuffer jpegMetaDataPtr, long jpegMetaDataSize) {
75+
return ultimateMrzSdkJNI.UltMrzSdkEngine_exifOrientation(jpegMetaDataPtr, jpegMetaDataSize);
76+
}
77+
7478
public static UltMrzSdkResult requestRuntimeLicenseKey(boolean rawInsteadOfJSON) {
7579
return new UltMrzSdkResult(ultimateMrzSdkJNI.UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(rawInsteadOfJSON), true);
7680
}

java/org/doubango/ultimateMrz/Sdk/ultimateMrzSdkConstants.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
public interface ultimateMrzSdkConstants {
1212
public final static int ULTMRZ_SDK_VERSION_MAJOR = 2;
13-
public final static int ULTMRZ_SDK_VERSION_MINOR = 3;
14-
public final static int ULTMRZ_SDK_VERSION_MICRO = 4;
13+
public final static int ULTMRZ_SDK_VERSION_MINOR = 9;
14+
public final static int ULTMRZ_SDK_VERSION_MICRO = 0;
1515
}

java/org/doubango/ultimateMrz/Sdk/ultimateMrzSdkJNI.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ultimateMrzSdkJNI {
2828
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);
2929
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);
3030
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);
31+
public final static native int UltMrzSdkEngine_exifOrientation(java.nio.ByteBuffer jarg1, long jarg2);
3132
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(boolean jarg1);
3233
public final static native long UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_1();
3334
public final static native void delete_UltMrzSdkEngine(long jarg1);

python/ultimateMRZ-SDK-API-PUBLIC-SWIG_python.cxx

+40-1
Original file line numberDiff line numberDiff line change
@@ -4728,6 +4728,44 @@ SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_process(PyObject *self, PyObject *arg
47284728
}
47294729

47304730

4731+
SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_exifOrientation(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
4732+
PyObject *resultobj = 0;
4733+
void *arg1 = (void *) 0 ;
4734+
size_t arg2 ;
4735+
size_t val2 ;
4736+
int ecode2 = 0 ;
4737+
PyObject * obj0 = 0 ;
4738+
PyObject * obj1 = 0 ;
4739+
int result;
4740+
4741+
if (!PyArg_ParseTuple(args,(char *)"OO:UltMrzSdkEngine_exifOrientation",&obj0,&obj1)) SWIG_fail;
4742+
{
4743+
// https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
4744+
// char* PyBytes_AsString(PyObject *o)
4745+
// Return a pointer to the contents of o. The pointer refers to the internal buffer of o, which consists of len(o) + 1 bytes.
4746+
// The last byte in the buffer is always null, regardless of whether there are any other null bytes.
4747+
// The data must not be modified in any way, unless the object was just created using PyBytes_FromStringAndSize(NULL, size).
4748+
// It must not be deallocated. If o is not a bytes object at all, PyBytes_AsString() returns NULL and raises TypeError.
4749+
if (PyBytes_Check(obj0)) {
4750+
arg1 = (void *) PyBytes_AsString(obj0);
4751+
}
4752+
else if (PyString_Check(obj0)) {
4753+
arg1 = (void *) PyString_AsString(obj0);
4754+
}
4755+
}
4756+
ecode2 = SWIG_AsVal_size_t(obj1, &val2);
4757+
if (!SWIG_IsOK(ecode2)) {
4758+
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "UltMrzSdkEngine_exifOrientation" "', argument " "2"" of type '" "size_t""'");
4759+
}
4760+
arg2 = static_cast< size_t >(val2);
4761+
result = (int)ultimateMrzSdk::UltMrzSdkEngine::exifOrientation((void const *)arg1,arg2);
4762+
resultobj = SWIG_From_int(static_cast< int >(result));
4763+
return resultobj;
4764+
fail:
4765+
return NULL;
4766+
}
4767+
4768+
47314769
SWIGINTERN PyObject *_wrap_UltMrzSdkEngine_requestRuntimeLicenseKey__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
47324770
PyObject *resultobj = 0;
47334771
bool *arg1 = 0 ;
@@ -4839,6 +4877,7 @@ static PyMethodDef SwigMethods[] = {
48394877
{ (char *)"UltMrzSdkEngine_init", _wrap_UltMrzSdkEngine_init, METH_VARARGS, NULL},
48404878
{ (char *)"UltMrzSdkEngine_deInit", _wrap_UltMrzSdkEngine_deInit, METH_VARARGS, NULL},
48414879
{ (char *)"UltMrzSdkEngine_process", _wrap_UltMrzSdkEngine_process, METH_VARARGS, NULL},
4880+
{ (char *)"UltMrzSdkEngine_exifOrientation", _wrap_UltMrzSdkEngine_exifOrientation, METH_VARARGS, NULL},
48424881
{ (char *)"UltMrzSdkEngine_requestRuntimeLicenseKey", _wrap_UltMrzSdkEngine_requestRuntimeLicenseKey, METH_VARARGS, NULL},
48434882
{ (char *)"delete_UltMrzSdkEngine", _wrap_delete_UltMrzSdkEngine, METH_VARARGS, NULL},
48444883
{ (char *)"UltMrzSdkEngine_swigregister", UltMrzSdkEngine_swigregister, METH_VARARGS, NULL},
@@ -5583,7 +5622,7 @@ SWIG_init(void) {
55835622
SWIG_InstallConstants(d,swig_const_table);
55845623

55855624
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MAJOR",SWIG_From_int(static_cast< int >(2)));
5586-
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MINOR",SWIG_From_int(static_cast< int >(4)));
5625+
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MINOR",SWIG_From_int(static_cast< int >(9)));
55875626
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_VERSION_MICRO",SWIG_From_int(static_cast< int >(0)));
55885627
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_IMAGE_TYPE_RGB24",SWIG_From_int(static_cast< int >(ultimateMrzSdk::ULTMRZ_SDK_IMAGE_TYPE_RGB24)));
55895628
SWIG_Python_SetConstant(d, "ULTMRZ_SDK_IMAGE_TYPE_RGBA32",SWIG_From_int(static_cast< int >(ultimateMrzSdk::ULTMRZ_SDK_IMAGE_TYPE_RGBA32)));

python/ultimateMrzSdk.py

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def __init__(self, *args, **kwargs): raise AttributeError("No constructor define
114114
if _newclass:deInit = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_deInit)
115115
__swig_getmethods__["process"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_process
116116
if _newclass:process = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_process)
117+
__swig_getmethods__["exifOrientation"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation
118+
if _newclass:exifOrientation = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_exifOrientation)
117119
__swig_getmethods__["requestRuntimeLicenseKey"] = lambda x: _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey
118120
if _newclass:requestRuntimeLicenseKey = staticmethod(_ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey)
119121
__swig_destroy__ = _ultimateMrzSdk.delete_UltMrzSdkEngine
@@ -133,6 +135,10 @@ def UltMrzSdkEngine_process(*args):
133135
return _ultimateMrzSdk.UltMrzSdkEngine_process(*args)
134136
UltMrzSdkEngine_process = _ultimateMrzSdk.UltMrzSdkEngine_process
135137

138+
def UltMrzSdkEngine_exifOrientation(*args):
139+
return _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation(*args)
140+
UltMrzSdkEngine_exifOrientation = _ultimateMrzSdk.UltMrzSdkEngine_exifOrientation
141+
136142
def UltMrzSdkEngine_requestRuntimeLicenseKey(rawInsteadOfJSON=False):
137143
return _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey(rawInsteadOfJSON)
138144
UltMrzSdkEngine_requestRuntimeLicenseKey = _ultimateMrzSdk.UltMrzSdkEngine_requestRuntimeLicenseKey

samples/c++/recognizer/main.cxx

+64-19
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@
4040

4141
using namespace ultimateMrzSdk;
4242

43+
struct MrzFile {
44+
int width = 0, height = 0, channels = 0;
45+
stbi_uc* uncompressedDataPtr = nullptr;
46+
void* compressedDataPtr = nullptr;
47+
size_t compressedDataSize = 0;
48+
FILE* filePtr = nullptr;
49+
virtual ~MrzFile() {
50+
if (uncompressedDataPtr) free(uncompressedDataPtr), uncompressedDataPtr = nullptr;
51+
if (compressedDataPtr) free(compressedDataPtr), compressedDataPtr = nullptr;
52+
if (filePtr) fclose(filePtr), filePtr = nullptr;
53+
}
54+
bool isValid() const {
55+
return width > 0 && height > 0 && (channels == 1 || channels == 3 || channels == 4) && uncompressedDataPtr && compressedDataPtr && compressedDataSize > 0;
56+
}
57+
};
58+
4359
static void printUsage(const std::string& message = "");
4460
static bool parseArgs(int argc, char *argv[], std::map<std::string, std::string >& values);
61+
static bool readFile(const std::string& path, MrzFile& file);
4562

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

143160
// Decode the file
144-
FILE* file = nullptr;
145-
if (!file && (file = fopen(pathFileImage.c_str(), "rb")) == nullptr) {
146-
ULTMRZ_SDK_PRINT_ERROR("Can't open %s", pathFileImage.c_str());
147-
return -1;
148-
}
149-
150-
int width, height, channels;
151-
stbi_uc* uncompressedData = stbi_load_from_file(file, &width, &height, &channels, 0);
152-
fclose(file);
153-
if (!uncompressedData || !width || !height || (channels != 1 && channels != 3 && channels != 4)) {
154-
ULTMRZ_SDK_PRINT_ERROR("Invalid file(%s, %d, %d, %d)", pathFileImage.c_str(), width, height, channels);
161+
MrzFile file;
162+
if (!readFile(pathFileImage, file)) {
163+
ULTMRZ_SDK_PRINT_ERROR("Can't process %s", pathFileImage.c_str());
155164
return -1;
156165
}
166+
ULTMRZ_SDK_ASSERT(file.isValid());
157167

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

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

187-
// free memory
188-
stbi_image_free(uncompressedData);
189-
190199
// Press any key to terminate
191200
ULTMRZ_SDK_PRINT_INFO("Press any key to terminate !!");
192201
getchar();
@@ -253,4 +262,40 @@ static bool parseArgs(int argc, char *argv[], std::map<std::string, std::string
253262
}
254263

255264
return true;
256-
}
265+
}
266+
267+
static bool readFile(const std::string& path, MrzFile& file)
268+
{
269+
// Open the file
270+
if ((file.filePtr = fopen(path.c_str(), "rb")) == nullptr) {
271+
ULTMRZ_SDK_PRINT_ERROR("Can't open %s", path.c_str());
272+
return false;
273+
}
274+
275+
// Retrieve file size
276+
struct stat st_;
277+
if (stat(path.c_str(), &st_) != 0) {
278+
ULTMRZ_SDK_PRINT_ERROR("File is empty %s", path.c_str());
279+
}
280+
file.compressedDataSize = static_cast<size_t>(st_.st_size);
281+
282+
// Alloc memory and read data
283+
file.compressedDataPtr = ::malloc(file.compressedDataSize);
284+
if (!file.compressedDataPtr) {
285+
ULTMRZ_SDK_PRINT_ERROR("Failed to alloc mem with size = %zu", file.compressedDataSize);
286+
return false;
287+
}
288+
size_t read_;
289+
if (file.compressedDataSize != (read_ = fread(file.compressedDataPtr, 1, file.compressedDataSize, file.filePtr))) {
290+
ULTMRZ_SDK_PRINT_ERROR("fread(%s) returned %zu instead of %zu", path.c_str(), read_, file.compressedDataSize);
291+
return false;
292+
}
293+
294+
// Decode image
295+
file.uncompressedDataPtr = stbi_load_from_memory(
296+
reinterpret_cast<stbi_uc const *>(file.compressedDataPtr), static_cast<int>(file.compressedDataSize),
297+
&file.width, &file.height, &file.channels, 0
298+
);
299+
300+
return file.isValid();
301+
}

0 commit comments

Comments
 (0)