Some sludge about images

This page is currently putting up with massive transmutation and that is precisely why only the lonely code will have to make do. We will be back here soon, but till then, Thanx for visiting this page. If you are a member of the Java-crazed community, you can still try out the code furnished here. Maybe with some divine intervention you might be able to get the drift... a1.html
<applet code="zzz" width=350 height=300></applet>

zzz.java programs

Program 1

import java.applet.*;
import java.awt.*;
public class zzz extends Applet
{   public boolean mouseUp(Event e , int x, int y)	
	{	showStatus("Code:"+getCodeBase().toString()+"..."+"Document:"+
		getDocumentBase().toString());
                return true;
        }       
}
Program 2
import java.applet.*;
import java.awt.*;
public class zzz extends Applet
{       Image o;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
        }
        public void paint(Graphics g)
        {       g.drawImage(o,150,150,this);
        }
}
Program 3
import java.applet.*;
import java.awt.*;
public class zzz extends Applet
{       Image o,c;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                c=createImage(o.getSource());
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
Program 4
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
public class zzz extends Applet
{       Image o,c;
        ImageProducer p;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
		c=createImage(p);
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
The import commands for the following programs
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
Program 5
public class zzz extends Applet
{       Image o,c;
        ImageProducer p;
        ImageFilter f;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
                f=new ImageFilter();
                p=new FilteredImageSource(p,f);
                c=createImage(p); 
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
Program 6
public class zzz extends Applet 
{       Image o,c;
        ImageProducer p;
        ImageFilter f;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
                f=new RGBImageFilter();
                p=new FilteredImageSource(p,f);
                c=createImage(p);
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
/*
Error:RGBImageFilter is an abstract class. It cannot be instantiated
*/
Program 7
public class zzz extends Applet
{       Image o,c;
        ImageProducer p;
        ImageFilter f;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
                f=new fff();
                p=new FilteredImageSource(p,f);
                c=createImage(p);
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
class fff extends RGBImageFilter
{       public int filterRGB(int x, int y, int r)
        {       return r;
        }
}
Program 8
public class zzz extends Applet
{       Image o,c;
        ImageProducer p;
        ImageFilter f;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
                f=new fff();
                p=new FilteredImageSource(p,f);
                c=createImage(p);
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
        public synchronized boolean imageUpdate(Image m, int n, int x, 
	int y, int w, int h)
        {       repaint(1000);
                return true;
        }
}
class fff extends RGBImageFilter
{       public int filterRGB(int x, int y, int r)
        {       return r&0xff00ffff;
        }
} 
Program 9
public class zzz extends Applet
{       Image o,c;
        ImageProducer p;
        ImageFilter f;
        public void init()
        {       o=getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                p=o.getSource();
                f=new fff();
                p=new FilteredImageSource(p,f);
                c=createImage(p);
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);
                g.drawImage(o,150,150,this);
        }
}
class fff extends RGBImageFilter
{       public int filterRGB(int x, int y, int r)
        {       return r&0xff00ffff;
        }
}
If you have tried out the above, replace the fff class in the following ways...

        public int filterRGB(int x, int y, int r)
        {       return r & 0x00ffffff;
        }
        public int filterRGB(int x, int y, int r)
        {       if ( (r>>24)  == 0)
                        return 0xff00ff00 ;
                else
                        return r;
        }
        public int filterRGB(int x,int y, int r)
        {       return ((r & 0xff00ff00)
                | ((r & 0x00ff0000) >> 16)
                | ((r & 0x000000ff) << 16));
        
        }
        public int filterRGB(int x, int y, int r)
        {       if ( (r>>24)  == 0)
                        return 0xf000ff00 ;
                else
                        return r;
        }

Program 10
public class zzz extends Applet
{       Image  o;
        Image  c;
        int i = 0;
        public void init ()
        {       o = getImage(getDocumentBase(),"joe.surf.yellow.small.gif");
                pp();
        }
        public boolean mouseDown(Event e,int x,int y)
        {       i++;
                pp();
                repaint();
                return true;
        }
        public void paint(Graphics g)
        {       g.drawImage(c,0,0,this);    
        }
        public synchronized boolean imageUpdate(Image m, int f,int x, 
	int y, int w, int h)
        {       repaint(100);
                return true;
        }
        public synchronized void  pp()
        {       ImageFilter f;
                if ( i%2 == 0)
                        f=new xxx();
                else
                        f=new yyy();
                ImageProducer p = o.getSource();
                p = new FilteredImageSource(p, f);
                c = createImage(p);
        }
}
class yyy extends RGBImageFilter
{       public int filterRGB(int x, int y, int r)
        {       return r; 
        }
}
class xxx extends RGBImageFilter
{       public int filterRGB(int x, int y, int r)
        {       return  ((r & 0xff00ff00)|((r & 0xff0000) >> 16)
                        |((r & 0xff) << 16));
        }
}


Please rush to the next topic "The plot thickens" or just reach your messages i.e., your comments, feedback, suggestions et al to us.

Back to our Java page


Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in
1