xp_comm_proj/rd_dicom/Papyrus3/PapyFiles3.c
/********************************************************************************/
/*										*/
/*	ComputeUndefinedSequenceLength3 : compute the size of a sequence of 	*/
/*	undefined length, starting from the current file position.		*/
/*										*/
/********************************************************************************/
ComputeUndefinedSequenceLength3 : compute the size of a sequence of
undefined length, starting from the current file position.
ComputeUndefinedSequenceLength3 : compute the size of a sequence of undefined length starting from the current file position .
PapyShort
ComputeUndefinedSequenceLength3 (PapyShort inFileNb, PapyULong *ioSeqLengthP)
{
  PapyULong	theElemLength, theBufPos, theFileStartPos, i;
  PapyUShort	theGrNb, theElemNb;
  char		theVR [3];
  unsigned char	*theBuffP, theBuff [8];
  int 		OK, theErr = 0;
  theGrNb         = 0;
  theElemNb       = 0;
  theElemLength   = 0L;
  OK 	          = FALSE;
  Papy3FTell (gPapyFile [inFileNb], (PapyLong *) &theFileStartPos);
  theBuffP = (unsigned char *) &theBuff [0];
  while (!OK)
  {
    i = 8L;
    if (Papy3FRead (gPapyFile [inFileNb], &i, 1L, theBuffP) < 0)
    {
      Papy3FClose (&(gPapyFile [inFileNb]));
      RETURN (papReadFile)
    } 
    *ioSeqLengthP += 8L;
    theBufPos 	  = 0L;
    theGrNb       = Extract2Bytes (theBuffP, &theBufPos);
    theElemNb     = Extract2Bytes (theBuffP, &theBufPos);
    if ((gArrTransfSyntax [inFileNb] == LITTLE_ENDIAN_IMPL && theGrNb != 0x0002) || 
    	(theGrNb == 0xFFFE && theElemNb == 0xE000) ||
    	(theGrNb == 0xFFFE && theElemNb == 0xE00D) ||
    	(theGrNb == 0xFFFE && theElemNb == 0xE0DD))
      theElemLength = Extract4Bytes (theBuffP, &theBufPos);
    else
    {
      theBuffP  += theBufPos;
      theVR [0]  = (char) *theBuffP;
      theVR [1]  = (char) *(theBuffP + 1);
      theVR [2]  = '\0';
      theBuffP   = (unsigned char *) &theBuff [0];
      theBufPos += 2;
      if (strcmp (theVR, "OB") == 0 ||
          strcmp (theVR, "OW") == 0 ||
          strcmp (theVR, "SQ") == 0 || 
          strcmp (theVR, "UN") == 0 || 
          strcmp (theVR, "UT") == 0)
      {
        i = 4L;
        if (Papy3FRead (gPapyFile [inFileNb], &i, 1L, theBuffP) < 0)
        {
	  Papy3FClose (&(gPapyFile [inFileNb]));
	  RETURN (papReadFile)
        } 
        *ioSeqLengthP += 4L;
        theBufPos = 0L;
        theElemLength = Extract4Bytes (theBuffP, &theBufPos);
      }
      else
        theElemLength = (PapyULong) Extract2Bytes (theBuffP, &theBufPos); 
    } 
    if (!((theGrNb == 0xFFFE) && (theElemNb == 0xE0DD) && (theElemLength == 0L)))
    {
      if (theElemLength == 0xFFFFFFFF)
      {
        theElemLength = 0L;
        if ((theErr = (int) ComputeUndefinedItemLength3 (inFileNb, &theElemLength)) < 0)
          RETURN (theErr);
      } 
      *ioSeqLengthP += theElemLength;
      Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_CUR, (PapyLong) theElemLength);
    } 
    else OK = TRUE;
  } 
  Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_SET, (PapyLong) theFileStartPos);
  return 0;
}
PapyShort ComputeUndefinedSequenceLength3 ( PapyShort inFileNb , PapyULong * ioSeqLengthP ) { PapyULong theElemLength , theBufPos , theFileStartPos , i ; PapyUShort theGrNb , theElemNb ; char theVR [ 3 ] ; unsigned char * theBuffP , theBuff [ 8 ] ; int OK , theErr = 0 ; theGrNb = 0 ; theElemNb = 0 ; theElemLength = 0L ; OK = FALSE ; Papy3FTell ( gPapyFile [ inFileNb ] , ( PapyLong * ) & theFileStartPos ) ; theBuffP = ( unsigned char * ) & theBuff [ 0 ] ; while ( ! OK ) { i = 8L ; if ( Papy3FRead ( gPapyFile [ inFileNb ] , & i , 1L , theBuffP ) < 0 ) { Papy3FClose ( & ( gPapyFile [ inFileNb ] ) ) ; RETURN ( papReadFile ) } * ioSeqLengthP += 8L ; theBufPos = 0L ; theGrNb = Extract2Bytes ( theBuffP , & theBufPos ) ; theElemNb = Extract2Bytes ( theBuffP , & theBufPos ) ; if ( ( gArrTransfSyntax [ inFileNb ] == LITTLE_ENDIAN_IMPL && theGrNb != 0x0002 ) || ( theGrNb == 0xFFFE && theElemNb == 0xE000 ) || ( theGrNb == 0xFFFE && theElemNb == 0xE00D ) || ( theGrNb == 0xFFFE && theElemNb == 0xE0DD ) ) theElemLength = Extract4Bytes ( theBuffP , & theBufPos ) ; else { theBuffP += theBufPos ; theVR [ 0 ] = ( char ) * theBuffP ; theVR [ 1 ] = ( char ) * ( theBuffP + 1 ) ; theVR [ 2 ] = ' \0 ' ; theBuffP = ( unsigned char * ) & theBuff [ 0 ] ; theBufPos += 2 ; if ( strcmp ( theVR , " " ) == 0 || strcmp ( theVR , " " ) == 0 || strcmp ( theVR , " " ) == 0 || strcmp ( theVR , " " ) == 0 || strcmp ( theVR , " " ) == 0 ) { i = 4L ; if ( Papy3FRead ( gPapyFile [ inFileNb ] , & i , 1L , theBuffP ) < 0 ) { Papy3FClose ( & ( gPapyFile [ inFileNb ] ) ) ; RETURN ( papReadFile ) } * ioSeqLengthP += 4L ; theBufPos = 0L ; theElemLength = Extract4Bytes ( theBuffP , & theBufPos ) ; } else theElemLength = ( PapyULong ) Extract2Bytes ( theBuffP , & theBufPos ) ; } if ( ! ( ( theGrNb == 0xFFFE ) && ( theElemNb == 0xE0DD ) && ( theElemLength == 0L ) ) ) { if ( theElemLength == 0xFFFFFFFF ) { theElemLength = 0L ; if ( ( theErr = ( int ) ComputeUndefinedItemLength3 ( inFileNb , & theElemLength ) ) < 0 ) RETURN ( theErr ) ; } * ioSeqLengthP += theElemLength ; Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_CUR , ( PapyLong ) theElemLength ) ; } else OK = TRUE ; } Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_SET , ( PapyLong ) theFileStartPos ) ; return 0 ; }
ComputeUndefinedSequenceLength3 : compute the size of a sequence of
undefined length, starting from the current file position.
ComputeUndefinedSequenceLength3 : compute the size of a sequence of undefined length starting from the current file position .
/* initialisation */ /* allocate the read buffer */ /* look for the end of sequence delimiter */ /* read the file until the item length value */ /* if */ /* get the group number, the element number and the element length of the */ /* item delimiter element */ /* extract the element length depending on the syntax */ /* extract the VR */ /* get the element length depending on the VR */ /* read 4 more bytes */ /* if */ /* else ...EXPLICIT VR */ /* is it the sequence delimiter ? */ /* if the element has an undefined length (i.e. item of undefined length */ /* if */ /* move the file pointer */ /* if ...not sequence delimiter */ /* while ...looking for the end of the sequence */ /* reset the file pointer to its previous position */