libCZI
Reading and Writing CZI documents made easy
|
The CZI-writer object implements this interface:
The intented mode of operation is:
The model employed for the output-stream is:
The ICziWriterInfo-object passed in with the Create-function allows to specify a bounds for the coordinates and for the M-index. If the dimensions to be used in creating the CZI are known beforehand, it is recommended to specify them. If they are specified, then the writer-object will check the validity of the coordinates added, and so help to ensure that the resulting CZI is valid and well-formed. The CZI-segments containing the subblock-directory, the attachment-directory and the metadata are written last (in normal operation), and therefore they get added at the end of the file. However, those same segments are usually read first (most likely directly when opening the file), so there is some benefit of having them at the beginning of the file (we can save a seek-operation). For this purpose, it is possible to reserve space for those segments. The size for the reservations must be specified with the ICziWriterInfo at creation time. If the reserved space is not sufficient, then still the segment will be added at the end.
In order to write bitmap-data into a subblock, the method SyncAddSubBlock takes an argument of type AddSubBlockInfo. It employes a pull-based approach, where callbacks are used to provide the data (which is to be written into the CZI).
A subblock consists of three parts - the data, the metadata and the attachment. For each of those parts, the size (in bytes) needs to be specified. Metadata and attachment are optional, and a zero size means that the corresponding part is not used. The function objects are called in order to retrieve the data. The callback-function needs to give a pointer and the size of a data-block. The functions are only called while the method SyncAddSubBlock executes, and the pointer needs to be valid until either the same function is called again or the SyncAddSubBlock-method returns. The function will be called as many times as necessary in order to retrieve the amount of data specified. The parameter "callCnt" increments which each call, and the parameter offset gives how many data has already been retrieved. If the callback returns false, the remainder of the subblock will be filled with zeroes. If it provides more data than required, then the surplus data will not be used.
Pixel-data in a subblock needs to a stored with a stride exactly equal to bytes-per-pel times width-in-pixels. However, this callback-based approach allows to store pixel-data with an arbitrary stride. The library provides a couple of overloads for SyncAddSubBlock
They provide a simplified way if dealing with bitmap-data when it is given as e. g. a bitmap consecutive in memory but with a specific stride (which may not be equal to the minimal stride required in storage in CZI).