- * \brief computes the length (in bytes) we must ALLOCATE to receive the
- * image(s) pixels (multiframes taken into account)
- * \warning : it is NOT the group 7FE0 length
- * (no interest for compressed images).
- */
-int File::ComputeDecompressedPixelDataSizeFromHeader()
-{
- // see PS 3.3-2003 : C.7.6.3.2.1
- //
- // MONOCHROME1
- // MONOCHROME2
- // PALETTE COLOR
- // RGB
- // HSV (Retired)
- // ARGB (Retired)
- // CMYK (Retired)
- // YBR_FULL
- // YBR_FULL_422 (no LUT, no Palette)
- // YBR_PARTIAL_422
- // YBR_ICT
- // YBR_RCT
-
- // LUT's
- // ex : gdcm-US-ALOKA-16.dcm
- // 0028|1221 [OW] [Segmented Red Palette Color Lookup Table Data]
- // 0028|1222 [OW] [Segmented Green Palette Color Lookup Table Data]
- // 0028|1223 [OW] [Segmented Blue Palette Color Lookup Table Data]
-
- // ex : OT-PAL-8-face.dcm
- // 0028|1201 [US] [Red Palette Color Lookup Table Data]
- // 0028|1202 [US] [Green Palette Color Lookup Table Data]
- // 0028|1203 [US] [Blue Palette Color Lookup Table Data]
-
- int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
- // Number of "Bits Allocated" is fixed to 16 when:
- // - it is not defined (i.e. it's value is 0)
- // - it's 12, since we will expand the image to 16 bits (see
- // PixelConvert::ConvertDecompress12BitsTo16Bits() )
- if ( ( numberBitsAllocated == 0 ) || ( numberBitsAllocated == 12 ) )
- {
- numberBitsAllocated = 16;
- }
-
- int DecompressedSize = HeaderInternal->GetXSize()
- * HeaderInternal->GetYSize()
- * HeaderInternal->GetZSize()
- * ( numberBitsAllocated / 8 )
- * HeaderInternal->GetSamplesPerPixel();
-
- return DecompressedSize;
-}
-
-/**
- * \brief - Allocates necessary memory,
- * - Reads 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 the pixel data (image[s]/volume[s]) to newly allocated zone.
- * @return Pointer to newly allocated pixel data.
- * NULL if alloc fails
- */
-uint8_t* File::GetImageData()
-{
- // FIXME (Mathieu)
- // I need to deallocate Pixel_Data before doing any allocation:
-
- 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
+ * \brief Check whether this a MONOCHROME1 picture (high values = dark)
+ * or not using "Photometric Interpretation" tag (0x0028,0x0004).
+ * @return true when "MONOCHROME1" . False otherwise.
+ */
+bool File::IsMonochrome1()
+{
+ const std::string &PhotometricInterp = GetEntryString( 0x0028, 0x0004 );
+ if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
+ }
+ return false;
+}
+
+/**
+ * \brief Check whether this a "PALETTE COLOR" picture or not by accessing
+ * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
+ * @return true when "PALETTE COLOR". False otherwise.
+ */
+bool File::IsPaletteColor()
+{
+ std::string PhotometricInterp = GetEntryString( 0x0028, 0x0004 );
+ if ( PhotometricInterp == "PALETTE COLOR " )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Palette color (0028,0004)");
+ }
+ return false;
+}