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

public final class DSymmetry 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 midx = width / 2;
    int midy = height / 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 >= 0; x--) {
          if (x > y) {
            outChannel[x + y * width] = inChannel[(y * width / height) + (x * height / width) * width];
          } else {
            int offset = x + y * width;
            outChannel[offset] = inChannel[offset];
          }
        }
      }
    }
  }

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

  public String description()
  {
    return "Mirrors across the diagonal";
  }  

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