gdcmJpeg12.cxx \
gdcmJpeg2000.cxx \
gdcmRLE.cxx \
+ gdcmParse.cxx \
gdcmJpegIdo.cxx
libgdcmincludedir = $(includedir)
-libgdcminclude_HEADERS = \
- gdcmException.h \
- gdcmHeader.h \
- gdcmHeaderHelper.h \
- gdcmCommon.h \
- gdcm.h \
- gdcmDictSet.h \
- gdcmDict.h \
- gdcmDictEntry.h \
- gdcmElValue.h \
- gdcmElValSet.h \
- gdcmVR.h \
- gdcmTS.h \
+libgdcminclude_HEADERS = \
+ gdcmException.h \
+ gdcmHeader.h \
+ gdcmHeaderHelper.h \
+ gdcmCommon.h \
+ gdcm.h \
+ gdcmDictSet.h \
+ gdcmDict.h \
+ gdcmDictEntry.h \
+ gdcmElValue.h \
+ gdcmElValSet.h \
+ gdcmVR.h \
+ gdcmTS.h \
gdcmFile.h
-EXTRA_DIST = \
- gdcmUtil.h \
- gdcmIdo.h \
+EXTRA_DIST = \
+ gdcmUtil.h \
+ gdcmIdo.h \
iddcmjpeg.h
/* src/config.h. Generated automatically by configure. */
-/* src/config.h.in. Generated from configure.in by autoheader. */
+/* src/config.h.in. Generated automatically from configure.in by autoheader. */
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-/* #undef HAVE_INTTYPES_H */
-
-/* Define to 1 if you have the <memory.h> header file. */
-/* #undef HAVE_MEMORY_H */
-
-/* Define to 1 if you have the <stdint.h> header file. */
-/* #undef HAVE_STDINT_H */
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-/* #undef HAVE_STDLIB_H */
-
-/* Define to 1 if you have the <strings.h> header file. */
-/* #undef HAVE_STRINGS_H */
-
-/* Define to 1 if you have the <string.h> header file. */
-/* #undef HAVE_STRING_H */
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-/* #undef HAVE_SYS_STAT_H */
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-/* #undef HAVE_SYS_TYPES_H */
-
-/* Define to 1 if you have the <unistd.h> header file. */
-/* #undef HAVE_UNISTD_H */
-
-/* Name of package */
-#define PACKAGE "gdcm"
-
-/* Define to the address where bug reports for this package should be sent. */
-/* #undef PACKAGE_BUGREPORT */
+/* Define to empty if the keyword does not work. */
+/* #undef const */
-/* Define to the full name of this package. */
-/* #undef PACKAGE_NAME */
+/* Define to `unsigned' if <sys/types.h> doesn't define. */
+/* #undef size_t */
-/* Define to the full name and version of this package. */
-/* #undef PACKAGE_STRING */
+/* Define if you have the ANSI C header files. */
+#define STDC_HEADERS 1
-/* Define to the one symbol short name of this package. */
-/* #undef PACKAGE_TARNAME */
+/* Define if your <sys/time.h> declares struct tm. */
+/* #undef TM_IN_SYS_TIME */
-/* Define to the version of this package. */
-/* #undef PACKAGE_VERSION */
+/* Define if your processor stores words with the most significant
+ byte first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
-/* The size of a `char', as computed by sizeof. */
+/* The number of bytes in a char. */
#define SIZEOF_CHAR 1
-/* The size of a `int', as computed by sizeof. */
+/* The number of bytes in a int. */
#define SIZEOF_INT 4
-/* The size of a `long', as computed by sizeof. */
+/* The number of bytes in a long. */
#define SIZEOF_LONG 4
-/* The size of a `long long', as computed by sizeof. */
+/* The number of bytes in a long long. */
#define SIZEOF_LONG_LONG 8
-/* The size of a `short', as computed by sizeof. */
+/* The number of bytes in a short. */
#define SIZEOF_SHORT 2
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
+/* Define if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
-/* Define to 1 if your <sys/time.h> declares `struct tm'. */
-/* #undef TM_IN_SYS_TIME */
+/* Name of package */
+#define PACKAGE "gdcm"
/* Version number of package */
#define VERSION "0.3.0"
-/* Define to 1 if your processor stores words with the most significant byte
- first (like Motorola and SPARC, unlike Intel and VAX). */
-/* #undef WORDS_BIGENDIAN */
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define to `unsigned' if <sys/types.h> does not define. */
-/* #undef size_t */
-/* src/config.h.in. Generated from configure.in by autoheader. */
+/* src/config.h.in. Generated automatically from configure.in by autoheader. */
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
+/* Define to empty if the keyword does not work. */
+#undef const
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
+/* Define to `unsigned' if <sys/types.h> doesn't define. */
+#undef size_t
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
+/* Define if you have the ANSI C header files. */
+#undef STDC_HEADERS
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
+/* Define if your <sys/time.h> declares struct tm. */
+#undef TM_IN_SYS_TIME
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
+/* Define if your processor stores words with the most significant
+ byte first (like Motorola and SPARC, unlike Intel and VAX). */
+#undef WORDS_BIGENDIAN
-/* The size of a `char', as computed by sizeof. */
+/* The number of bytes in a char. */
#undef SIZEOF_CHAR
-/* The size of a `int', as computed by sizeof. */
+/* The number of bytes in a int. */
#undef SIZEOF_INT
-/* The size of a `long', as computed by sizeof. */
+/* The number of bytes in a long. */
#undef SIZEOF_LONG
-/* The size of a `long long', as computed by sizeof. */
+/* The number of bytes in a long long. */
#undef SIZEOF_LONG_LONG
-/* The size of a `short', as computed by sizeof. */
+/* The number of bytes in a short. */
#undef SIZEOF_SHORT
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
+/* Define if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
-/* Define to 1 if your <sys/time.h> declares `struct tm'. */
-#undef TM_IN_SYS_TIME
+/* Name of package */
+#undef PACKAGE
/* Version number of package */
#undef VERSION
-/* Define to 1 if your processor stores words with the most significant byte
- first (like Motorola and SPARC, unlike Intel and VAX). */
-#undef WORDS_BIGENDIAN
-
-/* Define to empty if `const' does not conform to ANSI C. */
-#undef const
-
-/* Define to `unsigned' if <sys/types.h> does not define. */
-#undef size_t
#include "gdcmUtil.h"
#include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess
-#define str2num(str, typeNum) *((typeNum *)(str))
-
/////////////////////////////////////////////////////////////////
/**
* \ingroup gdcmFile
* \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les
* pixels de l'image
* ou DES images dans le cas d'un multiframe
- * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels
+ * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels
* (dans le cas d'images compressees, elle n'a pas de sens).
*
* @return longueur a allouer
|| str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !!
lgrTotale*=3;
}
-
- // remaining to check :
- // str_PhotometricInterpretation == "YBR_FULL"
- // str_PhotometricInterpretation == "YBR_FULL_422" (no LUT, no Palette)
- // -->and some more !!
}
+ // see PS 3.3-2003 : C.7.6.3.2.1
+ //
+ // MONOCHROME1
+ // MONOCHROME2
+ // PALETTE COLOR
+ // RGB
+ // HSV (Retired)
+ // ARGB (Retired)
+ // CMYK (Retired)
+ // YBR_FULL
+ // YBR_FULL_422 (no LUT, no Palette)
+ // YBR_PARTIAL_422
+ // YBR_ICT
+ // YBR_RCT
+
+ // LUT's
+ // ex : gdcm-US-ALOKA-16.dcm
+ // 0028|1221 [OW] [Segmented Red Palette Color Lookup Table Data]
+ // 0028|1222 [OW] [Segmented Green Palette Color Lookup Table Data]
+ // 0028|1223 [OW] [Segmented Blue Palette Color Lookup Table Data]
+
+ // ex : US-PAL-8-10x-echo.dcm, 8BitsRunLengthColor.dcm
+ // 0028|1201 [OW] [Red Palette Color Lookup Table Data]
+ // 0028|1202 [OW] [Green Palette Color Lookup Table Data]
+ // 0028|1203 [OW] [Blue Palette Color Lookup Table Data]
+
+ // ex : OT-PAL-8-face.dcm
+ // 0028|1201 [US] [Red Palette Color Lookup Table Data]
+ // 0028|1202 [US] [Green Palette Color Lookup Table Data]
+ // 0028|1203 [US] [Blue Palette Color Lookup Table Data]
+
+
/////////////////////////////////////////////////////////////////
/**
* the pixel data represented in this file.
* @return The size of pixel data in bytes.
*/
+
size_t gdcmFile::GetImageDataSize(void) {
return (lgrTotale);
}
-/////////////////////////////////////////////////////////////////
-/**
- * \ingroup gdcmFile
- * \brief Parse pixel data from disk and *prints* the result
- * \ For multi-fragment Jpeg/Rle 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, page 85)
- *
- */
-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/RLE File\n");
- return 0;
- }
-
- int nb;
- std::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");
-
- guint16 ItemTagGr,ItemTagEl;
- int ln;
- long ftellRes;
- char * destination = NULL;
-
- // ------------------------------- for Parsing : Position on begining of Jpeg/RLE Pixels
-
- if( !IsRLELossLessTransferSyntax()) {
-
- // JPEG Image
-
- std::cout << "JPEG image" << std::endl;
- 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 );
- }
-
- } else {
-
- // RLE Image
-
- std::cout << "RLE image" << std::endl;
- long RleSegmentLength[15],fragmentLength;
- guint32 nbRleSegments;
- guint32 RleSegmentOffsetTable[15];
- ftellRes=ftell(fp);
- // Basic Offset Table with Item Value
- // Item Tag
- 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 );
- // Item Length
- 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 'Sequence Delimiter Item' (fffe,e0dd) not found
- while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
- // Parse fragments of the current Fragment (Frame)
- ftellRes=ftell(fp);
- fread(&fragmentLength,4,1,fp);
- if(GetSwapCode())
- fragmentLength=SwapLong(fragmentLength); // length
- printf(" at %x : 'fragment' length %d x(%08x)\n",
- ftellRes, fragmentLength,fragmentLength);
-
-// destination += taille * nBytes; // location in user's memory
-// printf (" Destination will be x(%x) = %d \n",
-// destination,destination );
-
- //------------------ scanning (not reading) fragment pixels
-
- fread(&nbRleSegments,4,1,fp); // Reading : Number of RLE Segments
- if(GetSwapCode())
- nbRleSegments=SwapLong(nbRleSegments);
- printf(" Nb of RLE Segments : %d\n",nbRleSegments);
-
- for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
- ftellRes=ftell(fp);
- fread(&RleSegmentOffsetTable[k],4,1,fp);
- if(GetSwapCode())
- RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
- printf(" at : %x Offset Segment %d : %d (%x)\n",
- ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
- }
- if (nbRleSegments>1) {
- for(int k=1; k<=nbRleSegments-1; k++) { // skipping (not reading) RLE Segments
- RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k];
- ftellRes=ftell(fp);
- printf (" Segment %d : Length = %d Start at %x\n",
- k,RleSegmentLength[k], ftellRes);
- fseek(fp,RleSegmentLength[k],SEEK_CUR);
- }
- }
- RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments] ;
- // TODO : Check the value
- ftellRes=ftell(fp);
- printf (" Segment %d : Length = %d Start at %x\n",
- nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes);
-
- fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
-
- // ------------------ end of scanning 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;
-}
-
/////////////////////////////////////////////////////////////////
/**
* \ingroup gdcmFile
}
int nBytes= nb/8;
- //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel();
int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
if (b)
res = (bool)gdcm_read_JPEG2000_file (destination); // Reading Fragment pixels
- else if (IsJPEGLossless()) { // ------------- call to LibIDO Jpeg for each Frame/fragment
+ else if (IsJPEGLossless()) {
+ // ------------- call to LibIDO Jpeg for each Frame/fragment
- // Warning : Works only if there is one fragment per frame
- // (Or a single fragment for the multiframe file)
+ // Warning : Works only if there is one fragment per frame
+ // (Or a single fragment for the multiframe file)
ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one.
// (We use the LibIDO one :-(
if(jpg == NULL) {
}
}
- // Try to deal with the color
+ // *Try* to deal with the color
// --------------------------
std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
|| (str_PhotometricInterpretation == "RGB")) {
return lgrTotale;
}
+ int planConf=GetPlanarConfiguration();
+
+ if( str_PhotometricInterpretation!="PALETTE COLOR" && planConf == 0)
+ planConf=2; // Sorry, this is an heuristic
- switch ( GetPlanarConfiguration() ) {
+ switch ( planConf) {
case 0:
// Pixels are already RGB
break;
-
+
case 1:
// need to make RGB Pixels from Planes R,G,B
{
--- /dev/null
+// gdcmParse.cxx
+
+//This is needed when compiling in debug mode
+#ifdef _MSC_VER
+// 'type' : forcing value to bool 'true' or 'false' (performance warning)
+//#pragma warning ( disable : 4800 )
+// 'identifier' : class 'type' needs to have dll-interface to be used by
+// clients of class 'type2'
+#pragma warning ( disable : 4251 )
+// 'identifier' : identifier was truncated to 'number' characters in the
+// debug information
+#pragma warning ( disable : 4786 )
+#endif //_MSC_VER
+
+#include "gdcmFile.h"
+#include "gdcmUtil.h"
+#include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess
+
+#define str2num(str, typeNum) *((typeNum *)(str))
+
+/////////////////////////////////////////////////////////////////
+/**
+ * \ingroup gdcmFile
+ * \brief Parse pixel data from disk and *prints* the result
+ * \ For multi-fragment Jpeg/Rle 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, page 85)
+ *
+ */
+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/RLE File\n");
+ return 0;
+ }
+
+ int nb;
+ std::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() * GetSamplesPerPixel();
+
+ printf ("Checking the Dicom-encapsulated Jpeg/RLE Pixels\n");
+
+ guint16 ItemTagGr,ItemTagEl;
+ int ln;
+ long ftellRes;
+ char * destination = NULL;
+
+ // ------------------------------- for Parsing : Position on begining of Jpeg/RLE Pixels
+
+ if( !IsRLELossLessTransferSyntax()) {
+
+ // JPEG Image
+
+ std::cout << "JPEG image" << std::endl;
+ 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 );
+ }
+
+ } else {
+
+ // RLE Image
+
+ std::cout << "RLE image" << std::endl;
+ long RleSegmentLength[15],fragmentLength;
+ guint32 nbRleSegments;
+ guint32 RleSegmentOffsetTable[15];
+ ftellRes=ftell(fp);
+ // Basic Offset Table with Item Value
+ // Item Tag
+ 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 );
+ // Item Length
+ 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 'Sequence Delimiter Item' (fffe,e0dd) not found
+ while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
+ // Parse fragments of the current Fragment (Frame)
+ ftellRes=ftell(fp);
+ fread(&fragmentLength,4,1,fp);
+ if(GetSwapCode())
+ fragmentLength=SwapLong(fragmentLength); // length
+ printf(" at %x : 'fragment' length %d x(%08x)\n",
+ ftellRes, fragmentLength,fragmentLength);
+
+ //------------------ scanning (not reading) fragment pixels
+
+ fread(&nbRleSegments,4,1,fp); // Reading : Number of RLE Segments
+ if(GetSwapCode())
+ nbRleSegments=SwapLong(nbRleSegments);
+ printf(" Nb of RLE Segments : %d\n",nbRleSegments);
+
+ for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
+ ftellRes=ftell(fp);
+ fread(&RleSegmentOffsetTable[k],4,1,fp);
+ if(GetSwapCode())
+ RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
+ printf(" at : %x Offset Segment %d : %d (%x)\n",
+ ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
+ }
+
+ if (nbRleSegments>1) {
+ for(int k=1; k<=nbRleSegments-1; k++) { // skipping (not reading) RLE Segments
+ RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k];
+ ftellRes=ftell(fp);
+ printf (" Segment %d : Length = %d x(%x) Start at %x\n",
+ k,RleSegmentLength[k],RleSegmentLength[k], ftellRes);
+ fseek(fp,RleSegmentLength[k],SEEK_CUR);
+ }
+ }
+ RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments] ;
+ // TODO : Check the value
+ ftellRes=ftell(fp);
+ printf (" Segment %d : Length = %d x(%x) Start at %x\n",
+ nbRleSegments,RleSegmentLength[nbRleSegments],
+ RleSegmentLength[nbRleSegments],ftellRes);
+
+ fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
+
+ // ------------------ end of scanning 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;
+}
FILE* fp);
// static because nothing but gdcm_read_RLE_file may call it
+#define DEBUG 0
+// Will be removed
+
// ----------------------------------------------------------------------------
/**
* \ingroup gdcmFile
int
gdcmFile::gdcm_read_RLE_file (void * image_buffer) {
+ long fragmentBegining; // for ftell, fseek
char * im = (char *)image_buffer;
- std::cout << "RLE image" << std::endl;
+ if (DEBUG)std::cout << "RLE image" << std::endl;
long RleSegmentLength[15],fragmentLength,uncompressedSegmentSize;;
long ftellRes, ln;
guint32 RleSegmentOffsetTable[15];
guint16 ItemTagGr,ItemTagEl;
uncompressedSegmentSize=GetXSize()*GetYSize();
- printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize);
+ if (DEBUG)printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize);
ftellRes=ftell(fp);
// Basic Offset Table with Item Value
// Item Tag
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
+ if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
ftellRes,ItemTagGr,ItemTagEl );
// Item Length
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",
+ if (DEBUG)printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n",
ftellRes,ln,ln);
if (ln != 0) {
// What is it used for ??
guint32 a;
for (int i=0;i<ln;i+=4){
a=str2num(&BasicOffsetTableItemValue[i],guint32);
- printf(" x(%08x) %d\n",a,a);
+ if (DEBUG)printf(" x(%08x) %d\n",a,a);
}
}
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
+ if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
ftellRes,ItemTagGr,ItemTagEl );
// while 'Sequence Delimiter Item' (fffe,e0dd) not found
fread(&fragmentLength,4,1,fp);
if(GetSwapCode())
fragmentLength=SwapLong(fragmentLength); // length
- printf(" at %x : fragment length %d x(%08x)\n",
+ if (DEBUG)printf(" at %x : fragment length %d x(%08x)\n",
ftellRes, fragmentLength,fragmentLength);
- // scanning fragment pixels
+ //------------------ scanning (not reading) fragment pixels
fread(&nbRleSegments,4,1,fp); // Reading : Number of RLE Segments
if(GetSwapCode())
nbRleSegments=SwapLong(nbRleSegments);
- printf(" Nb of RLE Segments : %d\n",nbRleSegments);
+ if (DEBUG)printf(" Nb of RLE Segments : %d\n",nbRleSegments);
for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
ftellRes=ftell(fp);
fread(&RleSegmentOffsetTable[k],4,1,fp);
if(GetSwapCode())
RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
- printf(" at : %x Offset Segment %d : %d (%x)\n",
- ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
+ if (DEBUG)printf(" at : %x Offset Segment %d : %d (%x)\n",
+ ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
}
- if (nbRleSegments>1) {
- for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments
- RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k];
- ftellRes=ftell(fp);
- printf (" Segment %d : Length = %d Start at %x\n",
- k,RleSegmentLength[k], ftellRes);
- _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp);
- //fseek(fp,RleSegmentLength[k],SEEK_CUR);
-
- }
- }
- RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments]; // + 4;
- // 4 : bytes for number of RLE Segments (WHY ???);
- // TODO : Check the value
- ftellRes=ftell(fp);
- printf (" Segment %d : Length = %d Start at %x\n",
- nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes);
- _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp);
- //fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
-
-
- // end of scanning fragment pixels
+ if (nbRleSegments>1) {
+ for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments
+ RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k];
+ ftellRes=ftell(fp);
+ if (DEBUG)printf (" (in) Segment %d : Length = %d x(%x) Start at %x\n",
+ k,RleSegmentLength[k],RleSegmentLength[k], ftellRes);
+ fragmentBegining=ftell(fp);
+ _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp);
+ fseek(fp,fragmentBegining,SEEK_SET);
+ fseek(fp,RleSegmentLength[k],SEEK_CUR);
+ }
+ }
+ RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments];
+ ftellRes=ftell(fp);
+ if (DEBUG)printf (" (out)Segment %d : Length = %d x(%x) Start at %x\n",
+ nbRleSegments,
+ RleSegmentLength[nbRleSegments],RleSegmentLength[nbRleSegments],
+ ftellRes);
+ fragmentBegining=ftell(fp);
+ _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp);
+ fseek(fp,fragmentBegining,SEEK_SET);
+ fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
+
+ // end of scanning fragment pixels
ftellRes=ftell(fp);
fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
+ if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
ftellRes,ItemTagGr,ItemTagEl );
}
return (1);
long numberOfOutputBytes=0;
char n, car;
ftellRes =ftell(fp);
- printf ("Fragment begin : %x lengthToDecode %d\n",ftellRes,lengthToDecode);
while(numberOfOutputBytes<uncompressedSegmentSize) {
ftellRes =ftell(fp);
fread(&n,sizeof(char),1,fp);
count=n;
- //printf (" Piece begin : %x count : %d x(%x)\n",ftellRes, count, count);
if (count >= 0 && count <= 127) {
fread(*areaToRead,(count+1)*sizeof(char),1,fp);
*areaToRead+=count+1;