-/////////////////////////////////////////////////////////////////
-/**
- * \ingroup gdcmFile
- * \brief Parse pixel data from disk and *prints* the result
- * \ For multi-fragment Jpeg files checking purpose *only*
- * \ Allows to 'see' if the file *does* conform
- * \ (some of them do not)
- * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58)
- *
- */
-bool gdcmFile::ParsePixelData(void) {
- if ( !OpenFile())
- return false;
-
- if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
- CloseFile();
- return false;
- }
-
- if ( !IsDicomV3() ||
- IsImplicitVRLittleEndianTransferSyntax() ||
- IsExplicitVRLittleEndianTransferSyntax() ||
- IsExplicitVRBigEndianTransferSyntax() ||
- IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
-
- printf ("gdcmFile::ParsePixelData : non JPEG File\n");
- return 0;
- }
-
- 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 taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel();
- int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
-
- printf ("Checking the Dicom-Jpeg/RLE Pixels\n");
-
- // ------------------------------- for Parsing : Position on begining of Jpeg Pixels
- guint16 ItemTagGr,ItemTagEl;
- int ln;
- long ftellRes;
- char * destination = NULL;
- ftellRes=ftell(fp);
- fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Basic Offset Table Item Tag Gr
- fread(&ItemTagEl,2,1,fp); // Reading (e000) : Basic Offset Table Item Tag El
- if(GetSwapCode()) {
- ItemTagGr=SwapShort(ItemTagGr);
- ItemTagEl=SwapShort(ItemTagEl);
- }
- printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
- ftellRes,ItemTagGr,ItemTagEl );
- ftellRes=ftell(fp);
- fread(&ln,4,1,fp);
- if(GetSwapCode())
- ln=SwapLong(ln); // Basic Offset Table Item Lentgh
- printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n",
- ftellRes,ln,ln);
- if (ln != 0) {
- // What is it used for ??
- char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
- fread(BasicOffsetTableItemValue,ln,1,fp);
- guint32 a;
- for (int i=0;i<ln;i+=4){
- a=str2num(&BasicOffsetTableItemValue[i],guint32);
- printf(" x(%08x) %d\n",a,a);
- }
- }
-
- ftellRes=ftell(fp);
- 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);
- }
- printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
- ftellRes,ItemTagGr,ItemTagEl );
-
- while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { // Parse fragments
-
- ftellRes=ftell(fp);
- fread(&ln,4,1,fp);
- if(GetSwapCode())
- ln=SwapLong(ln); // length
- printf(" at %x : fragment length %d x(%08x)\n",
- ftellRes, ln,ln);
-
- destination += taille * nBytes; // location in user's memory
-
- printf (" Destination will be x(%x) = %d \n",
- destination,destination );
-
- fseek(fp,ln,SEEK_CUR); // skipping (not reading) fragment pixels
-
- ftellRes=ftell(fp);
- 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);
- }
- printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
- ftellRes,ItemTagGr,ItemTagEl );
-
-
- }
- return 1;
-}
-