public class Negative {
    /* Reads an image filename from the command line,
     *  computes the negative of the image and displays it.
     *  Also measures and prints the time elapsed until completion.
     */
    public static void main(String[] args) {
        int MAX_RGB_VALUE = 255;
        String filename = args[0];
        Stopwatch watch = new Stopwatch(); // Start measuring time
        StdPicture.read(filename);

        int width = StdPicture.width();
        int height = StdPicture.height();

        for (int col = 0; col < width; col++) {
            for (int row = 0; row < height; row++) {
                // Read red, green and blue levels
                int r = StdPicture.getRed(col, row);
                int g = StdPicture.getGreen(col, row);
                int b = StdPicture.getBlue(col, row);

                // Set the negative of the levels
                StdPicture.setRGB(col, row, MAX_RGB_VALUE - r,
                                  MAX_RGB_VALUE - g, MAX_RGB_VALUE - b);
            }
        }
        // Stop measuring and print elapsed time
        System.out.println("Elapsed time: " + watch.elapsedTime() + "sec.");
        // Show negative of picture
        StdPicture.show();
    }
}
