Skip to content

Commit

Permalink
MSVS 2015 compat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MartinPulec committed Mar 24, 2023
1 parent 0da2a3a commit 3ea2798
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gpujpeg_common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/gpujpeg_huffman_cpu_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
2 changes: 2 additions & 0 deletions src/gpujpeg_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/gpujpeg_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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");
Expand All @@ -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 ) {
Expand Down

0 comments on commit 3ea2798

Please sign in to comment.