/* MediaMath.java * * Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Tero Mäyränen */ package org.gzigzag.module.multimedia; import org.gzigzag.*; import java.awt.*; import java.awt.image.*; import java.util.*; /** * MediaMath is a collection of MediaZObs that do mathematical functions. * If at all possible, in the future this should be done with some actual * mathematical language designed for GZigZag... */ public class MediaMath { public static final String rcsid = "$Id: MediaMath.java,v 1.1 2002/10/07 12:37:34 tuukkah Exp $"; public abstract class MathZOb extends MediaZOb { protected Pixels pix = null; protected Vector oldframes = new Vector(); /** * The inputs for these are just lists of MediaZObs connected on d.2, * unlike the normal way, which is a list of parameter names, which * in turn are connected to ZObs on d.1........ */ protected Vector readInputPixels() { Vector v = new Vector(); Pixels inpix; ZZCell d = cell; do { inpix = MediaZOb.newMediaZOb(d).getPixels(); v.addElement(inpix); d = d.s("d.2"); } while ((d != null) && (!d.equals(cell))); return v; } protected Vector readInputZObs() { Vector v = new Vector(); MediaZOb mz; ZZCell d = cell; do { mz = MediaZOb.newMediaZOb(d); v.addElement(mz); d = d.s("d.2"); } while ((d != null) && (!d.equals(cell))); return v; } /** * Allocate enough pixels to fit all inputs in their correct coordinate positions. */ protected void createPix(Vector inputs) { if (inputs.size() < 1) { pix = new Pixels(1, 1); pix.getPixels()[0] = 0xff000000; return; } Pixels inpix = (Pixels)inputs.elementAt(0); int w = inpix.getWidth(), h = inpix.getHeight(); int x = inpix.getX(), y = inpix.getY(); for (int i=1; i (w + x)) { w = inpix.getWidth() + inpix.getX() - x; } if ((inpix.getHeight() + inpix.getY()) > (h + y)) { h = inpix.getHeight() + inpix.getY() - y; } } if (pix == null) { pix = new Pixels(w, h); } else { pix.setSize(w, h); } pix.setX(x); pix.setY(y); } } public class add extends MathZOb { public int getInt(int def) { Vector inputs = readInputZObs(); if (inputs.size() < 1) return def; int S = 0; for (int i=0; i 0xff0000) r = 0xff0000; g = (pp & 0xff00) + (ipp & 0xff00); if (g > 0xff00) g = 0xff00; b = (pp & 0xff) + (ipp & 0xff); if (b > 0xff) b = 0xff; p[pi++] = 0xff000000 | r | g | b; } pi += pix.getWidth() - inpix.getWidth(); } } pix.setFrame(pix.getFrame()+1); return pix; } } public class and extends MathZOb { public int getInt(int def) { Vector inputs = readInputZObs(); if (inputs.size() < 1) return def; int S = 0xffffffff; for (int i=0; i> 12) & 0xff0) * ((ipp >> 12) & 0xff0)) & 0xff0000; g = (((pp >> 8) & 0xff) * ((ipp >> 8) & 0xff)) & 0xff00; b = ((pp & 0xff) * (ipp & 0xff)) >> 8; p[pi++] = 0xff000000 | r | g | b; } pi += pix.getWidth() - inpix.getWidth(); } } pix.setFrame(pix.getFrame()+1); return pix; } } public class or extends MathZOb { public int getInt(int def) { Vector inputs = readInputZObs(); if (inputs.size() < 1) return def; int S = 0; for (int i=0; i