X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelWriteConvert.cxx;h=8c93216dbc4f02f60542ac16944ee8fb4541072f;hb=5037cb08a173d3ac3b4d9db71201c635bcabd19b;hp=00a3fbf25c6b9df7abdcb6f850cf9144a6ffe01f;hpb=6a5de9524996d429cd18c722261421ff4e298681;p=gdcm.git diff --git a/src/gdcmPixelWriteConvert.cxx b/src/gdcmPixelWriteConvert.cxx index 00a3fbf2..8c93216d 100644 --- a/src/gdcmPixelWriteConvert.cxx +++ b/src/gdcmPixelWriteConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelWriteConvert.cxx,v $ Language: C++ - Date: $Date: 2007/08/24 10:45:18 $ - Version: $Revision: 1.17 $ + Date: $Date: 2007/09/15 11:10:37 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -240,27 +240,35 @@ void PixelWriteConvert::SetCompressJPEG2000UserData(uint8_t *data, size_t size, std::ostringstream *of = new std::ostringstream(); int xsize = image->GetXSize(); - int ysize = image->GetYSize(); - int zsize = image->GetZSize(); + int ysize = image->GetYSize(); + int zsize = image->GetZSize(); int samplesPerPixel = image->GetSamplesPerPixel(); //std::cout << "X: " << xsize << std::endl; //std::cout << "Y: " << ysize << std::endl; //std::cout << "Sample: " << samplesPerPixel << std::endl; int bitsallocated = image->GetBitsAllocated(); int sign = image->IsSignedPixelData(); - unsigned int fragment_size = xsize*ysize*samplesPerPixel * (bitsallocated / 8); - assert( fragment_size*zsize == size ); - + unsigned int fragment_size = xsize*ysize*samplesPerPixel * (bitsallocated / 8); + //assert( fragment_size*zsize == size ); + + gdcmDebugMacro("fragment_size " << fragment_size << " zsize " << zsize << " size " << size); + assert( abs((long)(fragment_size*zsize-size)) <=1 ); + JpegVector JpegFragmentSize; + gdcmDebugMacro("Call Encode..BasicOffsetTable " ); #if WITHOFFSETTABLE size_t bots; //basic offset table start EncodeWithBasicOffsetTable(of, zsize, bots); #else EncodeWithoutBasicOffsetTable(of, 1); #endif + + gdcmDebugMacro("Out of Encode..BasicOffsetTable " ); + uint8_t *pImageData = data; for(int i=0; itellp(); gdcm_write_JPEG2000_file(of, (char*)pImageData,size, @@ -320,13 +328,22 @@ void PixelWriteConvert::SetCompressJPEGUserData(uint8_t *data, size_t size, File int xsize = image->GetXSize(); int ysize = image->GetYSize(); int zsize = image->GetZSize(); + int samplesPerPixel = image->GetSamplesPerPixel(); + int bitsAllocated = image->GetBitsAllocated(); + int bitsStored = image->GetBitsStored(); + //std::cout << "X: " << xsize << std::endl; //std::cout << "Y: " << ysize << std::endl; //std::cout << "Sample: " << samplesPerPixel << std::endl; - int bitsallocated = image->GetBitsAllocated(); - unsigned int fragment_size = xsize*ysize*samplesPerPixel * (bitsallocated / 8); - assert( fragment_size*zsize == size ); + + gdcmDebugMacro( "bitsAllocated " << bitsAllocated << " bitsStored " <tellp(); - if( bitsallocated == 8 ) + size_t beg = of->tellp(); + if( bitsStored == 8 ) { gdcm_write_JPEG_file8(of, (char*)pImageData,size, - image->GetXSize(), image->GetYSize(), image->GetZSize(), image->GetSamplesPerPixel(), - image->GetBitsAllocated(), 100 ); + xsize, ysize, zsize, samplesPerPixel, + bitsAllocated, 100 ); } - else if (bitsallocated <= 12) + else if (bitsStored <= 12) { - assert( bitsallocated >= 8 ); - gdcm_write_JPEG_file12(of, (char*)pImageData,size, - image->GetXSize(), image->GetYSize(), image->GetZSize(), image->GetSamplesPerPixel(), - image->GetBitsAllocated(), 100); + assert( bitsStored >= 8 ); + gdcm_write_JPEG_file12(of, (char*)pImageData, size, + xsize, ysize, zsize, samplesPerPixel, + bitsAllocated, 100); } - else if (bitsallocated <= 16) + else if (bitsStored <= 16) { - assert( bitsallocated >= 12 ); + assert( bitsStored >= 12 ); gdcm_write_JPEG_file16(of, (char*)pImageData,size, - image->GetXSize(), image->GetYSize(), image->GetZSize(), image->GetSamplesPerPixel(), - image->GetBitsAllocated(), 100); + xsize, ysize, zsize, samplesPerPixel, + bitsAllocated, 100); } + else if (bitsStored <= 32) // if we are lucky (?), it will compress as a 2 bytes stream + { // (Actually it doesn't !) + // Just to allow ctest not to abort on 32bits per pixel image RTDOSE.dcm + assert( bitsStored >= 16 ); + gdcmDebugMacro( "Warning : bitsStored>16 not supported by JPEG !" ); + gdcm_write_JPEG_file16(of, (char*)pImageData, size, + xsize, ysize, zsize, samplesPerPixel, + bitsAllocated, 100); + } else { + std::cerr << "Major pb : bitsStored =" << bitsStored << std::endl; abort(); } size_t end = of->tellp(); //static int i = 0; JpegPair &jp = JpegFragmentSize[i]; - jp.second = (uint32_t)(end-beg); + jp.second = (uint32_t)(end-beg); if( ((end-beg) % 2) ) { of->put( '\0' ); @@ -380,7 +414,6 @@ void PixelWriteConvert::SetCompressJPEGUserData(uint8_t *data, size_t size, File //JpegPair &jp = v[0]; //jp.second = 15328; - //userData, UserDataSize); // CreateOneFrame(of, pImageData, fragment_size, xsize, ysize, zsize, // samplesPerPixel, quality, JpegFragmentSize); @@ -392,7 +425,6 @@ void PixelWriteConvert::SetCompressJPEGUserData(uint8_t *data, size_t size, File UpdateBasicOffsetTable(of, JpegFragmentSize, bots); #endif - size_t of_size = of->str().size(); UserData = new uint8_t[of_size]; memcpy(UserData, of->str().c_str(), of_size);