2 //-----------------------------------------------------------------------------
3 //This is needed when compiling in debug mode
5 // 'type' : forcing value to bool 'true' or 'false' (performance warning)
6 //#pragma warning ( disable : 4800 )
7 // 'identifier' : class 'type' needs to have dll-interface to be used by
8 // clients of class 'type2'
9 #pragma warning ( disable : 4251 )
10 // 'identifier' : identifier was truncated to 'number' characters in the
12 #pragma warning ( disable : 4786 )
18 #define str2num(str, typeNum) *((typeNum *)(str))
20 //-----------------------------------------------------------------------------
23 * \brief Parse pixel data from disk and *prints* the result
24 * \ For multi-fragment Jpeg/Rle files checking purpose *only*
25 * \ Allows to 'see' if the file *does* conform
26 * \ (some of them do not)
27 * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58, page 85)
30 bool gdcmFile::ParsePixelData(void) {
31 // DO NOT remove the printf s.
32 // The ONLY purpose of this method is to PRINT the content
35 if ( !(fp=Header->OpenFile()))
38 if ( fseek(fp, Header->GetPixelOffset(), SEEK_SET) == -1 ) {
43 if ( !Header->IsDicomV3() ||
44 Header->IsImplicitVRLittleEndianTransferSyntax() ||
45 Header->IsExplicitVRLittleEndianTransferSyntax() ||
46 Header->IsExplicitVRBigEndianTransferSyntax() ||
47 Header->IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
49 printf ("gdcmFile::ParsePixelData : non JPEG/RLE File\n");
54 std::string str_nb=Header->GetEntryByNumber(0x0028,0x0100);
55 if (str_nb == GDCM_UNFOUND ) {
58 nb = atoi(str_nb.c_str() );
63 int taille = Header->GetXSize() * Header->GetYSize() * Header->GetSamplesPerPixel();
65 printf ("Checking the Dicom-encapsulated Jpeg/RLE Pixels\n");
67 guint16 ItemTagGr,ItemTagEl;
70 char * destination = NULL;
72 // -------------------- for Parsing : Position on begining of Jpeg/RLE Pixels
74 if( !Header->IsRLELossLessTransferSyntax()) {
78 fread(&ItemTagGr,2,1,fp); //Reading (fffe):Basic Offset Table Item Tag Gr
79 fread(&ItemTagEl,2,1,fp); //Reading (e000):Basic Offset Table Item Tag El
80 if(Header->GetSwapCode()) {
81 ItemTagGr=Header->SwapShort(ItemTagGr);
82 ItemTagEl=Header->SwapShort(ItemTagEl);
84 printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
85 ftellRes,ItemTagGr,ItemTagEl );
88 if(Header->GetSwapCode())
89 ln=Header->SwapLong(ln); // Basic Offset Table Item Length
90 printf("at %x : Basic Offset Table Item Length (??) %d x(%08x)\n",
93 // What is it used for ??
94 char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
95 fread(BasicOffsetTableItemValue,ln,1,fp);
97 for (int i=0;i<ln;i+=4){
98 a=str2num(&BasicOffsetTableItemValue[i],guint32);
99 printf(" x(%08x) %d\n",a,a);
104 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
105 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
106 if(Header->GetSwapCode()) {
107 ItemTagGr=Header->SwapShort(ItemTagGr);
108 ItemTagEl=Header->SwapShort(ItemTagEl);
110 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
111 ftellRes,ItemTagGr,ItemTagEl );
113 while ( ( ItemTagGr==0xfffe) && (ItemTagEl!=0xe0dd) ) { // Parse fragments
117 if(Header->GetSwapCode())
118 ln=Header->SwapLong(ln); // length
119 printf(" at %x : fragment length %d x(%08x)\n",
122 // destination += taille * nBytes; // location in user's memory
123 //printf (" Destination will be x(%x) = %d \n",
124 // destination,destination );
126 // ------------------------
127 fseek(fp,ln,SEEK_CUR); // skipping (not reading) fragment pixels
128 // ------------------------
131 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
132 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
133 if(Header->GetSwapCode()) {
134 ItemTagGr=Header->SwapShort(ItemTagGr);
135 ItemTagEl=Header->SwapShort(ItemTagEl);
137 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
138 ftellRes,ItemTagGr,ItemTagEl );
144 long RleSegmentLength[15],fragmentLength;
145 guint32 nbRleSegments;
146 guint32 RleSegmentOffsetTable[15];
148 // Basic Offset Table with Item Value
150 fread(&ItemTagGr,2,1,fp); //Reading (fffe):Basic Offset Table Item Tag Gr
151 fread(&ItemTagEl,2,1,fp); //Reading (e000):Basic Offset Table Item Tag El
152 if(Header->GetSwapCode()) {
153 ItemTagGr=Header->SwapShort(ItemTagGr);
154 ItemTagEl=Header->SwapShort(ItemTagEl);
156 printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
157 ftellRes,ItemTagGr,ItemTagEl );
161 if(Header->GetSwapCode())
162 ln=Header->SwapLong(ln); // Basic Offset Table Item Length
163 printf("at %x : Basic Offset Table Item Length (??) %d x(%08x)\n",
166 // What is it used for ??
167 char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
168 fread(BasicOffsetTableItemValue,ln,1,fp);
170 for (int i=0;i<ln;i+=4){
171 a=str2num(&BasicOffsetTableItemValue[i],guint32);
172 printf(" x(%08x) %d\n",a,a);
177 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
178 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
179 if(Header->GetSwapCode()) {
180 ItemTagGr=Header->SwapShort(ItemTagGr);
181 ItemTagEl=Header->SwapShort(ItemTagEl);
183 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
184 ftellRes,ItemTagGr,ItemTagEl );
186 // while 'Sequence Delimiter Item' (fffe,e0dd) not found
187 while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
188 // Parse fragments of the current Fragment (Frame)
190 fread(&fragmentLength,4,1,fp);
191 if(Header->GetSwapCode())
192 fragmentLength=Header->SwapLong(fragmentLength); // length
193 printf(" at %x : 'fragment' length %d x(%08x)\n",
194 ftellRes, fragmentLength,fragmentLength);
196 //------------------ scanning (not reading) fragment pixels
198 fread(&nbRleSegments,4,1,fp); // Reading : Number of RLE Segments
199 if(Header->GetSwapCode())
200 nbRleSegments=Header->SwapLong(nbRleSegments);
201 printf(" Nb of RLE Segments : %d\n",nbRleSegments);
203 for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
205 fread(&RleSegmentOffsetTable[k],4,1,fp);
206 if(Header->GetSwapCode())
207 RleSegmentOffsetTable[k]=Header->SwapLong(RleSegmentOffsetTable[k]);
208 printf(" at : %x Offset Segment %d : %d (%x)\n",
209 ftellRes,k,RleSegmentOffsetTable[k],
210 RleSegmentOffsetTable[k]);
213 if (nbRleSegments>1) { // skipping (not reading) RLE Segments
214 for(int k=1; k<=nbRleSegments-1; k++) {
215 RleSegmentLength[k]= RleSegmentOffsetTable[k+1]
216 - RleSegmentOffsetTable[k];
218 printf (" Segment %d : Length = %d x(%x) Start at %x\n",
219 k,RleSegmentLength[k],RleSegmentLength[k], ftellRes);
220 fseek(fp,RleSegmentLength[k],SEEK_CUR);
223 RleSegmentLength[nbRleSegments]= fragmentLength
224 - RleSegmentOffsetTable[nbRleSegments];
226 printf (" Segment %d : Length = %d x(%x) Start at %x\n",
227 nbRleSegments,RleSegmentLength[nbRleSegments],
228 RleSegmentLength[nbRleSegments],ftellRes);
230 fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
232 // ------------------ end of scanning fragment pixels
235 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
236 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
237 if(Header->GetSwapCode()) {
238 ItemTagGr=Header->SwapShort(ItemTagGr);
239 ItemTagEl=Header->SwapShort(ItemTagEl);
241 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
242 ftellRes,ItemTagGr,ItemTagEl );
248 //-----------------------------------------------------------------------------