Skip to content

feat: JPEG 2000 codec and PDF JPXDecode support - #45

Merged
Malcolmnixon merged 46 commits into
mainfrom
feature/jpeg2000-codec
Oct 10, 2026
Merged

Malcolmnixon merged 46 commits into
mainfrom
feature/jpeg2000-codec

Conversation

@Malcolmnixon

@Malcolmnixon Malcolmnixon commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Pull Request

Description

Adds a dependency-free, decode-only JPEG 2000 codec (Jpeg2000Codec) and wires it into the PDF renderer so the /JPXDecode image filter works.

  • Codec: ISO 15444-1 Part 1 — JP2 boxes (ihdr, bpcc, colr, pclr/cmap, cdef) and raw codestreams; tiles/tile-parts; all five progression orders with POC; precincts; code-block styles; EBCOT tier-1 with the MQ decoder; tier-2 packets with tag trees; 5/3 and 9/7 inverse DWT; RCT/ICT; subsampling; ROI max-shift; 1–16 bit and signed samples (output scaled to 8 bits). Part-2/HTJ2K and >4 colour channels fail closed with UnsupportedImageFeatureException; malformed input throws InvalidDataException; allocations and work are capped.
  • PDF: JPX images use the JP2 colour space unless /ColorSpace is given; /SMaskInData, /Decode, and JPX as an /SMask. Also adds a general /SMask path (previously unsupported for raw/DCT images).
  • Tests/docs: test-only encoder, codec, fixture (ImageMagick-generated) and PDF tests, plus hostile-input tests; decode-wide CPU budget and public Jpeg2000DecoderLimits; raw 1/2/4/8/16-bit sample support; SysML2, reqstream, design, verification, reviewmark, README/user guide updated.

Known limitations: ICC profiles reported but not applied; naive CMYK; /Mask//Matte unsupported; JPX must be the sole filter; no inline images; truncated tile data is rejected. Encoder and decoder share an author, so 5/3, RCT, bypass and ROI paths are verified only against the test encoder (MQ verified against the T.88 vector; 9/7 against real files, not committed).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Related Issues

Closes #

Pre-Submission Checklist

Build and Test

  • Code builds successfully and all tests pass: pwsh ./build.ps1 (12,552 tests, 0 failed)
  • Code produces zero warnings

Code Quality

  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • All linters pass: pwsh ./lint.ps1 (no errors)

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated docs/ documentation (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

Real-world smoke check against a local third-party PDF with 7 JPX streams (not committed) decoded correctly, and a mutation fuzz run produced only the two allowed exception types.

Malcolm Nixon and others added 10 commits October 9, 2026 23:03
…et decoding

Work packages 1-2: markers, tile-parts, PPM/PPT, geometry, tag trees, all progression orders, POC, SOP/EPH.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rse DWT

Work packages 3-4: MQ and raw decoders, all code-block styles, ROI maxshift, 5/3 and 9/7 inverse wavelets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…00Codec API

Work package 5: RCT/ICT, subsampling, bit-depth scaling, colr/pclr/cmap/cdef, Load/GetInfo/Decode, Jpeg2000Image.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tiles lost main-header POC entries; a tile-part POC now replaces the inherited list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Includes T.88 MQ vector, round trips for all Part 1 features, JP2 boxes and hostile-input tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rted-filter PDF test to JBIG2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ion and user docs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 03:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved codec compilation and decoding correctness issues remain.

9 open findings
What changed in this PR

Adds a dependency-free JPEG 2000 decoder and PDF /JPXDecode/soft-mask support.

Changes:

  • Added JP2 and raw codestream decoding.
  • Integrated JPEG 2000 images and masks into PDF rendering.
  • Added tests, documentation, requirements, and traceability updates.
File Description
test/​DemaConsulting.CanvasNet.Tests/​Codecs/​Jpeg2000TestEncoder.Markers.cs Test encoder marker and JP2 support
test/​DemaConsulting.CanvasNet.Pdf.Tests/​PdfDocumentTests.cs Updated filter coverage
test/​DemaConsulting.CanvasNet.Pdf.Tests/​PdfDocumentJpxTests.cs JPX and mask tests
test/​DemaConsulting.CanvasNet.Pdf.Tests/​DemaConsulting.CanvasNet.Pdf.Tests.csproj Linked test encoder sources
src/​DemaConsulting.CanvasNet/​Codecs/​NamespaceDoc.cs Codec documentation
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000Image.cs Decoded image model
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000ColorSpace.cs Color-space definitions
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000Codec.cs Public codec API
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Tier1.cs EBCOT tier-1 decoding
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Packets.cs Tier-2 packet decoding
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Mq.cs MQ arithmetic decoding
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Jp2.cs JP2 box and channel parsing
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Geometry.cs Tile and code-block geometry
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Dwt.cs Inverse wavelet transforms
src/​DemaConsulting.CanvasNet/​Codecs/​Jpeg2000/​Jpeg2000Codec.Decoder.cs Decode orchestration
src/​DemaConsulting.CanvasNet.Pdf/​PdfDocument.Images.cs JPX and soft-mask rendering
src/​DemaConsulting.CanvasNet.Pdf/​PdfDocument.Filters.cs Filter documentation
src/​DemaConsulting.CanvasNet.Pdf/​PdfDocument.cs PDF feature documentation
src/​DemaConsulting.CanvasNet.Pdf/​NamespaceDoc.cs PDF namespace documentation
requirements.yaml JPEG 2000 requirements
README.md Feature documentation
docs/​verification/​canvas-net/​codecs/​jpeg2000-codec.md Codec verification design
docs/​verification/​canvas-net/​codecs.md Codec verification overview
docs/​verification/​canvas-net.md System verification
docs/​verification/​canvas-net-pdf/​pdf-document.md PDF verification
docs/​user_guide/​introduction.md Public API documentation
docs/​sysml2/​model/​canvas-net/​codecs/​jpeg2000-codec.sysml JPEG 2000 model
docs/​sysml2/​model/​canvas-net/​codecs.sysml Codec subsystem model
docs/​reqstream/​canvas-net/​codecs/​jpeg2000-codec.yaml Codec requirements
docs/​reqstream/​canvas-net/​codecs.yaml Codec subsystem requirements
docs/​reqstream/​canvas-net.yaml Library requirements
docs/​reqstream/​canvas-net-pdf/​pdf-document.yaml PDF requirements
docs/​reqstream/​canvas-net-pdf.yaml PDF traceability
docs/​design/​introduction.md Design overview
docs/​design/​canvas-net/​codecs/​jpeg2000-codec.md JPEG 2000 design
docs/​design/​canvas-net/​codecs.md Codec subsystem design
docs/​design/​canvas-net.md System design
docs/​design/​canvas-net-pdf/​pdf-document.md PDF image design
docs/​design/​canvas-net-pdf.md PDF subsystem design
.reviewmark.yaml Review coverage configuration
.cspell.yaml JPEG 2000 terminology

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/verification/canvas-net/codecs.md Resolved
Add ImageMagick/OpenJPEG-generated fixtures from synthetic sources, exact-match
decode tests against PNG sources, a PDF JPXDecode test and a system integration
test, with requirement and verification links.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 13:05
@Malcolmnixon

Copy link
Copy Markdown
Member Author

Added independent real-encoder evidence (07ede83): fixtures generated with ImageMagick 7.1.2/OpenJPEG from synthetic images (no third-party content), decoded pixel-exact against the source (5/3+RCT, all five progression orders, layers, gray, alpha, 16-bit, raw codestream), plus a system-integration and a PDF-level test. Also verified locally (not committed, licenses unclear) against ~38 jpylyzer-test-files: pixel-exact vs OpenJPEG on Kakadu/OpenJPEG/GraphicsMagick/ERDAS/Sentinel files, +/-1-3 levels on sYCC files; everything OpenJPEG rejects we reject. Not independently covered: 9/7 from committed fixtures, tiles, precincts, PPM/PPT (test encoder only).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Malcolm Nixon and others added 12 commits October 10, 2026 09:18
…; fix doc counts

Expose Jpeg2000Image.BitDepth and HasPalette; PdfDocument rejects an
Indexed /ColorSpace over non-8-bit samples and any /ColorSpace override
on JP2 data with its own palette. Correct ordinal, test count and
codecs verification list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…validation

- Add Jpeg2000DecoderLimits enforced during header validation before allocation
- Single decode-wide progression budget, POC entry cap and covered-volume skipping
- Reject codestreams with missing tiles; validate bit-plane counts and segmentation symbols
- Treat four channels as CMYK only when CMYK or unspecified
- Narrow the Guard backstop; tests assert specific exception types

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…s and limits to review set

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nData order

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ket caps

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…et, coverage, TPsot tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… names, user guide limits

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…es, tests

Unpack sub-byte and 16-bit samples through the shared sample path so soft masks of
any depth work, apply /Decode exactly to 1- and 3-channel JPEGs, and add CCITT and
Indexed /Decode regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t, document budget calibration

The per-input-byte term already bounds hostile input; the absolute ceiling
only needs to exceed the work of any image the default sample limit admits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Moderate findings remain in PDF image handling and JP2 channel and alpha processing.

0 open findings

2 resolved since last review

🧠 Review effort: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical and moderate findings affect malformed-input validation, PDF transparency correctness, and resource bounds.

2 open findings

🧠 Review effort: Lite

Malcolm Nixon and others added 3 commits October 10, 2026 15:52
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…es; document SOP leniency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved moderate findings remain in PDF image handling and JPEG 2000 decoding validation.

3 open findings
2 resolved since last review

🧠 Review effort: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Six unresolved findings remain, including five moderate issues affecting limits, validation, color handling, alpha conversion, and tile coverage.

0 open findings

3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Correct JPX dimension-limit security boundary documentation

src/​DemaConsulting.CanvasNet.Pdf/​PdfDocument.Images.cs:509

These remarks say the JPX decode is bounded by the PDF dictionary's /Width and /Height, but the implementation deliberately does not use those entries as limits; JpxDecoderLimits only sets Surface.MaxDimension. This misstates the security boundary and should describe the renderer-wide dimension limits instead.

🧠 Review effort: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 10, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical and moderate findings affect malformed-input handling, resource limits, PDF dimensions, and premultiplied color processing.

2 open findings

🧠 Review effort: Lite

@Malcolmnixon
Malcolmnixon merged commit 46c832d into main Oct 10, 2026
7 checks passed
@Malcolmnixon
Malcolmnixon deleted the feature/jpeg2000-codec branch October 10, 2026 22:31
Malcolmnixon added a commit that referenced this pull request Nov 16, 2026
…ted Markdown (#148)

* Sync DEMA Agents files (Agents 5fb794e)

Copy the updated agent definitions, canvasnet skill, and shared standards, add the C++ standards, and merge the template-level AGENTS.md changes (C++ standards rows, LintMark configuration and tooling mentions) while keeping the CanvasNet-specific sections.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Switch Markdown linting to LintMark

Add the demaconsulting.lintmark 0.1.0-beta.2 tool and .lintmark.yaml (template #49, with the CanvasNet ignores carried over from .markdownlint-cli2.yaml), run it from lint.ps1 and fix.ps1 instead of markdownlint-cli2, drop the node/npm VersionMark captures and the Node.js setup of the quality job, and capture the LintMark version there. package.json keeps only the pinned mermaid and mermaid-cli used by the tools/visual-diff developer scripts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Move inline spell-check directives into TextLint overrides

Adopt the template #45 .textlint.yaml guidance (where an exception belongs, overrides), add lintmark to the words, and replace the inline cspell directives of the seven Mermaid link-check test files, the StateModel verification design, the PngSuite tests, and the two fuzz random tests with overrides scoped to exactly those files (the fuzz hex literals are already covered by the hexadecimal-literal pattern). Narrow the Mermaid math-vector and entity-marker patterns that were global to the upstream vector files that need them, and scope the C++ standard terms to the C++ standards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Keep the LintMark and TextLint configuration comments stable under yamlfix

Reword the comments that yamlfix re-indented (a nested '#' in the fragment-markdown note and the override examples) and wrap the AGENTS.md technologies line to the 120-column LintMark limit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Exclude build output and test results from LintMark

The test projects copy their fixture READMEs into bin/, so a local lint after a build reported them; ignore bin/, obj/, and TestResults/ as .textlint.yaml already does.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Format Markdown with LintMark

Apply 'dotnet lintmark --fix' repository-wide: asterisk emphasis, compact tables with blank lines around them, dash bullets, and paragraphs re-wrapped to the 120-column limit. No wording changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Rewrite the over-wide tables of the user guides

Turn the tables whose rows exceed the 120-column LintMark limit into definition lists ('**term**: text', '**key** (default value): meaning', or a term with sub-bullets for a matrix), with a lead-in where the table header carried meaning; shorten or split rows, or move a detail into the sentence after the table, where only a few rows were a little too wide. Update the sentences that pointed at a converted table, and drop the markdownlint MD013 comments that LintMark no longer needs (it exempts tables from the line length).

The help-card parity tests (HelpTopicsTests) now read the definition lists of the Mermaid guide's syntax, relation, tag, setting, and code sections and the tool guide's Flatten Reference and File Access Reference sections instead of their tables; the comparison with the cards is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Rewrite the over-wide tables of the design documents

Turn the tables whose rows exceed the 120-column LintMark limit into definition lists: each external interface with its direction and format in parentheses, each limit or setting with its default, and a term with labeled sub-bullets where a table had several descriptive columns; add a lead-in where the header carried meaning, and update the sentences that pointed at a converted table. Where only a row or two were too wide, shorten them, split them, or move a detail into a note or sentence after the table (canvas-net.md, image-pipeline.md, scad-parser.md, scad-evaluator.md, discovery-commands.md).

Also drop the markdownlint MD013 comments that LintMark no longer needs, and re-wrap the three paragraphs LintMark could not wrap (a code span too long for one line in title-builder.md, and irregular continuation lines in legend-builder.md and scale-resolver.md). No wording changes beyond those.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Re-wrap two verification paragraphs that LintMark could not wrap

Collapse the stray runs of spaces and the irregular continuation indentation in time-calendar.md and sandboxed-file-resolver.md so LintMark can wrap them to 120 columns; whitespace only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Rewrite the over-wide tables of the test fixture READMEs

Turn the fixture tables whose rows exceed the 120-column LintMark limit (long file names and upstream URLs) into definition lists, keeping every file name, URL, and description, and drop the markdownlint MD013 comments that LintMark no longer needs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Malcolm Nixon <Malcolm.Nixon@hiarc.inc>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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