//#include "gdcm.h"
#include "gdcmHeader.h"
#include "gdcmFile.h"
+#include <string>
// ecriture d'un fichier DICOM à partir d'un dcmHeader correct.
// On suppose que les champs DICOM du 2ieme fichier existent *effectivement*
- f1->ReplaceOrCreateByNumber( f2->GetPubElValByNumber(0x0028, 0x0008),
- 0x0028, 0x0008);// nb Frames
+ string nbFrames = f2->GetPubElValByNumber(0x0028, 0x0008);
+ if(nbFrames != "gdcm::Unfound") {
+ f1->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
+ }
+
f1->ReplaceOrCreateByNumber( f2->GetPubElValByNumber(0x0028, 0x0010),
0x0028, 0x0010);// nbLig
f1->ReplaceOrCreateByNumber( f2->GetPubElValByNumber(0x0028, 0x0011),
0x0028, 0x0011);// nbCol
+
// sans doute d'autres à mettre à jour...
+ // TODO : rajouter une valeur par defaut.
// TODO : une routine qui recoit une liste de couples (gr,el), et qui fasse le boulot.
dataSize = f2->GetImageDataSize();
printf ("dataSize %d\n",dataSize);
imageData= f2->GetImageData();
-
+
f1->SetImageData(imageData,dataSize);
// ou, plus joli:
- //f1->SetImageData(f2->GetImageData(),f2->GetImageDataSize());
+ //f1->SetImageData(f2->GetImageData(),f2->GetImageDataSize());
+
+ string s0 =f2->GetPubElValByNumber(0x7fe0, 0x0000);
+ string s10=f2->GetPubElValByNumber(0x7fe0, 0x0010);
+ printf("lgr 7fe0, 0000 %s\n",s0.c_str());
+ printf("lgr 7fe0, 0010 %s\n",s10.c_str());
+
+ f1->ReplaceOrCreateByNumber( f2->GetPubElValByNumber(0x7fe0, 0x0000),
+ 0x7fe0, 0x0000);
+ //f1->ReplaceOrCreateByNumber( f2->GetPubElValByNumber(0x7fe0, 0x0010),
+ // 0x7fe0, 0x0010);
sprintf(resultat, "%s.vol", deuxieme.c_str());
printf ("WriteDCM\n");
- f1->WriteDcmImplVR(resultat);
+ //f1->WriteDcmImplVR(resultat);
+ f1->WriteAcr(resultat);
}
bool gdcmFile::ReadPixelData(void* destination) {
if ( !OpenFile())
return false;
- if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
+
+ if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
CloseFile();
return false;
+ }
+
+ if ( !IsDicomV3() ||
+ IsImplicitVRLittleEndianTransferSyntax() ||
+ IsExplicitVRLittleEndianTransferSyntax() ||
+ IsExplicitVRBigEndianTransferSyntax() ||
+ IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
+
+ size_t ItemRead = fread(destination, lgrTotale, 1, fp);
+ if ( ItemRead != 1 ) {
+ CloseFile();
+ return false;
+ } else {
+ CloseFile();
+ return true;
+ }
}
+
if (IsJPEGLossless()) {
- destination = _IdDcmJpegRead(fp);
- } else {
- size_t ItemRead = fread(destination, lgrTotale, 1, fp);
- if ( ItemRead != 1 ) {
+ int ln;
+ fseek(fp,4,SEEK_CUR);
+ fread(&ln,4,1,fp);
+ if(GetSwapCode())
+ ln=SwapLong(ln);
+ //if (DEBUG)
+ printf ("ln %d\n",ln);
+ fseek(fp,ln,SEEK_CUR);
+ fseek(fp,4,SEEK_CUR);
+ fread(&ln,4,1,fp);
+ if(GetSwapCode())
+ ln=SwapLong(ln);
+ //if (DEBUG)
+ printf ("ln image comprimée %d\n",ln);
+
+ ClbJpeg* jpg = _IdDcmJpegRead(fp);
+ if(jpg == NULL) {
CloseFile();
return false;
- }
- }
- CloseFile();
- return true;
+ }
+ memcpy(destination,jpg->DataImg,lgrTotale);
+ _IdDcmJpegFree (jpg);
+ CloseFile();
+ return true;
+ }
+
+ printf ("Sorry, TransfertSyntax not yet taken into account ...\n");
+ CloseFile();
+ return false;
+
}
/////////////////////////////////////////////////////////////////
return false;
LoadElementValueSafe(Element);
const char * Transfert = Element->GetValue().c_str();
+ printf("TransfertSyntx %s\n",Transfert);
if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
return false;
guint16 ReadInt16(void);
guint32 ReadInt32(void);
- guint16 SwapShort(guint16);
- guint32 SwapLong(guint32);
guint32 FindLengthOB(void);
void Initialise(void);
void CheckSwap(void);
protected:
FILE * fp;
FileType filetype;
+
+ guint16 SwapShort(guint16); // needed by gdcmFile
+ guint32 SwapLong(guint32); // for JPEG Files :-(
bool OpenFile(bool exception_on_error = false)
throw(gdcmFileError);
bool CloseFile(void);
ClbJpeg * _IdDcmJpegRead (FILE * fp){
ClbJpeg * jpg=NULL;
jpg=ClbJpegAlloc();
- if(!jpg)
- return(NULL);
+ if(!jpg) {
+ printf("Fail to ClbJpegAlloc \n");
+ return(NULL);
+ }
ClbJpegInit (jpg);
- if(!ClbJpegStart(jpg, fp))
- return (NULL);
+ if(!ClbJpegStart(jpg, fp)) {
+ printf("Fail to ClbJpegStart \n");
+ return (NULL);
+ }
return (jpg);
}
static BOOL ClbJpegStart(ClbJpeg *jpg, FILE *inputfp)
{
jpg->infp=inputfp;
- if (!ClbJpegReadHeader(jpg)) return 0;
+ if (!ClbJpegReadHeader(jpg)) {
+ printf("Fail to ClbJpegReadHeader\n");
+ return 0;
+ }
//printf("sortie ClbJpegReadHeader\n");
- if (!ClbJpegDecodeData(jpg)) return 0;
+ if (!ClbJpegDecodeData(jpg)) {
+ printf("Fail to ClbJpegDecodeData\n");
+ return 0;
+ }
//printf("sortie ClbJpegDecodeData\n");
return 1;
}
while(!HeaderEnd)
{
gr=fgetc(jpg->infp);
- if(gr!=0xFF) return 0;
+ if(gr!=0xFF) {
+ printf("gr!=0xFF (=%02x)\n",gr);
+ return 0;
+ }
el=fgetc(jpg->infp);
if ( (el==0xFF) || (el==0x01) || (el==0xD8) ||(el==0xD9) ||( (el>=0xD0) && (el<=0xD7) ))
l2=fgetc(jpg->infp);
jpg->lSof.Wimg=(l1*256)+l2;
- jpg->lSof.NbComponent=fgetc(jpg->infp);
+ jpg->lSof.NbComponent=fgetc(jpg->infp);
jpg->lSof.SofTabPos=ftell(jpg->infp);
}
}
- if (!isLossLess) return 0;
+ if (!isLossLess) {
+ printf("NOT isLossLess\n");
+ return 0;
+ }
return 1;
}