View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.formats.png;
18  
19  /**
20   * Used to specify physical scale when reading or storing image information.
21   */
22  public final class PhysicalScale {
23      private static final int METER_UNITS = 1;
24      private static final int RADIAN_UNITS = 2;
25      public static final PhysicalScale UNDEFINED = createFromMeters(-1.0, -1.0);
26  
27      public static PhysicalScale createFromMeters(final double x, final double y) {
28          return new PhysicalScale(METER_UNITS, x, y);
29      }
30  
31      public static PhysicalScale createFromRadians(final double x, final double y) {
32          return new PhysicalScale(RADIAN_UNITS, x, y);
33      }
34  
35      private final int units;
36  
37      private final double horizontalUnitsPerPixel;
38  
39      private final double verticalUnitsPerPixel;
40  
41      private PhysicalScale(final int units, final double horizontalUnitsPerPixel, final double verticalUnitsPerPixel) {
42          this.units = units;
43          this.horizontalUnitsPerPixel = horizontalUnitsPerPixel;
44          this.verticalUnitsPerPixel = verticalUnitsPerPixel;
45      }
46  
47      public double getHorizontalUnitsPerPixel() {
48          return horizontalUnitsPerPixel;
49      }
50  
51      public double getVerticalUnitsPerPixel() {
52          return verticalUnitsPerPixel;
53      }
54  
55      public boolean isInMeters() {
56          return METER_UNITS == units;
57      }
58  
59      public boolean isInRadians() {
60          return RADIAN_UNITS == units;
61      }
62  }