+bool gdcmFile::ReadPixelData(void* destination) {
+ if ( !OpenFile())
+ return false;
+
+ printf("GetPixelOffset() %d\n",GetPixelOffset() );
+
+ if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
+ CloseFile();
+ return false;
+ }
+
+ if ( !IsDicomV3() ||
+ IsImplicitVRLittleEndianTransferSyntax() ||
+ IsExplicitVRLittleEndianTransferSyntax() ||
+ IsExplicitVRBigEndianTransferSyntax() ||
+ IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
+
+ size_t ItemRead = fread(destination, lgrTotale, 1, fp);
+ if ( ItemRead != 1 ) {
+ CloseFile();
+ return false;
+ } else {
+ CloseFile();
+ return true;
+ }
+ }
+
+ // ------------------------------- Position on begining of Jpeg Pixels
+
+ int ln;
+ fseek(fp,4,SEEK_CUR);
+ fread(&ln,4,1,fp);
+ if(GetSwapCode())
+ ln=SwapLong(ln);
+ if (DEBUG)
+ printf ("ln %d\n",ln);
+ fseek(fp,ln,SEEK_CUR);
+ fseek(fp,4,SEEK_CUR);
+ fread(&ln,4,1,fp);
+ if(GetSwapCode())
+ ln=SwapLong(ln);
+ if (DEBUG)
+ printf ("ln image comprimée %d\n",ln);
+
+ // ------------------------------- JPEG LossLess : call to Jpeg Libido
+
+ if (IsJPEGLossless()) {
+
+ ClbJpeg* jpg = _IdDcmJpegRead(fp);
+ if(jpg == NULL) {
+ CloseFile();
+ return false;
+ }
+
+ int nb;
+ string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
+ if (str_nb == "gdcm::Unfound" ) {
+ nb = 16;
+ } else {
+ nb = atoi(str_nb.c_str() );
+ if (nb == 12) nb =16;
+ }
+ int nBytes= nb/8;
+ int * dataJpg = jpg->DataImg;
+ int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel();
+
+ switch (nBytes) {
+ case 1:
+ {
+ unsigned short *dest = (unsigned short *)destination;
+ for (int i=0; i<taille; i++) {
+ *((unsigned char *)dest+i) = *(dataJpg +i);
+ }
+ }
+ break;
+
+ case 2:
+ {
+ unsigned short *dest = (unsigned short *)destination;
+ for (int i=0; i<taille; i++) {
+ *((unsigned short *)dest+i) = *(dataJpg +i);
+ }
+ }
+ break;
+
+ case 4:
+ {
+ unsigned int *dest=(unsigned int *)destination;
+ for (int i=0;i<taille; i++) {
+ *((unsigned int *)dest+i) = *(dataJpg +i);
+ }
+ }
+ break;
+ }
+
+ _IdDcmJpegFree (jpg);
+ return true;
+ }
+
+ // ------------------------------- JPEG Lossy : call to IJG 6b
+
+ // TODO : faire qq chose d'intelligent pour limiter
+ // la duplication du code JPEG <bits=8 / bits=12>
+ // TODO : eplucher icelui pour traiter *egalement* bits=16
+
+ int nBS;
+ if ((nBS = GetBitsStored()) != 12) {
+ printf("Sorry, Bits Stored = %d not yet taken into account\n",nBS);
+ return false;
+ }
+
+ bool res = (bool)gdcm_read_JPEG_file (destination);
+ return res;
+}