diff --git a/examples/example_compress_chunk.c b/examples/example_compress_chunk.c index 3291de47590f02c7632d9357583011dad50e3171..4dac0d85186eb68c8769ef9e23502d8dac5f44c3 100644 --- a/examples/example_compress_chunk.c +++ b/examples/example_compress_chunk.c @@ -60,7 +60,7 @@ static int demo_comperss_chunk_1d(void) struct offset offset_data[2] = {{1, 2}, {3, 4}}; enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data) + sizeof(offset_data) }; - uint32_t chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ + uint8_t chunk[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */ uint32_t *compressed_data; int cmp_size_bytes; @@ -74,7 +74,7 @@ static int demo_comperss_chunk_1d(void) return -1; memcpy(col->entry, background_data, sizeof(background_data)); - col = (struct collection_hdr *)((uint8_t *)chunk + cmp_col_get_size(col)); + col = (struct collection_hdr *)(chunk + cmp_col_get_size(col)); if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) return -1; if (cmp_col_set_data_length(col, sizeof(offset_data))) @@ -166,16 +166,16 @@ static int demo_comperss_chunk_model(void) struct offset offset_data[2] = {{1, 32}, {23, 42}}; enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data) + sizeof(offset_data) }; - uint32_t chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ - uint32_t model_chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ - uint32_t updated_chunk_model[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ + uint8_t chunk[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */ + uint8_t model_chunk[(CHUNK_SIZE)] = {0}; /* Do not put large amount of data on the stack! */ + uint8_t updated_chunk_model[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */ /* * Here we use the COMPRESS_CHUNK_BOUND macro to determine the worst * case compression size; to do this we need to know the chunk_size and * the number of collections in the chunk (2 in this demo) */ - uint32_t compressed_data[COMPRESS_CHUNK_BOUND(CHUNK_SIZE, 2)]; /* Do not put large amount of data on the stack! */ + uint32_t compressed_data[COMPRESS_CHUNK_BOUND(CHUNK_SIZE, 2)/4]; /* Do not put large amount of data on the stack! */ int cmp_size_bytes; { /* build a chunk of a background and an offset collection */ @@ -187,7 +187,7 @@ static int demo_comperss_chunk_model(void) return -1; memcpy(col->entry, background_data, sizeof(background_data)); - col = (struct collection_hdr *)((uint8_t *)chunk + cmp_col_get_size(col)); + col = (struct collection_hdr *)(chunk + cmp_col_get_size(col)); if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) return -1; if (cmp_col_set_data_length(col, sizeof(offset_data))) @@ -203,7 +203,7 @@ static int demo_comperss_chunk_model(void) return -1; memcpy(col->entry, background_model, sizeof(background_model)); - col = (struct collection_hdr *)((uint8_t *)model_chunk + cmp_col_get_size(col)); + col = (struct collection_hdr *)(model_chunk + cmp_col_get_size(col)); if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) return -1; if (cmp_col_set_data_length(col, sizeof(offset_model))) @@ -269,7 +269,7 @@ int main(void) int error = 0; error |= demo_comperss_chunk_1d(); - /* error |= demo_comperss_chunk_model(); */ + error |= demo_comperss_chunk_model(); if (error) return EXIT_FAILURE; diff --git a/lib/cmp_chunk.h b/lib/cmp_chunk.h index a71200016020b962ab2d61d730f47e5e9df97f2b..c74171601de92df17a308bf6a3147d3479ef8089 100644 --- a/lib/cmp_chunk.h +++ b/lib/cmp_chunk.h @@ -109,9 +109,10 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id); * small to hold the whole compressed data */ -int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, - uint32_t *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, - const struct cmp_par *cmp_par); +int32_t compress_chunk(void *chunk, uint32_t chunk_size, + void *chunk_model, void *updated_chunk_model, + uint32_t *dst, uint32_t dst_capacity, + const struct cmp_par *cmp_par); /** * @brief set the model id and model counter in the compression entity header diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c index 56d6831572567ee7e686398ade2198cb8c705dba..e75ccfadd62ed6ef5284e9f248b1d5f84a885ef4 100644 --- a/lib/icu_compress/cmp_icu.c +++ b/lib/icu_compress/cmp_icu.c @@ -2314,10 +2314,11 @@ static int set_cmp_col_size(uint8_t *p, int cmp_col_size) /* TODO: doc string */ -static int cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, uint32_t *dst, - uint32_t dst_capacity, struct cmp_cfg *cfg, int dst_size) +static int32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, + uint32_t *dst, uint32_t dst_capacity, + struct cmp_cfg *cfg, int32_t dst_size) { - int dst_size_begin = dst_size; + int32_t dst_size_begin = dst_size; int dst_size_bits; if (dst_size < 0) @@ -2387,7 +2388,7 @@ static int cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, return dst_size_bits; } - dst_size = (int)cmp_bit_to_byte((unsigned int)dst_size_bits); /*TODO: fix casts */ + dst_size = (int32_t)cmp_bit_to_byte((unsigned int)dst_size_bits); /*TODO: fix casts */ if (dst && cfg->cmp_mode != CMP_MODE_RAW) if (set_cmp_col_size((uint8_t *)dst+dst_size_begin, dst_size-dst_size_begin)) return -1; @@ -2618,14 +2619,15 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id) * small to hold the whole compressed data */ -int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, - uint32_t *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, - const struct cmp_par *cmp_par) +int32_t compress_chunk(void *chunk, uint32_t chunk_size, + void *chunk_model, void *updated_chunk_model, + uint32_t *dst, uint32_t dst_capacity, + const struct cmp_par *cmp_par) { uint64_t start_timestamp = get_timestamp(); size_t read_bytes; struct collection_hdr *col = (struct collection_hdr *)chunk; - int cmp_size_byte; /* size of the compressed data in bytes */ + int32_t cmp_size_byte; /* size of the compressed data in bytes */ enum chunk_type chunk_type; struct cmp_cfg cfg; int err; @@ -2649,11 +2651,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, else cmp_size_byte = NON_IMAGETTE_HEADER_SIZE; if (dst) { - if (dst_capacity < (size_t)cmp_size_byte) { + if (dst_capacity < (uint32_t)cmp_size_byte) { debug_print("Error: The destination capacity is smaller than the minimum compression entity size.\n"); return CMP_ERROR_SMALL_BUF; } - memset(dst, 0, (size_t)cmp_size_byte); + memset(dst, 0, (uint32_t)cmp_size_byte); } chunk_type = cmp_col_get_chunk_type(col); @@ -2666,11 +2668,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, uint8_t *col_model = NULL; uint8_t *col_up_model = NULL; /* setup pointers for the next collection we want to compress */ - col = (struct collection_hdr *)((uint8_t *)chunk + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED? */ + col = (struct collection_hdr *)((uint8_t *)chunk + read_bytes); if (chunk_model) - col_model = ((uint8_t *)chunk_model + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED?*/ + col_model = ((uint8_t *)chunk_model + read_bytes); if (updated_chunk_model) - col_up_model = ((uint8_t *)updated_chunk_model + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED?*/ + col_up_model = ((uint8_t *)updated_chunk_model + read_bytes); if (cmp_col_get_chunk_type(col) != chunk_type) { debug_print("Error: The chunk contains collections with an incompatible mix of subservices.\n");