- if ( str_PhotometricInterpretation == "MONOCHROME1 "
- || str_PhotometricInterpretation == "MONOCHROME2 " )
- {
- return ImageDataSize;
- }
-
- // Planar configuration = 0 : Pixels are already RGB
- // Planar configuration = 1 : 3 planes : R, G, B
- // Planar configuration = 2 : 1 gray Plane + 3 LUT
-
- // Well ... supposed to be !
- // See US-PAL-8-10x-echo.dcm: PlanarConfiguration=0,
- // PhotometricInterpretation=PALETTE COLOR
- // and heuristic has to be found :-(
-
- int planConf = Header->GetPlanarConfiguration(); // 0028,0006
-
- // Whatever Planar Configuration is,
- // "PALETTE COLOR " implies that we deal with the palette.
- if ( str_PhotometricInterpretation == "PALETTE COLOR ")
- {
- planConf = 2;
- }
-
- switch ( planConf )
- {
- case 0:
- // Pixels are already RGB
- break;
- case 1:
- if (str_PhotometricInterpretation == "YBR_FULL")
- {
- // Warning : YBR_FULL_422 acts as RGB
- // : we need to make RGB Pixels from Planes Y,cB,cR
-
- // to see the tricks about YBR_FULL, YBR_FULL_422,
- // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
- // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
- // and be *very* affraid
- //
- int l = Header->GetXSize() * Header->GetYSize();
- int nbFrames = Header->GetZSize();
-
- uint8_t* newDest = new uint8_t[ImageDataSize];
- uint8_t* x = newDest;
- uint8_t* a = (uint8_t*)destination;
- uint8_t* b = a + l;
- uint8_t* c = b + l;
- double R,G,B;
-
- /// \todo : Replace by the 'well known' integer computation
- /// counterpart
- /// see http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
- /// for code optimisation
-
- for (int i = 0; i < nbFrames; i++)
- {
- for (int j = 0; j < l; j++)
- {
- R = 1.164 *(*a-16) + 1.596 *(*c -128) + 0.5;
- G = 1.164 *(*a-16) - 0.813 *(*c -128) - 0.392 *(*b -128) + 0.5;
- B = 1.164 *(*a-16) + 2.017 *(*b -128) + 0.5;
-
- if (R < 0.0) R = 0.0;
- if (G < 0.0) G = 0.0;
- if (B < 0.0) B = 0.0;
- if (R > 255.0) R = 255.0;
- if (G > 255.0) G = 255.0;
- if (B > 255.0) B = 255.0;
-
- *(x++) = (uint8_t)R;
- *(x++) = (uint8_t)G;
- *(x++) = (uint8_t)B;
- a++; b++; c++;
- }
- }
- memmove(destination, newDest, ImageDataSize);
- delete[] newDest;
- }
- else
- {
- // need to make RGB Pixels from R,G,B Planes
- // (all the Frames at a time)
-
- int l = Header->GetXSize() * Header->GetYSize() * Header->GetZSize();
-
- uint8_t *newDest = new uint8_t[ImageDataSize];
- uint8_t *x = newDest;
- uint8_t *a = (uint8_t *)destination;
- uint8_t *b = a + l;
- uint8_t *c = b + l;
-
- for (int j = 0; j < l; j++)
- {
- *(x++) = *(a++);
- *(x++) = *(b++);
- *(x++) = *(c++);
- }
- memmove(destination, newDest, ImageDataSize);
- delete[] newDest;
- }
- break;
- case 2:
- // Palettes were found
- // Let the user deal with them !
- return ImageDataSize;
- }
- // now, it's an RGB image
- // Lets's write it in the Header
-
- // Droping Palette Color out of the Header
- // has been moved to the Write process.
-
- // TODO : move 'values' modification to the write process
- // : save also (in order to be able to restore)
- // : 'high bit' -when not equal to 'bits stored' + 1
- // : 'bits allocated', when it's equal to 12 ?!
-
- std::string spp = "3"; // Samples Per Pixel
- std::string photInt = "RGB "; // Photometric Interpretation
- std::string planConfig = "0"; // Planar Configuration
-
- Header->SetEntryByNumber(spp,0x0028,0x0002);
- Header->SetEntryByNumber(photInt,0x0028,0x0004);
- Header->SetEntryByNumber(planConfig,0x0028,0x0006);
-
- return ImageDataSize;