Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / third_party / om-file-format-sys / c / include / om_encoder.h
om_encoder.h63 lines · 2.4 KiBRaw
| 1 | /** |
| 2 | * @file om_encoder.h |
| 3 | * @brief OmFileEncoder: Write compressed chunks arrays to an OM file |
| 4 | * |
| 5 | * Created by Patrick Zippenfenig on 29.10.2024. |
| 6 | */ |
| 7 | |
| 8 | #ifndef OM_ENCODER_H |
| 9 | #define OM_ENCODER_H |
| 10 | |
| 11 | #include "om_common.h" |
| 12 | |
| 13 | |
| 14 | // Encoder struct |
| 15 | typedef struct { |
| 16 | const uint64_t *dimensions; |
| 17 | const uint64_t *chunks; |
| 18 | uint64_t dimension_count; |
| 19 | |
| 20 | float scale_factor; |
| 21 | |
| 22 | /// An offset to convert floats to integers while scaling |
| 23 | float add_offset; |
| 24 | |
| 25 | /// The data type of the data |
| 26 | uint8_t data_type; |
| 27 | |
| 28 | /// The compression type of the data |
| 29 | uint8_t compression; |
| 30 | |
| 31 | /// The size of the elements in bytes |
| 32 | uint8_t bytes_per_element; |
| 33 | |
| 34 | /// The size of the elements in bytes after compression, e.g. Int16 could be used to scale floats |
| 35 | uint8_t bytes_per_element_compressed; |
| 36 | } OmEncoder_t; |
| 37 | |
| 38 | /// Initialise the OmEncoder structure with information about the shape of data |
| 39 | /// May return an error on invalid compression or data types |
| 40 | OmError_t om_encoder_init(OmEncoder_t* encoder, float scale_factor, float add_offset, OmCompression_t compression, OmDataType_t data_type, const uint64_t* dimensions, const uint64_t* chunks, uint64_t dimension_count); |
| 41 | |
| 42 | /// Get the number of chunks that is calculated from dimensions and chunks |
| 43 | uint64_t om_encoder_count_chunks(const OmEncoder_t* encoder); |
| 44 | |
| 45 | /// Calculate how many chunks can be filled from a given input |
| 46 | uint64_t om_encoder_count_chunks_in_array(const OmEncoder_t* encoder, const uint64_t* array_count); |
| 47 | |
| 48 | /// The buffer size required to collect a single chunk of data |
| 49 | uint64_t om_encoder_chunk_buffer_size(const OmEncoder_t* encoder); |
| 50 | |
| 51 | /// The buffer size required to compress a single chunk. |
| 52 | uint64_t om_encoder_compressed_chunk_buffer_size(const OmEncoder_t* encoder); |
| 53 | |
| 54 | /// Calculate the required buffer size for the entire compressed LUT |
| 55 | uint64_t om_encoder_lut_buffer_size(const uint64_t* lookUpTable, uint64_t lookUpTableCount); |
| 56 | |
| 57 | /// Compress the LUT and return the size of compressed LUT in bytes |
| 58 | uint64_t om_encoder_compress_lut(const uint64_t* lookUpTable, uint64_t lookUpTableCount, uint8_t* out, uint64_t size_of_compressed_lut); |
| 59 | |
| 60 | /// Compress a single chunk. Chunk buffer must be of size `OmEncoder_chunkBufferSize` |
| 61 | uint64_t om_encoder_compress_chunk(const OmEncoder_t* encoder, const void* array, const uint64_t* arrayDimensions, const uint64_t* arrayOffset, const uint64_t* arrayCount, uint64_t chunkIndex, uint64_t chunkIndexOffsetInThisArray, uint8_t* out, uint8_t* chunkBuffer); |
| 62 | |
| 63 | #endif // OM_ENCODER_H |