MeVisLab Toolbox Reference
mlImageFormatTools.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_IMAGE_FORMAT_TOOLS_H
14 #define ML_IMAGE_FORMAT_TOOLS_H
15 
19 
20 // Resolve platform independencies.
22 
23 #include "mlModuleIncludes.h"
24 #include "mlImageFormatTagList.h"
25 #include <mlTimeCounter.h>
26 
27 // Implement everything in ML namespace.
28 ML_START_NAMESPACE
29 
31  class MLImageFormatInfos;
32  class DataCompressor;
33  class MLImageFormatIdxTable;
34 
35  //----------------------------------------------------------------------
38  //----------------------------------------------------------------------
40 
41  public:
42  friend class MLImageFormatSaveHandler;
43 
45  enum SaveModeBits {
46  DefaultSaveMode = 0,
47  AllowPartialPages = 1,
49  SaveOnlyDefaultValue = 2
52  };
53 
54  //--------------------------------------------------------------------------------
57  //--------------------------------------------------------------------------------
58  typedef void MLImageFormatNotifyCB(double progress,
59  void *usrData
60  );
61 
62 
63  //--------------------------------------------------------------------------------
68  //--------------------------------------------------------------------------------
69  static const std::string ML_FILE_VERSION_STRING;
70 
71  //--------------------------------------------------------------------------------
75  //--------------------------------------------------------------------------------
76  static const std::string ML_FILE_VERSION_STRING_EXT;
77 
78  //--------------------------------------------------------------------------------
81  //--------------------------------------------------------------------------------
83 
84  //----------------------------------------------------------------------
85  //
88  //
89  //----------------------------------------------------------------------
90 
127  const std::string &fileName,
128  bool truncate = false,
129  const std::string &compressorName = "",
130  const MLImageFormatTagList &compressionTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
131  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
132  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
133  const std::string &defaultVoxelValue = "0",
134  bool rewritable = true,
135  bool suppressReadCheckSumTests = false);
136 
142  bool truncate = false,
143  const std::string &compressorName = "",
144  const MLImageFormatTagList &compressionTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
145  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
146  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
147  const std::string &defaultVoxelValue = "0",
148  bool rewritable = true,
149  bool suppressReadCheckSumTests = false);
150 
157 
186  PagedImage &inputPagedImg,
187  const SubImageBox &box = SubImageBox(),
188  MLImageFormatNotifyCB *callback = nullptr,
189  void *userData = nullptr,
190  const ScaleShiftData &scaleShiftData = ScaleShiftData(),
191  MLuint32 saveModeBits = DefaultSaveMode,
192  MLdouble *saveTime = nullptr ,
193  MLdouble *prepTime = nullptr);
194 
195 
212  MLuint32 saveModeBits);
213 
214 
241  PagedImage &inputPagedImg ,
242  const SubImageBox &box ,
243  MLImageFormatNotifyCB *callback ,
244  void *userData ,
245  const ScaleShiftData &scaleShiftData,
246  MLuint32 saveModeBits = DefaultSaveMode,
247  MLdouble *saveTime = nullptr ,
248  MLdouble *prepTime = nullptr);
249 
273  const SubImage &inputSubImg ,
274  MLImageFormatNotifyCB *callback ,
275  void *userData ,
276  const ScaleShiftData &scaleShiftData,
277  MLuint32 saveModeBits = DefaultSaveMode,
278  MLdouble *saveTime = nullptr ,
279  MLdouble *prepTime = nullptr);
280 
314  SubImage &subImgToFill,
315  bool useFileDataType,
316  bool useFileRegion,
317  const ScaleShiftData &scaleShiftData);
319 
320 
331  static MLuint32 calcCheckSum(const void *dataPtr, size_t numBytes, size_t voxSize);
332 
343  const std::string &fileName);
344 
345 
346  protected:
347 
355 
360 
372  MLint pageId,
373  SubImage &pageBuf);
374 
385  const size_t savedPageSizeInBytes,
386  const size_t expectedSizeInBytes,
387  MLuint8 *&loadedPage,
388  bool &isLossy);
389 
433  const SubImageBox &box,
434  PagedImage *inputPagedImg,
435  const SubImage *inputSubImg,
436  MLImageFormatNotifyCB *callback,
437  void *userData,
438  const ScaleShiftData &scaleShiftData,
439  bool replaceAreaToSave,
440  MLuint32 saveModeBits,
441  MLdouble *saveTime=nullptr,
442  MLdouble *prepTime=nullptr);
443 
472  const MLint pageId,
473  const bool isOutsideAreaToSave,
474  const MLTypeData *defaultVoxelPtr,
475  const SubImage &subImgToSave,
476  const bool replaceOnlyWrittenPageIds,
477  const MLuint32 saveModeBits,
478  TimeCounter &saveTimer,
479  MLdouble &saveTime,
480  TimeCounter &calcTimer,
481  MLdouble &calcTime);
482 
497  SubImage &dataSubImg,
498  MLint &dstBufSize);
499 
500  };
501 
502 ML_END_NAMESPACE
503 
504 #endif // of __mlImageFormatTools_H
505 
506 
#define MLIMAGEFORMATBASE_EXPORT
Abstract base class for ML data compression algorithms.
A base class for abstract read/write access of the MLImageFileFormat.
A internal structure containing information about an opened file.
Class defining a list of tags used in the MLImageFormat class.
Basic tool functions used to store, load, and modify a PagedImage in a file, used by the MLImageForma...
static MLErrorCode _decompressPageData(const MLImageFormatInfos &infos, const size_t savedPageSizeInBytes, const size_t expectedSizeInBytes, MLuint8 *&loadedPage, bool &isLossy)
Decompresses and replaces data given as pointer in loadedPage.
static const std::string ML_FILE_VERSION_STRING
Basic file version string used for MeVisLab release 1.5.
static MLErrorCode open(MLImageFormatInfos *&infos, const std::string &fileName, bool truncate=false, const std::string &compressorName="", const MLImageFormatTagList &compressionTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &userTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &privateTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const std::string &defaultVoxelValue="0", bool rewritable=true, bool suppressReadCheckSumTests=false)
Opens a file in binary mode returning a descriptor for the opened file.
static MLErrorCode overwrite(MLImageFormatInfos &infos, const SubImage &inputSubImg, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr)
Overwrites a region in a file that has been written before (with save).
static MLErrorCode close(MLImageFormatInfos *&infos)
Closes an open file.
static MLErrorCode overwrite(MLImageFormatInfos &infos, PagedImage &inputPagedImg, const SubImageBox &box, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr)
Overwrites a region in a file that has been written before (with save).
static MLuint32 calcCheckSum(const void *dataPtr, size_t numBytes, size_t voxSize)
Calculates a 24 bit checksum for the data given by dataPtr.
static const std::string ML_FILE_VERSION_STRING_EXT
Basic file version string used for MeVisLab release 1.5 plus addOns.
static MLErrorCode save(MLImageFormatInfos &infos, PagedImage &inputPagedImg, const SubImageBox &box=SubImageBox(), MLImageFormatNotifyCB *callback=nullptr, void *userData=nullptr, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLuint32 saveModeBits=DefaultSaveMode, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr)
Saves the data of the paged image inputPagedImg from the region given by box in the file.
void MLImageFormatNotifyCB(double progress, void *usrData)
Callback type that can be registered in save and overwrite functions to interrupt processing and to g...
static MLErrorCode _destroyFileProperties(MLImageFormatInfos *&infos)
Destroys the MLImageFileInfo object and resets the pointer to NULL.
static MLErrorCode open(MLImageFormatInfos *&infos, MLImageFormatAbstractFileHandle *fileHandle, bool truncate=false, const std::string &compressorName="", const MLImageFormatTagList &compressionTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &userTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const MLImageFormatTagList &privateTagList=MLImageFormatTagList::getDefaultEmptyTagList(), const std::string &defaultVoxelValue="0", bool rewritable=true, bool suppressReadCheckSumTests=false)
Overload of open() with a virtual file handle, have a look at open(..., filename, ....
SaveModeBits
Mode bits describing special save options.
static const size_t ML_MAX_VERSION_AND_FIRST_PAIR_SIZE
Number of characters that will not be exceeded by version string and first tag pair.
static MLErrorCode _saveIndexTableAndPages(MLImageFormatInfos &infos, const SubImageBox &box, PagedImage *inputPagedImg, const SubImage *inputSubImg, MLImageFormatNotifyCB *callback, void *userData, const ScaleShiftData &scaleShiftData, bool replaceAreaToSave, MLuint32 saveModeBits, MLdouble *saveTime=nullptr, MLdouble *prepTime=nullptr)
Saves or overwrites pages overlapping areaToSave of inputPagedImg.
static MLErrorCode _loadPage(const MLImageFormatInfos &infos, MLint pageId, SubImage &pageBuf)
Reads page given by ID pageId into memory handled by pageBuf.
static void setDICOMTreeSourceFileName(PagedImage &outImg, const std::string &fileName)
If the paged image has DicomTreeImagePropertyExtensions, then set their file names,...
static MLErrorCode overwriteHeaderAndPageList(const MLImageFormatInfos &infos, MLuint32 saveModeBits)
Saves the file header information a second time over the already written file.
static MLErrorCode getTile(const MLImageFormatInfos &infos, SubImage &subImgToFill, bool useFileDataType, bool useFileRegion, const ScaleShiftData &scaleShiftData)
Loads a subimage from the specified file and returns an MLErrorCode describing success or failure.
static MLErrorCode _savePage(MLImageFormatInfos &infos, const MLint pageId, const bool isOutsideAreaToSave, const MLTypeData *defaultVoxelPtr, const SubImage &subImgToSave, const bool replaceOnlyWrittenPageIds, const MLuint32 saveModeBits, TimeCounter &saveTimer, MLdouble &saveTime, TimeCounter &calcTimer, MLdouble &calcTime)
Stores the page subImgToSave in file given by infos and updates the corresponding entry in the index ...
static MLErrorCode _compressPageData(DataCompressor *compressor, SubImage &dataSubImg, MLint &dstBufSize)
Compresses data of a subimage.
static MLErrorCode _loadFileProperties(MLImageFormatInfos &infos)
Reads all information from the file given by fileHandle in infos and stores it in the returned inform...
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Definition: mlPagedImage.h:66
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition: mlSubImage.h:75
Class to measure precise time intervals.
Definition: mlTimeCounter.h:26
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:716
unsigned int MLuint32
Definition: mlTypeDefs.h:185
unsigned char MLuint8
Definition: mlTypeDefs.h:109
double MLdouble
Definition: mlTypeDefs.h:217
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
Definition: mlTypeDefs.h:1300
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:490
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...