Basic tool functions used to store, load, and modify a PagedImage in a file, used by the MLImageFormat.
More...
#include <mlImageFormatTools.h>
|
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 void | setDICOMTreeSourceFileName (PagedImage &outImg, const std::string &fileName) |
| If the paged image has DicomTreeImagePropertyExtensions then set their file names, because other modules perhaps want to derive destination file names from them as it is done for example in ImageSave.
|
|
|
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 | 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, ...).
|
|
static MLErrorCode | close (MLImageFormatInfos *&infos) |
| Closes an open file.
|
|
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.
|
|
static MLErrorCode | overwriteHeaderAndPageList (const MLImageFormatInfos &infos, MLuint32 saveModeBits) |
| Save the file header information a second time over the already written 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 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 | 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 | _loadFileProperties (MLImageFormatInfos &infos) |
| Reads all information from the file given by fileHandle in infos and stores it the returned information object.
|
|
static MLErrorCode | _destroyFileProperties (MLImageFormatInfos *&infos) |
| Destroys the MLImageFileInfo object and resets the pointer to NULL.
|
|
static MLErrorCode | _loadPage (const MLImageFormatInfos &infos, MLint pageId, SubImage &pageBuf) |
| Read page given by id pageId into memory handled by pageBuf.
|
|
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 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 | _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 table.
|
|
static MLErrorCode | _compressPageData (DataCompressor *compressor, SubImage &dataSubImg, MLint &dstBufSize) |
| Compresses data of a subimage.
|
|
Basic tool functions used to store, load, and modify a PagedImage in a file, used by the MLImageFormat.
Definition at line 39 of file mlImageFormatTools.h.
◆ MLImageFormatNotifyCB
Callback type which can be registered in save and overwrite functions to interrupt processing and to get process state information.
Definition at line 58 of file mlImageFormatTools.h.
◆ SaveModeBits
Mode bits describing special save options.
Enumerator |
---|
DefaultSaveMode | Normal save, readable by version 000.000.000.
|
AllowPartialPages | Allows storage of pages reaching outside image as partial pages pages; cannot be read by version 000.000.000 code any more.
|
SaveOnlyDefaultValue | Written pages are only filled with default value and no data is requested from the input image; used for fast creation of empty images.
Not supported for overwriting existing regions.
|
Definition at line 45 of file mlImageFormatTools.h.
◆ _compressPageData()
Compresses data of a subimage.
- Parameters
-
compressor | Instance of MLDataCompressor used for compression of page data if non NULL. If NULL the page data is not compressed. |
dataSubImg | Subimage containing the data to compress. Its data chunk is (only) overwritten with compressed data on effective and successful compression. |
dstBufSize | Size of compressed data or 0 if no compression took place (because it was ineffective or no compressor was available). |
- Returns
- ML_RESULT_OK on success and if data was not compressed. On failure an error describing code is returned.
◆ _decompressPageData()
Decompress and replace data given as pointer in loadedPage.
- Parameters
-
infos | The information structure about the current working file. Its settings must fit with corresponding settings of inputPagedImg. |
savedPageSizeInBytes | Must be exactly the size of the compressed memory buffer given in loadedPage. |
expectedSizeInBytes | The expected size of the uncompressed memory. |
loadedPage | must be a valid pointer to loaded and compressed page data. It will be freed with MLFree() and replaced with decompressed data if decompression takes place. On failure is also could be returned as NULL. |
isLossy | will be overwritten to false if data was lossless compressed, otherwise true. |
◆ _destroyFileProperties()
Destroys the MLImageFileInfo object and resets the pointer to NULL.
Returns ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ _loadFileProperties()
Reads all information from the file given by fileHandle in infos and stores it the returned information object.
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to read from. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ _loadPage()
Read page given by id pageId into memory handled by pageBuf.
pageBuf must provide enough data for a full loaded page extent. Returns ML_RESULT_OK on success and another MLErrorCode otherwise. Requires that infos is valid, that it describes a file opened for reading and that all passed parameters (index table and tag list) are already read from that open file. It also requires that data type and box of pageBuf are set correctly. Note that the loading process may cause that the page box is modified to match the valid image region.
◆ _saveIndexTableAndPages()
static MLErrorCode ml::MLImageFormatTools::_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 ) |
|
staticprotected |
Save or overwrite pages overlapping areaToSave of inputPagedImg.
Note that only one of both pointers, inputPagedImg and inputSubImg, may be non NULL to define a unique source for the data to be written. Whichever is used - its data type must fit the setting in info and it must contain the box to be saved if box is non empty.
- Parameters
-
infos | The information structure about the current working file. Its settings must fit with corresponding settings of inputPagedImg. |
box | box describing the pages to be written, pages outside are not stored and marked as pages filled with defaultVoxelValue. Regions outside but inside of pages are filled with defaultVoxelValue. An empty box is considered as full image. |
inputPagedImg | The paged image from where page data and/or image properties are taken to be stored. It must be up to date. |
inputSubImg | The subimage from which page data and image properties are taken to be stored. It must be up to date. |
callback | Function to be called on different processing and storage to notify and/or break the storage process. May be passed as NULL pointer and is ignored then. |
userData | Application data passed to the callback function or NULL not needed. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disc. Default is the identical transformation. |
replaceAreaToSave | if true then the area to save is overwritten without changes of other file contents outside that region. If false then all pages are overwritten, even if outside the areaToSave. Note that true also may cause that partially written pages are loaded and rewritten with changes. It also may cause a fragmentation of the file if written pages do not fit into their former data gap. Default is false. |
saveTime | Ignored if NULL, otherwise it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL, otherwise it returns the time needed for data preparation such as reordering or compression without saving. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ _savePage()
static MLErrorCode ml::MLImageFormatTools::_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 ) |
|
staticprotected |
Store the page subImgToSave in file given by infos and update the corresponding entry in the index table.
Note that pages outside the areaToSave are not stored - only the index table entries are updated. In this case subImgToSave does not need to have a valid data pointer. If saveModeBits allow storing partial pages then subImgToSave will be reduced to
- Parameters
-
infos | File information structure from file open in writable and binary mode. |
pageId | id of page to be stored. |
isOutsideAreaToSave | true if page is outside the area to save, false otherwise. If true then only entries of the index table are updated. |
defaultVoxelPtr | Pointer to value used for non stored values outside box and for stored page regions outside box. |
subImgToSave | The page data to be saved. It must be up to date. |
replaceOnlyWrittenPageIds | if true then entries of the index table are updated only if isOutsideAreaToSave is false. Otherwise all page ids are updated, even those whose pages are not stored. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTimer | TimeCounter used to measure the time needed for pure data saving without data preparation such as data reordering or compression. |
saveTime | The time measured with saveTimer is added to this value. |
calcTimer | TimeCounter used to measure the time needed for data processing such as compression, reordering and checksums without saving time. |
calcTime | The time measured with calcTimer is added to this value. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ calcCheckSum()
Calculates a 24 bit check sum for the data given by dataPtr.
All values of each byte in the data are multiplied with their byte position and added to the sum. The checkSum calculation traverses voxel data endianess independent; therefore it assumes that the data is in local machine endianess. Thus the calculated sum will be the same on machines with other endianess.
- Parameters
-
dataPtr | points to the chunk of data to be check-summed. |
numBytes | is the whole number of bytes to be included in checksum. |
voxSize | is the size of a voxel in bytes stored in the data. numBytes must be divisible exactly by voxSize. |
◆ close()
Closes an open file.
Closing a non open file causes an error.
- Parameters
-
infos | A pointer to a valid information structure created by open() on the file to be closed. |
- Returns
- ML_RESULT_OK on success or another code describing the problem. Pointer to infos is always reset to NULL.
◆ getTile()
Loads a subimage from the specified file and returns an MLErrorCode describing success or failure.
Previous settings of the subimage are overwritten. Subimage memory will be (re)allocated if its pointer is NULL or if memory denoted by box and data type is too small, otherwise memory will be reused.
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to read from. |
subImgToFill | The subimage to be manage the loaded data. |
useFileDataType | If true then the data type of the stored file is used; if false the data type of subImgToFill is used. Default is to use the data type of the subimage. |
useFileRegion | If true then the extent of the file is loaded as tile and the subImgToFill box is overwritten; if false the region of subImgToFill is used. Default is to use the region of the subimage. |
scaleShiftData | Specifies scale factor and offset for loaded data. If not passed the data will not be rescaled. |
- Returns
- An MLErrorCode describing the success or failure of the operation and ML_RESULT_OK on success.
Note that this routine will use subImgToFill.free() and subImgToFill.allocate() to (re)allocate the data if its size is not enough. Be sure that eventually set subimage data was also allocated with subImgToFill.allocate() or MLAllocateMemory (and not with new or so) to avoid collisions of memory managers. Automatically opens the file if still not done and closes it after operation if autoClose is true (the default).
◆ open() [1/2]
Opens a file in binary mode returning a descriptor for the opened file.
- Parameters
-
infos | A NULL MLImageFormatPointer which is initialized with an object with open file information. |
fileName | is the UTF8 encoded path and name of the file to be opened. |
truncate | opens the file for new or overwriting the file and discarding the previous contents if true. Reopens an exiting file for reading and manipulation if false. |
compressorName | name of DataCompressor used for data compression if not "" (the default). |
compressionTagList | is the list of MLImageFormatTags storing arguments for the compressor passed in compressor argument. Ignored if compressor is NULL. |
userTagList | is the list of MLImageFormatTags storing user information. |
privateTagList | is the list of MLImageFormatTags storing private information. |
defaultVoxelValue | is the string value used for all non existing pages and not written pages to define a background value for sparsely written image. |
rewritable | If truncate is false then this flag decides whether the file is opened as read only or as a rewritable file. Default is true which means that opening is done in read-write mode. This flag is ignored if truncate is true. |
suppressReadCheckSumTests | If true then checksum tests are disabled while reading page data to gain maximum load performance; the default is off, because this is not recommended. Not allowed if the file is created or modified. |
- Returns
- a new MLImageFormatInfo structure with a valid file handle on success or NULL on failure. On failures the file is closed.
◆ open() [2/2]
◆ overwrite() [1/2]
Overwrites a region in a file which has been written before (with save).
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to write in. |
inputSubImg | is the ML subimage which shall overwrite the corresponding area in the file. |
callback | function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | application data to be passed to the callback function if it is called. Otherwise it is ignored. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disc. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL, otherwise it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL, otherwise it returns the time needed for data preparation such as reordering or compression without saving. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ overwrite() [2/2]
Overwrites a region in a file which has been written before (with save).
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to write in. |
inputPagedImg | is the ML paged image providing the image data to be stored. |
box | only pages overlapping with box are written into the file. It defaults to the empty box. An empty box means that the whole image is to be stored. |
callback | function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | application data to be passed to the callback function if it is called. Otherwise it is ignored. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disc. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL, otherwise it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL, otherwise it returns the time needed for data preparation such as reordering or compression without saving. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ overwriteHeaderAndPageList()
Save the file header information a second time over the already written file.
It requires that the file is already written (for example with save()) and that the file is open. It allows an update of already written tags, for example after correcting the minimum or maximum voxel values or other image properties. WARNING, IMPORTANT: It is only possible to overwrite the tag list correctly if its binary size is unchanged and page properties and indexes remain consistent. It is left to the caller to guarantee this consistency. So use this method with care!
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to write in. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
- Returns
- ML_RESULT_OK on success or another code in case of failure.
◆ save()
Saves the data of the paged image inputPagedImg from the region given by box in the file.
Regions outside box are filled with the value given in infos. Existing files will be overwritten without check.
- Parameters
-
infos | infos must be a valid information structure created by open() on the file to write in. |
inputPagedImg | is the ML paged image providing the image data to be stored. |
box | only pages overlapping with box are written into the file. It defaults to the empty box. An empty box means that the whole image is to be stored. |
callback | function to be executed during the save process to update process state or NULL (the default) if not set. |
userData | application data to be passed to the callback function if it is called. Otherwise it is ignored. |
scaleShiftData | Defines a linear transformation to be applied on data from inputPagedImg or inputSubImg before saving it on disc. Default is the identical transformation. |
saveModeBits | Bit combination setting special save options: See SaveModeBits for possible options. |
saveTime | Ignored if NULL, otherwise it returns the time needed for pure data saving without data preparation such as data reordering or compression. |
prepTime | Ignored if NULL, otherwise it returns the time needed for data preparation such as reordering or compression without saving. |
- Returns
- ML_RESULT_OK on success or on failure an MLErrorCode describing the problem.
◆ setDICOMTreeSourceFileName()
If the paged image has DicomTreeImagePropertyExtensions then set their file names, because other modules perhaps want to derive destination file names from them as it is done for example in ImageSave.
If there is no such extension then create an empty one, because the file name if often needed. Invalid output images are not modified and no names are set.
- Parameters
-
outImg | is the output image in whose DICOM property extensions the file names shall be set. |
fileName | is the file name to be set. |
◆ MLImageFormatSaveHandler
◆ ML_FILE_VERSION_STRING
const std::string ml::MLImageFormatTools::ML_FILE_VERSION_STRING |
|
static |
Basic file version string used for MeVisLab release 1.5.
Version string used by the first MLImageFormat source. If possible all future versions should be able to read it. The length of the string will not change in future versions.
Definition at line 69 of file mlImageFormatTools.h.
◆ ML_FILE_VERSION_STRING_EXT
const std::string ml::MLImageFormatTools::ML_FILE_VERSION_STRING_EXT |
|
static |
Basic file version string used for MeVisLab release 1.5 plus addOns which endanger backward compatibility to version ML_FILE_VERSION_STRING.
Definition at line 75 of file mlImageFormatTools.h.
◆ ML_MAX_VERSION_AND_FIRST_PAIR_SIZE
const size_t ml::MLImageFormatTools::ML_MAX_VERSION_AND_FIRST_PAIR_SIZE |
|
static |
Number of characters which will not be exceeded by version string and first tag pair.
Definition at line 81 of file mlImageFormatTools.h.
The documentation for this class was generated from the following file: