
import cds.aladin.*;

public class PixelTransformPlug extends AladinPlugin {
   
   public String menu()        { return "Image 90° rotation"; }
   public String description() {
      return "PLUGIN TUTORIAL:\n" +
             "This plugin is an example for manipulating the pixels.\n" +
             "This plugin applies a 90° rotation to the current image.\n\n" +
             "This plugin can be launched by the \"rot\" script command.";
   }   
   public String author()      { return "Pierre Fernique"; }
   public String version()     { return "2.0 - January 2007"; }
   public String category()    { return "Plugin tutorial/Image"; }
   public String url() { return "http://aladin.u-strasbg.fr/java/Plugins/PixelTransformPlug.java"; }
   public String scriptCommand() { return "rot"; }
   public String scriptHelp() {
      return "#n:rot - image rotation" +
             "#s:rot [labelPlane]" +
             "#d:Simple 90° image rotation. Apply on the current image or on" +
             "the specified image." +
             "#t:The astrometry solution is not adjusted" +
             "#e:rot Image1" +
             "#g:@show";
   }
   
   /*
    * Execute an 90° image rotation
    * 1) get the pixels and image size
    * 2) create a new pixel array width=>height and height=>width
    * 3) rotate the image from the previous array to the new one
    * 4) send the new pixel array to Aladin
    */
   public void exec() throws AladinException {
      AladinData sd = aladin.getAladinImage();
      double [][] pix = sd.getPixels();
      int w = sd.getWidth();
      int h = sd.getHeight();
      double [][] rotpix = new double[h][w];
      for( int y=0; y<h; y++) {
         for( int x=0; x<w; x++ ) rotpix[y][w-x-1] = pix[x][y];
      }
      sd.setPixels(rotpix);
   } 
}