- int nBytes= nb/8;
- int taille = Header->GetXSize() * Header->GetYSize()
- * Header->GetSamplesPerPixel();
- long fragmentBegining; // for ftell, fseek
-
- bool jpg2000 = Header->IsJPEG2000();
- bool jpgLossless = Header->IsJPEGLossless();
-
- bool res = true;
- uint16_t ItemTagGr, ItemTagEl;
- int ln;
-
- // Position on begining of Jpeg Pixels
-
- fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
- fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
- if(Header->GetSwapCode())
- {
- ItemTagGr = Header->SwapShort(ItemTagGr);
- ItemTagEl = Header->SwapShort(ItemTagEl);
- }
-
- fread(&ln,4,1,fp);
- if( Header->GetSwapCode() )
- {
- ln = Header->SwapLong( ln ); // Basic Offset Table Item length
- }
-
- if ( ln != 0 )
- {
- // What is it used for ?!?
- uint8_t* BasicOffsetTableItemValue = new uint8_t[ln+1];
- fread(BasicOffsetTableItemValue,ln,1,fp);
- //delete[] BasicOffsetTableItemValue;
- }
-
- // first Fragment initialisation
- fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
- fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
- if( Header->GetSwapCode() )
- {
- ItemTagGr = Header->SwapShort( ItemTagGr );
- ItemTagEl = Header->SwapShort( ItemTagEl );
- }
-
- // parsing fragments until Sequence Delim. Tag found
- while ( ItemTagGr == 0xfffe && ItemTagEl != 0xe0dd )
- {
- // --- for each Fragment
- fread(&ln,4,1,fp);
- if( Header->GetSwapCode() )
- {
- ln = Header->SwapLong(ln); // Fragment Item length
- }
- fragmentBegining = ftell( fp );
-
- if ( jpg2000 )
- {
- // JPEG 2000 : call to ???
- res = gdcm_read_JPEG2000_file (fp,destination); // Not Yet written
- // ------------------------------------- endif (JPEG2000)
- }
- else if (jpgLossless)
- {
- // JPEG LossLess : call to xmedcom Lossless JPEG
- // Reading Fragment pixels
- JPEGLosslessDecodeImage (fp, (uint16_t*)destination,
- Header->GetPixelSize() * 8 * Header->GetSamplesPerPixel(), ln);
- res = 1; // in order not to break the loop
-
- } // ------------------------------------- endif (JPEGLossless)
- else
- {
- // JPEG Lossy : call to IJG 6b
- if ( Header->GetBitsStored() == 8)
- {
- // Reading Fragment pixels
- res = gdcm_read_JPEG_file (fp,destination);
- }
- else
- {
- // Reading Fragment pixels
- res = gdcm_read_JPEG_file12 (fp,destination);
- }
- // ------------------------------------- endif (JPEGLossy)
- }
-
- if ( !res )
- {
- break;
- }
-
- // location in user's memory
- // for next fragment (if any)
- destination = (uint8_t*)destination + taille * nBytes;
-
- fseek(fp,fragmentBegining, SEEK_SET); // To be sure we start
- fseek(fp,ln,SEEK_CUR); // at the begining of next fragment
-
- ItemTagGr = ItemTagEl = 0;
- fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
- fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
- if( Header->GetSwapCode() )
- {
- ItemTagGr = Header->SwapShort( ItemTagGr );
- ItemTagEl = Header->SwapShort( ItemTagEl );
- }
- }
- // endWhile parsing fragments until Sequence Delim. Tag found
-
- Header->CloseFile();
- return res;
-}
-//-----------------------------------------------------------------------------