Search in sources :

Example 1 with ImageInput

use of digilib.io.ImageInput 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 ImageInput

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

the class ImageLoaderDocuImage method identify.

/* 
     * Check image size and type and store in ImageInput
     * @see digilib.image.ImageInfoDocuImage#identify(digilib.io.ImageInput)
     */
public ImageInput identify(ImageInput input) throws IOException {
    ImageInput ii = null;
    if (!reuseReader) {
        // try parent method first
        ii = super.identify(input);
        if (ii != null) {
            return ii;
        }
    }
    logger.debug("identifying (ImageIO) " + input);
    try {
        /*
             * try ImageReader
             */
        reader = getReader(input);
        // set size
        ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0));
        input.setSize(d);
        // set mime type
        if (input.getMimetype() == null) {
            if (input.hasFile()) {
                String t = FileOps.mimeForFile(input.getFile());
                input.setMimetype(t);
            } else {
                // FIXME: is format name a mime type???
                String t = reader.getFormatName();
                input.setMimetype(t);
            }
        }
        return input;
    } catch (FileOpException e) {
        // maybe just our class doesn't know what to do
        logger.error("ImageLoaderDocuimage unable to identify: " + e);
        return null;
    } finally {
        if (!reuseReader && reader != null) {
            reader.dispose();
        }
    }
}
Also used : ImageInput(digilib.io.ImageInput) ImageSize(digilib.util.ImageSize) FileOpException(digilib.io.FileOpException)

Example 3 with ImageInput

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

the class ImageJ1DocuImage method identify.

/* Check image size and type and store in ImageInput */
public ImageInput identify(ImageInput input) throws IOException {
    // try parent method first
    ImageInput ii = super.identify(input);
    if (ii != null) {
        return ii;
    }
    logger.debug("identifying (ImageJ1) " + input);
    String path = input.getFile().getAbsolutePath();
    img = IJ.openImage(path);
    // set size
    ImageSize d = new ImageSize(img.getWidth(), img.getHeight());
    input.setSize(d);
    // set mime type
    if (input.getMimetype() == null) {
        String t = FileOps.mimeForFile(input.getFile());
        input.setMimetype(t);
    }
    return input;
}
Also used : ImageInput(digilib.io.ImageInput) ImageSize(digilib.util.ImageSize)

Example 4 with ImageInput

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

the class Scaler method processRequest.

/**
 * Service this request using the response.
 *
 * @param request
 * @param response
 * @throws ServletException
 */
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    if (dlConfig == null) {
        logger.error("ERROR: No Configuration!");
        throw new ServletException("NO VALID digilib CONFIGURATION!");
    }
    accountlog.debug("request: " + request.getQueryString());
    logger.debug("request: " + request.getQueryString());
    // logger.debug("processRequest response committed=" + response.isCommitted());
    if (response.isCommitted()) {
        logger.error("Crap: response committed before we got a chance!");
    }
    final long startTime = System.currentTimeMillis();
    // parse request
    DigilibServletRequest dlRequest = new DigilibServletRequest(request, dlConfig);
    // type of error reporting
    ErrMsg errMsgType = defaultErrMsgType;
    if (dlRequest.hasOption(DigilibOption.errimg)) {
        errMsgType = ErrMsg.IMAGE;
    } else if (dlRequest.hasOption(DigilibOption.errtxt)) {
        errMsgType = ErrMsg.TEXT;
    } else if (dlRequest.hasOption(DigilibOption.errcode)) {
        errMsgType = ErrMsg.CODE;
    }
    try {
        // extract the job information
        final ImageJobDescription jobTicket = ImageJobDescription.getInstance(dlRequest, dlConfig);
        // handle the IIIF info-request
        if (dlRequest.hasOption(DigilibOption.info)) {
            ServletOps.sendIiifInfo(dlRequest, response, logger);
            return;
        }
        if (dlRequest.hasOption(DigilibOption.redirect_info)) {
            StringBuffer url = request.getRequestURL();
            if (url.toString().endsWith("/")) {
                url.append("info.json");
            } else {
                url.append("/info.json");
            }
            // TODO: the redirect should have code 303
            response.sendRedirect(url.toString());
            return;
        }
        // error out if request was bad
        if (dlRequest.errorMessage != null) {
            digilibError(errMsgType, Error.UNKNOWN, dlRequest.errorMessage, response);
            return;
        }
        /*
             * check permissions
             */
        if (useAuthorization) {
            // is the current request/user authorized?
            if (!authzOp.isAuthorized(dlRequest)) {
                // send deny answer and abort
                throw new AuthOpException("Access denied!");
            }
        }
        /*
             * get the input file
             */
        ImageInput fileToLoad = jobTicket.getInput();
        /*
             * if requested, send image as a file
             */
        if (sendFileAllowed && jobTicket.getSendAsFile()) {
            String mt = null;
            if (jobTicket.hasOption(DigilibOption.rawfile)) {
                // mo=rawfile sends as octet-stream
                mt = "application/octet-stream";
            }
            logger.debug("Sending RAW File as is.");
            ServletOps.sendFile(fileToLoad.getFile(), mt, null, response, logger);
            logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
            return;
        }
        /*
             * send the image if it's possible without having to transform it
             */
        if (!jobTicket.isTransformRequired()) {
            logger.debug("Sending File as is.");
            ServletOps.sendFile(fileToLoad.getFile(), null, null, response, logger);
            logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
            return;
        }
        /*
             * check load of workers
             */
        if (imageJobCenter.isBusy()) {
            logger.error("Servlet overloaded!");
            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
            return;
        }
        /*
             * dispatch worker job to be done asynchronously
             */
        AsyncContext asyncCtx = request.startAsync();
        // create job
        AsyncServletWorker job = new AsyncServletWorker(dlConfig, jobTicket, asyncCtx, errMsgType, startTime);
        // AsyncServletWorker is its own AsyncListener
        asyncCtx.addListener(job);
        // submit job
        imageJobCenter.submit(job);
    // we're done for now
    } catch (ImageOpException e) {
        logger.error(e.getClass() + ": " + e.getMessage());
        digilibError(errMsgType, Error.IMAGE, null, response);
    } catch (IOException e) {
        logger.error(e.getClass() + ": " + e.getMessage());
        digilibError(errMsgType, Error.FILE, null, response);
    } catch (AuthOpException e) {
        logger.error(e.getClass() + ": " + e.getMessage());
        digilibError(errMsgType, Error.AUTH, null, response);
    } catch (Exception e) {
        logger.error("Other Exception: ", e);
    // TODO: should we rethrow or swallow?
    // throw new ServletException(e);
    }
}
Also used : ImageOpException(digilib.image.ImageOpException) DigilibServletRequest(digilib.conf.DigilibServletRequest) ImageJobDescription(digilib.image.ImageJobDescription) AsyncContext(javax.servlet.AsyncContext) IOException(java.io.IOException) ImageOpException(digilib.image.ImageOpException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AuthOpException(digilib.auth.AuthOpException) ServletException(javax.servlet.ServletException) AuthOpException(digilib.auth.AuthOpException) ImageInput(digilib.io.ImageInput)

Example 5 with ImageInput

use of digilib.io.ImageInput 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)

Aggregations

ImageInput (digilib.io.ImageInput)9 ImageSize (digilib.util.ImageSize)6 FileOpException (digilib.io.FileOpException)4 IOException (java.io.IOException)4 ImageSet (digilib.io.ImageSet)3 ServletException (javax.servlet.ServletException)3 AuthOpException (digilib.auth.AuthOpException)2 DigilibServletRequest (digilib.conf.DigilibServletRequest)2 ImageJobDescription (digilib.image.ImageJobDescription)2 ImageOpException (digilib.image.ImageOpException)2 DocuImage (digilib.image.DocuImage)1 ImageWorker (digilib.image.ImageWorker)1 DocuDirectory (digilib.io.DocuDirectory)1 DocuDirent (digilib.io.DocuDirent)1 ImageFileSet (digilib.io.ImageFileSet)1 JsonGenerator (javax.json.stream.JsonGenerator)1 RenderedOp (javax.media.jai.RenderedOp)1 AsyncContext (javax.servlet.AsyncContext)1 ServletOutputStream (javax.servlet.ServletOutputStream)1