Skip to content

Commit 606ba5b

Browse files
committed
[babl] Add msvc support
1 parent 61d43ee commit 606ba5b

File tree

5 files changed

+230
-2
lines changed

5 files changed

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

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-0.1")
43+
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/bin")
44+
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/babl-0.1" "${CURRENT_PACKAGES_DIR}/bin/babl-0.1")
45+
endif()
46+
47+
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/babl-0.1")
48+
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/bin")
49+
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/babl-0.1" "${CURRENT_PACKAGES_DIR}/debug/bin/babl-0.1")
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": "16a18ff6443cd8db4175c1965229e956a254e87b",
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)