Skip to content

Commit

Permalink
moved compat to one place
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Mar 27, 2023
1 parent 3ea2798 commit 7388c8a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/gpujpeg_common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@
#include <cuda_runtime.h>
#include <math.h> // NAN
#include <stdio.h>
#include <stdlib.h>
#include "gpujpeg_util.h"
#include "libgpujpeg/gpujpeg_common.h"
#include "libgpujpeg/gpujpeg_type.h"

// VS 2015 compat
#if defined _MSC_VER && _MSC_VER <= 1900
#define __func__ ""
#define _Static_assert(cond, msg)
#endif // VS <=2015

/** Contants */
#define GPUJPEG_BLOCK_SIZE 8
#define GPUJPEG_BLOCK_SQUARED_SIZE 64
Expand All @@ -50,11 +57,7 @@
/** 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: 0 additions & 2 deletions src/gpujpeg_huffman_cpu_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,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_
#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: 0 additions & 2 deletions src/gpujpeg_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,7 @@ 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
5 changes: 1 addition & 4 deletions src/gpujpeg_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "gpujpeg_common_internal.h"
#include "gpujpeg_table.h"
#include "gpujpeg_util.h"

Expand Down Expand Up @@ -308,7 +309,6 @@ 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 @@ -317,7 +317,6 @@ 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 @@ -347,7 +346,6 @@ 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 @@ -356,7 +354,6 @@ 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 7388c8a

Please sign in to comment.