Class Encode

java.lang.Object
is.galia.operation.Encode
All Implemented Interfaces:
Operation

public class Encode extends Object implements Operation

Encapsulates an image encoding operation.

Typically appears at the very end of an OperationList.

  • Field Details

  • Constructor Details

    • Encode

      public Encode(Format format)
  • Method Details

    • freeze

      public void freeze()
      Description copied from interface: Operation
      Makes the instance unmodifiable. When frozen, mutation methods should throw an IllegalStateException and getters should return immutable values, if possible. (But they should do that anyway.)
      Specified by:
      freeze in interface Operation
    • getBackgroundColor

      public Color getBackgroundColor()
      Returns:
      Color with which to fill the empty portions of the image when getFormat() returns a format that does not support transparency and when either rotating by a non-90-degree multiple, or when flattening an image with alpha. May be null.
    • getFormat

      public Format getFormat()
    • getMaxComponentSize

      public int getMaxComponentSize()
      Returns:
      Maximum sample size to encode. May be Integer.MAX_VALUE indicating no max.
    • getNativeMetadata

      public Optional<NativeMetadata> getNativeMetadata()
      Returns:
      Native metadata.
    • getOptions

      public Configuration getOptions()
      Returns:
      Unmodifiable options.
      See Also:
    • getXMP

      public Optional<String> getXMP()
      Returns:
      Embeddable XMP metadata. rdf:RDF is the enclosing tag.
    • hasEffect

      public boolean hasEffect()
      Description copied from interface: Operation
      Simpler but less-accurate counterpart of Operation.hasEffect(Size, OperationList).
      Specified by:
      hasEffect in interface Operation
      Returns:
      true.
    • hasEffect

      public boolean hasEffect(Size fullSize, OperationList opList)
      Description copied from interface: Operation
      Context-aware counterpart to Operation.hasEffect(). For example, a scale operation specifying a scale to 300×200, when the given operation list contains a crop of 300×200, would return false.
      Specified by:
      hasEffect in interface Operation
      Parameters:
      fullSize - Full size of the source image.
      opList - Operation list of which the operation may or may not be a member.
      Returns:
      true.
    • removeOption

      public void removeOption(String key)
      Throws:
      IllegalStateException - if the instance is frozen.
    • setBackgroundColor

      public void setBackgroundColor(Color color)
      Parameters:
      color - Background color.
      Throws:
      IllegalStateException - if the instance is frozen.
    • setFormat

      public void setFormat(Format format)
      Parameters:
      format - Format to set.
      Throws:
      IllegalStateException - if the instance is frozen.
    • setMaxComponentSize

      public void setMaxComponentSize(int depth)
      Parameters:
      depth - Maximum sample size to encode. Supply 0 to indicate no max.
      Throws:
      IllegalStateException - if the instance is frozen.
    • setNativeMetadata

      public void setNativeMetadata(NativeMetadata metadata)
      Parameters:
      metadata - Native metadata.
      Throws:
      IllegalStateException - if the instance is frozen.
    • setOption

      public void setOption(String key, Object value)

      Some encoders may support their own custom encoding options. Rather than forcing them to draw this information directly from the application configuration, which would make it invisible in the operation pipeline (and therefore not considered in e.g. variant image cache keys), these options can be supplied here, where they will affect the output of toString() and toMap(is.galia.image.Size, is.galia.image.ScaleConstraint).

      Parameters:
      key - Option key, which must start with OPTION_PREFIX. No other constraints are imposed, but as keys are drawn from the application configuration, they should align with that syntax.
      value - Option value.
      Throws:
      IllegalArgumentException - if the key does not conform to the required syntax.
      IllegalStateException - if the instance is frozen.
      See Also:
    • setXMP

      public void setXMP(String xmp)
      Parameters:
      xmp - Embeddable XMP metadata. rdf:RDF is the enclosing tag.
      Throws:
      IllegalStateException - if the instance is frozen.
    • toMap

      public Map<String,Object> toMap(Size fullSize, ScaleConstraint scaleConstraint)

      Returns a map in the following format:

      {
           class: "Encode"
           background_color: Hexadecimal string
           format: Media type string
           max_sample_size: Integer
           native_metadata: See NativeMetadata.toMap()
           xmp: String
           options: {
               key1: value
               key2: value
           }
       }
      Specified by:
      toMap in interface Operation
      Parameters:
      fullSize - Full size of the source image on which the operation is being applied.
      scaleConstraint - Scale constraint applied to the given full size.
      Returns:
      Map representation of the instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      String representation of the instance, guaranteed to uniquely represent it.