xp_comm_proj/rd_dicom/Papyrus3/PapyDataSetRead3.c
/********************************************************************************/
/*									 	*/
/*	ExtractPapyDataSetInformation3 : Extracts the data sets relativ 	*/
/*	information i.e. the number of images, and the offsets to the data sets */
/*	and the pixel datas for a PAPYRUS 3 file.				*/
/*	return : standard error message.					*/
/*										*/
/********************************************************************************/
ExtractPapyDataSetInformation3 : Extracts the data sets relativ
information i.e. the number of images, and the offsets to the data sets
and the pixel datas for a PAPYRUS 3 file.
return : standard error message.
ExtractPapyDataSetInformation3 : Extracts the data sets relativ information i . e . the number of images and the offsets to the data sets and the pixel datas for a PAPYRUS 3 file . return : standard error message .
PapyShort
ExtractPapyDataSetInformation3 (PapyShort inFileNb)
{
  PapyShort	theErr, i;
  PapyUShort	theElemCreator, theElemNb;
  PapyULong	theNbVal, theSavedFilePos, theItemLength, theULong;
  int		theElemType;
  SElement	*theGroupP;
  UValue_T	*theValP;
  if ((theErr = Papy3GotoGroupNb (inFileNb, 0x0041)) < 0) RETURN (theErr);
  if ((theElemCreator = Papy3FindOwnerRange (inFileNb, 0x0041, "PAPYRUS 3.0")) == 0)
    RETURN (papNotFound);
  Papy3FTell (gPapyFile [inFileNb], (PapyLong *) &theSavedFilePos);
  theElemNb  = theElemCreator << 8;
  theElemNb |= 0x0010;
  if ((theErr = Papy3GotoElemNb (inFileNb, 0x0041, theElemNb, &theULong)) < 0) RETURN (theErr);
  Papy3FTell (gPapyFile [inFileNb], (PapyLong *) &gOffsetToPtrSeq [inFileNb]);
  theElemNb  = theElemCreator << 8;
  theElemNb |= 0x0050;
  if ((theErr = Papy3GotoElemNb (inFileNb, 0x0041, theElemNb, &theULong)) < 0) RETURN (theErr);
  Papy3FTell (gPapyFile [inFileNb], (PapyLong *) &gOffsetToImageSeq [inFileNb]);
  Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_SET, (PapyLong) theSavedFilePos);
  if ((theErr = Papy3GroupRead (inFileNb, &gArrGroup41 [inFileNb])) < 0) RETURN (papReadGroup);
  theValP = Papy3GetElement (gArrGroup41 [inFileNb], papNumberofimagesGr, &theNbVal, &theElemType);
  gArrNbImages [inFileNb] = theValP->us;
  gRefImagePointer [inFileNb] = (PapyULong *) ecalloc3 ((PapyULong) gArrNbImages [inFileNb], 
    						     (PapyULong) sizeof (PapyULong));
  gRefPixelOffset  [inFileNb] = (PapyULong *) ecalloc3 ((PapyULong) gArrNbImages [inFileNb], 
    						     (PapyULong) sizeof (PapyULong));
  gImageSOPinstUID [inFileNb] = (char **) ecalloc3 ((PapyULong) gArrNbImages [inFileNb], 
    						     (PapyULong) sizeof (char *));
  if (gArrTransfSyntax [inFileNb] == LITTLE_ENDIAN_IMPL)
    Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_SET, (PapyLong) (gOffsetToPtrSeq [inFileNb] + 8L));
  else if (gArrTransfSyntax [inFileNb] == LITTLE_ENDIAN_EXPL)
    Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_SET, (PapyLong) (gOffsetToPtrSeq [inFileNb] + 12L));
  for (i = 0; i < gArrNbImages [inFileNb]; i++)
  {
    theItemLength  = Papy3ExtractItemLength (inFileNb);
    if ((int) theItemLength < 0) RETURN ((int) theItemLength);
    Papy3FTell (gPapyFile [inFileNb], (PapyLong *) &theULong);
    theItemLength += theULong;
    if ((theErr = Papy3GotoGroupNb (inFileNb, 0x0041)) < 0) RETURN (theErr);
    if ((theErr = Papy3GroupRead (inFileNb, &theGroupP)) < 0) RETURN (theErr);
    theValP = Papy3GetElement (theGroupP, papImagePointerGr, &theNbVal, &theElemType);
    *(gRefImagePointer [inFileNb] + i) = theValP->ul;
    theValP = Papy3GetElement (theGroupP, papPixelOffsetGr, &theNbVal, &theElemType);
    *(gRefPixelOffset [inFileNb] + i) = theValP->ul;
    theValP = Papy3GetElement (theGroupP, papReferencedImageSOPClassUIDGr, &theNbVal, &theElemType);
    if (theValP != NULL)
      *(gImageSOPinstUID [inFileNb] + i) = (char *) PapyStrDup (theValP->a);
    theErr = Papy3GroupFree (&theGroupP, TRUE);
    Papy3FSeek (gPapyFile [inFileNb], (int) SEEK_SET, (PapyLong) theItemLength);
  } 
  RETURN (theErr);
}
PapyShort ExtractPapyDataSetInformation3 ( PapyShort inFileNb ) { PapyShort theErr , i ; PapyUShort theElemCreator , theElemNb ; PapyULong theNbVal , theSavedFilePos , theItemLength , theULong ; int theElemType ; SElement * theGroupP ; UValue_T * theValP ; if ( ( theErr = Papy3GotoGroupNb ( inFileNb , 0x0041 ) ) < 0 ) RETURN ( theErr ) ; if ( ( theElemCreator = Papy3FindOwnerRange ( inFileNb , 0x0041 , " " ) ) == 0 ) RETURN ( papNotFound ) ; Papy3FTell ( gPapyFile [ inFileNb ] , ( PapyLong * ) & theSavedFilePos ) ; theElemNb = theElemCreator << 8 ; theElemNb |= 0x0010 ; if ( ( theErr = Papy3GotoElemNb ( inFileNb , 0x0041 , theElemNb , & theULong ) ) < 0 ) RETURN ( theErr ) ; Papy3FTell ( gPapyFile [ inFileNb ] , ( PapyLong * ) & gOffsetToPtrSeq [ inFileNb ] ) ; theElemNb = theElemCreator << 8 ; theElemNb |= 0x0050 ; if ( ( theErr = Papy3GotoElemNb ( inFileNb , 0x0041 , theElemNb , & theULong ) ) < 0 ) RETURN ( theErr ) ; Papy3FTell ( gPapyFile [ inFileNb ] , ( PapyLong * ) & gOffsetToImageSeq [ inFileNb ] ) ; Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_SET , ( PapyLong ) theSavedFilePos ) ; if ( ( theErr = Papy3GroupRead ( inFileNb , & gArrGroup41 [ inFileNb ] ) ) < 0 ) RETURN ( papReadGroup ) ; theValP = Papy3GetElement ( gArrGroup41 [ inFileNb ] , papNumberofimagesGr , & theNbVal , & theElemType ) ; gArrNbImages [ inFileNb ] = theValP -> us ; gRefImagePointer [ inFileNb ] = ( PapyULong * ) ecalloc3 ( ( PapyULong ) gArrNbImages [ inFileNb ] , ( PapyULong ) sizeof ( PapyULong ) ) ; gRefPixelOffset [ inFileNb ] = ( PapyULong * ) ecalloc3 ( ( PapyULong ) gArrNbImages [ inFileNb ] , ( PapyULong ) sizeof ( PapyULong ) ) ; gImageSOPinstUID [ inFileNb ] = ( char * * ) ecalloc3 ( ( PapyULong ) gArrNbImages [ inFileNb ] , ( PapyULong ) sizeof ( char * ) ) ; if ( gArrTransfSyntax [ inFileNb ] == LITTLE_ENDIAN_IMPL ) Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_SET , ( PapyLong ) ( gOffsetToPtrSeq [ inFileNb ] + 8L ) ) ; else if ( gArrTransfSyntax [ inFileNb ] == LITTLE_ENDIAN_EXPL ) Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_SET , ( PapyLong ) ( gOffsetToPtrSeq [ inFileNb ] + 12L ) ) ; for ( i = 0 ; i < gArrNbImages [ inFileNb ] ; i ++ ) { theItemLength = Papy3ExtractItemLength ( inFileNb ) ; if ( ( int ) theItemLength < 0 ) RETURN ( ( int ) theItemLength ) ; Papy3FTell ( gPapyFile [ inFileNb ] , ( PapyLong * ) & theULong ) ; theItemLength += theULong ; if ( ( theErr = Papy3GotoGroupNb ( inFileNb , 0x0041 ) ) < 0 ) RETURN ( theErr ) ; if ( ( theErr = Papy3GroupRead ( inFileNb , & theGroupP ) ) < 0 ) RETURN ( theErr ) ; theValP = Papy3GetElement ( theGroupP , papImagePointerGr , & theNbVal , & theElemType ) ; * ( gRefImagePointer [ inFileNb ] + i ) = theValP -> ul ; theValP = Papy3GetElement ( theGroupP , papPixelOffsetGr , & theNbVal , & theElemType ) ; * ( gRefPixelOffset [ inFileNb ] + i ) = theValP -> ul ; theValP = Papy3GetElement ( theGroupP , papReferencedImageSOPClassUIDGr , & theNbVal , & theElemType ) ; if ( theValP != NULL ) * ( gImageSOPinstUID [ inFileNb ] + i ) = ( char * ) PapyStrDup ( theValP -> a ) ; theErr = Papy3GroupFree ( & theGroupP , TRUE ) ; Papy3FSeek ( gPapyFile [ inFileNb ] , ( int ) SEEK_SET , ( PapyLong ) theItemLength ) ; } RETURN ( theErr ) ; }
ExtractPapyDataSetInformation3 : Extracts the data sets relativ
information i.e.
ExtractPapyDataSetInformation3 : Extracts the data sets relativ information i . e .
/* move the file pointer to group 41 */ /* find the creator element number for the PAPYRUS 3.0 elements */ /* look for the position of the pointer and the image sequence */ /* save the current file pos */ /* elem (0x0041, 0x??10) = pointer sequence */ /* elem (0x0041, 0x??50) = image sequence */ /* reset the file pointer to the begining of group 41 */ /* read THE group 41 and stores it */ /* extracts the number of images in the file */ /* allocate room for the offsets to the data set and pixel data of the file */ /* allocate room for the SOP instance UID of the images */ /* extraction of the offsets to the data set(s) and the image(s) */ /* so points to the first element of the pointer sequence */ /* extract the offset to data set and the image and the UID for each image */ /* extract the length of this item of the pointer sequence */ /* move the file pointer to the group 41 of the pointer sequence */ /* read the group */ /* extract the offset to the data set */ /* extract the offset to the pixel datas */ /* extract the SOP instance UID of the image */ /* free the group */ /* go to the end of this item of the pointer sequence */ /* for ...extraction of the offsets to data set and the images */