Skip to content

Commit 67556d9

Browse files
committed
[babl] Add msvc support
1 parent 61d43ee commit 67556d9

5 files changed

Lines changed: 229 additions & 2 deletions

File tree

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
diff --git a/babl/babl-extension.c b/babl/babl-extension.c
2+
index 772cf60..45013a4 100644
3+
--- a/babl/babl-extension.c
4+
+++ b/babl/babl-extension.c
5+
@@ -290,7 +290,8 @@ dir_foreach (const char *base_path,
6+
path = babl_strcat (path, entry);
7+
8+
if ((extension = strrchr (entry, '.')) != NULL &&
9+
- !strcmp (extension, SHREXT))
10+
+ !strcmp (extension, SHREXT) &&
11+
+ strncmp (entry, BABL_LIBRARY, strlen (BABL_LIBRARY)))
12+
{
13+
int excluded = 0;
14+
for (int i = 0; ctx->exclusion_patterns[i]; i++)
15+
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
16+
index 5c03ea9..f436c9a 100644
17+
--- a/babl/babl-fish-path.c
18+
+++ b/babl/babl-fish-path.c
19+
@@ -127,8 +127,13 @@ babl_gc (void)
20+
}
21+
}
22+
23+
-#define BABL_LIKELY(x) __builtin_expect(!!(x), 1)
24+
-#define BABL_UNLIKELY(x) __builtin_expect(!!(x), 0)
25+
+#ifdef _MSC_VER
26+
+ #define BABL_LIKELY(x) (x)
27+
+ #define BABL_UNLIKELY(x) (x)
28+
+#else
29+
+ #define BABL_LIKELY(x) __builtin_expect(!!(x), 1)
30+
+ #define BABL_UNLIKELY(x) __builtin_expect(!!(x), 0)
31+
+#endif
32+
33+
static float timings[256] = {0,};
34+
35+
diff --git a/babl/babl-format.c b/babl/babl-format.c
36+
index df44b1f..f6d399e 100644
37+
--- a/babl/babl-format.c
38+
+++ b/babl/babl-format.c
39+
@@ -21,7 +21,7 @@
40+
#include <stdarg.h>
41+
#include <math.h>
42+
43+
-#ifdef _WIN64
44+
+#ifdef _WIN32
45+
#include <basetsd.h>
46+
typedef SSIZE_T ssize_t;
47+
#endif
48+
@@ -276,9 +276,9 @@ babl_format_n (const Babl *btype,
49+
int id = 0;
50+
int planar = 0;
51+
BablModel *model = (BablModel *)babl_model ("Y");
52+
- BablComponent *component [components];
53+
- BablSampling *sampling [components];
54+
- const BablType *type [components];
55+
+ BablComponent **component = babl_malloc (sizeof (BablComponent *) * components);
56+
+ BablSampling **sampling = babl_malloc (sizeof (BablSampling *) * components);
57+
+ const BablType **type = babl_malloc (sizeof (const BablType *) * components);
58+
char *name = NULL;
59+
60+
for (i = 0; i<components; i++)
61+
@@ -296,6 +296,9 @@ babl_format_n (const Babl *btype,
62+
* returning the preexistent one instead.
63+
*/
64+
babl_free (name);
65+
+ babl_free (component);
66+
+ babl_free (sampling);
67+
+ babl_free ((void *) type);
68+
return babl;
69+
}
70+
71+
@@ -305,6 +308,9 @@ babl_format_n (const Babl *btype,
72+
babl_space("sRGB"),
73+
component, sampling, type, NULL);
74+
75+
+ babl_free (component);
76+
+ babl_free (sampling);
77+
+ babl_free ((void *) type);
78+
babl_format_set_is_format_n (babl);
79+
80+
babl_db_insert (db, babl);
81+
diff --git a/babl/babl-image.c b/babl/babl-image.c
82+
index 44c0cac..9e4a1b5 100644
83+
--- a/babl/babl-image.c
84+
+++ b/babl/babl-image.c
85+
@@ -107,10 +107,11 @@ babl_image_from_linear (char *buffer,
86+
case BABL_FORMAT:
87+
components = format->format.components;
88+
89+
-#if 1
90+
+#if defined(__GNUC__) || defined(__clang__)
91+
babl = __atomic_exchange_n (&format->format.image_template, NULL,
92+
__ATOMIC_ACQ_REL);
93+
#else
94+
+ /* MSVC lacks the GCC atomic builtin used here; keep the fallback path. */
95+
/* todo: add a configure check for the above gcc extension and use
96+
a mutex if we do not have it?
97+
*/
98+
diff --git a/babl/base/babl-rgb-converter.c b/babl/base/babl-rgb-converter.c
99+
index 52f912d..3d89a2b 100644
100+
--- a/babl/base/babl-rgb-converter.c
101+
+++ b/babl/base/babl-rgb-converter.c
102+
@@ -201,7 +201,7 @@ universal_nonlinear_rgb_u8_converter (const Babl *conversion,
103+
uint8_t *rgb_in_u8 = (void*)src_char;
104+
uint8_t *rgb_out_u8 = (void*)dst_char;
105+
106+
- float rgba_out[4*samples];
107+
+ float *rgba_out = babl_malloc (sizeof (float) * 4 * samples);
108+
109+
for (i = 0; i < samples; i++)
110+
{
111+
@@ -221,6 +221,8 @@ universal_nonlinear_rgb_u8_converter (const Babl *conversion,
112+
rgb_out_u8[i*3+c] = rgba_out[i*4+c] * 255.0f;
113+
}
114+
115+
+ babl_free (rgba_out);
116+
+
117+
}
118+
119+
120+
diff --git a/extensions/gegl-fixups.c b/extensions/gegl-fixups.c
121+
index e8fd785..ca3bbc1 100644
122+
--- a/extensions/gegl-fixups.c
123+
+++ b/extensions/gegl-fixups.c
124+
@@ -49,6 +49,12 @@
125+
#include "base/util.h"
126+
#include "extensions/util.h"
127+
128+
+#if defined(_MSC_VER) && !defined(__clang__)
129+
+#define BABL_ATTRIBUTE_UNUSED
130+
+#else
131+
+#define BABL_ATTRIBUTE_UNUSED __attribute__((unused))
132+
+#endif
133+
+
134+
135+
/* lookup tables used in conversion */
136+
137+
@@ -184,7 +190,7 @@ conv_F_8g (const Babl *conversion,
138+
}
139+
140+
141+
-static inline void __attribute__((unused))
142+
+static inline void BABL_ATTRIBUTE_UNUSED
143+
conv_8_F (const Babl *conversion,
144+
unsigned char *src,
145+
unsigned char *dst,
146+
@@ -233,7 +239,7 @@ conv_rgbaF_rgb8 (const Babl *conversion,
147+
}
148+
149+
150+
-static void __attribute__((unused))
151+
+static void BABL_ATTRIBUTE_UNUSED
152+
conv_rgbaF_rgba8 (const Babl *conversion,
153+
unsigned char *src,
154+
unsigned char *dst,
155+
@@ -267,7 +273,7 @@ conv_rgbaF_rgba8 (const Babl *conversion,
156+
157+
#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
158+
159+
-static void __attribute__((unused))
160+
+static void BABL_ATTRIBUTE_UNUSED
161+
conv_rgbF_rgb8 (const Babl *conversion,
162+
unsigned char *src,
163+
unsigned char *dst,
164+
@@ -276,7 +282,7 @@ conv_rgbF_rgb8 (const Babl *conversion,
165+
conv_F_8g (conversion, src, dst, samples * 3);
166+
}
167+
168+
-static void __attribute__((unused))
169+
+static void BABL_ATTRIBUTE_UNUSED
170+
conv_gaF_ga8 (const Babl *conversion,
171+
unsigned char *src,
172+
unsigned char *dst,
173+
diff --git a/meson.build b/meson.build
174+
index a1b46c0..9a32fa0 100644
175+
--- a/meson.build
176+
+++ b/meson.build
177+
@@ -209,6 +209,9 @@ endif
178+
if cc.get_argument_syntax() == 'msvc'
179+
#Needed otherwise MSVC get angry with the headers provided by UCRT
180+
common_c_flags += ['/D_USE_MATH_DEFINES']
181+
+ common_c_flags += ['/std:c11']
182+
+ common_c_flags += ['/experimental:c11atomics']
183+
+ common_c_flags += ['/D__restrict__=__restrict']
184+
endif
185+
186+
add_project_arguments(common_c_flags, language: 'c')
187+
diff --git a/babl/babl.c b/babl/babl.c
188+
--- a/babl/babl.c
189+
+++ b/babl/babl.c
190+
@@ -101,7 +101,7 @@ babl_dir_list (void)
191+
babl_fatal ("Converting module filename to UTF-8 failed");
192+
193+
/* If the DLL file name is of the format
194+
- * <foobar>\bin\*.dll, use <foobar>\lib\{BABL_LIBRARY}.
195+
+ * <foobar>\bin\*.dll, use <foobar>\plugins\{BABL_LIBRARY}.
196+
* Otherwise, use the directory where the DLL is.
197+
*/
198+
199+
@@ -119,7 +119,7 @@ babl_dir_list (void)
200+
strlen (BABL_DIR_SEPARATOR BABL_LIBRARY) + 4));
201+
strcpy_s (filename_tmp, strlen(filename) + 1, filename);
202+
babl_free (filename);
203+
- strcat (filename_tmp, "lib" BABL_DIR_SEPARATOR BABL_LIBRARY);
204+
+ strcat (filename_tmp, "plugins" BABL_DIR_SEPARATOR BABL_LIBRARY);
205+
filename = filename_tmp;
206+
}
207+
}

ports/babl/portfile.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ vcpkg_extract_source_archive(
1010
SOURCE_PATH
1111
ARCHIVE "${ARCHIVE}"
1212
PATCHES
13+
msvc-restrict-compat.patch
1314
remove-consistency-check.patch
1415
)
1516

@@ -37,9 +38,22 @@ vcpkg_configure_meson(
3738
"g-ir-scanner='${GIR_SCANNER}'"
3839
)
3940
vcpkg_install_meson()
41+
42+
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/babl-${VERSION_MAJOR_MINOR}")
43+
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/plugins")
44+
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/babl-${VERSION_MAJOR_MINOR}" "${CURRENT_PACKAGES_DIR}/plugins/babl-${VERSION_MAJOR_MINOR}")
45+
endif()
46+
47+
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/babl-${VERSION_MAJOR_MINOR}")
48+
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/plugins")
49+
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/babl-${VERSION_MAJOR_MINOR}" "${CURRENT_PACKAGES_DIR}/debug/plugins/babl-${VERSION_MAJOR_MINOR}")
50+
endif()
51+
4052
vcpkg_copy_pdbs()
4153
vcpkg_fixup_pkgconfig()
4254

55+
vcpkg_copy_tools(TOOL_NAMES babl AUTO_CLEAN)
56+
4357
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
4458

4559
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")

ports/babl/vcpkg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "babl",
33
"version": "0.1.124",
4+
"port-version": 1,
45
"description": "A pixel encoding and color space conversion engine.",
56
"homepage": "https://gegl.org/babl/",
67
"license": "LGPL-3.0-or-later",
7-
"supports": "!windows | mingw",
88
"dependencies": [
99
{
1010
"name": "vcpkg-tool-meson",
@@ -20,6 +20,7 @@
2020
},
2121
"introspection": {
2222
"description": "Enable introspection",
23+
"supports": "!windows | mingw",
2324
"dependencies": [
2425
"gobject-introspection"
2526
]

versions/b-/babl.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "d14e77bd99f71792c94ffd9f92ae0bff9d7e85d0",
5+
"version": "0.1.124",
6+
"port-version": 1
7+
},
38
{
49
"git-tree": "712240fb456214b23808542557986b3787dcc174",
510
"version": "0.1.124",

versions/baseline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@
622622
},
623623
"babl": {
624624
"baseline": "0.1.124",
625-
"port-version": 0
625+
"port-version": 1
626626
},
627627
"backward-cpp": {
628628
"baseline": "2023-11-24",

0 commit comments

Comments
 (0)