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

Merged
merged 6 commits into from
Jul 2, 2025

Conversation

wooyechan
Copy link
Contributor

@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.

// 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)?

@@ -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.

@wooyechan
Copy link
Contributor Author

Thank you for the feedback. I’ve applied all your suggestions except for making E2E_PATTERNS a constexpr. The reason is that ToInt is currently used in the computation, which makes it difficult to convert directly under the current structure.

While it's possible to work around this by rewriting the logic differently, or by manually declaring all patterns as done in CODE_PATTERNS, I wasn't sure which approach you'd prefer. Also, I’m currently tied up with other tasks, so I couldn’t find the time to implement either option at the moment.

Apologies for postponing that part, and please feel free to share any further thoughts on the current changes.

@@ -8,7 +8,7 @@

namespace ZXing::OneD::Code128 {

const std::array<std::array<int, 6>, 107> CODE_PATTERNS = { {
constexpr std::array<std::array<int, 6>, 107> 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.

Please leave the Code128 part as is for now.


namespace ZXing::OneD::Code93 {

constexpr 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.

Here I meant move the definition of the variable into the header and drop the cpp-file completely. I'm not sure that adding constexpr at this location changes anything at all.

@wooyechan wooyechan requested a review from axxel July 2, 2025 07:26
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.

I added 3 single comments an hour ago. Is there anything else, you'd like to see from me?

@wooyechan
Copy link
Contributor Author

Sorry about that. I accidentally clicked it.. :'( I’ll push the updated changes very soon.

@wooyechan
Copy link
Contributor Author

I’ve made the requested changes. I’m truly sorry if my lack of experience caused any unnecessary trouble or wasted your valuable time.

@wooyechan wooyechan requested a review from axxel July 2, 2025 08:08
@axxel axxel merged commit 7f9702e into zxing-cpp:master Jul 2, 2025
18 checks passed
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