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  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[] {
31              new FormatInfo(ImageFormats.PNG, true, true,
32                      COLOR_FULL_RGB, true, true), //
33              new FormatInfo(ImageFormats.ICO, true, true,
34                      COLOR_FULL_RGB, true, true), //
35              new FormatInfo(ImageFormats.TIFF, true, true,
36                      COLOR_FULL_RGB, true, true), //
37              new FormatInfo(ImageFormats.BMP, true, true,
38                      COLOR_FULL_RGB, true, true), //
39              new FormatInfo(ImageFormats.PCX, true, true,
40                      COLOR_FULL_RGB, true, true), //
41              new FormatInfo(ImageFormats.DCX, true, true,
42                      COLOR_FULL_RGB, true, true), //
43      };
44  
45      static FormatInfo[] READ_WRITE_FORMATS = new FormatInfo[] {
46              new FormatInfo(ImageFormats.PNG, true, true,
47                      COLOR_FULL_RGB, true, true), //
48              new FormatInfo(ImageFormats.GIF, true, true,
49                      COLOR_LIMITED_INDEX, true, false), //
50              new FormatInfo(ImageFormats.ICO, true, true,
51                      COLOR_FULL_RGB, true, true), //
52              new FormatInfo(ImageFormats.TIFF, true, true,
53                      COLOR_FULL_RGB, true, true), //
54              new FormatInfo(ImageFormats.BMP, true, true,
55                      COLOR_FULL_RGB, true, true), //
56              new FormatInfo(ImageFormats.PBM, true, true,
57                      COLOR_BITMAP, true, false), //
58              new FormatInfo(ImageFormats.PGM, true, true,
59                      COLOR_GRAYSCALE, true, false), //
60              new FormatInfo(ImageFormats.PPM, true, true,
61                      COLOR_FULL_RGB, true, false), //
62              new FormatInfo(ImageFormats.PAM, true, true,
63                      COLOR_FULL_RGB, true, false),//
64              new FormatInfo(ImageFormats.WBMP, true, true,
65                      COLOR_BITMAP, true, false), //
66              new FormatInfo(ImageFormats.PCX, true, true,
67                      COLOR_FULL_RGB, true, true), //
68              new FormatInfo(ImageFormats.DCX, true, true,
69                      COLOR_FULL_RGB, true, true), //
70              new FormatInfo(ImageFormats.XBM, true, true,
71                      COLOR_BITMAP, false, false), //
72              new FormatInfo(ImageFormats.XPM, true, true,
73                      COLOR_FULL_RGB, false, false), //
74      };
75  
76      static final FormatInfo[] ALL_FORMATS = { //
77              new FormatInfo(ImageFormats.PNG, true, true,
78                      COLOR_FULL_RGB, true, true), //
79              new FormatInfo(ImageFormats.GIF, true, true,
80                      COLOR_LIMITED_INDEX, true, false), //
81              new FormatInfo(ImageFormats.ICO, true, true,
82                      COLOR_FULL_RGB, true, true), //
83              new FormatInfo(ImageFormats.TIFF, true, true,
84                      COLOR_FULL_RGB, true, true), //
85              new FormatInfo(ImageFormats.JPEG, true, false,
86                      COLOR_FULL_RGB, true, true), //
87              new FormatInfo(ImageFormats.BMP, true, true,
88                      COLOR_FULL_RGB, true, true), //
89              new FormatInfo(ImageFormats.PSD, true, false,
90                      COLOR_FULL_RGB, true, true), //
91              new FormatInfo(ImageFormats.PBM, true, true,
92                      COLOR_BITMAP, true, false), //
93              new FormatInfo(ImageFormats.PGM, true, true,
94                      COLOR_GRAYSCALE, true, false), //
95              new FormatInfo(ImageFormats.PPM, true, true,
96                      COLOR_FULL_RGB, true, false), //
97              new FormatInfo(ImageFormats.PAM, true, true,
98                      COLOR_FULL_RGB, true, false),//
99              new FormatInfo(ImageFormats.PNM, true, true,
100                     COLOR_FULL_RGB, true, false), //
101             new FormatInfo(ImageFormats.TGA, false, false,
102                     COLOR_FULL_RGB, true, true), //
103             new FormatInfo(ImageFormats.WBMP, true, true,
104                     COLOR_BITMAP, true, false), //
105             new FormatInfo(ImageFormats.PCX, true, true,
106                     COLOR_FULL_RGB, true, true), //
107             new FormatInfo(ImageFormats.DCX, true, true,
108                     COLOR_FULL_RGB, true, true), //
109             new FormatInfo(ImageFormats.XBM, true, true,
110                     COLOR_BITMAP, false, false), //
111             new FormatInfo(ImageFormats.XPM, true, true,
112                     COLOR_FULL_RGB, false, false), //
113     };
114 
115     final ImageFormat format;
116     final boolean canRead;
117     final boolean canWrite;
118     final int colorSupport;
119     final boolean identicalSecondWrite;
120     final boolean preservesResolution;
121 
122     FormatInfo(final ImageFormat format, final boolean canRead,
123                       final boolean canWrite, final int colorSupport,
124                       final boolean identicalSecondWrite,
125                       final boolean preservesResolution) {
126         this.canRead = canRead;
127         this.canWrite = canWrite;
128         this.colorSupport = colorSupport;
129         this.format = format;
130         this.identicalSecondWrite = identicalSecondWrite;
131         this.preservesResolution = preservesResolution;
132     }
133 }