+ // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
+
+ char *LUTRGBA = (char *)calloc(1024,1); // 256 * 4 (R, G, B, Alpha)
+ if (!LUTRGBA) {
+ return NULL;
+ }
+ // Bits Allocated
+ int nb;
+ std::string str_nb = GetPubElValByNumber(0x0028,0x0100);
+ if (str_nb == GDCM_UNFOUND ) {
+ nb = 16;
+ } else {
+ nb = atoi(str_nb.c_str() );
+ }
+ int mult;
+
+ if (nbitsR==16 && nb==8) // when LUT item size is different than pixel size
+ mult=2; // high byte must be = low byte
+ else // See PS 3.3-2003 C.11.1.1.2 p 619
+ mult=1;
+
+
+ // if we get a black image, let's just remove the '+1'
+ // from 'i*mult+1' and check again
+ // if it works, we shall have to check the 3 Palettes
+ // to see which byte is ==0 (first one, or second one)
+ // and fix the code
+ // We give up the checking to avoid some overhead
+ char *a;
+ a= LUTRGBA+debR;
+ for(int i=0;i<lengthR;i++) {
+ *a = lutR[i*mult+1];
+ a+=4;
+ }
+ a= LUTRGBA+debG;
+ for(int i=0;i<lengthG;i++) {
+ *(a+1) = lutG[i*mult+1];
+ a+=4;
+ }
+ a= LUTRGBA+debB;
+ for(int i=0;i<lengthB;i++) {
+ *(a+2) = lutB[i*mult+1];
+ a+=4;
+ }
+ for(int i=0;i<255;i++) {
+ *(a+3) = 1; // Alpha component
+ a+=4;
+ }
+
+for (int i=0;i<255;i++)
+ printf ( "%d %02x %02x %02x %02x \n",
+ i,(LUTRGBA+i*4)[0],(LUTRGBA+i*4)[1],(LUTRGBA+i*4)[2],(LUTRGBA+i*4)[3]);
+
+// WHY does it seg fault ?!?
+//free(LutR); free(LutB); free(LutG); printf ("libere\n");
+
+ return(LUTRGBA);
+}