home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-10-02 | 3.0 KB | 112 lines |
- /*
- * @(#)GIFBuilder.java 1999/09/28
- *
- * Written by David Griffiths, 1999.
- *
- * The parts of this software that were specifically written by David Griffiths
- * are released into the Public Domain. However, you should note that some parts are
- * based on other libraries and you should read and be aware of the additional
- * conditions that are specified in some of the attached files
- * (notably GIFImage.java and LZWCompressor.java). The GIF format is the copyright
- * of CompuServe Incorporated.
- *
- * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
- * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- /**
- * GIFBuilder is an Animator class for assembling and optimizing GIF animations.
- * @version 1.0 1999/09/28
- * @author David Griffiths
- */
-
- import java.lang.String;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.io.*;
- import java.net.*;
- import java.awt.image.*;
-
-
- public class GIFBuilder extends Animator {
- private GIFImage myGIF;
-
- GIFBuilder(int Width, int Height) {
- myGIF = new GIFImage(Width, Height);
- }
-
- // Attributes
-
- public Animation getAnimation() {
- return myGIF;
- }
-
- public void setFPS(int newFps) {
- myGIF.setFPS(newFps);
- }
-
- public int getFPS() {
- return myGIF.getFPS();
- }
-
- private int currentGG[] = {};
-
- public int addImage(Image image, Component c) {
- int frameCount = -1;
- MediaTracker mediaTracker = new MediaTracker(c);
- mediaTracker.addImage(image, 1);
- try {
- GIFGraphics newGraphics;
-
- mediaTracker.waitForID(1);
-
- newGraphics = new GIFGraphics(image, c);
-
- if (currentGG.length == 0) {
- currentGG = new int[newGraphics.pixels.length];
- for (int i = 0; i < currentGG.length; i++)
- currentGG[i] = newGraphics.pixels[i];
- }
- else {
- int top = newGraphics.height;
- int left = newGraphics.width;
- int height = 0;
- int width = 0;
- int i = 0;
- for (int y = 0; y < newGraphics.height; y++)
- for (int x = 0; x < newGraphics.width; x++)
- if (newGraphics.pixels[i] == currentGG[i])
- newGraphics.pixels[i++] = 0;
- else {
- if (x < left)
- left = x;
- if (y < top)
- top = y;
- if ((left + width) < x)
- width = x - left;
- if ((top + height) < y)
- height = y - top;
- currentGG[i] = newGraphics.pixels[i];
- i++;
- }
- newGraphics.cropTo(new Rectangle(left, top, width + 1, height + 1));
- }
-
- frameCount = myGIF.addImage(newGraphics);
- }
- catch (Exception e) {
- System.out.println("Unable to create GIFImage: " + e);
- e.printStackTrace();
- }
- return frameCount;
- }
- }
-