/*
 * Copyright 2014 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.util;

import java.awt.image.BufferedImage;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import org.w3c.dom.Element;

/**
 *
 * @author Tilman Hausherr
 */
class JPEGUtil
{
    static final String JPEG_NATIVE_FORMAT = "javax_imageio_jpeg_image_1.0";

    static void updateMetadata(IIOMetadata metadata, int dpi) throws IIOInvalidTreeException
    {
        // https://svn.apache.org/repos/asf/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOJPEGImageWriter.java
        // http://docs.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html

        Element root = (Element) metadata.getAsTree(JPEG_NATIVE_FORMAT);
        Element child = (Element) root.getElementsByTagName("app0JFIF").item(0);
        child.setAttribute("resUnits", "1"); // inch
        child.setAttribute("Xdensity", Integer.toString(dpi));
        child.setAttribute("Ydensity", Integer.toString(dpi));
        metadata.mergeTree(JPEG_NATIVE_FORMAT, root);
    }
}

@@ -646,45 +646,8 @@
 l;%0A%0A
-import java.awt.image.BufferedImage;%0A
 impo
@@ -697,16 +697,16 @@
 eption;%0A
+
 import j
@@ -902,16 +902,203 @@
 _1.0%22;%0A%0A
+    /**%0A     * Set dpi ina JPEG file%0A     * %0A     * @param metadata the meta data%0A     * @param dpi the dpi%0A     * %0A     * @throws IIOInvalidTreeException if something goes wrong%0A     */%0A
     stat
@@ -1339,16 +1339,16 @@
 er.java%0A
+
         
@@ -1443,17 +1443,16 @@
 ta.html%0A
-%0A
         

set and test resolution for JPEG images (forgot javadoc and cleanup)