Package gov.lanl.adore.djatoka.util

Source Code of gov.lanl.adore.djatoka.util.ImageRecordUtils

/*
* Copyright (c) 2008 Los Alamos National Security, LLC.
*
* Los Alamos National Laboratory Research Library Digital Library Research &
* Prototyping Team
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

package gov.lanl.adore.djatoka.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ij.ImagePlus;
import ij.io.Opener;
import ij.process.ImageProcessor;

/**
* Image Information Utility used to obtain width and height information. This util is useful when processing images
* using external compression applications, such as Kakadu JPEG 2000 kdu_compress.
*
* @author Ryan Chute
* @author Kevin S. Clarke <a href="mailto:ksclarke@gmail.com">ksclarke@gmail.com</a>
*/
public class ImageRecordUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(ImageRecordUtils.class);

    /**
     * Return an ImageRecord containing the images pixel dimensions.
     *
     * @param file absolute file path to image
     * @return ImageRecord containing the images pixel dimensions
     */
    public static ImageRecord getImageDimensions(final String file) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Getting image dimensions from: {}", file);
        }

        final ImageRecord dim = new ImageRecord(file);
        final Opener o = new Opener();
        final ImagePlus imp = o.openImage(file);
        if (imp == null) {
            return null;
        }
        ImageProcessor ip = imp.getProcessor();
        final int width = ip.getWidth();
        final int height = ip.getHeight();

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("{} (width: {} | height: {})", file, Integer.toString(width), Integer.toString(height));
        }

        dim.setWidth(width);
        dim.setHeight(height);
        ip = null;
        return dim;
    }
}
TOP

Related Classes of gov.lanl.adore.djatoka.util.ImageRecordUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.