-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.94 2003/10/03 16:22:24 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.95 2003/10/06 13:37:25 jpr Exp $
#include "gdcmHeader.h"
void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
if ( FoundLength == 0xffffffff)
FoundLength = 0;
+ // Sorry for the patch!
+ // XMedCom did the trick to read some nasty GE images ...
+ if (FoundLength == 13)
+ FoundLength =10;
+
ElVal->SetLength(FoundLength);
}
fseek(fp, 2L, SEEK_CUR);
guint32 length32 = ReadInt32();
+
if ( (vr == "OB") && (length32 == 0xffffffff) ) {
ElVal->SetLength(FindLengthOB());
return;
// Heuristic: well some files are really ill-formed.
if ( length16 == 0xffff) {
length16 = 0;
- dbg.Verbose(0, "gdcmHeader::FindLength",
- "Erroneous element length fixed.");
+ //dbg.Verbose(0, "gdcmHeader::FindLength",
+ // "Erroneous element length fixed.");
+ // Actually, length= 0xffff means that we deal with
+ // Unknown Sequence Length
}
+
FixFoundLength(ElVal, (guint32)length16);
return;
}
int ci, dctbl, actbl;
jpeg_component_info * compptr;
+fprintf (stderr,"=======================================================JPEG12\n");
+
if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
entropy->pub.encode_mcu = encode_mcu_gather;
p = 0;
for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l];
- if (i < 0 || p + i > 256) /* protect against table overrun */
+ if (i < 0 || p + i > 256) { /* protect against table overrun */
+ printf ("JERR_BAD_HUFF_TABLE : protect against table overrun (i=%d p=%d)\n",i,p);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
while (i--)
huffsize[p++] = (char) l;
}
/* code is now 1 more than the last code used for codelength si; but
* it must still fit in si bits, since no code is allowed to be all ones.
*/
- if (((INT32) code) >= (((INT32) 1) << si))
+ if (((INT32) code) >= (((INT32) 1) << si)) {
+ printf("JERR_BAD_HUFF_TABLE : (((INT32) code) >= (((INT32) 1) << si)) code %d si%d\v",code, si);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
code <<= 1;
si++;
}
for (p = 0; p < lastp; p++) {
i = htbl->huffval[p];
- if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
+ if (i < 0 || i > maxsymbol || dtbl->ehufsi[i]) {
+ printf("JERR_BAD_HUFF_TABLE (i < 0 || i > maxsymbol || dtbl->ehufsi[i]) i %d maxsymbol %d dtbl->ehufsi[i] %d\n", i, maxsymbol, dtbl->ehufsi[i]);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
dtbl->ehufco[i] = huffcode[p];
dtbl->ehufsi[i] = huffsize[p];
}
nsymbols = 0;
for (len = 1; len <= 16; len++)
nsymbols += bits[len];
- if (nsymbols < 1 || nsymbols > 256)
+ if (nsymbols < 1 || nsymbols > 256) {
+ printf ("JERR_BAD_HUFF_TABLE nsymbols %d\n",nsymbols);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
p = 0;
for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l];
- if (i < 0 || p + i > 256) /* protect against table overrun */
+ if (i < 0 || p + i > 256){ /* protect against table overrun */
+ printf ("JERR_BAD_HUFF_TABLE : protect against table overrun (i=%d p=%d)\n",i,p);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
while (i--)
huffsize[p++] = (char) l;
}
/* code is now 1 more than the last code used for codelength si; but
* it must still fit in si bits, since no code is allowed to be all ones.
*/
- if (((INT32) code) >= (((INT32) 1) << si))
+ if (((INT32) code) >= (((INT32) 1) << si)) {
+ printf("JERR_BAD_HUFF_TABLE : (((INT32) code) >= (((INT32) 1) << si)) code %d si%d\v",code, si);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
code <<= 1;
si++;
}
if (isDC) {
for (i = 0; i < numsymbols; i++) {
int sym = htbl->huffval[i];
- if (sym < 0 || sym > 15)
- ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ //printf ("htbl->huffval[%d]=%d\n",i,htbl->huffval[i]);
+ if (sym < 0 || sym > 15) {
+ printf("JERR_BAD_HUFF_TABLE sym %d (>15)\n",sym);
+ //ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ // Sorry for the patch :
+ // Now, we can read Philips MRI Images
+ htbl->huffval[i]=15;
+ }
}
}
}
/* Here we just do minimal validation of the counts to avoid walking
* off the end of our table space. jdhuff.c will check more carefully.
*/
- if (count > 256 || ((INT32) count) > length)
+ if (count > 256 || ((INT32) count) > length) {
+ printf("JERR_BAD_HUFF_TABLE in jdmarker12.c count : %d\n",count);
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
-
+ }
for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE);