import java.awt.*;
import java.awt.image.*;
import Raster;

class ScalableRaster extends Raster{
    protected int scale;

    ///////////////////////// Constructors //////////////////////

    /**
     *  This constructor which takes no arguments
     *  allows for future extension.
     */
    public ScalableRaster()
    {
    }

    /**
     *  This constructor creates an uninitialized
     *  Raster Object of a given size (w x h).
     */
    public ScalableRaster(int w, int h, int s)
    {
        super(w, h);
        scale = s;
    }

    /**
     *  This constructor creates an Raster initialized
     *  with the contents of an image.
     */
    public ScalableRaster(Image img, int scale)
    {
    	 //****
    	 super(img);
    	 /*
        try {
            PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true);
            if (grabber.grabPixels()) {
                width = grabber.getWidth();
                height = grabber.getHeight();
                pixel = (int []) grabber.getPixels();
            }
        } catch (InterruptedException e) {
        }
        */
    }

    ////////////////////////// Methods //////////////////////////

    /**
     *  Returns the number of pixels in the Raster
     */
    //public int size( ) {
    //    return(getHeight() * getWidth());
    //}
    
    /**
     *  Access instance variables
     */
    public int getWidth() {
        return super.getWidth() / scale;
    }
    
    public int getHeight() {
        return super.getHeight() / scale; 
    }
    
    /**
     *  Gets a pixel from a Raster
     */
    public int getPixel(int x, int y) {
        return super.getPixel(scale * x, scale * y);
    }

    public float getDepth(int x, int y) {
        return super.getDepth(scale * x, scale * y);
    }

    /**
     *  Gets a color from a Raster
     */
    public Color getColor(int x, int y) {
        return super.getColor(scale * x, scale * y);
    }

    /**
     *  Sets a pixel to a given value
     */
    public boolean setPixel(int pix, int x, int y) {
		int xp = x * scale, yp = y * scale;
		for (int i = 0; i < scale; i++)
		{
			for (int j = 0; j < scale; j++)
			{
				if (!super.setPixel(pix, xp+i, yp+j)) return false;
			}
		}
		return true;
    }

    /**
     *  Sets a pixel to a given value
     */
    public boolean setPixel(int pix, int x, int y, float z) {
		int xp = x * scale, yp = y * scale;
		for (int i = 0; i < scale; i++)
		{
			for (int j = 0; j < scale; j++)
			{
				if (!super.setPixel(pix, xp+i, yp+j, z)) return false;
			}
		}
		return true;
    }

    /**
     *  Sets a pixel to a given color
     */
    public boolean setColor(Color c, int x, int y) {
		int xp = x * scale, yp = y * scale;
		for (int i = 0; i < scale; i++)
		{
			for (int j = 0; j < scale; i++)
			{
				if (!super.setColor(c, xp+i, yp+j)) return false;
			}
		}
		return true;
    }

    /**
     *  Sets a pixel to a given color
     */
    public boolean setColor(Color c, int x, int y, float z) {
		int xp = x * scale, yp = y * scale;
		for (int i = 0; i < scale; i++)
		{
			for (int j = 0; j < scale; i++)
			{
				if (!super.setColor(c, xp+i, yp+j, z)) return false;
			}
		}
		return true;
    }

}