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

public final class ExpandRange 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 = out.numElements - 1; i >= 0; i--) {
	red[i] = clamp(ared[i] * 2f - 1f);
	grn[i] = clamp(agrn[i] * 2f - 1f);
	blu[i] = clamp(ablu[i] * 2f - 1f);
    }
  }

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

  public String description()
  {
    return "Expands the dynamic range from (0, 1) to (-1, 1).";
  }  

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