    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.ImagingException;
    024import org.apache.commons.imaging.ImagingParameters;
    025import org.apache.commons.imaging.formats.jpeg.JpegImagingParameters;
    026import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser;
    027import org.apache.commons.imaging.formats.jpeg.iptc.PhotoshopApp13Data;
    028
    029public class App13Segment extends AppnSegment {
    030
    031    public App13Segment(final int marker, final byte[] segmentData) throws IOException {
    032        this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
    033    }
    034
    035    public App13Segment(final int marker, final int markerLength, final InputStream is) throws IOException {
    036        super(marker, markerLength, is);
    037
    038        // isIPTCJpegSegment = new IptcParser().isIPTCJpegSegment(bytes);
    039        // if (isIPTCJpegSegment)
    040        // {
    041        // /*
    042        // * In practice, App13 segments are only used for Photoshop/IPTC
    043        // * metadata. However, we should not treat App13 signatures without
    044        // * Photoshop's signature as Photoshop/IPTC segments.
    045        // */
    046        // boolean verbose = false;
    047        // boolean strict = false;
    048        // elements.addAll(new IptcParser().parseIPTCJPEGSegment(bytes,
    049        // verbose, strict));
    050        // }
    051    }
    052
    053    public boolean isPhotoshopJpegSegment() {
    054        return new IptcParser().isPhotoshopJpegSegment(getSegmentData());
    055    }
    056
    057    public PhotoshopApp13Data parsePhotoshopSegment(final ImagingParameters<JpegImagingParameters> params) throws ImagingException, IOException {
    058        /*
    059         * In practice, App13 segments are only used for Photoshop/IPTC metadata. However, we should not treat App13 signatures without Photoshop's signature as
    060         * Photoshop/IPTC segments.
    061         */
    062        if (!isPhotoshopJpegSegment()) {
    063            return null;
    064        }
    065
    066        return new IptcParser().parsePhotoshopSegment(getSegmentData(), params);
    067    }
    068}