Search in sources :

Example 1 with ImageSet

use of digilib.io.ImageSet in project digilib by robcast.

the class ImageJobDescription method getHiresSize.

/**
 * Return the size of the highest resolution image.
 *
 * @return
 * @throws IOException
 */
public ImageSize getHiresSize() throws IOException {
    // logger.debug("get_hiresSize()");
    if (hiresSize == null) {
        ImageSet fileset = getImageSet();
        ImageInput hiresFile = fileset.getBiggest();
        hiresSize = hiresFile.getSize();
        if (hiresSize == null) {
            throw new FileOpException("Can't get size from hires image file!");
        }
    }
    return hiresSize;
}
Also used : ImageInput(digilib.io.ImageInput) FileOpException(digilib.io.FileOpException) ImageSet(digilib.io.ImageSet)

Example 2 with ImageSet

use of digilib.io.ImageSet in project digilib by robcast.

the class DocumentBean method setRequest.

/**
 * Sets the current DigilibRequest. Also completes information in the request.
 *
 * @param dlRequest
 *            The dlRequest to set.
 */
public void setRequest(DigilibServletRequest dlRequest) throws Exception {
    this.dlRequest = dlRequest;
    if (dirCache == null) {
        return;
    }
    String fn = dlRequest.getFilePath();
    // get information about the file
    ImageSet fileset = (ImageSet) dirCache.getFile(fn, dlRequest.getAsInt("pn"));
    if (fileset == null) {
        return;
    }
    // add file name
    dlRequest.setValue("img.fn", fileset);
    // add dpi
    dlRequest.setValue("img.dpix", new Double(fileset.getResX()));
    dlRequest.setValue("img.dpiy", new Double(fileset.getResY()));
    // get number of pages in directory
    DocuDirectory dd = dirCache.getDirectory(fn);
    if (dd != null) {
        // add pt
        dlRequest.setValue("pt", dd.size());
    }
    // get original pixel size
    ImageInput origfile = fileset.getBiggest();
    // check image for size (TODO: just if mo=hires?)
    ImageSize pixsize = origfile.getSize();
    if (pixsize != null) {
        // add pixel size
        dlRequest.setValue("img.pix_x", new Integer(pixsize.getWidth()));
        dlRequest.setValue("img.pix_y", new Integer(pixsize.getHeight()));
    }
}
Also used : ImageInput(digilib.io.ImageInput) ImageSize(digilib.util.ImageSize) DocuDirectory(digilib.io.DocuDirectory) ImageSet(digilib.io.ImageSet)

Example 3 with ImageSet

use of digilib.io.ImageSet in project digilib by robcast.

the class ServletOps method sendIiifInfo.

/**
 * Returns IIIF compatible image information as application/json response.
 *
 * @param dlReq
 * @param response
 * @param logger
 * @throws FileOpException
 * @throws ServletException
 * @see <a href="http://www-sul.stanford.edu/iiif/image-api/1.1/#info">IIIF Image Information Request</a>
 */
public static void sendIiifInfo(DigilibServletRequest dlReq, HttpServletResponse response, Logger logger) throws ServletException {
    if (response == null) {
        logger.error("No response!");
        return;
    }
    /*
         * get image size
         */
    ImageSize size = null;
    ImageSet imageSet = null;
    try {
        // get original image size
        imageSet = dlReq.getJobDescription().getImageSet();
        ImageInput img = imageSet.getBiggest();
        size = img.getSize();
    } catch (FileOpException e) {
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        } catch (IOException e1) {
            throw new ServletException("Unable to write error response!", e);
        }
    }
    /*
         * get resource URL
         */
    String url = dlReq.getServletRequest().getRequestURL().toString();
    if (url.endsWith("/info.json")) {
        url = url.substring(0, url.lastIndexOf("/info.json"));
    } else if (url.endsWith("/")) {
        url = url.substring(0, url.lastIndexOf("/"));
    }
    /*
         * send response
         */
    response.setCharacterEncoding("UTF-8");
    logger.debug("sending info.json");
    try {
        /*
             * set CORS header ACAO "*" for info response as per IIIF spec
             */
        if (corsForInfoRequests) {
            String origin = dlReq.getServletRequest().getHeader("Origin");
            if (origin != null) {
                response.setHeader("Access-Control-Allow-Origin", "*");
            }
        }
        if (dlConfig.getAsString("iiif-api-version").startsWith("2.")) {
            /*
                 * IIIF Image API version 2 image information
                 */
            // use JSON-LD content type only when asked
            String accept = dlReq.getServletRequest().getHeader("Accept");
            if (accept != null && accept.contains("application/ld+json")) {
                response.setContentType("application/ld+json");
            } else {
                response.setContentType("application/json");
            }
            // write info.json
            ServletOutputStream out = response.getOutputStream();
            JsonGenerator info = Json.createGenerator(out);
            // top level object
            info.writeStartObject().write("@context", "http://iiif.io/api/image/2/context.json").write("@id", url).write("protocol", "http://iiif.io/api/image").write("width", size.width).write("height", size.height);
            // profile[ array
            info.writeStartArray("profile").write("http://iiif.io/api/image/2/level2.json");
            // profile[{ object
            info.writeStartObject();
            // profile[{formats[
            info.writeStartArray("formats").write("jpg").write("png").writeEnd();
            // profile[{qualities[
            info.writeStartArray("qualities").write("color").write("gray").writeEnd();
            // profile[{maxArea
            if (dlConfig.getAsInt("max-image-size") > 0) {
                info.write("maxArea", dlConfig.getAsInt("max-image-size"));
            }
            // profile[{supports[
            info.writeStartArray("supports").write("mirroring").write("rotationArbitrary").write("sizeAboveFull").write("regionSquare").writeEnd();
            // profile[{}
            info.writeEnd();
            // profile[]
            info.writeEnd();
            // add size of original and prescaled images
            int numImgs = imageSet.size();
            if (numImgs > 0) {
                // sizes[
                info.writeStartArray("sizes");
                for (int i = numImgs - 1; i >= 0; --i) {
                    ImageInput ii = imageSet.get(i);
                    ImageSize is = ii.getSize();
                    // sizes[{
                    info.writeStartObject().write("width", is.getWidth()).write("height", is.getHeight()).writeEnd();
                }
                // sizes[]
                info.writeEnd();
            }
            // end info.json
            info.writeEnd();
            info.close();
        } else {
            /*
                 * IIIF Image API version 1 image information
                 */
            response.setContentType("application/json,application/ld+json");
            // write info.json
            ServletOutputStream out = response.getOutputStream();
            JsonGenerator info = Json.createGenerator(out);
            // top level object
            info.writeStartObject().write("@context", "http://library.stanford.edu/iiif/image-api/1.1/context.json").write("@id", url).write("width", size.width).write("height", size.height);
            // formats[
            info.writeStartArray("formats").write("jpg").write("png").writeEnd();
            // qualities[
            info.writeStartArray("qualities").write("native").write("color").write("gray").writeEnd();
            // profile
            info.write("profile", "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2");
            // end info.json
            info.writeEnd();
            info.close();
        }
    } catch (IOException e) {
        throw new ServletException("Unable to write response!", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) ImageSize(digilib.util.ImageSize) ImageInput(digilib.io.ImageInput) ServletOutputStream(javax.servlet.ServletOutputStream) FileOpException(digilib.io.FileOpException) JsonGenerator(javax.json.stream.JsonGenerator) ImageSet(digilib.io.ImageSet) IOException(java.io.IOException)

Example 4 with ImageSet

use of digilib.io.ImageSet in project digilib by robcast.

the class ImageJobDescription method setInput.

/**
 * Set the current ImageInput.
 *
 * @param input
 *            the input to set
 */
public void setInput(ImageInput input) {
    this.input = input;
    // create and set ImageSet if needed
    if (dirCache == null && imageSet == null) {
        imageSet = new ImageSet();
        imageSet.add(input);
    }
}
Also used : ImageSet(digilib.io.ImageSet)

Aggregations

ImageSet (digilib.io.ImageSet)4 ImageInput (digilib.io.ImageInput)3 FileOpException (digilib.io.FileOpException)2 ImageSize (digilib.util.ImageSize)2 DocuDirectory (digilib.io.DocuDirectory)1 IOException (java.io.IOException)1 JsonGenerator (javax.json.stream.JsonGenerator)1 ServletException (javax.servlet.ServletException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1