Class Crop

java.lang.Object
is.galia.operation.Crop
All Implemented Interfaces:
Operation
Direct Known Subclasses:
CropByPercent, CropByPixels, CropToSquare

public abstract class Crop extends Object implements Operation

Abstract cropping operation.

The basic idea is that getRegion(is.galia.image.Size) is used to compute a source image region based on arguments supplied to it and to subclasses' mutator methods.

  • Constructor Details

    • Crop

      public Crop()
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • 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
    • getRegion

      public Region getRegion(Size fullSize)
      Parameters:
      fullSize - Full-sized image dimensions.
      Returns:
      Region relative to the given full dimensions.
    • getRegion

      public Region getRegion(Size fullSize, ScaleConstraint scaleConstraint)
      Parameters:
      fullSize - Full-sized image dimensions.
      scaleConstraint - Scale constraint yet to be applied to the input image. The instance is expressed relative to this constraint rather than to fullSize.
      Returns:
      Region relative to the given full dimensions.
    • getRegion

      public abstract Region getRegion(Size reducedSize, ReductionFactor reductionFactor, ScaleConstraint scaleConstraint)
      Computes an effective crop rectangle in source image coordinates.
      Parameters:
      reducedSize - Size of the input image, reduced by reductionFactor.
      reductionFactor - Factor by which the full-sized image has been reduced to become reducedSize.
      scaleConstraint - Scale constraint yet to be applied to the input image. The instance is expressed relative to this constraint rather than to reducedSize or the full image size.
      Returns:
      Region relative to the given reduced dimensions.
    • 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 size of the source image on which the operation is being applied.
      scaleConstraint - Scale constraint applied to the given full size.
      Returns:
      Resulting dimensions when the operation is applied.
    • hasEffect

      public abstract boolean hasEffect()
      This method may produce false positives. hasEffect(Size, OperationList) should be used instead where possible, unless overrides mention otherwise.
      Specified by:
      hasEffect in interface Operation
      Returns:
      Whether the crop is not effectively a no-op.
    • hasEffect

      public abstract 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:
      Whether the crop is not effectively a no-op.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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 applied to the given full size.
      Returns:
      Map with class, x, y, width, and height keys and integer values corresponding to the instance coordinates.
    • validate

      public void validate(Size fullSize, ScaleConstraint scaleConstraint) throws OperationException

      Checks the intersection and dimensions.

      Validates the instance, throwing an exception if invalid.

      Implementations can also throw exceptions from property setters as an alternative to using this method.

      This default implementation does nothing.

      Specified by:
      validate 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.
      Throws:
      OperationException - if the instance is invalid.