30 for (
auto iter = m_ByteBuffers.begin(); iter != m_ByteBuffers.end(); ++iter)
40 for (
auto iter = m_ByteBuffers.begin(); iter != m_ByteBuffers.end(); ++iter)
45 m_ByteBuffers.clear();
50 m_ImageDimensions.clear();
54 m_OneTimeStepImageSizeInBytes = m_PixelType->GetSize();
55 for (
unsigned int i = 0; i < m_ImageDimension; ++i)
57 unsigned int currentImageDimension = image->
GetDimension(i);
58 m_ImageDimensions.push_back(currentImageDimension);
61 m_OneTimeStepImageSizeInBytes *= currentImageDimension;
67 m_NumberOfTimeSteps = 1;
68 if (m_ImageDimension > 3)
73 for (
unsigned int timestep = 0; timestep < m_NumberOfTimeSteps; ++timestep)
76 unsigned long bufferSize =
77 m_OneTimeStepImageSizeInBytes +
static_cast<unsigned long>(m_OneTimeStepImageSizeInBytes * 0.2) + 12;
78 unsigned char *byteBuffer = (
unsigned char *)malloc(bufferSize);
80 if (itk::Object::GetDebug())
83 MITK_INFO <<
"Using ZLib version: '" << zlibVersion() <<
"'" << std::endl
84 <<
"Attempting to compress " << m_OneTimeStepImageSizeInBytes <<
" image bytes into a buffer of size "
85 << bufferSize << std::endl;
89 ::Bytef *dest(byteBuffer);
90 ::uLongf destLen(bufferSize);
91 ::Bytef *source((
unsigned char *)imgAcc.GetData());
92 ::uLongf sourceLen(m_OneTimeStepImageSizeInBytes);
93 int zlibRetVal = ::compress(dest, &destLen, source, sourceLen);
94 if (itk::Object::GetDebug())
96 if (zlibRetVal == Z_OK)
98 MITK_INFO <<
"Success, using " << destLen <<
" bytes of the buffer (ratio "
99 << ((double)destLen / (
double)sourceLen) <<
")" << std::endl;
106 MITK_ERROR <<
"not enough memory" << std::endl;
109 MITK_ERROR <<
"output buffer too small" << std::endl;
112 MITK_ERROR <<
"other, unspecified error" << std::endl;
119 byteBuffer = (
unsigned char *)realloc(byteBuffer, destLen);
120 bufferSize = destLen;
124 m_ByteBuffers.push_back(std::pair<unsigned char *, unsigned long>(byteBuffer, bufferSize));
130 if (m_ByteBuffers.empty())
135 unsigned int dims[20];
136 for (
unsigned int dim = 0; dim < m_ImageDimension; ++dim)
137 dims[dim] = m_ImageDimensions[dim];
139 image->Initialize(*m_PixelType, m_ImageDimension, dims);
142 unsigned int timeStep(0);
143 for (
auto iter = m_ByteBuffers.begin(); iter != m_ByteBuffers.end(); ++iter, ++timeStep)
146 ::Bytef *dest((
unsigned char *)imgAcc.GetData());
147 ::uLongf destLen(m_OneTimeStepImageSizeInBytes);
148 ::Bytef *source(iter->first);
149 ::uLongf sourceLen(iter->second);
150 int zlibRetVal = ::uncompress(dest, &destLen, source, sourceLen);
151 if (itk::Object::GetDebug())
153 if (zlibRetVal == Z_OK)
155 MITK_INFO <<
"Success, destLen now " << destLen <<
" bytes" << std::endl;
162 MITK_ERROR <<
"compressed data corrupted" << std::endl;
165 MITK_ERROR <<
"not enough memory" << std::endl;
168 MITK_ERROR <<
"output buffer too small" << std::endl;
171 MITK_ERROR <<
"other, unspecified error" << std::endl;
178 image->SetGeometry(m_ImageGeometry);
void SetImage(Image *)
Creates a compressed version of the image.
virtual ImageDataItemPointer GetVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
Image::Pointer GetImage()
Creates a full mitk::Image from its compressed version.
Image class for storing images.
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
CompressedImageContainer()
virtual ~CompressedImageContainer()
unsigned int GetDimension() const
Get dimension of the image.
ImageReadAccessor class to get locked read access for a particular image part.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.