Skip to content

Commit 2388f23

Browse files
committed
Add support for UltraHDR images
1 parent 27b22b6 commit 2388f23

File tree

14 files changed

+547
-3
lines changed

14 files changed

+547
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Uses libvips v8.18.0-rc2, compiled with Emscripten v4.0.21.
1212

1313
- Support all typed array variants in `Image.newFromMemory()` and
1414
`image.writeToMemory()`.
15+
- Support for UltraHDR images.
16+
- Add `image.gainmap` property to retrieve the gainmap from
17+
Ultra HDR images.
18+
- Add `image.setImage()` method to attach an image as metadata.
19+
- Add `vips.Utils.typeFromName()` helper.
1520

1621
### Changed
1722

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ used under the terms of the following licences:
2121
| libnsgif | MIT Licence |
2222
| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
2323
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
24+
| libultrahdr | Apache-2.0 License |
2425
| libvips | LGPLv3 |
2526
| libwebp | New BSD License |
2627
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |

build.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ LTO=false
5151
# Dynamic loadable modules, enabled by default
5252
MODULES=true
5353

54+
# Support for UltraHDR images, enabled by default
55+
UHDR=true
56+
5457
# Support for JPEG XL images, enabled by default
5558
JXL=true
5659

@@ -78,6 +81,7 @@ while [ $# -gt 0 ]; do
7881
;;
7982
--disable-simd) SIMD=false ;;
8083
--disable-wasm-bigint) WASM_BIGINT=false ;;
84+
--disable-uhdr) UHDR=false ;;
8185
--disable-jxl) JXL=false ;;
8286
--disable-avif) AVIF=false ;;
8387
--disable-svg) SVG=false ;;
@@ -91,7 +95,7 @@ while [ $# -gt 0 ]; do
9195
done
9296

9397
# Configure the ENABLE_* and DISABLE_* expansion helpers
94-
for arg in SIMD JXL AVIF SVG MODULES BINDINGS; do
98+
for arg in SIMD UHDR JXL AVIF SVG MODULES BINDINGS; do
9599
if [ "${!arg}" = "true" ]; then
96100
declare ENABLE_$arg=true
97101
else
@@ -178,6 +182,7 @@ VERSION_LCMS2=2.17 # https://github.com/mm2/Little-CMS
178182
VERSION_HWY=1.3.0 # https://github.com/google/highway
179183
VERSION_BROTLI=1.2.0 # https://github.com/google/brotli
180184
VERSION_MOZJPEG=0826579 # https://github.com/mozilla/mozjpeg
185+
VERSION_UHDR=1.4.0 # https://github.com/google/libultrahdr
181186
VERSION_JXL=0.11.1 # https://github.com/libjxl/libjxl
182187
VERSION_PNG=1.6.52 # https://github.com/pnggroup/libpng
183188
VERSION_IMAGEQUANT=2.4.1 # https://github.com/lovell/libimagequant
@@ -210,6 +215,7 @@ VERSION_EMSCRIPTEN="$(emcc -dumpversion)"
210215
printf " \"png\": \"${VERSION_PNG}\",\n"; \
211216
[ -n "$DISABLE_SVG" ] || printf " \"resvg\": \"${VERSION_RESVG}\",\n"; \
212217
printf " \"tiff\": \"${VERSION_TIFF}\",\n"; \
218+
[ -n "$DISABLE_UHDR" ] || printf " \"uhdr\": \"${VERSION_UHDR}\",\n"; \
213219
printf " \"vips\": \"${VERSION_VIPS}\",\n"; \
214220
printf " \"webp\": \"${VERSION_WEBP}\",\n"; \
215221
printf " \"zlib-ng\": \"${VERSION_ZLIB_NG}\"\n"; \
@@ -348,6 +354,20 @@ node --version
348354
make -C _build install
349355
)
350356

357+
[ -f "$TARGET/lib/pkgconfig/libuhdr.pc" ] || [ -n "$DISABLE_UHDR" ] || (
358+
stage "Compiling uhdr"
359+
mkdir $DEPS/uhdr
360+
curl -Ls https://github.com/google/libultrahdr/archive/refs/tags/v$VERSION_UHDR.tar.gz | tar xzC $DEPS/uhdr --strip-components=1
361+
cd $DEPS/uhdr
362+
# Ensure install targets are enabled when cross-compiling
363+
sed -i 's/CMAKE_CROSSCOMPILING AND UHDR_ENABLE_INSTALL/FALSE/' CMakeLists.txt
364+
# Disable threading support, we rely on libvips' thread pool
365+
sed -i 's/(std::max)(1u, std::thread::hardware_concurrency())/1u/' lib/src/jpegr.cpp
366+
emcmake cmake -B_build -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$TARGET $CMAKE_ARGS -DBUILD_SHARED_LIBS=FALSE \
367+
-DCMAKE_POSITION_INDEPENDENT_CODE=$MODULES -DUHDR_BUILD_EXAMPLES=FALSE -DUHDR_MAX_DIMENSION=65500
368+
make -C _build install
369+
)
370+
351371
[ -f "$TARGET/lib/pkgconfig/libjxl.pc" ] || [ -n "$DISABLE_JXL" ] || (
352372
stage "Compiling jxl"
353373
mkdir $DEPS/jxl
@@ -493,7 +513,7 @@ node --version
493513
${DISABLE_SIMD:+-Dhighway=disabled} ${DISABLE_JXL:+-Djpeg-xl=disabled} -Dmagick=disabled \
494514
-Dmatio=disabled -Dnifti=disabled -Dopenexr=disabled -Dopenjpeg=disabled \
495515
-Dopenslide=disabled -Dpangocairo=disabled -Dpdfium=disabled -Dpoppler=disabled \
496-
-Draw=disabled ${DISABLE_SVG:+-Dresvg=disabled} -Drsvg=disabled -Duhdr=disabled
516+
-Draw=disabled ${DISABLE_SVG:+-Dresvg=disabled} -Drsvg=disabled ${DISABLE_UHDR:+-Duhdr=disabled}
497517
meson install -C _build --tag runtime,devel
498518
# Emscripten requires linking to side modules to find the necessary symbols to export
499519
module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1)

build/preamble_vips.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ declare module Vips {
283283
* Handy utilities.
284284
*/
285285
abstract class Utils {
286+
/**
287+
* Return the GType for a name.
288+
* @param name Type name to lookup.
289+
* @return Corresponding type ID, or `0` if not found.
290+
*/
291+
static typeFromName(name: string): number;
292+
286293
/**
287294
* Get the GType for a name.
288295
* Looks up the GType for a nickname. Types below basename in the type hierarchy are searched.
@@ -522,6 +529,11 @@ declare module Vips {
522529
*/
523530
readonly filename?: string;
524531

532+
/**
533+
* The associated gainmap image, if any.
534+
*/
535+
readonly gainmap?: Image;
536+
525537
/**
526538
* Page height in pixels.
527539
*/
@@ -900,6 +912,14 @@ declare module Vips {
900912
*/
901913
setString(name: string, value: string): void;
902914

915+
/**
916+
* Set an image to another image as metadata.
917+
* This is typically used to update the gainmap.
918+
* @param name The name of the piece of metadata to set the value of.
919+
* @param value The metadata value.
920+
*/
921+
setImage(name: string, value: Image): void;
922+
903923
/**
904924
* Set a blob on an image as metadata.
905925
* The value will internally be copied from JavaScript to WASM.

lib/vips.d.ts

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/src/playground-runner.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
console.log('Open files:'.padEnd(pad), module.Stats.files());
120120

121121
console.log('JPEG support:'.padEnd(pad), have('jpegload') ? 'yes' : 'no');
122+
console.log('UltraHDR support:'.padEnd(pad), have('uhdrload') ? 'yes' : 'no');
122123
console.log('JPEG XL support:'.padEnd(pad), have('jxlload') ? 'yes' : 'no');
123124
console.log('AVIF support:'.padEnd(pad), have('heifload') ? 'yes' : 'no');
124125
console.log('PNG support:'.padEnd(pad), have('pngload') ? 'yes' : 'no');

src/bindings/image.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ class Image : public Object {
8989
return vips_image_get_page_height(get_image());
9090
}
9191

92+
std::optional<Image> gainmap() const {
93+
VipsImage *image = vips_image_get_gainmap(get_image());
94+
if (image == nullptr)
95+
return {};
96+
97+
return Image(image);
98+
}
99+
92100
bool is_killed() const {
93101
return vips_image_iskilled(get_image());
94102
}
@@ -133,6 +141,10 @@ class Image : public Object {
133141
vips_image_set_string(get_image(), field.c_str(), value.c_str());
134142
}
135143

144+
void set(const std::string &field, const Image &value) const {
145+
vips_image_set_image(get_image(), field.c_str(), value.get_image());
146+
}
147+
136148
void set_blob(const std::string &field, const std::string &data) const {
137149
// We must take a copy of the data.
138150
vips_image_set_blob_copy(get_image(), field.c_str(), data.c_str(),

0 commit comments

Comments
 (0)