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; 018 019/** 020 * Used to specify physical scale when reading or storing image information. 021 */ 022public class PhysicalScale { 023 private static final int METER_UNITS = 1; 024 private static final int RADIAN_UNITS = 2; 025 public static final PhysicalScale UNDEFINED = createFromMeters(-1.0, -1.0); 026 027 private final int units; 028 private final double horizontalUnitsPerPixel; 029 private final double verticalUnitsPerPixel; 030 031 private PhysicalScale(final int units, final double horizontalUnitsPerPixel, 032 final double verticalUnitsPerPixel) { 033 this.units = units; 034 this.horizontalUnitsPerPixel = horizontalUnitsPerPixel; 035 this.verticalUnitsPerPixel = verticalUnitsPerPixel; 036 } 037 038 public static PhysicalScale createFromMeters(final double x, final double y) { 039 return new PhysicalScale(METER_UNITS, x, y); 040 } 041 042 public static PhysicalScale createFromRadians(final double x, final double y) { 043 return new PhysicalScale(RADIAN_UNITS, x, y); 044 } 045 046 public boolean isInMeters() { 047 return METER_UNITS == units; 048 } 049 050 public boolean isInRadians() { 051 return RADIAN_UNITS == units; 052 } 053 054 public double getHorizontalUnitsPerPixel() { 055 return horizontalUnitsPerPixel; 056 } 057 058 public double getVerticalUnitsPerPixel() { 059 return verticalUnitsPerPixel; 060 } 061}