CloseFile();
return false;
}
-
+
// ------------------------- Compacted File (12 Bits Per Pixel)
/* unpack 12 Bits pixels into 16 Bits pixels */
}
return(true);
}
-
+
// ------------------------- Uncompressed File
return true;
}
}
+
+
+// ------------------------- Run Length Encoding
+
+ if (gdcmHeader::IsRLELossLessTransferSyntax()) {
+ int res = (bool)gdcm_read_RLE_file (destination);
+ return res;
+ }
+
+
- // ------------------------ Compressed File .
+// ----------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000
int nb;
std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
}
int nBytes= nb/8;
- int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
-
-
-
- // ---------------- RLE
-
- if (gdcmHeader::IsRLELossLessTransferSyntax()) {
- int res = (bool)gdcm_read_RLE_file (destination);
- return res;
- }
-
- // ----------------- SingleFrame/Multiframe JPEG
-
+ int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
long fragmentBegining; // for ftell, fseek
- bool b = gdcmHeader::IsJPEG2000();
+ bool jpg2000 = IsJPEG2000();
+ bool jpgLossless = IsJPEGLossless();
bool res = true;
guint16 ItemTagGr,ItemTagEl;
fragmentBegining=ftell(fp);
- if (b)
+ if (jpg2000) { // JPEG 2000 : call to ???
+
res = (bool)gdcm_read_JPEG2000_file (destination); // Not Yet written
-
- else if (IsJPEGLossless()) { // JPEG LossLess : call to xmedcom JPEG
+
+ } // ------------------------------------- endif (JPEG2000)
+
+ else if (jpgLossless) { // JPEG LossLess : call to xmedcom JPEG
- JPEGLosslessDecodeImage (fp,
+ JPEGLosslessDecodeImage (fp, // Reading Fragment pixels
(unsigned short *)destination,
GetPixelSize()*8* GetSamplesPerPixel(),
- ln);
-
+ ln);
res=1; // in order not to break the loop
- } // ------------------------------------- endif (IsJPEGLossless())
+ } // ------------------------------------- endif (JPEGLossless)
- else { // JPEG Lossy : call to xmedcon JPEG
- // (just to see if it works) --> it does NOT !
- /*
- JPEGLosslessDecodeImage (fp,
- (unsigned short *)destination,
- GetPixelSize()*8* GetSamplesPerPixel(),
- ln);
-
- */
- // JPEG Lossy : call to IJG 6b
+ else { // JPEG Lossy : call to IJG 6b
if (GetBitsStored() == 8) {
res = (bool)gdcm_read_JPEG_file (destination); // Reading Fragment pixels
} else {
res = (bool)gdcm_read_JPEG_file12 (destination);// Reading Fragment pixels
}
-
-
- }
+ } // ------------------------------------- endif (JPEGLossy)
if (!res) break;
// *Try* to deal with the color
// ----------------------------
-
+
+ std::string str_PhotometricInterpretation =
+ gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
+
+ if ( (str_PhotometricInterpretation == "MONOCHROME1 ")
+ || (str_PhotometricInterpretation == "MONOCHROME2 ") ) {
+ return lgrTotale;
+ }
+
// Planar configuration = 0 : Pixels are already RGB
// Planar configuration = 1 : 3 planes : R, G, B
// Planar configuration = 2 : 1 gray Plane + 3 LUT
// Well ... supposed to be !
- // See US-PAL-8-10x-echo.dcm: PlanarConfiguration=0,PhotometricInterpretation=PALETTE COLOR
+ // See US-PAL-8-10x-echo.dcm: PlanarConfiguration=0,
+ // PhotometricInterpretation=PALETTE COLOR
// and heuristic has to be found :-(
- std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
-
- if ( (str_PhotometricInterpretation == "MONOCHROME1 ")
- || (str_PhotometricInterpretation == "MONOCHROME2 ")
- || (str_PhotometricInterpretation == "RGB")) {
- return lgrTotale;
- }
int planConf=GetPlanarConfiguration();
- // Whatever Planar Configuration is, "PALETTE COLOR " implies that we deal with the palette.
+ // Whatever Planar Configuration is,
+ // "PALETTE COLOR " implies that we deal with the palette.
if (str_PhotometricInterpretation == "PALETTE COLOR ")
planConf=2;
// integer computation counterpart
for (int i=0;i<nbFrames;i++) {
for (int j=0;j<l; j++) {
- R= 1.164 *( *a-16) + 1.596 *( *c -128) + 0.5;
- G= 1.164 *( *a-16) - 0.813 *( *c -128) - 0.392 *(*b -128) + 0.5;
- B= 1.164 *( *a-16) + 2.017 *( *b -128) + 0.5;
+ R= 1.164 *(*a-16) + 1.596 *(*c -128) + 0.5;
+ G= 1.164 *(*a-16) - 0.813 *(*c -128) - 0.392 *(*b -128) + 0.5;
+ B= 1.164 *(*a-16) + 2.017 *(*b -128) + 0.5;
if (R<0.0) R=0.0;
if (G<0.0) G=0.0;
memmove(destination,newDest,lgrTotale);
free(newDest);
}
-
- // now, it's an RGB image
- // Lets's write it in the Header
- std::string spp = "3";
- gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
- std::string rgb="RGB";
- gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
+
break;
}
// and check again
// if it works, we shall have to check the 3 Palettes
// to see which byte is ==0 (first one, or second one)
-
- //unsigned char * x = newDest;
-
+
for (int i=0;i<l; i++) {
j=newDest[i]*mult +1;
*a++ = lutR[j];
}
free(newDest);
-
- // now, it's an RGB image
- std::string spp = "3";
- gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
- std::string rgb="RGB";
- gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
} else { // need to make RGB Pixels (?)
// from grey Pixels (?!)
// Well . I'll wait till I find such an image
}
break;
- }
+ }
}
-
+
+ // now, it's an RGB image
+ // Lets's write it in the Header
+
+ // CreateOrReplaceIfExist ?
+
+ std::string spp = "3"; // Samples Per Pixel
+ gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
+ std::string rgb="RGB "; // Photometric Interpretation
+ gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
+ std::string planConfig = "0"; // Planar Configuration
+ gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
+
+ // + Drop Palette Color ?
+
return lgrTotale;
}
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.102 2003/10/21 12:18:23 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.103 2003/10/23 12:08:32 jpr Exp $
#include "gdcmHeader.h"
// Fourth semantics:
//
-// ---> Warning : This fourth fiels is NOT part
+// ---> Warning : This fourth field is NOT part
// of the 'official' Dicom Dictionnary
// and should NOT be used.
// (Not defined for all the groups
return 0;
TotalLength += 4; // We even have to decount the group and element
- if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */ {
+ if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */ {
char msg[100]; // for sprintf. Sorry
sprintf(msg,"wrong group (%04x) for an item sequence (%04x,%04x)\n",g, g,n);
dbg.Verbose(1, "gdcmHeader::FindLengthOB: ",msg);
errno = 1;
return 0;
}
- if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header */
+ if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header */
FoundSequenceDelimiter = true;
else if ( n != 0xe000 ){
char msg[100]; // for sprintf. Sorry
/**
* \ingroup gdcmHeader
- * \brief
+ * \brief
* @return
*/
void gdcmHeader::PrintPubDict(std::ostream & os) {
/**
* \ingroup gdcmHeader
* \brief
- * @return
+ * @return integer, acts as a Boolean
*/
int gdcmHeader::Write(FILE * fp, FileType type) {
free(a);
return NULL;
}
- // TODO : finish the function !!!
return a;
}
FILE* fp);
// static because nothing but gdcm_read_RLE_file may call it
-#define DEBUG 0
-// Will be removed
-
// ----------------------------------------------------------------------------
/**
* \ingroup gdcmFile
gdcmFile::gdcm_read_RLE_file (void * image_buffer) {
long fragmentBegining; // for ftell, fseek
char * im = (char *)image_buffer;
- 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();
- if (DEBUG)printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize);
ftellRes=ftell(fp);
// Basic Offset Table with Item Value
// Item Tag
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- 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
- 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 ??
char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
guint32 a;
for (int i=0;i<ln;i+=4){
a=str2num(&BasicOffsetTableItemValue[i],guint32);
- if (DEBUG)printf(" x(%08x) %d\n",a,a);
}
}
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- 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
while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
fread(&fragmentLength,4,1,fp);
if(GetSwapCode())
fragmentLength=SwapLong(fragmentLength); // length
- if (DEBUG)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);
- 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]);
- 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);
- 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);
}
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);
ItemTagGr=SwapShort(ItemTagGr);
ItemTagEl=SwapShort(ItemTagEl);
}
- if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
- ftellRes,ItemTagGr,ItemTagEl );
}
+
+ if (GetBitsAllocated()==16) { // try to deal with RLE 16 Bits
+
+ im = (char *)image_buffer;
+ // need to make 16 Bits Pixels from Low Byte and Hight Byte 'Planes'
+
+ int l = GetXSize()*GetYSize();
+ int nbFrames = GetZSize();
+
+ char * newDest = (char*) malloc(l*nbFrames*2);
+ char *x = newDest;
+ char * a = (char *)image_buffer;
+ char * b = a + l;
+
+ for (int i=0;i<nbFrames;i++) {
+ for (int j=0;j<l; j++) {
+ *(x++) = *(a++);
+ *(x++) = *(b++);
+ }
+ }
+ memmove(image_buffer,newDest,lgrTotale);
+ free(newDest);
+ }
+
return (1);
}