mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
stubbing new reader / multireader
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
mod data_mask;
|
||||
pub mod decoder;
|
||||
pub mod detector;
|
||||
mod qr_cpp_reader;
|
||||
|
||||
pub use qr_cpp_reader::QrReader;
|
||||
|
||||
mod bitmatrix_parser;
|
||||
|
||||
272
src/qrcode/cpp_port/qr_cpp_reader.rs
Normal file
272
src/qrcode/cpp_port/qr_cpp_reader.rs
Normal file
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright 2016 Nu-book Inc.
|
||||
* Copyright 2016 ZXing authors
|
||||
* Copyright 2022 Axel Waggershauser
|
||||
*/
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// #include "QRReader.h"
|
||||
|
||||
// #include "BinaryBitmap.h"
|
||||
// #include "ConcentricFinder.h"
|
||||
// #include "DecodeHints.h"
|
||||
// #include "DecoderResult.h"
|
||||
// #include "DetectorResult.h"
|
||||
// #include "LogMatrix.h"
|
||||
// #include "QRDecoder.h"
|
||||
// #include "QRDetector.h"
|
||||
// #include "Result.h"
|
||||
|
||||
// #include <utility>
|
||||
|
||||
// namespace ZXing::QRCode {
|
||||
|
||||
// Result Reader::decode(const BinaryBitmap& image) const
|
||||
// {
|
||||
// #if 1
|
||||
// if (!_hints.isPure())
|
||||
// return FirstOrDefault(decode(image, 1));
|
||||
// #endif
|
||||
|
||||
// auto binImg = image.getBitMatrix();
|
||||
// if (binImg == nullptr)
|
||||
// return {};
|
||||
|
||||
// DetectorResult detectorResult;
|
||||
// if (_hints.hasFormat(BarcodeFormat::QRCode))
|
||||
// detectorResult = DetectPureQR(*binImg);
|
||||
// if (_hints.hasFormat(BarcodeFormat::MicroQRCode) && !detectorResult.isValid())
|
||||
// detectorResult = DetectPureMQR(*binImg);
|
||||
|
||||
// if (!detectorResult.isValid())
|
||||
// return {};
|
||||
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
|
||||
// return Result(std::move(decoderResult), std::move(position),
|
||||
// detectorResult.bits().width() < 21 ? BarcodeFormat::MicroQRCode : BarcodeFormat::QRCode);
|
||||
// }
|
||||
|
||||
// void logFPSet(const FinderPatternSet& fps [[maybe_unused]])
|
||||
// {
|
||||
// #ifdef PRINT_DEBUG
|
||||
// auto drawLine = [](PointF a, PointF b) {
|
||||
// int steps = maxAbsComponent(b - a);
|
||||
// PointF dir = bresenhamDirection(PointF(b - a));
|
||||
// for (int i = 0; i < steps; ++i)
|
||||
// log(centered(a + i * dir), 2);
|
||||
// };
|
||||
|
||||
// drawLine(fps.bl, fps.tl);
|
||||
// drawLine(fps.tl, fps.tr);
|
||||
// drawLine(fps.tr, fps.bl);
|
||||
// #endif
|
||||
// }
|
||||
|
||||
// Results Reader::decode(const BinaryBitmap& image, int maxSymbols) const
|
||||
// {
|
||||
// auto binImg = image.getBitMatrix();
|
||||
// if (binImg == nullptr)
|
||||
// return {};
|
||||
|
||||
// #ifdef PRINT_DEBUG
|
||||
// LogMatrixWriter lmw(log, *binImg, 5, "qr-log.pnm");
|
||||
// #endif
|
||||
|
||||
// auto allFPs = FindFinderPatterns(*binImg, _hints.tryHarder());
|
||||
|
||||
// #ifdef PRINT_DEBUG
|
||||
// printf("allFPs: %d\n", Size(allFPs));
|
||||
// #endif
|
||||
|
||||
// std::vector<ConcentricPattern> usedFPs;
|
||||
// Results results;
|
||||
|
||||
// if (_hints.hasFormat(BarcodeFormat::QRCode)) {
|
||||
// auto allFPSets = GenerateFinderPatternSets(allFPs);
|
||||
// for (const auto& fpSet : allFPSets) {
|
||||
// if (Contains(usedFPs, fpSet.bl) || Contains(usedFPs, fpSet.tl) || Contains(usedFPs, fpSet.tr))
|
||||
// continue;
|
||||
|
||||
// logFPSet(fpSet);
|
||||
|
||||
// auto detectorResult = SampleQR(*binImg, fpSet);
|
||||
// if (detectorResult.isValid()) {
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
// if (decoderResult.isValid()) {
|
||||
// usedFPs.push_back(fpSet.bl);
|
||||
// usedFPs.push_back(fpSet.tl);
|
||||
// usedFPs.push_back(fpSet.tr);
|
||||
// }
|
||||
// if (decoderResult.isValid(_hints.returnErrors())) {
|
||||
// results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::QRCode);
|
||||
// if (maxSymbols && Size(results) == maxSymbols)
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (_hints.hasFormat(BarcodeFormat::MicroQRCode) && !(maxSymbols && Size(results) == maxSymbols)) {
|
||||
// for (const auto& fp : allFPs) {
|
||||
// if (Contains(usedFPs, fp))
|
||||
// continue;
|
||||
|
||||
// auto detectorResult = SampleMQR(*binImg, fp);
|
||||
// if (detectorResult.isValid()) {
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
// if (decoderResult.isValid(_hints.returnErrors())) {
|
||||
// results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::MicroQRCode);
|
||||
// if (maxSymbols && Size(results) == maxSymbols)
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return results;
|
||||
// }
|
||||
|
||||
// } // namespace ZXing::QRCode
|
||||
|
||||
|
||||
use crate::{Reader, DecodingHintDictionary, multi::MultipleBarcodeReader};
|
||||
|
||||
pub struct QrReader{}
|
||||
|
||||
impl Reader for QrReader {
|
||||
fn decode<B: crate::Binarizer>(&mut self, image: &mut crate::BinaryBitmap<B>) -> crate::common::Result<crate::RXingResult> {
|
||||
self.decode_with_hints(image, &DecodingHintDictionary::new())
|
||||
}
|
||||
|
||||
fn decode_with_hints<B: crate::Binarizer>(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap<B>,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> crate::common::Result<crate::RXingResult> {
|
||||
todo!()
|
||||
// #if 1
|
||||
// if (!_hints.isPure())
|
||||
// return FirstOrDefault(decode(image, 1));
|
||||
// #endif
|
||||
|
||||
// auto binImg = image.getBitMatrix();
|
||||
// if (binImg == nullptr)
|
||||
// return {};
|
||||
|
||||
// DetectorResult detectorResult;
|
||||
// if (_hints.hasFormat(BarcodeFormat::QRCode))
|
||||
// detectorResult = DetectPureQR(*binImg);
|
||||
// if (_hints.hasFormat(BarcodeFormat::MicroQRCode) && !detectorResult.isValid())
|
||||
// detectorResult = DetectPureMQR(*binImg);
|
||||
|
||||
// if (!detectorResult.isValid())
|
||||
// return {};
|
||||
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
|
||||
// return Result(std::move(decoderResult), std::move(position),
|
||||
// detectorResult.bits().width() < 21 ? BarcodeFormat::MicroQRCode : BarcodeFormat::QRCode);
|
||||
// }
|
||||
|
||||
// void logFPSet(const FinderPatternSet& fps [[maybe_unused]])
|
||||
// {
|
||||
// #ifdef PRINT_DEBUG
|
||||
// auto drawLine = [](PointF a, PointF b) {
|
||||
// int steps = maxAbsComponent(b - a);
|
||||
// PointF dir = bresenhamDirection(PointF(b - a));
|
||||
// for (int i = 0; i < steps; ++i)
|
||||
// log(centered(a + i * dir), 2);
|
||||
// };
|
||||
|
||||
// drawLine(fps.bl, fps.tl);
|
||||
// drawLine(fps.tl, fps.tr);
|
||||
// drawLine(fps.tr, fps.bl);
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
impl MultipleBarcodeReader for QrReader {
|
||||
fn decode_multiple<B: crate::Binarizer>(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap<B>,
|
||||
) -> crate::common::Result<Vec<crate::RXingResult>> {
|
||||
self.decode_multiple_with_hints(image, &DecodingHintDictionary::new())
|
||||
}
|
||||
|
||||
fn decode_multiple_with_hints<B: crate::Binarizer>(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap<B>,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> crate::common::Result<Vec<crate::RXingResult>> {
|
||||
todo!()
|
||||
// auto binImg = image.getBitMatrix();
|
||||
// if (binImg == nullptr)
|
||||
// return {};
|
||||
|
||||
// #ifdef PRINT_DEBUG
|
||||
// LogMatrixWriter lmw(log, *binImg, 5, "qr-log.pnm");
|
||||
// #endif
|
||||
|
||||
// auto allFPs = FindFinderPatterns(*binImg, _hints.tryHarder());
|
||||
|
||||
// #ifdef PRINT_DEBUG
|
||||
// printf("allFPs: %d\n", Size(allFPs));
|
||||
// #endif
|
||||
|
||||
// std::vector<ConcentricPattern> usedFPs;
|
||||
// Results results;
|
||||
|
||||
// if (_hints.hasFormat(BarcodeFormat::QRCode)) {
|
||||
// auto allFPSets = GenerateFinderPatternSets(allFPs);
|
||||
// for (const auto& fpSet : allFPSets) {
|
||||
// if (Contains(usedFPs, fpSet.bl) || Contains(usedFPs, fpSet.tl) || Contains(usedFPs, fpSet.tr))
|
||||
// continue;
|
||||
|
||||
// logFPSet(fpSet);
|
||||
|
||||
// auto detectorResult = SampleQR(*binImg, fpSet);
|
||||
// if (detectorResult.isValid()) {
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
// if (decoderResult.isValid()) {
|
||||
// usedFPs.push_back(fpSet.bl);
|
||||
// usedFPs.push_back(fpSet.tl);
|
||||
// usedFPs.push_back(fpSet.tr);
|
||||
// }
|
||||
// if (decoderResult.isValid(_hints.returnErrors())) {
|
||||
// results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::QRCode);
|
||||
// if (maxSymbols && Size(results) == maxSymbols)
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (_hints.hasFormat(BarcodeFormat::MicroQRCode) && !(maxSymbols && Size(results) == maxSymbols)) {
|
||||
// for (const auto& fp : allFPs) {
|
||||
// if (Contains(usedFPs, fp))
|
||||
// continue;
|
||||
|
||||
// auto detectorResult = SampleMQR(*binImg, fp);
|
||||
// if (detectorResult.isValid()) {
|
||||
// auto decoderResult = Decode(detectorResult.bits());
|
||||
// auto position = detectorResult.position();
|
||||
// if (decoderResult.isValid(_hints.returnErrors())) {
|
||||
// results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::MicroQRCode);
|
||||
// if (maxSymbols && Size(results) == maxSymbols)
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user