Class SizeRequest
- java.lang.Object
-
- de.digitalcollections.iiif.model.image.SizeRequest
-
public class SizeRequest extends Object
-
-
Constructor Summary
Constructors Constructor Description SizeRequest()Create a size request for the full native resolution of the image region.SizeRequest(boolean isMax)Create a size request for the maximum supported size of the image region, if isMax is true.SizeRequest(int width, int height, boolean bestFit)Create a size request for a given width and height and signal that the server can decide to render smaller resolutions as it deems neccessary.SizeRequest(Integer width, Integer height)Create a size request for a given width or height.SizeRequest(BigDecimal percentage)Create a size request that scaled both dimensions according to a fixed percentage, maintaining the aspect ratio.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static SizeRequestfromString(String str)Parse an IIIF Image API compliant size request stringStringgetCanonicalForm(Dimension nativeSize, ImageApiProfile profile)Get the canonical form of this request.IntegergetHeight()Get the requested heightBigDecimalgetPercentage()Get the requested percentage to be used for scalingIntegergetWidth()Get the requested widthinthashCode()booleanisBestFit()Return whether the server can decide to render smaller resolutions than desired.booleanisMax()Return whether the maximum resolution was requested.Dimensionresolve(Dimension nativeSize, ImageApiProfile profile)Dimensionresolve(Dimension nativeSize, List<Dimension> availableSizes, ImageApiProfile profile)Resolve the request to dimensions that can be used for scaling, based on the native size of the image region and the available profile.Dimensionresolve(Rectangle region, ImageApiProfile profile)Likeresolve(Dimension, ImageApiProfile), but can be used with aRectangle, e.g.StringtoString()Create an IIIF Image API compliant size request string
-
-
-
Constructor Detail
-
SizeRequest
public SizeRequest()
Create a size request for the full native resolution of the image region.
-
SizeRequest
public SizeRequest(boolean isMax)
Create a size request for the maximum supported size of the image region, if isMax is true. If isMax is false, it behaves identically to the default constructor.- Parameters:
isMax- true causes a size request for the maximum supported size of the image region
-
SizeRequest
public SizeRequest(Integer width, Integer height) throws ResolvingException
Create a size request for a given width or height. One of both can be null (the other value will be determined based on the aspect ratio of the image region), but not both at once.- Parameters:
width- width of size requestheight- height of size request- Throws:
ResolvingException- if neither width nor height are specified
-
SizeRequest
public SizeRequest(int width, int height, boolean bestFit) throws ResolvingExceptionCreate a size request for a given width and height and signal that the server can decide to render smaller resolutions as it deems neccessary.- Parameters:
width- width of size requestheight- height of size requestbestFit- true, if server can decide to render smaller resolutions as it deems neccessary- Throws:
ResolvingException- if params can not be resolved to Size Request
-
SizeRequest
public SizeRequest(BigDecimal percentage) throws ResolvingException
Create a size request that scaled both dimensions according to a fixed percentage, maintaining the aspect ratio.- Parameters:
percentage- scaling percentage, maintaining aspect ratio- Throws:
ResolvingException- if the percentage is not between 0 and 100
-
-
Method Detail
-
fromString
public static SizeRequest fromString(String str) throws ResolvingException
Parse an IIIF Image API compliant size request string- Parameters:
str- IIIF Image API compliant size request string- Returns:
- parsed SizeRequest
- Throws:
ResolvingException- if the request string is malformed
-
isMax
public boolean isMax()
Return whether the maximum resolution was requested.- Returns:
- true, if maximum resolution was requested
-
isBestFit
public boolean isBestFit()
Return whether the server can decide to render smaller resolutions than desired.- Returns:
- true, if the server can decide to render smaller resolutions than desired
-
getWidth
public Integer getWidth()
Get the requested width- Returns:
- requested width
-
getHeight
public Integer getHeight()
Get the requested height- Returns:
- requested height
-
getPercentage
public BigDecimal getPercentage()
Get the requested percentage to be used for scaling- Returns:
- requested percentage to be used for scaling
-
getCanonicalForm
public String getCanonicalForm(Dimension nativeSize, ImageApiProfile profile) throws ResolvingException
Get the canonical form of this request.- Parameters:
nativeSize- native size of requestprofile- image api profile- Returns:
- canonical form of this request
- Throws:
ResolvingException- if nativeSize can not be converted to canonical form- See Also:
- IIIF Image API specification
-
resolve
public Dimension resolve(Dimension nativeSize, ImageApiProfile profile) throws ResolvingException
- Throws:
ResolvingException
-
resolve
public Dimension resolve(Dimension nativeSize, List<Dimension> availableSizes, ImageApiProfile profile) throws ResolvingException
Resolve the request to dimensions that can be used for scaling, based on the native size of the image region and the available profile.- Parameters:
nativeSize- native size of the image regionavailableSizes- available sizesprofile- image api profile- Returns:
- resolved dimension
- Throws:
ResolvingException- if params can not be resolved to Dimension
-
resolve
public Dimension resolve(Rectangle region, ImageApiProfile profile) throws ResolvingException
Likeresolve(Dimension, ImageApiProfile), but can be used with aRectangle, e.g. as returned fromRegionRequest.resolve(Dimension).- Parameters:
region- image regionprofile- image api profile- Returns:
- resolved size dimension
- Throws:
ResolvingException- if rectangle region can not be resolved
-
toString
public String toString()
Create an IIIF Image API compliant size request string
-
-