Class ImageScaleState


  • public final class ImageScaleState
    extends java.lang.Object
    This class represents the state of an image through the processing of scaling, cropping and bordering.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2012 Created on May 26, 2012
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private EScaleDirection borderDirection  
      private int bordered  
      private static int BORDERED_MASK
      Mask indicating that the image was bordered
      private ECrop crop
      Where to crop the image
      private int cropped
      Amount that was cropped away
      private static int CROPPED_MASK
      The mask indicating that the image was cropped
      private int maxCrop
      Maximum that may be cropped away on the unscaled image
      private static int NONE_MASK
      Mask indicating that no operation was executed yet
      private javafx.geometry.Dimension2D originalImageDim
      Original dimension of the image
      private static int SCALED_MASK
      The mask indicating that the image was scaled
      private double scaleFactor  
      private int state
      current state
      private javafx.geometry.Dimension2D targetImageDim
      Dimension that the image should be scaled to
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageScaleState​(javafx.geometry.Dimension2D originalImageDim, javafx.geometry.Dimension2D targetImageDim, ECrop crop, int maxCrop)
      Initialize the image state for an image that can be cropped.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void border()
      Update the state for the bordering of the image
      void crop()
      Update the state for the cropping of the image
      EScaleDirection getBorderDirection()  
      int getBordered()
      Retrieve the amount of bordered pixels
      ECrop getCrop()
      Indicate where the image may be cropped
      int getCropped()
      Retrieve the number of cropped pixels based on the scaled image
      int getMaxCrop()
      Retrieve the maximum amount of pixel that may be cropped away from the unscaled image
      javafx.geometry.Dimension2D getOriginalImageDimension()
      Retrieve the dimension of the original image
      double getScaleFactor()
      Retrieve the factor that was used in the scaling
      javafx.geometry.Dimension2D getTargetImageDimension()
      Retrieve the dimension for the target
      boolean isBordered()
      Check if the image was bordered
      boolean isCropped()
      Check if the image was cropped
      boolean isScaled()
      Check if the image was scaled
      void scale()
      Update the state for the scaling of the image
      void setBorderDirection​(EScaleDirection borderDirection)  
      void setBordered​(int bordered)
      Set the number of pixels that is bordered on the scaled image (only one border).
      void setCropped​(int cropped)
      Set the number of pixels that were cropped away based on the scaled image.
      void setScaleFactor​(double scale)
      Set the factor that was used in the scaling
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • originalImageDim

        private final javafx.geometry.Dimension2D originalImageDim
        Original dimension of the image
      • targetImageDim

        private final javafx.geometry.Dimension2D targetImageDim
        Dimension that the image should be scaled to
      • crop

        private final ECrop crop
        Where to crop the image
      • maxCrop

        private final int maxCrop
        Maximum that may be cropped away on the unscaled image
      • cropped

        private int cropped
        Amount that was cropped away
      • NONE_MASK

        private static final int NONE_MASK
        Mask indicating that no operation was executed yet
        See Also:
        Constant Field Values
      • SCALED_MASK

        private static final int SCALED_MASK
        The mask indicating that the image was scaled
        See Also:
        Constant Field Values
      • CROPPED_MASK

        private static final int CROPPED_MASK
        The mask indicating that the image was cropped
        See Also:
        Constant Field Values
      • BORDERED_MASK

        private static final int BORDERED_MASK
        Mask indicating that the image was bordered
        See Also:
        Constant Field Values
      • state

        private int state
        current state
      • scaleFactor

        private double scaleFactor
      • bordered

        private int bordered
    • Constructor Detail

      • ImageScaleState

        public ImageScaleState​(javafx.geometry.Dimension2D originalImageDim,
                               javafx.geometry.Dimension2D targetImageDim,
                               ECrop crop,
                               int maxCrop)
        Initialize the image state for an image that can be cropped.
        Parameters:
        originalImageDim - Dimension of the original image (unscaled)
        targetImageDim - target dimension to which the image should be transformed
        crop - indicate where the image may be cropped
        maxCrop - maximum number of pixels that may be cropped away based on the unscaled image
    • Method Detail

      • isCropped

        public boolean isCropped()
        Check if the image was cropped
        Returns:
        true if the image is croped
      • isScaled

        public boolean isScaled()
        Check if the image was scaled
        Returns:
        true if the image is scaled
      • isBordered

        public boolean isBordered()
        Check if the image was bordered
        Returns:
        true if the image is bordered
      • crop

        public void crop()
        Update the state for the cropping of the image
      • scale

        public void scale()
        Update the state for the scaling of the image
      • border

        public void border()
        Update the state for the bordering of the image
      • setScaleFactor

        public void setScaleFactor​(double scale)
        Set the factor that was used in the scaling
        Parameters:
        scale - new scale factor
      • getScaleFactor

        public double getScaleFactor()
        Retrieve the factor that was used in the scaling
      • getOriginalImageDimension

        public javafx.geometry.Dimension2D getOriginalImageDimension()
        Retrieve the dimension of the original image
        Returns:
        original dimensions of the image (unscaled)
      • getTargetImageDimension

        public javafx.geometry.Dimension2D getTargetImageDimension()
        Retrieve the dimension for the target
        Returns:
        target dimensions of the scaled image
      • getCropped

        public int getCropped()
        Retrieve the number of cropped pixels based on the scaled image
        Returns:
        number of pixels that are cropped.
      • setCropped

        public void setCropped​(int cropped)
        Set the number of pixels that were cropped away based on the scaled image. This can only be set if the state is cropped
        Parameters:
        cropped - number of pixels that are cropped.
      • setBordered

        public void setBordered​(int bordered)
        Set the number of pixels that is bordered on the scaled image (only one border). This action is only applied after the border state is set
        Parameters:
        bordered - number of pixels that are bordered.
      • getBordered

        public int getBordered()
        Retrieve the amount of bordered pixels
        Returns:
        number of bordered pixels.
      • getCrop

        public ECrop getCrop()
        Indicate where the image may be cropped
        Returns:
        corp type
      • getMaxCrop

        public int getMaxCrop()
        Retrieve the maximum amount of pixel that may be cropped away from the unscaled image
        Returns:
        number of pixels that can be maximal cropped.
      • setBorderDirection

        public void setBorderDirection​(EScaleDirection borderDirection)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object