- std::string StrSize = GetPubElValByNumber(0x0028,0x0008);
- if (StrSize != GDCM_UNFOUND)
- return atoi(StrSize.c_str());
-
- // We then consider the "Planes" entry as the third dimension [we
- // cannot retrieve by name since "Planes tag is present both in
- // IMG (0028,0012) and OLY (6000,0012) sections of the dictionary].
- StrSize = GetPubElValByNumber(0x0028,0x0012);
- if (StrSize != GDCM_UNFOUND)
- return atoi(StrSize.c_str());
- return 1;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Retrieve the number of Bits Stored
- * (as opposite to number of Bits Allocated)
- *
- * @return The encountered number of Bits Stored, 0 by default.
- */
-int gdcmHeader::GetBitsStored(void) {
- std::string StrSize = GetPubElValByNumber(0x0028,0x0101);
- if (StrSize == GDCM_UNFOUND)
- return 1;
- return atoi(StrSize.c_str());
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Retrieve the number of Bits Allocated
- * (8, 12 -compacted ACR-NEMA files, 16, ...)
- *
- * @return The encountered number of Bits Allocated, 0 by default.
- */
-int gdcmHeader::GetBitsAllocated(void) {
- std::string StrSize = GetPubElValByNumber(0x0028,0x0100);
- if (StrSize == GDCM_UNFOUND)
- return 1;
- return atoi(StrSize.c_str());
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Retrieve the number of Samples Per Pixel
- * (1 : gray level, 3 : RGB -1 or 3 Planes-)
- *
- * @return The encountered number of Samples Per Pixel, 1 by default.
- */
-int gdcmHeader::GetSamplesPerPixel(void) {
- std::string StrSize = GetPubElValByNumber(0x0028,0x0002);
- if (StrSize == GDCM_UNFOUND)
- return 1; // Well, it's supposed to be mandatory ...
- return atoi(StrSize.c_str());
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Retrieve the Planar Configuration for RGB images
- * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
- *
- * @return The encountered Planar Configuration, 0 by default.
- */
-int gdcmHeader::GetPlanarConfiguration(void) {
- std::string StrSize = GetPubElValByNumber(0x0028,0x0006);
- if (StrSize == GDCM_UNFOUND)
- return 0;
- return atoi(StrSize.c_str());
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Return the size (in bytes) of a single pixel of data.
- * @return The size in bytes of a single pixel of data.
- *
- */
-int gdcmHeader::GetPixelSize(void) {
- std::string PixelType = GetPixelType();
- if (PixelType == "8U" || PixelType == "8S")
- return 1;
- if (PixelType == "16U" || PixelType == "16S")
- return 2;
- if (PixelType == "32U" || PixelType == "32S")
- return 4;
- dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
- return 0;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Build the Pixel Type of the image.
- * Possible values are:
- * - 8U unsigned 8 bit,
- * - 8S signed 8 bit,
- * - 16U unsigned 16 bit,
- * - 16S signed 16 bit,
- * - 32U unsigned 32 bit,
- * - 32S signed 32 bit,
- * \warning 12 bit images appear as 16 bit.
- * \ 24 bit images appear as 8 bit
- * @return
- */
-std::string gdcmHeader::GetPixelType(void) {
- std::string BitsAlloc;
- BitsAlloc = GetPubElValByNumber(0x0028, 0x0100); // Bits Allocated
- if (BitsAlloc == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
- BitsAlloc = std::string("16");
- }
- if (BitsAlloc == "12") // It will be unpacked
- BitsAlloc = std::string("16");
- else if (BitsAlloc == "24") // (in order no to be messed up
- BitsAlloc = std::string("8"); // by old RGB images)
-
- std::string Signed;
- Signed = GetPubElValByNumber(0x0028, 0x0103); // "Pixel Representation"
- if (Signed == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
- BitsAlloc = std::string("0");
- }
- if (Signed == "0")
- Signed = std::string("U");
- else
- Signed = std::string("S");
-
- return( BitsAlloc + Signed);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Recover the offset (from the beginning of the file) of the pixels.
- */
-size_t gdcmHeader::GetPixelOffset(void) {
- // If this file complies with the norm we should encounter the
- // "Image Location" tag (0x0028, 0x0200). This tag contains the
- // the group that contains the pixel data (hence the "Pixel Data"
- // is found by indirection through the "Image Location").
- // Inside the group pointed by "Image Location" the searched element
- // is conventionally the element 0x0010 (when the norm is respected).
- // When the "Image Location" is absent we default to group 0x7fe0.
- guint16 grPixel;
- guint16 numPixel;
- std::string ImageLocation = GetPubElValByNumber(0x0028, 0x0200);
- if ( ImageLocation == GDCM_UNFOUND ) { // Image Location
- grPixel = 0x7fe0;
- } else {
- grPixel = (guint16) atoi( ImageLocation.c_str() );
- }
- if (grPixel != 0x7fe0)
- // This is a kludge for old dirty Philips imager.
- numPixel = 0x1010;
- else
- numPixel = 0x0010;
-
- gdcmElValue* PixelElement = PubElValSet.GetElementByNumber(grPixel,
- numPixel);
- if (PixelElement)
- return PixelElement->GetOffset();
- else
- return 0;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Recover the pixel area length (in Bytes) .
- */
-size_t gdcmHeader::GetPixelAreaLength(void) {
- // If this file complies with the norm we should encounter the
- // "Image Location" tag (0x0028, 0x0200). This tag contains the
- // the group that contains the pixel data (hence the "Pixel Data"
- // is found by indirection through the "Image Location").
- // Inside the group pointed by "Image Location" the searched element
- // is conventionally the element 0x0010 (when the norm is respected).
- // When the "Image Location" is absent we default to group 0x7fe0.
- guint16 grPixel;
- guint16 numPixel;
- std::string ImageLocation = GetPubElValByNumber(0x0028, 0x0200);
- if ( ImageLocation == GDCM_UNFOUND ) {
- grPixel = 0x7fe0;
- } else {
- grPixel = (guint16) atoi( ImageLocation.c_str() );
- }
- if (grPixel != 0x7fe0)
- // This is a kludge for old dirty Philips imager.
- numPixel = 0x1010;
- else
- numPixel = 0x0010;
-
- gdcmElValue* PixelElement = PubElValSet.GetElementByNumber(grPixel,
- numPixel);
- if (PixelElement)
- return PixelElement->GetLength();
- else
- return 0;
-}