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 final 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 public static PhysicalScale createFromMeters(final double x, final double y) { 028 return new PhysicalScale(METER_UNITS, x, y); 029 } 030 031 public static PhysicalScale createFromRadians(final double x, final double y) { 032 return new PhysicalScale(RADIAN_UNITS, x, y); 033 } 034 035 private final int units; 036 037 private final double horizontalUnitsPerPixel; 038 039 private final double verticalUnitsPerPixel; 040 041 private PhysicalScale(final int units, final double horizontalUnitsPerPixel, final double verticalUnitsPerPixel) { 042 this.units = units; 043 this.horizontalUnitsPerPixel = horizontalUnitsPerPixel; 044 this.verticalUnitsPerPixel = verticalUnitsPerPixel; 045 } 046 047 public double getHorizontalUnitsPerPixel() { 048 return horizontalUnitsPerPixel; 049 } 050 051 public double getVerticalUnitsPerPixel() { 052 return verticalUnitsPerPixel; 053 } 054 055 public boolean isInMeters() { 056 return METER_UNITS == units; 057 } 058 059 public boolean isInRadians() { 060 return RADIAN_UNITS == units; 061 } 062}