001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 * under the License. 014 */ 015 016package org.apache.commons.imaging.formats.png; 017 018import java.util.Collections; 019import java.util.List; 020 021import org.apache.commons.imaging.common.XmpImagingParameters; 022 023/** 024 * PNG format parameters. 025 * 026 * @since 1.0-alpha3 027 */ 028public class PngImagingParameters extends XmpImagingParameters<PngImagingParameters> { 029 030 public static final byte DEFAULT_BIT_DEPTH = 8; 031 032 /** 033 * Bit depth. Default value is {@literal 8}. 034 */ 035 private byte bitDepth = DEFAULT_BIT_DEPTH; 036 037 private boolean forceIndexedColor; 038 039 private boolean forceTrueColor; 040 041 private boolean predictorEnabled; 042 043 /** 044 * Used in write operations to indicate the Physical Scale - sCAL. 045 * 046 * <p> 047 * Valid values: PhysicalScale 048 * </p> 049 * 050 * @see org.apache.commons.imaging.formats.png.PhysicalScale 051 */ 052 private PhysicalScale physicalScale; 053 054 /** 055 * <p> 056 * Only used when writing PNG images. 057 * </p> 058 * 059 * <p> 060 * Valid values: a list of WriteTexts. 061 * </p> 062 */ 063 private List<? extends AbstractPngText> textChunks; 064 065 public byte getBitDepth() { 066 return bitDepth; 067 } 068 069 public PhysicalScale getPhysicalScale() { 070 return physicalScale; 071 } 072 073 public List<? extends AbstractPngText> getTextChunks() { 074 return textChunks != null ? Collections.unmodifiableList(textChunks) : null; 075 } 076 077 public boolean isForceIndexedColor() { 078 return forceIndexedColor; 079 } 080 081 public boolean isForceTrueColor() { 082 return forceTrueColor; 083 } 084 085 /** 086 * Indicates that the PNG write operation should enable the predictor. 087 * 088 * @return true if the predictor is enabled; otherwise, false. 089 */ 090 public boolean isPredictorEnabled() { 091 return predictorEnabled; 092 } 093 094 public PngImagingParameters setBitDepth(final byte bitDepth) { 095 this.bitDepth = bitDepth; 096 return asThis(); 097 } 098 099 public PngImagingParameters setForceIndexedColor(final boolean forceIndexedColor) { 100 this.forceIndexedColor = forceIndexedColor; 101 return asThis(); 102 } 103 104 public PngImagingParameters setForceTrueColor(final boolean forceTrueColor) { 105 this.forceTrueColor = forceTrueColor; 106 return asThis(); 107 } 108 109 public PngImagingParameters setPhysicalScale(final PhysicalScale physicalScale) { 110 this.physicalScale = physicalScale; 111 return asThis(); 112 } 113 114 /** 115 * Sets the enabled status of the predictor. When performing data compression on an image, a PNG predictor often results in a reduced file size. Predictors 116 * are particularly effective on photographic images, but may also work on graphics. The specification of a predictor may result in an increased processing 117 * time when writing an image, but will not affect the time required to read an image. 118 * 119 * @param predictorEnabled true if a predictor is enabled; otherwise, false. 120 * @return {@code this} instance. 121 */ 122 public PngImagingParameters setPredictorEnabled(final boolean predictorEnabled) { 123 this.predictorEnabled = predictorEnabled; 124 return asThis(); 125 } 126 127 public PngImagingParameters setTextChunks(final List<? extends AbstractPngText> textChunks) { 128 this.textChunks = Collections.unmodifiableList(textChunks); 129 return asThis(); 130 } 131}