Updates the canvas dimension method to use multiple bundles.

This commit is contained in:
Michael Spalti
2022-07-13 14:56:38 -07:00
committed by Tim Donohue
parent b5b94b2986
commit 18ce42c388
2 changed files with 26 additions and 17 deletions

View File

@@ -23,8 +23,7 @@ import org.dspace.iiif.util.IIIFSharedUtils;
/**
* Queries the configured IIIF server for image dimensions. Used for
* formats that cannot be easily read using ImageIO (jpeg 2000).
* Queries the configured IIIF image server via the Image API.
*
* @author Michael Spalti mspalti@willamette.edu
*/

View File

@@ -78,29 +78,39 @@ public class CanvasService extends AbstractResourceService {
}
/**
* Checks for bitstream iiif.image.width metadata in the first
* bitstream in first IIIF bundle. If bitstream metadata is not
* found, use the IIIF image service to update the default canvas
* dimensions for this request. Called once for each manifest.
* Checks for "iiif.image.width" metadata in the first
* bitstream of IIIF bundles. If bitstream metadata is not
* found, sets the default canvas dimensions for this request,
* using the IIIF image service to get the dimensions. Called
* once for each manifest.
* @param bundles IIIF bundles for this item
*/
protected void guessCanvasDimensions(List<Bundle> bundles) {
Bitstream firstBistream = bundles.get(0).getBitstreams().get(0);
if (!utils.hasWidthMetadata(firstBistream)) {
int[] imageDims = utils.getImageDimensions(firstBistream);
// prevent redundant updates.
boolean dimensionUpdated = false;
for (Bundle bundle : bundles) {
if(bundle.getBitstreams().size() > 0 && !dimensionUpdated) {
Bitstream firstBitstream = bundle.getBitstreams().get(0);
if (!utils.hasWidthMetadata(firstBitstream)) {
// get the dimensions of the first image.
int[] imageDims = utils.getImageDimensions(firstBitstream);
if (imageDims != null && imageDims.length == 2) {
// update the fallback dimensions
defaultCanvasWidthFallback = imageDims[0];
defaultCanvasHeightFallback = imageDims[1];
}
setDefaultCanvasDimensions();
// the default dimension for this request has been updated.
dimensionUpdated = true;
}
}
}
}
/**
* Used to set the height and width dimensions for all images when iiif.image.default-width and
* iiif.image.default-height are set to -1 in DSpace configuration.
* The values are updated only if the bitstream does not have its own iiif.image.width metadata.
* Sets the height and width dimensions for all images when "iiif.image.default-width"
* and "iiif.image.default-height" are set to -1 in DSpace configuration. The values
* are updated only when the bitstream does not have its own image dimension metadata.
* @param bitstream
*/
private void setCanvasDimensions(Bitstream bitstream) {