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.photometricinterpreters;
018
019import java.io.IOException;
020
021import org.apache.commons.imaging.ImageReadException;
022import org.apache.commons.imaging.common.ImageBuilder;
023
024/**
025 * Interpreter for photometric information in TIFF images. The photometric
026 * interpretation tag is a requirement for valid TIFF images, and defines the
027 * color space of the image data.
028 *
029 * @see <a href=
030 *      "https://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html">
031 *      Baseline TIFF Tag PhotometricInterpretation </a>
032 */
033public abstract class PhotometricInterpreter {
034    protected final int samplesPerPixel;
035    private final int[] bitsPerSample;
036    protected final int predictor;
037    protected final int width;
038    protected final int height;
039
040    public PhotometricInterpreter(final int samplesPerPixel, final int[] bitsPerSample,
041            final int predictor, final int width, final int height) {
042        this.samplesPerPixel = samplesPerPixel;
043        this.bitsPerSample = bitsPerSample;
044        this.predictor = predictor;
045        this.width = width;
046        this.height = height;
047    }
048
049    public abstract void interpretPixel(ImageBuilder imageBuilder,
050            int[] samples, int x, int y) throws ImageReadException, IOException;
051
052    protected int getBitsPerSample(final int offset) {
053        return bitsPerSample[offset];
054    }
055}