From 140a6660f63f88d05ba9aae0bf1c4b401bb6574d Mon Sep 17 00:00:00 2001 From: cirakg Date: Sun, 25 Oct 2026 14:17:45 +0100 Subject: fix(codes): encoding progress follows the work The QR percentage counted phases and the display froze at 90 % once encoding ended, so the first opening sat at 90 % while the slow stages ran. Each 2D symbology now weights its phases by measured cost, interpolates inside the long ones, and the display splits encode, pack and runs; a cached code counts its runs from 0. Co-Authored-By: Claude Opus 5.5 --- source/codes/DataMatrix.mc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source/codes/DataMatrix.mc') diff --git a/source/codes/DataMatrix.mc b/source/codes/DataMatrix.mc index 76a29e8..4fcc179 100644 --- a/source/codes/DataMatrix.mc +++ b/source/codes/DataMatrix.mc @@ -39,6 +39,8 @@ module DataMatrix { // with a 1,500-byte payload (144 x 144 modules). const BYTES_PER_STEP = 250; // codeword encodation const ECC_WORK_PER_STEP = 400; // data symbols x EC symbols + // Cumulative percent at the end of each phase 0-4 (see DataMatrixJob.percent). + const PHASE_ENDS = [2, 44, 45, 69, 100]; const BUILD_MODULES_PER_STEP = 300; // symbol modules var field as ReedSolomon.Field? = null; @@ -184,8 +186,28 @@ module DataMatrix { _data = Bytes.fromUtf8(text); } + // Progress 0-100: the share of each phase (simulator timings; the + // Reed-Solomon blocks, the placement and the symbol take the most). function percent() as Number { - return _phase * 20; + var done = 0; + var total = 0; + if (_phase == 1 && _size.size() > 0) { // blocks done, and the current one + var e = _encoder; + done = _block * 100 + (e != null ? e.percent() : 0); + total = _size[5] * 100; + } else if (_phase == 3 && _size.size() > 0) { // codewords placed + done = _chr - 1; + total = _size[3] + _size[4]; + } else if (_phase == 4 && _size.size() > 0) { // rows built + done = _buildRow; + total = _size[0]; + } + return Codes.phased(PHASE_ENDS, _phase, done, total); + } + + // Packing and runs: about 84 / 3 / 13 % of a whole display job. + function stageEnds() as Array { + return [84, 87]; } function matrix() as Codes.Matrix? { -- cgit v1.2.3