From dd62854fc2a89a6ee4d5fac5d265a06788e9e0df Mon Sep 17 00:00:00 2001 From: monoamine11231 Date: Fri, 16 Dec 2022 11:00:04 +0100 Subject: [PATCH 1/2] Fixed compatibility between C & C++ --- cpp/{mixbox.cpp => mixbox.c} | 46 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) rename cpp/{mixbox.cpp => mixbox.c} (99%) diff --git a/cpp/mixbox.cpp b/cpp/mixbox.c similarity index 99% rename from cpp/mixbox.cpp rename to cpp/mixbox.c index a213a7c..401f8b4 100644 --- a/cpp/mixbox.cpp +++ b/cpp/mixbox.c @@ -49,7 +49,13 @@ #include "mixbox.h" -#include +#ifdef __cplusplus + #include + // For pow instead of std::pow + using namespace std; +#else + #include +#endif #ifdef _MSC_VER #define INLINE __forceinline @@ -66,12 +72,12 @@ INLINE static float clamp01(float x) INLINE static float srgb_to_linear(float x) { - return (x >= 0.04045f) ? std::pow((x + 0.055f) / 1.055f, 2.4f) : x/12.92f; + return (x >= 0.04045f) ? pow((x + 0.055f) / 1.055f, 2.4f) : x/12.92f; } INLINE static float linear_to_srgb(float x) { - return (x >= 0.0031308f) ? 1.055f*std::pow(x, 1.0f/2.4f) - 0.055f : 12.92f*x; + return (x >= 0.0031308f) ? 1.055f*pow(x, 1.0f/2.4f) - 0.055f : 12.92f*x; } INLINE static void eval_polynomial(float c0, float c1, float c2, float c3, float* rgb) @@ -127,13 +133,13 @@ INLINE static void float_rgb_to_latent(float r, float g, float b, mixbox_latent const float y = g * 63.0f; const float z = b * 63.0f; - const int ix = int(x); - const int iy = int(y); - const int iz = int(z); + const int ix = (int)x; + const int iy = (int)y; + const int iz = (int)z; - const float tx = x - float(ix); - const float ty = y - float(iy); - const float tz = z - float(iz); + const float tx = x - (float)ix; + const float ty = y - (float)iy; + const float tz = z - (float)iz; const unsigned char* const lut_ptr = &(mixbox_lut()[((ix + iy*64 + iz*64*64) & 0x3FFFF) * 3]); @@ -189,7 +195,7 @@ INLINE static void latent_to_rgb(mixbox_latent latent, unsigned char* out_r, uns INLINE static void rgb_to_latent(unsigned char r, unsigned char g, unsigned char b, mixbox_latent out_latent) { - float_rgb_to_latent(float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, out_latent); + float_rgb_to_latent((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, out_latent); } INLINE static void linear_float_rgb_to_latent(float r, float g, float b, mixbox_latent out_latent) @@ -373,6 +379,10 @@ struct zhuffman uint16 value[288]; }; +#ifndef __cplusplus + typedef struct zhuffman zhuffman; +#endif + INLINE static int bitreverse16(int n) { n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); @@ -450,6 +460,10 @@ struct zbuf zhuffman z_length, z_distance; }; +#ifndef __cplusplus + typedef struct zbuf zbuf; +#endif + INLINE static unsigned char decode_b85_char(char c) { return (c >= 92) ? c - 36 : c - 35; @@ -693,13 +707,7 @@ static int decompress(char* obuffer, int olen) INLINE static const unsigned char* mixbox_lut() { - struct mixbox_init_t - { - unsigned char lut[64*64*64*3 + 12675]; - mixbox_init_t() { decompress((char*)lut, sizeof(lut)); } - }; - - static const mixbox_init_t decompressed; - - return decompressed.lut; + static unsigned char lut[64*64*64*3 + 12675]; + decompress((char*)&lut[0], sizeof(lut)); + return &lut[0]; } From 7fcceab803766e503d10ade4af0c9fc6013f5685 Mon Sep 17 00:00:00 2001 From: monoamine11231 Date: Fri, 16 Dec 2022 11:06:45 +0100 Subject: [PATCH 2/2] renamed dir --- {cpp => c-cpp}/README.md | 0 {cpp => c-cpp}/mixbox.c | 0 {cpp => c-cpp}/mixbox.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {cpp => c-cpp}/README.md (100%) rename {cpp => c-cpp}/mixbox.c (100%) rename {cpp => c-cpp}/mixbox.h (100%) diff --git a/cpp/README.md b/c-cpp/README.md similarity index 100% rename from cpp/README.md rename to c-cpp/README.md diff --git a/cpp/mixbox.c b/c-cpp/mixbox.c similarity index 100% rename from cpp/mixbox.c rename to c-cpp/mixbox.c diff --git a/cpp/mixbox.h b/c-cpp/mixbox.h similarity index 100% rename from cpp/mixbox.h rename to c-cpp/mixbox.h