    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.imaging.formats.jpeg.segments;
    018
    019import java.io.ByteArrayInputStream;
    020import java.io.IOException;
    021import java.io.InputStream;
    022
    023import org.apache.commons.imaging.ImageReadException;
    024import org.apache.commons.imaging.ImagingParameters;
    025import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser;
    026import org.apache.commons.imaging.formats.jpeg.iptc.PhotoshopApp13Data;
    027
    028public class App13Segment extends AppnSegment {
    029
    030    public App13Segment(final int marker, final byte[] segmentData)
    031            throws IOException {
    032        this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
    033    }
    034
    035    public App13Segment(final int marker, final int markerLength,
    036            final InputStream is) throws IOException {
    037        super(marker, markerLength, is);
    038
    039        // isIPTCJpegSegment = new IptcParser().isIPTCJpegSegment(bytes);
    040        // if (isIPTCJpegSegment)
    041        // {
    042        // /*
    043        // * In practice, App13 segments are only used for Photoshop/IPTC
    044        // * metadata. However, we should not treat App13 signatures without
    045        // * Photoshop's signature as Photoshop/IPTC segments.
    046        // */
    047        // boolean verbose = false;
    048        // boolean strict = false;
    049        // elements.addAll(new IptcParser().parseIPTCJPEGSegment(bytes,
    050        // verbose, strict));
    051        // }
    052    }
    053
    054    public boolean isPhotoshopJpegSegment() {
    055        return new IptcParser().isPhotoshopJpegSegment(getSegmentData());
    056    }
    057
    058    public PhotoshopApp13Data parsePhotoshopSegment(final ImagingParameters params)
    059            throws ImageReadException, IOException {
    060        /*
    061         * In practice, App13 segments are only used for Photoshop/IPTC
    062         * metadata. However, we should not treat App13 signatures without
    063         * Photoshop's signature as Photoshop/IPTC segments.
    064         */
    065        if (!isPhotoshopJpegSegment()) {
    066            return null;
    067        }
    068
    069        return new IptcParser().parsePhotoshopSegment(getSegmentData(), params);
    070    }
    071}