From a7fa7014ef9b43ecadc262939c4895bb5e9270a1 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 13 Dec 2022 11:37:08 +0000 Subject: [PATCH] Add experimental support for JPEG-XL, requires libvips with libjxl The prebuilt binaries do not include support for this format. --- docs/api-output.md | 32 ++++++++++++++ docs/changelog.md | 3 ++ docs/search-index.json | 2 +- lib/constructor.js | 4 ++ lib/output.js | 69 +++++++++++++++++++++++++++++- src/common.cc | 6 +++ src/common.h | 2 + src/pipeline.cc | 31 ++++++++++++++ src/pipeline.h | 8 ++++ src/utilities.cc | 2 +- test/unit/jxl.js | 97 ++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 test/unit/jxl.js diff --git a/docs/api-output.md b/docs/api-output.md index bb0894c1c..87e811305 100644 --- a/docs/api-output.md +++ b/docs/api-output.md @@ -536,6 +536,38 @@ Returns **Sharp** * **since**: 0.23.0 +## jxl + +Use these JPEG-XL (JXL) options for output image. + +This feature is experimental, please do not use in production systems. + +Requires libvips compiled with support for libjxl. +The prebuilt binaries do not include this - see +[installing a custom libvips][14]. + +Image metadata (EXIF, XMP) is unsupported. + +### Parameters + +* `options` **[Object][6]?** output options + + * `options.distance` **[number][12]** maximum encoding error, between 0 (highest quality) and 15 (lowest quality) (optional, default `1.0`) + * `options.quality` **[number][12]?** calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified + * `options.decodingTier` **[number][12]** target decode speed tier, between 0 (highest quality) and 4 (lowest quality) (optional, default `0`) + * `options.lossless` **[boolean][10]** use lossless compression (optional, default `false`) + * `options.effort` **[number][12]** CPU effort, between 3 (fastest) and 9 (slowest) (optional, default `7`) + + + +* Throws **[Error][4]** Invalid options + +Returns **Sharp** + +**Meta** + +* **since**: 0.31.3 + ## raw Force output to be raw, uncompressed pixel data. diff --git a/docs/changelog.md b/docs/changelog.md index 46cd41399..cece1b13b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,9 @@ Requires libvips v8.13.3 ### v0.31.3 - TBD +* Add experimental support for JPEG-XL images. Requires libvips compiled with libjxl. + [#2731](https://github.com/lovell/sharp/issues/2731) + * Expose `interFrameMaxError` and `interPaletteMaxError` GIF optimisation properties. [#3401](https://github.com/lovell/sharp/issues/3401) diff --git a/docs/search-index.json b/docs/search-index.json index a0670feb8..f0c2c8b09 100644 --- a/docs/search-index.json +++ b/docs/search-index.json @@ -1 +1 @@ -[{"t":"Prerequisites","d":"Node.js 14.15.0","k":"prerequisites node","l":"/install#prerequisites"},{"t":"Prebuilt binaries","d":"Ready-compiled sharp and libvips binaries are provided for use on the most common platforms macOS x64 10.13 macOS ARM64 Linux x64 glibc 2.17, musl 1.1.24, CPU with SSE4.2 Linux ARM64 glibc 2.17, musl","k":"prebuilt binaries compiled sharp libvips common platforms macos arm linux glibc musl cpu sse","l":"/install#prebuilt-binaries"},{"t":"Common problems","d":"The architecture and platform of Node.js used for npm install must be the same as the architecture and platform of Node.js used at runtime. See the cross-platform","k":"common problems architecture platform node npm install runtime cross","l":"/install#common-problems"},{"t":"Apple M1","d":"Prebuilt sharp and libvips binaries have been provided for macOS on ARM64 since sharp v0.29.0.","k":"apple prebuilt sharp libvips binaries macos arm","l":"/install#apple-m1"},{"t":"Custom libvips","d":"To use a custom, globally-installed version of libvips instead of the provided binaries, make sure it is at least the version listed under config.libvips in the package.json file and that it can be lo","k":"custom libvips globally installed version instead binaries listed config package json file","l":"/install#custom-libvips"},{"t":"Building from source","d":"This module will be compiled from source at npm install time when a globally-installed libvips is detected set the SHARP_IGNORE_GLOBAL_LIBVIPS environment variable to skip this, prebuilt sharp binarie","k":"building source module compiled npm install time globally installed libvips detected environment variable skip prebuilt sharp binarie","l":"/install#building-from-source"},{"t":"Custom prebuilt binaries","d":"This is an advanced approach that most people will not require.","k":"custom prebuilt binaries advanced approach people require","l":"/install#custom-prebuilt-binaries"},{"t":"Prebuilt sharp binaries","d":"To install the prebuilt sharp binaries from a custom URL, set the sharp_binary_host npm config option or the npm_config_sharp_binary_host environment variable. To install the prebuilt sharp binaries f","k":"prebuilt sharp binaries install custom url npm config option environment variable","l":"/install#prebuilt-sharp-binaries"},{"t":"Prebuilt libvips binaries","d":"To install the prebuilt libvips binaries from a custom URL, set the sharp_libvips_binary_host npm config option or the npm_config_sharp_libvips_binary_host environment variable. To install the prebuil","k":"prebuilt libvips binaries install custom url npm config option environment variable prebuil","l":"/install#prebuilt-libvips-binaries"},{"t":"Chinese mirror","d":"A mirror site based in China, provided by Alibaba, contains binaries for both sharp and libvips. To use this either set the following configuration sh npm config set sharp_binary_host https//npmmirror","k":"chinese mirror china alibaba binaries sharp libvips configuration npm config https npmmirror","l":"/install#chinese-mirror"},{"t":"FreeBSD","d":"The vips package must be installed before npm install is run. sh pkg install -y pkgconf vips sh cd /usr/ports/graphics/vips/ make install clean","k":"freebsd vips package installed npm install run pkg pkgconf usr ports graphics clean","l":"/install#freebsd"},{"t":"Linux memory allocator","d":"The default memory allocator on most glibc-based Linux systems e.g. Debian, Red Hat is unsuitable for long-running, multi-threaded processes that involve lots of small memory allocations. For this rea","k":"linux memory allocator glibc systems debian red hat long running multi threaded processes small allocations rea","l":"/install#linux-memory-allocator"},{"t":"Heroku","d":"Add the jemalloc buildpack to reduce the effects of memory fragmentation. Set NODE_MODULES_CACHE","k":"heroku add jemalloc buildpack reduce effects memory fragmentation","l":"/install#heroku"},{"t":"AWS Lambda","d":"The node_modules directory of the deployment package must include binaries for the Linux x64 platform. When building your deployment package on machines other than Linux x64 glibc, run the following a","k":"aws lambda nodemodules directory deployment package binaries linux platform building your machines glibc run","l":"/install#aws-lambda"},{"t":"webpack","d":"Ensure sharp is excluded from bundling via the externals configuration. js externals sharp commonjs sharp","k":"webpack sharp excluded bundling via externals configuration commonjs","l":"/install#webpack"},{"t":"esbuild","d":"Ensure sharp is excluded from bundling via the external","k":"esbuild sharp excluded bundling via external","l":"/install#esbuild"},{"t":"Fonts","d":"When creating text images or rendering SVG images that contain text elements, fontconfig is used to find the relevant fonts. On Windows and macOS systems, all system fonts are available for use. On ma","k":"fonts creating text images rendering svg contain elements fontconfig find relevant windows macos systems system available","l":"/install#fonts"},{"t":"Worker threads","d":"On some platforms, including glibc-based Linux, the main thread must call requiresharp _before_ worker threads are created. This is to ensure shared libraries remain loaded in memory until after all t","k":"worker threads platforms glibc linux main thread shared libraries remain loaded memory","l":"/install#worker-threads"},{"t":"Canvas and Windows","d":"The prebuilt binaries provided by canvas for Windows from v2.7.0 onwards depend on the Visual C Runtime MSVCRT. These conflict with the binaries provided by sharp, which depend on the more modern Univ","k":"canvas windows prebuilt binaries onwards depend visual runtime msvcrt conflict sharp modern univ","l":"/install#canvas-and-windows"},{"t":"Sharp","d":"Constructor factory to create an instance of sharp, to which further methods are chained.","k":"sharp constructor factory create instance further methods chained","l":"/api-constructor#sharp"},{"t":"clone","d":"Take a snapshot of the Sharp instance, returning a new instance. Cloned instances inherit the input of their parent instance. This allows multiple output Streams and therefore multiple processing pipe","k":"clone snapshot sharp instance returning new cloned instances inherit input parent multiple output streams processing pipe","l":"/api-constructor#clone"},{"t":"metadata","d":"Fast access to uncached image metadata without decoding any compressed pixel data.","k":"metadata fast access uncached decoding compressed pixel data","l":"/api-input#metadata"},{"t":"stats","d":"Access to pixel-derived image statistics for every channel in the image. A Promise is returned when callback is not provided.","k":"stats access pixel derived statistics channel promise","l":"/api-input#stats"},{"t":"toFile","d":"Write output image data to a file.","k":"tofile write output data file","l":"/api-output#tofile"},{"t":"toBuffer","d":"Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.","k":"tobuffer write output buffer jpeg png webp avif tiff gif raw pixel data","l":"/api-output#tobuffer"},{"t":"withMetadata","d":"Include all metadata EXIF, XMP, IPTC from the input image in the output image. This will also convert to and add a web-friendly sRGB ICC profile unless a custom output profile is provided.","k":"withmetadata metadata exif xmp iptc input output convert add web friendly srgb icc profile custom","l":"/api-output#withmetadata"},{"t":"toFormat","d":"Force output to a given format.","k":"toformat force output format","l":"/api-output#toformat"},{"t":"jpeg","d":"Use these JPEG options for output image.","k":"jpeg output quality progressive optimisecoding optimizecoding mozjpeg optimisescans optimizescans force","l":"/api-output#jpeg"},{"t":"png","d":"Use these PNG options for output image.","k":"png output","l":"/api-output#png"},{"t":"webp","d":"Use these WebP options for output image.","k":"webp output quality alphaquality lossless nearlossless smartsubsample effort loop delay minsize mixed force","l":"/api-output#webp"},{"t":"gif","d":"Use these GIF options for the output image.","k":"gif output","l":"/api-output#gif"},{"t":"tiff","d":"Use these TIFF options for output image.","k":"tiff output","l":"/api-output#tiff"},{"t":"avif","d":"Use these AVIF options for output image.","k":"avif output","l":"/api-output#avif"},{"t":"heif","d":"Use these HEIF options for output image.","k":"heif output","l":"/api-output#heif"},{"t":"raw","d":"Force output to be raw, uncompressed pixel data. Pixel ordering is left-to-right, top-to-bottom, without padding. Channel ordering will be RGB or RGBA for non-greyscale colourspaces.","k":"raw force output uncompressed pixel data ordering left right top bottom padding channel rgb rgba greyscale colourspaces depth size overlap angle background skipblanks container layout centre center basename","l":"/api-output#raw"},{"t":"timeout","d":"Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour.","k":"timeout processing seconds zero continue indefinitely behaviour","l":"/api-output#timeout"},{"t":"resize","d":"Resize image to width, height or width x height.","k":"resize width height","l":"/api-resize#resize"},{"t":"extend","d":"Extends/pads the edges of the image with the provided background colour. This operation will always occur after resizing and extraction, if any.","k":"extend extends pads edges background colour operation resizing extraction","l":"/api-resize#extend"},{"t":"extract","d":"Extract/crop a region of the image.","k":"extract crop region","l":"/api-resize#extract"},{"t":"trim","d":"Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.","k":"trim pixels edges contain similar background colour defaults top left pixel","l":"/api-resize#trim"},{"t":"composite","d":"Composite images over the processed resized, extracted etc. image.","k":"composite images processed resized extracted","l":"/api-composite#composite"},{"t":"rotate","d":"Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.","k":"rotate output explicit angle auto orient exif orientation tag","l":"/api-operation#rotate"},{"t":"flip","d":"Flip the image about the vertical Y axis. This always occurs before rotation, if any. The use of flip implies the removal of the EXIF Orientation tag, if any.","k":"flip vertical axis rotation removal exif orientation tag","l":"/api-operation#flip"},{"t":"flop","d":"Flop the image about the horizontal X axis. This always occurs before rotation, if any. The use of flop implies the removal of the EXIF Orientation tag, if any.","k":"flop horizontal axis rotation removal exif orientation tag","l":"/api-operation#flop"},{"t":"affine","d":"Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.","k":"affine transform operation resizing extraction rotation","l":"/api-operation#affine"},{"t":"sharpen","d":"Sharpen the image.","k":"sharpen","l":"/api-operation#sharpen"},{"t":"median","d":"Apply median filter. When used without parameters the default window is 3x3.","k":"median apply filter parameters window","l":"/api-operation#median"},{"t":"blur","d":"Blur the image.","k":"blur","l":"/api-operation#blur"},{"t":"flatten","d":"Merge alpha transparency channel, if any, with a background, then remove the alpha channel.","k":"flatten merge alpha transparency channel background remove","l":"/api-operation#flatten"},{"t":"gamma","d":"Apply a gamma correction by reducing the encoding darken pre-resize at a factor of 1/gamma then increasing the encoding brighten post-resize at a factor of gamma. This can improve the perceived bright","k":"gamma apply correction reducing encoding darken pre resize factor increasing brighten post improve perceived bright","l":"/api-operation#gamma"},{"t":"negate","d":"Produce the negative of the image.","k":"negate negative alpha","l":"/api-operation#negate"},{"t":"normalise","d":"Enhance output image contrast by stretching its luminance to cover the full dynamic range.","k":"normalise enhance output contrast stretching luminance cover full dynamic range","l":"/api-operation#normalise"},{"t":"normalize","d":"Alternative spelling of normalise.","k":"normalize normalise","l":"/api-operation#normalize"},{"t":"clahe","d":"Perform contrast limiting adaptive histogram equalization CLAHE10.","k":"clahe contrast limiting adaptive histogram equalization","l":"/api-operation#clahe"},{"t":"convolve","d":"Convolve the image with the specified kernel.","k":"convolve kernel","l":"/api-operation#convolve"},{"t":"threshold","d":"Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.","k":"threshold pixel greater equal otherwise greyscale grayscale","l":"/api-operation#threshold"},{"t":"boolean","d":"Perform a bitwise boolean operation with operand image.","k":"boolean bitwise operation operand","l":"/api-operation#boolean"},{"t":"linear","d":"Apply the linear formula a input b to the image to adjust image levels.","k":"linear apply formula input adjust levels","l":"/api-operation#linear"},{"t":"recomb","d":"Recomb the image with the specified matrix.","k":"recomb matrix","l":"/api-operation#recomb"},{"t":"modulate","d":"Transforms the image using brightness, saturation, hue rotation, and lightness. Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas","k":"modulate transforms brightness saturation hue rotation lightness operate luminance difference being multiplicative whereas","l":"/api-operation#modulate"},{"t":"removeAlpha","d":"Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.","k":"removealpha remove alpha channel","l":"/api-channel#removealpha"},{"t":"ensureAlpha","d":"Ensure the output image has an alpha transparency channel. If missing, the added alpha channel will have the specified transparency level, defaulting to fully-opaque 1. This is a no-op if the image al","k":"ensurealpha output alpha transparency channel missing added level defaulting fully opaque","l":"/api-channel#ensurealpha"},{"t":"extractChannel","d":"Extract a single channel from a multi-channel image.","k":"extractchannel extract single channel multi","l":"/api-channel#extractchannel"},{"t":"joinChannel","d":"Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace. By default the output image will be web-friendly sRGB, with additio","k":"joinchannel join one channels meaning added depends output colourspace tocolourspace web friendly srgb additio","l":"/api-channel#joinchannel"},{"t":"bandbool","d":"Perform a bitwise boolean operation on all input image channels bands to produce a single channel output image.","k":"bandbool bitwise boolean operation input channels bands single channel output","l":"/api-channel#bandbool"},{"t":"tint","d":"Tint the image using the provided chroma while preserving the image luminance. An alpha channel may be present and will be unchanged by the operation.","k":"tint chroma preserving luminance alpha channel present unchanged operation","l":"/api-colour#tint"},{"t":"greyscale","d":"Convert to 8-bit greyscale 256 shades of grey. This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use gamma with greyscale for the best results. By default th","k":"greyscale convert bit shades grey linear operation input colour space srgb gamma best results","l":"/api-colour#greyscale"},{"t":"grayscale","d":"Alternative spelling of greyscale.","k":"grayscale greyscale","l":"/api-colour#grayscale"},{"t":"pipelineColourspace","d":"Set the pipeline colourspace.","k":"pipeline colourspace","l":"/api-colour#pipelinecolourspace"},{"t":"pipelineColorspace","d":"Alternative spelling of pipelineColourspace.","k":"","l":"/api-colour#pipelinecolorspace"},{"t":"toColourspace","d":"Set the output colourspace. By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.","k":"tocolourspace output colourspace web friendly srgb additional channels interpreted alpha","l":"/api-colour#tocolourspace"},{"t":"toColorspace","d":"Alternative spelling of toColourspace.","k":"tocolorspace tocolourspace","l":"/api-colour#tocolorspace"},{"t":"format","d":"An Object containing nested boolean values representing the available input and output formats/methods.","k":"format object nested boolean representing available input output formats methods","l":"/api-utility#format"},{"t":"interpolators","d":"An Object containing the available interpolators and their proper values","k":"interpolators object available proper","l":"/api-utility#interpolators"},{"t":"versions","d":"An Object containing the version numbers of libvips and its dependencies.","k":"versions object version numbers libvips dependencies","l":"/api-utility#versions"},{"t":"vendor","d":"An Object containing the platform and architecture of the current and installed vendored binaries.","k":"vendor object platform architecture installed vendored binaries","l":"/api-utility#vendor"},{"t":"cache","d":"Gets or, when options are provided, sets the limits of libvips operation cache. Existing entries in the cache will be trimmed after any change in limits. This method always returns cache statistics, u","k":"cache limits libvips operation existing entries trimmed change method returns statistics memory files items","l":"/api-utility#cache"},{"t":"concurrency","d":"Gets or, when a concurrency is provided, sets the maximum number of threads libvips should use to process each image. These are from a thread pool managed by glib, which helps avoid the overhead of cr","k":"concurrency maximum number threads libvips process thread pool managed glib helps avoid overhead","l":"/api-utility#concurrency"},{"t":"queue","d":"An EventEmitter that emits a change event when a task is either","k":"queue eventemitter emits change event","l":"/api-utility#queue"},{"t":"counters","d":"Provides access to internal task counters.","k":"counters provides access internal","l":"/api-utility#counters"},{"t":"simd","d":"Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support.","k":"simd vector unit instructions libvips compiled liborc","l":"/api-utility#simd"}] \ No newline at end of file +[{"t":"Prerequisites","d":"Node.js 14.15.0","k":"prerequisites node","l":"/install#prerequisites"},{"t":"Prebuilt binaries","d":"Ready-compiled sharp and libvips binaries are provided for use on the most common platforms macOS x64 10.13 macOS ARM64 Linux x64 glibc 2.17, musl 1.1.24, CPU with SSE4.2 Linux ARM64 glibc 2.17, musl","k":"prebuilt binaries compiled sharp libvips common platforms macos arm linux glibc musl cpu sse","l":"/install#prebuilt-binaries"},{"t":"Common problems","d":"The architecture and platform of Node.js used for npm install must be the same as the architecture and platform of Node.js used at runtime. See the cross-platform","k":"common problems architecture platform node npm install runtime cross","l":"/install#common-problems"},{"t":"Apple M1","d":"Prebuilt sharp and libvips binaries have been provided for macOS on ARM64 since sharp v0.29.0.","k":"apple prebuilt sharp libvips binaries macos arm","l":"/install#apple-m1"},{"t":"Custom libvips","d":"To use a custom, globally-installed version of libvips instead of the provided binaries, make sure it is at least the version listed under config.libvips in the package.json file and that it can be lo","k":"custom libvips globally installed version instead binaries listed config package json file","l":"/install#custom-libvips"},{"t":"Building from source","d":"This module will be compiled from source at npm install time when a globally-installed libvips is detected set the SHARP_IGNORE_GLOBAL_LIBVIPS environment variable to skip this, prebuilt sharp binarie","k":"building source module compiled npm install time globally installed libvips detected environment variable skip prebuilt sharp binarie","l":"/install#building-from-source"},{"t":"Custom prebuilt binaries","d":"This is an advanced approach that most people will not require.","k":"custom prebuilt binaries advanced approach people require","l":"/install#custom-prebuilt-binaries"},{"t":"Prebuilt sharp binaries","d":"To install the prebuilt sharp binaries from a custom URL, set the sharp_binary_host npm config option or the npm_config_sharp_binary_host environment variable. To install the prebuilt sharp binaries f","k":"prebuilt sharp binaries install custom url npm config option environment variable","l":"/install#prebuilt-sharp-binaries"},{"t":"Prebuilt libvips binaries","d":"To install the prebuilt libvips binaries from a custom URL, set the sharp_libvips_binary_host npm config option or the npm_config_sharp_libvips_binary_host environment variable. To install the prebuil","k":"prebuilt libvips binaries install custom url npm config option environment variable prebuil","l":"/install#prebuilt-libvips-binaries"},{"t":"Chinese mirror","d":"A mirror site based in China, provided by Alibaba, contains binaries for both sharp and libvips. To use this either set the following configuration sh npm config set sharp_binary_host https//npmmirror","k":"chinese mirror china alibaba binaries sharp libvips configuration npm config https npmmirror","l":"/install#chinese-mirror"},{"t":"FreeBSD","d":"The vips package must be installed before npm install is run. sh pkg install -y pkgconf vips sh cd /usr/ports/graphics/vips/ make install clean","k":"freebsd vips package installed npm install run pkg pkgconf usr ports graphics clean","l":"/install#freebsd"},{"t":"Linux memory allocator","d":"The default memory allocator on most glibc-based Linux systems e.g. Debian, Red Hat is unsuitable for long-running, multi-threaded processes that involve lots of small memory allocations. For this rea","k":"linux memory allocator glibc systems debian red hat long running multi threaded processes small allocations rea","l":"/install#linux-memory-allocator"},{"t":"Heroku","d":"Add the jemalloc buildpack to reduce the effects of memory fragmentation. Set NODE_MODULES_CACHE","k":"heroku add jemalloc buildpack reduce effects memory fragmentation","l":"/install#heroku"},{"t":"AWS Lambda","d":"The node_modules directory of the deployment package must include binaries for the Linux x64 platform. When building your deployment package on machines other than Linux x64 glibc, run the following a","k":"aws lambda nodemodules directory deployment package binaries linux platform building your machines glibc run","l":"/install#aws-lambda"},{"t":"webpack","d":"Ensure sharp is excluded from bundling via the externals configuration. js externals sharp commonjs sharp","k":"webpack sharp excluded bundling via externals configuration commonjs","l":"/install#webpack"},{"t":"esbuild","d":"Ensure sharp is excluded from bundling via the external","k":"esbuild sharp excluded bundling via external","l":"/install#esbuild"},{"t":"Fonts","d":"When creating text images or rendering SVG images that contain text elements, fontconfig is used to find the relevant fonts. On Windows and macOS systems, all system fonts are available for use. On ma","k":"fonts creating text images rendering svg contain elements fontconfig find relevant windows macos systems system available","l":"/install#fonts"},{"t":"Worker threads","d":"On some platforms, including glibc-based Linux, the main thread must call requiresharp _before_ worker threads are created. This is to ensure shared libraries remain loaded in memory until after all t","k":"worker threads platforms glibc linux main thread shared libraries remain loaded memory","l":"/install#worker-threads"},{"t":"Canvas and Windows","d":"The prebuilt binaries provided by canvas for Windows from v2.7.0 onwards depend on the Visual C Runtime MSVCRT. These conflict with the binaries provided by sharp, which depend on the more modern Univ","k":"canvas windows prebuilt binaries onwards depend visual runtime msvcrt conflict sharp modern univ","l":"/install#canvas-and-windows"},{"t":"Sharp","d":"Constructor factory to create an instance of sharp, to which further methods are chained.","k":"sharp constructor factory create instance further methods chained","l":"/api-constructor#sharp"},{"t":"clone","d":"Take a snapshot of the Sharp instance, returning a new instance. Cloned instances inherit the input of their parent instance. This allows multiple output Streams and therefore multiple processing pipe","k":"clone snapshot sharp instance returning new cloned instances inherit input parent multiple output streams processing pipe","l":"/api-constructor#clone"},{"t":"metadata","d":"Fast access to uncached image metadata without decoding any compressed pixel data.","k":"metadata fast access uncached decoding compressed pixel data","l":"/api-input#metadata"},{"t":"stats","d":"Access to pixel-derived image statistics for every channel in the image. A Promise is returned when callback is not provided.","k":"stats access pixel derived statistics channel promise","l":"/api-input#stats"},{"t":"toFile","d":"Write output image data to a file.","k":"tofile write output data file","l":"/api-output#tofile"},{"t":"toBuffer","d":"Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.","k":"tobuffer write output buffer jpeg png webp avif tiff gif raw pixel data","l":"/api-output#tobuffer"},{"t":"withMetadata","d":"Include all metadata EXIF, XMP, IPTC from the input image in the output image. This will also convert to and add a web-friendly sRGB ICC profile unless a custom output profile is provided.","k":"withmetadata metadata exif xmp iptc input output convert add web friendly srgb icc profile custom","l":"/api-output#withmetadata"},{"t":"toFormat","d":"Force output to a given format.","k":"toformat force output format","l":"/api-output#toformat"},{"t":"jpeg","d":"Use these JPEG options for output image.","k":"jpeg output quality progressive optimisecoding optimizecoding mozjpeg optimisescans optimizescans force","l":"/api-output#jpeg"},{"t":"png","d":"Use these PNG options for output image.","k":"png output","l":"/api-output#png"},{"t":"webp","d":"Use these WebP options for output image.","k":"webp output quality alphaquality lossless nearlossless smartsubsample effort loop delay minsize mixed force","l":"/api-output#webp"},{"t":"gif","d":"Use these GIF options for the output image.","k":"gif output","l":"/api-output#gif"},{"t":"tiff","d":"Use these TIFF options for output image.","k":"tiff output","l":"/api-output#tiff"},{"t":"avif","d":"Use these AVIF options for output image.","k":"avif output","l":"/api-output#avif"},{"t":"heif","d":"Use these HEIF options for output image.","k":"heif output","l":"/api-output#heif"},{"t":"jxl","d":"Use these JPEG-XL JXL options for output image.","k":"jxl jpeg output","l":"/api-output#jxl"},{"t":"raw","d":"Force output to be raw, uncompressed pixel data. Pixel ordering is left-to-right, top-to-bottom, without padding. Channel ordering will be RGB or RGBA for non-greyscale colourspaces.","k":"raw force output uncompressed pixel data ordering left right top bottom padding channel rgb rgba greyscale colourspaces depth size overlap angle background skipblanks container layout centre center basename","l":"/api-output#raw"},{"t":"timeout","d":"Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour.","k":"timeout processing seconds zero continue indefinitely behaviour","l":"/api-output#timeout"},{"t":"resize","d":"Resize image to width, height or width x height.","k":"resize width height","l":"/api-resize#resize"},{"t":"extend","d":"Extends/pads the edges of the image with the provided background colour. This operation will always occur after resizing and extraction, if any.","k":"extend extends pads edges background colour operation resizing extraction","l":"/api-resize#extend"},{"t":"extract","d":"Extract/crop a region of the image.","k":"extract crop region","l":"/api-resize#extract"},{"t":"trim","d":"Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.","k":"trim pixels edges contain similar background colour defaults top left pixel","l":"/api-resize#trim"},{"t":"composite","d":"Composite images over the processed resized, extracted etc. image.","k":"composite images processed resized extracted","l":"/api-composite#composite"},{"t":"rotate","d":"Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.","k":"rotate output explicit angle auto orient exif orientation tag","l":"/api-operation#rotate"},{"t":"flip","d":"Flip the image about the vertical Y axis. This always occurs before rotation, if any. The use of flip implies the removal of the EXIF Orientation tag, if any.","k":"flip vertical axis rotation removal exif orientation tag","l":"/api-operation#flip"},{"t":"flop","d":"Flop the image about the horizontal X axis. This always occurs before rotation, if any. The use of flop implies the removal of the EXIF Orientation tag, if any.","k":"flop horizontal axis rotation removal exif orientation tag","l":"/api-operation#flop"},{"t":"affine","d":"Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.","k":"affine transform operation resizing extraction rotation","l":"/api-operation#affine"},{"t":"sharpen","d":"Sharpen the image.","k":"sharpen","l":"/api-operation#sharpen"},{"t":"median","d":"Apply median filter. When used without parameters the default window is 3x3.","k":"median apply filter parameters window","l":"/api-operation#median"},{"t":"blur","d":"Blur the image.","k":"blur","l":"/api-operation#blur"},{"t":"flatten","d":"Merge alpha transparency channel, if any, with a background, then remove the alpha channel.","k":"flatten merge alpha transparency channel background remove","l":"/api-operation#flatten"},{"t":"gamma","d":"Apply a gamma correction by reducing the encoding darken pre-resize at a factor of 1/gamma then increasing the encoding brighten post-resize at a factor of gamma. This can improve the perceived bright","k":"gamma apply correction reducing encoding darken pre resize factor increasing brighten post improve perceived bright","l":"/api-operation#gamma"},{"t":"negate","d":"Produce the negative of the image.","k":"negate negative alpha","l":"/api-operation#negate"},{"t":"normalise","d":"Enhance output image contrast by stretching its luminance to cover the full dynamic range.","k":"normalise enhance output contrast stretching luminance cover full dynamic range","l":"/api-operation#normalise"},{"t":"normalize","d":"Alternative spelling of normalise.","k":"normalize normalise","l":"/api-operation#normalize"},{"t":"clahe","d":"Perform contrast limiting adaptive histogram equalization CLAHE10.","k":"clahe contrast limiting adaptive histogram equalization","l":"/api-operation#clahe"},{"t":"convolve","d":"Convolve the image with the specified kernel.","k":"convolve kernel","l":"/api-operation#convolve"},{"t":"threshold","d":"Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.","k":"threshold pixel greater equal otherwise greyscale grayscale","l":"/api-operation#threshold"},{"t":"boolean","d":"Perform a bitwise boolean operation with operand image.","k":"boolean bitwise operation operand","l":"/api-operation#boolean"},{"t":"linear","d":"Apply the linear formula a input b to the image to adjust image levels.","k":"linear apply formula input adjust levels","l":"/api-operation#linear"},{"t":"recomb","d":"Recomb the image with the specified matrix.","k":"recomb matrix","l":"/api-operation#recomb"},{"t":"modulate","d":"Transforms the image using brightness, saturation, hue rotation, and lightness. Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas","k":"modulate transforms brightness saturation hue rotation lightness operate luminance difference being multiplicative whereas","l":"/api-operation#modulate"},{"t":"removeAlpha","d":"Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.","k":"removealpha remove alpha channel","l":"/api-channel#removealpha"},{"t":"ensureAlpha","d":"Ensure the output image has an alpha transparency channel. If missing, the added alpha channel will have the specified transparency level, defaulting to fully-opaque 1. This is a no-op if the image al","k":"ensurealpha output alpha transparency channel missing added level defaulting fully opaque","l":"/api-channel#ensurealpha"},{"t":"extractChannel","d":"Extract a single channel from a multi-channel image.","k":"extractchannel extract single channel multi","l":"/api-channel#extractchannel"},{"t":"joinChannel","d":"Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace. By default the output image will be web-friendly sRGB, with additio","k":"joinchannel join one channels meaning added depends output colourspace tocolourspace web friendly srgb additio","l":"/api-channel#joinchannel"},{"t":"bandbool","d":"Perform a bitwise boolean operation on all input image channels bands to produce a single channel output image.","k":"bandbool bitwise boolean operation input channels bands single channel output","l":"/api-channel#bandbool"},{"t":"tint","d":"Tint the image using the provided chroma while preserving the image luminance. An alpha channel may be present and will be unchanged by the operation.","k":"tint chroma preserving luminance alpha channel present unchanged operation","l":"/api-colour#tint"},{"t":"greyscale","d":"Convert to 8-bit greyscale 256 shades of grey. This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use gamma with greyscale for the best results. By default th","k":"greyscale convert bit shades grey linear operation input colour space srgb gamma best results","l":"/api-colour#greyscale"},{"t":"grayscale","d":"Alternative spelling of greyscale.","k":"grayscale greyscale","l":"/api-colour#grayscale"},{"t":"pipelineColourspace","d":"Set the pipeline colourspace.","k":"pipeline colourspace","l":"/api-colour#pipelinecolourspace"},{"t":"pipelineColorspace","d":"Alternative spelling of pipelineColourspace.","k":"","l":"/api-colour#pipelinecolorspace"},{"t":"toColourspace","d":"Set the output colourspace. By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.","k":"tocolourspace output colourspace web friendly srgb additional channels interpreted alpha","l":"/api-colour#tocolourspace"},{"t":"toColorspace","d":"Alternative spelling of toColourspace.","k":"tocolorspace tocolourspace","l":"/api-colour#tocolorspace"},{"t":"format","d":"An Object containing nested boolean values representing the available input and output formats/methods.","k":"format object nested boolean representing available input output formats methods","l":"/api-utility#format"},{"t":"interpolators","d":"An Object containing the available interpolators and their proper values","k":"interpolators object available proper","l":"/api-utility#interpolators"},{"t":"versions","d":"An Object containing the version numbers of libvips and its dependencies.","k":"versions object version numbers libvips dependencies","l":"/api-utility#versions"},{"t":"vendor","d":"An Object containing the platform and architecture of the current and installed vendored binaries.","k":"vendor object platform architecture installed vendored binaries","l":"/api-utility#vendor"},{"t":"cache","d":"Gets or, when options are provided, sets the limits of libvips operation cache. Existing entries in the cache will be trimmed after any change in limits. This method always returns cache statistics, u","k":"cache limits libvips operation existing entries trimmed change method returns statistics memory files items","l":"/api-utility#cache"},{"t":"concurrency","d":"Gets or, when a concurrency is provided, sets the maximum number of threads libvips should use to process each image. These are from a thread pool managed by glib, which helps avoid the overhead of cr","k":"concurrency maximum number threads libvips process thread pool managed glib helps avoid overhead","l":"/api-utility#concurrency"},{"t":"queue","d":"An EventEmitter that emits a change event when a task is either","k":"queue eventemitter emits change event","l":"/api-utility#queue"},{"t":"counters","d":"Provides access to internal task counters.","k":"counters provides access internal","l":"/api-utility#counters"},{"t":"simd","d":"Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support.","k":"simd vector unit instructions libvips compiled liborc","l":"/api-utility#simd"}] \ No newline at end of file diff --git a/lib/constructor.js b/lib/constructor.js index b7927e4de..51947e5b6 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -308,6 +308,10 @@ const Sharp = function (input, options) { heifCompression: 'av1', heifEffort: 4, heifChromaSubsampling: '4:4:4', + jxlDistance: 1, + jxlDecodingTier: 0, + jxlEffort: 7, + jxlLossless: false, rawDepth: 'uchar', tileSize: 256, tileOverlap: 0, diff --git a/lib/output.js b/lib/output.js index b63ea8ecf..ee5514f8a 100644 --- a/lib/output.js +++ b/lib/output.js @@ -22,7 +22,8 @@ const formats = new Map([ ['jp2', 'jp2'], ['jpx', 'jp2'], ['j2k', 'jp2'], - ['j2c', 'jp2'] + ['j2c', 'jp2'], + ['jxl', 'jxl'] ]); const jp2Regex = /\.jp[2x]|j2[kc]$/i; @@ -938,6 +939,71 @@ function heif (options) { return this._updateFormatOut('heif', options); } +/** + * Use these JPEG-XL (JXL) options for output image. + * + * This feature is experimental, please do not use in production systems. + * + * Requires libvips compiled with support for libjxl. + * The prebuilt binaries do not include this - see + * {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}. + * + * Image metadata (EXIF, XMP) is unsupported. + * + * @since 0.31.3 + * + * @param {Object} [options] - output options + * @param {number} [options.distance=1.0] - maximum encoding error, between 0 (highest quality) and 15 (lowest quality) + * @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified + * @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality) + * @param {boolean} [options.lossless=false] - use lossless compression + * @param {number} [options.effort=7] - CPU effort, between 3 (fastest) and 9 (slowest) + * @returns {Sharp} + * @throws {Error} Invalid options + */ +function jxl (options) { + if (is.object(options)) { + if (is.defined(options.quality)) { + if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { + // https://github.com/libjxl/libjxl/blob/0aeea7f180bafd6893c1db8072dcb67d2aa5b03d/tools/cjxl_main.cc#L640-L644 + this.options.jxlDistance = options.quality >= 30 + ? 0.1 + (100 - options.quality) * 0.09 + : 53 / 3000 * options.quality * options.quality - 23 / 20 * options.quality + 25; + } else { + throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality); + } + } else if (is.defined(options.distance)) { + if (is.number(options.distance) && is.inRange(options.distance, 0, 15)) { + this.options.jxlDistance = options.distance; + } else { + throw is.invalidParameterError('distance', 'number between 0.0 and 15.0', options.distance); + } + } + if (is.defined(options.decodingTier)) { + if (is.integer(options.decodingTier) && is.inRange(options.decodingTier, 0, 4)) { + this.options.jxlDecodingTier = options.decodingTier; + } else { + throw is.invalidParameterError('decodingTier', 'integer between 0 and 4', options.decodingTier); + } + } + if (is.defined(options.lossless)) { + if (is.bool(options.lossless)) { + this.options.jxlLossless = options.lossless; + } else { + throw is.invalidParameterError('lossless', 'boolean', options.lossless); + } + } + if (is.defined(options.effort)) { + if (is.integer(options.effort) && is.inRange(options.effort, 3, 9)) { + this.options.jxlEffort = options.effort; + } else { + throw is.invalidParameterError('effort', 'integer between 3 and 9', options.effort); + } + } + } + return this._updateFormatOut('jxl', options); +} + /** * Force output to be raw, uncompressed pixel data. * Pixel ordering is left-to-right, top-to-bottom, without padding. @@ -1308,6 +1374,7 @@ module.exports = function (Sharp) { tiff, avif, heif, + jxl, gif, raw, tile, diff --git a/src/common.cc b/src/common.cc index 3a208951f..c617cc710 100644 --- a/src/common.cc +++ b/src/common.cc @@ -207,6 +207,9 @@ namespace sharp { bool IsAvif(std::string const &str) { return EndsWith(str, ".avif") || EndsWith(str, ".AVIF"); } + bool IsJxl(std::string const &str) { + return EndsWith(str, ".jxl") || EndsWith(str, ".JXL"); + } bool IsDz(std::string const &str) { return EndsWith(str, ".dzi") || EndsWith(str, ".DZI"); } @@ -237,6 +240,7 @@ namespace sharp { case ImageType::PPM: id = "ppm"; break; case ImageType::FITS: id = "fits"; break; case ImageType::EXR: id = "exr"; break; + case ImageType::JXL: id = "jxl"; break; case ImageType::VIPS: id = "vips"; break; case ImageType::RAW: id = "raw"; break; case ImageType::UNKNOWN: id = "unknown"; break; @@ -281,6 +285,8 @@ namespace sharp { { "VipsForeignLoadPpmFile", ImageType::PPM }, { "VipsForeignLoadFitsFile", ImageType::FITS }, { "VipsForeignLoadOpenexr", ImageType::EXR }, + { "VipsForeignLoadJxlFile", ImageType::JXL }, + { "VipsForeignLoadJxlBuffer", ImageType::JXL }, { "VipsForeignLoadVips", ImageType::VIPS }, { "VipsForeignLoadVipsFile", ImageType::VIPS }, { "VipsForeignLoadRaw", ImageType::RAW } diff --git a/src/common.h b/src/common.h index b9ae02635..d7cbe32de 100644 --- a/src/common.h +++ b/src/common.h @@ -152,6 +152,7 @@ namespace sharp { PPM, FITS, EXR, + JXL, VIPS, RAW, UNKNOWN, @@ -182,6 +183,7 @@ namespace sharp { bool IsHeic(std::string const &str); bool IsHeif(std::string const &str); bool IsAvif(std::string const &str); + bool IsJxl(std::string const &str); bool IsDz(std::string const &str); bool IsDzZip(std::string const &str); bool IsV(std::string const &str); diff --git a/src/pipeline.cc b/src/pipeline.cc index 854be0d14..115a1b908 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -939,6 +939,21 @@ class PipelineWorker : public Napi::AsyncWorker { area->free_fn = nullptr; vips_area_unref(area); baton->formatOut = "dz"; + } else if (baton->formatOut == "jxl" || + (baton->formatOut == "input" && inputImageType == sharp::ImageType::JXL)) { + // Write JXL to buffer + image = sharp::RemoveAnimationProperties(image); + VipsArea *area = reinterpret_cast(image.jxlsave_buffer(VImage::option() + ->set("strip", !baton->withMetadata) + ->set("distance", baton->jxlDistance) + ->set("tier", baton->jxlDecodingTier) + ->set("effort", baton->jxlEffort) + ->set("lossless", baton->jxlLossless))); + baton->bufferOut = static_cast(area->data); + baton->bufferOutLength = area->length; + area->free_fn = nullptr; + vips_area_unref(area); + baton->formatOut = "jxl"; } else if (baton->formatOut == "raw" || (baton->formatOut == "input" && inputImageType == sharp::ImageType::RAW)) { // Write raw, uncompressed image data to buffer @@ -977,6 +992,7 @@ class PipelineWorker : public Napi::AsyncWorker { bool const isTiff = sharp::IsTiff(baton->fileOut); bool const isJp2 = sharp::IsJp2(baton->fileOut); bool const isHeif = sharp::IsHeif(baton->fileOut); + bool const isJxl = sharp::IsJxl(baton->fileOut); bool const isDz = sharp::IsDz(baton->fileOut); bool const isDzZip = sharp::IsDzZip(baton->fileOut); bool const isV = sharp::IsV(baton->fileOut); @@ -1094,6 +1110,17 @@ class PipelineWorker : public Napi::AsyncWorker { ? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON) ->set("lossless", baton->heifLossless)); baton->formatOut = "heif"; + } else if (baton->formatOut == "jxl" || (mightMatchInput && isJxl) || + (willMatchInput && inputImageType == sharp::ImageType::JXL)) { + // Write JXL to file + image = sharp::RemoveAnimationProperties(image); + image.jxlsave(const_cast(baton->fileOut.data()), VImage::option() + ->set("strip", !baton->withMetadata) + ->set("distance", baton->jxlDistance) + ->set("tier", baton->jxlDecodingTier) + ->set("effort", baton->jxlEffort) + ->set("lossless", baton->jxlLossless)); + baton->formatOut = "jxl"; } else if (baton->formatOut == "dz" || isDz || isDzZip) { // Write DZ to file if (isDzZip) { @@ -1579,6 +1606,10 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) { options, "heifCompression", VIPS_TYPE_FOREIGN_HEIF_COMPRESSION); baton->heifEffort = sharp::AttrAsUint32(options, "heifEffort"); baton->heifChromaSubsampling = sharp::AttrAsStr(options, "heifChromaSubsampling"); + baton->jxlDistance = sharp::AttrAsDouble(options, "jxlDistance"); + baton->jxlDecodingTier = sharp::AttrAsUint32(options, "jxlDecodingTier"); + baton->jxlEffort = sharp::AttrAsUint32(options, "jxlEffort"); + baton->jxlLossless = sharp::AttrAsBool(options, "jxlLossless"); baton->rawDepth = sharp::AttrAsEnum(options, "rawDepth", VIPS_TYPE_BAND_FORMAT); // Animated output properties if (sharp::HasAttr(options, "loop")) { diff --git a/src/pipeline.h b/src/pipeline.h index 33c227dbf..78e2b5e09 100644 --- a/src/pipeline.h +++ b/src/pipeline.h @@ -182,6 +182,10 @@ struct PipelineBaton { int heifEffort; std::string heifChromaSubsampling; bool heifLossless; + double jxlDistance; + int jxlDecodingTier; + int jxlEffort; + bool jxlLossless; VipsBandFormat rawDepth; std::string err; bool withMetadata; @@ -335,6 +339,10 @@ struct PipelineBaton { heifEffort(4), heifChromaSubsampling("4:4:4"), heifLossless(false), + jxlDistance(1.0), + jxlDecodingTier(0), + jxlEffort(7), + jxlLossless(false), rawDepth(VIPS_FORMAT_UCHAR), withMetadata(false), withMetadataOrientation(-1), diff --git a/src/utilities.cc b/src/utilities.cc index 8f34fb206..da638289a 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -115,7 +115,7 @@ Napi::Value format(const Napi::CallbackInfo& info) { Napi::Object format = Napi::Object::New(env); for (std::string const f : { "jpeg", "png", "webp", "tiff", "magick", "openslide", "dz", - "ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k" + "ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl" }) { // Input const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str()); diff --git a/test/unit/jxl.js b/test/unit/jxl.js new file mode 100644 index 000000000..f7bfad17b --- /dev/null +++ b/test/unit/jxl.js @@ -0,0 +1,97 @@ +'use strict'; + +const assert = require('assert'); + +const sharp = require('../../'); + +describe('JXL', () => { + it('called without options does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl(); + }); + }); + it('valid distance does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl({ distance: 2.3 }); + }); + }); + it('invalid distance should throw an error', () => { + assert.throws(() => { + sharp().jxl({ distance: 15.1 }); + }); + }); + it('non-numeric distance should throw an error', () => { + assert.throws(() => { + sharp().jxl({ distance: 'fail' }); + }); + }); + it('valid quality > 30 does not throw an error', () => { + const s = sharp(); + assert.doesNotThrow(() => { + s.jxl({ quality: 80 }); + }); + assert.strictEqual(s.options.jxlDistance, 1.9); + }); + it('valid quality < 30 does not throw an error', () => { + const s = sharp(); + assert.doesNotThrow(() => { + s.jxl({ quality: 20 }); + }); + assert.strictEqual(s.options.jxlDistance, 9.066666666666666); + }); + it('valid quality does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl({ quality: 80 }); + }); + }); + it('invalid quality should throw an error', () => { + assert.throws(() => { + sharp().jxl({ quality: 101 }); + }); + }); + it('non-numeric quality should throw an error', () => { + assert.throws(() => { + sharp().jxl({ quality: 'fail' }); + }); + }); + it('valid decodingTier does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl({ decodingTier: 2 }); + }); + }); + it('invalid decodingTier should throw an error', () => { + assert.throws(() => { + sharp().jxl({ decodingTier: 5 }); + }); + }); + it('non-numeric decodingTier should throw an error', () => { + assert.throws(() => { + sharp().jxl({ decodingTier: 'fail' }); + }); + }); + it('valid lossless does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl({ lossless: true }); + }); + }); + it('non-boolean lossless should throw an error', () => { + assert.throws(() => { + sharp().jxl({ lossless: 'fail' }); + }); + }); + it('valid effort does not throw an error', () => { + assert.doesNotThrow(() => { + sharp().jxl({ effort: 6 }); + }); + }); + it('out of range effort should throw an error', () => { + assert.throws(() => { + sharp().jxl({ effort: 10 }); + }); + }); + it('invalid effort should throw an error', () => { + assert.throws(() => { + sharp().jxl({ effort: 'fail' }); + }); + }); +});