Skip to content

Remove legacy OneToFourBitPattern function from Code93 decoder #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wooyechan
Copy link

@wooyechan wooyechan commented Jun 30, 2025

This PR removes the OneToFourBitPattern function, which was part of the legacy Code93 decoding logic.

Code93 now consistently uses NormalizedE2EPattern, instead of OneToFourBitPattern.
Removing this helps simplify the code and reduce technical debt.

Key changes:

  • Replaced all usage of OneToFourBitPattern with the standardized NormalizedE2EPattern approach, already used across other symbologies.
  • Introduced new files to isolate and manage Code93 pattern data:
    • ODCode93Patterns.cpp: Contains the CODE_PATTERNS definition for Code93.
    • ODCode93Patterns.h: Corresponding header for pattern definitions.

Modified files:

  • ODCode93Reader.cpp: Removed OneToFourBitPattern, updated decoding logic to use NormalizedE2EPattern.
  • ODMultiUPCEANReader.cpp: Removed residual mentions of OneToFourBitPattern from an unused/dead code path in DecodeDigit. This was done for cleanup and consistency.
  • ODRowReader.h: Removed OneToFourBitPattern, which is no more needed.
  • core/CMakeLists.txt: Added the new ODCode93Patterns files to the build.

Please review the changes and let me know if further adjustments are needed.

Thank you.

Copy link
Collaborator

@axxel axxel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much. If you feel like improving this PR, please see my comments. I thought about changing the constexpr part inside the Code128 decoder as a reference first, but I don't have the time right now.


namespace ZXing::OneD::Code93 {

const std::array<std::array<int, 6>, 48> CODE_PATTERNS = { {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see this in the header and making it constexpr.

0x11A, 0x158, 0x14C, 0x146, 0x12C, 0x116, 0x1B4, 0x1B2, 0x1AC, 0x1A6, // K-T
0x196, 0x19A, 0x16C, 0x166, 0x136, 0x13A, // U-Z
0x12E, 0x1D4, 0x1D2, 0x1CA, 0x16E, 0x176, 0x1AE, // - - %
0x126, 0x1DA, 0x1D6, 0x132, 0x15E, // Control chars ($)==a, (%)==b, (/)==c, (+)==d, *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving the comment regarding the control characters would be nice.

0x126, 0x1DA, 0x1D6, 0x132, 0x15E, // Control chars ($)==a, (%)==b, (/)==c, (+)==d, *
};

static_assert(Size(ALPHABET) == Size(CHARACTER_ENCODINGS), "table size mismatch");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static_assert should also be preserved.

// quiet zone is half the width of a character symbol
constexpr float QUIET_ZONE_SCALE = 0.5f;

//TODO: make this a constexpr variable initialization
static auto E2E_PATTERNS = [ ] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to implement this TODO (see also comment above)?

@@ -99,9 +95,13 @@ Barcode Code93Reader::decodePattern(int rowNumber, PatternView& next, std::uniqu
if (!next.skipSymbol())
return {};

txt += LookupBitPattern(OneToFourBitPattern<CHAR_LEN, CHAR_SUM>(next), CHARACTER_ENCODINGS, ALPHABET);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LookupBitPattern helper use could very well stay.

@@ -62,46 +61,6 @@ static bool DecodeDigit(const PatternView& view, std::string& txt, int* lgPatter
AppendBit(*lgPattern, bestMatch >= 10);

return true;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this disabled code alone. It might be useful as documentation in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants