- // ---------------------- Run Length Encoding
-
- if (gdcmHeader::IsRLELossLessTransferSyntax()) {
- int res = (bool)gdcm_read_RLE_file (destination);
- return res;
- }
-
- // --------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000
-
- int nb;
- std::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; // ?? 12 should be ACR-NEMA only ?
- }
- int nBytes= nb/8;
-
- int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
- long fragmentBegining; // for ftell, fseek
-
- bool jpg2000 = IsJPEG2000();
- bool jpgLossless = IsJPEGLossless();
-
- bool res = true;
- guint16 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(GetSwapCode()) {
- ItemTagGr=SwapShort(ItemTagGr);
- ItemTagEl=SwapShort(ItemTagEl);
- }
- fread(&ln,4,1,fp);
- if(GetSwapCode())
- ln=SwapLong(ln); // Basic Offset Table Item length
-
- if (ln != 0) {
- // What is it used for ?!?
- char *BasicOffsetTableItemValue = (char *)malloc(ln+1);
- fread(BasicOffsetTableItemValue,ln,1,fp);
- }
-
- // first Fragment initialisation
- fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
- fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
- if(GetSwapCode()) {
- ItemTagGr=SwapShort(ItemTagGr);
- ItemTagEl=SwapShort(ItemTagEl);
- }
-
- // parsing fragments until Sequence Delim. Tag found
-
- while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
-
- // --- for each Fragment
-
- fread(&ln,4,1,fp);
- if(GetSwapCode())
- ln=SwapLong(ln); // Fragment Item length
-
- fragmentBegining=ftell(fp);
-
- if (jpg2000) { // JPEG 2000 : call to ???
-
- res = (bool)gdcm_read_JPEG2000_file (destination); // Not Yet written
-
- } // ------------------------------------- endif (JPEG2000)
-
- else if (jpgLossless) { // JPEG LossLess : call to xmedcom JPEG
-
- JPEGLosslessDecodeImage (fp, // Reading Fragment pixels
- (unsigned short *)destination,
- GetPixelSize()*8* GetSamplesPerPixel(),
- ln);
- res=1; // in order not to break the loop
-
- } // ------------------------------------- endif (JPEGLossless)
-
- else { // JPEG Lossy : call to IJG 6b
-
- if (GetBitsStored() == 8) {
- res = (bool)gdcm_read_JPEG_file (destination); // Reading Fragment pixels
- } else {
- res = (bool)gdcm_read_JPEG_file12 (destination);// Reading Fragment pixels
- }
- } // ------------------------------------- endif (JPEGLossy)
-
- if (!res) break;
-
- destination = (char *)destination + taille * nBytes; // location in user's memory
- // for next fragment (if any)
-
- 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(GetSwapCode()) {
- ItemTagGr=SwapShort(ItemTagGr);
- ItemTagEl=SwapShort(ItemTagEl);
- }
-
- } // endWhile parsing fragments until Sequence Delim. Tag found
-
- return res;
-}