Class WebPSupport

java.lang.Object
com.iizix.image.WebPSupport

public final class WebPSupport extends Object
WebP image support of ImageIO: the pure-Java reader of TwelveMonkeys ImageIO (imageio-webp 3.15.3 and the five jars it needs, in com.iizix.core/lib/image), which runs on every architecture, so a WebP image is read on x86-64 and on ARM64 alike (a Mac with Apple silicon, Windows on ARM, Linux ARM64), in the server's JVM and in the Designer's. It replaces webp-imageio 0.1.6 (order 512), a JNI wrapper of libwebp 1.0.0 with an x86-64 native only, which order 486 had to leave out on ARM64.

Registration. ImageIO's registry finds a reader through the service files of the jars on the class path of the thread that first touches it. On the server's plain class path that finds the reader; in the Designer's OSGi it does not (order 486 measured that the Designer's registry held no WebP reader at all: the service file lives inside the core bundle's class path, invisible to the thread that first touches the registry, and the TwelveMonkeys jars' own OSGi metadata needs a ServiceLoader mediator Eclipse does not carry). So SystemConfig's static initializer calls register() at core start: it registers the reader where the registry has none and does nothing where the service scan has found it. It calls it through registerAtStart(), which tells a class path without the plugin (one WARNING line) from a failure.

Reading only. IIZI reads WebP (a PWA icon or screenshot under a PNG or JPEG name, a profile picture, the favicon sources, thumbnailator) and never writes it: no WebP writer is registered, ImageIO.write(image,"webp",out) answers false and ImageIO.getImageWritersByMIMEType("image/webp") is empty - as it was in the Designer before. A writer is a decision of a later version (v5.3).

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The media type of WebP.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Tells whether the IIORegistry holds the WebP reader now.
    static boolean
    Tells whether a WebP writer is registered: false, IIZI writes no WebP (see the class comment).
    static boolean
    isWebP(byte[] head, int length)
    Tells whether the head of a file is a WebP image (the RIFF/WEBP signature).
    static int
    The number of WebP readers of the plugin registered: 1 after core start.
    static boolean
    Makes sure the IIORegistry holds the WebP reader: registers TwelveMonkeys' WebPImageReaderSpi when no provider of that class is registered, and does nothing when the registry's service scan has found it (or an earlier call registered it).
    static boolean
    Calls register() at core start (SystemConfig's static initializer) and logs its failure: ONE line at WARNING when the TwelveMonkeys plugin is absent from the class path - a tool that loads the core without its lib/image jars, such as the test load of LicenseSystemBuilder: WebP images are then not read, and nothing else is wrong - naming "imageio-webp-3.15.3.jar" and the missing class; SEVERE with the stack for any other failure.
    static Boolean
    Tells how the reader came into the registry at core start (the first register()): TRUE when that call registered it (the Designer's OSGi, where the service scan does not see the core bundle's jars), FALSE when the registry's service scan had found it already (a plain class path: the server), null when register() has not been called.
  • Field Details

  • Method Details

    • register

      public static boolean register()
      Makes sure the IIORegistry holds the WebP reader: registers TwelveMonkeys' WebPImageReaderSpi when no provider of that class is registered, and does nothing when the registry's service scan has found it (or an earlier call registered it). Called at core start by SystemConfig's static initializer; a later call registers the reader again only when it has been deregistered since.
      Returns:
      true when this call registered the reader, false when the registry held it already.
    • registerAtStart

      public static boolean registerAtStart()
      Calls register() at core start (SystemConfig's static initializer) and logs its failure: ONE line at WARNING when the TwelveMonkeys plugin is absent from the class path - a tool that loads the core without its lib/image jars, such as the test load of LicenseSystemBuilder: WebP images are then not read, and nothing else is wrong - naming "imageio-webp-3.15.3.jar" and the missing class; SEVERE with the stack for any other failure. Never throws.
      Returns:
      true when the call ended with the reader registered (by it or by the registry's service scan), false when it failed.
    • registeredAtStart

      public static Boolean registeredAtStart()
      Tells how the reader came into the registry at core start (the first register()): TRUE when that call registered it (the Designer's OSGi, where the service scan does not see the core bundle's jars), FALSE when the registry's service scan had found it already (a plain class path: the server), null when register() has not been called.
      Returns:
      The state, or null before core start.
    • hasReader

      public static boolean hasReader()
      Tells whether the IIORegistry holds the WebP reader now.
      Returns:
      true when a reader of the TwelveMonkeys WebP plugin is registered.
    • readerCount

      public static int readerCount()
      The number of WebP readers of the plugin registered: 1 after core start.
      Returns:
      The count.
    • hasWriter

      public static boolean hasWriter()
      Tells whether a WebP writer is registered: false, IIZI writes no WebP (see the class comment).
      Returns:
      true when any ImageWriterSpi of the media type image/webp is registered.
    • isWebP

      public static boolean isWebP(byte[] head, int length)
      Tells whether the head of a file is a WebP image (the RIFF/WEBP signature).
      Parameters:
      head - The first bytes of the file.
      length - The valid length of head.
      Returns:
      true for a WebP image.