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; 018 019import org.apache.commons.imaging.common.BufferedImageFactory; 020 021/** 022 * Imaging parameters. 023 * 024 * <p> 025 * Contains parameters that are common to all formats. Implementations must include the specific parameters for each image format. 026 * </p> 027 * 028 * @param <E> This type 029 * @since 1.0-alpha3 030 */ 031public class ImagingParameters<E extends ImagingParameters<E>> { 032 033 /** 034 * Whether to throw an exception when any issue occurs during reading or writing a file format. Default is {@code false}. 035 */ 036 private boolean strict; 037 038 /** 039 * 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 040 * {@code null}. 041 */ 042 private String fileName; 043 044 /** 045 * Creates {@code BufferedImage}s. Default is {@code null}. 046 */ 047 private BufferedImageFactory bufferedImageFactory; 048 049 /** 050 * <p> 051 * Parameter key. Used in write operations to indicate the desired pixel density (DPI), and/or aspect ratio. 052 * </p> 053 */ 054 private PixelDensity pixelDensity; 055 056 /** 057 * Returns this instance typed as the subclass type {@code E}. 058 * <p> 059 * This is the same as the expression: 060 * </p> 061 * <pre> 062 * (B) this 063 * </pre> 064 * 065 * @return this instance typed as the subclass type {@code E}. 066 */ 067 @SuppressWarnings("unchecked") 068 public E asThis() { 069 return (E) this; 070 } 071 072 public BufferedImageFactory getBufferedImageFactory() { 073 return bufferedImageFactory; 074 } 075 076 public String getFileName() { 077 return fileName; 078 } 079 080 public PixelDensity getPixelDensity() { 081 return pixelDensity; 082 } 083 084 public boolean isStrict() { 085 return strict; 086 } 087 088 public E setBufferedImageFactory(final BufferedImageFactory bufferedImageFactory) { 089 this.bufferedImageFactory = bufferedImageFactory; 090 return asThis(); 091 } 092 093 public E setFileName(final String fileName) { 094 this.fileName = fileName; 095 return asThis(); 096 } 097 098 public E setPixelDensity(final PixelDensity pixelDensity) { 099 this.pixelDensity = pixelDensity; 100 return asThis(); 101 } 102 103 public E setStrict(final boolean strict) { 104 this.strict = strict; 105 return asThis(); 106 } 107}