L_DicomGetOverlayBitmap

Summary

Retrieves the "Overlay Data" (60xx,3000) for the specified overlay index.

Syntax

#include "ltdic.h"

L_LTDIC_API L_UINT16 L_DicomGetOverlayBitmap(hDS, uOverlayIndex, pBitmap, uStructSize, uFlags)

Parameters

HDICOMDS hDS

A DICOM handle.

L_UINT uOverlayIndex

The index of the overlay for which to get the bitmap. This index is zero-based.

pBITMAPHANDLE pBitmap

Pointer to a bitmap handle which will be filled with the overlay data. Cannot be NULL.

L_UINT uStructSize

Size of the BITMAPHANDLE structure. Pass sizeof(BITMAPHANDLE).

L_UINT uFlags

Reserved for future use. Pass 0.

Returns

Value Meaning
DICOM_SUCCESS The function was successful.
>0 An error occurred. Refer to Return Codes.

Comments

This function will extract the "Overlay Data" (60xx,3000) for an overlay, initialize and allocate pBitmap based on the "Overlay Columns" (60xx,0011) and "Overlay Rows"(60xx,0010), and then fill pBitmap with the stream of bytes under the "Overlay Data" (60xx,3000) element. Please note that pBitmap is assumed to be unallocated and un-initialized. It will be filled without freeing the existing data.

If the function does not find the "Overlay Data" element inside the dataset it will return DICOM_ERROR_OVERLAY_DATA_MISSING.

Before calling this function you must call L_DicomGetOverlayAttributes to determine if the overlay pixel data is embedded in the "Image Pixel Data" (7FE0,0010) element or is under "Overlay Data" (60xx,3000) element. If the overlay data is embedded in the "Image Pixel Data", the flag OVERLAY_USEBITPLANE will be set inside pOverlayAttributes->uFlags (pOverlayAttributes is the OVERLAYATTRIBUTES structure returned by the L_DicomGetOverlayAttributes function).

If the overlay pixel data is embedded in the "Image Pixel Data" (7FE0, 0010), follow these steps to get the overlay data as a bitmap handle:

  1. Call one of the functions that can be used to extract the "Image Pixel Data", such as L_DicomGetImage. This will return a bitmap handle populated with the "Image Pixel Data" which has the overlay data embedded. For this example, assume that the bitmap handle returned by this function is called pMainBitmap.

  2. Call L_DicomGetOverlayAttributes to get the attributes of the overlay. For this example, assume that the OVERLAYATTRIBUTES structure returned by this function is called pOverlayAttributes.

  3. Now we need to add our overlay as one of the overlays associated with pMainBitmap. To do that we need to call L_SetOverlayAttributes:

    • L_SetOverlayAttributes(pMainBitmap,0,pOverlayAttributes, OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_BITINDEX | OVERLAYATTRIBUTES_ORIGIN | OVERLAYATTRIBUTES_DICOM | OVERLAYATTRIBUTES_COLOR);
    • We are assuming that this is the first overlay in the bitmap, thus we are passing 0 as the overlay index.
  4. Now we need extract the overlay data from the main image data

  5. Now call L_GetOverlayBitmap to get the overlay data itself as a bitmap handle.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example will extract the overlays from a DICOM dataset and associate them with a bitmap,
the bitmap is assumed to be extracted from the same DICOM dataset.

L_INT DicomGetOverlayBitmapExample( 
   HDICOMDS hDicomDS,      // handle to Dicom DS 
   pBITMAPHANDLE pBitmap)  // Bitmap which will be associated with 
                           // the overlays, note this should be a  
                           // valid bitmap loaded from the same DICOM  
                           // dataset where the overlays exist. 
{ 
   L_UINT16             uRet; 
   L_UINT               uOverlayCount; 
   L_UINT               uOverlayIndex; 
   OVERLAYATTRIBUTES    OverlayAttributes = {0}; 
   L_INT                GroupNumber=0; 
   L_BOOL               IsOverlayInDataset = FALSE;  
   L_INT                nLEADRet; 
   L_UINT               uLEADOverlayIndex; 
   BITMAPHANDLE         OverlayBitmap = {0}; 
 
   //(1)Sanity Check ! 
   if((NULL == pBitmap) ||  (NULL == hDicomDS)) 
      return DICOM_ERROR_NULL_PTR; 
 
   uOverlayCount =0; 
 
   //(2)Do we have any overlays at all 
   uRet = L_DicomGetOverlayCount(hDicomDS,&uOverlayCount); 
   if( (DICOM_SUCCESS !=uRet) || (0 == uOverlayCount) ) 
      return DICOM_SUCCESS; 
 
   //(3)Go through the overlays one by one 
   uOverlayIndex     = 0; 
   uLEADOverlayIndex = 0; 
   while(uOverlayIndex < uOverlayCount) 
   { 
      // Reset the overlay attributes structure 
      memset(&OverlayAttributes,0,sizeof(OverlayAttributes)); 
      GroupNumber                =  0; 
      IsOverlayInDataset         = FALSE; 
 
      // Reset the overlay bitmap 
       (&OverlayBitmap, sizeof(OverlayBitmap), 1, 1, 1); 
 
      // Get the attributes of this overlay 
      uRet = L_DicomGetOverlayAttributes( hDicomDS, uOverlayIndex, &OverlayAttributes, sizeof(OverlayAttributes), &GroupNumber, &IsOverlayInDataset,0); 
      if(DICOM_SUCCESS !=uRet) 
         return uRet; 
 
      if(!IsOverlayInDataset) 
      { 
         uOverlayIndex++; 
         continue; 
      } 
 
      // Auto paint and process overlays 
      OverlayAttributes.uFlags |= OVERLAY_AUTOPAINT | OVERLAY_AUTOPROCESS; 
      OverlayAttributes.crColor = RGB(0xFF,0xFF,0xFF); 
 
      // Is the overlay embedded inside the image data ? 
      if(OverlayAttributes.uFlags & OVERLAY_USEBITPLANE) 
      { 
         // Add this overlay to the list of overlays 
         // in the bitmap handle 
         nLEADRet =  L_SetOverlayAttributes(pBitmap, uLEADOverlayIndex, &OverlayAttributes, OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_BITINDEX | OVERLAYATTRIBUTES_ORIGIN | OVERLAYATTRIBUTES_DICOM | OVERLAYATTRIBUTES_COLOR); 
         if(SUCCESS != nLEADRet) 
            return DICOM_ERROR_MEMORY; 
 
         // Make sure to extract the overlay data from the image data 
         nLEADRet = L_UpdateBitmapOverlayBits(pBitmap, uLEADOverlayIndex, SETOVERLAYBITS_FROMBITMAP); 
         if(SUCCESS != nLEADRet) 
            return DICOM_ERROR_MEMORY; 
      } 
      // The overlay is inside overlay data 
      else 
      { 
         // Add this overlay to the list of overlays 
         // in the bitmap handle 
         nLEADRet = L_SetOverlayAttributes(pBitmap, uLEADOverlayIndex, &OverlayAttributes, OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_ORIGIN | OVERLAYATTRIBUTES_DICOM | OVERLAYATTRIBUTES_COLOR); 
         if(SUCCESS != nLEADRet) 
            return DICOM_ERROR_MEMORY; 
 
         // Get the overlay bitmap from the overlay data 
         uRet = L_DicomGetOverlayBitmap(hDicomDS , uOverlayIndex, &OverlayBitmap, sizeof(OverlayBitmap), 0); 
         if(DICOM_SUCCESS !=uRet) 
            return uRet; 
 
         // Set the bitmap for this overlay inside the  
         // list of overlays we have in the bitmap handle 
         nLEADRet = L_SetOverlayBitmap(pBitmap, uLEADOverlayIndex, &OverlayBitmap, OVERLAY_MOVE); 
         if(SUCCESS != nLEADRet) 
         { 
            if(OverlayBitmap.Flags.Allocated) 
            { 
               L_FreeBitmap(&OverlayBitmap); 
               memset(&OverlayBitmap,0,sizeof(OverlayBitmap)); 
            } 
            return DICOM_ERROR_MEMORY; 
         } 
         memset(&OverlayBitmap,0,sizeof(OverlayBitmap)); 
      } 
      uOverlayIndex++; 
      uLEADOverlayIndex++; 
   } 
   return DICOM_SUCCESS; 
} 

Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.