Search in sources :

Example 1 with MCRIIIFImageTargetRotation

use of org.mycore.iiif.image.model.MCRIIIFImageTargetRotation in project mycore by MyCoRe-Org.

the class MCRIIIFImageResource method getImage.

@GET
@Path("{" + IDENTIFIER_PARAM + "}/{region}/{size}/{rotation}/{quality}.{format}")
public Response getImage(@PathParam(IMPL_PARAM) String implStr, @PathParam(IDENTIFIER_PARAM) String identifier, @PathParam("region") String region, @PathParam("size") String size, @PathParam("rotation") String rotation, @PathParam("quality") String quality, @PathParam("format") String format) {
    try {
        MCRIIIFImageImpl impl = getImpl(implStr);
        MCRIIIFImageInformation information = impl.getInformation(identifier);
        MCRIIIFRegionParser rp = new MCRIIIFRegionParser(region, information.width, information.height);
        MCRIIIFImageSourceRegion sourceRegion = rp.parseImageRegion();
        MCRIIIFScaleParser sp = new MCRIIIFScaleParser(size, sourceRegion.getX2() - sourceRegion.getX1(), sourceRegion.getY2() - sourceRegion.getY1());
        MCRIIIFImageTargetSize targetSize = sp.parseTargetScale();
        MCRIIIFRotationParser rotationParser = new MCRIIIFRotationParser(rotation);
        MCRIIIFImageTargetRotation parsedRotation = rotationParser.parse();
        MCRIIIFImageQuality imageQuality = MCRIIIFImageQuality.fromString(quality);
        BufferedImage provide = impl.provide(identifier, sourceRegion, targetSize, parsedRotation, imageQuality, format);
        Response.Status status = rp.isCompleteValid() ? Response.Status.OK : Response.Status.BAD_REQUEST;
        Response.ResponseBuilder responseBuilder = Response.status(status);
        return responseBuilder.header("Link", buildCanonicalURL(impl, identifier)).header("Profile", buildProfileURL()).type("image/" + format).entity((StreamingOutput) outputStream -> ImageIO.write(provide, format, outputStream)).build();
    } catch (MCRIIIFImageNotFoundException e) {
        return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
    } catch (IllegalArgumentException | MCRIIIFUnsupportedFormatException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
    } catch (MCRAccessException e) {
        return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build();
    } catch (Exception e) {
        LOGGER.error(() -> "Error while getting Image " + identifier + " from " + implStr + " with region: " + region + ", size: " + size + ", rotation: " + rotation + ", quality: " + quality + ", format: " + format, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}
Also used : MCRIIIFImageTargetRotation(org.mycore.iiif.image.model.MCRIIIFImageTargetRotation) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRAccessException(org.mycore.access.MCRAccessException) MCRIIIFImageQuality(org.mycore.iiif.image.model.MCRIIIFImageQuality) StreamingOutput(javax.ws.rs.core.StreamingOutput) MCRIIIFUnsupportedFormatException(org.mycore.iiif.image.impl.MCRIIIFUnsupportedFormatException) BufferedImage(java.awt.image.BufferedImage) URISyntaxException(java.net.URISyntaxException) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRAccessException(org.mycore.access.MCRAccessException) MCRIIIFUnsupportedFormatException(org.mycore.iiif.image.impl.MCRIIIFUnsupportedFormatException) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Response(javax.ws.rs.core.Response) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageTargetSize(org.mycore.iiif.image.model.MCRIIIFImageTargetSize) MCRIIIFImageSourceRegion(org.mycore.iiif.image.model.MCRIIIFImageSourceRegion) MCRIIIFRotationParser(org.mycore.iiif.image.parser.MCRIIIFRotationParser) MCRIIIFRegionParser(org.mycore.iiif.image.parser.MCRIIIFRegionParser) MCRIIIFScaleParser(org.mycore.iiif.image.parser.MCRIIIFScaleParser) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with MCRIIIFImageTargetRotation

use of org.mycore.iiif.image.model.MCRIIIFImageTargetRotation in project mycore by MyCoRe-Org.

the class MCRIIIFRotationParserTest method testParse.

@Test
public void testParse() throws Exception {
    Map<String, MCRIIIFImageTargetRotation> testValues = new Hashtable<>();
    testValues.put("0", new MCRIIIFImageTargetRotation(false, 0));
    testValues.put("!0", new MCRIIIFImageTargetRotation(true, 0));
    testValues.put("90", new MCRIIIFImageTargetRotation(false, 90));
    testValues.put("!90", new MCRIIIFImageTargetRotation(true, 90));
    testValues.put("180", new MCRIIIFImageTargetRotation(false, 180));
    testValues.put("!180", new MCRIIIFImageTargetRotation(true, 180));
    testValues.put("270", new MCRIIIFImageTargetRotation(false, 270));
    testValues.put("!270", new MCRIIIFImageTargetRotation(true, 270));
    testValues.forEach((rotationString, expectedResult) -> Assert.assertEquals(new MCRIIIFRotationParser(rotationString).parse(), expectedResult));
}
Also used : MCRIIIFImageTargetRotation(org.mycore.iiif.image.model.MCRIIIFImageTargetRotation) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Aggregations

MCRIIIFImageTargetRotation (org.mycore.iiif.image.model.MCRIIIFImageTargetRotation)2 BufferedImage (java.awt.image.BufferedImage)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 Hashtable (java.util.Hashtable)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Test (org.junit.Test)1 MCRAccessException (org.mycore.access.MCRAccessException)1 MCRIIIFImageImpl (org.mycore.iiif.image.impl.MCRIIIFImageImpl)1 MCRIIIFImageNotFoundException (org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException)1 MCRIIIFImageProvidingException (org.mycore.iiif.image.impl.MCRIIIFImageProvidingException)1 MCRIIIFUnsupportedFormatException (org.mycore.iiif.image.impl.MCRIIIFUnsupportedFormatException)1 MCRIIIFImageInformation (org.mycore.iiif.image.model.MCRIIIFImageInformation)1 MCRIIIFImageQuality (org.mycore.iiif.image.model.MCRIIIFImageQuality)1 MCRIIIFImageSourceRegion (org.mycore.iiif.image.model.MCRIIIFImageSourceRegion)1 MCRIIIFImageTargetSize (org.mycore.iiif.image.model.MCRIIIFImageTargetSize)1 MCRIIIFRegionParser (org.mycore.iiif.image.parser.MCRIIIFRegionParser)1