- if ( Pixel_Data )
- if ( LastAllocatedPixelDataLength != ImageDataSize )
- free(Pixel_Data);
- if ( !Pixel_Data )
- Pixel_Data = new uint8_t[ImageDataSize];
-
- if ( Pixel_Data )
- {
- LastAllocatedPixelDataLength = ImageDataSize;
-
- // we load the pixels (and transform grey level + LUT into RGB)
- GetImageDataIntoVector(Pixel_Data, ImageDataSize);
-
- // We say the value *is* loaded.
- GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
-
- // Will be 7fe0, 0010 in standard case
- GetHeader()->SetEntryBinAreaByNumber( Pixel_Data,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
- }
- PixelRead = 0; // no PixelRaw
-
- return Pixel_Data;
-}
-
-/**
- * \brief
- * Read the pixels from disk (uncompress if necessary),
- * Transforms YBR pixels, if any, into RGB pixels
- * Transforms 3 planes R, G, B, if any, into a single RGB Plane
- * Transforms single Grey plane + 3 Palettes into a RGB Plane
- * Copies at most MaxSize bytes of pixel data to caller allocated
- * memory space.
- * \warning This function allows people that want to build a volume
- * from an image stack *not to* have, first to get the image pixels,
- * and then move them to the volume area.
- * It's absolutely useless for any VTK user since vtk chooses
- * to invert the lines of an image, that is the last line comes first
- * (for some axis related reasons?). Hence he will have
- * to load the image line by line, starting from the end.
- * VTK users have to call GetImageData
- *
- * @param destination Address (in caller's memory space) at which the
- * pixel data should be copied
- * @param maxSize Maximum number of bytes to be copied. When MaxSize
- * is not sufficient to hold the pixel data the copy is not
- * executed (i.e. no partial copy).
- * @return On success, the number of bytes actually copied. Zero on
- * failure e.g. MaxSize is lower than necessary.
- */
-size_t File::GetImageDataIntoVector (void* destination, size_t maxSize)
-{
- GetImageDataIntoVectorRaw (destination, maxSize);
- PixelRead = 0 ; // =0 : no ImageDataRaw
- if ( !HeaderInternal->HasLUT() )
- {
- return ImageDataSize;
- }
-
- // from Lut R + Lut G + Lut B
- uint8_t *newDest = new uint8_t[ImageDataSize];
- uint8_t *a = (uint8_t *)destination;
- uint8_t *lutRGBA = HeaderInternal->GetLUTRGBA();
-
- if ( lutRGBA )
- {
- int j;
- // move Gray pixels to temp area
- memmove(newDest, destination, ImageDataSizeRaw);
- for (size_t i=0; i<ImageDataSizeRaw; ++i)
- {
- // Build RGB Pixels
- j = newDest[i]*4;
- *a++ = lutRGBA[j];
- *a++ = lutRGBA[j+1];
- *a++ = lutRGBA[j+2];
- }
- delete[] newDest;
-
- // now, it's an RGB image
- // Lets's write it in the Header
-
- // FIXME : Better use CreateOrReplaceIfExist ?
-
- std::string spp = "3"; // Samples Per Pixel
- HeaderInternal->SetEntryByNumber(spp,0x0028,0x0002);
- std::string rgb = "RGB "; // Photometric Interpretation
- HeaderInternal->SetEntryByNumber(rgb,0x0028,0x0004);
- std::string planConfig = "0"; // Planar Configuration
- HeaderInternal->SetEntryByNumber(planConfig,0x0028,0x0006);
-
- }
- else // GetLUTRGBA() failed
- {
- // (gdcm-US-ALOKA-16.dcm), contains Segmented xxx Palette Color
- // that are *more* than 65535 long ?!?
- // No idea how to manage such an image !
- // Need to make RGB Pixels (?) from grey Pixels (?!) and Gray Lut (!?!)
- // It seems that *no Dicom Viewer* has any idea :-(
-
- std::string photomInterp = "MONOCHROME1 "; // Photometric Interpretation
- HeaderInternal->SetEntryByNumber(photomInterp,0x0028,0x0004);
- }
-
- /// \todo Drop Palette Color out of the Header?
- return ImageDataSize;
-}
-
-/**
- * \brief Allocates necessary memory,
- * Transforms YBR pixels (if any) into RGB pixels
- * Transforms 3 planes R, G, B (if any) into a single RGB Plane
- * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
- * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
- * @return Pointer to newly allocated pixel data.
- * \ NULL if alloc fails
- */
-uint8_t* File::GetImageDataRaw ()
-{
- size_t imgDataSize;
- if ( HeaderInternal->HasLUT() )
- /// \todo Let Header user a chance to get the right value
- imgDataSize = ImageDataSizeRaw;
- else
- imgDataSize = ImageDataSize;
-
- // FIXME (Mathieu)
- // I need to deallocate Pixel_Data before doing any allocation:
-
- if ( Pixel_Data )
- if ( LastAllocatedPixelDataLength != imgDataSize )
- free(Pixel_Data);
- if ( !Pixel_Data )
- Pixel_Data = new uint8_t[imgDataSize];