Skip to content

Commit

Permalink
Add some restrict qualifiers, 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaaaa123456789 committed May 9, 2022
1 parent d491e4c commit bbb8a6a
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 56 deletions.
10 changes: 5 additions & 5 deletions src/jpegarithmetic.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "proto.h"

void decompress_JPEG_arithmetic_scan (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_decoder_tables * tables,
size_t rowunits, const struct JPEG_component_info * components, const size_t * offsets, unsigned shift, unsigned char first,
unsigned char last, bool differential) {
size_t rowunits, const struct JPEG_component_info * components, const size_t * restrict offsets, unsigned shift,
unsigned char first, unsigned char last, bool differential) {
for (size_t restart_interval = 0; restart_interval <= state -> restart_count; restart_interval ++) {
size_t units = (restart_interval == state -> restart_count) ? state -> last_size : state -> restart_size;
if (!units) break;
Expand Down Expand Up @@ -80,7 +80,7 @@ void decompress_JPEG_arithmetic_scan (struct context * context, struct JPEG_deco
}

void decompress_JPEG_arithmetic_bit_scan (struct context * context, struct JPEG_decompressor_state * restrict state, size_t rowunits,
const struct JPEG_component_info * components, const size_t * offsets, unsigned shift, unsigned char first,
const struct JPEG_component_info * components, const size_t * restrict offsets, unsigned shift, unsigned char first,
unsigned char last) {
// this function is very similar to decompress_JPEG_arithmetic_scan, but it only decodes the next bit for already-initialized data
if (last && !first) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
Expand Down Expand Up @@ -148,8 +148,8 @@ void decompress_JPEG_arithmetic_bit_scan (struct context * context, struct JPEG_
}

void decompress_JPEG_arithmetic_lossless_scan (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_decoder_tables * tables,
size_t rowunits, const struct JPEG_component_info * components, const size_t * offsets, unsigned char predictor,
unsigned precision) {
size_t rowunits, const struct JPEG_component_info * components, const size_t * restrict offsets,
unsigned char predictor, unsigned precision) {
bool scancomponents[4] = {0};
for (uint_fast8_t p = 0; state -> MCU[p] != MCU_END_LIST; p ++) if (state -> MCU[p] < 4) scancomponents[state -> MCU[p]] = true;
uint16_t * rowdifferences[4] = {0};
Expand Down
6 changes: 3 additions & 3 deletions src/jpegdecompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void initialize_JPEG_decompressor_state (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_component_info * components,
const unsigned char * componentIDs, size_t * restrict unitsH, size_t unitsV, size_t width, size_t height,
unsigned char maxH, unsigned char maxV, const struct JPEG_decoder_tables * tables, const size_t * offsets,
unsigned char maxH, unsigned char maxV, const struct JPEG_decoder_tables * tables, const size_t * restrict offsets,
int16_t (* restrict * output)[64]) {
initialize_JPEG_decompressor_state_common(context, state, components, componentIDs, unitsH, unitsV, width, height, maxH, maxV, tables, offsets, 8);
for (uint_fast8_t p = 0; p < 4; p ++) state -> current_block[p] = NULL;
Expand All @@ -12,7 +12,7 @@ void initialize_JPEG_decompressor_state (struct context * context, struct JPEG_d
void initialize_JPEG_decompressor_state_lossless (struct context * context, struct JPEG_decompressor_state * restrict state,
const struct JPEG_component_info * components, const unsigned char * componentIDs, size_t * restrict unitsH,
size_t unitsV, size_t width, size_t height, unsigned char maxH, unsigned char maxV,
const struct JPEG_decoder_tables * tables, const size_t * offsets, uint16_t * restrict * output) {
const struct JPEG_decoder_tables * tables, const size_t * restrict offsets, uint16_t * restrict * output) {
initialize_JPEG_decompressor_state_common(context, state, components, componentIDs, unitsH, unitsV, width, height, maxH, maxV, tables, offsets, 1);
for (uint_fast8_t p = 0; p < 4; p ++) state -> current_value[p] = NULL;
for (uint_fast8_t p = 0; p < state -> component_count; p ++) state -> current_value[componentIDs[p]] = output[componentIDs[p]];
Expand All @@ -21,7 +21,7 @@ void initialize_JPEG_decompressor_state_lossless (struct context * context, stru
void initialize_JPEG_decompressor_state_common (struct context * context, struct JPEG_decompressor_state * restrict state,
const struct JPEG_component_info * components, const unsigned char * componentIDs, size_t * restrict unitsH,
size_t unitsV, size_t width, size_t height, unsigned char maxH, unsigned char maxV,
const struct JPEG_decoder_tables * tables, const size_t * offsets, unsigned char unit_dimensions) {
const struct JPEG_decoder_tables * tables, const size_t * restrict offsets, unsigned char unit_dimensions) {
if (componentIDs[1] != 0xff) {
unsigned char * entry = state -> MCU;
uint_fast8_t component;
Expand Down
14 changes: 7 additions & 7 deletions src/jpeghuffman.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "proto.h"

void decompress_JPEG_Huffman_scan (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_decoder_tables * tables,
size_t rowunits, const struct JPEG_component_info * components, const size_t * offsets, unsigned shift, unsigned char first,
unsigned char last, bool differential) {
size_t rowunits, const struct JPEG_component_info * components, const size_t * restrict offsets, unsigned shift,
unsigned char first, unsigned char last, bool differential) {
for (size_t restart_interval = 0; restart_interval <= state -> restart_count; restart_interval ++) {
size_t units = (restart_interval == state -> restart_count) ? state -> last_size : state -> restart_size;
if (!units) break;
Expand Down Expand Up @@ -73,8 +73,8 @@ void decompress_JPEG_Huffman_scan (struct context * context, struct JPEG_decompr
}

void decompress_JPEG_Huffman_bit_scan (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_decoder_tables * tables,
size_t rowunits, const struct JPEG_component_info * components, const size_t * offsets, unsigned shift, unsigned char first,
unsigned char last) {
size_t rowunits, const struct JPEG_component_info * components, const size_t * restrict offsets, unsigned shift,
unsigned char first, unsigned char last) {
// this function is essentially the same as decompress_JPEG_Huffman_scan, but it uses already-initialized component data, and it decodes one bit at a time
if (last && !first) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
for (size_t restart_interval = 0; restart_interval <= state -> restart_count; restart_interval ++) {
Expand Down Expand Up @@ -148,8 +148,8 @@ void decompress_JPEG_Huffman_bit_scan (struct context * context, struct JPEG_dec
}

void decompress_JPEG_Huffman_lossless_scan (struct context * context, struct JPEG_decompressor_state * restrict state, const struct JPEG_decoder_tables * tables,
size_t rowunits, const struct JPEG_component_info * components, const size_t * offsets, unsigned char predictor,
unsigned precision) {
size_t rowunits, const struct JPEG_component_info * components, const size_t * restrict offsets,
unsigned char predictor, unsigned precision) {
for (size_t restart_interval = 0; restart_interval <= state -> restart_count; restart_interval ++) {
size_t units = (restart_interval == state -> restart_count) ? state -> last_size : state -> restart_size;
if (!units) break;
Expand Down Expand Up @@ -211,7 +211,7 @@ void decompress_JPEG_Huffman_lossless_scan (struct context * context, struct JPE
}

unsigned char next_JPEG_Huffman_value (struct context * context, const unsigned char ** data, size_t * restrict count, uint32_t * restrict dataword,
uint8_t * restrict bits, const short * table) {
uint8_t * restrict bits, const short * restrict table) {
unsigned short index = 0;
while (true) {
index += shift_in_right_JPEG(context, 1, dataword, bits, data, count);
Expand Down
2 changes: 1 addition & 1 deletion src/jpegread.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ unsigned load_single_frame_JPEG (struct context * context, const struct JPEG_mar
}

unsigned char process_JPEG_metadata_until_offset (struct context * context, const struct JPEG_marker_layout * layout, struct JPEG_decoder_tables * tables,
size_t * index, size_t limit) {
size_t * restrict index, size_t limit) {
unsigned char expansion = 0;
for (; layout -> markers[*index] && layout -> markers[*index] < limit; ++ *index) {
const unsigned char * markerdata = context -> data + layout -> markers[*index];
Expand Down
6 changes: 4 additions & 2 deletions src/jpegreadframe.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "proto.h"

void load_JPEG_DCT_frame (struct context * context, const struct JPEG_marker_layout * layout, uint32_t components, size_t frameindex,
struct JPEG_decoder_tables * tables, size_t * metadata_index, double ** output, unsigned precision, size_t width, size_t height) {
struct JPEG_decoder_tables * tables, size_t * restrict metadata_index, double ** output, unsigned precision, size_t width,
size_t height) {
const size_t * scans = layout -> framescans[frameindex];
const size_t ** offsets = (const size_t **) layout -> framedata[frameindex];
// obtain this frame's components' parameters and compute the number of (non-subsampled) blocks per MCU (maximum scale factor for each dimension)
Expand Down Expand Up @@ -87,7 +88,8 @@ void load_JPEG_DCT_frame (struct context * context, const struct JPEG_marker_lay
}

void load_JPEG_lossless_frame (struct context * context, const struct JPEG_marker_layout * layout, uint32_t components, size_t frameindex,
struct JPEG_decoder_tables * tables, size_t * metadata_index, double ** output, unsigned precision, size_t width, size_t height) {
struct JPEG_decoder_tables * tables, size_t * restrict metadata_index, double ** output, unsigned precision, size_t width,
size_t height) {
const size_t * scans = layout -> framescans[frameindex];
const size_t ** offsets = (const size_t **) layout -> framedata[frameindex];
// obtain this frame's components' parameters and compute the number of pixels per MCU (maximum scale factor for each dimension)
Expand Down
2 changes: 1 addition & 1 deletion src/jpegtables.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ short * process_JPEG_Huffman_table (struct context * context, const unsigned cha
return ctxrealloc(context, result, next * sizeof *result);
}

void load_default_JPEG_Huffman_tables (struct context * context, struct JPEG_decoder_tables * tables) {
void load_default_JPEG_Huffman_tables (struct context * context, struct JPEG_decoder_tables * restrict tables) {
/* default tables from the JPEG specification, already preprocessed into a tree, in the same format as other trees:
two values per node, non-negative values are leaves, negative values are array indexes where the next node is
found (always even, because each node takes up two entries), -1 is an empty branch; index 0 is the root node */
Expand Down
8 changes: 4 additions & 4 deletions src/multibyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ static inline uint32_t read_be32_unaligned (const unsigned char * data) {
return (uint32_t) data[3] | ((uint32_t) data[2] << 8) | ((uint32_t) data[1] << 16) | ((uint32_t) *data << 24);
}

static inline void write_le16_unaligned (unsigned char * buffer, uint16_t value) {
static inline void write_le16_unaligned (unsigned char * restrict buffer, uint16_t value) {
bytewrite(buffer, value, value >> 8);
}

static inline void write_le32_unaligned (unsigned char * buffer, uint32_t value) {
static inline void write_le32_unaligned (unsigned char * restrict buffer, uint32_t value) {
bytewrite(buffer, value, value >> 8, value >> 16, value >> 24);
}

static inline void write_be16_unaligned (unsigned char * buffer, uint32_t value) {
static inline void write_be16_unaligned (unsigned char * restrict buffer, uint32_t value) {
bytewrite(buffer, value >> 8, value);
}

static inline void write_be32_unaligned (unsigned char * buffer, uint32_t value) {
static inline void write_be32_unaligned (unsigned char * restrict buffer, uint32_t value) {
bytewrite(buffer, value >> 24, value >> 16, value >> 8, value);
}
3 changes: 2 additions & 1 deletion src/pngcompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ size_t compute_uncompressed_PNG_block_size (const unsigned char * restrict data,
return current_offset - offset;
}

unsigned find_PNG_reference (const unsigned char * data, const uint16_t * references, size_t current_offset, size_t size, size_t * restrict reference_offset) {
unsigned find_PNG_reference (const unsigned char * restrict data, const uint16_t * restrict references, size_t current_offset, size_t size,
size_t * restrict reference_offset) {
uint_fast32_t search = compute_PNG_reference_key(data + current_offset) * (uint_fast32_t) PNG_MAX_LOOKBACK_COUNT;
unsigned best = 0;
for (uint_fast8_t p = 0; p < PNG_MAX_LOOKBACK_COUNT && references[search + p] != 0xffffu; p ++) {
Expand Down
2 changes: 1 addition & 1 deletion src/pngdecompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ short * decode_PNG_Huffman_tree (struct context * context, const unsigned char *
return ctxrealloc(context, result, last * sizeof *result);
}

uint16_t next_PNG_Huffman_code (struct context * context, const short * tree, const unsigned char ** compressed, size_t * restrict size,
uint16_t next_PNG_Huffman_code (struct context * context, const short * restrict tree, const unsigned char ** compressed, size_t * restrict size,
uint32_t * restrict dataword, uint8_t * restrict bits) {
short index = 0;
while (true) {
Expand Down
8 changes: 4 additions & 4 deletions src/pngread.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ struct PNG_chunk_locations * load_PNG_chunk_locations (struct context * context)
return result;
}

void append_PNG_chunk_location (struct context * context, size_t ** locations, size_t location, size_t * count) {
void append_PNG_chunk_location (struct context * context, size_t ** locations, size_t location, size_t * restrict count) {
*locations = ctxrealloc(context, *locations, sizeof **locations * (*count + 1));
(*locations)[(*count) ++] = location;
}

void sort_PNG_animation_chunks (struct context * context, struct PNG_chunk_locations * locations, const size_t * framedata, size_t frameinfo_count,
size_t framedata_count) {
void sort_PNG_animation_chunks (struct context * context, struct PNG_chunk_locations * restrict locations, const size_t * restrict framedata,
size_t frameinfo_count, size_t framedata_count) {
if ((frameinfo_count + framedata_count) > 0x80000000u) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
if (!frameinfo_count || (frameinfo_count > 1 && !framedata_count)) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
uint64_t * indexes = ctxmalloc(context, sizeof *indexes * (frameinfo_count + framedata_count));
Expand Down Expand Up @@ -257,7 +257,7 @@ void sort_PNG_animation_chunks (struct context * context, struct PNG_chunk_locat
ctxfree(context, indexes);
}

uint8_t load_PNG_palette (struct context * context, const struct PNG_chunk_locations * chunks, uint8_t bitdepth, uint64_t * restrict palette) {
uint8_t load_PNG_palette (struct context * context, const struct PNG_chunk_locations * restrict chunks, uint8_t bitdepth, uint64_t * restrict palette) {
if (!chunks -> palette) throw(context, PLUM_ERR_UNDEFINED_PALETTE);
uint_fast32_t count = read_be32_unaligned(context -> data + chunks -> palette - 8) / 3;
if (count > (1 << bitdepth)) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
Expand Down
2 changes: 1 addition & 1 deletion src/pnmread.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void add_PNM_bit_depth_metadata (struct context * context, const struct PNM_imag
add_color_depth_metadata(context, 0, 0, 0, alphadepth, colordepth);
}

void load_PNM_frame (struct context * context, const struct PNM_image_header * header, uint64_t * restrict buffer) {
void load_PNM_frame (struct context * context, const struct PNM_image_header * restrict header, uint64_t * restrict buffer) {
size_t offset = header -> datastart, imagewidth = context -> image -> width, imageheight = context -> image -> height;
if (header -> width < imagewidth)
for (uint_fast32_t row = 0; row < header -> height; row ++)
Expand Down
4 changes: 2 additions & 2 deletions src/pnmwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ uint32_t * get_true_PNM_frame_sizes (struct context * context) {
return NULL;
}

void generate_PPM_data (struct context * context, const uint32_t * sizes, unsigned bitdepth, uint64_t * restrict buffer) {
void generate_PPM_data (struct context * context, const uint32_t * restrict sizes, unsigned bitdepth, uint64_t * restrict buffer) {
size_t offset = (size_t) context -> source -> width * context -> source -> height;
if (!context -> source -> palette) offset = plum_color_buffer_size(offset, context -> source -> color_format);
for (size_t frame = 0; frame < context -> source -> frames; frame ++) {
Expand Down Expand Up @@ -163,7 +163,7 @@ void generate_PAM_header (struct context * context, unsigned bitdepth) {
context -> output -> size = offset;
}

size_t write_PNM_number (unsigned char * buffer, uint32_t number) {
size_t write_PNM_number (unsigned char * restrict buffer, uint32_t number) {
// won't work for 0, but there's no need to write a 0 anywhere
unsigned char data[10];
uint_fast8_t size = 0;
Expand Down
Loading

0 comments on commit bbb8a6a

Please sign in to comment.