From f25cae887a0906bd4c4733da51a88bf08a85e840 Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 21 Oct 2003 12:14:31 +0000 Subject: [PATCH] - call of 'xmedcom' Jpeg Lossles libray (instead of the old LibIDO one) - 'Compacted Files' (12 Bits Allocate, 12 Bits Stored) are now dealt with --- src/gdcmFile.cxx | 166 ++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 96 deletions(-) diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 7274df46..4490655c 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,6 +3,7 @@ #include "gdcmFile.h" #include "gdcmUtil.h" #include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess +#include "jpeg/ljpg/jpegless.h" ///////////////////////////////////////////////////////////////// /** @@ -124,7 +125,34 @@ bool gdcmFile::ReadPixelData(void* destination) { if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { CloseFile(); return false; - } + } + +// ------------------------- Compacted File (12 Bits Per Pixel) + + /* unpack 12 Bits pixels into 16 Bits pixels */ + /* 2 pixels 12bit = [0xABCDEF] */ + /* 2 pixels 16bit = [0x0ABD] + [0x0FCE] */ + + if (GetBitsAllocated()==12) { + int nbPixels = GetXSize()*GetYSize(); + unsigned char b0, b1, b2; + + for(int p=0;p> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f); + /* A */ /* B */ /* D */ + *((unsigned short int*)destination)++ = + ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4); + /* F */ /* C */ /* E */ + + // Troubles expected on Big-Endian processors ? + } + return(true); + } + // ------------------------- Uncompressed File @@ -152,74 +180,32 @@ bool gdcmFile::ReadPixelData(void* destination) { nb = 16; } else { nb = atoi(str_nb.c_str() ); - if (nb == 12) nb =16; + if (nb == 12) nb =16; // ?? 12 should be ACR-NEMA only ? } int nBytes= nb/8; int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); - - // ------------------------------- JPEG LossLess : call to Jpeg Libido - - if (IsJPEGLossless() && GetZSize() == 1) { - - int ln; // Position on begining of Jpeg Pixels - fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : Basic Offset Table Item - fread(&ln,4,1,fp); - if(GetSwapCode()) - ln=SwapLong(ln); // Item length - fseek(fp,ln,SEEK_CUR); // skipping Basic Offset Table ('ln' bytes) - fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : First fragment Item Tag - fread(&ln,4,1,fp); // First fragment length (just to know) - if(GetSwapCode()) - ln=SwapLong(ln); - - ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one. - // (We use the LibIDO one :-( - if(jpg == NULL) { - CloseFile(); - return false; - } - int * dataJpg = jpg->DataImg; - - switch (nBytes) { - case 1: - { - unsigned short *dest = (unsigned short *)destination; - for (int i=0; iDataImg; - unsigned short *dest = (unsigned short *)destination; - switch (nBytes) { - case 1: - { - for (int i=0; i it does NOT ! + /* + JPEGLosslessDecodeImage (fp, + (unsigned short *)destination, + GetPixelSize()*8* GetSamplesPerPixel(), + ln); + + */ + // 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 - } + } + + + } if (!res) break; @@ -320,7 +294,7 @@ bool gdcmFile::ReadPixelData(void* destination) { } } // endWhile parsing fragments until Sequence Delim. Tag found - + return res; } @@ -559,8 +533,6 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { int l = lgrTotale/3; memmove(newDest, destination, l);// move Gray pixels to temp area - unsigned char * x = newDest; - int j; // See PS 3.3-2003 C.11.1.1.2 p 619 // @@ -571,7 +543,9 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { // if we get a black image, let's just remove the '+1' // and check again // if it works, we shall have to check the 3 Palettes - // to see which byte is ==0 (first one, on second one) + // to see which byte is ==0 (first one, or second one) + + //unsigned char * x = newDest; for (int i=0;i