Skip to content

feat(video): port buildImageDataset with the encapsulated frame-count fix - #578

Merged
awatson1978 merged 2 commits into
release/1.0-beta-videofrom
video-pr2-build-dataset
Oct 2, 2026
Merged

awatson1978 merged 2 commits into
release/1.0-beta-videofrom
video-pr2-build-dataset

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This ports buildImageDataset and fixes review finding 10 inside the port. The builder is the codec-free primitive for turning already-decoded pixels (or pre-encoded encapsulated frames) into a conformant naturalized image dataset. dcmjs deliberately ships no PNG/JPEG codecs; callers decode with whatever fits their environment and hand over pixels plus geometry. The load-bearing conformance rules carried in from v2: actual image geometry always wins over metadata claims, and a metadata document that identifies an original instance yields a DERIVED\SECONDARY instance with a fresh SOPInstanceUID — original UIDs are never reused for rebuilt pixel data.

On provenance: buildImageDataset.js and its 21-test suite are verbatim ports from the v2 branch, isolated in their own commit with exactly two mechanical adjustments for the package boundary — DicomMetaDictionary and validationLog now come from @dcmjs-org/core instead of relative paths, and the test imports the builder from the package's image index. The hand-written surface is the finding fix and its four new tests.

  • Finding 10 (HIGH). numberOfFrames came only from decodedImage.numberOfFrames || 1, was never derived from or checked against options.encapsulated.frames.length, and the attribute was written only when above 1. So buildImageDataset({rows: 4, columns: 4}, {encapsulated: {transferSyntaxUID, frames: [f, f, f]}}) wrote three fragments and no NumberOfFrames — a conformant reader shows frame 1 and frames 2 and 3 are unreachable — while the reverse shape, an explicit numberOfFrames: 7 over two fragments, emitted NumberOfFrames 7 unchecked. In encapsulated mode the fragment list is now the ground truth: the count defaults to frames.length and an explicit mismatch throws. Both regressions were written first and observed red against the ported-unfixed builder (the three-fragment case got undefined where 3 was expected; the mismatch case did not throw). Two companion tests pin the edges: a matching explicit count is accepted, and a single fragment still omits the attribute (NumberOfFrames stays conditional, as before).

The 12-bit question from #576 still stands and I've deliberately not encoded an answer here: a 12-bit extended JPEG flows through this builder as BitsAllocated 12, but DICOM allows only 8 or 16 (the conformant encoding is BitsAllocated 16, BitsStored 12). It's about five lines in resolveGeometry once a maintainer blesses the policy.

Twenty-five tests in the suite — the 21 ported ones (defaults, geometry-wins, 16-bit/color, validation, metadata forms, derived-instance conformance) plus the four finding tests — and 42 in the package overall, all green.

🤖 Generated with Claude Code

awatson1978 and others added 2 commits October 2, 2026 13:14
Verbatim from v2.0-development src/image/buildImageDataset.js and its
21-test suite, with two mechanical adjustments for the package boundary:
DicomMetaDictionary and validationLog now come from @dcmjs-org/core, and
the test imports the builder from the package's image index (which now
exports it alongside the header parsers). No behavior changed in this
commit — review finding 10 is fixed on top with its regressions observed
red first.

Co-Authored-By: Claude Fable 5 <[email protected]>
Review finding 10 (HIGH): numberOfFrames came only from
decodedImage.numberOfFrames || 1 and was never derived from or checked
against options.encapsulated.frames.length, and the attribute was only
written when above 1. Three encapsulated fragments therefore produced an
instance with no NumberOfFrames — a conformant reader showed frame 1 and
the rest were unreachable — while an explicit numberOfFrames 7 over 2
fragments emitted the bogus claim unchecked. In encapsulated mode the
fragment list is now the ground truth: the count defaults to
frames.length and an explicit mismatch throws. Both regressions were
observed red against the ported-unfixed builder before this fix; two
companion tests pin that a matching explicit count is accepted and that
a single fragment still omits the attribute.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 1fd7bfc into release/1.0-beta-video Oct 2, 2026
8 checks passed
@awatson1978
awatson1978 deleted the video-pr2-build-dataset branch October 2, 2026 18:40
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.

1 participant