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;
18
19 import org.apache.commons.imaging.common.BufferedImageFactory;
20
21 /**
22 * Imaging parameters.
23 *
24 * <p>
25 * Contains parameters that are common to all formats. Implementations must include the specific parameters for each image format.
26 * </p>
27 *
28 * @param <E> This type
29 * @since 1.0-alpha3
30 */
31 public class ImagingParameters<E extends ImagingParameters<E>> {
32
33 /**
34 * Whether to throw an exception when any issue occurs during reading or writing a file format. Default is {@code false}.
35 */
36 private boolean strict;
37
38 /**
39 * An optional file name, used for the description of input streams where a file name would be hard (or not possible) to be identified. Default is
40 * {@code null}.
41 */
42 private String fileName;
43
44 /**
45 * Factory to create {@code BufferedImage}s. Default is {@code null}.
46 */
47 private BufferedImageFactory bufferedImageFactory;
48
49 /**
50 * <p>
51 * Parameter key. Used in write operations to indicate the desired pixel density (DPI), and/or aspect ratio.
52 * </p>
53 */
54 private PixelDensity pixelDensity;
55
56 // getters and setters
57
58 @SuppressWarnings("unchecked")
59 public E asThis() {
60 return (E) this;
61 }
62
63 public BufferedImageFactory getBufferedImageFactory() {
64 return bufferedImageFactory;
65 }
66
67 public String getFileName() {
68 return fileName;
69 }
70
71 public PixelDensity getPixelDensity() {
72 return pixelDensity;
73 }
74
75 public boolean isStrict() {
76 return strict;
77 }
78
79 public E setBufferedImageFactory(final BufferedImageFactory bufferedImageFactory) {
80 this.bufferedImageFactory = bufferedImageFactory;
81 return asThis();
82 }
83
84 public E setFileName(final String fileName) {
85 this.fileName = fileName;
86 return asThis();
87 }
88
89 public E setPixelDensity(final PixelDensity pixelDensity) {
90 this.pixelDensity = pixelDensity;
91 return asThis();
92 }
93
94 public E setStrict(final boolean strict) {
95 this.strict = strict;
96 return asThis();
97 }
98 }