/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library 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 2.1 of the License, or (at your option) * any later version. * * This library 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 GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Oct 15, 2005 */ package ml.image; /** * A framebuffer channel. A framebuffer consists of several * named channels. This class contains the data of one single * channel. It stores the data in a floating point format, * thus providing high dynamic range data storage capabilities. * * @see Framebuffer * * @author gregor */ public class Channel implements Cloneable { private String name; private int width, height; private float[] data; /** * Default constructor. It takes the name of the channel * and the size. * * @param name the name of the channel * @param width the width of the data * @param height the height of the data */ public Channel(String name, int width, int height) { this.name=name; this.width=width; this.height=height; data=new float[width*height]; } /** * @return the name of the channel */ public String getName() { return name; } /** * @return the width of the channel */ public int getWidth() { return width; } /** * @return the height of the channel */ public int getHeight() { return height; } /** * Return the value of the pixel at the given position. * * @param x the x coordinate of the pixel * @param y the y coordinate of the pixel * @return the pixel value */ public float getPixel(int x, int y) { return data[y*width+x]; } /** * Set the pixel at the given position to the given value. * * @param x the x coordinate of the pixel * @param y the y coordinate of the pixel * @param value the new pixel value */ public void putPixel(int x, int y, float value) { data[y*width+x]=value; } /** * Return the internal data buffer for direct manipulation. * The buffer is a single array with a row-major ordering * of the data. * * @return the internal data buffer */ public float[] getBuffer() { return data; } @Override public Channel clone() { Channel channel=null; try { channel=(Channel)super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } channel.name=name; channel.width=width; channel.height=height; channel.data=data.clone(); return channel; } }