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.png.chunks; 018 019import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes; 020import static org.apache.commons.imaging.common.BinaryFunctions.readByte; 021 022import java.io.ByteArrayInputStream; 023import java.io.IOException; 024 025public final class PngChunkPhys extends PngChunk { 026 027 private final int pixelsPerUnitXAxis; 028 private final int pixelsPerUnitYAxis; 029 private final int unitSpecifier; 030 031 public PngChunkPhys(final int length, final int chunkType, final int crc, final byte[] bytes) throws IOException { 032 super(length, chunkType, crc, bytes); 033 final ByteArrayInputStream is = new ByteArrayInputStream(bytes); 034 pixelsPerUnitXAxis = read4Bytes("PixelsPerUnitXAxis", is, "Not a Valid PNG File: pHYs Corrupt", getByteOrder()); 035 pixelsPerUnitYAxis = read4Bytes("PixelsPerUnitYAxis", is, "Not a Valid PNG File: pHYs Corrupt", getByteOrder()); 036 unitSpecifier = readByte("Unit specifier", is, "Not a Valid PNG File: pHYs Corrupt"); 037 } 038 039 public int getPixelsPerUnitXAxis() { 040 return pixelsPerUnitXAxis; 041 } 042 043 public int getPixelsPerUnitYAxis() { 044 return pixelsPerUnitYAxis; 045 } 046 047 public int getUnitSpecifier() { 048 return unitSpecifier; 049 } 050 051}