From 7010089d3b3bc5e11f850ba2e404a9fb37b1ff33 Mon Sep 17 00:00:00 2001 From: Chorbier Date: Tue, 28 Oct 2025 06:49:37 +0500 Subject: [PATCH] fnc1 raw bytes fix --- core/src/Content.h | 1 + core/src/Result.cpp | 18 ++++++++++++++++ core/src/Result.h | 5 +++++ core/src/datamatrix/DMDecoder.cpp | 34 +++++++++++++++---------------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/core/src/Content.h b/core/src/Content.h index 501f89d5b7..475189da88 100644 --- a/core/src/Content.h +++ b/core/src/Content.h @@ -52,6 +52,7 @@ class Content SymbologyIdentifier symbology; CharacterSet defaultCharset = CharacterSet::Unknown; bool hasECI = false; + std::vector fncPositions; Content(); Content(ByteArray&& bytes, SymbologyIdentifier si); diff --git a/core/src/Result.cpp b/core/src/Result.cpp index 7739b3cd09..ac09a449d7 100644 --- a/core/src/Result.cpp +++ b/core/src/Result.cpp @@ -52,6 +52,24 @@ const ByteArray& Result::bytes() const return _content.bytes; } +ByteArray Result::bytesFNCFix() const +{ + auto& fncPos = _content.fncPositions; + if(fncPos.empty()) { + return ByteArray(_content.bytes); + } + ByteArray newBytes(_content.bytes.size() - fncPos.size() * 5); + size_t a = 0, i = 0; + for(size_t b : fncPos){ + std::copy(&_content.bytes[a], &_content.bytes[b], &newBytes[i]); + i+=b-a; + newBytes[i++] = 232; + a = b + 6; + } + std::copy(&_content.bytes[a], &_content.bytes[_content.bytes.size()], &newBytes[i]); + return newBytes; +} + ByteArray Result::bytesECI() const { return _content.bytesECI(); diff --git a/core/src/Result.h b/core/src/Result.h index ddd0b6c183..322180db92 100644 --- a/core/src/Result.h +++ b/core/src/Result.h @@ -60,6 +60,11 @@ class Result */ const ByteArray& bytes() const; + /** + * @brief bytes is the raw / standard content without any modifications like character set conversions + */ + ByteArray bytesFNCFix() const; + /** * @brief bytesECI is the raw / standard content following the ECI protocol */ diff --git a/core/src/datamatrix/DMDecoder.cpp b/core/src/datamatrix/DMDecoder.cpp index 142a2b6960..a50b36b0fe 100644 --- a/core/src/datamatrix/DMDecoder.cpp +++ b/core/src/datamatrix/DMDecoder.cpp @@ -168,6 +168,8 @@ static void DecodeC40OrTextSegment(BitSource& bits, Content& result, Mode mode) case 2: if (cValue < 28) // Size(SHIFT_SET_CHARS)) if (SHIFT_SET_CHARS[cValue] == (char)29) { + // result.push_back(232); + result.fncPositions.push_back(result.bytes.size()); result.push_back((char)'{'); result.push_back((char)'F'); result.push_back((char)'N'); @@ -295,7 +297,7 @@ DecoderResult Decode(ByteArray&& bytes, const bool isDMRE) bool readerInit = false; bool firstCodeword = true; bool done = false; - int firstFNC1Position = 1; + // int firstFNC1Position = 1; Shift128 upperShift; // See ISO 16022:2006, 5.2.3 and Annex C, Table C.2 @@ -314,25 +316,21 @@ DecoderResult Decode(ByteArray&& bytes, const bool isDMRE) // Only recognizing an FNC1 as first/second by codeword position (aka symbol character position), not // by decoded character position, i.e. not recognizing a C40/Text encoded FNC1 (which requires a latch // and a shift) - if (bits.byteOffset() == firstFNC1Position) - { - result.push_back((char)'{'); - result.push_back((char)'F'); - result.push_back((char)'N'); - result.push_back((char)'C'); - result.push_back((char)'1'); - result.push_back((char)'}'); - break; - } - //result.symbology.modifier = '2'; // GS1 + // if (bits.byteOffset() == firstFNC1Position) + // result.symbology.modifier = '2'; // GS1 // else if (bits.byteOffset() == firstFNC1Position + 1) // result.symbology.modifier = '3'; // AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2 - else - { - result.push_back((char)29); // translate as ASCII 29 - break; - } - + // else + // result.push_back((char)29); // translate as ASCII 29 + // result.push_back(232); + result.fncPositions.push_back(result.bytes.size()); + result.push_back((char)'{'); + result.push_back((char)'F'); + result.push_back((char)'N'); + result.push_back((char)'C'); + result.push_back((char)'1'); + result.push_back((char)'}'); + break; case 233: // Structured Append if (!firstCodeword) // Must be first ISO 16022:2006 5.6.1 throw FormatError("structured append tag must be first code word");