53 unsigned int currentImageDimension = image->
GetDimension(i);
57 m_OneTimeStepImageSizeInBytes *= currentImageDimension;
64 if (m_ImageDimension > 3)
72 unsigned long bufferSize =
73 m_OneTimeStepImageSizeInBytes +
static_cast<unsigned long>(m_OneTimeStepImageSizeInBytes * 0.2) + 12;
74 auto *byteBuffer = (
unsigned char *)malloc(bufferSize);
76 if (itk::Object::GetDebug())
79 MITK_INFO <<
"Using ZLib version: '" << zlibVersion() <<
"'" << std::endl
80 <<
"Attempting to compress " << m_OneTimeStepImageSizeInBytes <<
" image bytes into a buffer of size " 81 << bufferSize << std::endl;
85 ::Bytef *dest(byteBuffer);
86 ::uLongf destLen(bufferSize);
87 auto *source((
unsigned char *)imgAcc.GetData());
88 ::uLongf sourceLen(m_OneTimeStepImageSizeInBytes);
89 int zlibRetVal = ::compress(dest, &destLen, source, sourceLen);
90 if (itk::Object::GetDebug())
92 if (zlibRetVal == Z_OK)
94 MITK_INFO <<
"Success, using " << destLen <<
" bytes of the buffer (ratio " 95 << ((double)destLen / (
double)sourceLen) <<
")" << std::endl;
102 MITK_ERROR <<
"not enough memory" << std::endl;
105 MITK_ERROR <<
"output buffer too small" << std::endl;
108 MITK_ERROR <<
"other, unspecified error" << std::endl;
115 byteBuffer = (
unsigned char *)realloc(byteBuffer, destLen);
116 bufferSize = destLen;
120 m_ByteBuffers.push_back(std::pair<unsigned char *, unsigned long>(byteBuffer, bufferSize));
131 unsigned int dims[20];
135 image->Initialize(*
m_PixelType, m_ImageDimension, dims);
138 unsigned int timeStep(0);
142 auto *dest((
unsigned char *)imgAcc.GetData());
144 ::Bytef *source(iter->first);
145 ::uLongf sourceLen(iter->second);
146 int zlibRetVal = ::uncompress(dest, &destLen, source, sourceLen);
147 if (itk::Object::GetDebug())
149 if (zlibRetVal == Z_OK)
151 MITK_INFO <<
"Success, destLen now " << destLen <<
" bytes" << std::endl;
158 MITK_ERROR <<
"compressed data corrupted" << std::endl;
161 MITK_ERROR <<
"not enough memory" << std::endl;
164 MITK_ERROR <<
"output buffer too small" << std::endl;
167 MITK_ERROR <<
"other, unspecified error" << std::endl;
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
unsigned int m_ImageDimension
void SetImage(Image *)
Creates a compressed version of the image.
~CompressedImageContainer() override
BaseGeometry::Pointer m_ImageGeometry
Image::Pointer GetImage()
Creates a full mitk::Image from its compressed version.
unsigned int GetDimension() const
Get dimension of the image.
virtual ImageDataItemPointer GetVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
Image class for storing images.
std::vector< unsigned int > m_ImageDimensions
mitk::Image::Pointer image
unsigned int m_NumberOfTimeSteps
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
CompressedImageContainer()
unsigned long m_OneTimeStepImageSizeInBytes
std::vector< std::pair< unsigned char *, unsigned long > > m_ByteBuffers
one for each timestep. first = pointer to compressed data; second = size of buffer in bytes ...
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.
Class for defining the data type of pixels.