- int nb, nbu, highBit, sign;
-
- // 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
- std::string str_nb = Header->GetEntryByNumber(0x0028,0x0100);
- if ( str_nb == GDCM_UNFOUND )
- {
- nb = 16;
- }
- else
- {
- nb = atoi( str_nb.c_str() );
- // FIXME
- // From reading SetPixelDataSizeFromHeader, it seems 12 should be treated
- // separately, correct ?
- }
-
- // Number of Bits actually used
- std::string str_nbu = Header->GetEntryByNumber(0x0028,0x0101);
- if ( str_nbu == GDCM_UNFOUND )
- {
- nbu = nb;
- }
- else
- {
- nbu = atoi( str_nbu.c_str() );
- }
-
- // High Bit Position
- std::string str_highBit = Header->GetEntryByNumber(0x0028,0x0102);
- if ( str_highBit == GDCM_UNFOUND )
- {
- highBit = nb - 1;
- }
- else
- {
- highBit = atoi( str_highBit.c_str() );
- }
-
- // Pixel sign
- // 0 = Unsigned
- // 1 = Signed
- std::string str_sign = Header->GetEntryByNumber(0x0028,0x0103);
- if ( str_sign == GDCM_UNFOUND )
- {
- sign = 0; // default is unsigned
- }
- else
- {
- sign = atoi( str_sign.c_str() );
- }
-
- // re arange bytes inside the integer (processor endianity)
- if ( nb != 8 )
- {
- SwapZone(destination, Header->GetSwapCode(), ImageDataSize, nb);
- }
-
- // to avoid pb with some xmedcon breakers images
- if ( nb == 16 && nbu < nb && sign == 0)
- {
- int l = (int)(ImageDataSize / (nb/8));
- uint16_t *deb = (uint16_t *)destination;
- for(int i = 0; i<l; i++)
- {
- if( *deb == 0xffff )
- {
- *deb = 0;
- }
- deb++;
- }
- }
-
- // re arange bits inside the bytes
- if ( nbu != nb )
- {
- int l = (int)(ImageDataSize / (nb/8));
- if ( nb == 16 )
- {
- uint16_t mask = 0xffff;
- mask = mask >> (nb-nbu);
- uint16_t *deb = (uint16_t *)destination;
- for(int i = 0; i<l; i++)
- {
- *deb = (*deb >> (nbu - highBit - 1)) & mask;
- deb++;
- }
- }
- else if ( nb == 32 )
- {
- uint32_t mask = 0xffffffff;
- mask = mask >> (nb - nbu);
- uint32_t *deb = (uint32_t *)destination;
- for(int i = 0; i<l; i++)
- {
- *deb = (*deb >> (nbu - highBit - 1)) & mask;
- deb++;
- }
- }
- else
- {
- dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: weird image");
- return 0;
- }
- }
-/// \todo
-/// DO NOT remove this code commented out.
-/// Nobody knows what's expecting you ...
-/// Just to 'see' what was actually read on disk :-(
-///
-/// FILE* f2;
-/// f2 = fopen("SpuriousFile.RAW","wb");
-/// fwrite(destination,ImageDataSize,1,f2);
-/// fclose(f2);
-
- // Deal with the color
- // -------------------
-
- std::string str_PhotometricInterpretation =
- Header->GetEntryByNumber(0x0028,0x0004);