I'm doing a project where I develop functions to apply effects to photos (like Contrast, Vignette, Sepia ...).
As I apply effects to photos, the various states of photos are stored in an image vector.
In this same project, I need two functions, Undo and Redo. The Undo will serve to obtain the photo with the effect previously applied and Redo will serve to obtain again the last effect applied.
Can anyone help me with the development of these functions (Undo and Redo)?
Thank you.
Here's what I have in the class:
class Historico {
private ColorImage [] VCI;
private int atual;
boolean undo = false;
private int undos;
private int redos;
public Historico(ColorImage [] VCI) {
this.VCI = VCI;
atual = 0;
undos = 0;
redos = 0;
}
static ColorImage copy (ColorImage CI) {
ColorImage NCI = new ColorImage(CI.getWidth(),CI.getHeight());
for(int x = 0; x < CI.getWidth(); x++){
for(int y = 0; y < CI.getHeight(); y++){
Color c = CI.getColor(x,y);
NCI.setColor(x,y,c);
}
}
return NCI;
}
void saveImage(ColorImage CI) {
VCI [atual] = copy(CI);
atual++;
undo = false;
undos = 0;
redos=0;
}
public void undo() {
ColorImage CI = copy(VCI[atual-2-undos]);
VCI[atual] = CI;
atual = atual + 1;
undo = true;
undos = undos + 2;
}
public void redo() {
if(undo = true) {
ColorImage CI = copy(VCI[atual-2-redos]);
VCI[atual] = CI;
atual = atual + 1;
undos--;
if(undos<0){
undos = 0;
undo = false;
}
redos = redos + 2;
}
}
}