/*
 * jHebras.java
 *
 * Created on 22 de octubre de 2006, 15:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package dectecmovimiento;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Image;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;


/**
 *
 * @author Robotica
 */
public class jHebras extends Thread{
    
    /** Creates a new instance of jHebras */
    public BufferedImage temMatriz1, temMatriz2;
    private jVentana ventana;
    private int umbralValor = 0;
    private boolean ESTADO = true; 
    private int umBral=0;
    
    public jHebras(BufferedImage m, int umBralParam, jVentana vent) {
        ventana = vent;
        temMatriz1 = m;
        temMatriz2 = new BufferedImage(m.getWidth(), m.getHeight(), m.getType());
        umbralValor = umBralParam;
    }
    
    public void run(){
        Color a1 = null; 
        Color b1 = null;
        int Red = 0;
        
        while(true){
            
            temMatriz1 = ventana.temp;
            for(int i=0; i < temMatriz1.getWidth(); i++)
                for(int j = 0; j < temMatriz1.getHeight(); j++){
                    //if((i == 0) && (j == 0))System.out.println("hebra " + temMatriz1.getRGB(0,0));
                    a1 = new Color(temMatriz1.getRGB(i,j));
                    if(a1.getRed() < umbralValor) b1 = new Color(0,0,0);
                    else b1 = new Color(255,255,255);
                    temMatriz2.setRGB(i, j, b1.getRGB());
            }
            
            //ventana.setMatriz(temMatriz2);
            ventana.paint(ventana.getGraphics());
            ventana.jPanel1.repaint();
            dormit();
        }
            
    }
        
    
    public synchronized void dormit(){
        try {      
            wait();  
        } catch (InterruptedException ex) {
            ex.printStackTrace();}
    }
    
    public synchronized void despertar(){
        notify();
    }
    
    public BufferedImage getMatriz(){
        return(temMatriz2);  
    }
    
    public void setMatriz(BufferedImage matriz){
        temMatriz1 = matriz;
    }
    public void setUmbral(int valor){
        umbralValor = valor;
    }
    public void killHebra(boolean control){
        
        if(control) ESTADO = false;
    }

}
