- size_t imgDataSize;
- if ( Header->HasLUT() )
- /// \todo Let gdcmHeader 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];
-
- if ( Pixel_Data )
- {
- LastAllocatedPixelDataLength = imgDataSize;
-
- // we load the pixels ( grey level or RGB, but NO transformation)
- GetImageDataIntoVectorRaw(Pixel_Data, imgDataSize);
-
- // We say the value *is* loaded.
- GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
-
- // will be 7fe0, 0010 in standard cases
- GetHeader()->SetEntryBinAreaByNumber(Pixel_Data,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
- }
- PixelRead = 1; // PixelRaw
-
- return Pixel_Data;
-}
-
-/**
- * \brief Copies at most MaxSize bytes of pixel data to caller's
- * memory space.
- * \warning This function was designed to avoid people that want to build
- * a volume from an image stack to need 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 hace to call GetImageData
- * \warning DOES NOT transform the Grey Plane + Palette Color (if any)
- * into a single RGB Pixels Plane
- * the (VTK) user will manage the palettes
- *
- * @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 gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t maxSize)
-{
- // we save the initial values of the following
- // in order to be able to restore the header in a disk-consistent state
- // (if user asks twice to get the pixels from disk)
-
- if ( PixelRead != -1 ) // File was "read" before
- {
- RestoreInitialValues();
- }
-
- PixelRead = 1 ; // PixelRaw
-
- if ( ImageDataSize > maxSize )
- {
- dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: pixel data bigger"
- "than caller's expected MaxSize");
- return (size_t)0;
- }
-
- ReadPixelData( destination );
-
- // Number of Bits Allocated for storing a Pixel
- int numberBitsAllocated = Header->GetBitsAllocated();
- if ( numberBitsAllocated == 0 )
- {
- numberBitsAllocated = 16;
- }
-
- // Number of Bits actually used
- int numberBitsStored = Header->GetBitsStored();
- if ( numberBitsStored == 0 )
- {
- numberBitsStored = numberBitsAllocated;
- }
-
- // High Bit Position
- int highBitPosition = Header->GetHighBitPosition();
- if ( highBitPosition == 0 )