|
OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
|
Example compression plug-in that always fails to compress. More...
Classes | |
| class | Register |
| Register the compress and decompress functions in the factory. More... | |
Static Public Member Functions | |
| static compressor_t | getCompressor (const std::vector< std::string > &) |
| Get a functor for compressing data. More... | |
| static rawdata_t | compress (const rawdata_t &data, const index3_t &shape) |
| Compress using the chosen algorithm. More... | |
| static rawdata_t | decompress (const rawdata_t &cdata, const BrickStatus &status, const index3_t &shape) |
| Decompress data if it was compressed by our algorithm. More... | |
Example compression plug-in that always fails to compress.
This class is here just as an example and for documentation. Real compression classes may use "copydoc" instead of repeating what is explained here.
|
static |
Compress using the chosen algorithm.
| data | Smart pointer to data, and size in bytes of data. |
| shape | hint for 3d layout of data in number of samples. |
The number and type of parameters, except for the first one, varies depending on the algorithm being used. Some algorithms might not need additional parameters at all.
Current assumptions that apply to all compression algorithms. Except for the one about thread safety these are subject to change.
|
static |
Decompress data if it was compressed by our algorithm.
| cdata | Compressed data, possibly with trailing garbage. |
| status | Might be used to identfy which algorithm was used. |
| shape | rank and size in samples of the uncompressed result. |
The algorithm should check both the status argument and any magic number at the start of the buffer to decide whether this is data we know how to decompress. If not then return {nullptr, 0} which should make the caller try something else.
If the algorithm is recognized but the data cannot be decompressed because it is corrupt then the method may throw an exception. In that case no further algorithms will be tried.
Older versions of this function also received the value type of the data that was compressed and the value type we want it returned in This is now redundant since we only allow compressing float data. Anything else is simply not useful.
Passing an uncompressed brick to this function is an error. I.e. status will never be Normal. We don't have enough context to handle uncompressed bricks that might require byteswapping and fix for legacy quirks. Also cannot handle constant bricks, missing bricks, etc.
Current assumptions that apply to all decompression algorithms. Except for the one about thread safety these are subject to change.
|
static |
Get a functor for compressing data.
Parse the stringly typed arguments that the factory sent us. Do a consistency check on the arguments. Capture the now strongly typed compressor arguments in a lambda that can be used to compress one block of data.
The returned lambda function is supposed to be thread safe.
The return is allowed to be an empty function. The caller will treat this as if no compression had been requested. This is not precisely the same as returning a factor that always returns "I give up". The latter case would limit the file to float32 type and might turn off alignments in the file.
If the compressor needs mutable state, e.g. to accumulate perfromance measurements, it can be declared as an instance method allowing the lambda to capture "this". The class would normally be noncopyable. The returned lambda can be copied at will; the copies will share the same state. Remember to use locks to protect the shared state in "this".
Another option for mutable state is to have this function allocate some kind of "state" instance and capture it in the lambda. How to access that state later, e.g. to extract any timing measurements, is left as an exercise ;-).
1.8.17