Repository navigation
feat(video): port buildImageDataset with the encapsulated frame-count fix - #578
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ports
buildImageDatasetand 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.jsand 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 —DicomMetaDictionaryandvalidationLognow come from@dcmjs-org/coreinstead 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.numberOfFramescame only fromdecodedImage.numberOfFrames || 1, was never derived from or checked againstoptions.encapsulated.frames.length, and the attribute was written only when above 1. SobuildImageDataset({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 explicitnumberOfFrames: 7over two fragments, emittedNumberOfFrames 7unchecked. In encapsulated mode the fragment list is now the ground truth: the count defaults toframes.lengthand an explicit mismatch throws. Both regressions were written first and observed red against the ported-unfixed builder (the three-fragment case gotundefinedwhere 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 inresolveGeometryonce 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