- // re arange bits inside the bytes
- if (nbu != nb){
- int l = (int)lgrTotale / (nb/8);
- if (nb == 16) {
- guint16 mask = 0xffff;
- mask = mask >> (nb-nbu);
- guint16 *deb = (guint16 *)destination;
- for(int i = 0; i<l; i++) {
- *deb = (*deb >> (nbu-highBit-1)) & mask;
- deb ++;
- }
- } else if (nb == 32 ) {
- guint32 mask = 0xffffffff;
- mask = mask >> (nb-nbu);
- guint32 *deb = (guint32 *)destination;
- for(int i = 0; i<l; i++) {
- *deb = (*deb >> (nbu-highBit-1)) & mask;
- deb ++;
- }
- } else {
- dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: wierd image");
- return (size_t)0;
- }
- }
-
-// Just to 'see' was was actually read on disk :-(
-// Some troubles expected
-
- // *Try* to deal with the color
- // ----------------------------
-
- // 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 :-(
-
- std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
-
- if ( (str_PhotometricInterpretation == "MONOCHROME1 ")
- || (str_PhotometricInterpretation == "MONOCHROME2 ")
- || (str_PhotometricInterpretation == "RGB")) {
- return lgrTotale;
- }
- int planConf=GetPlanarConfiguration();
-
- // 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 (?!)
-
- // need to make RGB Pixels from Planes Y,cB,cR
- // see http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
- // for code optimisation
-
- int l = GetXSize()*GetYSize();
- int nbFrames = GetZSize();
-
- unsigned char * newDest = (unsigned char*) malloc(lgrTotale);
- unsigned char *x = newDest;
- unsigned char * a = (unsigned char *)destination;
- unsigned char * b = a + l;
- unsigned char * c = b + l;
-
- double R,G,B;
-
- // TODO : Replace by the 'well known'
- // integer computation counterpart
- 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++) = (unsigned char)R;
- *(x++) = (unsigned char)G;
- *(x++) = (unsigned char)B;
- a++; b++; c++;
- }
- }
- memmove(destination,newDest,lgrTotale);
- free(newDest);
-
- } else {
-
- // need to make RGB Pixels from Planes R,G,B
-
- int l = GetXSize()*GetYSize();
- int nbFrames = GetZSize();
-
- char * newDest = (char*) malloc(lgrTotale);
- char *x = newDest;
- char * a = (char *)destination;
- char * b = a + l;
- char * c = b + l;
-
- // TODO :
- // any trick not to have to allocate temporary buffer is welcome ...
-
- for (int i=0;i<nbFrames;i++) {
- for (int j=0;j<l; j++) {
- *(x++) = *(a++);
- *(x++) = *(b++);
- *(x++) = *(c++);
- }
- }
- memmove(destination,newDest,lgrTotale);
- free(newDest);
- }