I need to add tint to a picture and then revert the picture back to its original color. I am able to add tint but don't know how to revert the picture back to it's original colors.

I want to create a method where it resets the picture back to its original color.

Attempt

public void changeBlues(double param){
    Pixel[] pixelArray =  this.getPixels();
    Pixel pixel = null;
    int value = 0;
    int index = 0;

    if(param <= 0.0){
      System.out.println("Error! Parameter less than or equal to 0.0");
      return;
    }
    else if(param > 5.0){
      System.out.println("Error! Paramater is greater than five.");
      return;
    }



    //loop through all the pixels

    //get the current pixel
    while(index < (int)(pixelArray.length)){  
      if(param < 1.0){
        pixel = pixelArray[index];

        //get the value
        value = pixel.getBlue();

        // decrease the value by param
        value = (int)((value - (value * param)));

        // set he blue value of the current pixel to the new value
        pixel.setBlue(value);

        // increment the index
        index = index + 1;
      }

      pixel = pixelArray[index];

      //get the value
      value = pixel.getBlue();

      // decrease the value by param
      value = (int)((value + (value * param)));

      // set he blue value of the current pixel to the new value
      pixel.setBlue(value);

      // increment the index
      index = index + 1;


  }
}

1 Answers

0
TreffnonX On

As suggested by MadProgrammer, you need to either maintain a copy of the original, or create a (bidirectional) delta for each change. The advantage of the later is, that you can revert to all stages of your editings, sort of like a history (CTRL + Z/Y in many programs under windows).

To do this, you need to create an object that stores the pixel change information and can be applied or reverted. Since you loop over all pixels, and practically almost all pixels will be affected, you could just store the entire image in the history. This depends on whether you will have operations in your program that change the image on a more limited basis, instead of making whole-picture-modifications.

@Edit: Since you want to rotate between multiple different tinted pictures, aparrently, just genreate the three buffered pictures and rorate them.