Skip to content

Commit

Permalink
fix: convert RGBA to RGB for GPU rendering if cached (#152)
Browse files Browse the repository at this point in the history
* fix: convert RGBA to RGB for GPU if cached

* bump cswil version
  • Loading branch information
sedghi authored Jul 27, 2022
1 parent 57a279c commit fb8aa36
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
19 changes: 18 additions & 1 deletion packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,24 @@ class StackViewport extends Viewport implements IStackViewport {
const scalars = this._imageData.getPointData().getScalars();
const scalarData = scalars.getData() as Uint8Array | Float32Array;

scalarData.set(pixelData);
if (image.rgba) {
// if image is already cached with rgba for any reason (cpu fallback),
// we need to convert it to rgb for the pixel data set
// RGB case
const numPixels = pixelData.length / 4;

let rgbIndex = 0;
let index = 0;

for (let i = 0; i < numPixels; i++) {
scalarData[index++] = pixelData[rgbIndex++]; // red
scalarData[index++] = pixelData[rgbIndex++]; // green
scalarData[index++] = pixelData[rgbIndex++]; // blue
rgbIndex++; // skip alpha
}
} else {
scalarData.set(pixelData);
}

// Trigger modified on the VTK Object so the texture is updated
// TODO: evaluate directly changing things with texSubImage3D later
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@mdx-js/react": "^1.6.21",
"@svgr/webpack": "^6.2.1",
"clsx": "^1.1.1",
"cornerstone-wado-image-loader": "^4.1.5",
"cornerstone-wado-image-loader": "^4.2.0",
"dcmjs": "0.19.2",
"detect-gpu": "^4.0.7",
"dicom-parser": "^1.8.11",
Expand Down
4 changes: 2 additions & 2 deletions packages/streaming-image-volume-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
},
"dependencies": {
"@cornerstonejs/core": "^0.13.10",
"cornerstone-wado-image-loader": "^4.1.5"
"cornerstone-wado-image-loader": "^4.2.0"
},
"peerDependencies": {
"@cornerstonejs/calculate-suv": "1.0.2"
},
"devDependencies": {
"@cornerstonejs/calculate-suv": "1.0.2",
"@cornerstonejs/core": "^0.9.0",
"cornerstone-wado-image-loader": "^4.1.5"
"cornerstone-wado-image-loader": "^4.2.0"
},
"contributors": [
{
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7072,10 +7072,10 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cornerstone-wado-image-loader@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/cornerstone-wado-image-loader/-/cornerstone-wado-image-loader-4.1.5.tgz#1e120564e887bf85b03d4a7f90c6aaea5fd5acf2"
integrity sha512-N+CqivL+KNnVzftUqhwtKa7ULvdO96Bo3sTd4dBu05b57FSKoyAjFQ40md/UzbwzC3hEdVy94rh1TVMPRdMN4w==
cornerstone-wado-image-loader@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/cornerstone-wado-image-loader/-/cornerstone-wado-image-loader-4.2.0.tgz#c2fd715d20c69310c6d9434d6673aa1ccab1f77a"
integrity sha512-J7FQcJlBaLHcbc8qj9sHW5w039w3s+i2kU8wK2Yghn1rnLcOay8N8pr+aEYua3XT04iD9GOj5NyikSiplITZWQ==
dependencies:
"@cornerstonejs/codec-charls" "^0.1.1"
"@cornerstonejs/codec-libjpeg-turbo-8bit" "^0.0.7"
Expand Down

0 comments on commit fb8aa36

Please sign in to comment.