diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index bc74850f2c..2afedb078a 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -137,8 +137,8 @@ if (BUILD_READERS) src/ThresholdBinarizer.h src/WhiteRectDetector.h src/WhiteRectDetector.cpp - $<$:src/zxing-c.h> - $<$:src/zxing-c.cpp> + $<$:src/ZXingC.h> + $<$:src/ZXingC.cpp> ) endif() if (BUILD_WRITERS) @@ -177,7 +177,7 @@ if (BUILD_READERS) src/ReaderOptions.h src/Result.h src/StructuredAppend.h - $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/zxing-c.h> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/ZXingC.h> ) endif() if (BUILD_WRITERS) @@ -481,7 +481,7 @@ endif() set_target_properties(ZXing PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") set(PRECOMPILE_HEADERS ${PUBLIC_HEADERS}) -list(REMOVE_ITEM PRECOMPILE_HEADERS "$<$:${CMAKE_CURRENT_SOURCE_DIR}/src/zxing-c.h>") +list(REMOVE_ITEM PRECOMPILE_HEADERS "$<$:${CMAKE_CURRENT_SOURCE_DIR}/src/ZXingC.h>") target_precompile_headers(ZXing PRIVATE ${PRECOMPILE_HEADERS}) set_source_files_properties(src/libzueci/zueci.c PROPERTIES SKIP_PRECOMPILE_HEADERS ON) set_source_files_properties(src/DecodeHints.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON) diff --git a/core/src/zxing-c.cpp b/core/src/ZXingC.cpp similarity index 63% rename from core/src/zxing-c.cpp rename to core/src/ZXingC.cpp index f141130b6d..05579f29f0 100644 --- a/core/src/zxing-c.cpp +++ b/core/src/ZXingC.cpp @@ -4,7 +4,7 @@ */ // SPDX-License-Identifier: Apache-2.0 -#include "zxing-c.h" +#include "ZXingC.h" #include "ReadBarcode.h" @@ -48,7 +48,7 @@ static uint8_t* copy(const ByteArray& ba, int* len) return ret; } -static std::tuple ReadBarcodesAndSetLastError(const zxing_ImageView* iv, const zxing_ReaderOptions* opts, +static std::tuple ReadBarcodesAndSetLastError(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts, int maxSymbols) { try { @@ -73,7 +73,7 @@ extern "C" { * ZXing/ImageView.h */ -zxing_ImageView* zxing_ImageView_new(const uint8_t* data, int width, int height, zxing_ImageFormat format, int rowStride, +ZXing_ImageView* ZXing_ImageView_new(const uint8_t* data, int width, int height, ZXing_ImageFormat format, int rowStride, int pixStride) { ImageFormat cppformat = static_cast(format); @@ -85,7 +85,7 @@ zxing_ImageView* zxing_ImageView_new(const uint8_t* data, int width, int height, return NULL; } -zxing_ImageView* zxing_ImageView_new_checked(const uint8_t* data, int size, int width, int height, zxing_ImageFormat format, +ZXing_ImageView* ZXing_ImageView_new_checked(const uint8_t* data, int size, int width, int height, ZXing_ImageFormat format, int rowStride, int pixStride) { ImageFormat cppformat = static_cast(format); @@ -97,17 +97,17 @@ zxing_ImageView* zxing_ImageView_new_checked(const uint8_t* data, int size, int return NULL; } -void zxing_ImageView_delete(zxing_ImageView* iv) +void ZXing_ImageView_delete(ZXing_ImageView* iv) { delete iv; } -void zxing_ImageView_crop(zxing_ImageView* iv, int left, int top, int width, int height) +void ZXing_ImageView_crop(ZXing_ImageView* iv, int left, int top, int width, int height) { *iv = iv->cropped(left, top, width, height); } -void zxing_ImageView_rotate(zxing_ImageView* iv, int degree) +void ZXing_ImageView_rotate(ZXing_ImageView* iv, int degree) { *iv = iv->rotated(degree); } @@ -116,29 +116,29 @@ void zxing_ImageView_rotate(zxing_ImageView* iv, int degree) * ZXing/BarcodeFormat.h */ -zxing_BarcodeFormats zxing_BarcodeFormatsFromString(const char* str) +ZXing_BarcodeFormats ZXing_BarcodeFormatsFromString(const char* str) { if (!str) return {}; try { auto format = BarcodeFormatsFromString(str); - return static_cast(transmute_cast(format)); + return static_cast(transmute_cast(format)); } catch (std::exception& e) { lastErrorMsg = e.what(); } catch (...) { lastErrorMsg = "Unknown error"; } - return zxing_BarcodeFormat_Invalid; + return ZXing_BarcodeFormat_Invalid; } -zxing_BarcodeFormat zxing_BarcodeFormatFromString(const char* str) +ZXing_BarcodeFormat ZXing_BarcodeFormatFromString(const char* str) { - zxing_BarcodeFormat res = zxing_BarcodeFormatsFromString(str); - return BitHacks::CountBitsSet(res) == 1 ? res : zxing_BarcodeFormat_Invalid; + ZXing_BarcodeFormat res = ZXing_BarcodeFormatsFromString(str); + return BitHacks::CountBitsSet(res) == 1 ? res : ZXing_BarcodeFormat_Invalid; } -char* zxing_BarcodeFormatToString(zxing_BarcodeFormat format) +char* ZXing_BarcodeFormatToString(ZXing_BarcodeFormat format) { return copy(ToString(static_cast(format))); } @@ -147,19 +147,19 @@ char* zxing_BarcodeFormatToString(zxing_BarcodeFormat format) * ZXing/ReaderOptions.h */ -zxing_ReaderOptions* zxing_ReaderOptions_new() +ZXing_ReaderOptions* ZXing_ReaderOptions_new() { return new ReaderOptions(); } -void zxing_ReaderOptions_delete(zxing_ReaderOptions* opts) +void ZXing_ReaderOptions_delete(ZXing_ReaderOptions* opts) { delete opts; } #define ZX_PROPERTY(TYPE, GETTER, SETTER) \ - TYPE zxing_ReaderOptions_get##SETTER(const zxing_ReaderOptions* opts) { return opts->GETTER(); } \ - void zxing_ReaderOptions_set##SETTER(zxing_ReaderOptions* opts, TYPE val) { opts->set##SETTER(val); } + TYPE ZXing_ReaderOptions_get##SETTER(const ZXing_ReaderOptions* opts) { return opts->GETTER(); } \ + void ZXing_ReaderOptions_set##SETTER(ZXing_ReaderOptions* opts, TYPE val) { opts->set##SETTER(val); } ZX_PROPERTY(bool, tryHarder, TryHarder) ZX_PROPERTY(bool, tryRotate, TryRotate) @@ -170,20 +170,20 @@ ZX_PROPERTY(bool, returnErrors, ReturnErrors) ZX_PROPERTY(int, minLineCount, MinLineCount) ZX_PROPERTY(int, maxNumberOfSymbols, MaxNumberOfSymbols) -void zxing_ReaderOptions_setFormats(zxing_ReaderOptions* opts, zxing_BarcodeFormats formats) +void ZXing_ReaderOptions_setFormats(ZXing_ReaderOptions* opts, ZXing_BarcodeFormats formats) { opts->setFormats(static_cast(formats)); } -zxing_BarcodeFormats zxing_ReaderOptions_getFormats(const zxing_ReaderOptions* opts) +ZXing_BarcodeFormats ZXing_ReaderOptions_getFormats(const ZXing_ReaderOptions* opts) { auto v = opts->formats(); - return transmute_cast(v); + return transmute_cast(v); } #define ZX_ENUM_PROPERTY(TYPE, GETTER, SETTER) \ - zxing_##TYPE zxing_ReaderOptions_get##SETTER(const zxing_ReaderOptions* opts) { return static_cast(opts->GETTER()); } \ - void zxing_ReaderOptions_set##SETTER(zxing_ReaderOptions* opts, zxing_##TYPE val) { opts->set##SETTER(static_cast(val)); } + ZXing_##TYPE ZXing_ReaderOptions_get##SETTER(const ZXing_ReaderOptions* opts) { return static_cast(opts->GETTER()); } \ + void ZXing_ReaderOptions_set##SETTER(ZXing_ReaderOptions* opts, ZXing_##TYPE val) { opts->set##SETTER(static_cast(val)); } ZX_ENUM_PROPERTY(Binarizer, binarizer, Binarizer) ZX_ENUM_PROPERTY(EanAddOnSymbol, eanAddOnSymbol, EanAddOnSymbol) @@ -193,46 +193,46 @@ ZX_ENUM_PROPERTY(TextMode, textMode, TextMode) * ZXing/Result.h */ -char* zxing_ContentTypeToString(zxing_ContentType type) +char* ZXing_ContentTypeToString(ZXing_ContentType type) { return copy(ToString(static_cast(type))); } -char* zxing_PositionToString(zxing_Position position) +char* ZXing_PositionToString(ZXing_Position position) { return copy(ToString(transmute_cast(position))); } -bool zxing_Barcode_isValid(const zxing_Barcode* barcode) +bool ZXing_Barcode_isValid(const ZXing_Barcode* barcode) { return barcode != NULL && barcode->isValid(); } -char* zxing_Barcode_errorMsg(const zxing_Barcode* barcode) +char* ZXing_Barcode_errorMsg(const ZXing_Barcode* barcode) { return copy(ToString(barcode->error())); } -uint8_t* zxing_Barcode_bytes(const zxing_Barcode* barcode, int* len) +uint8_t* ZXing_Barcode_bytes(const ZXing_Barcode* barcode, int* len) { return copy(barcode->bytes(), len); } -uint8_t* zxing_Barcode_bytesECI(const zxing_Barcode* barcode, int* len) +uint8_t* ZXing_Barcode_bytesECI(const ZXing_Barcode* barcode, int* len) { return copy(barcode->bytesECI(), len); } #define ZX_GETTER(TYPE, GETTER, TRANS) \ - TYPE zxing_Barcode_##GETTER(const zxing_Barcode* barcode) { return static_cast(TRANS(barcode->GETTER())); } + TYPE ZXing_Barcode_##GETTER(const ZXing_Barcode* barcode) { return static_cast(TRANS(barcode->GETTER())); } -ZX_GETTER(zxing_BarcodeFormat, format,) -ZX_GETTER(zxing_ContentType, contentType,) +ZX_GETTER(ZXing_BarcodeFormat, format,) +ZX_GETTER(ZXing_ContentType, contentType,) ZX_GETTER(char*, text, copy) ZX_GETTER(char*, ecLevel, copy) ZX_GETTER(char*, symbologyIdentifier, copy) -ZX_GETTER(zxing_Position, position, transmute_cast) +ZX_GETTER(ZXing_Position, position, transmute_cast) ZX_GETTER(int, orientation,) ZX_GETTER(bool, hasECI,) @@ -245,41 +245,41 @@ ZX_GETTER(int, lineCount,) * ZXing/ReadBarcode.h */ -zxing_Barcode* zxing_ReadBarcode(const zxing_ImageView* iv, const zxing_ReaderOptions* opts) +ZXing_Barcode* ZXing_ReadBarcode(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts) { auto [res, ok] = ReadBarcodesAndSetLastError(iv, opts, 1); return !res.empty() ? new Result(std::move(res.front())) : NULL; } -zxing_Barcodes* zxing_ReadBarcodes(const zxing_ImageView* iv, const zxing_ReaderOptions* opts) +ZXing_Barcodes* ZXing_ReadBarcodes(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts) { auto [res, ok] = ReadBarcodesAndSetLastError(iv, opts, 0); return !res.empty() || ok ? new Results(std::move(res)) : NULL; } -void zxing_Barcode_delete(zxing_Barcode* barcode) +void ZXing_Barcode_delete(ZXing_Barcode* barcode) { delete barcode; } -void zxing_Barcodes_delete(zxing_Barcodes* barcodes) +void ZXing_Barcodes_delete(ZXing_Barcodes* barcodes) { delete barcodes; } -int zxing_Barcodes_size(const zxing_Barcodes* barcodes) +int ZXing_Barcodes_size(const ZXing_Barcodes* barcodes) { return barcodes ? Size(*barcodes) : 0; } -const zxing_Barcode* zxing_Barcodes_at(const zxing_Barcodes* barcodes, int i) +const ZXing_Barcode* ZXing_Barcodes_at(const ZXing_Barcodes* barcodes, int i) { if (!barcodes || i < 0 || i >= Size(*barcodes)) return NULL; return &(*barcodes)[i]; } -zxing_Barcode* zxing_Barcodes_move(zxing_Barcodes* barcodes, int i) +ZXing_Barcode* ZXing_Barcodes_move(ZXing_Barcodes* barcodes, int i) { if (!barcodes || i < 0 || i >= Size(*barcodes)) return NULL; @@ -287,7 +287,7 @@ zxing_Barcode* zxing_Barcodes_move(zxing_Barcodes* barcodes, int i) return new Result(std::move((*barcodes)[i])); } -char* zxing_LastErrorMsg() +char* ZXing_LastErrorMsg() { if (lastErrorMsg.empty()) return NULL; @@ -295,7 +295,7 @@ char* zxing_LastErrorMsg() return copy(std::exchange(lastErrorMsg, {})); } -void zxing_free(void* ptr) +void ZXing_free(void* ptr) { free(ptr); } diff --git a/core/src/ZXingC.h b/core/src/ZXingC.h new file mode 100644 index 0000000000..63d249ed6c --- /dev/null +++ b/core/src/ZXingC.h @@ -0,0 +1,228 @@ +/* +* Copyright 2023 siiky +* Copyright 2023 Axel Waggershauser +*/ +// SPDX-License-Identifier: Apache-2.0 + +#ifndef _ZXING_C_H +#define _ZXING_C_H + +#include +#include + +#ifdef __cplusplus + +#include "ReaderOptions.h" +#include "ImageView.h" +#include "Result.h" + +typedef ZXing::ImageView ZXing_ImageView; +typedef ZXing::ReaderOptions ZXing_ReaderOptions; +typedef ZXing::Result ZXing_Barcode; +typedef ZXing::Results ZXing_Barcodes; + +extern "C" +{ +#else + +typedef struct ZXing_ImageView ZXing_ImageView; +typedef struct ZXing_ReaderOptions ZXing_ReaderOptions; +typedef struct ZXing_Barcode ZXing_Barcode; +typedef struct ZXing_Barcodes ZXing_Barcodes; + +#endif + +/* + * ZXing/ImageView.h + */ + +typedef enum { + ZXing_ImageFormat_None = 0, + ZXing_ImageFormat_Lum = 0x01000000, + ZXing_ImageFormat_RGB = 0x03000102, + ZXing_ImageFormat_BGR = 0x03020100, + ZXing_ImageFormat_RGBX = 0x04000102, + ZXing_ImageFormat_XRGB = 0x04010203, + ZXing_ImageFormat_BGRX = 0x04020100, + ZXing_ImageFormat_XBGR = 0x04030201, +} ZXing_ImageFormat; + +ZXing_ImageView* ZXing_ImageView_new(const uint8_t* data, int width, int height, ZXing_ImageFormat format, int rowStride, + int pixStride); +ZXing_ImageView* ZXing_ImageView_new_checked(const uint8_t* data, int size, int width, int height, ZXing_ImageFormat format, + int rowStride, int pixStride); +void ZXing_ImageView_delete(ZXing_ImageView* iv); + +void ZXing_ImageView_crop(ZXing_ImageView* iv, int left, int top, int width, int height); +void ZXing_ImageView_rotate(ZXing_ImageView* iv, int degree); + +/* + * ZXing/BarcodeFormat.h + */ + +typedef enum +{ + ZXing_BarcodeFormat_None = 0, + ZXing_BarcodeFormat_Aztec = (1 << 0), + ZXing_BarcodeFormat_Codabar = (1 << 1), + ZXing_BarcodeFormat_Code39 = (1 << 2), + ZXing_BarcodeFormat_Code93 = (1 << 3), + ZXing_BarcodeFormat_Code128 = (1 << 4), + ZXing_BarcodeFormat_DataBar = (1 << 5), + ZXing_BarcodeFormat_DataBarExpanded = (1 << 6), + ZXing_BarcodeFormat_DataMatrix = (1 << 7), + ZXing_BarcodeFormat_EAN8 = (1 << 8), + ZXing_BarcodeFormat_EAN13 = (1 << 9), + ZXing_BarcodeFormat_ITF = (1 << 10), + ZXing_BarcodeFormat_MaxiCode = (1 << 11), + ZXing_BarcodeFormat_PDF417 = (1 << 12), + ZXing_BarcodeFormat_QRCode = (1 << 13), + ZXing_BarcodeFormat_UPCA = (1 << 14), + ZXing_BarcodeFormat_UPCE = (1 << 15), + ZXing_BarcodeFormat_MicroQRCode = (1 << 16), + ZXing_BarcodeFormat_RMQRCode = (1 << 17), + ZXing_BarcodeFormat_DXFilmEdge = (1 << 18), + + ZXing_BarcodeFormat_LinearCodes = ZXing_BarcodeFormat_Codabar | ZXing_BarcodeFormat_Code39 | ZXing_BarcodeFormat_Code93 + | ZXing_BarcodeFormat_Code128 | ZXing_BarcodeFormat_EAN8 | ZXing_BarcodeFormat_EAN13 + | ZXing_BarcodeFormat_ITF | ZXing_BarcodeFormat_DataBar | ZXing_BarcodeFormat_DataBarExpanded + | ZXing_BarcodeFormat_DXFilmEdge | ZXing_BarcodeFormat_UPCA | ZXing_BarcodeFormat_UPCE, + ZXing_BarcodeFormat_MatrixCodes = ZXing_BarcodeFormat_Aztec | ZXing_BarcodeFormat_DataMatrix | ZXing_BarcodeFormat_MaxiCode + | ZXing_BarcodeFormat_PDF417 | ZXing_BarcodeFormat_QRCode | ZXing_BarcodeFormat_MicroQRCode + | ZXing_BarcodeFormat_RMQRCode, + ZXing_BarcodeFormat_Any = ZXing_BarcodeFormat_LinearCodes | ZXing_BarcodeFormat_MatrixCodes, + + ZXing_BarcodeFormat_Invalid = 0xFFFFFFFFu /* return value when BarcodeFormatsFromString() throws */ +} ZXing_BarcodeFormat; + +typedef ZXing_BarcodeFormat ZXing_BarcodeFormats; + +ZXing_BarcodeFormats ZXing_BarcodeFormatsFromString(const char* str); +ZXing_BarcodeFormat ZXing_BarcodeFormatFromString(const char* str); +char* ZXing_BarcodeFormatToString(ZXing_BarcodeFormat format); + +/* + * ZXing/ReaderOptions.h + */ + +typedef enum +{ + ZXing_Binarizer_LocalAverage, + ZXing_Binarizer_GlobalHistogram, + ZXing_Binarizer_FixedThreshold, + ZXing_Binarizer_BoolCast, +} ZXing_Binarizer; + +typedef enum +{ + ZXing_EanAddOnSymbol_Ignore, + ZXing_EanAddOnSymbol_Read, + ZXing_EanAddOnSymbol_Require, +} ZXing_EanAddOnSymbol; + +typedef enum +{ + ZXing_TextMode_Plain, + ZXing_TextMode_ECI, + ZXing_TextMode_HRI, + ZXing_TextMode_Hex, + ZXing_TextMode_Escaped, +} ZXing_TextMode; + +ZXing_ReaderOptions* ZXing_ReaderOptions_new(); +void ZXing_ReaderOptions_delete(ZXing_ReaderOptions* opts); + +void ZXing_ReaderOptions_setTryHarder(ZXing_ReaderOptions* opts, bool tryHarder); +void ZXing_ReaderOptions_setTryRotate(ZXing_ReaderOptions* opts, bool tryRotate); +void ZXing_ReaderOptions_setTryInvert(ZXing_ReaderOptions* opts, bool tryInvert); +void ZXing_ReaderOptions_setTryDownscale(ZXing_ReaderOptions* opts, bool tryDownscale); +void ZXing_ReaderOptions_setIsPure(ZXing_ReaderOptions* opts, bool isPure); +void ZXing_ReaderOptions_setReturnErrors(ZXing_ReaderOptions* opts, bool returnErrors); +void ZXing_ReaderOptions_setFormats(ZXing_ReaderOptions* opts, ZXing_BarcodeFormats formats); +void ZXing_ReaderOptions_setBinarizer(ZXing_ReaderOptions* opts, ZXing_Binarizer binarizer); +void ZXing_ReaderOptions_setEanAddOnSymbol(ZXing_ReaderOptions* opts, ZXing_EanAddOnSymbol eanAddOnSymbol); +void ZXing_ReaderOptions_setTextMode(ZXing_ReaderOptions* opts, ZXing_TextMode textMode); +void ZXing_ReaderOptions_setMinLineCount(ZXing_ReaderOptions* opts, int n); +void ZXing_ReaderOptions_setMaxNumberOfSymbols(ZXing_ReaderOptions* opts, int n); + +bool ZXing_ReaderOptions_getTryHarder(const ZXing_ReaderOptions* opts); +bool ZXing_ReaderOptions_getTryRotate(const ZXing_ReaderOptions* opts); +bool ZXing_ReaderOptions_getTryInvert(const ZXing_ReaderOptions* opts); +bool ZXing_ReaderOptions_getTryDownscale(const ZXing_ReaderOptions* opts); +bool ZXing_ReaderOptions_getIsPure(const ZXing_ReaderOptions* opts); +bool ZXing_ReaderOptions_getReturnErrors(const ZXing_ReaderOptions* opts); +ZXing_BarcodeFormats ZXing_ReaderOptions_getFormats(const ZXing_ReaderOptions* opts); +ZXing_Binarizer ZXing_ReaderOptions_getBinarizer(const ZXing_ReaderOptions* opts); +ZXing_EanAddOnSymbol ZXing_ReaderOptions_getEanAddOnSymbol(const ZXing_ReaderOptions* opts); +ZXing_TextMode ZXing_ReaderOptions_getTextMode(const ZXing_ReaderOptions* opts); +int ZXing_ReaderOptions_getMinLineCount(const ZXing_ReaderOptions* opts); +int ZXing_ReaderOptions_getMaxNumberOfSymbols(const ZXing_ReaderOptions* opts); + +/* + * ZXing/Result.h + */ + +typedef enum +{ + ZXing_ContentType_Text, + ZXing_ContentType_Binary, + ZXing_ContentType_Mixed, + ZXing_ContentType_GS1, + ZXing_ContentType_ISO15434, + ZXing_ContentType_UnknownECI +} ZXing_ContentType; + +char* ZXing_ContentTypeToString(ZXing_ContentType type); + +typedef struct ZXing_PointI +{ + int x, y; +} ZXing_PointI; + +typedef struct ZXing_Position +{ + ZXing_PointI topLeft, topRight, bottomRight, bottomLeft; +} ZXing_Position; + +char* ZXing_PositionToString(ZXing_Position position); + +bool ZXing_Barcode_isValid(const ZXing_Barcode* barcode); +char* ZXing_Barcode_errorMsg(const ZXing_Barcode* barcode); +ZXing_BarcodeFormat ZXing_Barcode_format(const ZXing_Barcode* barcode); +ZXing_ContentType ZXing_Barcode_contentType(const ZXing_Barcode* barcode); +uint8_t* ZXing_Barcode_bytes(const ZXing_Barcode* barcode, int* len); +uint8_t* ZXing_Barcode_bytesECI(const ZXing_Barcode* barcode, int* len); +char* ZXing_Barcode_text(const ZXing_Barcode* barcode); +char* ZXing_Barcode_ecLevel(const ZXing_Barcode* barcode); +char* ZXing_Barcode_symbologyIdentifier(const ZXing_Barcode* barcode); +ZXing_Position ZXing_Barcode_position(const ZXing_Barcode* barcode); +int ZXing_Barcode_orientation(const ZXing_Barcode* barcode); +bool ZXing_Barcode_hasECI(const ZXing_Barcode* barcode); +bool ZXing_Barcode_isInverted(const ZXing_Barcode* barcode); +bool ZXing_Barcode_isMirrored(const ZXing_Barcode* barcode); +int ZXing_Barcode_lineCount(const ZXing_Barcode* barcode); + +/* + * ZXing/ReadBarcode.h + */ + +/** Note: opts is optional, i.e. it can be NULL, which will imply default settings. */ +ZXing_Barcode* ZXing_ReadBarcode(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts); +ZXing_Barcodes* ZXing_ReadBarcodes(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts); + +void ZXing_Barcode_delete(ZXing_Barcode* barcode); +void ZXing_Barcodes_delete(ZXing_Barcodes* barcodes); + +int ZXing_Barcodes_size(const ZXing_Barcodes* barcodes); +const ZXing_Barcode* ZXing_Barcodes_at(const ZXing_Barcodes* barcodes, int i); +ZXing_Barcode* ZXing_Barcodes_move(ZXing_Barcodes* barcodes, int i); + +char* ZXing_LastErrorMsg(); + +void ZXing_free(void* ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* _ZXING_C_H */ diff --git a/core/src/zxing-c.h b/core/src/zxing-c.h deleted file mode 100644 index 75207aa679..0000000000 --- a/core/src/zxing-c.h +++ /dev/null @@ -1,228 +0,0 @@ -/* -* Copyright 2023 siiky -* Copyright 2023 Axel Waggershauser -*/ -// SPDX-License-Identifier: Apache-2.0 - -#ifndef _ZXING_C_H -#define _ZXING_C_H - -#include -#include - -#ifdef __cplusplus - -#include "ReaderOptions.h" -#include "ImageView.h" -#include "Result.h" - -typedef ZXing::ImageView zxing_ImageView; -typedef ZXing::ReaderOptions zxing_ReaderOptions; -typedef ZXing::Result zxing_Barcode; -typedef ZXing::Results zxing_Barcodes; - -extern "C" -{ -#else - -typedef struct zxing_ImageView zxing_ImageView; -typedef struct zxing_ReaderOptions zxing_ReaderOptions; -typedef struct zxing_Barcode zxing_Barcode; -typedef struct zxing_Barcodes zxing_Barcodes; - -#endif - -/* - * ZXing/ImageView.h - */ - -typedef enum { - zxing_ImageFormat_None = 0, - zxing_ImageFormat_Lum = 0x01000000, - zxing_ImageFormat_RGB = 0x03000102, - zxing_ImageFormat_BGR = 0x03020100, - zxing_ImageFormat_RGBX = 0x04000102, - zxing_ImageFormat_XRGB = 0x04010203, - zxing_ImageFormat_BGRX = 0x04020100, - zxing_ImageFormat_XBGR = 0x04030201, -} zxing_ImageFormat; - -zxing_ImageView* zxing_ImageView_new(const uint8_t* data, int width, int height, zxing_ImageFormat format, int rowStride, - int pixStride); -zxing_ImageView* zxing_ImageView_new_checked(const uint8_t* data, int size, int width, int height, zxing_ImageFormat format, - int rowStride, int pixStride); -void zxing_ImageView_delete(zxing_ImageView* iv); - -void zxing_ImageView_crop(zxing_ImageView* iv, int left, int top, int width, int height); -void zxing_ImageView_rotate(zxing_ImageView* iv, int degree); - -/* - * ZXing/BarcodeFormat.h - */ - -typedef enum -{ - zxing_BarcodeFormat_None = 0, - zxing_BarcodeFormat_Aztec = (1 << 0), - zxing_BarcodeFormat_Codabar = (1 << 1), - zxing_BarcodeFormat_Code39 = (1 << 2), - zxing_BarcodeFormat_Code93 = (1 << 3), - zxing_BarcodeFormat_Code128 = (1 << 4), - zxing_BarcodeFormat_DataBar = (1 << 5), - zxing_BarcodeFormat_DataBarExpanded = (1 << 6), - zxing_BarcodeFormat_DataMatrix = (1 << 7), - zxing_BarcodeFormat_EAN8 = (1 << 8), - zxing_BarcodeFormat_EAN13 = (1 << 9), - zxing_BarcodeFormat_ITF = (1 << 10), - zxing_BarcodeFormat_MaxiCode = (1 << 11), - zxing_BarcodeFormat_PDF417 = (1 << 12), - zxing_BarcodeFormat_QRCode = (1 << 13), - zxing_BarcodeFormat_UPCA = (1 << 14), - zxing_BarcodeFormat_UPCE = (1 << 15), - zxing_BarcodeFormat_MicroQRCode = (1 << 16), - zxing_BarcodeFormat_RMQRCode = (1 << 17), - zxing_BarcodeFormat_DXFilmEdge = (1 << 18), - - zxing_BarcodeFormat_LinearCodes = zxing_BarcodeFormat_Codabar | zxing_BarcodeFormat_Code39 | zxing_BarcodeFormat_Code93 - | zxing_BarcodeFormat_Code128 | zxing_BarcodeFormat_EAN8 | zxing_BarcodeFormat_EAN13 - | zxing_BarcodeFormat_ITF | zxing_BarcodeFormat_DataBar | zxing_BarcodeFormat_DataBarExpanded - | zxing_BarcodeFormat_DXFilmEdge | zxing_BarcodeFormat_UPCA | zxing_BarcodeFormat_UPCE, - zxing_BarcodeFormat_MatrixCodes = zxing_BarcodeFormat_Aztec | zxing_BarcodeFormat_DataMatrix | zxing_BarcodeFormat_MaxiCode - | zxing_BarcodeFormat_PDF417 | zxing_BarcodeFormat_QRCode | zxing_BarcodeFormat_MicroQRCode - | zxing_BarcodeFormat_RMQRCode, - zxing_BarcodeFormat_Any = zxing_BarcodeFormat_LinearCodes | zxing_BarcodeFormat_MatrixCodes, - - zxing_BarcodeFormat_Invalid = 0xFFFFFFFFu /* return value when BarcodeFormatsFromString() throws */ -} zxing_BarcodeFormat; - -typedef zxing_BarcodeFormat zxing_BarcodeFormats; - -zxing_BarcodeFormats zxing_BarcodeFormatsFromString(const char* str); -zxing_BarcodeFormat zxing_BarcodeFormatFromString(const char* str); -char* zxing_BarcodeFormatToString(zxing_BarcodeFormat format); - -/* - * ZXing/ReaderOptions.h - */ - -typedef enum -{ - zxing_Binarizer_LocalAverage, - zxing_Binarizer_GlobalHistogram, - zxing_Binarizer_FixedThreshold, - zxing_Binarizer_BoolCast, -} zxing_Binarizer; - -typedef enum -{ - zxing_EanAddOnSymbol_Ignore, - zxing_EanAddOnSymbol_Read, - zxing_EanAddOnSymbol_Require, -} zxing_EanAddOnSymbol; - -typedef enum -{ - zxing_TextMode_Plain, - zxing_TextMode_ECI, - zxing_TextMode_HRI, - zxing_TextMode_Hex, - zxing_TextMode_Escaped, -} zxing_TextMode; - -zxing_ReaderOptions* zxing_ReaderOptions_new(); -void zxing_ReaderOptions_delete(zxing_ReaderOptions* opts); - -void zxing_ReaderOptions_setTryHarder(zxing_ReaderOptions* opts, bool tryHarder); -void zxing_ReaderOptions_setTryRotate(zxing_ReaderOptions* opts, bool tryRotate); -void zxing_ReaderOptions_setTryInvert(zxing_ReaderOptions* opts, bool tryInvert); -void zxing_ReaderOptions_setTryDownscale(zxing_ReaderOptions* opts, bool tryDownscale); -void zxing_ReaderOptions_setIsPure(zxing_ReaderOptions* opts, bool isPure); -void zxing_ReaderOptions_setReturnErrors(zxing_ReaderOptions* opts, bool returnErrors); -void zxing_ReaderOptions_setFormats(zxing_ReaderOptions* opts, zxing_BarcodeFormats formats); -void zxing_ReaderOptions_setBinarizer(zxing_ReaderOptions* opts, zxing_Binarizer binarizer); -void zxing_ReaderOptions_setEanAddOnSymbol(zxing_ReaderOptions* opts, zxing_EanAddOnSymbol eanAddOnSymbol); -void zxing_ReaderOptions_setTextMode(zxing_ReaderOptions* opts, zxing_TextMode textMode); -void zxing_ReaderOptions_setMinLineCount(zxing_ReaderOptions* opts, int n); -void zxing_ReaderOptions_setMaxNumberOfSymbols(zxing_ReaderOptions* opts, int n); - -bool zxing_ReaderOptions_getTryHarder(const zxing_ReaderOptions* opts); -bool zxing_ReaderOptions_getTryRotate(const zxing_ReaderOptions* opts); -bool zxing_ReaderOptions_getTryInvert(const zxing_ReaderOptions* opts); -bool zxing_ReaderOptions_getTryDownscale(const zxing_ReaderOptions* opts); -bool zxing_ReaderOptions_getIsPure(const zxing_ReaderOptions* opts); -bool zxing_ReaderOptions_getReturnErrors(const zxing_ReaderOptions* opts); -zxing_BarcodeFormats zxing_ReaderOptions_getFormats(const zxing_ReaderOptions* opts); -zxing_Binarizer zxing_ReaderOptions_getBinarizer(const zxing_ReaderOptions* opts); -zxing_EanAddOnSymbol zxing_ReaderOptions_getEanAddOnSymbol(const zxing_ReaderOptions* opts); -zxing_TextMode zxing_ReaderOptions_getTextMode(const zxing_ReaderOptions* opts); -int zxing_ReaderOptions_getMinLineCount(const zxing_ReaderOptions* opts); -int zxing_ReaderOptions_getMaxNumberOfSymbols(const zxing_ReaderOptions* opts); - -/* - * ZXing/Result.h - */ - -typedef enum -{ - zxing_ContentType_Text, - zxing_ContentType_Binary, - zxing_ContentType_Mixed, - zxing_ContentType_GS1, - zxing_ContentType_ISO15434, - zxing_ContentType_UnknownECI -} zxing_ContentType; - -char* zxing_ContentTypeToString(zxing_ContentType type); - -typedef struct zxing_PointI -{ - int x, y; -} zxing_PointI; - -typedef struct zxing_Position -{ - zxing_PointI topLeft, topRight, bottomRight, bottomLeft; -} zxing_Position; - -char* zxing_PositionToString(zxing_Position position); - -bool zxing_Barcode_isValid(const zxing_Barcode* barcode); -char* zxing_Barcode_errorMsg(const zxing_Barcode* barcode); -zxing_BarcodeFormat zxing_Barcode_format(const zxing_Barcode* barcode); -zxing_ContentType zxing_Barcode_contentType(const zxing_Barcode* barcode); -uint8_t* zxing_Barcode_bytes(const zxing_Barcode* barcode, int* len); -uint8_t* zxing_Barcode_bytesECI(const zxing_Barcode* barcode, int* len); -char* zxing_Barcode_text(const zxing_Barcode* barcode); -char* zxing_Barcode_ecLevel(const zxing_Barcode* barcode); -char* zxing_Barcode_symbologyIdentifier(const zxing_Barcode* barcode); -zxing_Position zxing_Barcode_position(const zxing_Barcode* barcode); -int zxing_Barcode_orientation(const zxing_Barcode* barcode); -bool zxing_Barcode_hasECI(const zxing_Barcode* barcode); -bool zxing_Barcode_isInverted(const zxing_Barcode* barcode); -bool zxing_Barcode_isMirrored(const zxing_Barcode* barcode); -int zxing_Barcode_lineCount(const zxing_Barcode* barcode); - -/* - * ZXing/ReadBarcode.h - */ - -/** Note: opts is optional, i.e. it can be NULL, which will imply default settings. */ -zxing_Barcode* zxing_ReadBarcode(const zxing_ImageView* iv, const zxing_ReaderOptions* opts); -zxing_Barcodes* zxing_ReadBarcodes(const zxing_ImageView* iv, const zxing_ReaderOptions* opts); - -void zxing_Barcode_delete(zxing_Barcode* barcode); -void zxing_Barcodes_delete(zxing_Barcodes* barcodes); - -int zxing_Barcodes_size(const zxing_Barcodes* barcodes); -const zxing_Barcode* zxing_Barcodes_at(const zxing_Barcodes* barcodes, int i); -zxing_Barcode* zxing_Barcodes_move(zxing_Barcodes* barcodes, int i); - -char* zxing_LastErrorMsg(); - -void zxing_free(void* ptr); - -#ifdef __cplusplus -} -#endif - -#endif /* _ZXING_C_H */ diff --git a/wrappers/c/CMakeLists.txt b/wrappers/c/CMakeLists.txt index 0de0d12036..9754a9f70b 100644 --- a/wrappers/c/CMakeLists.txt +++ b/wrappers/c/CMakeLists.txt @@ -1,7 +1,7 @@ zxing_add_package_stb() if (BUILD_READERS) - add_executable (zxing-c-test zxing-c-test.c) - target_link_libraries (zxing-c-test ZXing::ZXing stb::stb) - add_test(NAME zxing-c-test COMMAND zxing-c-test ${CMAKE_SOURCE_DIR}/test/samples/qrcode-1/1.png) + add_executable (ZXingCTest ZXingCTest.c) + target_link_libraries (ZXingCTest ZXing::ZXing stb::stb) + add_test(NAME ZXingCTest COMMAND ZXingCTest ${CMAKE_SOURCE_DIR}/test/samples/qrcode-1/1.png) endif() diff --git a/wrappers/c/README.md b/wrappers/c/README.md index 62b920ae97..aa0d8c1a94 100644 --- a/wrappers/c/README.md +++ b/wrappers/c/README.md @@ -6,48 +6,49 @@ This is a preview/proposal for a C-API to zxing-cpp. If you have any comments or It is currently included in the default build to be trivially accessible for everyone. -Probably the easiest way to play with the C-API is to just modify the [zxing-c-test.c](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/c/zxing-c-test.c) file. +Probably the easiest way to play with the C-API is to just modify the [ZXingCTest.c](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/c/ZXingCTest.c) file. ## Usage The following is close to the most trivial use case scenario that is supported. ```c -#include "ZXing/zxing-c.h" +#include "ZXing/ZXingC.h" int main(int argc, char** argv) { int width, height; unsigned char* data; - /* load your image data from somewhere. ImageFormat_Lum assumes grey scale image data. */ + /* load your image data from somewhere. ZXing_ImageFormat_Lum assumes grey scale image data. */ - zxing_ImageView* iv = zxing_ImageView_new(data, width, height, zxing_ImageFormat_Lum, 0, 0); + ZXing_ImageView* iv = ZXing_ImageView_new(data, width, height, ZXing_ImageFormat_Lum, 0, 0); - zxing_ReaderOptions* opts = zxing_ReaderOptions_new(); - /* set ReaderOptions properties, if requried */ + ZXing_ReaderOptions* opts = ZXing_ReaderOptions_new(); + /* set ReaderOptions properties, if requried, e.g. */ + ZXing_ReaderOptions_setFormats(ZXing_BarcodeFormat_QRCode | ZXing_BarcodeFromat_EAN13); - zxing_Barcodes* barcodes = zxing_ReadBarcodes(iv, opts); + ZXing_Barcodes* barcodes = ZXing_ReadBarcodes(iv, opts); - zxing_ImageView_delete(iv); - zxing_ReaderOptions_delete(opts); + ZXing_ImageView_delete(iv); + ZXing_ReaderOptions_delete(opts); if (barcodes) { - for (int i = 0, n = zxing_Barcodes_size(barcodes); i < n; ++i) { - const zxing_Barcode* barcode = zxing_Barcodes_at(barcodes, i); + for (int i = 0, n = ZXing_Barcodes_size(barcodes); i < n; ++i) { + const ZXing_Barcode* barcode = ZXing_Barcodes_at(barcodes, i); - char* format = zxing_BarcodeFormatToString(zxing_Barcode_format(barcode)); + char* format = ZXing_BarcodeFormatToString(ZXing_Barcode_format(barcode)); printf("Format : %s\n", format); - zxing_free(format); + ZXing_free(format); - char* text = zxing_Barcode_text(barcode); + char* text = ZXing_Barcode_text(barcode); printf("Text : %s\n", text); - zxing_free(text); + ZXing_free(text); } - zxing_Barcodes_delete(barcodes); + ZXing_Barcodes_delete(barcodes); } else { - char* error = zxing_LastErrorMsg(); + char* error = ZXing_LastErrorMsg(); fprintf(stderr, "%s\n", error); - zxing_free(error); + ZXing_free(error); } return 0; diff --git a/wrappers/c/ZXingCTest.c b/wrappers/c/ZXingCTest.c new file mode 100644 index 0000000000..fd1b73def3 --- /dev/null +++ b/wrappers/c/ZXingCTest.c @@ -0,0 +1,108 @@ +/* +* Copyright 2023 siiky +* Copyright 2023 Axel Waggershauser +*/ +// SPDX-License-Identifier: Apache-2.0 + +#include "ZXingC.h" + +#include +#include + +#define STB_IMAGE_IMPLEMENTATION +#define STBI_NO_LINEAR // prevent dependency on -lm +#define STBI_NO_HDR +#include + +int usage(char* pname) +{ + fprintf(stderr, "Usage: %s FILE [FORMATS]\n", pname); + return 1; +} + +bool parse_args(int argc, char** argv, char** filename, ZXing_BarcodeFormats* formats) +{ + if (argc < 2) + return false; + *filename = argv[1]; + if (argc >= 3) { + *formats = ZXing_BarcodeFormatsFromString(argv[2]); + if (*formats == ZXing_BarcodeFormat_Invalid) { + fprintf(stderr, "%s\n", ZXing_LastErrorMsg()); + return false; + } + } + return true; +} + +void printF(const char* fmt, char* text) +{ + if (!text) + return; + if (*text) + printf(fmt, text); + ZXing_free(text); +} + +int main(int argc, char** argv) +{ + int ret = 0; + char* filename = NULL; + ZXing_BarcodeFormats formats = ZXing_BarcodeFormat_None; + + if (!parse_args(argc, argv, &filename, &formats)) + return usage(argv[0]); + + int width = 0; + int height = 0; + int channels = 0; + stbi_uc* data = stbi_load(filename, &width, &height, &channels, STBI_grey); + if (!data) { + fprintf(stderr, "Could not read image '%s'\n", filename); + return 2; + } + + ZXing_ReaderOptions* opts = ZXing_ReaderOptions_new(); + ZXing_ReaderOptions_setTextMode(opts, ZXing_TextMode_HRI); + ZXing_ReaderOptions_setEanAddOnSymbol(opts, ZXing_EanAddOnSymbol_Ignore); + ZXing_ReaderOptions_setFormats(opts, formats); + ZXing_ReaderOptions_setReturnErrors(opts, true); + + ZXing_ImageView* iv = ZXing_ImageView_new(data, width, height, ZXing_ImageFormat_Lum, 0, 0); + + ZXing_Barcodes* barcodes = ZXing_ReadBarcodes(iv, opts); + + ZXing_ImageView_delete(iv); + ZXing_ReaderOptions_delete(opts); + stbi_image_free(data); + + if (barcodes) { + for (int i = 0, n = ZXing_Barcodes_size(barcodes); i < n; ++i) { + const ZXing_Barcode* barcode = ZXing_Barcodes_at(barcodes, i); + + printF("Text : %s\n", ZXing_Barcode_text(barcode)); + printF("Format : %s\n", ZXing_BarcodeFormatToString(ZXing_Barcode_format(barcode))); + printF("Content : %s\n", ZXing_ContentTypeToString(ZXing_Barcode_contentType(barcode))); + printF("Identifier : %s\n", ZXing_Barcode_symbologyIdentifier(barcode)); + printF("EC Level : %s\n", ZXing_Barcode_ecLevel(barcode)); + printF("Error : %s\n", ZXing_Barcode_errorMsg(barcode)); + printF("Position : %s\n", ZXing_PositionToString(ZXing_Barcode_position(barcode))); + printf("Rotation : %d\n", ZXing_Barcode_orientation(barcode)); + + if (i < n-1) + printf("\n"); + } + + if (ZXing_Barcodes_size(barcodes) == 0) + printf("No barcode found\n"); + + ZXing_Barcodes_delete(barcodes); + } else { + char* error = ZXing_LastErrorMsg(); + fprintf(stderr, "%s\n", error); + ZXing_free(error); + ret = 2; + } + + return ret; +} diff --git a/wrappers/c/zxing-c-test.c b/wrappers/c/zxing-c-test.c deleted file mode 100644 index e5bef602c0..0000000000 --- a/wrappers/c/zxing-c-test.c +++ /dev/null @@ -1,108 +0,0 @@ -/* -* Copyright 2023 siiky -* Copyright 2023 Axel Waggershauser -*/ -// SPDX-License-Identifier: Apache-2.0 - -#include "zxing-c.h" - -#include -#include - -#define STB_IMAGE_IMPLEMENTATION -#define STBI_NO_LINEAR // prevent dependency on -lm -#define STBI_NO_HDR -#include - -int usage(char* pname) -{ - fprintf(stderr, "Usage: %s FILE [FORMATS]\n", pname); - return 1; -} - -bool parse_args(int argc, char** argv, char** filename, zxing_BarcodeFormats* formats) -{ - if (argc < 2) - return false; - *filename = argv[1]; - if (argc >= 3) { - *formats = zxing_BarcodeFormatsFromString(argv[2]); - if (*formats == zxing_BarcodeFormat_Invalid) { - fprintf(stderr, "%s\n", zxing_LastErrorMsg()); - return false; - } - } - return true; -} - -void printF(const char* fmt, char* text) -{ - if (!text) - return; - if (*text) - printf(fmt, text); - zxing_free(text); -} - -int main(int argc, char** argv) -{ - int ret = 0; - char* filename = NULL; - zxing_BarcodeFormats formats = zxing_BarcodeFormat_None; - - if (!parse_args(argc, argv, &filename, &formats)) - return usage(argv[0]); - - int width = 0; - int height = 0; - int channels = 0; - stbi_uc* data = stbi_load(filename, &width, &height, &channels, STBI_grey); - if (!data) { - fprintf(stderr, "Could not read image '%s'\n", filename); - return 2; - } - - zxing_ReaderOptions* opts = zxing_ReaderOptions_new(); - zxing_ReaderOptions_setTextMode(opts, zxing_TextMode_HRI); - zxing_ReaderOptions_setEanAddOnSymbol(opts, zxing_EanAddOnSymbol_Ignore); - zxing_ReaderOptions_setFormats(opts, formats); - zxing_ReaderOptions_setReturnErrors(opts, true); - - zxing_ImageView* iv = zxing_ImageView_new(data, width, height, zxing_ImageFormat_Lum, 0, 0); - - zxing_Barcodes* barcodes = zxing_ReadBarcodes(iv, opts); - - zxing_ImageView_delete(iv); - zxing_ReaderOptions_delete(opts); - stbi_image_free(data); - - if (barcodes) { - for (int i = 0, n = zxing_Barcodes_size(barcodes); i < n; ++i) { - const zxing_Barcode* barcode = zxing_Barcodes_at(barcodes, i); - - printF("Text : %s\n", zxing_Barcode_text(barcode)); - printF("Format : %s\n", zxing_BarcodeFormatToString(zxing_Barcode_format(barcode))); - printF("Content : %s\n", zxing_ContentTypeToString(zxing_Barcode_contentType(barcode))); - printF("Identifier : %s\n", zxing_Barcode_symbologyIdentifier(barcode)); - printF("EC Level : %s\n", zxing_Barcode_ecLevel(barcode)); - printF("Error : %s\n", zxing_Barcode_errorMsg(barcode)); - printF("Position : %s\n", zxing_PositionToString(zxing_Barcode_position(barcode))); - printf("Rotation : %d\n", zxing_Barcode_orientation(barcode)); - - if (i < n-1) - printf("\n"); - } - - if (zxing_Barcodes_size(barcodes) == 0) - printf("No barcode found\n"); - - zxing_Barcodes_delete(barcodes); - } else { - char* error = zxing_LastErrorMsg(); - fprintf(stderr, "%s\n", error); - zxing_free(error); - ret = 2; - } - - return ret; -} diff --git a/wrappers/dotnet/ZXingCpp/ZXingCpp.cs b/wrappers/dotnet/ZXingCpp/ZXingCpp.cs index 61545ceef3..a02081174c 100644 --- a/wrappers/dotnet/ZXingCpp/ZXingCpp.cs +++ b/wrappers/dotnet/ZXingCpp/ZXingCpp.cs @@ -16,65 +16,65 @@ internal class Dll { private const string DllName = "ZXing"; - [DllImport(DllName)] public static extern IntPtr zxing_ReaderOptions_new(); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_delete(IntPtr opts); - - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setTryHarder(IntPtr opts, bool tryHarder); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getTryHarder(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setTryRotate(IntPtr opts, bool tryRotate); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getTryRotate(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setTryInvert(IntPtr opts, bool tryInvert); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getTryInvert(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setTryDownscale(IntPtr opts, bool tryDownscale); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getTryDownscale(IntPtr opts); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getIsPure(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setIsPure(IntPtr opts, bool isPure); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setReturnErrors(IntPtr opts, bool returnErrors); - [DllImport(DllName)] public static extern bool zxing_ReaderOptions_getReturnErrors(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setFormats(IntPtr opts, BarcodeFormats formats); - [DllImport(DllName)] public static extern BarcodeFormats zxing_ReaderOptions_getFormats(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setBinarizer(IntPtr opts, Binarizer binarizer); - [DllImport(DllName)] public static extern Binarizer zxing_ReaderOptions_getBinarizer(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setEanAddOnSymbol(IntPtr opts, EanAddOnSymbol eanAddOnSymbol); - [DllImport(DllName)] public static extern EanAddOnSymbol zxing_ReaderOptions_getEanAddOnSymbol(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setTextMode(IntPtr opts, TextMode textMode); - [DllImport(DllName)] public static extern TextMode zxing_ReaderOptions_getTextMode(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setMinLineCount(IntPtr opts, int n); - [DllImport(DllName)] public static extern int zxing_ReaderOptions_getMinLineCount(IntPtr opts); - [DllImport(DllName)] public static extern void zxing_ReaderOptions_setMaxNumberOfSymbols(IntPtr opts, int n); - [DllImport(DllName)] public static extern int zxing_ReaderOptions_getMaxNumberOfSymbols(IntPtr opts); - - [DllImport(DllName)] public static extern IntPtr zxing_PositionToString(Position position); - [DllImport(DllName)] public static extern BarcodeFormats zxing_BarcodeFormatsFromString(string str); - - [DllImport(DllName)] public static extern IntPtr zxing_ImageView_new(IntPtr data, int width, int height, ImageFormat format, int rowStride, int pixStride); - [DllImport(DllName)] public static extern IntPtr zxing_ImageView_new_checked(byte[] data, int size, int width, int height, ImageFormat format, int rowStride, int pixStride); - [DllImport(DllName)] public static extern void zxing_ImageView_delete(IntPtr iv); - - [DllImport(DllName)] public static extern IntPtr zxing_ReadBarcodes(IntPtr iv, IntPtr opts); - [DllImport(DllName)] public static extern void zxing_Barcode_delete(IntPtr result); - [DllImport(DllName)] public static extern void zxing_Barcodes_delete(IntPtr results); - [DllImport(DllName)] public static extern int zxing_Barcodes_size(IntPtr results); - [DllImport(DllName)] public static extern IntPtr zxing_Barcodes_move(IntPtr results, int i); - - [DllImport(DllName)] public static extern bool zxing_Barcode_isValid(IntPtr result); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_errorMsg(IntPtr result); - [DllImport(DllName)] public static extern BarcodeFormat zxing_Barcode_format(IntPtr result); - [DllImport(DllName)] public static extern ContentType zxing_Barcode_contentType(IntPtr result); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_bytes(IntPtr result, out int len); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_bytesECI(IntPtr result, out int len); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_text(IntPtr result); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_ecLevel(IntPtr result); - [DllImport(DllName)] public static extern IntPtr zxing_Barcode_symbologyIdentifier(IntPtr result); - [DllImport(DllName)] public static extern Position zxing_Barcode_position(IntPtr result); - [DllImport(DllName)] public static extern int zxing_Barcode_orientation(IntPtr result); - [DllImport(DllName)] public static extern bool zxing_Barcode_hasECI(IntPtr result); - [DllImport(DllName)] public static extern bool zxing_Barcode_isInverted(IntPtr result); - [DllImport(DllName)] public static extern bool zxing_Barcode_isMirrored(IntPtr result); - [DllImport(DllName)] public static extern int zxing_Barcode_lineCount(IntPtr result); - - [DllImport(DllName)] public static extern void zxing_free(IntPtr opts); - [DllImport(DllName)] public static extern IntPtr zxing_LastErrorMsg(); + [DllImport(DllName)] public static extern IntPtr ZXing_ReaderOptions_new(); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_delete(IntPtr opts); + + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setTryHarder(IntPtr opts, bool tryHarder); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getTryHarder(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setTryRotate(IntPtr opts, bool tryRotate); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getTryRotate(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setTryInvert(IntPtr opts, bool tryInvert); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getTryInvert(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setTryDownscale(IntPtr opts, bool tryDownscale); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getTryDownscale(IntPtr opts); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getIsPure(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setIsPure(IntPtr opts, bool isPure); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setReturnErrors(IntPtr opts, bool returnErrors); + [DllImport(DllName)] public static extern bool ZXing_ReaderOptions_getReturnErrors(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setFormats(IntPtr opts, BarcodeFormats formats); + [DllImport(DllName)] public static extern BarcodeFormats ZXing_ReaderOptions_getFormats(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setBinarizer(IntPtr opts, Binarizer binarizer); + [DllImport(DllName)] public static extern Binarizer ZXing_ReaderOptions_getBinarizer(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setEanAddOnSymbol(IntPtr opts, EanAddOnSymbol eanAddOnSymbol); + [DllImport(DllName)] public static extern EanAddOnSymbol ZXing_ReaderOptions_getEanAddOnSymbol(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setTextMode(IntPtr opts, TextMode textMode); + [DllImport(DllName)] public static extern TextMode ZXing_ReaderOptions_getTextMode(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setMinLineCount(IntPtr opts, int n); + [DllImport(DllName)] public static extern int ZXing_ReaderOptions_getMinLineCount(IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_ReaderOptions_setMaxNumberOfSymbols(IntPtr opts, int n); + [DllImport(DllName)] public static extern int ZXing_ReaderOptions_getMaxNumberOfSymbols(IntPtr opts); + + [DllImport(DllName)] public static extern IntPtr ZXing_PositionToString(Position position); + [DllImport(DllName)] public static extern BarcodeFormats ZXing_BarcodeFormatsFromString(string str); + + [DllImport(DllName)] public static extern IntPtr ZXing_ImageView_new(IntPtr data, int width, int height, ImageFormat format, int rowStride, int pixStride); + [DllImport(DllName)] public static extern IntPtr ZXing_ImageView_new_checked(byte[] data, int size, int width, int height, ImageFormat format, int rowStride, int pixStride); + [DllImport(DllName)] public static extern void ZXing_ImageView_delete(IntPtr iv); + + [DllImport(DllName)] public static extern IntPtr ZXing_ReadBarcodes(IntPtr iv, IntPtr opts); + [DllImport(DllName)] public static extern void ZXing_Barcode_delete(IntPtr result); + [DllImport(DllName)] public static extern void ZXing_Barcodes_delete(IntPtr results); + [DllImport(DllName)] public static extern int ZXing_Barcodes_size(IntPtr results); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcodes_move(IntPtr results, int i); + + [DllImport(DllName)] public static extern bool ZXing_Barcode_isValid(IntPtr result); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_errorMsg(IntPtr result); + [DllImport(DllName)] public static extern BarcodeFormat ZXing_Barcode_format(IntPtr result); + [DllImport(DllName)] public static extern ContentType ZXing_Barcode_contentType(IntPtr result); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_bytes(IntPtr result, out int len); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_bytesECI(IntPtr result, out int len); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_text(IntPtr result); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_ecLevel(IntPtr result); + [DllImport(DllName)] public static extern IntPtr ZXing_Barcode_symbologyIdentifier(IntPtr result); + [DllImport(DllName)] public static extern Position ZXing_Barcode_position(IntPtr result); + [DllImport(DllName)] public static extern int ZXing_Barcode_orientation(IntPtr result); + [DllImport(DllName)] public static extern bool ZXing_Barcode_hasECI(IntPtr result); + [DllImport(DllName)] public static extern bool ZXing_Barcode_isInverted(IntPtr result); + [DllImport(DllName)] public static extern bool ZXing_Barcode_isMirrored(IntPtr result); + [DllImport(DllName)] public static extern int ZXing_Barcode_lineCount(IntPtr result); + + [DllImport(DllName)] public static extern void ZXing_free(IntPtr opts); + [DllImport(DllName)] public static extern IntPtr ZXing_LastErrorMsg(); public static string MarshalAsString(IntPtr ptr) @@ -83,7 +83,7 @@ public static string MarshalAsString(IntPtr ptr) throw new Exception("ZXing C-API returned a NULL char*."); string res = Marshal.PtrToStringUTF8(ptr) ?? ""; - zxing_free(ptr); + ZXing_free(ptr); return res; } @@ -97,7 +97,7 @@ public static byte[] MarshalAsBytes(RetBytesFunc func, IntPtr d) byte[] res = new byte[len]; Marshal.Copy(ptr, res, 0, len); - zxing_free(ptr); + ZXing_free(ptr); return res; } } @@ -178,7 +178,7 @@ public struct Position { public PointI TopLeft, TopRight, BottomRight, BottomLeft; - public override string ToString() => MarshalAsString(zxing_PositionToString(this)); + public override string ToString() => MarshalAsString(ZXing_PositionToString(this)); }; public class ImageView @@ -187,19 +187,19 @@ public class ImageView public ImageView(byte[] data, int width, int height, ImageFormat format, int rowStride = 0, int pixStride = 0) { - _d = zxing_ImageView_new_checked(data, data.Length, width, height, format, rowStride, pixStride); + _d = ZXing_ImageView_new_checked(data, data.Length, width, height, format, rowStride, pixStride); if (_d == IntPtr.Zero) - throw new Exception(MarshalAsString(zxing_LastErrorMsg())); + throw new Exception(MarshalAsString(ZXing_LastErrorMsg())); } public ImageView(IntPtr data, int width, int height, ImageFormat format, int rowStride = 0, int pixStride = 0) { - _d = zxing_ImageView_new(data, width, height, format, rowStride, pixStride); + _d = ZXing_ImageView_new(data, width, height, format, rowStride, pixStride); if (_d == IntPtr.Zero) - throw new Exception(MarshalAsString(zxing_LastErrorMsg())); + throw new Exception(MarshalAsString(ZXing_LastErrorMsg())); } - ~ImageView() => zxing_ImageView_delete(_d); + ~ImageView() => ZXing_ImageView_delete(_d); } public class ReaderOptions @@ -208,83 +208,83 @@ public class ReaderOptions public ReaderOptions() { - _d = zxing_ReaderOptions_new(); + _d = ZXing_ReaderOptions_new(); if (_d == IntPtr.Zero) throw new Exception("Failed to create ReaderOptions."); } - ~ReaderOptions() => zxing_ReaderOptions_delete(_d); + ~ReaderOptions() => ZXing_ReaderOptions_delete(_d); public bool TryHarder { - get => zxing_ReaderOptions_getTryHarder(_d); - set => zxing_ReaderOptions_setTryHarder(_d, value); + get => ZXing_ReaderOptions_getTryHarder(_d); + set => ZXing_ReaderOptions_setTryHarder(_d, value); } public bool TryRotate { - get => zxing_ReaderOptions_getTryRotate(_d); - set => zxing_ReaderOptions_setTryRotate(_d, value); + get => ZXing_ReaderOptions_getTryRotate(_d); + set => ZXing_ReaderOptions_setTryRotate(_d, value); } public bool TryInvert { - get => zxing_ReaderOptions_getTryInvert(_d); - set => zxing_ReaderOptions_setTryInvert(_d, value); + get => ZXing_ReaderOptions_getTryInvert(_d); + set => ZXing_ReaderOptions_setTryInvert(_d, value); } public bool TryDownscale { - get => zxing_ReaderOptions_getTryDownscale(_d); - set => zxing_ReaderOptions_setTryDownscale(_d, value); + get => ZXing_ReaderOptions_getTryDownscale(_d); + set => ZXing_ReaderOptions_setTryDownscale(_d, value); } public bool IsPure { - get => zxing_ReaderOptions_getIsPure(_d); - set => zxing_ReaderOptions_setIsPure(_d, value); + get => ZXing_ReaderOptions_getIsPure(_d); + set => ZXing_ReaderOptions_setIsPure(_d, value); } public bool ReturnErrors { - get => zxing_ReaderOptions_getReturnErrors(_d); - set => zxing_ReaderOptions_setReturnErrors(_d, value); + get => ZXing_ReaderOptions_getReturnErrors(_d); + set => ZXing_ReaderOptions_setReturnErrors(_d, value); } public BarcodeFormats Formats { - get => zxing_ReaderOptions_getFormats(_d); - set => zxing_ReaderOptions_setFormats(_d, value); + get => ZXing_ReaderOptions_getFormats(_d); + set => ZXing_ReaderOptions_setFormats(_d, value); } public Binarizer Binarizer { - get => zxing_ReaderOptions_getBinarizer(_d); - set => zxing_ReaderOptions_setBinarizer(_d, value); + get => ZXing_ReaderOptions_getBinarizer(_d); + set => ZXing_ReaderOptions_setBinarizer(_d, value); } public EanAddOnSymbol EanAddOnSymbol { - get => zxing_ReaderOptions_getEanAddOnSymbol(_d); - set => zxing_ReaderOptions_setEanAddOnSymbol(_d, value); + get => ZXing_ReaderOptions_getEanAddOnSymbol(_d); + set => ZXing_ReaderOptions_setEanAddOnSymbol(_d, value); } public TextMode TextMode { - get => zxing_ReaderOptions_getTextMode(_d); - set => zxing_ReaderOptions_setTextMode(_d, value); + get => ZXing_ReaderOptions_getTextMode(_d); + set => ZXing_ReaderOptions_setTextMode(_d, value); } public int MinLineCount { - get => zxing_ReaderOptions_getMinLineCount(_d); - set => zxing_ReaderOptions_setMinLineCount(_d, value); + get => ZXing_ReaderOptions_getMinLineCount(_d); + set => ZXing_ReaderOptions_setMinLineCount(_d, value); } public int MaxNumberOfSymbols { - get => zxing_ReaderOptions_getMaxNumberOfSymbols(_d); - set => zxing_ReaderOptions_setMaxNumberOfSymbols(_d, value); + get => ZXing_ReaderOptions_getMaxNumberOfSymbols(_d); + set => ZXing_ReaderOptions_setMaxNumberOfSymbols(_d, value); } } @@ -294,46 +294,46 @@ public class Barcode internal IntPtr _d; internal Barcode(IntPtr d) => _d = d; - ~Barcode() => zxing_Barcode_delete(_d); - - public bool IsValid => zxing_Barcode_isValid(_d); - public BarcodeFormat Format => zxing_Barcode_format(_d); - public ContentType ContentType => zxing_Barcode_contentType(_d); - public string Text => MarshalAsString(zxing_Barcode_text(_d)); - public byte[] Bytes => MarshalAsBytes(zxing_Barcode_bytes, _d); - public byte[] BytesECI => MarshalAsBytes(zxing_Barcode_bytesECI, _d); - public string ECLevel => MarshalAsString(zxing_Barcode_ecLevel(_d)); - public string SymbologyIdentifier => MarshalAsString(zxing_Barcode_symbologyIdentifier(_d)); - public string ErrorMsg => MarshalAsString(zxing_Barcode_errorMsg(_d)); - public Position Position => zxing_Barcode_position(_d); - public int Orientation => zxing_Barcode_orientation(_d); - public bool HasECI => zxing_Barcode_hasECI(_d); - public bool IsInverted => zxing_Barcode_isInverted(_d); - public bool IsMirrored => zxing_Barcode_isMirrored(_d); - public int LineCount => zxing_Barcode_lineCount(_d); + ~Barcode() => ZXing_Barcode_delete(_d); + + public bool IsValid => ZXing_Barcode_isValid(_d); + public BarcodeFormat Format => ZXing_Barcode_format(_d); + public ContentType ContentType => ZXing_Barcode_contentType(_d); + public string Text => MarshalAsString(ZXing_Barcode_text(_d)); + public byte[] Bytes => MarshalAsBytes(ZXing_Barcode_bytes, _d); + public byte[] BytesECI => MarshalAsBytes(ZXing_Barcode_bytesECI, _d); + public string ECLevel => MarshalAsString(ZXing_Barcode_ecLevel(_d)); + public string SymbologyIdentifier => MarshalAsString(ZXing_Barcode_symbologyIdentifier(_d)); + public string ErrorMsg => MarshalAsString(ZXing_Barcode_errorMsg(_d)); + public Position Position => ZXing_Barcode_position(_d); + public int Orientation => ZXing_Barcode_orientation(_d); + public bool HasECI => ZXing_Barcode_hasECI(_d); + public bool IsInverted => ZXing_Barcode_isInverted(_d); + public bool IsMirrored => ZXing_Barcode_isMirrored(_d); + public int LineCount => ZXing_Barcode_lineCount(_d); } public class BarcodeReader : ReaderOptions { public static BarcodeFormats FormatsFromString(string str) { - var fmts = zxing_BarcodeFormatsFromString(str); - if ((int)fmts == -1) // see zxing_BarcodeFormat_Invalid - throw new Exception(MarshalAsString(zxing_LastErrorMsg())); + var fmts = ZXing_BarcodeFormatsFromString(str); + if ((int)fmts == -1) // see ZXing_BarcodeFormat_Invalid + throw new Exception(MarshalAsString(ZXing_LastErrorMsg())); return fmts; } public static List Read(ImageView iv, ReaderOptions? opts = null) { - var ptr = zxing_ReadBarcodes(iv._d, opts?._d ?? IntPtr.Zero); + var ptr = ZXing_ReadBarcodes(iv._d, opts?._d ?? IntPtr.Zero); if (ptr == IntPtr.Zero) - throw new Exception(MarshalAsString(zxing_LastErrorMsg())); + throw new Exception(MarshalAsString(ZXing_LastErrorMsg())); - var size = zxing_Barcodes_size(ptr); + var size = ZXing_Barcodes_size(ptr); var res = new List(size); for (int i = 0; i < size; ++i) - res.Add(new Barcode(zxing_Barcodes_move(ptr, i))); - zxing_Barcodes_delete(ptr); + res.Add(new Barcode(ZXing_Barcodes_move(ptr, i))); + ZXing_Barcodes_delete(ptr); return res; } diff --git a/wrappers/rust/build.rs b/wrappers/rust/build.rs index 6d754a58d6..8f43f3a1be 100644 --- a/wrappers/rust/build.rs +++ b/wrappers/rust/build.rs @@ -29,7 +29,7 @@ fn main() -> miette::Result<()> { } // manual bindings.rs generation: - // bindgen core/src/zxing-c.h -o src/bindings.rs --no-prepend-enum-name --merge-extern-blocks --use-core --no-doc-comments --no-layout-tests --with-derive-partialeq --allowlist-item "zxing.*" + // bindgen core/src/ZXingC.h -o src/bindings.rs --no-prepend-enum-name --merge-extern-blocks --use-core --no-doc-comments --no-layout-tests --with-derive-partialeq --allowlist-item "ZXing.*" Ok(()) } diff --git a/wrappers/rust/src/bindings.rs b/wrappers/rust/src/bindings.rs index 52e659b622..00a465a6c8 100644 --- a/wrappers/rust/src/bindings.rs +++ b/wrappers/rust/src/bindings.rs @@ -2,175 +2,175 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct zxing_ImageView { +pub struct ZXing_ImageView { _unused: [u8; 0], } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct zxing_ReaderOptions { +pub struct ZXing_ReaderOptions { _unused: [u8; 0], } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct zxing_Barcode { +pub struct ZXing_Barcode { _unused: [u8; 0], } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct zxing_Barcodes { +pub struct ZXing_Barcodes { _unused: [u8; 0], } -pub const zxing_ImageFormat_None: zxing_ImageFormat = 0; -pub const zxing_ImageFormat_Lum: zxing_ImageFormat = 16777216; -pub const zxing_ImageFormat_RGB: zxing_ImageFormat = 50331906; -pub const zxing_ImageFormat_BGR: zxing_ImageFormat = 50462976; -pub const zxing_ImageFormat_RGBX: zxing_ImageFormat = 67109122; -pub const zxing_ImageFormat_XRGB: zxing_ImageFormat = 67174915; -pub const zxing_ImageFormat_BGRX: zxing_ImageFormat = 67240192; -pub const zxing_ImageFormat_XBGR: zxing_ImageFormat = 67305985; -pub type zxing_ImageFormat = ::core::ffi::c_uint; -pub const zxing_BarcodeFormat_None: zxing_BarcodeFormat = 0; -pub const zxing_BarcodeFormat_Aztec: zxing_BarcodeFormat = 1; -pub const zxing_BarcodeFormat_Codabar: zxing_BarcodeFormat = 2; -pub const zxing_BarcodeFormat_Code39: zxing_BarcodeFormat = 4; -pub const zxing_BarcodeFormat_Code93: zxing_BarcodeFormat = 8; -pub const zxing_BarcodeFormat_Code128: zxing_BarcodeFormat = 16; -pub const zxing_BarcodeFormat_DataBar: zxing_BarcodeFormat = 32; -pub const zxing_BarcodeFormat_DataBarExpanded: zxing_BarcodeFormat = 64; -pub const zxing_BarcodeFormat_DataMatrix: zxing_BarcodeFormat = 128; -pub const zxing_BarcodeFormat_EAN8: zxing_BarcodeFormat = 256; -pub const zxing_BarcodeFormat_EAN13: zxing_BarcodeFormat = 512; -pub const zxing_BarcodeFormat_ITF: zxing_BarcodeFormat = 1024; -pub const zxing_BarcodeFormat_MaxiCode: zxing_BarcodeFormat = 2048; -pub const zxing_BarcodeFormat_PDF417: zxing_BarcodeFormat = 4096; -pub const zxing_BarcodeFormat_QRCode: zxing_BarcodeFormat = 8192; -pub const zxing_BarcodeFormat_UPCA: zxing_BarcodeFormat = 16384; -pub const zxing_BarcodeFormat_UPCE: zxing_BarcodeFormat = 32768; -pub const zxing_BarcodeFormat_MicroQRCode: zxing_BarcodeFormat = 65536; -pub const zxing_BarcodeFormat_RMQRCode: zxing_BarcodeFormat = 131072; -pub const zxing_BarcodeFormat_DXFilmEdge: zxing_BarcodeFormat = 262144; -pub const zxing_BarcodeFormat_LinearCodes: zxing_BarcodeFormat = 313214; -pub const zxing_BarcodeFormat_MatrixCodes: zxing_BarcodeFormat = 211073; -pub const zxing_BarcodeFormat_Any: zxing_BarcodeFormat = 524287; -pub const zxing_BarcodeFormat_Invalid: zxing_BarcodeFormat = 4294967295; -pub type zxing_BarcodeFormat = ::core::ffi::c_uint; -pub use self::zxing_BarcodeFormat as zxing_BarcodeFormats; -pub const zxing_Binarizer_LocalAverage: zxing_Binarizer = 0; -pub const zxing_Binarizer_GlobalHistogram: zxing_Binarizer = 1; -pub const zxing_Binarizer_FixedThreshold: zxing_Binarizer = 2; -pub const zxing_Binarizer_BoolCast: zxing_Binarizer = 3; -pub type zxing_Binarizer = ::core::ffi::c_uint; -pub const zxing_EanAddOnSymbol_Ignore: zxing_EanAddOnSymbol = 0; -pub const zxing_EanAddOnSymbol_Read: zxing_EanAddOnSymbol = 1; -pub const zxing_EanAddOnSymbol_Require: zxing_EanAddOnSymbol = 2; -pub type zxing_EanAddOnSymbol = ::core::ffi::c_uint; -pub const zxing_TextMode_Plain: zxing_TextMode = 0; -pub const zxing_TextMode_ECI: zxing_TextMode = 1; -pub const zxing_TextMode_HRI: zxing_TextMode = 2; -pub const zxing_TextMode_Hex: zxing_TextMode = 3; -pub const zxing_TextMode_Escaped: zxing_TextMode = 4; -pub type zxing_TextMode = ::core::ffi::c_uint; -pub const zxing_ContentType_Text: zxing_ContentType = 0; -pub const zxing_ContentType_Binary: zxing_ContentType = 1; -pub const zxing_ContentType_Mixed: zxing_ContentType = 2; -pub const zxing_ContentType_GS1: zxing_ContentType = 3; -pub const zxing_ContentType_ISO15434: zxing_ContentType = 4; -pub const zxing_ContentType_UnknownECI: zxing_ContentType = 5; -pub type zxing_ContentType = ::core::ffi::c_uint; +pub const ZXing_ImageFormat_None: ZXing_ImageFormat = 0; +pub const ZXing_ImageFormat_Lum: ZXing_ImageFormat = 16777216; +pub const ZXing_ImageFormat_RGB: ZXing_ImageFormat = 50331906; +pub const ZXing_ImageFormat_BGR: ZXing_ImageFormat = 50462976; +pub const ZXing_ImageFormat_RGBX: ZXing_ImageFormat = 67109122; +pub const ZXing_ImageFormat_XRGB: ZXing_ImageFormat = 67174915; +pub const ZXing_ImageFormat_BGRX: ZXing_ImageFormat = 67240192; +pub const ZXing_ImageFormat_XBGR: ZXing_ImageFormat = 67305985; +pub type ZXing_ImageFormat = ::core::ffi::c_uint; +pub const ZXing_BarcodeFormat_None: ZXing_BarcodeFormat = 0; +pub const ZXing_BarcodeFormat_Aztec: ZXing_BarcodeFormat = 1; +pub const ZXing_BarcodeFormat_Codabar: ZXing_BarcodeFormat = 2; +pub const ZXing_BarcodeFormat_Code39: ZXing_BarcodeFormat = 4; +pub const ZXing_BarcodeFormat_Code93: ZXing_BarcodeFormat = 8; +pub const ZXing_BarcodeFormat_Code128: ZXing_BarcodeFormat = 16; +pub const ZXing_BarcodeFormat_DataBar: ZXing_BarcodeFormat = 32; +pub const ZXing_BarcodeFormat_DataBarExpanded: ZXing_BarcodeFormat = 64; +pub const ZXing_BarcodeFormat_DataMatrix: ZXing_BarcodeFormat = 128; +pub const ZXing_BarcodeFormat_EAN8: ZXing_BarcodeFormat = 256; +pub const ZXing_BarcodeFormat_EAN13: ZXing_BarcodeFormat = 512; +pub const ZXing_BarcodeFormat_ITF: ZXing_BarcodeFormat = 1024; +pub const ZXing_BarcodeFormat_MaxiCode: ZXing_BarcodeFormat = 2048; +pub const ZXing_BarcodeFormat_PDF417: ZXing_BarcodeFormat = 4096; +pub const ZXing_BarcodeFormat_QRCode: ZXing_BarcodeFormat = 8192; +pub const ZXing_BarcodeFormat_UPCA: ZXing_BarcodeFormat = 16384; +pub const ZXing_BarcodeFormat_UPCE: ZXing_BarcodeFormat = 32768; +pub const ZXing_BarcodeFormat_MicroQRCode: ZXing_BarcodeFormat = 65536; +pub const ZXing_BarcodeFormat_RMQRCode: ZXing_BarcodeFormat = 131072; +pub const ZXing_BarcodeFormat_DXFilmEdge: ZXing_BarcodeFormat = 262144; +pub const ZXing_BarcodeFormat_LinearCodes: ZXing_BarcodeFormat = 313214; +pub const ZXing_BarcodeFormat_MatrixCodes: ZXing_BarcodeFormat = 211073; +pub const ZXing_BarcodeFormat_Any: ZXing_BarcodeFormat = 524287; +pub const ZXing_BarcodeFormat_Invalid: ZXing_BarcodeFormat = 4294967295; +pub type ZXing_BarcodeFormat = ::core::ffi::c_uint; +pub use self::ZXing_BarcodeFormat as ZXing_BarcodeFormats; +pub const ZXing_Binarizer_LocalAverage: ZXing_Binarizer = 0; +pub const ZXing_Binarizer_GlobalHistogram: ZXing_Binarizer = 1; +pub const ZXing_Binarizer_FixedThreshold: ZXing_Binarizer = 2; +pub const ZXing_Binarizer_BoolCast: ZXing_Binarizer = 3; +pub type ZXing_Binarizer = ::core::ffi::c_uint; +pub const ZXing_EanAddOnSymbol_Ignore: ZXing_EanAddOnSymbol = 0; +pub const ZXing_EanAddOnSymbol_Read: ZXing_EanAddOnSymbol = 1; +pub const ZXing_EanAddOnSymbol_Require: ZXing_EanAddOnSymbol = 2; +pub type ZXing_EanAddOnSymbol = ::core::ffi::c_uint; +pub const ZXing_TextMode_Plain: ZXing_TextMode = 0; +pub const ZXing_TextMode_ECI: ZXing_TextMode = 1; +pub const ZXing_TextMode_HRI: ZXing_TextMode = 2; +pub const ZXing_TextMode_Hex: ZXing_TextMode = 3; +pub const ZXing_TextMode_Escaped: ZXing_TextMode = 4; +pub type ZXing_TextMode = ::core::ffi::c_uint; +pub const ZXing_ContentType_Text: ZXing_ContentType = 0; +pub const ZXing_ContentType_Binary: ZXing_ContentType = 1; +pub const ZXing_ContentType_Mixed: ZXing_ContentType = 2; +pub const ZXing_ContentType_GS1: ZXing_ContentType = 3; +pub const ZXing_ContentType_ISO15434: ZXing_ContentType = 4; +pub const ZXing_ContentType_UnknownECI: ZXing_ContentType = 5; +pub type ZXing_ContentType = ::core::ffi::c_uint; #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq)] -pub struct zxing_PointI { +pub struct ZXing_PointI { pub x: ::core::ffi::c_int, pub y: ::core::ffi::c_int, } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq)] -pub struct zxing_Position { - pub topLeft: zxing_PointI, - pub topRight: zxing_PointI, - pub bottomRight: zxing_PointI, - pub bottomLeft: zxing_PointI, +pub struct ZXing_Position { + pub topLeft: ZXing_PointI, + pub topRight: ZXing_PointI, + pub bottomRight: ZXing_PointI, + pub bottomLeft: ZXing_PointI, } extern "C" { - pub fn zxing_ImageView_new( + pub fn ZXing_ImageView_new( data: *const u8, width: ::core::ffi::c_int, height: ::core::ffi::c_int, - format: zxing_ImageFormat, + format: ZXing_ImageFormat, rowStride: ::core::ffi::c_int, pixStride: ::core::ffi::c_int, - ) -> *mut zxing_ImageView; - pub fn zxing_ImageView_new_checked( + ) -> *mut ZXing_ImageView; + pub fn ZXing_ImageView_new_checked( data: *const u8, size: ::core::ffi::c_int, width: ::core::ffi::c_int, height: ::core::ffi::c_int, - format: zxing_ImageFormat, + format: ZXing_ImageFormat, rowStride: ::core::ffi::c_int, pixStride: ::core::ffi::c_int, - ) -> *mut zxing_ImageView; - pub fn zxing_ImageView_delete(iv: *mut zxing_ImageView); - pub fn zxing_ImageView_crop( - iv: *mut zxing_ImageView, + ) -> *mut ZXing_ImageView; + pub fn ZXing_ImageView_delete(iv: *mut ZXing_ImageView); + pub fn ZXing_ImageView_crop( + iv: *mut ZXing_ImageView, left: ::core::ffi::c_int, top: ::core::ffi::c_int, width: ::core::ffi::c_int, height: ::core::ffi::c_int, ); - pub fn zxing_ImageView_rotate(iv: *mut zxing_ImageView, degree: ::core::ffi::c_int); - pub fn zxing_BarcodeFormatsFromString(str_: *const ::core::ffi::c_char) -> zxing_BarcodeFormats; - pub fn zxing_BarcodeFormatFromString(str_: *const ::core::ffi::c_char) -> zxing_BarcodeFormat; - pub fn zxing_BarcodeFormatToString(format: zxing_BarcodeFormat) -> *mut ::core::ffi::c_char; - pub fn zxing_ReaderOptions_new() -> *mut zxing_ReaderOptions; - pub fn zxing_ReaderOptions_delete(opts: *mut zxing_ReaderOptions); - pub fn zxing_ReaderOptions_setTryHarder(opts: *mut zxing_ReaderOptions, tryHarder: bool); - pub fn zxing_ReaderOptions_setTryRotate(opts: *mut zxing_ReaderOptions, tryRotate: bool); - pub fn zxing_ReaderOptions_setTryInvert(opts: *mut zxing_ReaderOptions, tryInvert: bool); - pub fn zxing_ReaderOptions_setTryDownscale(opts: *mut zxing_ReaderOptions, tryDownscale: bool); - pub fn zxing_ReaderOptions_setIsPure(opts: *mut zxing_ReaderOptions, isPure: bool); - pub fn zxing_ReaderOptions_setReturnErrors(opts: *mut zxing_ReaderOptions, returnErrors: bool); - pub fn zxing_ReaderOptions_setFormats(opts: *mut zxing_ReaderOptions, formats: zxing_BarcodeFormats); - pub fn zxing_ReaderOptions_setBinarizer(opts: *mut zxing_ReaderOptions, binarizer: zxing_Binarizer); - pub fn zxing_ReaderOptions_setEanAddOnSymbol(opts: *mut zxing_ReaderOptions, eanAddOnSymbol: zxing_EanAddOnSymbol); - pub fn zxing_ReaderOptions_setTextMode(opts: *mut zxing_ReaderOptions, textMode: zxing_TextMode); - pub fn zxing_ReaderOptions_setMinLineCount(opts: *mut zxing_ReaderOptions, n: ::core::ffi::c_int); - pub fn zxing_ReaderOptions_setMaxNumberOfSymbols(opts: *mut zxing_ReaderOptions, n: ::core::ffi::c_int); - pub fn zxing_ReaderOptions_getTryHarder(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getTryRotate(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getTryInvert(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getTryDownscale(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getIsPure(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getReturnErrors(opts: *const zxing_ReaderOptions) -> bool; - pub fn zxing_ReaderOptions_getFormats(opts: *const zxing_ReaderOptions) -> zxing_BarcodeFormats; - pub fn zxing_ReaderOptions_getBinarizer(opts: *const zxing_ReaderOptions) -> zxing_Binarizer; - pub fn zxing_ReaderOptions_getEanAddOnSymbol(opts: *const zxing_ReaderOptions) -> zxing_EanAddOnSymbol; - pub fn zxing_ReaderOptions_getTextMode(opts: *const zxing_ReaderOptions) -> zxing_TextMode; - pub fn zxing_ReaderOptions_getMinLineCount(opts: *const zxing_ReaderOptions) -> ::core::ffi::c_int; - pub fn zxing_ReaderOptions_getMaxNumberOfSymbols(opts: *const zxing_ReaderOptions) -> ::core::ffi::c_int; - pub fn zxing_ContentTypeToString(type_: zxing_ContentType) -> *mut ::core::ffi::c_char; - pub fn zxing_PositionToString(position: zxing_Position) -> *mut ::core::ffi::c_char; - pub fn zxing_Barcode_isValid(barcode: *const zxing_Barcode) -> bool; - pub fn zxing_Barcode_errorMsg(barcode: *const zxing_Barcode) -> *mut ::core::ffi::c_char; - pub fn zxing_Barcode_format(barcode: *const zxing_Barcode) -> zxing_BarcodeFormat; - pub fn zxing_Barcode_contentType(barcode: *const zxing_Barcode) -> zxing_ContentType; - pub fn zxing_Barcode_bytes(barcode: *const zxing_Barcode, len: *mut ::core::ffi::c_int) -> *mut u8; - pub fn zxing_Barcode_bytesECI(barcode: *const zxing_Barcode, len: *mut ::core::ffi::c_int) -> *mut u8; - pub fn zxing_Barcode_text(barcode: *const zxing_Barcode) -> *mut ::core::ffi::c_char; - pub fn zxing_Barcode_ecLevel(barcode: *const zxing_Barcode) -> *mut ::core::ffi::c_char; - pub fn zxing_Barcode_symbologyIdentifier(barcode: *const zxing_Barcode) -> *mut ::core::ffi::c_char; - pub fn zxing_Barcode_position(barcode: *const zxing_Barcode) -> zxing_Position; - pub fn zxing_Barcode_orientation(barcode: *const zxing_Barcode) -> ::core::ffi::c_int; - pub fn zxing_Barcode_hasECI(barcode: *const zxing_Barcode) -> bool; - pub fn zxing_Barcode_isInverted(barcode: *const zxing_Barcode) -> bool; - pub fn zxing_Barcode_isMirrored(barcode: *const zxing_Barcode) -> bool; - pub fn zxing_Barcode_lineCount(barcode: *const zxing_Barcode) -> ::core::ffi::c_int; - pub fn zxing_ReadBarcode(iv: *const zxing_ImageView, opts: *const zxing_ReaderOptions) -> *mut zxing_Barcode; - pub fn zxing_ReadBarcodes(iv: *const zxing_ImageView, opts: *const zxing_ReaderOptions) -> *mut zxing_Barcodes; - pub fn zxing_Barcode_delete(barcode: *mut zxing_Barcode); - pub fn zxing_Barcodes_delete(barcodes: *mut zxing_Barcodes); - pub fn zxing_Barcodes_size(barcodes: *const zxing_Barcodes) -> ::core::ffi::c_int; - pub fn zxing_Barcodes_at(barcodes: *const zxing_Barcodes, i: ::core::ffi::c_int) -> *const zxing_Barcode; - pub fn zxing_Barcodes_move(barcodes: *mut zxing_Barcodes, i: ::core::ffi::c_int) -> *mut zxing_Barcode; - pub fn zxing_LastErrorMsg() -> *mut ::core::ffi::c_char; - pub fn zxing_free(ptr: *mut ::core::ffi::c_void); + pub fn ZXing_ImageView_rotate(iv: *mut ZXing_ImageView, degree: ::core::ffi::c_int); + pub fn ZXing_BarcodeFormatsFromString(str_: *const ::core::ffi::c_char) -> ZXing_BarcodeFormats; + pub fn ZXing_BarcodeFormatFromString(str_: *const ::core::ffi::c_char) -> ZXing_BarcodeFormat; + pub fn ZXing_BarcodeFormatToString(format: ZXing_BarcodeFormat) -> *mut ::core::ffi::c_char; + pub fn ZXing_ReaderOptions_new() -> *mut ZXing_ReaderOptions; + pub fn ZXing_ReaderOptions_delete(opts: *mut ZXing_ReaderOptions); + pub fn ZXing_ReaderOptions_setTryHarder(opts: *mut ZXing_ReaderOptions, tryHarder: bool); + pub fn ZXing_ReaderOptions_setTryRotate(opts: *mut ZXing_ReaderOptions, tryRotate: bool); + pub fn ZXing_ReaderOptions_setTryInvert(opts: *mut ZXing_ReaderOptions, tryInvert: bool); + pub fn ZXing_ReaderOptions_setTryDownscale(opts: *mut ZXing_ReaderOptions, tryDownscale: bool); + pub fn ZXing_ReaderOptions_setIsPure(opts: *mut ZXing_ReaderOptions, isPure: bool); + pub fn ZXing_ReaderOptions_setReturnErrors(opts: *mut ZXing_ReaderOptions, returnErrors: bool); + pub fn ZXing_ReaderOptions_setFormats(opts: *mut ZXing_ReaderOptions, formats: ZXing_BarcodeFormats); + pub fn ZXing_ReaderOptions_setBinarizer(opts: *mut ZXing_ReaderOptions, binarizer: ZXing_Binarizer); + pub fn ZXing_ReaderOptions_setEanAddOnSymbol(opts: *mut ZXing_ReaderOptions, eanAddOnSymbol: ZXing_EanAddOnSymbol); + pub fn ZXing_ReaderOptions_setTextMode(opts: *mut ZXing_ReaderOptions, textMode: ZXing_TextMode); + pub fn ZXing_ReaderOptions_setMinLineCount(opts: *mut ZXing_ReaderOptions, n: ::core::ffi::c_int); + pub fn ZXing_ReaderOptions_setMaxNumberOfSymbols(opts: *mut ZXing_ReaderOptions, n: ::core::ffi::c_int); + pub fn ZXing_ReaderOptions_getTryHarder(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getTryRotate(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getTryInvert(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getTryDownscale(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getIsPure(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getReturnErrors(opts: *const ZXing_ReaderOptions) -> bool; + pub fn ZXing_ReaderOptions_getFormats(opts: *const ZXing_ReaderOptions) -> ZXing_BarcodeFormats; + pub fn ZXing_ReaderOptions_getBinarizer(opts: *const ZXing_ReaderOptions) -> ZXing_Binarizer; + pub fn ZXing_ReaderOptions_getEanAddOnSymbol(opts: *const ZXing_ReaderOptions) -> ZXing_EanAddOnSymbol; + pub fn ZXing_ReaderOptions_getTextMode(opts: *const ZXing_ReaderOptions) -> ZXing_TextMode; + pub fn ZXing_ReaderOptions_getMinLineCount(opts: *const ZXing_ReaderOptions) -> ::core::ffi::c_int; + pub fn ZXing_ReaderOptions_getMaxNumberOfSymbols(opts: *const ZXing_ReaderOptions) -> ::core::ffi::c_int; + pub fn ZXing_ContentTypeToString(type_: ZXing_ContentType) -> *mut ::core::ffi::c_char; + pub fn ZXing_PositionToString(position: ZXing_Position) -> *mut ::core::ffi::c_char; + pub fn ZXing_Barcode_isValid(barcode: *const ZXing_Barcode) -> bool; + pub fn ZXing_Barcode_errorMsg(barcode: *const ZXing_Barcode) -> *mut ::core::ffi::c_char; + pub fn ZXing_Barcode_format(barcode: *const ZXing_Barcode) -> ZXing_BarcodeFormat; + pub fn ZXing_Barcode_contentType(barcode: *const ZXing_Barcode) -> ZXing_ContentType; + pub fn ZXing_Barcode_bytes(barcode: *const ZXing_Barcode, len: *mut ::core::ffi::c_int) -> *mut u8; + pub fn ZXing_Barcode_bytesECI(barcode: *const ZXing_Barcode, len: *mut ::core::ffi::c_int) -> *mut u8; + pub fn ZXing_Barcode_text(barcode: *const ZXing_Barcode) -> *mut ::core::ffi::c_char; + pub fn ZXing_Barcode_ecLevel(barcode: *const ZXing_Barcode) -> *mut ::core::ffi::c_char; + pub fn ZXing_Barcode_symbologyIdentifier(barcode: *const ZXing_Barcode) -> *mut ::core::ffi::c_char; + pub fn ZXing_Barcode_position(barcode: *const ZXing_Barcode) -> ZXing_Position; + pub fn ZXing_Barcode_orientation(barcode: *const ZXing_Barcode) -> ::core::ffi::c_int; + pub fn ZXing_Barcode_hasECI(barcode: *const ZXing_Barcode) -> bool; + pub fn ZXing_Barcode_isInverted(barcode: *const ZXing_Barcode) -> bool; + pub fn ZXing_Barcode_isMirrored(barcode: *const ZXing_Barcode) -> bool; + pub fn ZXing_Barcode_lineCount(barcode: *const ZXing_Barcode) -> ::core::ffi::c_int; + pub fn ZXing_ReadBarcode(iv: *const ZXing_ImageView, opts: *const ZXing_ReaderOptions) -> *mut ZXing_Barcode; + pub fn ZXing_ReadBarcodes(iv: *const ZXing_ImageView, opts: *const ZXing_ReaderOptions) -> *mut ZXing_Barcodes; + pub fn ZXing_Barcode_delete(barcode: *mut ZXing_Barcode); + pub fn ZXing_Barcodes_delete(barcodes: *mut ZXing_Barcodes); + pub fn ZXing_Barcodes_size(barcodes: *const ZXing_Barcodes) -> ::core::ffi::c_int; + pub fn ZXing_Barcodes_at(barcodes: *const ZXing_Barcodes, i: ::core::ffi::c_int) -> *const ZXing_Barcode; + pub fn ZXing_Barcodes_move(barcodes: *mut ZXing_Barcodes, i: ::core::ffi::c_int) -> *mut ZXing_Barcode; + pub fn ZXing_LastErrorMsg() -> *mut ::core::ffi::c_char; + pub fn ZXing_free(ptr: *mut ::core::ffi::c_void); } diff --git a/wrappers/rust/src/lib.rs b/wrappers/rust/src/lib.rs index 9df557eff9..95af608812 100644 --- a/wrappers/rust/src/lib.rs +++ b/wrappers/rust/src/lib.rs @@ -60,7 +60,7 @@ fn c2r_str(str: *mut c_char) -> String { let mut res = String::new(); if !str.is_null() { unsafe { res = CStr::from_ptr(str).to_string_lossy().to_string() }; - unsafe { zxing_free(str as *mut c_void) }; + unsafe { ZXing_free(str as *mut c_void) }; } res } @@ -69,21 +69,21 @@ fn c2r_vec(buf: *mut u8, len: c_int) -> Vec { let mut res = Vec::::new(); if !buf.is_null() && len > 0 { unsafe { res = std::slice::from_raw_parts(buf, len as usize).to_vec() }; - unsafe { zxing_free(buf as *mut c_void) }; + unsafe { ZXing_free(buf as *mut c_void) }; } res } fn last_error() -> Error { - match unsafe { zxing_LastErrorMsg().as_mut() } { - None => panic!("Internal error: zxing_LastErrorMsg() returned NULL"), + match unsafe { ZXing_LastErrorMsg().as_mut() } { + None => panic!("Internal error: ZXing_LastErrorMsg() returned NULL"), Some(error) => Error::InvalidInput(c2r_str(error)), } } macro_rules! last_error_or { ($expr:expr) => { - match unsafe { zxing_LastErrorMsg().as_mut() } { + match unsafe { ZXing_LastErrorMsg().as_mut() } { None => Ok($expr), Some(error) => Err(Error::InvalidInput(c2r_str(error))), } @@ -95,7 +95,7 @@ macro_rules! make_zxing_enum { #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq)] pub enum $name { - $($field = paste! { [] },)* + $($field = paste! { [] },)* } } } @@ -105,7 +105,7 @@ macro_rules! make_zxing_flags { flags! { #[repr(u32)] pub enum $name: c_uint { - $($field = paste! { [] },)* + $($field = paste! { [] },)* } } } @@ -131,22 +131,22 @@ pub type BarcodeFormats = FlagSet; impl Display for BarcodeFormat { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", unsafe { c2r_str(zxing_BarcodeFormatToString(BarcodeFormats::from(*self).bits())) }) + write!(f, "{}", unsafe { c2r_str(ZXing_BarcodeFormatToString(BarcodeFormats::from(*self).bits())) }) } } impl Display for ContentType { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", unsafe { c2r_str(zxing_ContentTypeToString(transmute(*self))) }) + write!(f, "{}", unsafe { c2r_str(ZXing_ContentTypeToString(transmute(*self))) }) } } #[derive(Debug, PartialEq)] -struct ImageViewOwner<'a>(*mut zxing_ImageView, PhantomData<&'a u8>); +struct ImageViewOwner<'a>(*mut ZXing_ImageView, PhantomData<&'a u8>); impl Drop for ImageViewOwner<'_> { fn drop(&mut self) { - unsafe { zxing_ImageView_delete(self.0) } + unsafe { ZXing_ImageView_delete(self.0) } } } #[derive(Debug, Clone, PartialEq)] @@ -180,11 +180,11 @@ impl<'a> ImageView<'a> { row_stride: U, pix_stride: U, ) -> Result { - let iv = zxing_ImageView_new( + let iv = ZXing_ImageView_new( ptr, Self::try_into_int(width)?, Self::try_into_int(height)?, - format as zxing_ImageFormat, + format as ZXing_ImageFormat, Self::try_into_int(row_stride)?, Self::try_into_int(pix_stride)?, ); @@ -197,12 +197,12 @@ impl<'a> ImageView<'a> { pub fn from_slice>(data: &'a [u8], width: T, height: T, format: ImageFormat) -> Result { unsafe { - let iv = zxing_ImageView_new_checked( + let iv = ZXing_ImageView_new_checked( data.as_ptr(), data.len() as c_int, Self::try_into_int(width)?, Self::try_into_int(height)?, - format as zxing_ImageFormat, + format as ZXing_ImageFormat, 0, 0, ); @@ -215,12 +215,12 @@ impl<'a> ImageView<'a> { } pub fn cropped(self, left: i32, top: i32, width: i32, height: i32) -> Self { - unsafe { zxing_ImageView_crop((self.0).0, left, top, width, height) } + unsafe { ZXing_ImageView_crop((self.0).0, left, top, width, height) } self } pub fn rotated(self, degree: i32) -> Self { - unsafe { zxing_ImageView_rotate((self.0).0, degree) } + unsafe { ZXing_ImageView_rotate((self.0).0, degree) } self } } @@ -253,11 +253,11 @@ impl<'a> TryFrom<&'a image::DynamicImage> for ImageView<'a> { } } -pub struct ReaderOptions(*mut zxing_ReaderOptions); +pub struct ReaderOptions(*mut ZXing_ReaderOptions); impl Drop for ReaderOptions { fn drop(&mut self) { - unsafe { zxing_ReaderOptions_delete(self.0) } + unsafe { ZXing_ReaderOptions_delete(self.0) } } } @@ -276,18 +276,18 @@ impl AsRef for ReaderOptions { macro_rules! property { ($name:ident, $type:ty) => { pub fn $name(self, v: impl Into<$type>) -> Self { - paste! { unsafe { [](self.0, transmute(v.into())) } }; + paste! { unsafe { [](self.0, transmute(v.into())) } }; self } paste! { pub fn [](&mut self, v : impl Into<$type>) -> &mut Self { - unsafe { [](self.0, transmute(v.into())) }; + unsafe { [](self.0, transmute(v.into())) }; self } pub fn [](&self) -> $type { - unsafe { transmute([](self.0)) } + unsafe { transmute([](self.0)) } } } }; @@ -295,7 +295,7 @@ macro_rules! property { impl ReaderOptions { pub fn new() -> Self { - unsafe { ReaderOptions(zxing_ReaderOptions_new()) } + unsafe { ReaderOptions(ZXing_ReaderOptions_new()) } } property!(try_harder, bool); @@ -312,15 +312,15 @@ impl ReaderOptions { property!(min_line_count, i32); } -pub struct Barcode(*mut zxing_Barcode); +pub struct Barcode(*mut ZXing_Barcode); impl Drop for Barcode { fn drop(&mut self) { - unsafe { zxing_Barcode_delete(self.0) } + unsafe { ZXing_Barcode_delete(self.0) } } } -pub type PointI = zxing_PointI; +pub type PointI = ZXing_PointI; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Position { @@ -339,7 +339,7 @@ impl Display for PointI { impl Display for Position { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", unsafe { - c2r_str(zxing_PositionToString(*(self as *const Position as *const zxing_Position))) + c2r_str(ZXing_PositionToString(*(self as *const Position as *const ZXing_Position))) }) } } @@ -347,7 +347,7 @@ impl Display for Position { macro_rules! getter { ($r_name:ident, $c_name:ident, $conv:expr, $type:ty) => { pub fn $r_name(&self) -> $type { - paste! { unsafe { $conv([](self.0)) } } + paste! { unsafe { $conv([](self.0)) } } } }; } @@ -369,17 +369,17 @@ impl Barcode { pub fn bytes(&self) -> Vec { let mut len: c_int = 0; - unsafe { c2r_vec(zxing_Barcode_bytes(self.0, &mut len), len) } + unsafe { c2r_vec(ZXing_Barcode_bytes(self.0, &mut len), len) } } pub fn bytes_eci(&self) -> Vec { let mut len: c_int = 0; - unsafe { c2r_vec(zxing_Barcode_bytesECI(self.0, &mut len), len) } + unsafe { c2r_vec(ZXing_Barcode_bytesECI(self.0, &mut len), len) } } } pub fn barcode_formats_from_string(str: impl AsRef) -> Result { let cstr = CString::new(str.as_ref())?; - let res = unsafe { BarcodeFormats::new_unchecked(zxing_BarcodeFormatsFromString(cstr.as_ptr())) }; + let res = unsafe { BarcodeFormats::new_unchecked(ZXing_BarcodeFormatsFromString(cstr.as_ptr())) }; match res.bits() { u32::MAX => last_error_or!(BarcodeFormats::default()), 0 => Ok(BarcodeFormats::full()), @@ -395,14 +395,14 @@ where { let iv_: ImageView = image.try_into().map_err(Into::into)?; unsafe { - let results = zxing_ReadBarcodes((iv_.0).0, opts.as_ref().0); + let results = ZXing_ReadBarcodes((iv_.0).0, opts.as_ref().0); if !results.is_null() { - let size = zxing_Barcodes_size(results); + let size = ZXing_Barcodes_size(results); let mut vec = Vec::::with_capacity(size as usize); for i in 0..size { - vec.push(Barcode(zxing_Barcodes_move(results, i))); + vec.push(Barcode(ZXing_Barcodes_move(results, i))); } - zxing_Barcodes_delete(results); + ZXing_Barcodes_delete(results); Ok(vec) } else { Err(last_error())