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  //--------------------------------------------------------------------------------
74  //--------------------------------------------------------------------------------
75  static const std::string ML_FILE_VERSION_STRING_EXT;
76 
77  //--------------------------------------------------------------------------------
80  //--------------------------------------------------------------------------------
82 
83  //----------------------------------------------------------------------
84  //
87  //
88  //----------------------------------------------------------------------
89 
126  const std::string &fileName,
127  bool truncate = false,
128  const std::string &compressorName = "",
129  const MLImageFormatTagList &compressionTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
130  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
131  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
132  const std::string &defaultVoxelValue = "0",
133  bool rewritable = true,
134  bool suppressReadCheckSumTests = false);
135 
141  bool truncate = false,
142  const std::string &compressorName = "",
143  const MLImageFormatTagList &compressionTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
144  const MLImageFormatTagList &userTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
145  const MLImageFormatTagList &privateTagList = MLImageFormatTagList::getDefaultEmptyTagList(),
146  const std::string &defaultVoxelValue = "0",
147  bool rewritable = true,
148  bool suppressReadCheckSumTests = false);
149 
156 
185  PagedImage &inputPagedImg,
186  const SubImageBox &box = SubImageBox(),
187  MLImageFormatNotifyCB *callback = nullptr,
188  void *userData = nullptr,
189  const ScaleShiftData &scaleShiftData = ScaleShiftData(),
190  MLuint32 saveModeBits = DefaultSaveMode,
191  MLdouble *saveTime = nullptr ,
192  MLdouble *prepTime = nullptr);
193 
194 
211  MLuint32 saveModeBits);
212 
213 
240  PagedImage &inputPagedImg ,
241  const SubImageBox &box ,
242  MLImageFormatNotifyCB *callback ,
243  void *userData ,
244  const ScaleShiftData &scaleShiftData,
245  MLuint32 saveModeBits = DefaultSaveMode,
246  MLdouble *saveTime = nullptr ,
247  MLdouble *prepTime = nullptr);
248 
272  const SubImage &inputSubImg ,
273  MLImageFormatNotifyCB *callback ,
274  void *userData ,
275  const ScaleShiftData &scaleShiftData,
276  MLuint32 saveModeBits = DefaultSaveMode,
277  MLdouble *saveTime = nullptr ,
278  MLdouble *prepTime = nullptr);
279 
313  SubImage &subImgToFill,
314  bool useFileDataType,
315  bool useFileRegion,
316  const ScaleShiftData &scaleShiftData);
318 
319 
330  static MLuint32 calcCheckSum(const void *dataPtr, size_t numBytes, size_t voxSize);
331 
342  const std::string &fileName);
343 
344 
345  protected:
346 
354 
359 
371  MLint pageId,
372  SubImage &pageBuf);
373 
384  const size_t savedPageSizeInBytes,
385  const size_t expectedSizeInBytes,
386  MLuint8 *&loadedPage,
387  bool &isLossy);
388 
432  const SubImageBox &box,
433  PagedImage *inputPagedImg,
434  const SubImage *inputSubImg,
435  MLImageFormatNotifyCB *callback,
436  void *userData,
437  const ScaleShiftData &scaleShiftData,
438  bool replaceAreaToSave,
439  MLuint32 saveModeBits,
440  MLdouble *saveTime=nullptr,
441  MLdouble *prepTime=nullptr);
442 
471  const MLint pageId,
472  const bool isOutsideAreaToSave,
473  const MLTypeData *defaultVoxelPtr,
474  const SubImage &subImgToSave,
475  const bool replaceOnlyWrittenPageIds,
476  const MLuint32 saveModeBits,
477  TimeCounter &saveTimer,
478  MLdouble &saveTime,
479  TimeCounter &calcTimer,
480  MLdouble &calcTime);
481 
496  SubImage &dataSubImg,
497  MLint &dstBufSize);
498 
499  };
500 
501 ML_END_NAMESPACE
502 
503 #endif // of __mlImageFormatTools_H
504 
505 
#define MLIMAGEFORMATBASE_EXPORT
Global and OS specific declarations for the MLImageFormatBase project.
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, not to be used, because it is subje...
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)
Decompress and replace 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 which 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 which has been written before (with save).
static MLuint32 calcCheckSum(const void *dataPtr, size_t numBytes, size_t voxSize)
Calculates a 24 bit check sum 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 which endanger backward compatibi...
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 which can be registered in save and overwrite functions to interrupt processing and to ...
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 which 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)
Save or overwrite pages overlapping areaToSave of inputPagedImg.
static MLErrorCode _loadPage(const MLImageFormatInfos &infos, MLint pageId, SubImage &pageBuf)
Read 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)
Save 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)
Store the page subImgToSave in file given by infos and update the corresponding entry in the index ta...
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 the returned informati...
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
This class manages/represents a rectangular 6d image region which 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:818
unsigned int MLuint32
Definition: mlTypeDefs.h:191
unsigned char MLuint8
Definition: mlTypeDefs.h:115
double MLdouble
Definition: mlTypeDefs.h:223
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
Definition: mlTypeDefs.h:1436
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Define the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type.