001package plugins.tutorial.training;
002
003import icy.gui.dialog.MessageDialog;
004import icy.image.IcyBufferedImage;
005import icy.plugin.abstract_.PluginActionable;
006
007public class ModifyImagePlugin1 extends PluginActionable
008{
009    @Override
010    public void run()
011    {
012        IcyBufferedImage image = getActiveImage();
013
014        // check if an image is opened
015        if (image == null)
016        {
017            MessageDialog.showDialog("This plugin needs an opened image.");
018            return;
019        }
020
021        // retrieve width and height of the image
022        int w = image.getSizeX();
023        int h = image.getSizeY();
024
025        for (int x = 0; x < w; x++)
026        {
027            for (int y = 0; y < h; y++)
028            {
029                // set pixel intensity to half of its original value
030                image.setData(x, y, 0, image.getData(x, y, 0) / 2);
031            }
032        }
033    }
034}