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