Package limn.graphics

Record Class ImageFormat

java.lang.Object
java.lang.Record
limn.graphics.ImageFormat
Record Components:
mediaType - lower-case IANA media type, e.g. "image/png"

public record ImageFormat(String mediaType) extends Record
An encoded image format, named by its IANA media type: what a caller asks Images.encode(Image, ImageFormat) for and what an ImageEncoder declares it can produce.

Deliberately a value and not an enum. A format is contributed by whichever encoder is installed, so a closed set would mean that adding JPEG or WebP required a toolkit release even though nothing in the toolkit would encode it. The price is that a misspelled media type is a runtime failure ("no encoder accepts …") rather than a compile error, which is why PNG is a constant: the one format the toolkit itself always provides never has to be spelled out.

The media type is the identity. It is trimmed and lower-cased on construction, so new ImageFormat("IMAGE/PNG") equals PNG, and an encoder may compare with equals rather than parsing the string. Parameters are not understood: "image/png; foo=bar" is a different format from "image/png" and nothing will accept it.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ImageFormat
    Portable Network Graphics: lossless, 8-bit RGBA with straight alpha, which is exactly Image's pixel contract, so a PNG round trip through this toolkit is bit-exact.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ImageFormat(String mediaType)
    Creates an instance of a ImageFormat record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the mediaType record component.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • PNG

      public static final ImageFormat PNG
      Portable Network Graphics: lossless, 8-bit RGBA with straight alpha, which is exactly Image's pixel contract, so a PNG round trip through this toolkit is bit-exact. Always encodable: the toolkit's own encoder is installed without a backend (see Images.installEncoder(limn.graphics.ImageEncoder)).
  • Constructor Details

    • ImageFormat

      public ImageFormat(String mediaType)
      Creates an instance of a ImageFormat record class.
      Parameters:
      mediaType - the value for the mediaType record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • mediaType

      public String mediaType()
      Returns the value of the mediaType record component.
      Returns:
      the value of the mediaType record component