Package ch.sahits.game.graphic.image
Class ImageScaleState
- java.lang.Object
-
- ch.sahits.game.graphic.image.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 borderedprivate ECrop
crop
Where to crop the imageprivate int
cropped
Amount that was cropped awayprivate static int
CROPPED_MASK
The mask indicating that the image was croppedprivate int
maxCrop
Maximum that may be cropped away on the unscaled imageprivate static int
NONE_MASK
Mask indicating that no operation was executed yetprivate javafx.geometry.Dimension2D
originalImageDim
Original dimension of the imageprivate static int
SCALED_MASK
The mask indicating that the image was scaledprivate double
scaleFactor
private int
state
current stateprivate 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 imagevoid
crop()
Update the state for the cropping of the imageEScaleDirection
getBorderDirection()
int
getBordered()
Retrieve the amount of bordered pixelsECrop
getCrop()
Indicate where the image may be croppedint
getCropped()
Retrieve the number of cropped pixels based on the scaled imageint
getMaxCrop()
Retrieve the maximum amount of pixel that may be cropped away from the unscaled imagejavafx.geometry.Dimension2D
getOriginalImageDimension()
Retrieve the dimension of the original imagedouble
getScaleFactor()
Retrieve the factor that was used in the scalingjavafx.geometry.Dimension2D
getTargetImageDimension()
Retrieve the dimension for the targetboolean
isBordered()
Check if the image was borderedboolean
isCropped()
Check if the image was croppedboolean
isScaled()
Check if the image was scaledvoid
scale()
Update the state for the scaling of the imagevoid
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 scalingjava.lang.String
toString()
-
-
-
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
-
borderDirection
private EScaleDirection borderDirection
-
-
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 transformedcrop
- indicate where the image may be croppedmaxCrop
- 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.
-
getBorderDirection
public EScaleDirection getBorderDirection()
-
setBorderDirection
public void setBorderDirection(EScaleDirection borderDirection)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-