@cornerstonejs/core 1.44.3 → 1.45.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "1.44.3",
3
+ "version": "1.45.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "type": "individual",
48
48
  "url": "https://ohif.org/donate"
49
49
  },
50
- "gitHead": "2d4cc217d2f58d5089945e6f5f651cbeda3dd85f"
50
+ "gitHead": "87999af23a3e0f399c2c3df80587b662ab079b93"
51
51
  }
@@ -156,6 +156,10 @@ class VideoViewport extends Viewport implements IVideoViewport {
156
156
  columnCosines[1],
157
157
  columnCosines[2]
158
158
  );
159
+
160
+ const { rows, columns } = imagePlaneModule;
161
+ this.videoWidth = columns;
162
+ this.videoHeight = rows;
159
163
  const scanAxisNormal = vec3.create();
160
164
  vec3.cross(scanAxisNormal, rowCosineVec, colCosineVec);
161
165
 
@@ -216,10 +220,14 @@ class VideoViewport extends Viewport implements IVideoViewport {
216
220
  this.numberOfFrames = numberOfFrames;
217
221
  // 1 based range setting
218
222
  this.setFrameRange([1, numberOfFrames]);
219
- if (frameNumber !== undefined) {
223
+ this.play();
224
+ // This is ugly, but without it, the video often fails to render initially
225
+ // so having a play, followed by a pause fixes things.
226
+ // 50 ms is a tested value that seems to work to prevent exceptions
227
+ window.setTimeout(() => {
220
228
  this.pause();
221
- this.setFrameNumber(frameNumber);
222
- }
229
+ this.setFrameNumber(frameNumber || 1);
230
+ }, 50);
223
231
  });
224
232
  }
225
233
 
@@ -258,17 +266,27 @@ class VideoViewport extends Viewport implements IVideoViewport {
258
266
  }
259
267
  }
260
268
 
261
- public play() {
262
- if (!this.isPlaying) {
263
- this.videoElement.play();
264
- this.isPlaying = true;
265
- this.renderWhilstPlaying();
269
+ public async play() {
270
+ try {
271
+ if (!this.isPlaying) {
272
+ // Play returns a promise that is true when playing completes.
273
+ await this.videoElement.play();
274
+ this.isPlaying = true;
275
+ this.renderWhilstPlaying();
276
+ }
277
+ } catch (e) {
278
+ // No-op, an exception sometimes gets thrown on the initial play, not
279
+ // quite sure why. Catching it prevents displaying an error
266
280
  }
267
281
  }
268
282
 
269
283
  public async pause() {
270
- await this.videoElement.pause();
271
- this.isPlaying = false;
284
+ try {
285
+ await this.videoElement.pause();
286
+ this.isPlaying = false;
287
+ } catch (e) {
288
+ // No-op - sometimes this happens on startup
289
+ }
272
290
  }
273
291
 
274
292
  public async scroll(delta = 1) {
@@ -457,7 +475,7 @@ class VideoViewport extends Viewport implements IVideoViewport {
457
475
 
458
476
  const spacing = metadata.spacing;
459
477
 
460
- return {
478
+ const imageData = {
461
479
  dimensions: metadata.dimensions,
462
480
  spacing,
463
481
  origin: metadata.origin,
@@ -486,6 +504,11 @@ class VideoViewport extends Viewport implements IVideoViewport {
486
504
  scaled: false,
487
505
  },
488
506
  };
507
+ Object.defineProperty(imageData, 'scalarData', {
508
+ get: () => this.getScalarData(),
509
+ enumerable: true,
510
+ });
511
+ return imageData;
489
512
  }
490
513
 
491
514
  /**
@@ -0,0 +1,27 @@
1
+ export default function convertToGrayscale(
2
+ scalarData,
3
+ width: number,
4
+ height: number
5
+ ) {
6
+ const isRGBA = scalarData.length === width * height * 4;
7
+ const isRGB = scalarData.length === width * height * 3;
8
+ if (isRGBA || isRGB) {
9
+ const newScalarData = new Float32Array(width * height);
10
+ let offset = 0;
11
+ let destOffset = 0;
12
+ const increment = isRGBA ? 4 : 3;
13
+ for (let x = 0; x < width; x++) {
14
+ for (let y = 0; y < height; y++) {
15
+ const r = scalarData[offset];
16
+ const g = scalarData[offset + 1];
17
+ const b = scalarData[offset + 2];
18
+ newScalarData[destOffset] = (r + g + b) / 3;
19
+ offset += increment;
20
+ destOffset++;
21
+ }
22
+ }
23
+ return newScalarData;
24
+ } else {
25
+ return scalarData;
26
+ }
27
+ }
@@ -66,6 +66,7 @@ import { convertStackToVolumeViewport } from './convertStackToVolumeViewport';
66
66
  import { convertVolumeToStackViewport } from './convertVolumeToStackViewport';
67
67
  import VoxelManager from './VoxelManager';
68
68
  import roundNumber, { roundToPrecision } from './roundNumber';
69
+ import convertToGrayscale from './convertToGrayscale';
69
70
 
70
71
  // name spaces
71
72
  import * as planar from './planar';
@@ -97,6 +98,7 @@ export {
97
98
  createInt16SharedArray,
98
99
  getViewportModality,
99
100
  windowLevel,
101
+ convertToGrayscale,
100
102
  getClosestImageId,
101
103
  getSpacingInNormalDirection,
102
104
  getTargetVolumeAndSpacingInNormalDir,