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