Skip to content

feat(graphics): add Floyd-Steinberg and Bayer dithering, PDF417, and ESC/POS byte parser - #173

Merged
adcondev merged 1 commit into
masterfrom
feat/graphics-barcodes-and-byte-parser
Oct 18, 2026
Merged

adcondev merged 1 commit into
masterfrom
feat/graphics-barcodes-and-byte-parser

Conversation

@adcondev

Copy link
Copy Markdown
Owner

Summary (Area 5 of 6)

  • Dithering & Raster Band Chunking (pkg/graphics/graph_engine.go, pkg/profile/escpos_profile.go, pkg/service/printer_service.go):
    • Implement FloydSteinberg (16-part error diffusion) and Ordered (4x4 Bayer matrix) dithering algorithms and wire "floyd_steinberg", "ordered", and "bayer" across DitherMap, executor/image_handler.go, and api/v1/ticket_document.schema.json.
    • Add MonochromeBitmap.SubBand(startY, bandHeight int) and profile.Escpos.MaxBandHeight (256 rows on 58mm profiles) so service.Printer.PrintBitmap automatically splits tall bitmaps into horizontal bands.
  • PDF417 & Expanded 1D Barcodes (pkg/commands/qrcode/pdf417.go, pkg/graphics/barcode.go, pkg/document/*, api/v1/*):
    • Implement standard ESC/POS PDF417 (GS ( k cn=48 functions 65–69, 80, 81, and ComposePDF417) and wire PDF417Command across schema, builder.DocumentBuilder.PDF417, executor, and api/v1/ticket_document.schema.json.
    • Expose CODE93, GS1128 (gs1_128 / gs1-128), and CODE128Auto (code128_auto) in graphics.MapSymbology and api/v1/ticket_document.schema.json.
  • Reverse ESC/POS Byte-Stream Parser (pkg/emulator/byte_parser.go):
    • Implement (*Engine).ParseESC(raw []byte) error, RenderBytesToPNG(raw []byte), and RenderBytesToPNGWithConfig(raw []byte, cfg Config) to parse raw ESC/POS byte streams (ESC @, LF, CR, ESC E, ESC -, ESC M, ESC a, ESC d, ESC 3/2, ESC !, GS !, GS B, GS V, and GS v 0 raster bitmaps) onto the 2D emulator canvas.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

@adcondev
adcondev merged commit 06f9f8f into master Oct 18, 2026
12 checks passed
@adcondev
adcondev deleted the feat/graphics-barcodes-and-byte-parser branch October 18, 2026 19:36
@github-actions

Copy link
Copy Markdown
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Benchmark Results

📈 Performance Comparison

📊 Click to expand detailed results

Current Branch Results

BenchmarkNewDocument-4    	1000000000	         0.2730 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 5244984	       230.2 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  545904	      2051 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  739588	      1465 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  733312	      1589 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	  138933	      8676 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  605378	      1809 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  405523	      2782 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  752653	      1438 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  354792	      3202 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	 9334453	       126.4 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 8605449	       137.7 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	337759818	         3.553 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	39903202	        30.20 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	19145757	        63.89 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  713908	      1692 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  194552	      5939 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     808	   1458955 ns/op	 3469939 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     397	   2909694 ns/op	 5481082 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     174	   6858758 ns/op	 5231179 B/op	  230423 allocs/op

Base Branch Results

BenchmarkNewDocument-4    	1000000000	         0.2729 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 5226048	       231.3 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  588606	      2048 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  689361	      1470 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  691735	      1600 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	  134937	      8922 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  610532	      1825 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  401179	      2843 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  756325	      1413 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  360610	      3224 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	10928299	       107.7 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 9747726	       121.4 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	338210284	         3.571 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	41548861	        30.20 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	19397677	        63.16 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  707466	      1699 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  197926	      5951 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     805	   1485595 ns/op	 3469935 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     405	   2940357 ns/op	 5481084 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     172	   6793319 ns/op	 5231184 B/op	  230423 allocs/op

💡 Note: Use benchstat for statistical comparison

🎯 Summary

  • Total Benchmarks: 32
  • Average Speed: 2049178 ns/op
  • Average Memory: 2396757 B/op
  • Average Allocations: 41077 allocs/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant