Class Scale

java.lang.Object
is.galia.operation.Scale
All Implemented Interfaces:
Operation
Direct Known Subclasses:
ScaleByPercent, ScaleByPixels

public abstract class Scale extends Object implements Operation
Encapsulates a scaling operation. Subclasses implement absolute (pixel-based) or relative (percentage-based) behavior.
  • Constructor Details

    • Scale

      public Scale()
  • 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
    • getFilter

      public Scale.Filter getFilter()
      Returns:
      Resample filter to prefer. May be null.
    • getReductionFactor

      public abstract ReductionFactor getReductionFactor(Size reducedSize, ScaleConstraint scaleConstraint, int maxFactor)
      Parameters:
      reducedSize - Size of an image that has been halved n times.
      scaleConstraint - Scale constraint relative to the full source image dimensions.
      maxFactor - Maximum factor to return.
      Returns:
      Reduction factor appropriate for the instance.
    • getResultingScales

      public abstract double[] getResultingScales(Size fullSize, ScaleConstraint scaleConstraint)
      Parameters:
      fullSize - Full source image dimensions.
      scaleConstraint - Scale constraint relative to the full source image dimensions. The instance is expressed relative to the constrained fullSize.
      Returns:
      Two-element array containing the resulting X and Y scales when the instance is applied to the given full size.
    • getResultingSize

      public Size getResultingSize(Size fullSize, ScaleConstraint scaleConstraint)
      Description copied from interface: Operation
      This default implementation returns the fullSize argument. It will need to be overridden by operations that could change the image's resulting size.
      Specified by:
      getResultingSize in interface Operation
      Parameters:
      fullSize - Full source image size.
      scaleConstraint - Scale constraint applied to the given full size.
      Returns:
      Resulting dimensions when the scale is applied to the given full size.
    • getResultingSize

      public abstract Size getResultingSize(Size imageSize, ReductionFactor reductionFactor, ScaleConstraint scaleConstraint)
      Parameters:
      imageSize - Image whose dimensions have been halved ReductionFactor.factor times.
      reductionFactor - Number of times the given dimensions have been halved.
      scaleConstraint - Scale constraint relative to the full source image dimensions.
      Returns:
      Resulting dimensions when the scale is applied to the constrained view of the given full size.
    • isHeightUp

      public boolean isHeightUp(Size comparedToSize, ScaleConstraint comparedToScaleConstraint)
      Returns:
      Whether the instance would effectively upscale the image it is applied to on the Y axis.
    • isLinear

      public boolean isLinear()
      Returns:
      Whether downscaling should happen in a linear color space.
    • isUp

      public boolean isUp(Size comparedToSize, ScaleConstraint comparedToScaleConstraint)
      Returns:
      Whether the instance would effectively upscale the image it is applied to on both axes.
    • isWidthUp

      public boolean isWidthUp(Size comparedToSize, ScaleConstraint comparedToScaleConstraint)
      Returns:
      Whether the instance would effectively upscale the image it is applied to on the X axis.
    • setFilter

      public void setFilter(Scale.Filter filter)
      Parameters:
      filter - Resample filter to prefer.
      Throws:
      IllegalStateException - if the instance is frozen.
    • setLinear

      public void setLinear(boolean isLinear)
      Parameters:
      isLinear - Whether downscaling should happen in a linear color space.
    • toMap

      public Map<String,Object> toMap(Size fullSize, ScaleConstraint scaleConstraint)
      Specified by:
      toMap in interface Operation
      Parameters:
      fullSize - Full size of the source image on which the operation is being applied.
      scaleConstraint - Scale constraint.
      Returns:
      Map with width and height keys and integer values corresponding to the resulting pixel size of the operation.