Skip to content

Commit

Permalink
Added rendering support for Icon Image Sequence
Browse files Browse the repository at this point in the history
Removed circular dependencies
Updated c8 and build workflow to work/test on multiple node versions
  • Loading branch information
PantelisGeorgiadis committed Dec 12, 2022
1 parent 778b084 commit 36a7b2e
Show file tree
Hide file tree
Showing 25 changed files with 607 additions and 283 deletions.
11 changes: 0 additions & 11 deletions .c8rc.json

This file was deleted.

25 changes: 15 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
name: build
'on':
name: Node.js CI

on:
push:
branches:
- master
branches: [ master ]
pull_request:
branches:
- master
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript
- name: Use Node.js
uses: actions/setup-node@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Build
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ documentation/
.gitignore
.gitattributes
.jsdocrc.json
.c8rc.json
index.test-d.ts
karma.config.js
webpack.config.js
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const renderingResult = image.render();

// Rendered pixels in an RGBA ArrayBuffer.
const renderedPixels = renderingResult.pixels;
// Rendered width.
const width = renderingResult.width;
// Rendered height.
const height = renderingResult.height;
```

#### Advanced image rendering
Expand Down Expand Up @@ -134,6 +138,10 @@ const renderingResult = image.render(renderingOpts);
const renderedPixels = renderingResult.pixels;
// Rendered frame index.
const frame = renderingResult.frame;
// Rendered width.
const width = renderingResult.width;
// Rendered height.
const height = renderingResult.height;
// Window/level used to render the pixels.
// In case of color images, windowLevel should not be present.
const windowLevel = renderingResult.windowLevel;
Expand Down
12 changes: 6 additions & 6 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
const renderedPixels = new Uint8Array(renderingResult.pixels);
const t1 = performance.now();

opts.canvasElement.width = opts.image.getWidth();
opts.canvasElement.height = opts.image.getHeight();
opts.canvasElement.width = renderingResult.width;
opts.canvasElement.height = renderingResult.height;

if (opts.useWebGl) {
const gl = opts.canvasElement.getContext('webgl');
Expand Down Expand Up @@ -253,8 +253,8 @@
gl.TEXTURE_2D,
0,
gl.RGBA,
opts.image.getWidth(),
opts.image.getHeight(),
renderingResult.width,
renderingResult.height,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
Expand All @@ -270,9 +270,9 @@
} else {
const ctx = opts.canvasElement.getContext('2d');
ctx.clearRect(0, 0, opts.canvasElement.width, opts.canvasElement.height);
const imageData = ctx.createImageData(opts.image.getWidth(), opts.image.getHeight());
const imageData = ctx.createImageData(renderingResult.width, renderingResult.height);
const canvasPixels = imageData.data;
for (let i = 0; i < 4 * opts.image.getWidth() * opts.image.getHeight(); i++) {
for (let i = 0; i < 4 * renderingResult.width * renderingResult.height; i++) {
canvasPixels[i] = renderedPixels[i];
}
ctx.putImageData(imageData, 0, 0);
Expand Down
8 changes: 4 additions & 4 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ async function renderToBmp(dicomFile, bmpFile) {
const renderedPixels = Buffer.from(renderingResult.pixels);

// BMP lib expects ABGR and the rendering output is RGBA
const argbPixels = Buffer.alloc(4 * image.getWidth() * image.getHeight());
for (let i = 0; i < 4 * image.getWidth() * image.getHeight(); i += 4) {
const argbPixels = Buffer.alloc(4 * renderingResult.width * renderingResult.height);
for (let i = 0; i < 4 * renderingResult.width * renderingResult.height; i += 4) {
argbPixels[i] = renderedPixels[i + 3];
argbPixels[i + 1] = renderedPixels[i + 2];
argbPixels[i + 2] = renderedPixels[i + 1];
Expand All @@ -32,8 +32,8 @@ async function renderToBmp(dicomFile, bmpFile) {

const encodedBmp = bmp.encode({
data: argbPixels,
width: image.getWidth(),
height: image.getHeight(),
width: renderingResult.width,
height: renderingResult.height,
});

fs.writeFileSync(bmpFile, encodedBmp.data);
Expand Down
8 changes: 4 additions & 4 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async function renderToBmp(dicomFile: string, bmpFile: string) {
const renderedPixels = Buffer.from(renderingResult.pixels);

// BMP lib expects ABGR and the rendering output is RGBA
const argbPixels = Buffer.alloc(4 * image.getWidth() * image.getHeight());
for (let i = 0; i < 4 * image.getWidth() * image.getHeight(); i += 4) {
const argbPixels = Buffer.alloc(4 * renderingResult.width * renderingResult.height);
for (let i = 0; i < 4 * renderingResult.width * renderingResult.height; i += 4) {
argbPixels[i] = renderedPixels[i + 3];
argbPixels[i + 1] = renderedPixels[i + 2];
argbPixels[i + 2] = renderedPixels[i + 1];
Expand All @@ -31,8 +31,8 @@ async function renderToBmp(dicomFile: string, bmpFile: string) {

const encodedBmp = bmp.encode({
data: argbPixels,
width: image.getWidth(),
height: image.getHeight(),
width: renderingResult.width,
height: renderingResult.height,
});

fs.writeFileSync(bmpFile, encodedBmp.data);
Expand Down
19 changes: 17 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ declare class WindowLevel {
setDescription(description: string): void;

/**
* Creates an array of window/level objects based on the image parameters.
* Creates an array of window/level objects based on the image elements.
*/
static fromDicomImage(image: DicomImage): Array<WindowLevel>;
static fromDicomImageElements(elements: Record<string, unknown>): Array<WindowLevel>;

/**
* Gets the window/level description.
Expand Down Expand Up @@ -192,6 +192,21 @@ declare class DicomImage {
colorPalette?: number;
}): {
frame: number;
width: number;
height: number;
pixels: ArrayBuffer;
windowLevel?: WindowLevel;
histograms?: Array<Histogram>;
colorPalette?: number;
};

/**
* Renders the icon image located within an icon image sequence, if exists.
*/
renderIcon(): {
frame: number;
width: number;
height: number;
pixels: ArrayBuffer;
windowLevel?: WindowLevel;
histograms?: Array<Histogram>;
Expand Down
16 changes: 15 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ expectType<number>(windowLevel.getLevel());
expectType<string | undefined>(windowLevel.getDescription());
expectType<string>(windowLevel.toString());
expectType<WindowLevel[]>(
WindowLevel.fromDicomImage(new DicomImage({}, TransferSyntax.ImplicitVRLittleEndian))
WindowLevel.fromDicomImageElements(
new DicomImage({}, TransferSyntax.ImplicitVRLittleEndian).getElements()
)
);

// Histogram
Expand Down Expand Up @@ -78,8 +80,11 @@ expectType<number>(dicomImage.getNumberOfFrames());
expectError(
dicomImage.render({ frame: '1', windowLevel: 'WW/WL', renderOverlays: 1, calculateHistograms: 0 })
);
expectError(dicomImage.renderIcon({ frame: 1 }));
expectType<{
frame: number;
width: number;
height: number;
pixels: ArrayBuffer;
windowLevel?: WindowLevel;
histograms?: Array<Histogram>;
Expand All @@ -92,4 +97,13 @@ expectType<{
colorPalette: StandardColorPalette.HotIron,
})
);
expectType<{
frame: number;
width: number;
height: number;
pixels: ArrayBuffer;
windowLevel?: WindowLevel;
histograms?: Array<Histogram>;
colorPalette?: number;
}>(dicomImage.renderIcon());
expectType<string>(dicomImage.toString());
Loading

0 comments on commit 36a7b2e

Please sign in to comment.