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.formats.tiff.constants;
018
019/**
020 * Defines options for the organization of data in a TIFF file.
021 */
022public enum TiffPlanarConfiguration {
023
024    /**
025     * Indicates that data is stored in an interleaved format, so that component values for each pixel are contiguous in the file.
026     */
027    CHUNKY(TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY),
028    /**
029     * Indicates that data is stored in a non-interleaved format, component values for each pixel are separated into distinct planes.
030     */
031    PLANAR(TiffTagConstants.PLANAR_CONFIGURATION_VALUE_PLANAR);
032
033    /**
034     * Interprets an integer code value to determine the enumerated value. Implements lenient rules for handling non-compliant values.
035     *
036     * @param codeValue an integer code corresponding to the TIFF specification.
037     * @return a valid enumeration.
038     */
039    public static TiffPlanarConfiguration lenientValueOf(final int codeValue) {
040        switch (codeValue) {
041        case TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY:
042            return CHUNKY;
043        case TiffTagConstants.PLANAR_CONFIGURATION_VALUE_PLANAR:
044            return PLANAR;
045        default:
046            return CHUNKY;
047        }
048    }
049
050    /**
051     * The integer code values used for indicating the planar configuration in a TIFF file.
052     */
053    public final int codeValue;
054
055    /**
056     *
057     * @param codeValue format-indicator value for use in file.
058     */
059    TiffPlanarConfiguration(final int codeValue) {
060        this.codeValue = codeValue;
061    }
062}