Add-ons
To add your own algorithms, unpack the archive and replace the java class file addons.class. This is most easily done by amending the example addonsextra.java included in the source zip.
Firstly amend the string array:
String[] names={"algorithm1","algorithm2",...} to give the names of all the new algorithms in the menu. This will ensure the new names appear in a new menu on the main menubar. An add-on algorithm will be called with two parameters: an input BufferedImage and the number of the algorithm in the menu. A switch/case routine can be used to ensure the right method is called. The output BufferedImage needs to be returned.
Buffered Image
A basic manipulation of a Java BufferedImage is logical and will not require deep knowledge of Java. An example is included in the file addonsextra.java
The most important features of the Java BufferedImage class are:
- Create a new BufferedImage:
BufferedImage b=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
- Retrieve the width/height:
int w=b.getWidth();
- Retrieve a pixel value:
int pix=b.getRGB(i,j);
- The first 8 bits of the integer give the blue component, the next 8 bits the green, the next 8 bits the red and the top 8 bits the alpha.
- Extract red,green,blue,alpha values:
int alpha=pix>>>24;int red=(pix>>>16)&0xFF;int green=(pix>>>8)&0xFF;int blue=pix&0xFF;
- Set red, green, blue, alpha [all in range 0-255]:
pix=blue+(green<<8)+(red<<16)+(alpha<<24);
- Set pixel value:
b.setRGB(i,j,pix);
The new java file needs to be recompiled using the Java SDK from Sun.
Starting Simian again, the new menu will appear.