Example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser JpegImageParser

List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageParser JpegImageParser

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser JpegImageParser.

Prototype

public JpegImageParser() 

Source Link

Usage

From source file:com.att.aro.core.bestpractice.impl.ImageMetaDataImpl.java

private void runTestForFiles(List<String> imageList, List<ImageMdataEntry> entrylist, Session session,
        HttpRequestResponseInfo req, String imagePath, String imgFile, String extractedImageName, int pos,
        File[] listOfFiles) {//from   w  ww  .  j  av  a  2 s  .  c  om
    String imgFullName = "";
    String imgExtn = "";

    // check folder exists
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            imgFullName = listOfFiles[i].getName();
            if (extractedImageName.equalsIgnoreCase(imgFullName)) {
                imgExtn = imgFullName.substring(pos, imgFullName.length());
                imgFile = imagePath + imgFullName;
                if (Util.isJPG(new File(imgFile), imgExtn)) {
                    extractMetadata(imgFile);
                }
                // isMetaDataPresent = true;
            } // clear
        }

        if (isMetaDataPresent) {
            File getImage = new File(imgFile);
            JpegImageParser imgP = new JpegImageParser();
            byte[] mdata = null;
            long mSize = 0;

            try {
                mdata = imgP.getExifRawData(new ByteSourceFile(getImage));
                mSize = mdata.length;
            } catch (ImageReadException | IOException e) {

            }
            imageList.add(imgFile);

            long iSize = getImage.length();

            double savings = (mSize * 100) / iSize;

            if (savings >= 15.00) {
                entrylist.add(new ImageMdataEntry(req, session.getDomainName(), imgFile,
                        Util.doubleFileSize(iSize), Util.doubleFileSize(mSize),
                        String.valueOf(new DecimalFormat("##.##").format(savings)) + "%"));
            }
            isMetaDataPresent = false;
        }
    }
}

From source file:org.gmdev.pdftrick.utils.CustomExtraImgReader.java

/**
 * Check if the images has Adobe byte marker and if is a YCCK type
 * @param imageByteArray/*from   ww  w .  ja v a 2  s.c om*/
 * @throws IOException
 * @throws ImageReadException
 */
private static void checkAdobeMarker(byte[] imageByteArray) throws IOException, ImageReadException {
    JpegImageParser parser = new JpegImageParser();
    ByteSource byteSource = new ByteSourceArray(imageByteArray);
    List<Segment> segments = parser.readSegments(byteSource, new int[] { 0xffee }, true);
    if (segments != null && segments.size() >= 1) {
        //UnknownSegment app14Segment = (UnknownSegment) segments.get(0);
        //App14Segment app14Segment = (App14Segment) segments.get(0);
        GenericSegment app14Segment = (GenericSegment) segments.get(0);
        byte[] data = app14Segment.getSegmentData();
        if (data.length >= 12 && data[0] == 'A' && data[1] == 'd' && data[2] == 'o' && data[3] == 'b'
                && data[4] == 'e') {
            hasAdobeMarker = true;
            byte[] data_2 = app14Segment.getSegmentData();
            int transform = data_2[11] & 0xff;
            if (transform == 2)
                colorType = COLOR_TYPE_YCCK;
        }
    }
}