Skip to content

feat: @dcmjs-org/video and @dcmjs-org/imaging - #585

Merged
wayfarer3130 merged 25 commits into
1.0-betafrom
release/1.0-beta-video
Oct 21, 2026
Merged

wayfarer3130 merged 25 commits into
1.0-betafrom
release/1.0-beta-video

Conversation

@awatson1978

@awatson1978 awatson1978 commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

This is the assembly PR for the video package: it brings release/1.0-beta-video into 1.0-beta, carrying PRs #576, #578, #581 and #583 on top of the core engine branch, each individually reviewed with its own plain-English description. Like the other assemblies (#542, #543, #575, #577, #584), it's open as a draft on purpose — please don't merge it yet; the landing order and the trunk overlap (details below) mean the assemblies should go in deliberately, not as soon as they're green.

What this is in plain terms. @dcmjs-org/video gets video and camera imagery into DICOM without re-encoding. Its header parsers (parseJpegInfo, parseMp4Info) read the geometry and timing DICOM needs — rows, columns, frame count, frame rate, codec profile — straight from the JPEG or MP4 bytes, without decoding a single pixel, so the compressed stream can travel verbatim into encapsulated PixelData. encapsulateVideo wraps an MP4's H.264 stream into a Video Photographic Image instance and extractEncapsulatedVideo recovers it byte-identically. buildImageDataset goes the other way for already-decoded pixels, producing a conformant image instance. And createVideoEventSource is the streaming path: MP4 to contract events, one fragment in memory at a time, feeding any event-stream sink. The package imports only @dcmjs-org/core and @dcmjs-org/parser — never legacy.

A worked example, both directions — run on this branch, output verbatim.

Creating: an MP4 becomes a complete Part 10 file, streamed one fragment at a time (the header parsers recover the geometry; nothing is re-encoded):

import { createVideoEventSource } from "./packages/video/src/index.js";
import { StreamingPart10Writer } from "@dcmjs-org/generator";
import fs from "fs";

const mp4 = fs.readFileSync("clip.mp4"); // the run below used the suite's synthetic MP4

const source = await createVideoEventSource(mp4, { PatientName: "FOX^JANE" });
source.info; // { rows: 48, columns: 64, numberOfFrames: 12, frameRate: 60,
             //   transferSyntaxUID: "1.2.840.10008.1.2.4.104.1", codec: "avc1" }

const writer = new StreamingPart10Writer();
await source.run(writer);
const part10 = writer.toArrayBuffer(); // 2,588 bytes for the 1,665-byte test clip
fs.writeFileSync("clip.dcm", Buffer.from(part10));

Reading: the Part 10 file comes back through the engine, and the original MP4 comes out byte-identical:

import { fromPart10, NaturalizedListener } from "@dcmjs-org/parser";
import { extractEncapsulatedVideo } from "./packages/video/src/index.js";

const listener = new NaturalizedListener();
await fromPart10(part10, listener);

const ds = listener.result;
ds.SOPClassUID;     // "1.2.840.10008.5.1.4.1.1.77.1.4.1" (Video Photographic Image)
ds.NumberOfFrames;  // 12
ds.CineRate;        // 60

const { bytes } = extractEncapsulatedVideo(ds);
// bytes === the original MP4 (verified: 1,665 of 1,665 bytes equal)

The buffered pair works the same way without the event stream: encapsulateVideo(mp4, attrs) gives the naturalized dataset directly, and extractEncapsulatedVideo recovers the stream from any dataset however it was read.

What's in it. Four PRs, in the order they landed:

The three review findings fixed here, from the PR #512 review map — each regression was written against the ported-but-unfixed code and observed failing first:

One open question for maintainers, raised in #576 and deliberately not fixed: 12-bit extended-sequential JPEG currently yields BitsAllocated 12, but PS3.5 allows only 8 or 16 (correct would be BitsAllocated 16 with BitsStored 12). It's a ~5-line fix in buildImageDataset if you agree.

Test evidence. 913 tests across 75 suites on this branch — 901 passing, 12 skipped (the pre-existing skips), zero failures, on Node 22 and 24. The package itself is 57 tests in 5 suites, including the new jpegInfo suite and the finding regressions. CI is green at the branch tip 58dba59: tests, lint/format, audit. One honest gap, declared in #576: every MP4 in the suite is synthetic (makeTinyMp4) — no real-world camera file exercises the box parser yet. Adding one later means a DATACITATION row and a license check, like every committed fixture.

Test usage. From the repo root:

npx jest packages/video --testTimeout 60000

Expected: 5 suites, 57 tests, all passing in a few seconds.

GitHub issues. None map directly — the historical backlog has no video-area issues (video support itself arrived with the 1.0 rewrite). The three fixes above trace to the #512 review map rather than filed issues.

The numbers. The package is +2,100 lines under packages/video/ (about two-thirds verbatim v2 port, declared per-PR; the hand-written remainder is the three fixes, their regressions, the new jpegInfo suite, and the legacy-free rework of the event source) across 4 PRs and their conventional commits, merged (not squashed) so the release tooling sees each one. The raw diff against 1.0-beta is much larger because this branch is cut from the core engine tip (e5f46e4) — it carries the whole core trunk that draft #542 also carries. Whichever assembly merges first absorbs that trunk, and this diff shrinks to just the video package.

Breaking changes. None — this is a new package; nothing under the existing src/ surface changes here. Within the port itself: truncated JPEGs and malformed MP4s that previously produced silently-wrong values now throw, and encapsulated multi-frame datasets gain the NumberOfFrames attribute they were always supposed to carry.

Still to come: the DicomEventStream facade factories (fromVideo, fromVideoStream, toVideo, fromImage) land with the media wave, which also carries the review's finding 14 (the lazy source-promise fix) — that wave touches the shared facade file, so it sequences after the three bulk-data packages rather than inside any one of them.

Update: one instance-creation model for all builders

This update has six commits on top of the assembly branch.

  • c9634a6 merges origin/1.0-beta into this branch. The merge brings @dcmjs-org/encapsulated (feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577) and createInstance in @dcmjs-org/core. The package table and step 6 of RELEASE_PLAN.md now name @dcmjs-org/encapsulated, @dcmjs-org/imaging and @dcmjs-org/video, and not @dcmjs-org/pdfs.
  • f875187 changes buildImageDataset and buildVideoDataset to use createInstance.
  • 7c9e118 keeps the keywords that a caller adds with registerTag.
  • 64992a8 makes one model for all builders, and documents the model.
  • c8aa8a7 moves the attributes into an overrides provider, adds postProcess, and simplifies the model.
  • 5b7dc92 keeps predecessorBase only in the encapsulated bases. Ten review rounds checked this work.

The model

packages/core/README.md documents the shared model (CORE-USR-1 to 15 and CORE-IMP-1 to 11). The READMEs of @dcmjs-org/encapsulated, @dcmjs-org/imaging and @dcmjs-org/video refer to the CORE identifiers. Each README keeps user requirements and implementation requirements in separate sections, and states the change rule.

encapsulate / encapsulatePdf buildVideoDataset / encapsulateVideo / createVideoEventSource buildImageDataset
baseDicom (encapsulatedBase) baseDicom (videoBase) baseDicom (imageBase)
instance, dataLevel, levels, predecessor, postProcess same same
overrides same same
mimeType fragmentBytes derivedFrom, lossy, encapsulated
encapsulatePdf(pdfBytes, {
    instance: priorInstance,
    dataLevel: "series",
    overrides: { DocumentTitle: "Discharge Summary" }
});
  • The options object holds controls only. An extra option key has no effect.
  • overrides holds the DICOM attributes. It is a naturalized DICOM provider with the same forms as baseDicom: a naturalized object, a function of the context, an array, or a combineBases block.
  • createInstance resolves baseDicom, then overrides. The merge order is: base blocks < attributes from instance (copied by level) < overrides. An _meta override merges key by key.
  • postProcess(dataset, context) runs once on the merged result. The default removeUndefinedAttributes deletes the top-level undefined values, so an undefined override removes the attribute. null and "" give a Type 2 empty value.
  • instance says where the new object goes. It gives the attributes that levels lists. The default levels do not hold the identity of instance.
  • predecessorBase is an optional base block in core (CORE-USR-9). With predecessor: true, it lists each instance in PredecessorDocumentsSequence. Only the encapsulated bases (encapsulatedBase, encapsulatedPdfBase) include it now. With the default imageBase and videoBase, predecessor: true has no effect. A caller can add the block, for example combineBases(imageBase, predecessorBase).
  • With dataLevel: "series", instance is the sample instance. The new InstanceNumber is its InstanceNumber plus 1. When instance is an array, the first item is the sample. In each other case the value is 1. An override wins.
  • Each builder sets its payload attributes after createInstance, and only when the payload gives them. Examples are the decoded image geometry, HighBit from a decoded bitsStored, and the video stream values. A builder writes no default for a payload attribute that the payload does not give.
  • A builder changes only _meta.TransferSyntaxUID, on a copy of _meta.
  • Validation is part of the usage flow (CORE-IMP-11). A function checks a value where it uses the value, when a wrong value gives a wrong result. Examples are the PDF magic, an unknown dataLevel, an extract* call on the wrong type, and pixel data that does not match the geometry. A function does not check a JS type that the JSDoc declares. A user requirement names each error.
  • derivedFrom (one naturalized instance or an array) is separate from instance. The base block derivedImageBase and the function derivedImageAttributes make the derived attributes.
  • Video keeps an override of the pixel attributes that the H.264 transfer syntaxes mandate (VID-USR-3). This is intentional, because the codec values take precedence for a conformant reader.

These changes also change the API of #577 on 1.0-beta. In #577, the attributes were top-level options, for example encapsulatePdf(bytes, { instance, DocumentTitle: "v1" }). Now the attributes go in overrides.

Changes needed in PRs 588, 584 and 595 when they merge this branch

These PRs are based on a 1.0-beta from before #577. When they merge this branch, these call sites must change:

  • packages/media/src/index.js:
    • It imports normalizeFragmentBytes from @dcmjs-org/video. That export is removed. Remove it from lines 22 and 48, and from packages/media/test/bundle.test.js lines 38–40.
    • It imports @dcmjs-org/pdfs. That package does not exist on 1.0-beta. Import from @dcmjs-org/encapsulated.
    • It imports buildImageDataset, SECONDARY_CAPTURE_SOP_CLASS_UID, parseJpegInfo and h264TransferSyntaxUID from @dcmjs-org/video. These are now in @dcmjs-org/imaging.
    • Native ESM does not load the bundle with these imports. Jest does not show the problem, because a missing import is undefined, and the identity test compares undefined with undefined.
  • src/eventStream/fromFhir.js lines 166 and 187 (PRs 584 and 595): the demographics and DocumentTitle are top-level options. After the merge, these keys have no effect, and the PDF and JPEG instances lose the patient name, the patient ID and the title, with no warning. Move them into overrides.

Tests

  • npx jest packages/core packages/encapsulated packages/imaging packages/video gives 10 suites and 100 tests. All tests pass.
  • The full suite, without streamEquivalence, has 3 failures: test_multiframe_1, test_oneslice_seg and test_deflated in test/data.test.js. These tests also fail without this update, because the downloaded test data was missing on the test machine.
  • ESLint and Prettier pass.
Changes to user requirements (compared with origin/1.0-beta, with 7c9e118, with 64992a8, and with c8aa8a7)
Changes to user requirements

The base of the comparison is origin/1.0-beta (the encapsulated README
of #577). The README of @dcmjs-org/encapsulated was the only README with
user requirements. The shared requirements of createInstance moved from
that README to packages/core/README.md (CORE-USR-n). The ENC identifiers
of the moved requirements stay reserved, and each one refers to its CORE
identifier.

@dcmjs-org/imaging (IMG-USR-n) and @dcmjs-org/video (VID-USR-n) are new
packages. Their user requirements are new, and are not changes.

Changes of behaviour

  • ENC-USR-2 → CORE-USR-3, CORE-USR-5 (InstanceNumber)
    • Old: "series: the same series (its UID, number, and description), as
      a new SOP instance." The InstanceNumber was always 1.
    • New: with dataLevel: "series", instance is the sample instance
      in the series. The new InstanceNumber is the InstanceNumber of
      the sample instance, plus 1. When instance is an array, the first
      item is the sample instance. The value is 1 when the sample instance
      has no usable value (not an integer, less than 0, or 2147483647 or
      more), or when dataLevel does not inherit the series. An
      InstanceNumber override replaces the value.
    • Reason: the intended behaviour changed. A new instance in a series
      must follow the sample instance, and must not repeat its number.
  • ENC-USR-2 → CORE-USR-3 (Type 2 values of an inherited level)
    • Old: no rule.
    • New: when an inherited study has no StudyDate or StudyTime, the
      value is "". When an inherited series has no SeriesNumber, the
      value is "".
    • Reason: the intended behaviour changed. These attributes are Type 2,
      and the result must have them.
  • ENC-USR-5 → ENC-USR-5 and ENC-USR-9 (CORE-USR-4, CORE-USR-10)
    • Old: "When an inherited Modality or SOPClassUID differs from the
      base, the builder logs a warning and keeps the inherited value."
    • New ENC-USR-5: "When an inherited Modality differs from the base
      Modality (DOC for PDF), the builder logs a warning and keeps the
      inherited value (CORE-USR-10)."
    • New ENC-USR-9: "With the default levels, the result does not get
      the SOPInstanceUID, SOPClassUID, InstanceNumber,
      MediaStorageSOPInstanceUID, or MediaStorageSOPClassUID of
      instance (CORE-USR-4). A custom levels copies each of these
      keywords that it lists. The base blocks set the identity: a new
      SOPInstanceUID, the SOPClassUID of the document class, and the
      InstanceNumber of CORE-USR-5. A copied value and an override
      replace a base value (CORE-USR-6)."
    • Code: CONSISTENCY_KEYS is ["Modality"]. At origin/1.0-beta, it
      was ["Modality", "SOPClassUID"]. createInstance copies exactly
      copyAttributesByLevel(instance, dataLevel, { levels }), as at
      origin/1.0-beta. No code removes an identity keyword.
    • Change of behaviour: the SOPClassUID warning is removed. A custom
      levels that lists SOPClassUID copies the value of instance,
      and the builder logs no warning. The default levels do not list
      SOPClassUID, so with the default levels the warning never
      occurred. The copy of the identity with a custom levels does not
      change against origin/1.0-beta.
    • Reason: the intended behaviour changed. The level list says what
      the result copies, and a custom levels is the choice of the
      caller. The old ID also held two different rules (the Modality
      warning and the identity), so the new text splits them.
  • (new) CORE-USR-7 (the input types; the keys of overrides)
    • Old: no rule. createInstance wrote each option that was not a
      createInstance option into the dataset.
    • New: the attributes go in overrides (CORE-USR-1). Each key of the
      resolved overrides goes into the merge, also a key with an
      undefined value (CORE-USR-8). An extra top-level option key has
      no effect. The JSDoc of each function states the input types. A user
      requirement names each error that a function throws for a wrong
      input value. CORE-IMP-11 gives the rule for these checks.
    • Reason: the intended behaviour changed. A control key of a builder
      must not go into the dataset.
  • (new) CORE-USR-8 (undefined, null, "" overrides)
    • Old: no rule. An undefined override wrote undefined into the
      dataset.
    • New: an undefined override replaces the base or inherited value.
      The default postProcess (CORE-USR-15) then deletes the key, so the
      result does not have the attribute. An undefined value from a base
      block or from instance also gives no attribute. null and ""
      give a Type 2 empty value. The builders do not invent a value.
    • Reason: the intended behaviour changed. A caller can remove an
      attribute of the base or of instance with an undefined
      override, and the dataset holds no undefined value.
  • (new) CORE-USR-15 (postProcess)
    • Old: no rule. No postProcess option.
    • New: postProcess is a createInstance control (CORE-USR-1), a
      function (dataset, context) => dataset. createInstance calls it
      once on the merged result, and returns its return value. The
      default is removeUndefinedAttributes, a new export of
      @dcmjs-org/core. This function deletes each top-level key with an
      undefined value, and does not change the items of a sequence. A
      custom postProcess replaces the default. A builder passes
      postProcess to createInstance, and does not call it again after
      it sets its payload attributes (CORE-USR-13).
    • Reason: the intended behaviour changed. A caller can change the
      merged result in one step, before the builder sets the payload.

Changes of text only (no change of behaviour)

  • (new) CORE-USR-12: instance is a naturalized dataset. The text
    tells the caller to use DicomMetaDictionary.naturalizeDataset on DICOM
    JSON first. createInstance does not detect DICOM JSON, as in feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577.
    The type check of instance is removed (see "Removed checks" below).
  • ENC-USR-1 → CORE-USR-2: "today's dates" became "the current date and
    time".
  • ENC-USR-3 → CORE-USR-6: "explicit option" became "override". The
    text adds the example of an override SOPInstanceUID. The text also
    names the exception for the payload attributes of a builder
    (CORE-USR-13). encapsulate replaced an override of its payload in
    feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577 also, so the behaviour does not change.
  • ENC-USR-4: "explicit" became "override". The text adds that
    mimeType replaces an override of MIMETypeOfEncapsulatedDocument.
  • ENC-USR-7 → CORE-USR-11: moved, same text.
  • ENC-USR-8 → CORE-USR-9: moved. The text adds that the base must have
    predecessorBase, and that an instance without the four reference UIDs
    throws an error.
  • (new) ENC-USR-10: the payload rule of encapsulate. The text
    describes the behaviour of feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577.
  • (new) CORE-USR-1, CORE-USR-13: the shared option shape and the
    payload rule of each builder. The text describes the current behaviour.

Changes since 7c9e118

The base of this comparison is the pushed branch (HEAD 7c9e118, the PR
body of #585). The comparison with origin/1.0-beta above stays valid.
At 7c9e118, the imaging and video packages had no README requirements.
The "Old" text below therefore comes from the PR body and from the code
of 7c9e118.

buildImageDataset (IMG-USR-n)
  • metadata option removed
    • Old: metadata was a control key. It took a naturalized or a DICOM
      JSON document. When the caller gave no instance, the stripped
      metadata was the instance, at the deepest level that its UIDs
      identified.
    • New: metadata is not an option. A top-level metadata key has
      no effect (CORE-USR-7). Without
      instance, the image goes into a new study (CORE-USR-2). The
      builder does not naturalize DICOM JSON. Give a naturalized
      instance, and give derivedFrom for a derivation.
    • Reason: the intended behaviour changed. All builders take the same
      options (CORE-USR-1). instance says where the image goes, and
      derivedFrom says what the image comes from (IMG-USR-1).
  • Old shapes of derivedFrom removed (IMG-USR-4)
    • Old: derivedFrom: true used the identity of metadata.
      derivedFrom: { sopClassUID, sopInstanceUID } named the source. A
      metadata with a SOPInstanceUID also made a derived image.
    • New: derivedFrom is a naturalized instance, or an array of them.
      Each item needs SOPClassUID and SOPInstanceUID. The old shapes
      throw an error that names the absent keyword.
      SourceImageSequence has one item for each source, in order.
    • Reason: the intended behaviour changed. One shape for the source
      instance, and more than one source.
  • SOPClassUID with derivedFrom (IMG-USR-3)
    • Old: the result got the SOPClassUID of the metadata or of the
      source, when the metadata had one.
    • New: SOPClassUID stays the value of the base: Secondary Capture
      for imageBase.
    • Reason: the description was wrong. The result is a new image from
      new pixels, and the source SOP class does not describe it.
  • ImageType is a base value (IMG-USR-5)
    • Old: the builder set ORIGINAL\PRIMARY or DERIVED\SECONDARY
      after createInstance. Only an override replaced the value.
    • New: secondaryCaptureImageBase sets ORIGINAL\PRIMARY, and
      derivedImageBase sets DERIVED\SECONDARY. A custom base, an
      inherited value, and an override each replace the value, in the
      order of CORE-USR-6. A custom base without
      secondaryCaptureImageBase has no ImageType.
    • Reason: the intended behaviour changed. Each producer of an
      attribute is a base block (CORE-IMP-4).
  • Lossy Image Compression (IMG-USR-3)
    • Old: lossy: false always gave "00". A ratio of 0 was dropped.
      Only the lossy object gave the method and the ratio.
    • New: a source with "01" keeps "01", also for lossy: false. A
      ratio of 0 stays. The method and the ratio of each lossy source
      come first, then the values of the lossy object. The ratios pair
      with the methods by position. When the count of ratios is not the
      count of methods, the result has no ratio, and the builder logs a
      warning.
    • Reason: the description was wrong. PS3.3 C.7.6.1.1.5 says that a
      lossy image stays lossy, and keeps the values of all lossy steps.
  • lossy without derivedFrom (IMG-USR-8): text only. lossy has
    no effect without derivedFrom, with no warning, as at 7c9e118.
  • New exports derivedImageAttributes and derivedImageBase
    (IMG-USR-7)
    • Old: none.
    • New: derivedImageBase(derivedFrom, { lossy }) is a base block, and
      derivedImageAttributes is the plain function under the block. A
      custom baseDicom with derivedImageBase gives the same result as
      the derivedFrom option. Both functions throw an error for an
      empty derivedFrom. The derivedFrom option of
      buildImageDataset takes an empty array as no derivedFrom.
All builders (CORE-USR-n)
  • InstanceNumber (CORE-USR-5)
    • Old: the InstanceNumber was always 1, for encapsulate,
      buildImageDataset, and buildVideoDataset.
    • New: with dataLevel: "series", the InstanceNumber is the
      InstanceNumber of the sample instance, plus 1. The sample instance
      is instance, or the first item when instance is an array. The
      other items have no effect on InstanceNumber. The value is 1 when
      the sample instance has no usable value (not an integer, less than
      0, or 2147483647 or more), or when dataLevel does not inherit the
      series. An InstanceNumber override replaces the value.
    • Reason: the intended behaviour changed. A new instance in a series
      must follow the sample instance, and must not repeat its number.
  • SeriesNumber of nextSeriesNumberBase (CORE-USR-12)
    • Old: nextSeriesNumberBase read each value with Number(...). Any
      finite number counted. A series number 7.5 gave SeriesNumber 8.5,
      and a negative or a very large value also counted.
    • New: only an IS integer from 0 to 2147483647 counts. A value outside
      this range, or a value that is not an integer, does not count, and
      the other series still count. For example, [7.5, 2] gives 3, and
      [3e9, 4] gives 5. When the largest series number is 2147483647
      (the IS maximum), the next SeriesNumber is 1. This is the integer
      rule of CORE-USR-5.
    • Reason: the description was wrong. SeriesNumber is IS, and a value
      outside the IS range is not a valid series number.
  • Type 2 values of an inherited level (CORE-USR-3)
    • Old: the PR body had this "Known gap": an inherited study or series
      without StudyDate, StudyTime, or SeriesNumber gave a dataset
      without these attributes.
    • New: the gap is fixed. These attributes are "" (Type 2 empty),
      and a source value replaces the empty value.
  • undefined overrides (CORE-USR-8)
    • Old: an undefined override wrote undefined into the dataset.
    • New: an undefined override replaces the base or inherited value,
      and the default postProcess deletes the key. The result does not
      have the attribute. null and "" give a Type 2 empty value.
  • (new) postProcess option and removeUndefinedAttributes export
    (CORE-USR-1, CORE-USR-15)
    • Old: none.
    • New: postProcess(dataset, context) runs on the merged result
      inside createInstance. The default is removeUndefinedAttributes,
      which deletes each top-level key with an undefined value. Each
      builder passes postProcess through to createInstance.
  • Identity of instance (CORE-USR-4)
    • Old: a custom levels that listed SOPInstanceUID,
      SOPClassUID, or InstanceNumber copied the identity of
      instance into the result. An inherited SOPClassUID that
      differed from the base gave a warning.
    • New: the copy does not change. The default levels do not hold the
      identity, so the result does not get it. A custom levels copies
      each identity keyword that it lists. The SOPClassUID warning is
      removed: CONSISTENCY_KEYS is ["Modality"]. CORE-USR-4 is new
      text, and states this rule.
  • Payload attributes (CORE-USR-6, CORE-USR-13)
    • Old: the PR body said that the builder sets the payload attributes
      after createInstance.
    • New: CORE-USR-6 names the exception. An override always wins,
      except for the payload attributes that a builder sets after
      createInstance. Each builder README lists these attributes. Video
      keeps an override of the pixel attributes that the H.264 transfer
      syntaxes mandate (VID-USR-3).
  • (new) CORE-USR-14 (an array instance): text only. The first item
    gives the inherited attributes and the sample InstanceNumber
    (CORE-USR-5). The predecessor rule uses all of the items, when the base
    includes predecessorBase.

Changes since the pushed HEAD 64992a8

The base of this comparison is the pushed branch (HEAD 64992a8). This change
is also a user-facing API change against origin/1.0-beta, because #577
merged the old option shape. Each caller of createInstance, encapsulate,
or encapsulatePdf that passes attributes at the top level must change.

All builders (CORE-USR-1, CORE-USR-6 to 8, CORE-USR-12, CORE-USR-15)
  • The DICOM attributes go in overrides (CORE-USR-1, CORE-USR-6)
    • Old (feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577 and 64992a8): the options object held the controls and the
      attributes together. createInstance took each option that was not
      baseDicom, instance, dataLevel, levels, or predecessor as
      an override, for example
      encapsulatePdf(bytes, { instance, DocumentTitle: "v1" }). The
      builders encapsulate, encapsulatePdf, buildImageDataset,
      buildVideoDataset, encapsulateVideo, and createVideoEventSource
      passed the rest of their options through in the same way.
    • New: the options object holds only controls. The attributes go in a
      separate overrides object, for example
      encapsulatePdf(bytes, { instance, overrides: { DocumentTitle: "v1" } }).
      These rules of the old top-level overrides now apply to
      overrides: the precedence, null and "", and the Modality
      warning. An undefined override now removes the attribute (see the
      postProcess entry below). The attribute-key filter is removed (see the
      next entry).
    • Reason: the intended behaviour changed. One object that holds both
      controls and attributes lets a misspelled control key become an
      attribute, or lets an attribute keyword hide a control key.
  • The attribute-key filter is removed (CORE-USR-7)
    • Old (64992a8): createInstance dropped each top-level key that was
      not a DICOM attribute, and logged the warning "is not a DICOM
      attribute". An attribute key was a dictionary keyword, a
      registerTag keyword, a tag of 8 hexadecimal digits, or an _ key.
      createInstance wrote each attribute key into the dataset.
    • New: the JSDoc of each function states the input types. A top-level
      key that is not a control of createInstance (baseDicom,
      instance, dataLevel, levels, predecessor, postProcess,
      overrides) has no effect, and gives no warning and no error. Each
      key of the resolved overrides goes into the merge, also a key with
      an undefined value (CORE-USR-8). No key of overrides gives a warning.
    • Reason: the intended behaviour changed. An extra key is not a value
      that createInstance uses, so it gives no error (CORE-IMP-11). The
      JSDoc gives the correct inputs.
    • Effect on the metadata entry above: a top-level metadata key has
      no effect.
  • overrides is a naturalized DICOM provider (CORE-USR-1, CORE-IMP-2)
    • Old: no overrides option. The attributes were top-level options.
    • New: overrides has the same forms as baseDicom: a naturalized
      object, a function that gets the context and returns a naturalized
      object, an array of these (a later entry wins), or a block from
      combineBases. createInstance resolves overrides once with
      resolveBase(overrides, context), and keeps the undefined values
      (CORE-USR-8). The resolved attributes have the highest precedence.
      overrides holds only DICOM attributes. The control keys of
      createInstance and of each builder are options, and never go in
      overrides. An overrides that is undefined or null
      gives no overrides, the same as a baseDicom of null.
      resolveBase does not check the type of its input, as at 64992a8
      (CORE-IMP-11).
    • Reason: the intended behaviour changed. overrides is a source of
      attributes, the same as baseDicom, so it takes the same forms.
  • An undefined override removes the attribute; new postProcess
    (CORE-USR-1, CORE-USR-8, CORE-USR-15, CORE-IMP-1)
    • Old (64992a8): createInstance skipped an undefined override, and
      the base or inherited value stayed. No postProcess option.
    • New: an undefined override replaces the base or inherited value.
      postProcess(dataset, context) is a new createInstance control.
      createInstance calls it once on the merged result, and returns its
      return value. The default is removeUndefinedAttributes, a new
      export of @dcmjs-org/core. This function deletes each top-level
      key with an undefined value, and does not change the items of a
      sequence. Thus with the default, an undefined override removes the
      attribute. A caller who wants a Type 2 empty value gives "" or
      null. A custom postProcess replaces the default. Each builder
      passes postProcess through to createInstance, and does not call
      it again after it sets its payload attributes.
    • Reason: the intended behaviour changed. A caller can remove an
      attribute of the base or of instance, and the dataset holds no
      undefined value. A caller can also change the merged result in one
      step.
  • DICOM JSON instance (CORE-USR-12, CORE-IMP-10)
    • Old (64992a8): a DICOM JSON instance threw an error. The error told
      the caller to use DicomMetaDictionary.naturalizeDataset first.
    • New: createInstance does not detect DICOM JSON, as in feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577 and at
      7c9e118. CORE-USR-12 tells the caller to naturalize DICOM JSON
      first. CORE-IMP-10 described the detection of DICOM JSON, and is
      marked as removed.
    • Reason: the intended behaviour changed. The shape of instance is a
      type, and the JSDoc gives the type (CORE-IMP-11).
  • context.options of a function block (CORE-IMP-4, CORE-USR-11)
    • Old: context.options held the controls and the attributes
      together. A custom block read an attribute as
      context.options.SeriesDescription.
    • New: context.options is the options object that createInstance
      gets. The attributes are in context.options.overrides, in the form
      that the caller gave. The context has no resolved overrides.
      createInstance resolves baseDicom first, then overrides, with
      the same context (CORE-IMP-1). A custom block that reads
      context.options.<keyword> now gets undefined, and no error
      occurs.
    • Reason: a custom block is an extension point that a caller can see
      (CORE-USR-11). The shape follows the new option shape.
  • InstanceNumber (CORE-USR-5, CORE-USR-14)
    • Old (64992a8): with dataLevel: "series", the InstanceNumber was
      the largest InstanceNumber of the instance items in the target
      series, plus 1. The target series was the top-level
      SeriesInstanceUID option, else the series of the first item. An
      item counted when its SeriesInstanceUID was the target series.
    • New: the InstanceNumber is the InstanceNumber of the sample
      instance, plus 1. The sample instance is instance, or the first
      item when instance is an array. The other items and a
      SeriesInstanceUID override have no effect on InstanceNumber. The
      value is 1 when the sample instance has no usable value, or when
      dataLevel does not inherit the series. An InstanceNumber
      override replaces the value.
    • Reason: the intended behaviour changed. One sample instance gives a
      simple rule, and the rule does not depend on the overrides.
  • An _meta override merges into the base _meta (CORE-USR-6,
    CORE-IMP-1)
    • Old (feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577 and 64992a8): an _meta override replaced the whole
      _meta of the base. For example,
      overrides: { _meta: { ImplementationVersionName: "x" } } gave a
      result without TransferSyntaxUID.
    • New: an _meta override that is an object merges into the base
      _meta key by key. A key of the override wins, and the other keys
      of the base stay. buildImageDataset sets Explicit VR Little Endian
      when the merged _meta has no TransferSyntaxUID (IMG-USR-2). The
      video builders now also keep the other _meta keys (see "One
      _meta rule for each builder" below).
    • Reason: the intended behaviour changed. A caller that adds one
      _meta key must not lose the transfer syntax.
  • The result _meta is a copy (encapsulate, encapsulatePdf,
    buildImageDataset)
    • Old (64992a8): the _meta of the result was the same object as the
      _meta override of the caller. A change to the result _meta also
      changed the object of the caller.
    • New: the result _meta is a new object. The _meta override of the
      caller does not change.
    • Reason: the intended behaviour changed. The builder must not share a
      mutable object with the caller.
  • The identity guard is removed (CORE-USR-4, CORE-IMP-1, ENC-USR-9,
    IMG-USR-6, VID-USR-1)
    • Old (64992a8): createInstance removed SOPInstanceUID,
      SOPClassUID, InstanceNumber, MediaStorageSOPInstanceUID, and
      MediaStorageSOPClassUID (INSTANCE_IDENTITY_KEYS) from the
      inherited attributes. A custom levels that listed these keywords
      did not copy them. CORE-USR-4 said "The result never gets the
      identity of instance".
    • New: the inherited attributes are exactly
      copyAttributesByLevel(instance, dataLevel, { levels }). The
      default levels do not hold the identity, so the result does not get
      it. A custom levels copies each identity keyword that it lists.
      An override still wins (CORE-USR-6). With predecessor: true and a
      base that includes predecessorBase (the encapsulated bases, see
      the last section), PredecessorDocumentsSequence still holds the
      identity of instance. The InstanceNumber rule (CORE-USR-5) does
      not change.
      CONSISTENCY_KEYS stays ["Modality"], so an inherited
      SOPClassUID gives no warning.
    • Reason: the intended behaviour changed. copyAttributesByLevel
      copies what the level list says, and gives the correct value. An
      extra removal only makes the code more complex. The behaviour is
      the same as at origin/1.0-beta and at 7c9e118.
encapsulatePdf (ENC-USR-n)
  • baseDicom: undefined keeps the PDF base
    • Old (64992a8): encapsulatePdf(bytes, { baseDicom: undefined }) used
      encapsulatedBase. The result had no SOPClassUID and no MIME
      type.
    • New: a baseDicom of undefined uses encapsulatedPdfBase, the
      same as no baseDicom.
    • Reason: the description was wrong. An undefined option means "the
      default".
buildImageDataset (IMG-USR-2, IMG-USR-8)
  • The geometry keywords in overrides (IMG-USR-2)
    • Old (64992a8): a geometry keyword at the top level of the options
      threw the error "comes from the decoded image and cannot be
      overridden".
    • New: the builder sets the geometry from the decoded image after
      createInstance. The value from the decoded image replaces a
      geometry keyword in overrides, with no error and no warning. This
      rule applies to each form of overrides. This is the payload rule
      of CORE-USR-13, the same as VID-USR-2. A geometry keyword at the top
      level has no effect (CORE-USR-7). The builder does not check the
      8-hex tag form of a geometry keyword, for example "00280010". The
      JSDoc names the keyword form only.
    • Reason: the intended behaviour changed. A geometry override is a
      value that the builder replaces, and does not use, so it gives no
      error (CORE-IMP-11).
  • lossy without derivedFrom (IMG-USR-8)
    • Old (64992a8): the builder logged the warning "lossy applies only
      with derivedFrom, and is ignored".
    • New: lossy without derivedFrom has no effect, and the builder
      logs no warning.
    • Reason: the intended behaviour changed. Without derivedFrom, the
      builder does not use lossy, so lossy gives no warning
      (CORE-IMP-11).
  • Only the decoded geometry is written (IMG-USR-2)
    • Old (64992a8): the builder removed each geometry attribute of the
      base, of instance, and of the overrides. Then the builder wrote
      every geometry attribute, with a default for each value that the
      decoded image did not give: SamplesPerPixel 1,
      PhotometricInterpretation MONOCHROME2 (or RGB for 3 samples),
      BitsStored = BitsAllocated, HighBit = BitsStored - 1,
      PixelRepresentation 0, and PlanarConfiguration 0. For
      encapsulated, BitsAllocated was 8 and NumberOfFrames was 1.
      decodedImage.rows and decodedImage.columns were required.
    • New: the builder writes a geometry attribute only when the decoded
      image gives it: a decodedImage field, BitsAllocated from the
      typed array, PixelRepresentation 1 from a signed typed array, or
      NumberOfFrames from encapsulated.frames.length. The decoded value
      replaces the value from the base, from instance, or from
      overrides. For an attribute that the decoded image does not give,
      the builder writes nothing, and the value from the base, from
      instance, or from overrides stays. The builder removes no
      geometry attribute, and writes no default.
    • New: HighBit is a decoded value when the decoded image determines
      it. The builder writes decodedImage.highBit when it is given.
      Otherwise, when decodedImage gives bitsStored, the builder writes
      HighBit = bitsStored - 1. Otherwise, the builder writes no
      HighBit, and the value from the base, from instance, or from
      overrides stays. The builder does not calculate HighBit from
      BitsAllocated, or from a BitsStored of the base, of instance,
      or of overrides.
    • New: the checks use the effective values (the decoded value, else
      the merged value). Rows and Columns can come from the merged
      dataset, and must be positive integers. For the pixel-length check
      only, an absent SamplesPerPixel or NumberOfFrames is 1. The
      builder does not write these values.
    • New: a decodedImage.numberOfFrames of 1 is written. A count of 1
      from encapsulated.frames.length alone is not written, except to
      replace an existing NumberOfFrames.
    • New: PlanarConfiguration uses the effective SamplesPerPixel. At
      64992a8, the builder wrote PlanarConfiguration when the decoded
      samplesPerPixel was more than 1. Now the builder writes a decoded
      planarConfiguration when the effective SamplesPerPixel (the
      decoded value, else the merged value) is more than 1. Thus
      overrides: { SamplesPerPixel: 3 } with a decoded
      planarConfiguration writes PlanarConfiguration. A decoded
      samplesPerPixel of 1 with a decoded planarConfiguration writes
      no PlanarConfiguration, as at 64992a8.
    • Reason: the intended behaviour changed. A caller can give the
      photometric attributes in overrides, or inherit them, when the
      decoder does not give them, for example MONOCHROME1 with
      BitsStored 12 over 16-bit pixels.
  • ConversionType is a base value (IMG-USR-5, IMG-IMP-3)
    • Old (64992a8): after createInstance, the builder set
      ConversionType to "WSD" when the result was Secondary Capture
      and had no ConversionType. Thus
      overrides: { ConversionType: undefined } and
      overrides: { ConversionType: "" } both gave "WSD".
    • New: secondaryCaptureImageBase sets ConversionType: "WSD". The
      builder writes no default after createInstance. An override
      replaces the value, an undefined override removes it, and ""
      gives a Type 2 empty value (CORE-USR-6, CORE-USR-8). A custom base
      without secondaryCaptureImageBase gives no ConversionType, the
      same as for ImageType. A Secondary Capture SOPClassUID override
      on another base no longer adds "WSD".
    • Reason: the description was wrong. ConversionType is not a payload
      attribute, so an override must win (CORE-USR-6).
      @dcmjs-org/encapsulated already had ConversionType as a base
      value (encapsulatedDocumentBase).
  • A floating-point pixels throws (IMG-USR-9)
    • Old: a Float32Array gave BitsAllocated 32, and a Float64Array
      gave BitsAllocated 64. The writer wrote the float bytes as integer
      pixels, with no error.
    • New: a Float32Array or a Float64Array as pixels throws the
      error "buildImageDataset: decodedImage.pixels is a Float32Array;
      DICOM integer pixel data needs an integer typed array" (the name of
      the array class is in the message). The check is in
      decodedGeometry, where the builder uses the typed array for
      BitsAllocated and PixelRepresentation.
    • Reason: the intended behaviour changed. A usage-flow check
      (CORE-IMP-11): a wrong value gave a wrong file.
  • PixelRepresentation 1 for an Int32Array (IMG-USR-2)
    • Old: only an Int8Array or an Int16Array gave
      PixelRepresentation 1. An Int32Array gave no
      PixelRepresentation.
    • New: an Int32Array also gives PixelRepresentation 1, when
      decodedImage has no pixelRepresentation. A Uint32Array gives
      BitsAllocated 32, as before.
    • Reason: the description was wrong. A signed array holds signed
      pixels.
Validation rule (CORE-USR-7, CORE-IMP-11, all four packages)
  • The rule for checks replaces "no input checks"
    • Old (this round, before the change): CORE-USR-7 said "The functions
      do not check their inputs, except for the errors that a requirement
      names. The result of an input that is not correct is not defined."
      Six errors had no requirement.
    • New CORE-USR-7: the JSDoc states the input types, an extra option
      key has no effect, and a user requirement names each error that a
      function throws for a wrong input value.
    • New CORE-IMP-11: validation is part of the usage flow. A function
      checks a value where it uses the value, when a wrong value gives a
      wrong result. A function does not check the JS type of an input
      that the JSDoc declares, because the JSDoc gives the type, and a
      type check blocks a future input form (a stream, an async result,
      another source).
    • Reason: the description was wrong. The checks at the point of use
      protect the user from a wrong file, and are user guarantees.
  • Kept checks, now named in a user requirement
    • Unknown dataLevel: CORE-USR-3 (new text).
    • Predecessor reference keywords: CORE-USR-9. The
      hierarchicalReferences error is new text in CORE-USR-9.
    • encapsulatePdf without the %PDF- magic, and
      extractEncapsulatedPdf on a dataset that is not an Encapsulated
      PDF: ENC-USR-11 (new).
    • buildImageDataset: pixels and encapsulated together, an
      encapsulated without transferSyntaxUID or frames, Rows and
      Columns, the photometric interpretation against
      SamplesPerPixel, bitsAllocated against the typed array,
      numberOfFrames against the frames, and the pixel byte length:
      IMG-USR-9 (new; the list moved from IMG-USR-2).
    • parseJpegInfo (no SOI, no SOF, truncated SOF): IMG-USR-9.
    • derivedFrom keywords and an empty derivedFrom: IMG-USR-4 and
      IMG-USR-7, no change.
    • Unsupported codec: VID-USR-4, no change. fragmentBytes range:
      VID-USR-5, no change.
    • extractEncapsulatedVideo on a dataset that is not a video:
      VID-USR-6 (new text).
    • parseMp4Info errors (no ftyp, a malformed box, no moov, no
      video track, no mdhd, no sample description, a malformed stts,
      no frame rate): VID-USR-7 (new).
  • Removed checks (pure JS type checks)
    • Old (64992a8, and feat: @dcmjs-org/encapsulated — encapsulated PDF wrap and unwrap #577 for the core and encapsulated checks): each
      check below threw an error.
    • copyAttributesByLevel (and thus createInstance): "instance must
      be a naturalized dataset". A string instance now gives no
      inherited attributes. An empty array instance now fails with a
      TypeError in copyAttributesByLevel, where the code reads the
      first item. An instance that is not naturalized (for example DICOM
      JSON, {}, or a string) gives no inherited attributes, and the
      inherited levels get no new UID. The result then has no
      StudyInstanceUID, and with dataLevel: "series" also no
      SeriesInstanceUID. No error occurs. CORE-USR-12 now states this
      behaviour. The user decided to keep the behaviour (review 10, N1).
    • toExactArrayBuffer of @dcmjs-org/encapsulated: "encapsulate
      expects an ArrayBuffer or Uint8Array". A value that is not a view
      now goes through as it is. encapsulatePdf then throws the
      %PDF- error for most wrong values, and a TypeError for
      undefined. encapsulate gives no error for a wrong value.
    • buildImageDataset: "decodedImage.pixels must be a typed array",
      and the "expected an ArrayBuffer or typed array" error of its
      toExactArrayBuffer (pixels and frames). Without pixels and
      without encapsulated, the builder now fails with a TypeError
      where it reads pixels.BYTES_PER_ELEMENT. An ArrayBuffer as
      pixels gives a BitsAllocated of NaN, and the pixel-length
      error of IMG-USR-9.
    • buildImageDataset: the Array.isArray(encapsulated.frames) part
      of the encapsulated check. The check now tests that frames has
      a length.
    • Reason: the intended behaviour changed. A JS type check is the job
      of the JSDoc (CORE-IMP-11).
_meta and the other builder results (CORE-USR-10, CORE-USR-13)
  • The Modality warning tests the presence of the override
    (CORE-USR-10, ENC-USR-5)
    • Old (this round, before the change): the warning tested
      !overrides[key]. An override Modality of undefined, null, or
      "" gave the warning, but the result had no inherited Modality.
      At 64992a8, createInstance skipped an undefined override, so
      the warning was correct for undefined.
    • New: the warning tests Object.hasOwn(overrides, "Modality"). An
      override with each value, also undefined, null, or "",
      decides the result, and gives no warning. CORE-USR-10 adds "and
      overrides does not give Modality".
    • Reason: the description was wrong. CORE-USR-10 said that the
      builder keeps the inherited value, but the override replaced it.
  • One _meta rule for each builder (CORE-USR-13, CORE-IMP-7,
    ENC-USR-10, IMG-USR-2, VID-USR-2)
    • Old (this round, before the change): encapsulate copied _meta,
      and changed no key. buildImageDataset copied _meta, and set
      only the transfer syntax. buildVideoDataset replaced all of
      _meta, so an ImplementationVersionName override did not stay.
    • New: the result _meta is a new object. A builder changes only
      _meta.TransferSyntaxUID, in the shape { Value: [uid] }, and
      keeps each other key of the merged _meta. buildVideoDataset
      now gives { ...dataset._meta, TransferSyntaxUID: { Value: [ts] } }.
    • Reason: the intended behaviour changed. CORE-USR-6 says that a
      caller that adds one _meta key keeps the others.
  • createVideoEventSource keeps the _meta of its dataset (VID-USR-2,
    CORE-IMP-7)
    • Old (pre-existing, also at 64992a8): datasetToMetaDict assigned
      the file meta group to the _meta of the returned dataset, in a
      flat shape (TransferSyntaxUID: "1.2.840.10008.1.2.4.104.1", plus
      MediaStorageSOPClassUID, FileMetaInformationVersion, and the
      others). A writer that read _meta.TransferSyntaxUID.Value[0] found
      no value.
    • New: datasetToMetaDict makes the file meta group in a local
      object. The returned dataset._meta is the _meta of
      buildVideoDataset. The fallback transfer syntax uses
      EXPLICIT_LITTLE_ENDIAN from @dcmjs-org/core.
    • Reason: the description was wrong. The return shape must be the
      same as the shape of buildVideoDataset.
  • The file meta group of createVideoEventSource keeps the other
    _meta keys (VID-USR-2)
    • Old (pre-existing, also at 64992a8): the file meta group had only
      the fixed keys. An ImplementationVersionName override of X stayed
      on the returned dataset._meta, but the file had dcmjs-0.0.
    • New: the file meta group gets each key of the dataset _meta (its
      Value[0]). createVideoEventSource always sets
      TransferSyntaxUID, MediaStorageSOPClassUID, and
      MediaStorageSOPInstanceUID from the dataset. It sets
      FileMetaInformationVersion, ImplementationClassUID, and
      ImplementationVersionName only when the dataset _meta has no
      value. Thus a caller can set these three keys, and other file meta
      keys, in overrides._meta. The returned dataset._meta does not
      change.
    • Reason: the intended behaviour changed. VID-USR-2 says that the
      builder keeps the other _meta keys, and the file must agree with
      the dataset.
  • The shape of an _meta value (CORE-USR-6): text only. Give each
    _meta value in the shape { Value: [value] }, for example
    _meta.TransferSyntaxUID = { Value: ["1.2.840.10008.1.2.1"] }.
  • buildVideoDataset writes no attribute for an absent mp4Info
    field (VID-USR-2)
    • Old: an mp4Info without, for example, cineRate gave
      CineRate: undefined in the result, and removed a CineRate
      override. postProcess had already run, so the key stayed.
    • New: the builder writes CineRate, FrameTime, NumberOfFrames,
      Rows, and Columns only when mp4Info gives the value. A
      parseMp4Info result always gives the fields, so only a
      caller-built mp4Info shows the change. mp4ByteLength stays
      required.
    • Reason: the intended behaviour changed. The same rule as the
      decoded geometry of buildImageDataset (IMG-USR-2).
Exports
  • PDF_MIME_TYPE is now in the index of @dcmjs-org/encapsulated.
  • normalizeFragmentBytes is no longer in the index of
    @dcmjs-org/video. It stays a module export of encapsulatedVideo.js
    for fromVideo.js and the tests. No other package on this branch uses
    it.

Changes since the pushed HEAD c8aa8a7

The base of this comparison is the pushed branch (HEAD c8aa8a7).

Image and video builders (CORE-USR-9, IMG-USR-10, VID-USR-8)
  • imageBase and videoBase do not include predecessorBase
    • Old (f875187..c8aa8a7): imageBase and videoBase included
      predecessorBase. With predecessor: true and an instance, an
      image or a video result had PredecessorDocumentsSequence. An
      instance without one of the four reference UIDs threw the
      predecessor error. CORE-USR-9 said "The default base of each builder
      has it."
    • New: only the encapsulated document bases (encapsulatedBase and
      encapsulatedPdfBase) include predecessorBase. With the default
      base, predecessor: true has no effect on buildImageDataset,
      buildVideoDataset, encapsulateVideo, and
      createVideoEventSource. The result has no
      PredecessorDocumentsSequence, and the builder throws no
      predecessor error. A caller can add the block to a custom base, for
      example combineBases(imageBase, predecessorBase). CORE-USR-9 now
      says that predecessorBase is an optional base block. IMG-USR-10
      and VID-USR-8 are new.
    • Reason: the intended behaviour changed. predecessorBase is one
      more way to add default attributes, and not a feature that every
      builder must support. PredecessorDocumentsSequence replaces an
      older document, so the encapsulated documents use the block now.
      Future document types can also add the block to their default base.
      predecessorBase, hierarchicalReferences, and the predecessor
      control stay in @dcmjs-org/core. Before f875187, the image and
      video builders had no predecessorBase either.

🤖 Generated with Claude Code

awatson1978 and others added 15 commits October 2, 2026 13:02
The package shell for the video wave: name, entry point, MIT license,
repository directory, and the @dcmjs-org/core workspace dependency. The
image-module index exports only the header parsers for now; the dataset
builder joins it in the next slice.

Co-Authored-By: Claude Fable 5 <[email protected]>
Verbatim from v2.0-development: src/image/jpegInfo.js (SOF geometry and
the JPEG transfer syntax mapping), src/image/mp4Info.js (the ISO BMFF box
walk over a random-access reader), the makeTinyMp4 synthesized-fixture
helper, and the ported mp4Info suite. Only the test import paths moved
with the files; no behavior changed in this commit — review findings 9
and 15 are fixed on top, each with its regression observed red first.

Co-Authored-By: Claude Fable 5 <[email protected]>
Review finding 9 (HIGH): the marker-walk guard only required four readable
bytes, but the SOF fields span bytes[offset+4 .. offset+9]. Out-of-range
reads coerce to 0 in the bitwise math, so the review map's vector — a
480x640 JPEG cut one byte into the width field — returned columns 512
instead of throwing, and a file cut right after the length field returned
rows 0, columns 0. The reader now validates that the declared SOF segment
fits inside the input (and is at least 8 bytes) before reading any field.

The new jpegInfo suite is hand-written (v2 carried no suite for this
file): the exact review vector, the cut-after-length shape, and valid
SOF0/SOF1/SOF2/SOF3 paths. Both finding tests were observed red against
the ported-unfixed reader before this fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
Review finding 15 (MED): the stts fallback loop trusted the raw uint32
entry_count. With stsz sample_count 0 and stts entry_count 0x00FFFFFF the
parser spun 16.7 million iterations over zero-coerced reads past the box
and fabricated numberOfFrames/frameRate from unrelated moov bytes; at
0xFFFFFFFF that is roughly 40 seconds of blocked thread. The loop now
requires 16 + entryCount * 8 to fit inside the stts box and throws on the
mismatch. The regression corrupts a synthesized MP4 exactly that way and
asserts the parse rejects in under two seconds — observed red (the
unfixed parser resolved with fabricated values) before this fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
feat(video): scaffold @dcmjs-org/video with the JPEG and MP4 header parsers
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]>
feat(video): port buildImageDataset with the encapsulated frame-count fix
Verbatim from v2.0-development src/encapsulated/encapsulatedVideo.js and
its 8-test suite, with one mechanical adjustment for the package
boundary: DicomMetaDictionary and isVideoTransferSyntax now come from
@dcmjs-org/core instead of relative paths. buildVideoDataset shapes the
Supplement 225 Video Photographic Image shell (XC modality, cine timing,
the (7FE0,0003) uint64 total length as a BigInt), encapsulateVideo
splits the MP4 into fragment-sized exact ArrayBuffer slices, and
extractEncapsulatedVideo concatenates fragments and truncates to the
declared length so the odd-fragment pad byte drops on extraction.

Co-Authored-By: Claude Fable 5 <[email protected]>
The video half of v2's encapsulated index only — the PDF half
(encapsulatedPdf) belongs to the media wave.

Co-Authored-By: Claude Fable 5 <[email protected]>
feat(video): port the buffered video encapsulation layer
@dcmjs-org/parser joins the dependencies — the video event source imports
fromDataSet and EVENT_STREAM_VOCABULARY — and @dcmjs-org/generator the
devDependencies (StreamingPart10Writer, tests only). Deliberately NOT
@dcmjs-org/legacy: this package stays off the legacy surface.

Co-Authored-By: Claude Fable 5 <[email protected]>
createVideoEventSource — MP4 → contract events with the Supplement 225
dataset shell replayed first and the stream emitted as encapsulated
PixelData fragments, one in memory at a time, backpressure between
fragments via awaitDrain().

The run loop, exactFragment, withoutEndDataSet and sortDict are verbatim
from v2.0-development src/eventStream/fromVideo.js. One seam is reworked
and hand-written: v2 imported datasetToDict from what is now
@dcmjs-org/legacy, which this package must not depend on, so a local
datasetToMetaDict helper mints the same file meta group (element list and
implementation UID copied from legacy's datasetToDict) and denaturalizes
both halves via core's DicomMetaDictionary — returning the plain
{ meta, dict } shape, which is all parser's fromDataSet reads.

The suite is the v2 fromVideo suite reworked off the DicomEventStream
facade (media wave): the source drives StreamingPart10Writer directly
and reads back through fromPart10/fromPart10Stream + NaturalizedListener
+ extractEncapsulatedVideo. All load-bearing assertions carried over:
byte-identical round trips (buffered and streaming reader), the
(7FE0,0003) UV uint64 pinned on the wire, the Sup 225 fragment layout,
single-endDataSet ordering, per-fragment backpressure, and the ffmpeg
corrective error. The facade-specific toVideo/fromPdf case stays with
the media wave, as does fromImage.test.js.

Co-Authored-By: Claude Fable 5 <[email protected]>
feat(video): port the video event source, legacy-free
…ented

GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of
>=3.0.4, but no such braces release exists on the registry, so there is
nothing to override to. Every path is dev tooling; braces never reaches
the published packages. Same entry the fhir staging branch already
carries (#589) — remove it the moment a patched braces ships.

Co-Authored-By: Claude Fable 5 <[email protected]>
(cherry picked from commit 7261970)
Per review on #542: the guide existed to hold the staged-landing PR
descriptions to one standard, and every description is now written.
Removed rather than kept stale; git history preserves it if the team
wants it back later. The PR template keeps the one-line spirit of it.

Co-Authored-By: Claude Fable 5 <[email protected]>
(cherry picked from commit 2a5935e)
@awatson1978 awatson1978 changed the title feat: @dcmjs-org/video assembly — MP4 wrapping, image datasets, and the video event source feat: @dcmjs-org/video — MP4 wrapping, image datasets, and the video event source Oct 6, 2026
…video

# Conflicts:
#	pnpm-lock.yaml
#	pnpm-workspace.yaml
@awatson1978
awatson1978 marked this pull request as ready for review October 19, 2026 06:50
PR #588 review (conversation with Bill): split the lightweight, codec-free
image building out of video so a consumer that only needs to build image
instances doesn't pull the heavy MP4/video machinery, and SOP-specific image
info stays out of core.

New @dcmjs-org/imaging (depends on core only):
- buildImageDataset + SECONDARY_CAPTURE_SOP_CLASS_UID (moved from video/src/image)
- parseJpegInfo (moved)
- h264TransferSyntaxUID (extracted from video/src/image/mp4Info.js into src/h264.js)

@dcmjs-org/video now depends on @dcmjs-org/imaging:
- parseMp4Info stays (MP4 container parsing is video-domain) and imports
  h264TransferSyntaxUID from imaging
- src/image/ and the public surface trimmed to parseMp4Info + the video
  encapsulation/streaming; descriptions/comments updated

Tests moved with their code (buildImageDataset, jpegInfo); the
h264TransferSyntaxUID describe block moved to packages/imaging/test/h264.test.js.
RELEASE_PLAN gains an imaging row and notes the landing order (imaging with/before
video). Full suite 954 passed / 11 skipped / 0 failed.

Follow-ons (separate branches): media exports an imaging namespace and sources the
image builders from imaging; fhir->imaging deferred until fhir builds images.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978 awatson1978 changed the title feat: @dcmjs-org/video — MP4 wrapping, image datasets, and the video event source feat: @dcmjs-org/video and @dcmjs-org/imaging Oct 19, 2026
wayfarer3130 and others added 3 commits October 20, 2026 17:03
buildImageDataset and buildVideoDataset now use createInstance from
@dcmjs-org/core, the same creator pattern as @dcmjs-org/encapsulated:

- New base blocks: imageBase / secondaryCaptureImageBase and
  videoBase / videoPhotographicBase, each with predecessorBase.
- The instance, dataLevel, levels, predecessor and baseDicom options pass
  through to createInstance. Payload attributes (geometry, stream values,
  transfer syntax) are set after it.
- createInstance writes only DICOM attributes (keywords, tags, _meta/_vrMap)
  from the overrides; other keys are dropped with a warning. Each builder
  removes its own control keys first.
- The video base no longer sets StudyID 1; a new study gets the Type 2
  empty StudyID from studyBase.
- buildImageDataset reuses the core EXPLICIT_LITTLE_ENDIAN and merges _vrMap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The attribute filter now accepts a keyword that lookupRegisteredTagByName
finds, as denaturalizeDataset does. Before this fix, such an override was
dropped with a warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 and others added 3 commits October 20, 2026 21:09
All builders (encapsulate, buildVideoDataset, buildImageDataset) take the
same options: createInstance options, attribute overrides, and their own
payload control keys. packages/core/README.md documents the shared model
(CORE-USR/CORE-IMP); the package READMEs refer to it.

core createInstance:
- never copies the identity of `instance` (SOPInstanceUID, SOPClassUID,
  InstanceNumber, media storage UIDs), also with a custom `levels`
- InstanceNumber at series level is the largest prior number + 1
- Type 2 empty StudyDate/StudyTime/SeriesNumber for an inherited level
- skips undefined overrides; rejects a DICOM JSON `instance`
- nextSeriesNumberBase counts only IS integers

imaging:
- remove the `metadata` option and the old `derivedFrom` shapes
- new derivedImageAttributes / derivedImageBase: derivation from one or
  more naturalized instances, as a base block; lossy history is kept
- ImageType ORIGINAL\PRIMARY is a base value

video: README with VID requirements; control keys removed before the call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cess

All builders take one option shape: the createInstance controls
(baseDicom, instance, dataLevel, levels, predecessor, postProcess), their
own control keys, and `overrides`. `overrides` is a naturalized DICOM
provider with the same forms as baseDicom; its attributes go only into the
result. An extra option key has no effect.

core createInstance:
- baseDicom resolves, then overrides; merge base < inherited < overrides,
  with a key merge of _meta; then postProcess (default
  removeUndefinedAttributes, top level only), so an undefined override
  removes the attribute
- `instance` gives the attributes that `levels` lists; at dataLevel
  series the new InstanceNumber is the sample (first) instance's + 1
- Modality warning uses a presence check of the override
- validation is part of the usage flow (CORE-IMP-11); pure type checks
  removed

encapsulated: export PDF_MIME_TYPE; a builder sets only
_meta.TransferSyntaxUID on a copy of _meta.

imaging: geometry, HighBit and PixelRepresentation are written only when
the decoded image gives them; ConversionType is a base value; a float
pixel array throws.

video: no attribute for a missing mp4Info field; createVideoEventSource
keeps the returned _meta and the caller's file meta keys;
normalizeFragmentBytes is no longer exported.

eslint: no-unused-vars ignoreRestSiblings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
predecessorBase is an optional base block in core, one more way to add
default attributes. The encapsulated document bases include it. imageBase
and videoBase no longer include it, so `predecessor: true` has no effect
with those default bases. A caller can add the block, for example
combineBases(imageBase, predecessorBase).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 merged commit 9f74889 into 1.0-beta Oct 21, 2026
9 checks passed
wayfarer3130 added a commit that referenced this pull request Oct 21, 2026
…media

1.0-beta now has #577 (@dcmjs-org/encapsulated) and #585 (@dcmjs-org/video
and @dcmjs-org/imaging, built on createInstance). The merge takes the
video package from 1.0-beta and moves the media wave onto the new packages:

- remove packages/pdfs; @dcmjs-org/encapsulated replaces it
- the media bundle and the DicomEventStream factories import from
  @dcmjs-org/encapsulated, @dcmjs-org/imaging, and @dcmjs-org/video
- the bundle re-exports the base blocks and the generic encapsulate, and
  drops normalizeFragmentBytes, which the video package no longer exports
- the factories pass the createInstance options to the builders; the
  DICOM attributes go in `overrides`, and the tests use that form
- a new test checks that fromPdf passes instance and dataLevel through

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 added a commit that referenced this pull request Oct 21, 2026
Take the 1.0-beta design for every package that the assemblies #577,
#585, #588 and #584 merged: @dcmjs-org/encapsulated replaces
@dcmjs-org/pdfs, @dcmjs-org/imaging holds buildImageDataset and
parseJpegInfo, and @dcmjs-org/media and @dcmjs-org/fhir come from
1.0-beta unchanged.

Keep only the wrapper on top: the @dcmjs-org/dcmjs rename without
"private", the media/encapsulated/image/fhir namespaces in src/index.js,
the root dependency on @dcmjs-org/media, test/bundle-size.test.js, and
the pnpm 12.9.1 pin. The dcmjs.fhir namespace tests move from
packages/fhir/test to test/fhirNamespace.test.js, so the package tests
stay off the root wrapper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

2 participants