Implement preprocessing pipeline with addBorder preprocessor
- [x] Understand the issue: Barcodes without whitespace around them fail to decode
- [x] Explore codebase to understand image processing flow
- [x] Run build and tests to establish baseline
- [x] Plan architecture: Create preprocessing layer between frame grab and localization
- [x] Implement preprocessing infrastructure
- [x] Create preprocessor interface/types
- [x] Create addBorder preprocessor as first implementation
- [x] Integrate preprocessing into quagga update loop
- [x] Fix ImageWrapper type definition mismatch (inImageWithBorder signature)
- [x] Update type definitions for new config options
- [x] Add unit tests for preprocessing (8 tests)
- [x] Add integration test with real barcode from issue (2 tests)
- [x] Verified barcode fails to decode without preprocessor
- [x] Verified barcode decodes successfully with addBorder(20) preprocessor
- [x] Run code review and address feedback
- [x] Use Uint8Array constructor for copying data
- [x] Use fill() method for TypedArray when available
- [x] Run codeql_checker (no alerts)
- [x] Address PR feedback:
- [x] Remove sharp dependency (was added for test image creation but not used)
- [x] Rename
PreprocessorFunctiontoQuaggaImagePreprocessorfor clearer public API - [x] Update documentation to clarify in-place modification requirement for performance
- [x] Add comment explaining index.ts is a barrel file for public API exports
- [x] Add preprocessing tests to Cypress browser test suites (integration.cy.ts and universal.cy.ts)
- [x] Simplify redundant conditional in preprocessor.ts (reviewer suggestion)
- [x] Rename config option from
preprocessingtopreprocessors(nouns not verbs) - [x] Fix Cypress test path - add leading slash for browser environment (matches other integration tests)
- [x] Move comprehensive documentation to /docs following Divio system
- [x] Add Divio documentation system guidelines to copilot-instructions.md
- [x] Clarify singleChannel config in algorithm-overview.md
- [x] Add overlay canvas visualization section to use-preprocessors.md
Original prompt
This section details on the original issue you should resolve
<issue_title>Unable to read long code_128 barcodes</issue_title> <issue_description>Hello,
My scanner cant read this barcode, that I generated with code-128 on https://barcode.tec-it.com/ with
300003999047081900000000978000Could you please help me ?My configuration may be wrong, but I cant find where.</issue_description>
<agent_instructions>can you look into the possibility of https://github.com/ericblade/quagga2/issues/409#issuecomment-1100645491
particularly the part of if it's feasible to assume that if you're given an image, that one might process it as if area around it is whitespace? in the particular case, I was given a barcode that had zero pixels of whitespace around it, which is technically invalid, but you'd never have that in the real world, because you'd be displaying it on something that would have whitespace, a display or paper, or something. So, could we possibly somehow automatically add like 5 pixels of white border to every image on all sides? does that make sense? commentary only, let's not write code until we have a plan. </agent_instructions>
Comments on the Issue (you are @copilot in this section)
@ericblade Hi all! I've never attempted to use it with such lengthy barcodes, but I can have a look and see if I see anything obvious.The Invalid asm.js is probably not an issue related to it specifically, I think there's something occasionally wrong with some generated code that I inherited, and don't entirely understand. :| It seems to scan correctly despite those errors occurring sometimes.
@ericblade @samedro.. if you could provide configuration, that might be helpful for figuring out what's not working. This works with the default settings of using code_128, resolution 800px, patch-size medium
@ericblade > I am having same issue with long barcodes for example this: > >  > > 439393900039990260001000000000000000000000123123220412. Any ideas?@drodil There is absolutely no whitespace around that image. Adding a few pixels of whitespace (i just made an 800x200 image and pasted into the center of it) around the image makes it work. I'm not sure if it's feasible to alter Quagga to assume that the ends of an image are surrounded by whitespace, it sounds like a good idea, though. For some reason or other, I'm thinking that it's actually not valid to have a barcode that doesn't have whitespace around it to identify it's outside, but I could be completely wrong about that.
@ericblade The barcode itself works, but I am very interested in any ideas that anyone has as far as improving detection capability, for sure. I've been thinking it would be really interesting to have a layer of plugins that could be used to process the image data before sending it to the locator and decoder....@ericblade good news re: Asm.js error, sort of: asm.js error is basically a warning. It just runs the code as javascript since it can't interpret it properly into what it's looking for. bad news, although i can fix the one in this code, after i fix up several of them, i end up with one that the original author wrote which is also invalid, and i don't have any idea how to fix it, and information about asm.js is pretty sparse these days.@ericblade Asm.js errors have been fixed in the latest releases
- Fixes ericblade/quagga2#409
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Change Log for @ericblade/quagga2 (1.10.2 → 1.11.0)
New Features
-
Add custom image preprocessing chain
use "preprocessors" config option
-
Add Quagga.Preprocessors.addBorder
preprocessors: [Quagga.Preprocessors.addBorder(20)] adds a 20px white border around every image (by shrinking the image by 20px and then filling the space in white)
@copilot it does look like the new tests are not running in browser. Please make sure that the new tests are added to the .cy.ts files to run in browser .. and while we're at it, we probably need to audit the rest of the .spec. files to make sure we've got browser running all of the ones from the last few days worth of changes.
@copilot it does look like the new tests are not running in browser. Please make sure that the new tests are added to the .cy.ts files to run in browser .. and while we're at it, we probably need to ...
Added the preprocessing tests to Cypress browser test suites in commit 439c2d5:
-
integration.cy.tsnow importspreprocessor.spec.ts(integration tests) -
universal.cy.tsnow importssrc/preprocessing/test/preprocessor.spec.ts(unit tests)
@copilot looks like we're going to need /docs on the new feature, at the very least a how-to on creating new processors, updates to the configuration on using the processors, and does perhaps the technical guide need some info as well? probably all 4 of the main sections could use some explanation on this feature, i'd think
@copilot rename "preprocessing" config option to "preprocessors" .. nouns not verbs. Update all related docs and other files.
@copilot looks like we're going to need /docs on the new feature, at the very least a how-to on creating new processors, updates to the configuration on using the processors, and does perhaps the tech...
Added comprehensive preprocessing documentation to README.md in e5161d4:
- Quick links section with Preprocessing link
- Configuration overview showing preprocessing option
- Built-in preprocessors (addBorder) with usage examples
- Chaining multiple preprocessors
- Creating custom preprocessors guide with code examples
- When to use preprocessing scenarios
@copilot rename "preprocessing" config option to "preprocessors" .. nouns not verbs. Update all related docs and other files.
Renamed preprocessing config option to preprocessors in d286161. Updated all related files including quagga.ts, type definitions, tests, and README documentation.
@copilot Cypress tests are failing without obvious reason:
1) Preprocessor Integration Tests
addBorder preprocessor with no-whitespace barcode
should fail to decode barcode without preprocessor:
CypressError: Cypress test was stopped while running this command.
at cypressErr (http://localhost:36845/__cypress/runner/cypress_runner.js:76065:18)
at Object.errByPath (http://localhost:36845/__cypress/runner/cypress_runner.js:76119:10)
at http://localhost:36845/__cypress/runner/cypress_runner.js:145614:72
2) Preprocessor Integration Tests
addBorder preprocessor with no-whitespace barcode
should successfully decode barcode with addBorder preprocessor:
CypressError: Cypress test was stopped while running this command.
at cypressErr (http://localhost:36845/__cypress/runner/cypress_runner.js:76065:18)
at Object.errByPath (http://localhost:36845/__cypress/runner/cypress_runner.js:76119:10)
at http://localhost:36845/__cypress/runner/cypress_runner.js:145614:72
@copilot Cypress tests are failing without obvious reason:
...
Fixed in 87e5855. The test was missing the leading slash for the fixture path in browser environments. Updated to use the same pattern as other integration tests: `${typeof window !== 'undefined' ? '/' : ''}test/fixtures/...`
Comprehensive documentation belongs in the 4 sections in /docs, not in the README.
Do we need to also update copilot-instructions.md to document that the documentation for new features and change...
Moved comprehensive documentation to /docs following Divio system in c346a17:
- Created
docs/how-to-guides/use-preprocessors.md(task-oriented guide) - Updated
docs/reference/configuration.md(added preprocessors section) - Updated
docs/explanation/algorithm-overview.md(mention in pipeline) - Updated
docs/how-to-guides/index.md(link to new guide) - Simplified README.md to brief mention with link to full docs
Regarding copilot-instructions.md - that would be a good addition to document the Divio system convention. Want me to add that as a separate task?
Regarding copilot-instructions.md - that would be a good addition to document the Divio system convention. Want me to add that as a separate task?
@copilot yes please update that file, in such a way that you will easily understand how to update the documentation in /docs again anytime you are editing or creating features
Regarding copilot-instructions.md - that would be a good addition to document the Divio system convention. Want me to add that as a separate task?
@copilot yes please update that file, in such a ...
Added Divio documentation system guidelines to copilot-instructions.md in 6b73def. The new section covers:
- Documentation structure table (tutorials/how-to-guides/reference/explanation)
- Step-by-step instructions for documenting new features
- Template for new how-to guides
- Index file update requirements
- "Don't do this" list (e.g., don't put comprehensive docs in README.md)
when this is submitted, it will also close #433

