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

public final class HSymmetry extends OneArgumentOperator implements ELOperator 
{
  public void apply(ELMatrix argument[], ELMatrix out, ELEnvironment environment)
  {
    checkArguments(argument);
        
    ELMatrix arg = argument[0];
    int width = out.getWidth();
    int height = out.getHeight();
    int mid = width / 2;
    
    for(int c = 0; c < 3; c++) {
      float inChannel[] = arg.channel[c];
      float outChannel[] = out.channel[c];
      for(int y = height - 1; y >= 0; y--) {
        for(int x = width - 1; x > mid; x--) {
          outChannel[x + y * width] = inChannel[(width - x) + y * width];
        }
        for(int x = mid; x >= 0; x--) {
          int offset = x + y * width;
          outChannel[offset] = inChannel[offset];
        }
      }
    }
  }

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

  public String description()
  {
    return "Mirrors the left half of the image on the right";
  }  

  protected String iconString()
  {
    return "<->";
  }
}
