File: BytePixelPlug.java

package info (click to toggle)
aladin 12.060%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,528 kB
  • sloc: java: 203,449; makefile: 149; xml: 49; sh: 1
file content (46 lines) | stat: -rw-r--r-- 1,862 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


import cds.aladin.*;

public class BytePixelPlug extends AladinPlugin {
   
   public String menu()          { return "Image dump & reverse"; }
   public String description()   {
      return "PLUGIN TUTORIAL:\n" +
             "This plugin is an example for manipulating the byte pixel buffer.\n" +
             "It will create a copy of current plane image, and will reverse" +
             "all pixels.\n\n" +
             "This plugin can be launched by script via the \"inverse\" command.";
   }   
   public String author()        { return "Pierre Fernique [CDS]"; }
   public String version()       { return "1.1 - January 2007"; }
   public String url() { return "http://aladin.u-strasbg.fr/java/Plugins/BytePixelPlug.java"; }
   public String category()      { return "Plugin tutorial/Image"; }
   public String scriptCommand() { return "inverse"; }   
   
   /**
    * 1) Clone image plane via VOAPP 
    * 2) Access to the Aladin byte pixel buffer of this plane
    * 3) Modify these pixels (inverse)
    * 4) Notify Aladin that the byte pixels has been modified => lost the full pixel access
    */
   public void exec() {
      
      try {
         // Dump the plane of the current image
         String labelImg = aladin.getAladinImage().getLabel();
         aladin.execCommand("copy "+labelImg+" copyOf"+labelImg);
         
         // Direct access to the byte pixel buffer of the copied image
         AladinData sd = aladin.getAladinData("copyOf"+labelImg);
         byte pix [] = sd.seeBytePixels();
         
         // Inverse each of them
         for( int i=0; i<pix.length; i++ ) pix[i] = (byte) ~(0xFF & pix[i]);
         
         // Notify Aladin
         sd.bytePixelsModified();
        
      } catch( AladinException e ) {  aladin.warning("Plugin error: "+e.getMessage()); }
   }
}