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  
18  package org.apache.commons.imaging.roundtrip;
19  
20  import org.apache.commons.imaging.ImageFormat;
21  import org.apache.commons.imaging.ImageFormats;
22  
23  final class FormatInfo {
24  
25      static final int COLOR_FULL_RGB = 0;
26      static final int COLOR_LIMITED_INDEX = 1;
27      static final int COLOR_GRAYSCALE = 2;
28      static final int COLOR_BITMAP = 3;
29  
30      static final FormatInfo[] PRESERVING_RESOLUTION_FORMATS = { new FormatInfo(ImageFormats.PNG, true, true, COLOR_FULL_RGB, true, true), //
31              new FormatInfo(ImageFormats.ICO, true, true, COLOR_FULL_RGB, true, true), //
32              new FormatInfo(ImageFormats.TIFF, true, true, COLOR_FULL_RGB, true, true), //
33              new FormatInfo(ImageFormats.BMP, true, true, COLOR_FULL_RGB, true, true), //
34              new FormatInfo(ImageFormats.PCX, true, true, COLOR_FULL_RGB, true, true), //
35              new FormatInfo(ImageFormats.DCX, true, true, COLOR_FULL_RGB, true, true), //
36      };
37  
38      static final FormatInfo[] READ_WRITE_FORMATS = { new FormatInfo(ImageFormats.PNG, true, true, COLOR_FULL_RGB, true, true), //
39              new FormatInfo(ImageFormats.GIF, true, true, COLOR_LIMITED_INDEX, true, false), //
40              new FormatInfo(ImageFormats.ICO, true, true, COLOR_FULL_RGB, true, true), //
41              new FormatInfo(ImageFormats.TIFF, true, true, COLOR_FULL_RGB, true, true), //
42              new FormatInfo(ImageFormats.BMP, true, true, COLOR_FULL_RGB, true, true), //
43              new FormatInfo(ImageFormats.PBM, true, true, COLOR_BITMAP, true, false), //
44              new FormatInfo(ImageFormats.PGM, true, true, COLOR_GRAYSCALE, true, false), //
45              new FormatInfo(ImageFormats.PPM, true, true, COLOR_FULL_RGB, true, false), //
46              new FormatInfo(ImageFormats.PAM, true, true, COLOR_FULL_RGB, true, false), //
47              new FormatInfo(ImageFormats.WBMP, true, true, COLOR_BITMAP, true, false), //
48              new FormatInfo(ImageFormats.PCX, true, true, COLOR_FULL_RGB, true, true), //
49              new FormatInfo(ImageFormats.DCX, true, true, COLOR_FULL_RGB, true, true), //
50              new FormatInfo(ImageFormats.XBM, true, true, COLOR_BITMAP, false, false), //
51              new FormatInfo(ImageFormats.XPM, true, true, COLOR_FULL_RGB, false, false), //
52      };
53  
54      static final FormatInfo[] ALL_FORMATS = { //
55              new FormatInfo(ImageFormats.PNG, true, true, COLOR_FULL_RGB, true, true), //
56              new FormatInfo(ImageFormats.GIF, true, true, COLOR_LIMITED_INDEX, true, false), //
57              new FormatInfo(ImageFormats.ICO, true, true, COLOR_FULL_RGB, true, true), //
58              new FormatInfo(ImageFormats.TIFF, true, true, COLOR_FULL_RGB, true, true), //
59              new FormatInfo(ImageFormats.JPEG, true, false, COLOR_FULL_RGB, true, true), //
60              new FormatInfo(ImageFormats.BMP, true, true, COLOR_FULL_RGB, true, true), //
61              new FormatInfo(ImageFormats.PSD, true, false, COLOR_FULL_RGB, true, true), //
62              new FormatInfo(ImageFormats.PBM, true, true, COLOR_BITMAP, true, false), //
63              new FormatInfo(ImageFormats.PGM, true, true, COLOR_GRAYSCALE, true, false), //
64              new FormatInfo(ImageFormats.PPM, true, true, COLOR_FULL_RGB, true, false), //
65              new FormatInfo(ImageFormats.PAM, true, true, COLOR_FULL_RGB, true, false), //
66              new FormatInfo(ImageFormats.PNM, true, true, COLOR_FULL_RGB, true, false), //
67              new FormatInfo(ImageFormats.TGA, false, false, COLOR_FULL_RGB, true, true), //
68              new FormatInfo(ImageFormats.WBMP, true, true, COLOR_BITMAP, true, false), //
69              new FormatInfo(ImageFormats.PCX, true, true, COLOR_FULL_RGB, true, true), //
70              new FormatInfo(ImageFormats.DCX, true, true, COLOR_FULL_RGB, true, true), //
71              new FormatInfo(ImageFormats.XBM, true, true, COLOR_BITMAP, false, false), //
72              new FormatInfo(ImageFormats.XPM, true, true, COLOR_FULL_RGB, false, false), //
73      };
74  
75      final ImageFormat format;
76      final boolean canRead;
77      final boolean canWrite;
78      final int colorSupport;
79      final boolean identicalSecondWrite;
80      final boolean preservesResolution;
81  
82      FormatInfo(final ImageFormat format, final boolean canRead, final boolean canWrite, final int colorSupport, final boolean identicalSecondWrite,
83              final boolean preservesResolution) {
84          this.canRead = canRead;
85          this.canWrite = canWrite;
86          this.colorSupport = colorSupport;
87          this.format = format;
88          this.identicalSecondWrite = identicalSecondWrite;
89          this.preservesResolution = preservesResolution;
90      }
91  
92      @Override
93      public String toString() {
94          return "FormatInfo{" + "format=" + format + ", canRead=" + canRead + ", canWrite=" + canWrite + ", colorSupport=" + colorSupport
95                  + ", identicalSecondWrite=" + identicalSecondWrite + ", preservesResolution=" + preservesResolution + '}';
96      }
97  }