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 * Queries the configured IIIF image server via the Image API.
* formats that cannot be easily read using ImageIO (jpeg 2000).
* *
* @author Michael Spalti mspalti@willamette.edu * @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 * Checks for "iiif.image.width" metadata in the first
* bitstream in first IIIF bundle. If bitstream metadata is not * bitstream of IIIF bundles. If bitstream metadata is not
* found, use the IIIF image service to update the default canvas * found, sets the default canvas dimensions for this request,
* dimensions for this request. Called once for each manifest. * using the IIIF image service to get the dimensions. Called
* once for each manifest.
* @param bundles IIIF bundles for this item * @param bundles IIIF bundles for this item
*/ */
protected void guessCanvasDimensions(List<Bundle> bundles) { protected void guessCanvasDimensions(List<Bundle> bundles) {
Bitstream firstBistream = bundles.get(0).getBitstreams().get(0); // prevent redundant updates.
if (!utils.hasWidthMetadata(firstBistream)) { boolean dimensionUpdated = false;
int[] imageDims = utils.getImageDimensions(firstBistream); for (Bundle bundle : bundles) {
if (imageDims != null && imageDims.length == 2) { if(bundle.getBitstreams().size() > 0 && !dimensionUpdated) {
// update the fallback dimensions Bitstream firstBitstream = bundle.getBitstreams().get(0);
defaultCanvasWidthFallback = imageDims[0]; if (!utils.hasWidthMetadata(firstBitstream)) {
defaultCanvasHeightFallback = imageDims[1]; // 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;
}
} }
setDefaultCanvasDimensions();
} }
} }
/** /**
* Used to set the height and width dimensions for all images when iiif.image.default-width and * Sets the height and width dimensions for all images when "iiif.image.default-width"
* iiif.image.default-height are set to -1 in DSpace configuration. * and "iiif.image.default-height" are set to -1 in DSpace configuration. The values
* The values are updated only if the bitstream does not have its own iiif.image.width metadata. * are updated only when the bitstream does not have its own image dimension metadata.
* @param bitstream * @param bitstream
*/ */
private void setCanvasDimensions(Bitstream bitstream) { private void setCanvasDimensions(Bitstream bitstream) {