    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 * @since 1.0-alpha3
    026 */
    027public class PngImagingParameters extends XmpImagingParameters {
    028
    029    public static final byte DEFAULT_BIT_DEPTH = 8;
    030
    031    /**
    032     * Bit depth. Default value is {@literal 8}.
    033     */
    034    private byte bitDepth = DEFAULT_BIT_DEPTH;
    035
    036    private boolean forceIndexedColor = false;
    037
    038    private boolean forceTrueColor = false;
    039
    040    private boolean predictorEnabled = false;
    041
    042    /**
    043     * Used in write operations to indicate the Physical Scale - sCAL.
    044     *
    045     * <p>Valid values: PhysicalScale</p>
    046     *
    047     * @see org.apache.commons.imaging.formats.png.PhysicalScale
    048     */
    049    private PhysicalScale physicalScale = null;
    050
    051    /**
    052     * <p>Only used when writing Png images.</p>
    053     *
    054     * <p>Valid values: a list of WriteTexts.</p>
    055     */
    056    private List<? extends PngText> textChunks = null;
    057
    058    public byte getBitDepth() {
    059        return bitDepth;
    060    }
    061
    062    public void setBitDepth(byte bitDepth) {
    063        this.bitDepth = bitDepth;
    064    }
    065
    066    public boolean isForceIndexedColor() {
    067        return forceIndexedColor;
    068    }
    069
    070    public void setForceIndexedColor(boolean forceIndexedColor) {
    071        this.forceIndexedColor = forceIndexedColor;
    072    }
    073
    074    public boolean isForceTrueColor() {
    075        return forceTrueColor;
    076    }
    077
    078    public void setForceTrueColor(boolean forceTrueColor) {
    079        this.forceTrueColor = forceTrueColor;
    080    }
    081
    082    public PhysicalScale getPhysicalScale() {
    083        return physicalScale;
    084    }
    085
    086    public void setPhysicalScale(PhysicalScale physicalScale) {
    087        this.physicalScale = physicalScale;
    088    }
    089
    090    public List<? extends PngText> getTextChunks() {
    091        return textChunks != null ? Collections.unmodifiableList(textChunks) : null;
    092    }
    093
    094    public void setTextChunks(List<? extends PngText> textChunks) {
    095        this.textChunks = Collections.unmodifiableList(textChunks);
    096    }
    097
    098    /**
    099     * Indicates that the PNG write operation should enable
    100     * the predictor.
    101     * @return true if the predictor is enabled; otherwise, false.
    102     */
    103    public boolean isPredictorEnabled(){
    104        return predictorEnabled;
    105    }
    106
    107    /**
    108     * Sets the enabled status of the predictor. When performing
    109     * data compression on an image, a PNG predictor often results in a
    110     * reduced file size. Predictors are particularly effective on
    111     * photographic images, but may also work on graphics.
    112     * The specification of a predictor may result in an increased
    113     * processing time when writing an image, but will not affect the
    114     * time required to read an image.
    115     * @param predictorEnabled true if a predictor is enabled; otherwise, false.
    116     */
    117    public void setPredictorEnabled(boolean predictorEnabled){
    118        this.predictorEnabled = predictorEnabled;
    119    }
    120}