diff --git a/.clang-format b/.clang-format index 65b396c..27bdbae 100644 --- a/.clang-format +++ b/.clang-format @@ -9,6 +9,7 @@ BraceWrapping: ColumnLimit: 120 IndentWidth: 4 PointerAlignment: Left +IndentPPDirectives: BeforeHash ReflowComments: true SpacesInParens: Custom SpacesInParensOptions: diff --git a/src/gpujpeg_common_internal.h b/src/gpujpeg_common_internal.h index d16794c..e636cb7 100644 --- a/src/gpujpeg_common_internal.h +++ b/src/gpujpeg_common_internal.h @@ -43,10 +43,20 @@ #include "../libgpujpeg/gpujpeg_type.h" #include "gpujpeg_util.h" +// static_assert compat +#if __STDC_VERSION__ < 202311L + #include // static_assert compat macro in C11-C17 +#elif __STDC_VERSION__ < 201112L + #if defined _MSC_VER && _MSC_VER <= 1900 + #define static_assert(cond, msg) + #else + #error "compiler is not supporting C11 - perhaps an error?" + #endif +#endif + // VS 2015 compat #if defined _MSC_VER && _MSC_VER <= 1900 #define __func__ "" -#define _Static_assert(cond, msg) #endif // VS <=2015 /** Contants */ diff --git a/src/gpujpeg_huffman_cpu_decoder.c b/src/gpujpeg_huffman_cpu_decoder.c index 4a7f3c3..3e9c8a2 100644 --- a/src/gpujpeg_huffman_cpu_decoder.c +++ b/src/gpujpeg_huffman_cpu_decoder.c @@ -187,7 +187,7 @@ gpujpeg_huffman_cpu_decoder_value_from_category(int category, int offset) #pragma GCC diagnostic ignored "-Wshift-negative-value" #pragma GCC diagnostic ignored "-Wpedantic" #endif // defined __GNUC_ - _Static_assert((-1)<<1 == -2, "Implementation defined behavior doesn't work as assumed."); + static_assert((-1)<<1 == -2, "Implementation defined behavior doesn't work as assumed."); //start[i] is the starting value in this category; surely it is below zero // entry n is (-1 << n) + 1 static const int start[16] = { diff --git a/src/gpujpeg_reader.c b/src/gpujpeg_reader.c index 28ff046..797e0b3 100644 --- a/src/gpujpeg_reader.c +++ b/src/gpujpeg_reader.c @@ -695,7 +695,7 @@ static const char *array_serialize(int comp_count, const uint8_t *comp_id) { * checks component ID to determine if JPEG is in YCbCr (component IDs 1, 2, 3) or RGB (component IDs 'R', 'G', 'B') */ static enum gpujpeg_color_space gpujpeg_reader_process_cid(int comp_count, uint8_t *comp_id, enum gpujpeg_color_space header_color_space) { - _Static_assert(GPUJPEG_MAX_COMPONENT_COUNT >= 3, "An array of at least 3 components expected"); + static_assert(GPUJPEG_MAX_COMPONENT_COUNT >= 3, "An array of at least 3 components expected"); static const uint8_t ycbcr_ids[] = { 1, 2, 3 }; static const uint8_t rgb_ids[] = { 'R', 'G', 'B' }; static const uint8_t bg_rgb_ids[] = { 'r', 'g', 'b' }; // big gamut sRGB (see ILG libjpeg - seemingly handled as above) @@ -1468,7 +1468,7 @@ adjust_pixel_format(struct gpujpeg_parameters * param, struct gpujpeg_image_para static void adjust_format(struct gpujpeg_parameters* param, struct gpujpeg_image_parameters* param_image) { - _Static_assert(GPUJPEG_PIXFMT_AUTODETECT < 0, "enum gpujpeg_pixel_format type should be signed"); + static_assert(GPUJPEG_PIXFMT_AUTODETECT < 0, "enum gpujpeg_pixel_format type should be signed"); if ( param_image->color_space == GPUJPEG_CS_DEFAULT ) { if ( param_image->pixel_format == GPUJPEG_U8 || (param_image->pixel_format <= GPUJPEG_PIXFMT_AUTODETECT && param->comp_count == 1) ) { diff --git a/src/gpujpeg_table.c b/src/gpujpeg_table.c index 8ec05d5..4418cf3 100644 --- a/src/gpujpeg_table.c +++ b/src/gpujpeg_table.c @@ -311,14 +311,14 @@ gpujpeg_table_huffman_encoder_init(struct gpujpeg_table_huffman_encoder* table, { assert(comp_type == GPUJPEG_COMPONENT_LUMINANCE || comp_type == GPUJPEG_COMPONENT_CHROMINANCE); assert(huff_type == GPUJPEG_HUFFMAN_DC || huff_type == GPUJPEG_HUFFMAN_AC); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_dc_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_dc_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_ac_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_ac_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_dc_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_dc_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_ac_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_ac_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_dc_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_dc_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_ac_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_ac_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_dc_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_dc_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_ac_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_ac_value), "table buffer too small"); if ( comp_type == GPUJPEG_COMPONENT_LUMINANCE ) { if ( huff_type == GPUJPEG_HUFFMAN_DC ) { @@ -348,14 +348,14 @@ gpujpeg_table_huffman_decoder_init(struct gpujpeg_table_huffman_decoder* table, { assert(comp_type == GPUJPEG_COMPONENT_LUMINANCE || comp_type == GPUJPEG_COMPONENT_CHROMINANCE); assert(huff_type == GPUJPEG_HUFFMAN_DC || huff_type == GPUJPEG_HUFFMAN_AC); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_dc_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_dc_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_ac_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_ac_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_dc_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_dc_value), "table buffer too small"); - _Static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_ac_bits), "table buffer too small"); - _Static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_ac_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_dc_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_dc_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_y_ac_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_y_ac_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_dc_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_dc_value), "table buffer too small"); + static_assert(sizeof(table->bits) >= sizeof(gpujpeg_table_huffman_cbcr_ac_bits), "table buffer too small"); + static_assert(sizeof(table->huffval) >= sizeof(gpujpeg_table_huffman_cbcr_ac_value), "table buffer too small"); if ( comp_type == GPUJPEG_COMPONENT_LUMINANCE ) { if ( huff_type == GPUJPEG_HUFFMAN_DC ) {