+//
+// ------------------------ 'non string' elements related functions
+//
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Loads (from disk) the element content
+ * when a string is not suitable
+ */
+void * gdcmHeader::LoadElementVoidArea(guint16 Group, guint16 Elem) {
+ gdcmElValue * Element= PubElValSet.GetElementByNumber(Group, Elem);
+ if ( !Element )
+ return NULL;
+ size_t o =(size_t)Element->GetOffset();
+ fseek(fp, o, SEEK_SET);
+ int l=Element->GetLength();
+ void * a = malloc(l);
+ if(!a) {
+ cout << "Big Broblem (LoadElementVoidArea, malloc) "
+ << hex << Group << " " << Elem << "\n";
+ return NULL;
+ }
+ int res = PubElValSet.SetVoidAreaByNumber(a, Group, Elem);
+ // TODO check the result
+ size_t l2 = fread(a, 1, l ,fp);
+ if(l != l2) {
+ cout << "Big Broblem (LoadElementVoidArea, fread) "
+ << hex << Group << " " << Elem << "\n";
+ free(a);
+ return NULL;
+ }
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Gets (from Header) the offset of a 'non string' element value
+ * \ (LoadElementValue has already be executed)
+ * @param Group
+ * @param Elem
+ * @return File Offset of the Element Value
+ */
+ size_t gdcmHeader::GetPubElValOffsetByNumber(guint16 Group, guint16 Elem) {
+ gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
+ if (!elValue) {
+ dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
+ "failed to Locate gdcmElValue");
+ return (size_t)0;
+ }
+ return elValue->GetOffset();
+}
+
+/**
+ * \ingroup gdcmHeader
+* \brief Gets (from Header) a 'non string' element value
+ * \ (LoadElementValue has already be executed)
+ * @param Group
+ * @param Elem
+ * @return Pointer to the 'non string' area
+
+ */
+ void * gdcmHeader::GetPubElValVoidAreaByNumber(guint16 Group, guint16 Elem) {
+ gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
+ if (!elValue) {
+ dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
+ "failed to Locate gdcmElValue");
+ return (NULL);
+ }
+ return elValue->GetVoidArea();
+}
+
+
+//
+// =============================================================================
+// Heuristics based accessors
+//==============================================================================
+//
+
+// TODO : move to an other file.
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of columns of image.
+ * @return The encountered size when found, 0 by default.
+ */
+int gdcmHeader::GetXSize(void) {
+ // We cannot check for "Columns" because the "Columns" tag is present
+ // both in IMG (0028,0011) and OLY (6000,0011) sections of the dictionary.
+ string StrSize = GetPubElValByNumber(0x0028,0x0011);
+ if (StrSize == "gdcm::Unfound")
+ return 0;
+ return atoi(StrSize.c_str());
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of lines of image.
+ * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
+ * @return The encountered size when found, 1 by default.
+ */
+int gdcmHeader::GetYSize(void) {
+ // We cannot check for "Rows" because the "Rows" tag is present
+ // both in IMG (0028,0010) and OLY (6000,0010) sections of the dictionary.
+ string StrSize = GetPubElValByNumber(0x0028,0x0010);
+ if (StrSize != "gdcm::Unfound")
+ return atoi(StrSize.c_str());
+ if ( IsDicomV3() )
+ return 0;
+ else
+ // The Rows (0028,0010) entry is optional for ACR/NEMA. It might
+ // hence be a signal (1d image). So we default to 1:
+ return 1;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief Retrieve the number of planes of volume or the number
+ * of frames of a multiframe.
+ * \warning When present we consider the "Number of Frames" as the third
+ * dimension. When absent we consider the third dimension as
+ * being the "Planes" tag content.
+ * @return The encountered size when found, 1 by default.
+ */
+int gdcmHeader::GetZSize(void) {
+ // Both in DicomV3 and ACR/Nema the consider the "Number of Frames"
+ // as the third dimension.
+ 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) {
+ string StrSize = GetPubElValByNumber(0x0028,0x0101);
+ 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)
+ *
+ * @return The encountered number of Samples Per Pixel, 1 by default.
+ */
+int gdcmHeader::GetSamplesPerPixel(void) {
+ 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) {
+ 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) {
+ 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.
+ * @return
+ */
+string gdcmHeader::GetPixelType(void) {
+ string BitsAlloc;
+ BitsAlloc = GetElValByName("Bits Allocated");
+ if (BitsAlloc == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
+ BitsAlloc = string("16");
+ }
+ if (BitsAlloc == "12")
+ BitsAlloc = string("16");
+
+ string Signed;
+ Signed = GetElValByName("Pixel Representation");
+ if (Signed == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
+ BitsAlloc = string("0");
+ }
+ if (Signed == "0")
+ Signed = string("U");
+ else
+ Signed = string("S");
+
+ return( BitsAlloc + Signed);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,0030 : Pixel Spacing
+ * \ else 1.
+ * @return X dimension of a pixel
+ */
+float gdcmHeader::GetXSpacing(void) {
+ float xspacing, yspacing;
+ string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+
+ if (StrSpacing == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
+ return 1.;
+ }
+ if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
+ return 0.;
+ //else
+ return xspacing;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,0030 : Pixel Spacing
+ * \ else 1.
+ * @return Y dimension of a pixel
+ */
+float gdcmHeader::GetYSpacing(void) {
+ float xspacing, yspacing;
+ string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+
+ if (StrSpacing == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
+ return 1.;
+ }
+ if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
+ return 0.;
+ if (yspacing == 0.) {
+ dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
+ // seems to be a bug in the header ...
+ sscanf( StrSpacing.c_str(), "%f\\0\\%f", &xspacing, &yspacing);
+ }
+ return yspacing;
+}
+
+
+/**
+ *\ingroup gdcmHeader
+ *\brief gets the info from 0018,0088 : Space Between Slices
+ *\ else from 0018,0050 : Slice Thickness
+ *\ else 1.
+ * @return Z dimension of a voxel-to be
+ */
+float gdcmHeader::GetZSpacing(void) {
+ // TODO : translate into English
+ // Spacing Between Slices : distance entre le milieu de chaque coupe
+ // Les coupes peuvent etre :
+ // jointives (Spacing between Slices = Slice Thickness)
+ // chevauchantes (Spacing between Slices < Slice Thickness)
+ // disjointes (Spacing between Slices > Slice Thickness)
+ // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
+ // ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
+ // Si le Spacing Between Slices est absent,
+ // on suppose que les coupes sont jointives
+
+ string StrSpacingBSlices = GetPubElValByNumber(0x0018,0x0088);
+
+ if (StrSpacingBSlices == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
+ string StrSliceThickness = GetPubElValByNumber(0x0018,0x0050);
+ if (StrSliceThickness == "gdcm::Unfound")
+ return 1.;
+ else
+ // if no 'Spacing Between Slices' is found,
+ // we assume slices join together
+ // (no overlapping, no interslice gap)
+ // if they don't, we're fucked up
+ return atof(StrSliceThickness.c_str());
+ } else {
+ return atof(StrSpacingBSlices.c_str());
+ }
+}
+
+//
+// Image Position Patient (0020,0032):
+// If not found (ACR_NEMA) we try Image Position (0020,0030)
+// If not found (ACR-NEMA), we consider Slice Location (0020,1041)
+// or Location (0020,0050)
+// as the Z coordinate,
+// 0. for all the coordinates if nothing is found
+
+// TODO : find a way to inform the caller nothing was found
+// TODO : How to tell the caller a wrong number of values was found?
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ *\ else from 0020,0030 : Image Position (RET)
+ *\ else 0.
+ * @return up-left image corner position
+ */
+float gdcmHeader::GetXImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
+ StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
+ // How to tell the caller nothing was found ?
+ return 0.;
+ }
+ }
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
+ return 0.;
+ return xImPos;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ * \ else from 0020,0030 : Image Position (RET)
+ * \ else 0.
+ * @return up-left image corner position
+ */
+float gdcmHeader::GetYImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
+ StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
+ // How to tell the caller nothing was found ?
+ return 0.;
+ }
+ }
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
+ return 0.;
+ return yImPos;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ * \ else from 0020,0030 : Image Position (RET)
+ * \ else from 0020,1041 : Slice Location
+ * \ else from 0020,0050 : Location
+ * \ else 0.
+ * @return up-left image corner position
+ */
+float gdcmHeader::GetZImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+ if (StrImPos != "gdcm::Unfound") {
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position Patient (0020,0032)");
+ return 0.; // bug in the element 0x0020,0x0032
+ } else {
+ return zImPos;
+ }
+ }
+ StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+ if (StrImPos != "gdcm::Unfound") {
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
+ return 0.; // bug in the element 0x0020,0x0032
+ } else {
+ return zImPos;
+ }
+ }
+ string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
+ if (StrSliceLocation != "gdcm::Unfound") {
+ if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
+ return 0.; // bug in the element 0x0020,0x1041
+ } else {
+ return zImPos;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
+ string StrLocation = GetPubElValByNumber(0x0020,0x0050);
+ if (StrLocation != "gdcm::Unfound") {
+ if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
+ return 0.; // bug in the element 0x0020,0x0050
+ } else {
+ return zImPos;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");
+ return 0.; // Hopeless
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0002,0010 : Transfert Syntax
+ * \ else 1.
+ * @return Transfert Syntax Name (as oposite to Transfert Syntax UID)
+ */
+string gdcmHeader::GetTransferSyntaxName(void) {
+ string TransfertSyntax = GetPubElValByNumber(0x0002,0x0010);
+ if (TransfertSyntax == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetTransferSyntaxName: unfound Transfert Syntax (0002,0010)");
+ return "Uncompressed ACR-NEMA";
+ }
+ // we do it only when we need it
+ gdcmTS * ts = gdcmGlobal::GetTS();
+ string tsName=ts->GetValue(TransfertSyntax);
+ //delete ts; // Seg Fault when deleted ?!
+ return tsName;
+}
+
+// -------------------------------- Lookup Table related functions ------------
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
+ * \ else 0
+ * @return Lookup Table Length
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ */
+
+int gdcmHeader::GetLUTLength(void) {
+ vector<string> tokens;
+ int LutLength;
+ //int LutDepth;
+ //int LutNbits;
+ // Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
+ string LutDescriptionR = GetPubElValByNumber(0x0028,0x1101);
+ if (LutDescriptionR == "gdcm::Unfound")
+ return 0;
+ string LutDescriptionG = GetPubElValByNumber(0x0028,0x1102);
+ if (LutDescriptionG == "gdcm::Unfound")
+ return 0;
+ string LutDescriptionB = GetPubElValByNumber(0x0028,0x1103);
+ if (LutDescriptionB == "gdcm::Unfound")
+ return 0;
+ if( (LutDescriptionR != LutDescriptionG) || (LutDescriptionR != LutDescriptionB) ) {
+ dbg.Verbose(0, "gdcmHeader::GetLUTLength: The CLUT R,G,B are not equal");
+ return 0;
+ }
+ cout << "Lut Description " << LutDescriptionR <<"\n";
+ tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+ Tokenize (LutDescriptionR, tokens, "\\");
+ LutLength=atoi(tokens[0].c_str());
+ //LutDepth=atoi(tokens[1].c_str());
+ //LutNbits=atoi(tokens[2].c_str());
+ tokens.clear();
+ return LutLength;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
+ * \ else 0
+ * @return Lookup Table nBit
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ */
+
+int gdcmHeader::GetLUTNbits(void) {
+ vector<string> tokens;
+ //int LutLength;
+ //int LutDepth;
+ int LutNbits;
+ // Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
+ // Consistency already checked in GetLUTLength
+ string LutDescription = GetPubElValByNumber(0x0028,0x1101);
+ if (LutDescription == "gdcm::Unfound")
+ return 0;
+ tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+ Tokenize (LutDescription, tokens, "\\");
+ //LutLength=atoi(tokens[0].c_str());
+ //LutDepth=atoi(tokens[1].c_str());
+ LutNbits=atoi(tokens[2].c_str());
+ tokens.clear();
+ return LutNbits;
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,1201 : Lookup Table Red
+ * \ else 0
+ * @return Lookup Table Red
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ */
+void * gdcmHeader::GetLUTRed(void) {
+ return GetPubElValVoidAreaByNumber(0x0028,0x1201);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,1202 : Lookup Table Green
+ * \ else 0
+ * @return Lookup Table Red
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ */
+ void * gdcmHeader::GetLUTGreen(void) {
+ return GetPubElValVoidAreaByNumber(0x0028,0x1202);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief gets the info from 0028,1202 : Lookup Table Blue
+ * \ else 0
+ * @return Lookup Table Blue
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ */
+void * gdcmHeader::GetLUTBlue(void) {
+ return GetPubElValVoidAreaByNumber(0x0028,0x1203);
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return Lookup Table RGB
+ * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ * \ and (0028,1201),(0028,1202),(0028,1202) are found
+ * \warning : hazardous ! Use better GetPubElValVoidAreaByNumber
+ */
+void * gdcmHeader::GetLUTRGB(void) {
+// Not so easy : see
+// http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
+// and OT-PAL-8-face.dcm
+
+ if (GetPubElValByNumber(0x0028,0x0004) == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetLUTRGB: unfound Photometric Interpretation");
+ return NULL;
+ }
+ void * LutR,*LutG,*LutB;
+ int l;
+
+ // Maybe, some day we get an image
+ // that respects the definition ...
+ // Let's consider no ones does.
+
+ l= GetLUTLength();
+ if(l==0)
+ return (NULL);
+ int nBits=GetLUTNbits();
+ // a virer quand on aura trouve UNE image
+ // qui correspond VRAIMENT à la definition !
+ cout << "l " << l << " nBits " << nBits;
+
+ l= l/(nBits/8);
+
+ LutR =GetPubElValVoidAreaByNumber(0x0028,0x1201);
+ LutG =GetPubElValVoidAreaByNumber(0x0028,0x1202);
+ LutB =GetPubElValVoidAreaByNumber(0x0028,0x1203);
+
+ // Warning : Any value for nBits as to be considered as 8
+ // Any value for Length as to be considered as 256
+ // That's DICOM ...
+
+ // Just wait before removing the following code
+ /*
+ if (nBits == 16) {
+ guint16 * LUTRGB, *rgb;
+ LUTRGB = rgb = (guint16 *) malloc(3*l*sizeof( guint16));
+ guint16 * r = (guint16 *)LutR;
+ guint16 * g = (guint16 *)LutG;
+ guint16 * b = (guint16 *)LutB;
+ for(int i=0;i<l;i++) {
+ *rgb++ = *r++;
+ *rgb++ = *g++;
+ *rgb++ = *b++;
+ }
+ return(LUTRGB);
+ } else
+
+ */ { // we assume it's always 8 Bits
+ l=256; // we assume ...
+ unsigned char * LUTRGB, *rgb;
+ LUTRGB = rgb = (unsigned char *) malloc(3*l*sizeof( char));
+ unsigned char * r = (unsigned char *)LutR;
+ unsigned char * g = (unsigned char *)LutG;
+ unsigned char * b = (unsigned char *)LutB;
+ for(int i=0;i<l;i++) {
+ //cout << "lut16 " << i << " : " << *r << " " << *g << " " << *b << "\n";
+ printf("lut 8 %d : %d %d %d \n",i,*r,*g,*b);
+ *rgb++ = *r++;
+ *rgb++ = *g++;
+ *rgb++ = *b++;
+ }
+ free(LutR); free(LutB); free(LutG);
+ return(LUTRGB);
+ }