Skip to content

fix palette color image loading#2610

Merged
wayfarer3130 merged 10 commits intomainfrom
fix/palleteColorImages
Feb 17, 2026
Merged

fix palette color image loading#2610
wayfarer3130 merged 10 commits intomainfrom
fix/palleteColorImages

Conversation

@rodrigobasilio2022
Copy link
Collaborator

Context

The convertPALETTECOLOR function was using Promise.all().then() without returning or awaiting the promise. This caused the function to complete immediately before the palette color data was fully fetched and the pixel data was properly converted. As a result, images with PALETTE COLOR photometric interpretation would sometimes render as black images because the pixel data was being used before it was ready.

Solution

Convert the color space conversion pipeline to use async/await pattern to ensure proper synchronization:

convertPALETTECOLOR - Changed from synchronous to async function that awaits palette data fetching and conversion
convertColorSpace - Converted to async function and awaits the palette color conversion when needed
createImage - Updated the decode promise handler to be async and await color space conversion

Changes

Modified convertPALETTECOLOR.ts: Changed function signature to async and replaced .then() with await
Modified convertColorSpace.ts: Made function async and added await for PALETTE COLOR conversion
Modified createImage.ts: Made the decode callback async to properly await color conversion

Impact

This ensures that palette color images are fully processed before rendering, eliminating the race condition that caused black images to appear intermittently.

Changes & Results

Testing

Checklist

PR

  • [] My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • [] My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] "OS:
  • [] "Node version:
  • [] "Browser:

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an asynchronous race condition in the DICOM image loading pipeline where PALETTE COLOR images could render as black because palette LUT data was not fully fetched/converted before pixel data was used.

Changes:

  • Made convertPALETTECOLOR asynchronous and ensured palette LUT fetching is awaited before conversion.
  • Made convertColorSpace asynchronous and awaited PALETTE COLOR conversion.
  • Updated createImage to await convertColorSpace during decode post-processing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/dicomImageLoader/src/imageLoader/createImage.ts Awaits color-space conversion during image creation to prevent premature use of unconverted pixel data.
packages/dicomImageLoader/src/imageLoader/convertColorSpace.ts Converts the color conversion dispatcher to async so PALETTE COLOR conversion can be awaited.
packages/dicomImageLoader/src/imageLoader/colorSpaceConverters/convertPALETTECOLOR.ts Converts the PALETTE COLOR converter to async/await to properly synchronize palette data fetching and conversion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

packages/dicomImageLoader/src/imageLoader/createImage.ts:48

  • PR description says convertColorSpace and the decode callback were converted to async/await, but in the current code convertColorSpace(...) is still called synchronously and the decodePromise.then(...) handler is not async. Please either update the PR description to match the implemented approach (palette prefetch in createImage) or update the code so it actually follows the described async/await pipeline.
async function createImage(
  imageId: string,
  pixelData: ByteArray,
  transferSyntax: string,
  options: DICOMLoaderImageOptions = {}
): Promise<DICOMLoaderIImage | Types.IImageFrame> {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 73 to 75
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new PALETTE COLOR preload path is central to fixing the black-image race. There are existing automated tests that cover createImage, but none appear to exercise PALETTE COLOR with palette bulkdata coming back asynchronously (e.g., WADO-RS). Please add a regression test that loads a palette-color DICOM and asserts the converted pixel data is produced deterministically (not all zeros) and that palette LUT data is present after createImage resolves.

Copilot uses AI. Check for mistakes.
Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not a request change but just to grab your attention

  • can you go over this example, and compare your local version of rendering to the deploy and make sure we don't have regression (i'm not sure if we have test for these)
    https://www.cornerstonejs.org/live-examples/dicomimageloaderwadouri

  • also can you connect it to OHIF and make sure US studies work fine, actually run the OHIF tests with your local version of cornerstone

@rodrigobasilio2022
Copy link
Collaborator Author

Look in to the example: one difference. In deflate option it gives an error and OSS silent give the same error, so i think the PR is better in not hiding problems. OHIF appears to look ok (didn't open all US examples)

Copy link
Collaborator

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I link to OHIF and run, I get an exception that hte palette colour hasn't been loaded yet. I suspect the load palette data is a little too late.

@wayfarer3130 wayfarer3130 merged commit c92964c into main Feb 17, 2026
10 checks passed
@wayfarer3130 wayfarer3130 deleted the fix/palleteColorImages branch February 17, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments