Browse Source

barcodes scanning is now works

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
ee47fc114c
  1. 4
      ios/Classes/src/native_zxing.cpp
  2. 8
      ios/Classes/src/native_zxing.h
  3. 8
      lib/flutter_zxing.dart
  4. 15
      lib/generated_bindings.dart

4
ios/Classes/src/native_zxing.cpp

@ -55,7 +55,7 @@ extern "C"
}
FUNCTION_ATTRIBUTE
struct CodeResult* readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled)
struct CodeResults readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled)
{
long long start = get_now();
@ -98,7 +98,7 @@ extern "C"
{
platform_log("zxingRead: %d ms", evalInMillis);
}
return codes;
return {i, codes};
}
FUNCTION_ATTRIBUTE

8
ios/Classes/src/native_zxing.h

@ -35,6 +35,12 @@ extern "C"
enum Format format;
};
struct CodeResults
{
int count;
struct CodeResult* results;
};
struct EncodeResult
{
int isValid;
@ -76,7 +82,7 @@ extern "C"
* @param logEnabled Log enabled.
* @return Barcode results.
*/
struct CodeResult* readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled);
struct CodeResults readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled);
/**
* @brief Encode a string into a barcode

8
lib/flutter_zxing.dart

@ -6,7 +6,6 @@ import 'dart:typed_data';
import 'package:camera/camera.dart';
import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:image/image.dart' as imglib;
@ -118,8 +117,11 @@ class FlutterZxing {
int height, int cropWidth, int cropHeight) {
final result = bindings.readBarcodes(bytes.allocatePointer(), format, width,
height, cropWidth, cropHeight, _logEnabled);
debugPrint(result.toString());
return [];
List<CodeResult> results = [];
for (int i = 0; i < result.count; i++) {
results.add(result.results.elementAt(i).ref);
}
return results;
}
static EncodeResult encodeBarcode(String contents, int width, int height,

15
lib/generated_bindings.dart

@ -77,7 +77,7 @@ class GeneratedBindings {
/// @param cropHeight Crop height.
/// @param logEnabled Log enabled.
/// @return Barcode results.
ffi.Pointer<CodeResult> readBarcodes(
CodeResults readBarcodes(
ffi.Pointer<ffi.Char> bytes,
int format,
int width,
@ -99,10 +99,10 @@ class GeneratedBindings {
late final _readBarcodesPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CodeResult> Function(ffi.Pointer<ffi.Char>, ffi.Int,
ffi.Int, ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes');
CodeResults Function(ffi.Pointer<ffi.Char>, ffi.Int, ffi.Int, ffi.Int,
ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes');
late final _readBarcodes = _readBarcodesPtr.asFunction<
ffi.Pointer<CodeResult> Function(
CodeResults Function(
ffi.Pointer<ffi.Char>, int, int, int, int, int, int)>();
/// @brief Encode a string into a barcode
@ -209,6 +209,13 @@ class CodeResult extends ffi.Struct {
external int format;
}
class CodeResults extends ffi.Struct {
@ffi.Int()
external int count;
external ffi.Pointer<CodeResult> results;
}
class EncodeResult extends ffi.Struct {
@ffi.Int()
external int isValid;

Loading…
Cancel
Save