@dcmjs-org/imaging 1.0.0-beta.3 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/License.txt +22 -0
- package/package.json +6 -2
- package/test/buildImageDataset.test.js +0 -550
- package/test/h264.test.js +0 -29
- package/test/jpegInfo.test.js +0 -154
package/License.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Steve Pieper
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcmjs-org/imaging",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Lightweight, codec-free image building for dcmjs: turn already-decoded pixels into a conformant DICOM image instance, and inspect JPEG/H.264 headers without decoding. The heavy MP4/video processing lives in @dcmjs-org/video",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"repository": {
|
|
8
12
|
"type": "git",
|
|
@@ -10,6 +14,6 @@
|
|
|
10
14
|
"directory": "packages/imaging"
|
|
11
15
|
},
|
|
12
16
|
"dependencies": {
|
|
13
|
-
"@dcmjs-org/core": "1.0.0-beta.
|
|
17
|
+
"@dcmjs-org/core": "1.0.0-beta.4"
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
// test/buildImageDataset.test.js
|
|
2
|
-
//
|
|
3
|
-
// buildImageDataset: decoded pixels -> a conformant naturalized image
|
|
4
|
-
// dataset, with the options of encapsulate. The load-bearing rules: the
|
|
5
|
-
// geometry comes from the pixels, and derivedFrom yields a DERIVED\SECONDARY
|
|
6
|
-
// result with a new SOPInstanceUID.
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
combineBases,
|
|
10
|
-
DATA_LEVELS,
|
|
11
|
-
extendDataLevels,
|
|
12
|
-
log,
|
|
13
|
-
predecessorBase,
|
|
14
|
-
validationLog
|
|
15
|
-
} from "@dcmjs-org/core";
|
|
16
|
-
import {
|
|
17
|
-
buildImageDataset,
|
|
18
|
-
derivedImageAttributes,
|
|
19
|
-
derivedImageBase,
|
|
20
|
-
imageBase,
|
|
21
|
-
SECONDARY_CAPTURE_SOP_CLASS_UID
|
|
22
|
-
} from "../src/index.js";
|
|
23
|
-
|
|
24
|
-
validationLog.setLevel(5);
|
|
25
|
-
|
|
26
|
-
const MR_SOP_CLASS_UID = "1.2.840.10008.5.1.4.1.1.4";
|
|
27
|
-
const SOURCE_SOP_INSTANCE_UID = "2.25.111222333444";
|
|
28
|
-
|
|
29
|
-
function grayPixels(rows = 4, columns = 4) {
|
|
30
|
-
return {
|
|
31
|
-
pixels: new Uint8Array(rows * columns).fill(128),
|
|
32
|
-
rows,
|
|
33
|
-
columns
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("createInstance options", () => {
|
|
38
|
-
test("instance and dataLevel place the image in an existing series", () => {
|
|
39
|
-
const source = {
|
|
40
|
-
PatientID: "P1",
|
|
41
|
-
StudyInstanceUID: "2.25.1",
|
|
42
|
-
SeriesInstanceUID: "2.25.2",
|
|
43
|
-
SOPClassUID: SECONDARY_CAPTURE_SOP_CLASS_UID,
|
|
44
|
-
SOPInstanceUID: "2.25.3",
|
|
45
|
-
Modality: "OT"
|
|
46
|
-
};
|
|
47
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
48
|
-
instance: source,
|
|
49
|
-
dataLevel: "series",
|
|
50
|
-
predecessor: true
|
|
51
|
-
});
|
|
52
|
-
expect(dataset.PatientID).toBe("P1");
|
|
53
|
-
expect(dataset.StudyInstanceUID).toBe("2.25.1");
|
|
54
|
-
expect(dataset.SeriesInstanceUID).toBe("2.25.2");
|
|
55
|
-
expect(dataset.SOPInstanceUID).not.toBe("2.25.3");
|
|
56
|
-
// imageBase has no predecessorBase (IMG-USR-10).
|
|
57
|
-
expect(dataset).not.toHaveProperty("PredecessorDocumentsSequence");
|
|
58
|
-
expect(dataset.instance).toBeUndefined();
|
|
59
|
-
expect(dataset.dataLevel).toBeUndefined();
|
|
60
|
-
|
|
61
|
-
// A caller adds predecessorBase to the base (CORE-USR-9).
|
|
62
|
-
const replacement = buildImageDataset(grayPixels(), {
|
|
63
|
-
baseDicom: combineBases(imageBase, predecessorBase),
|
|
64
|
-
instance: source,
|
|
65
|
-
dataLevel: "series",
|
|
66
|
-
predecessor: true
|
|
67
|
-
});
|
|
68
|
-
expect(
|
|
69
|
-
replacement.PredecessorDocumentsSequence[0]
|
|
70
|
-
.ReferencedSeriesSequence[0].ReferencedSOPSequence[0]
|
|
71
|
-
.ReferencedSOPInstanceUID
|
|
72
|
-
).toBe("2.25.3");
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("defaults (no instance)", () => {
|
|
77
|
-
const dataset = buildImageDataset(grayPixels());
|
|
78
|
-
|
|
79
|
-
test("Secondary Capture scaffold with minted UIDs", () => {
|
|
80
|
-
expect(dataset.SOPClassUID).toBe(SECONDARY_CAPTURE_SOP_CLASS_UID);
|
|
81
|
-
expect(dataset.SOPInstanceUID).toMatch(/^2\.25\./);
|
|
82
|
-
expect(dataset.StudyInstanceUID).toMatch(/^2\.25\./);
|
|
83
|
-
expect(dataset.SeriesInstanceUID).toMatch(/^2\.25\./);
|
|
84
|
-
expect(dataset.Modality).toBe("OT");
|
|
85
|
-
expect(dataset.ConversionType).toBe("WSD");
|
|
86
|
-
expect(dataset.ImageType).toEqual(["ORIGINAL", "PRIMARY"]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("Type-2 patient/study attributes are present and empty", () => {
|
|
90
|
-
for (const keyword of [
|
|
91
|
-
"PatientName",
|
|
92
|
-
"PatientID",
|
|
93
|
-
"PatientBirthDate",
|
|
94
|
-
"PatientSex",
|
|
95
|
-
"AccessionNumber",
|
|
96
|
-
"StudyID"
|
|
97
|
-
]) {
|
|
98
|
-
expect(dataset[keyword]).toBe("");
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// API: the builder writes only the geometry that the decoded input
|
|
103
|
-
// gives, and invents no default (IMG-USR-2).
|
|
104
|
-
test("only the decoded geometry, with no invented defaults", () => {
|
|
105
|
-
expect(dataset.Rows).toBe(4);
|
|
106
|
-
expect(dataset.Columns).toBe(4);
|
|
107
|
-
expect(dataset.BitsAllocated).toBe(8);
|
|
108
|
-
for (const keyword of [
|
|
109
|
-
"SamplesPerPixel",
|
|
110
|
-
"PhotometricInterpretation",
|
|
111
|
-
"BitsStored",
|
|
112
|
-
"HighBit",
|
|
113
|
-
"PixelRepresentation"
|
|
114
|
-
]) {
|
|
115
|
-
expect(dataset[keyword]).toBeUndefined();
|
|
116
|
-
}
|
|
117
|
-
expect(dataset.PlanarConfiguration).toBeUndefined();
|
|
118
|
-
expect(dataset.NumberOfFrames).toBeUndefined();
|
|
119
|
-
expect(dataset._vrMap.PixelData).toBe("OB");
|
|
120
|
-
expect(dataset.PixelData.byteLength).toBe(16);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe("decoded geometry replaces, absent geometry stays", () => {
|
|
125
|
-
// User experience: a caller that decodes only the size and the pixels
|
|
126
|
-
// keeps the photometric attributes of the series or of an override,
|
|
127
|
-
// and the decoded values replace the overrides (IMG-USR-2).
|
|
128
|
-
test("decoded Rows/Columns/BitsAllocated replace; the rest stays", () => {
|
|
129
|
-
const dataset = buildImageDataset(grayPixels(4, 4), {
|
|
130
|
-
instance: {
|
|
131
|
-
StudyInstanceUID: "1.2.3.4",
|
|
132
|
-
SeriesInstanceUID: "1.2.3.4.1",
|
|
133
|
-
Rows: 999,
|
|
134
|
-
PhotometricInterpretation: "MONOCHROME1"
|
|
135
|
-
},
|
|
136
|
-
dataLevel: "series",
|
|
137
|
-
levels: extendDataLevels(DATA_LEVELS, {
|
|
138
|
-
series: ["Rows", "PhotometricInterpretation"]
|
|
139
|
-
}),
|
|
140
|
-
overrides: {
|
|
141
|
-
Columns: 8,
|
|
142
|
-
BitsAllocated: 16,
|
|
143
|
-
SamplesPerPixel: 1,
|
|
144
|
-
BitsStored: 7
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
expect([
|
|
148
|
-
dataset.Rows,
|
|
149
|
-
dataset.Columns,
|
|
150
|
-
dataset.BitsAllocated,
|
|
151
|
-
dataset.PhotometricInterpretation,
|
|
152
|
-
dataset.SamplesPerPixel,
|
|
153
|
-
dataset.BitsStored,
|
|
154
|
-
dataset.HighBit
|
|
155
|
-
]).toEqual([4, 4, 8, "MONOCHROME1", 1, 7, undefined]);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// API: an override or a base value without a decoded value stays, and
|
|
159
|
-
// the decoded values replace the base values (IMG-USR-2).
|
|
160
|
-
test("overrides MONOCHROME1 and BitsStored 12 stay over 16-bit pixels", () => {
|
|
161
|
-
const dataset = buildImageDataset(
|
|
162
|
-
{ pixels: new Uint16Array(2 * 3), rows: 2, columns: 3 },
|
|
163
|
-
{
|
|
164
|
-
baseDicom: combineBases(imageBase, {
|
|
165
|
-
Rows: 512,
|
|
166
|
-
BitsAllocated: 8,
|
|
167
|
-
SamplesPerPixel: 1,
|
|
168
|
-
PixelRepresentation: 0
|
|
169
|
-
}),
|
|
170
|
-
overrides: {
|
|
171
|
-
PhotometricInterpretation: "MONOCHROME1",
|
|
172
|
-
BitsStored: 12
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
expect([
|
|
177
|
-
dataset.Rows,
|
|
178
|
-
dataset.Columns,
|
|
179
|
-
dataset.BitsAllocated,
|
|
180
|
-
dataset.PhotometricInterpretation,
|
|
181
|
-
dataset.BitsStored,
|
|
182
|
-
dataset.SamplesPerPixel,
|
|
183
|
-
dataset.PixelRepresentation,
|
|
184
|
-
dataset.HighBit,
|
|
185
|
-
dataset._vrMap.PixelData
|
|
186
|
-
]).toEqual([2, 3, 16, "MONOCHROME1", 12, 1, 0, undefined, "OW"]);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// API: the checks use the final values, also the values of overrides.
|
|
190
|
-
test("an override SamplesPerPixel that disagrees with the pixels throws", () => {
|
|
191
|
-
expect(() =>
|
|
192
|
-
buildImageDataset(grayPixels(4, 4), {
|
|
193
|
-
overrides: { SamplesPerPixel: 3 }
|
|
194
|
-
})
|
|
195
|
-
).toThrow(/16 bytes but 4x4x3 at 8 bits needs 48/);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe("16-bit and color", () => {
|
|
200
|
-
// API: a decoded bitsStored without highBit gives HighBit = bitsStored - 1.
|
|
201
|
-
test("Uint16Array yields 16-bit OW", () => {
|
|
202
|
-
const dataset = buildImageDataset({
|
|
203
|
-
pixels: new Uint16Array(4 * 4),
|
|
204
|
-
rows: 4,
|
|
205
|
-
columns: 4,
|
|
206
|
-
bitsStored: 12
|
|
207
|
-
});
|
|
208
|
-
expect(dataset.BitsAllocated).toBe(16);
|
|
209
|
-
expect(dataset.BitsStored).toBe(12);
|
|
210
|
-
expect(dataset.HighBit).toBe(11);
|
|
211
|
-
expect(dataset._vrMap.PixelData).toBe("OW");
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test("Int16Array defaults to signed PixelRepresentation", () => {
|
|
215
|
-
const dataset = buildImageDataset({
|
|
216
|
-
pixels: new Int16Array(4),
|
|
217
|
-
rows: 2,
|
|
218
|
-
columns: 2
|
|
219
|
-
});
|
|
220
|
-
expect(dataset.PixelRepresentation).toBe(1);
|
|
221
|
-
// API: a signed 32-bit array is also signed (IMG-USR-2).
|
|
222
|
-
expect(
|
|
223
|
-
buildImageDataset({
|
|
224
|
-
pixels: new Int32Array(4),
|
|
225
|
-
rows: 2,
|
|
226
|
-
columns: 2
|
|
227
|
-
}).PixelRepresentation
|
|
228
|
-
).toBe(1);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("RGB emits PlanarConfiguration", () => {
|
|
232
|
-
const dataset = buildImageDataset({
|
|
233
|
-
pixels: new Uint8Array(2 * 2 * 3),
|
|
234
|
-
rows: 2,
|
|
235
|
-
columns: 2,
|
|
236
|
-
samplesPerPixel: 3,
|
|
237
|
-
photometricInterpretation: "RGB",
|
|
238
|
-
planarConfiguration: 0
|
|
239
|
-
});
|
|
240
|
-
expect(dataset.PhotometricInterpretation).toBe("RGB");
|
|
241
|
-
expect(dataset.PlanarConfiguration).toBe(0);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
describe("validation", () => {
|
|
246
|
-
test("pixel length mismatch reports expected vs actual", () => {
|
|
247
|
-
expect(() =>
|
|
248
|
-
buildImageDataset({
|
|
249
|
-
pixels: new Uint8Array(10),
|
|
250
|
-
rows: 4,
|
|
251
|
-
columns: 4,
|
|
252
|
-
samplesPerPixel: 1
|
|
253
|
-
})
|
|
254
|
-
).toThrow(/10 bytes but 4x4x1 at 8 bits needs 16/);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test("bitsAllocated / typed-array mismatch throws", () => {
|
|
258
|
-
expect(() =>
|
|
259
|
-
buildImageDataset({
|
|
260
|
-
pixels: new Uint8Array(16),
|
|
261
|
-
rows: 4,
|
|
262
|
-
columns: 4,
|
|
263
|
-
bitsAllocated: 16
|
|
264
|
-
})
|
|
265
|
-
).toThrow(/does not match the 8-bit typed array/);
|
|
266
|
-
// API: float pixels throw, and write no integer pixels (IMG-USR-9).
|
|
267
|
-
expect(() =>
|
|
268
|
-
buildImageDataset({
|
|
269
|
-
pixels: new Float32Array(4),
|
|
270
|
-
rows: 2,
|
|
271
|
-
columns: 2
|
|
272
|
-
})
|
|
273
|
-
).toThrow(/needs an integer typed array/);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("photometric vs samplesPerPixel mismatch throws", () => {
|
|
277
|
-
expect(() =>
|
|
278
|
-
buildImageDataset({
|
|
279
|
-
pixels: new Uint8Array(16),
|
|
280
|
-
rows: 4,
|
|
281
|
-
columns: 4,
|
|
282
|
-
samplesPerPixel: 1,
|
|
283
|
-
photometricInterpretation: "RGB"
|
|
284
|
-
})
|
|
285
|
-
).toThrow(/RGB requires samplesPerPixel 3/);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
test("pixels plus encapsulated throws", () => {
|
|
289
|
-
expect(() =>
|
|
290
|
-
buildImageDataset(grayPixels(), {
|
|
291
|
-
encapsulated: {
|
|
292
|
-
transferSyntaxUID: "1.2.840.10008.1.2.4.50",
|
|
293
|
-
frames: [new Uint8Array(4)]
|
|
294
|
-
}
|
|
295
|
-
})
|
|
296
|
-
).toThrow(/not both/);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe("overrides", () => {
|
|
301
|
-
// API: an override beats the value inherited from instance.
|
|
302
|
-
test("keyword overrides beat instance", () => {
|
|
303
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
304
|
-
instance: { PatientID: "998877", StudyInstanceUID: "1.2.3.4" },
|
|
305
|
-
overrides: { PatientID: "22446688", PatientName: "FOX^JANE" }
|
|
306
|
-
});
|
|
307
|
-
expect(dataset.StudyInstanceUID).toBe("1.2.3.4");
|
|
308
|
-
expect(dataset.PatientID).toBe("22446688");
|
|
309
|
-
expect(dataset.PatientName).toBe("FOX^JANE");
|
|
310
|
-
// API: an undefined override removes ConversionType (IMG-USR-5).
|
|
311
|
-
expect(
|
|
312
|
-
buildImageDataset(grayPixels(), {
|
|
313
|
-
overrides: { ConversionType: undefined }
|
|
314
|
-
})
|
|
315
|
-
).not.toHaveProperty("ConversionType");
|
|
316
|
-
// API: Rows and Columns come from the merged dataset when the
|
|
317
|
-
// decoded image does not give them (IMG-USR-9).
|
|
318
|
-
expect(
|
|
319
|
-
buildImageDataset(
|
|
320
|
-
{ pixels: new Uint8Array(6) },
|
|
321
|
-
{ overrides: { Rows: 2, Columns: 3 } }
|
|
322
|
-
).Rows
|
|
323
|
-
).toBe(2);
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
describe("derived-instance conformance", () => {
|
|
328
|
-
const source = {
|
|
329
|
-
SOPClassUID: MR_SOP_CLASS_UID,
|
|
330
|
-
SOPInstanceUID: SOURCE_SOP_INSTANCE_UID,
|
|
331
|
-
Modality: "MR",
|
|
332
|
-
StudyInstanceUID: "1.2.3.4"
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// User experience: a derived image references its source and never
|
|
336
|
-
// reuses the source identity.
|
|
337
|
-
test("derivedFrom gives a DERIVED\\SECONDARY image that references the source", () => {
|
|
338
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
339
|
-
instance: source,
|
|
340
|
-
derivedFrom: source
|
|
341
|
-
});
|
|
342
|
-
expect(dataset.StudyInstanceUID).toBe("1.2.3.4");
|
|
343
|
-
expect(dataset.SOPInstanceUID).not.toBe(SOURCE_SOP_INSTANCE_UID);
|
|
344
|
-
expect(dataset.SOPClassUID).toBe(SECONDARY_CAPTURE_SOP_CLASS_UID);
|
|
345
|
-
expect(dataset.ImageType).toEqual(["DERIVED", "SECONDARY"]);
|
|
346
|
-
expect(dataset.SourceImageSequence).toEqual([
|
|
347
|
-
{
|
|
348
|
-
ReferencedSOPClassUID: MR_SOP_CLASS_UID,
|
|
349
|
-
ReferencedSOPInstanceUID: SOURCE_SOP_INSTANCE_UID
|
|
350
|
-
}
|
|
351
|
-
]);
|
|
352
|
-
expect(dataset.LossyImageCompression).toBe("01");
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// API: an override ImageType wins over the derived default.
|
|
356
|
-
test("an override ImageType wins with derivedFrom", () => {
|
|
357
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
358
|
-
derivedFrom: [source],
|
|
359
|
-
overrides: { ImageType: ["DERIVED", "PRIMARY"] }
|
|
360
|
-
});
|
|
361
|
-
expect(dataset.ImageType).toEqual(["DERIVED", "PRIMARY"]);
|
|
362
|
-
expect(dataset.SourceImageSequence).toHaveLength(1);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
// API: the lossy option sets the Lossy Image Compression attributes.
|
|
366
|
-
test("lossy: false marks a lossless derivation", () => {
|
|
367
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
368
|
-
derivedFrom: source,
|
|
369
|
-
lossy: false
|
|
370
|
-
});
|
|
371
|
-
expect(dataset.LossyImageCompression).toBe("00");
|
|
372
|
-
// A lossy source stays lossy (PS3.3 C.7.6.1.1.5).
|
|
373
|
-
expect(
|
|
374
|
-
buildImageDataset(grayPixels(), {
|
|
375
|
-
derivedFrom: { ...source, LossyImageCompression: "01" },
|
|
376
|
-
lossy: false
|
|
377
|
-
}).LossyImageCompression
|
|
378
|
-
).toBe("01");
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
// API: ImageType is a base value, so a custom base sets it, and
|
|
382
|
-
// derivedImageBase composed after it replaces it.
|
|
383
|
-
test("a custom base sets ImageType, and derivedImageBase replaces it", () => {
|
|
384
|
-
const base = combineBases(imageBase, {
|
|
385
|
-
ImageType: ["DERIVED", "PRIMARY"]
|
|
386
|
-
});
|
|
387
|
-
expect(
|
|
388
|
-
buildImageDataset(grayPixels(), { baseDicom: base }).ImageType
|
|
389
|
-
).toEqual(["DERIVED", "PRIMARY"]);
|
|
390
|
-
const derived = buildImageDataset(grayPixels(), {
|
|
391
|
-
baseDicom: combineBases(base, derivedImageBase(source))
|
|
392
|
-
});
|
|
393
|
-
expect(derived.ImageType).toEqual(["DERIVED", "SECONDARY"]);
|
|
394
|
-
expect(derived.SourceImageSequence).toHaveLength(1);
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// API: a lossy object sets the method and the ratio.
|
|
398
|
-
test("lossy detail carries method and ratio", () => {
|
|
399
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
400
|
-
derivedFrom: source,
|
|
401
|
-
lossy: { method: "ISO_10918_1", ratio: 8 }
|
|
402
|
-
});
|
|
403
|
-
expect(dataset.LossyImageCompressionMethod).toBe("ISO_10918_1");
|
|
404
|
-
expect(dataset.LossyImageCompressionRatio).toBe(8);
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// API: an override SOPInstanceUID always wins.
|
|
408
|
-
test("explicit SOPInstanceUID override is respected", () => {
|
|
409
|
-
const dataset = buildImageDataset(grayPixels(), {
|
|
410
|
-
instance: source,
|
|
411
|
-
derivedFrom: source,
|
|
412
|
-
overrides: { SOPInstanceUID: "2.25.42" }
|
|
413
|
-
});
|
|
414
|
-
expect(dataset.SOPInstanceUID).toBe("2.25.42");
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
describe("derivedImageAttributes", () => {
|
|
419
|
-
// API: one SourceImageSequence item for each source, and a clear error
|
|
420
|
-
// for a source without its identity.
|
|
421
|
-
test("references each partial instance, and names a missing keyword", () => {
|
|
422
|
-
const attributes = derivedImageAttributes([
|
|
423
|
-
{ SOPClassUID: MR_SOP_CLASS_UID, SOPInstanceUID: "2.25.1" },
|
|
424
|
-
{ SOPClassUID: MR_SOP_CLASS_UID, SOPInstanceUID: "2.25.2" }
|
|
425
|
-
]);
|
|
426
|
-
expect(attributes.ImageType).toEqual(["DERIVED", "SECONDARY"]);
|
|
427
|
-
expect(
|
|
428
|
-
attributes.SourceImageSequence.map(
|
|
429
|
-
item => item.ReferencedSOPInstanceUID
|
|
430
|
-
)
|
|
431
|
-
).toEqual(["2.25.1", "2.25.2"]);
|
|
432
|
-
expect(() =>
|
|
433
|
-
derivedImageAttributes([{ SOPClassUID: MR_SOP_CLASS_UID }])
|
|
434
|
-
).toThrow(/derivedFrom\[0\] is missing SOPInstanceUID/);
|
|
435
|
-
expect(() => derivedImageAttributes([])).toThrow(
|
|
436
|
-
/derivedFrom needs at least one instance/
|
|
437
|
-
);
|
|
438
|
-
expect(() => derivedImageBase([])).toThrow(
|
|
439
|
-
/derivedFrom needs at least one instance/
|
|
440
|
-
);
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// API: the lossy steps of a source stay in the history (PS3.3
|
|
444
|
-
// C.7.6.1.1.5), before the step of this derivation.
|
|
445
|
-
test("keeps the lossy compression history of a lossy source", () => {
|
|
446
|
-
const attributes = derivedImageAttributes(
|
|
447
|
-
{
|
|
448
|
-
SOPClassUID: MR_SOP_CLASS_UID,
|
|
449
|
-
SOPInstanceUID: "2.25.1",
|
|
450
|
-
LossyImageCompression: "01",
|
|
451
|
-
LossyImageCompressionMethod: "ISO_14495_1",
|
|
452
|
-
LossyImageCompressionRatio: 5
|
|
453
|
-
},
|
|
454
|
-
{ lossy: { method: "ISO_10918_1", ratio: 10 } }
|
|
455
|
-
);
|
|
456
|
-
expect([
|
|
457
|
-
attributes.LossyImageCompressionMethod,
|
|
458
|
-
attributes.LossyImageCompressionRatio
|
|
459
|
-
]).toEqual([
|
|
460
|
-
["ISO_14495_1", "ISO_10918_1"],
|
|
461
|
-
[5, 10]
|
|
462
|
-
]);
|
|
463
|
-
|
|
464
|
-
// A source method without a ratio: the ratios cannot pair by
|
|
465
|
-
// position, so the result has no ratio (IMG-USR-3).
|
|
466
|
-
const warn = jest.spyOn(log, "warn").mockImplementation(() => {});
|
|
467
|
-
const unpaired = derivedImageAttributes(
|
|
468
|
-
{
|
|
469
|
-
SOPClassUID: MR_SOP_CLASS_UID,
|
|
470
|
-
SOPInstanceUID: "2.25.1",
|
|
471
|
-
LossyImageCompression: "01",
|
|
472
|
-
LossyImageCompressionMethod: "ISO_15444_1"
|
|
473
|
-
},
|
|
474
|
-
{ lossy: { method: "ISO_10918_1", ratio: 8 } }
|
|
475
|
-
);
|
|
476
|
-
expect([
|
|
477
|
-
unpaired.LossyImageCompressionMethod,
|
|
478
|
-
unpaired.LossyImageCompressionRatio,
|
|
479
|
-
warn.mock.calls.length
|
|
480
|
-
]).toEqual([["ISO_15444_1", "ISO_10918_1"], undefined, 1]);
|
|
481
|
-
warn.mockRestore();
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
describe("encapsulated multi-frame (finding 10)", () => {
|
|
486
|
-
const JPEG_BASELINE_TS = "1.2.840.10008.1.2.4.50";
|
|
487
|
-
const frame = new Uint8Array([1, 2, 3, 4]);
|
|
488
|
-
|
|
489
|
-
// Review finding 10: numberOfFrames came only from
|
|
490
|
-
// decodedImage.numberOfFrames || 1 and the attribute was written only
|
|
491
|
-
// when above 1 — three encapsulated fragments produced an instance
|
|
492
|
-
// with no NumberOfFrames, so a conformant reader showed frame 1 and
|
|
493
|
-
// frames 2 and 3 were unreachable.
|
|
494
|
-
test("NumberOfFrames defaults to frames.length (finding 10)", () => {
|
|
495
|
-
const dataset = buildImageDataset(
|
|
496
|
-
{ rows: 4, columns: 4 },
|
|
497
|
-
{
|
|
498
|
-
encapsulated: {
|
|
499
|
-
transferSyntaxUID: JPEG_BASELINE_TS,
|
|
500
|
-
frames: [frame, frame, frame]
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
);
|
|
504
|
-
expect(dataset.NumberOfFrames).toBe(3);
|
|
505
|
-
expect(dataset.PixelData).toHaveLength(3);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
// The reverse shape also passed unchecked: an explicit frame count
|
|
509
|
-
// over a different number of fragments emitted the bogus claim.
|
|
510
|
-
test("explicit numberOfFrames over a different fragment count throws (finding 10)", () => {
|
|
511
|
-
expect(() =>
|
|
512
|
-
buildImageDataset(
|
|
513
|
-
{ rows: 4, columns: 4, numberOfFrames: 7 },
|
|
514
|
-
{
|
|
515
|
-
encapsulated: {
|
|
516
|
-
transferSyntaxUID: JPEG_BASELINE_TS,
|
|
517
|
-
frames: [frame, frame]
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
)
|
|
521
|
-
).toThrow(/does not match/);
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
test("a matching explicit count is accepted", () => {
|
|
525
|
-
const dataset = buildImageDataset(
|
|
526
|
-
{ rows: 4, columns: 4, numberOfFrames: 2 },
|
|
527
|
-
{
|
|
528
|
-
encapsulated: {
|
|
529
|
-
transferSyntaxUID: JPEG_BASELINE_TS,
|
|
530
|
-
frames: [frame, frame]
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
);
|
|
534
|
-
expect(dataset.NumberOfFrames).toBe(2);
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
test("a single encapsulated frame still omits NumberOfFrames", () => {
|
|
538
|
-
const dataset = buildImageDataset(
|
|
539
|
-
{ rows: 4, columns: 4 },
|
|
540
|
-
{
|
|
541
|
-
encapsulated: {
|
|
542
|
-
transferSyntaxUID: JPEG_BASELINE_TS,
|
|
543
|
-
frames: [frame]
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
);
|
|
547
|
-
expect(dataset.NumberOfFrames).toBeUndefined();
|
|
548
|
-
expect(dataset.PixelData).toHaveLength(1);
|
|
549
|
-
});
|
|
550
|
-
});
|
package/test/h264.test.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// test/h264.test.js
|
|
2
|
-
//
|
|
3
|
-
// h264TransferSyntaxUID: the AVC profile/level → DICOM transfer syntax
|
|
4
|
-
// mapping (Supplement 225). Extracted from the video package's mp4Info suite
|
|
5
|
-
// when this function moved to @dcmjs-org/imaging.
|
|
6
|
-
|
|
7
|
-
import { h264TransferSyntaxUID } from "../src/h264.js";
|
|
8
|
-
|
|
9
|
-
const H264_HIGH_41 = "1.2.840.10008.1.2.4.102.1";
|
|
10
|
-
const H264_HIGH_42 = "1.2.840.10008.1.2.4.104.1";
|
|
11
|
-
|
|
12
|
-
describe("h264TransferSyntaxUID", () => {
|
|
13
|
-
it("maps Baseline/Main/High ≤ 4.1 to the Level 4.1 fragmentable syntax", () => {
|
|
14
|
-
expect(h264TransferSyntaxUID(66, 30)).toBe(H264_HIGH_41);
|
|
15
|
-
expect(h264TransferSyntaxUID(77, 40)).toBe(H264_HIGH_41);
|
|
16
|
-
expect(h264TransferSyntaxUID(100, 41)).toBe(H264_HIGH_41);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("maps level 4.2 to the Level 4.2 fragmentable syntax", () => {
|
|
20
|
-
expect(h264TransferSyntaxUID(100, 42)).toBe(H264_HIGH_42);
|
|
21
|
-
expect(h264TransferSyntaxUID(66, 42)).toBe(H264_HIGH_42);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("returns null beyond the defined envelope", () => {
|
|
25
|
-
expect(h264TransferSyntaxUID(100, 51)).toBeNull(); // level 5.1
|
|
26
|
-
expect(h264TransferSyntaxUID(110, 42)).toBeNull(); // High-10
|
|
27
|
-
expect(h264TransferSyntaxUID(244, 41)).toBeNull(); // High-444
|
|
28
|
-
});
|
|
29
|
-
});
|
package/test/jpegInfo.test.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// test/jpegInfo.test.js
|
|
2
|
-
//
|
|
3
|
-
// parseJpegInfo: SOF geometry extraction and the JPEG → DICOM transfer
|
|
4
|
-
// syntax mapping, over bytes built inline — no binary fixtures. The
|
|
5
|
-
// truncation cases pin review finding 9: a JPEG cut inside the SOF field
|
|
6
|
-
// span must throw, never return zero-coerced geometry.
|
|
7
|
-
|
|
8
|
-
import { parseJpegInfo } from "../src/jpegInfo.js";
|
|
9
|
-
|
|
10
|
-
const JPEG_BASELINE_TS = "1.2.840.10008.1.2.4.50";
|
|
11
|
-
const JPEG_EXTENDED_TS = "1.2.840.10008.1.2.4.51";
|
|
12
|
-
const JPEG_LOSSLESS_TS = "1.2.840.10008.1.2.4.57";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A minimal structurally valid JPEG: SOI, APP0 stub, optional APP14 Adobe,
|
|
16
|
-
* SOF, EOI. `sampling` holds the H/V byte of each component.
|
|
17
|
-
*/
|
|
18
|
-
function makeJpeg({
|
|
19
|
-
sofMarker = 0xc0,
|
|
20
|
-
precision = 8,
|
|
21
|
-
rows = 480,
|
|
22
|
-
columns = 640,
|
|
23
|
-
components = 3,
|
|
24
|
-
ids = [1, 2, 3, 4],
|
|
25
|
-
sampling = [0x11, 0x11, 0x11, 0x11],
|
|
26
|
-
adobeTransform
|
|
27
|
-
} = {}) {
|
|
28
|
-
const componentSpecs = [];
|
|
29
|
-
for (let i = 0; i < components; i++) {
|
|
30
|
-
componentSpecs.push(ids[i], sampling[i], 0);
|
|
31
|
-
}
|
|
32
|
-
const adobe =
|
|
33
|
-
adobeTransform === undefined
|
|
34
|
-
? []
|
|
35
|
-
: [0xff, 0xee, 0x00, 0x0e, 0x41, 0x64, 0x6f, 0x62, 0x65].concat([
|
|
36
|
-
0,
|
|
37
|
-
100,
|
|
38
|
-
0,
|
|
39
|
-
0,
|
|
40
|
-
0,
|
|
41
|
-
0,
|
|
42
|
-
adobeTransform
|
|
43
|
-
]);
|
|
44
|
-
const sofLength = 8 + components * 3;
|
|
45
|
-
return Uint8Array.from([
|
|
46
|
-
0xff,
|
|
47
|
-
0xd8, // SOI
|
|
48
|
-
0xff,
|
|
49
|
-
0xe0,
|
|
50
|
-
0x00,
|
|
51
|
-
0x04,
|
|
52
|
-
0x4a,
|
|
53
|
-
0x46, // APP0 stub
|
|
54
|
-
...adobe,
|
|
55
|
-
0xff,
|
|
56
|
-
sofMarker,
|
|
57
|
-
(sofLength >> 8) & 0xff,
|
|
58
|
-
sofLength & 0xff,
|
|
59
|
-
precision,
|
|
60
|
-
(rows >> 8) & 0xff,
|
|
61
|
-
rows & 0xff,
|
|
62
|
-
(columns >> 8) & 0xff,
|
|
63
|
-
columns & 0xff,
|
|
64
|
-
components,
|
|
65
|
-
...componentSpecs,
|
|
66
|
-
0xff,
|
|
67
|
-
0xd9 // EOI
|
|
68
|
-
]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe("parseJpegInfo", () => {
|
|
72
|
-
it("reads geometry and maps SOF0 to the baseline transfer syntax", () => {
|
|
73
|
-
const info = parseJpegInfo(makeJpeg());
|
|
74
|
-
expect(info.rows).toBe(480);
|
|
75
|
-
expect(info.columns).toBe(640);
|
|
76
|
-
expect(info.bitsAllocated).toBe(8);
|
|
77
|
-
expect(info.samplesPerPixel).toBe(3);
|
|
78
|
-
expect(info.sofMarker).toBe(0xc0);
|
|
79
|
-
expect(info.transferSyntaxUID).toBe(JPEG_BASELINE_TS);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("maps SOF1 to extended and SOF3 to lossless", () => {
|
|
83
|
-
expect(
|
|
84
|
-
parseJpegInfo(makeJpeg({ sofMarker: 0xc1 })).transferSyntaxUID
|
|
85
|
-
).toBe(JPEG_EXTENDED_TS);
|
|
86
|
-
expect(
|
|
87
|
-
parseJpegInfo(makeJpeg({ sofMarker: 0xc3, components: 1 }))
|
|
88
|
-
.transferSyntaxUID
|
|
89
|
-
).toBe(JPEG_LOSSLESS_TS);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("gives DICOM bit depths: 12-bit precision is BitsAllocated 16, BitsStored 12", () => {
|
|
93
|
-
const info = parseJpegInfo(
|
|
94
|
-
makeJpeg({ sofMarker: 0xc1, precision: 12, components: 1 })
|
|
95
|
-
);
|
|
96
|
-
expect(info.bitsAllocated).toBe(16);
|
|
97
|
-
expect(info.bitsStored).toBe(12);
|
|
98
|
-
expect(info.photometricInterpretation).toBe("MONOCHROME2");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it.each([
|
|
102
|
-
["subsampled chroma", { sampling: [0x21, 0x11, 0x11] }, "YBR_FULL_422"],
|
|
103
|
-
["no subsampling (4:4:4)", {}, "YBR_FULL"],
|
|
104
|
-
["component IDs R, G, B", { ids: [0x52, 0x47, 0x42] }, "RGB"],
|
|
105
|
-
["Adobe transform 0", { adobeTransform: 0 }, "RGB"],
|
|
106
|
-
[
|
|
107
|
-
"Adobe transform 1 over R, G, B IDs",
|
|
108
|
-
{ adobeTransform: 1, ids: [0x52, 0x47, 0x42] },
|
|
109
|
-
"YBR_FULL"
|
|
110
|
-
],
|
|
111
|
-
["lossless SOF3", { sofMarker: 0xc3 }, "RGB"],
|
|
112
|
-
["4 components (CMYK)", { components: 4 }, null]
|
|
113
|
-
])("photometric interpretation: %s", (_, options, expected) => {
|
|
114
|
-
expect(parseJpegInfo(makeJpeg(options)).photometricInterpretation).toBe(
|
|
115
|
-
expected
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("leaves the transfer syntax null for progressive (SOF2)", () => {
|
|
120
|
-
const info = parseJpegInfo(makeJpeg({ sofMarker: 0xc2 }));
|
|
121
|
-
expect(info.transferSyntaxUID).toBeNull();
|
|
122
|
-
expect(info.columns).toBe(640);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("rejects non-JPEG input (missing SOI)", () => {
|
|
126
|
-
expect(() => parseJpegInfo(new Uint8Array(16).fill(0x41))).toThrow(
|
|
127
|
-
/not JPEG/
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("rejects a JPEG with no SOF before EOI", () => {
|
|
132
|
-
expect(() =>
|
|
133
|
-
parseJpegInfo(Uint8Array.from([0xff, 0xd8, 0xff, 0xd9]))
|
|
134
|
-
).toThrow(/no frame header/);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Review finding 9: the exact vector from the review map — a 480×640
|
|
138
|
-
// JPEG cut one byte into the width field. The unfixed reader returned
|
|
139
|
-
// columns 512 (undefined coerced to 0 in the bitwise OR) and the wrong
|
|
140
|
-
// geometry flowed silently into the built dataset.
|
|
141
|
-
it("throws on a JPEG cut one byte into the SOF width field (finding 9)", () => {
|
|
142
|
-
const truncated = Uint8Array.from([
|
|
143
|
-
0xff, 0xd8, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x01, 0xe0, 0x02
|
|
144
|
-
]);
|
|
145
|
-
expect(() => parseJpegInfo(truncated)).toThrow(/truncated/);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Finding 9, second shape: cut right after the SOF length field. The
|
|
149
|
-
// unfixed reader returned rows 0, columns 0, and no bit depth.
|
|
150
|
-
it("throws on a JPEG cut right after the SOF length field (finding 9)", () => {
|
|
151
|
-
const truncated = Uint8Array.from([0xff, 0xd8, 0xff, 0xc0, 0x00, 0x11]);
|
|
152
|
-
expect(() => parseJpegInfo(truncated)).toThrow(/truncated/);
|
|
153
|
-
});
|
|
154
|
-
});
|