Skip to content

Commit

Permalink
Merge pull request #11 from DedalusDIIT/fix_loader
Browse files Browse the repository at this point in the history
Remove RGBA check
  • Loading branch information
francescomartinod authored Oct 11, 2024
2 parents 328db90 + e5588cb commit e695eab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ByteArray } from 'dicom-parser';

export default function (
imageFrame: ByteArray,
colorBuffer: ByteArray,
useRGBA: boolean
): void {
export default function (imageFrame: ByteArray, colorBuffer: ByteArray): void {
if (imageFrame === undefined) {
throw new Error('decodeRGB: rgbBuffer must be defined');
}
Expand All @@ -20,17 +16,10 @@ export default function (

let bufferIndex = 0;

if (useRGBA) {
for (let i = 0; i < numPixels; i++) {
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // red
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // green
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // blue
colorBuffer[bufferIndex++] = 255; // alpha
}

return;
for (let i = 0; i < numPixels; i++) {
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // red
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // green
colorBuffer[bufferIndex++] = imageFrame[rgbIndex++]; // blue
colorBuffer[bufferIndex++] = 255; // alpha
}

// if RGB buffer
colorBuffer.set(imageFrame);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

function convertRGB(imageFrame, colorBuffer, useRGBA) {
if (imageFrame.planarConfiguration === 0) {
convertRGBColorByPixel(imageFrame.pixelData, colorBuffer, useRGBA);
convertRGBColorByPixel(imageFrame.pixelData, colorBuffer);
} else {
convertRGBColorByPlane(imageFrame.pixelData, colorBuffer, useRGBA);
}
Expand Down
37 changes: 23 additions & 14 deletions packages/dicomImageLoader/src/imageLoader/createImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
PixelDataTypedArray,
} from '../types';
import convertColorSpace from './convertColorSpace';
import isColorConversionRequired from './isColorConversionRequired';
import decodeImageFrame from './decodeImageFrame';
import getImageFrame from './getImageFrame';
import getScalingParameters from './getScalingParameters';
Expand Down Expand Up @@ -246,25 +245,23 @@ function createImage(
cornerstone.metaData.get(MetadataModules.CALIBRATION, imageId) || {};
const { rows, columns } = imageFrame;

if (isColorImage) {
if (isColorConversionRequired(imageFrame)) {
if (!isJPEGBaseline8BitColor(imageFrame, transferSyntax)) {
if (!alreadyTyped) {
setPixelDataType(imageFrame);
}

// convert color space
if (isColorImage) {
// setup the canvas context
canvas.height = imageFrame.rows;
canvas.width = imageFrame.columns;

const context = canvas.getContext('2d');
let imageData = context.createImageData(
const imageData = context.createImageData(
imageFrame.columns,
imageFrame.rows
);
if (!useRGBA) {
// Use a hard coded 3 samples per pixel for the destination, as the
// original samples per pixel may not be 3 for palette color
imageData = {
...imageData,
data: new Uint8ClampedArray(
3 * imageFrame.columns * imageFrame.rows
),
};
}

convertColorSpace(imageFrame, imageData.data, useRGBA);
imageFrame.imageData = imageData;
imageFrame.pixelData = imageData.data;
Expand Down Expand Up @@ -432,3 +429,15 @@ function createImage(
}

export default createImage;

function isJPEGBaseline8BitColor(imageFrame, transferSyntax) {
transferSyntax = transferSyntax || imageFrame.transferSyntax;

if (
imageFrame.bitsAllocated === 8 &&
transferSyntax === '1.2.840.10008.1.2.4.50' &&
(imageFrame.samplesPerPixel === 3 || imageFrame.samplesPerPixel === 4)
) {
return true;
}
}

0 comments on commit e695eab

Please sign in to comment.