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