package ch.epfl.isochrone.tiledmap;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

public class TransparentTileProvider extends FilteringTileProvider {

    private int opacite;
    
    public TransparentTileProvider (int opacite, TileProvider fournisseur)
    {
        this.opacite=opacite;
        this.fournisseur=fournisseur;
    }
    
    @Override
    public Tile tileAt(int zoom, int x, int y) {
        
        BufferedImage imageBase =fournisseur.tileAt(zoom, x, y).image();
        
        BufferedImage image = new BufferedImage(imageBase.getWidth(), imageBase.getHeight(), BufferedImage.TYPE_INT_ARGB);
        
        Graphics2D g = image.createGraphics();
        
        
        for (int i=0; i<imageBase.getWidth(); i++)
        {
            for (int j=0; j<imageBase.getWidth(); j++)
            {
                int rgb = imageBase.getRGB(i, j);
               
            }
        }
        
        
        return null;  // pas fini
    }

    @Override
    public int transformARGB(int argb) {
        return argb(opacite, r(argb), g(argb), b(argb));
    }
    
    public double a (int argb)  // mettre en divF, modF
    {
        return (((argb)/(int) Math.pow(2, 24))%(int) Math.pow(2, 8))/255.0;
    }
    
    public double r (int argb)
    {
        return (((argb)/(int) Math.pow(2, 16))%(int) Math.pow(2, 8))/255.0;
    }
    
    public double g (int argb)
    {
        return (((argb)/(int) Math.pow(2, 8))%(int) Math.pow(2, 8))/255.0;
    }
    
    
    public double b (int argb)
    {
        return (argb%(int) Math.pow(2, 8))/255.0;
    }
    
    public int argb (double a, double r, double g, double b)
    {
        return ((int) Math.pow(2, 24))*((int)(255*a)) + ((int) Math.pow(2, 16))*((int)(255*r)) + + ((int) Math.pow(2, 8))*((int)(255*g)) + + ((int)(255*b));
    }

}
