From 3ea2798fd19d428c5e5efb4054e1b3eb331b31d2 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 24 Mar 2023 15:18:56 +0100 Subject: [PATCH] MSVS 2015 compat The incompatibilities are quite minor so it may pay off to ifdef the problematic places. MSVS 2015 compatibility is needed to be compatible with CUDA 8.0 which is the last supported version for CUDA cc 2.x. --- src/gpujpeg_common_internal.h | 4 ++++ src/gpujpeg_huffman_cpu_decoder.c | 2 ++ src/gpujpeg_reader.c | 2 ++ src/gpujpeg_table.c | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/src/gpujpeg_common_internal.h b/src/gpujpeg_common_internal.h index 573b76a6..042211da 100644 --- a/src/gpujpeg_common_internal.h +++ b/src/gpujpeg_common_internal.h @@ -50,7 +50,11 @@ /** Maximum JPEG header size (MUST be divisible by 4!!!) */ #define GPUJPEG_MAX_HEADER_SIZE (65536 - 100) +#if defined _MSC_VER && _MSC_VER <= 1900 // VS 2015 +#define GPUJPEG_ASSERT(cond) do { if (!(cond)) { fprintf(stderr, "%s:%d: Assertion `" #cond "' failed.\n", __FILE__, __LINE__); abort(); } } while(0) +#else #define GPUJPEG_ASSERT(cond) do { if (!(cond)) { fprintf(stderr, "%s:%d: %s: Assertion `" #cond "' failed.\n", __FILE__, __LINE__, __func__); abort(); } } while(0) +#endif #define ERROR_MSG(...) do { fprintf(stderr, "[GPUJPEG] [Error] " __VA_ARGS__); } while(0) #define VERBOSE_MSG(log_level, ...) do { if (log_level >= 1) fprintf(stderr, "[GPUJPEG] [Warning] " __VA_ARGS__); } while(0) diff --git a/src/gpujpeg_huffman_cpu_decoder.c b/src/gpujpeg_huffman_cpu_decoder.c index 540db96f..e68cfd00 100644 --- a/src/gpujpeg_huffman_cpu_decoder.c +++ b/src/gpujpeg_huffman_cpu_decoder.c @@ -181,7 +181,9 @@ 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_ +#if ! defined _MSC_VER || _MSC_VER > 1900 // VS 2015 _Static_assert((-1)<<1 == -2, "Implementation defined behavior doesn't work as assumed."); +#endif // ! VS <=2015 //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 6543f50c..bcdad707 100644 --- a/src/gpujpeg_reader.c +++ b/src/gpujpeg_reader.c @@ -700,7 +700,9 @@ static const char *array_serialize(int comp_count, const uint8_t *comp_id) { } static enum gpujpeg_color_space gpujpeg_reader_process_cid(int comp_count, uint8_t *comp_id, enum gpujpeg_color_space header_color_space) { +#if ! defined _MSC_VER || _MSC_VER > 1900 // VS 2015 _Static_assert(GPUJPEG_MAX_COMPONENT_COUNT >= 3, "An array of at least 3 components expected"); +#endif // ! VS <=2015 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) diff --git a/src/gpujpeg_table.c b/src/gpujpeg_table.c index c633b857..87115d1d 100644 --- a/src/gpujpeg_table.c +++ b/src/gpujpeg_table.c @@ -308,6 +308,7 @@ 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); +#if ! defined _MSC_VER || _MSC_VER > 1900 // VS 2015 _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"); @@ -316,6 +317,7 @@ gpujpeg_table_huffman_encoder_init(struct gpujpeg_table_huffman_encoder* table, _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"); +#endif // ! VS <=2015 if ( comp_type == GPUJPEG_COMPONENT_LUMINANCE ) { if ( huff_type == GPUJPEG_HUFFMAN_DC ) { @@ -345,6 +347,7 @@ 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); +#if ! defined _MSC_VER || _MSC_VER > 1900 // VS 2015 _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"); @@ -353,6 +356,7 @@ gpujpeg_table_huffman_decoder_init(struct gpujpeg_table_huffman_decoder* table, _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"); +#endif // ! VS <=2015 if ( comp_type == GPUJPEG_COMPONENT_LUMINANCE ) { if ( huff_type == GPUJPEG_HUFFMAN_DC ) {