Skip to content

Commit fa14082

Browse files
committed
add SDL3_image meson files
1 parent f14836c commit fa14082

File tree

3 files changed

+363
-0
lines changed

3 files changed

+363
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
project('sdl3_image', 'c', version: '3.2.4')
2+
3+
cc = meson.get_compiler('c')
4+
5+
sdl3_dep = dependency('sdl3', version: '>=3.2.4')
6+
deps = [sdl3_dep]
7+
inc = include_directories('include')
8+
9+
feature_args = []
10+
extra_library_args = []
11+
12+
if host_machine.system() == 'windows' and get_option('default_library') != 'static'
13+
extra_library_args += '-DDLL_EXPORT'
14+
endif
15+
16+
# These are enabled by default it seems.
17+
#img_args = ['-DWANT_LIBPNG']
18+
#if jpg_dep.found()
19+
# img_args += '-DWANT_JPEGLIB'
20+
#endif
21+
22+
# Backends provide support for certain formats, allowing not to depend on external library or use potentially better optimized algorithm
23+
backend_provided_loaders = []
24+
25+
use_imageio_backend = get_option('use_imageio').require(
26+
host_machine.system() == 'darwin',
27+
error_message: 'Image I/O backend is exclusive to MacOS',
28+
).allowed()
29+
use_wic_backend = get_option('use_wic').require(
30+
host_machine.system() == 'windows',
31+
error_message: 'WIC backend is exclusive to Windows',
32+
).allowed()
33+
34+
native_backend_present = use_imageio_backend or use_wic_backend
35+
36+
# In meson 1.1.0+ this can be done using .disable_auto_if(native_backend_present).enabled()
37+
use_stbimage_backend = native_backend_present ? get_option('use_stbimage').enabled() : get_option(
38+
'use_stbimage',
39+
).allowed()
40+
if use_stbimage_backend
41+
feature_args += '-DUSE_STBIMAGE'
42+
backend_provided_loaders += ['png', 'jpg']
43+
endif
44+
45+
subdir('src')
46+
47+
full_library_args = [feature_args, extra_library_args]
48+
49+
img_lib = library(
50+
'sdl3_image',
51+
src,
52+
c_args: full_library_args,
53+
objc_args: full_library_args,
54+
include_directories: inc,
55+
gnu_symbol_visibility: 'hidden',
56+
dependencies: deps,
57+
)
58+
59+
sdl3_image_dep = declare_dependency(
60+
include_directories: inc,
61+
link_with: img_lib,
62+
)
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
option(
2+
'force_builtin_bmp',
3+
type: 'boolean',
4+
value: true,
5+
description: 'Do not use backend-provided BMP loaders. Potentially slower but pixel-perfect. Recommended for tests.',
6+
)
7+
8+
# Backends
9+
10+
option(
11+
'use_stbimage',
12+
type: 'feature',
13+
description: 'Use stb_image for JPEG and PNG',
14+
)
15+
16+
option(
17+
'use_imageio',
18+
type: 'feature',
19+
description: 'Use Image I/O framework for supported formats',
20+
)
21+
22+
option(
23+
'use_wic',
24+
type: 'feature',
25+
# It is disabled by default in upstream build system, plus CI fails to load WIC
26+
value: 'disabled',
27+
description: 'Use WIC (Windows Imaging Component) for supported formats',
28+
)
29+
30+
# Image loaders that may require external library (some can be provided by backends instead)
31+
32+
option(
33+
'jpg',
34+
type: 'feature',
35+
description: 'Support loading JPEG images',
36+
)
37+
38+
option(
39+
'jpg_save',
40+
type: 'feature',
41+
description: 'Support saving JPEG images',
42+
)
43+
44+
option(
45+
'png',
46+
type: 'feature',
47+
description: 'Support loading PNG images',
48+
)
49+
50+
option(
51+
'png_save',
52+
type: 'feature',
53+
description: 'Support saving PNG images',
54+
)
55+
56+
option(
57+
'avif',
58+
type: 'feature',
59+
description: 'Support loading AVIF images',
60+
)
61+
62+
option(
63+
'avif_save',
64+
type: 'feature',
65+
description: 'Support saving AVIF images',
66+
)
67+
68+
option(
69+
'jxl',
70+
type: 'feature',
71+
description: 'Support loading JXL images',
72+
)
73+
74+
option(
75+
'tif',
76+
type: 'feature',
77+
description: 'Support loading TIFF images',
78+
)
79+
80+
option(
81+
'webp',
82+
type: 'feature',
83+
description: 'Support loading WEBP images',
84+
)
85+
86+
# Image loaders that never require external libraries
87+
88+
option(
89+
'bmp',
90+
type: 'feature',
91+
description: 'Support loading BMP images',
92+
)
93+
94+
option(
95+
'gif',
96+
type: 'feature',
97+
description: 'Support loading GIF images',
98+
)
99+
100+
option(
101+
'lbm',
102+
type: 'feature',
103+
description: 'Support loading LBM images',
104+
)
105+
106+
option(
107+
'pcx',
108+
type: 'feature',
109+
description: 'Support loading PCX images',
110+
)
111+
112+
option(
113+
'pnm',
114+
type: 'feature',
115+
description: 'Support loading PNM images',
116+
)
117+
118+
option(
119+
'qoi',
120+
type: 'feature',
121+
description: 'Support loading QOI images',
122+
)
123+
124+
option(
125+
'svg',
126+
type: 'feature',
127+
description: 'Support loading SVG images',
128+
)
129+
130+
option(
131+
'tga',
132+
type: 'feature',
133+
description: 'Support loading TGA images',
134+
)
135+
136+
option(
137+
'xcf',
138+
type: 'feature',
139+
description: 'Support loading XCF images',
140+
)
141+
142+
option(
143+
'xpm',
144+
type: 'feature',
145+
description: 'Support loading XPM images',
146+
)
147+
148+
option(
149+
'xv',
150+
type: 'feature',
151+
description: 'Support loading XV images',
152+
)
153+
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Files that are not directly tied to loaders
2+
src = files('IMG.c', 'IMG_WIC.c', 'IMG_stb.c')
3+
4+
if use_imageio_backend
5+
add_languages(
6+
'objc',
7+
native: false,
8+
)
9+
src += files('IMG_ImageIO.m')
10+
deps += dependency(
11+
'appleframeworks',
12+
modules: ['ApplicationServices'],
13+
)
14+
15+
imageio_provided_formats = ['png', 'jpg', 'tif', 'gif', 'tga']
16+
if not get_option('force_builtin_bmp')
17+
imageio_provided_formats += 'bmp'
18+
endif
19+
20+
foreach format_name : imageio_provided_formats
21+
if format_name not in backend_provided_loaders
22+
feature_args += '-D@0@_USES_IMAGEIO'.format(format_name.to_upper())
23+
endif
24+
endforeach
25+
26+
backend_provided_loaders += imageio_provided_formats
27+
endif
28+
29+
if not use_imageio_backend and host_machine.system() == 'darwin'
30+
feature_args += '-DSDL_IMAGE_USE_COMMON_BACKEND'
31+
endif
32+
33+
if use_wic_backend
34+
feature_args += '-DSDL_IMAGE_USE_WIC_BACKEND'
35+
deps += cc.find_library('windowscodecs')
36+
backend_provided_loaders += ['png', 'jpg', 'tif']
37+
endif
38+
39+
summary(
40+
{
41+
'stb_image': use_stbimage_backend,
42+
'Image I/O': use_imageio_backend,
43+
'Windows Imaging Component': use_wic_backend,
44+
},
45+
section: 'Backends',
46+
)
47+
48+
# Loaders that don't depend on anything
49+
self_contained_loaders = [
50+
'bmp',
51+
'gif',
52+
'lbm',
53+
'pcx',
54+
'pnm',
55+
'qoi',
56+
'svg',
57+
'tga',
58+
'xcf',
59+
'xpm',
60+
'xv',
61+
]
62+
63+
foreach format_name : self_contained_loaders
64+
src += files('IMG_@[email protected]'.format(format_name))
65+
if get_option(format_name).allowed()
66+
feature_args += '-DLOAD_@0@'.format(format_name.to_upper())
67+
summary(
68+
format_name,
69+
format_name in backend_provided_loaders ? 'handled by backend' : 'built-in loader',
70+
section: 'Formats',
71+
)
72+
else
73+
summary(
74+
format_name,
75+
'disabled',
76+
section: 'Formats',
77+
)
78+
endif
79+
endforeach
80+
81+
# Loaders that depend on external libraries
82+
external_dep_loaders = {
83+
'avif': ['libavif'],
84+
'jpg': ['libjpeg'],
85+
'jxl': ['libjxl'],
86+
'png': ['libpng'],
87+
'tif': ['libtiff-4'],
88+
'webp': ['libwebp', 'libwebpdemux'],
89+
}
90+
91+
foreach format_name, library_names : external_dep_loaders
92+
src += files('IMG_@[email protected]'.format(format_name))
93+
if format_name in backend_provided_loaders
94+
if get_option(format_name).allowed()
95+
feature_args += '-DLOAD_@0@'.format(format_name.to_upper())
96+
summary(
97+
format_name,
98+
'handled by backend',
99+
section: 'Formats',
100+
)
101+
else
102+
summary(
103+
format_name,
104+
'disabled',
105+
section: 'Formats',
106+
)
107+
endif
108+
else
109+
summary_name = format_name
110+
summary_value = 'handled by ' + ', '.join(library_names)
111+
112+
foreach lib_name : library_names
113+
loader_library = dependency(
114+
lib_name,
115+
required: get_option(format_name),
116+
)
117+
if loader_library.found()
118+
deps += loader_library
119+
feature_args += '-DLOAD_@0@'.format(format_name.to_upper())
120+
else
121+
summary_value = 'disabled'
122+
endif
123+
endforeach
124+
summary(
125+
summary_name,
126+
summary_value,
127+
section: 'Formats',
128+
)
129+
endif
130+
endforeach
131+
132+
jpg_save_support = get_option('jpg_save').allowed()
133+
feature_args += '-DSDL_IMAGE_SAVE_JPG=@0@'.format(jpg_save_support.to_int())
134+
135+
png_save_support = get_option('png_save').allowed()
136+
feature_args += '-DSDL_IMAGE_SAVE_PNG=@0@'.format(png_save_support.to_int())
137+
138+
avif_save_support = get_option('avif_save').allowed()
139+
feature_args += '-DSDL_IMAGE_SAVE_AVIF=@0@'.format(png_save_support.to_int())
140+
141+
summary(
142+
{
143+
'jpg': jpg_save_support,
144+
'png': png_save_support,
145+
'avif': avif_save_support,
146+
},
147+
section: 'Image saving support',
148+
)

0 commit comments

Comments
 (0)