/* * 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; /** * \package ml.image * * This is a helper library for processing images. * In particular it contains a framework for loading * and saving image files from and to different formats. * * This package is part of the core program. */ import java.util.ArrayList; import java.util.List; /** * A framebuffer container class. A Frambuffer in moonlight * is simply a group of named channels which may or may not * correspond to certain colors or other values like alpha * or depth. * * @see Channel * * @author gregor */ public class Framebuffer implements Cloneable { private int width; private int height; private ArrayList channels; /** * Constructor creating a framebuffer with a given size in pixels * * @param width width of the framebuffer * @param height height of the framebuffer */ public Framebuffer(int width, int height) { this.width=width; this.height=height; channels=new ArrayList(); } /** * @return the width of the framebuffer */ public int getWidth() { return width; } /** * @return the height of the framebuffer */ public int getHeight() { return height; } /** * Add a new channel with the given name. * * @param name the name of the channel to add */ public void addChannel(String name) { channels.add(new Channel(name,width,height)); } /** * Return the channel with the given name. * * @param name the name of the channel * @return the channel or null if it does not exist. */ public Channel getChannel(String name) { for(int i=0;i getChannels() { ArrayList channelNames=new ArrayList(); for(Channel channel : channels) { channelNames.add(channel.getName()); } return channelNames; } @Override public Framebuffer clone() { Framebuffer framebuffer=null; try { framebuffer=(Framebuffer)super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } framebuffer.width=width; framebuffer.height=height; framebuffer.channels=new ArrayList(); for(Channel channel : channels) { framebuffer.channels.add(channel.clone()); } return framebuffer; } }