All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ojil.algorithm.RgbAdjustBrightness Maven / Gradle / Ivy

There is a newer version: 0.0.11
Show newest version
/*
 * RgbAdjustBrightness.java
 *
 * Created on August 27, 2006, 2:38 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 * Copyright 2007 by Jon A. Webb
 *     This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the Lesser GNU General Public License
 *    along with this program.  If not, see .
 *
 */

package com.github.ojil.algorithm;
import com.github.ojil.core.Error;
import com.github.ojil.core.Image;
import com.github.ojil.core.PipelineStage;
import com.github.ojil.core.RgbImage;
import com.github.ojil.core.RgbVal;

/**
 * Pipeline stage adjusts brightness of red, green, and blue bands independently
 * by a multiplicative factor.
 * @author webb
 */
public class RgbAdjustBrightness extends PipelineStage {
    int nRedFac, nGreenFac, nBlueFac;
    
    /** Creates a new instance of RgbAdjustBrightness. Multiplicative factors
     * are specified here.
     *
     * @param nRed red factor (scaled by 256)
     * @param nGreen green factor (scaled by 256)
     * @param nBlue blue factor (scaled by 256)
     */
    public RgbAdjustBrightness(
            int nRed,
            int nGreen,
            int nBlue) {
        this.nRedFac = nRed;
        this.nGreenFac = nGreen;
        this.nBlueFac = nBlue;
    }
    
    /** Adjust brightness of RGB image. This is an in-place modification;
     * input is modified.
     *
     * @param image the input image.
     */
    public void push(Image image) throws com.github.ojil.core.Error {
        if (!(image instanceof RgbImage)) {
            throw new Error(
                			Error.PACKAGE.ALGORITHM,
                			ErrorCodes.IMAGE_NOT_RGBIMAGE,
                			image.toString(),
                			null,
                			null);
        }
        RgbImage imageInput = (RgbImage) image;
        Integer[] rgb = imageInput.getData();
        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy