/// Evolver Copyright 2000, Morgan McGuire
/// matrix@alum.mit.edu   http://graphics3d.com/matrix
import java.awt.Color;

public final class Grayscale extends OneArgumentOperator implements ELOperator 
{
  public void apply(ELMatrix argument[], ELMatrix out, ELEnvironment environment)
  {
    checkArguments(argument);
        
    // For extra performance, pull the arrays into locals so we avoid
    // excess dereferences.
    float red[] = out.red;
    float grn[] = out.grn;
    float blu[] = out.blu;

    ELMatrix arg = argument[0];
    float ared[] = arg.red;
    float agrn[] = arg.grn;
    float ablu[] = arg.blu;

    for(int i = red.length - 1; i >= 0; i--) {
      float v = ared[i] * 0.25f + agrn[i] * 0.6f + ablu[i] * 0.15f;
      red[i] = v;
      grn[i] = v;
      blu[i] = v;
    }
  }

  public String name()
  {
    return "Grayscale";
  }

  public String description()
  {
    return "Takes image to (perceptual) grayscale";
  }  

  protected String iconString()
  {
    return "Gry";
  }
}
