Skip to content

Commit

Permalink
Test build for upcoming libvips 8.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed May 26, 2024
1 parent 0d47947 commit b7e0abf
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [v0.0.9] - TBD

Uses libvips v8.15.2, compiled with Emscripten v3.1.60.
Uses libvips v8.16.0, compiled with Emscripten v3.1.60.

### Changed

- Inline worker script (`.worker.js`) into the main output file.
[emscripten-core/emscripten#21701](https://github.com/emscripten-core/emscripten/pull/21701)
- Update methods/enums for libvips 8.16.

## [v0.0.8] - 2024-03-17

Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ VERSION_TIFF=4.6.0 # https://gitlab.com/libtiff/libtiff
VERSION_RESVG=0.41.0 # https://github.com/RazrFalcon/resvg
VERSION_AOM=3.9.0 # https://aomedia.googlesource.com/aom
VERSION_HEIF=1.17.6 # https://github.com/strukturag/libheif
VERSION_VIPS=8.15.2 # https://github.com/libvips/libvips
VERSION_VIPS=ec432a5 # https://github.com/libvips/libvips

VERSION_EMSCRIPTEN="$(emcc -dumpversion)"

Expand Down Expand Up @@ -481,12 +481,12 @@ node --version
[ -f "$TARGET/lib/pkgconfig/vips.pc" ] || (
stage "Compiling vips"
mkdir $DEPS/vips
curl -Ls https://github.com/libvips/libvips/releases/download/v$VERSION_VIPS/vips-$(without_prerelease $VERSION_VIPS).tar.xz | tar xJC $DEPS/vips --strip-components=1
curl -Ls https://github.com/libvips/libvips/archive/$VERSION_VIPS.tar.gz | tar xzC $DEPS/vips --strip-components=1
cd $DEPS/vips
# Emscripten specific patches
curl -Ls https://github.com/libvips/libvips/compare/v$VERSION_VIPS...kleisauke:wasm-vips-8.15.patch | patch -p1
curl -Ls https://github.com/libvips/libvips/compare/$VERSION_VIPS...kleisauke:wasm-vips-8.16.patch | patch -p1
# Disable HBR support in heifsave
curl -Ls https://github.com/kleisauke/libvips/commit/ad921cf9396dc5a224e93c71b601e87bd3a8a521.patch | patch -p1
curl -Ls https://github.com/kleisauke/libvips/commit/88b4db95ec6c13860638a0a94e7ef44ea7ce0c19.patch | patch -p1
# Disable building man pages, gettext po files, tools, and (fuzz-)tests
sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build
meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \
Expand Down
96 changes: 91 additions & 5 deletions lib/vips.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 33 additions & 3 deletions src/bindings/vips-operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,18 @@ Image Image::abs() const
return out;
}

Image Image::addalpha() const
{
Image out;

this->call("addalpha",
(new Option)
->set("in", *this)
->set("out", &out));

return out;
}

Image Image::affine(const std::vector<double> &matrix, emscripten::val js_options) const
{
Image out;
Expand Down Expand Up @@ -3310,12 +3322,30 @@ void Image::rawsave(const std::string &filename, emscripten::val js_options) con
js_options);
}

void Image::rawsave_fd(int fd, emscripten::val js_options) const
emscripten::val Image::rawsave_buffer(emscripten::val js_options) const
{
this->call("rawsave_fd",
VipsBlob *buffer;

this->call("rawsave_buffer",
(new Option)
->set("in", *this)
->set("fd", fd),
->set("buffer", &buffer),
js_options);

emscripten::val result = BlobVal.new_(emscripten::typed_memory_view(
VIPS_AREA(buffer)->length,
reinterpret_cast<uint8_t *>(VIPS_AREA(buffer)->data)));
vips_area_unref(VIPS_AREA(buffer));

return result;
}

void Image::rawsave_target(const Target &target, emscripten::val js_options) const
{
this->call("rawsave_target",
(new Option)
->set("in", *this)
->set("target", target),
js_options);
}

Expand Down
23 changes: 18 additions & 5 deletions src/bindings/vips-operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,12 @@ Image Yxy2XYZ() const;
*/
Image abs() const;

/**
* Append an alpha channel.
* @return Output image.
*/
Image addalpha() const;

/**
* Affine transform of an image.
* @param matrix Transformation matrix.
Expand Down Expand Up @@ -1570,7 +1576,7 @@ Image join(emscripten::val in2, emscripten::val direction, emscripten::val js_op

/**
* Save image in jpeg2000 format.
* @param filename Filename to load from.
* @param filename Filename to save to.
* @param js_options Optional options.
*/
void jp2ksave(const std::string &filename, emscripten::val js_options = emscripten::val::null()) const;
Expand Down Expand Up @@ -1618,7 +1624,7 @@ void jpegsave_target(const Target &target, emscripten::val js_options = emscript

/**
* Save image in jpeg-xl format.
* @param filename Filename to load from.
* @param filename Filename to save to.
* @param js_options Optional options.
*/
void jxlsave(const std::string &filename, emscripten::val js_options = emscripten::val::null()) const;
Expand Down Expand Up @@ -1961,11 +1967,18 @@ Image rank(int width, int height, int index) const;
void rawsave(const std::string &filename, emscripten::val js_options = emscripten::val::null()) const;

/**
* Write raw image to file descriptor.
* @param fd File descriptor to write to.
* Write raw image to buffer.
* @param js_options Optional options.
* @return Buffer to save to.
*/
emscripten::val rawsave_buffer(emscripten::val js_options = emscripten::val::null()) const;

/**
* Write raw image to target.
* @param target Target to save to.
* @param js_options Optional options.
*/
void rawsave_fd(int fd, emscripten::val js_options = emscripten::val::null()) const;
void rawsave_target(const Target &target, emscripten::val js_options = emscripten::val::null()) const;

/**
* Linear recombination with matrix.
Expand Down
11 changes: 8 additions & 3 deletions src/vips-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("XYZ2scRGB", &Image::XYZ2scRGB)
.function("Yxy2XYZ", &Image::Yxy2XYZ)
.function("abs", &Image::abs)
.function("addalpha", &Image::addalpha)
.function("affine", &Image::affine)
.function("affine", optional_override([](const Image &image, const std::vector<double> &matrix) {
return image.affine(matrix);
Expand Down Expand Up @@ -1883,9 +1884,13 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("rawsave", optional_override([](const Image &image, const std::string &filename) {
image.rawsave(filename);
}))
.function("rawsaveFd", &Image::rawsave_fd)
.function("rawsaveFd", optional_override([](const Image &image, int fd) {
image.rawsave_fd(fd);
.function("rawsaveBuffer", &Image::rawsave_buffer)
.function("rawsaveBuffer", optional_override([](const Image &image) {
return image.rawsave_buffer();
}))
.function("rawsaveTarget", &Image::rawsave_target)
.function("rawsaveTarget", optional_override([](const Image &image, const Target &target) {
image.rawsave_target(target);
}))
.function("recomb", &Image::recomb)
.function("reduce", &Image::reduce)
Expand Down
6 changes: 6 additions & 0 deletions test/unit/test_conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ describe('conversion', () => {
expect(x.extractBand(4).avg()).to.equal(2);
});

it('addalpha', function () {
const x = colour.addalpha();
expect(x.bands).to.equal(4);
expect(x.extractBand(3).avg()).to.equal(255);
});

it('bandmean', function () {
const bandmean = (x) => x instanceof vips.Image
? x.bandmean()
Expand Down
Loading

0 comments on commit b7e0abf

Please sign in to comment.