No, I don't use p1 as a reference.
I load the image in the img class then declare the object img p1;
I wish to use the photo loaded in img to edit it, the problem is that all the edits that I'm doing to the image won't be saved in the result photo, only the last one I choose.
For example, if I will select the following: Grayscale effect, Flip 1; after exiting the console the result will only be flipped, the first selection won't be saved.
I'm trying to figure out how to save all the edits on the same photo.
Here's the whole code:
#include<iostream>
#include<SFML/Graphics.hpp>
#include<list>
#include<windows.h>
int a; //declar global a pentru a putea lucra cu selectarea imaginilor, alta metoda nu mi-a venit in cap deoarece nu poti pune in if un obiect imagine valabil pentru tot programul
int s=0; //variabila globala ce decide lucrul cu poza de inceput sau cea temporara
char o[3];
class img
{
public:
sf::Image picture;
std::list<int> pixels={};
int LoadImg()
{
if(a==1)
{
if(!picture.loadFromFile("test1.jpg"))
return 0;
}
if(a==2)
{
if(!picture.loadFromFile("test2.jpg"))
return 0;
}
if(a==3)
{
if(!picture.loadFromFile("test3.jpg"))
return 0;
}
if(a==4)
{
if(!picture.loadFromFile("test4.jpg"))
return 0;
}
if(a==5)
{
if(!picture.loadFromFile("test5.jpg"))
return 0;
}
}
};
/*class temp
{
public:
sf::Image picture;
std::list<int> pixels={};
int LoadImg()
{
if(!picture.loadFromFile("temp1.jpg"))
return 0;
}
};*/
class temp
{
public:
sf::Image picture;
std::list<int> pixels={};
int LoadImg()
{
if(!picture.loadFromFile("result.jpg"))
return 0;
}
};
int main()
{
std::cout<<"Buna ziua, selectati imaginea ce doriti sa fie editata:\n";
A: std::cout<<"Poza 1 (Astronaut)\nPoza 2 (Stonehenge) \nPoza 3 (Frunza) \nPoza 4 (PH) \nPoza 5 (PH) \n";
std::cin>>a;
if(!(a>0 && a<4))
{
std::cout<<"Invalid Input, introduceti o valoare corecta - \n\n";
system("PAUSE");
system("CLS");
goto A;
}
img p1;
if(!p1.LoadImg())
{
std::cout<<"This window will close in 3 sec.";
Sleep(3000);
return -1;
}
img p3;
temp p2;
if(!p2.LoadImg())
{
std::cout<<"This window will close in 3 sec.";
Sleep(3000);
return -1;
}
system("CLS");
std::cout<<"Alegeti ce doriti sa editati la poza selectata:\n";
int h;
B: std::cout<<" 0 : Rotire; \n 1 : Efecte; \n 2 : Cropare; \n 3 : Prelucrare pixeli;\n-1 : RETURN\n";
std::cin>>h;
system("CLS");
if(!(h>-2 && h<4))
{
std::cout<<"Invalid Input, introduceti o valoare corecta - \n";
goto B;
}
int v=0;
if (h==0)
{
std::cout<<"----------------------------------------------------------------------------------\n";
std::cout<<" 0 : Flip 1;\n 1 : Flip 2;\n-1 : RETURN\n";
std::cout<<"----------------------------------------------------------------------------------\n";
std::cin>>v;
system("CLS");
}
if (h==1)
{
std::cout<<"----------------------------------------------------------------------------------\n";
std::cout<<" 2 : Grayscale;\n 3 : Efect Danila 1\n 4 : Efect Danila 2\n-1 : RETURN\n";
std::cout<<"----------------------------------------------------------------------------------\n";
std::cin>>v;
system("CLS");
}
if (h==3)
{
std::cout<<"----------------------------------------------------------------------------------\n";
std::cout<<" 5 : Adaugare rama pozei\n 6 : Schimbarea culorii pixelilor prezenti pe diagonala principala\n-1 : RETURN\n";
std::cout<<"----------------------------------------------------------------------------------\n";
std::cin>>v;
system("CLS");
}
/*Prelucrare Pixeli*/
sf::Image picture1;
sf::Image picture2;
sf::Image picture3;
if (h==-1)
{
goto A;
}
if (v==-1) /*posibilitatea utilizatorului de a da back*/
{
goto B;
}
sf::Color culoare(0,0,0);
picture1.create(p1.picture.getSize().x,p1.picture.getSize().y,sf::Color::Black);
picture1.copy(p1.picture,0,0);
picture2.create(p2.picture.getSize().x,p2.picture.getSize().y,sf::Color::Black);
picture2.copy(p2.picture,0,0);
if(v==0)
{
if(s==0)
{
//p1.LoadImg();
picture1.flipHorizontally();
//if(!picture1.saveToFile("temp1.jpg"))
/*if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}*/
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
s==1;
goto B;
}}
else
{
//p2.LoadImg();
picture1.copy(p1.picture,0,0);
picture1.flipHorizontally();
/* if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}*/
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}}
}
if(v==1)
{
if(s==0)
{
//p1.LoadImg();
picture1.flipVertically();
/*if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}*/
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
s++;
}
}
else
{
//p2.LoadImg();
picture1.copy(p1.picture,0,0);
picture1.flipVertically();
/*if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}*/
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
s++;
}
}
}
if(v==2)
{
p1.LoadImg();
for(int i=0;i<picture1.getSize().x;i++)
for(int j=0;j<picture1.getSize().y;j++)
{
culoare.r=picture1.getPixel(i,j).r;
culoare.g=picture1.getPixel(i,j).r;
culoare.b=picture1.getPixel(i,j).r;
picture1.setPixel(i,j,culoare);
}
/* if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}*/
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
s==1;
goto B;
}
}
if(v==3)
{
for(int i=0;i<picture1.getSize().x;i++)
for(int j=0;j<picture1.getSize().y;j++)
{
culoare.r=255-picture1.getPixel(i,j).r;
culoare.g=255-picture1.getPixel(i,j).r;
culoare.b=255-picture1.getPixel(i,j).r;
picture1.setPixel(i,j,culoare);
}
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
}
if(v==4)
{
for(int i=0;i<picture1.getSize().x;i++)
for(int j=0;j<picture1.getSize().y;j++)
{
culoare.r=picture1.getPixel(i,j).r;
culoare.g=picture1.getPixel(i,j).r+30;
culoare.b=picture1.getPixel(i,j).r;
picture1.setPixel(i,j,culoare);
}
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
}
if (v==5)
{
int q;
std::cout<<"Culoarea ramei adaugate sa fie:\n 0 : Alb;\n 1 : Negru;\n";
std::cin>>q;
if (q==0)
{
picture1.create(p1.picture.getSize().x+50,p1.picture.getSize().y+50,sf::Color::White);
picture1.copy(p1.picture,25,25);
for(int j=0;j<=p1.picture.getSize().y+50;j+=1)
for(int i=0;i<=25;i+=1)
picture1.setPixel(i,j,sf::Color::White); /*Adaugare rama pe partea stanga*/
for(int j=0;j<=p1.picture.getSize().y+50;j+=1)
for(int i=p1.picture.getSize().x+25;i<=p1.picture.getSize().x+49;i+=1)
picture1.setPixel(i,j,sf::Color::White); /*Adaugare rama pe partea dreapta*/
for(int i=0;i<=p1.picture.getSize().x+50;i+=1)
for(int j=0;j<=25;j+=1)
picture1.setPixel(i,j,sf::Color::White); /*Adaugare rama sus */
for(int i=0;i<=p1.picture.getSize().x+50;i+=1)
for(int j=p1.picture.getSize().y+25;j<=p1.picture.getSize().y+50;j+=1)
picture1.setPixel(i,j,sf::Color::White); /*Adaugare rama jos */
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
}
if (q==1)
{
picture1.create(p1.picture.getSize().x+50,p1.picture.getSize().y+50,sf::Color::White);
picture1.copy(p1.picture,25,25);
for(int j=0;j<=p1.picture.getSize().y+50;j+=1)
for(int i=0;i<=25;i+=1)
picture1.setPixel(i,j,sf::Color::Black); /*Adaugare rama pe partea stanga*/
for(int j=0;j<=p1.picture.getSize().y+50;j+=1)
for(int i=p1.picture.getSize().x+25;i<=p1.picture.getSize().x+49;i+=1)
picture1.setPixel(i,j,sf::Color::Black); /*Adaugare rama pe partea dreapta*/
for(int i=0;i<=p1.picture.getSize().x+50;i+=1)
for(int j=0;j<=25;j+=1)
picture1.setPixel(i,j,sf::Color::Black); /*Adaugare rama sus */
for(int i=0;i<=p1.picture.getSize().x+50;i+=1)
for(int j=p1.picture.getSize().y+25;j<=p1.picture.getSize().y+50;j+=1)
picture1.setPixel(i,j,sf::Color::Black); /*Adaugare rama jos */
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
}
}
if (v==6)
{
int h;
picture1.create(p1.picture.getSize().x,p1.picture.getSize().y,sf::Color::White);
picture1.copy(p1.picture,0,0);
int a=p1.picture.getSize().x;
int b=p1.picture.getSize().y;
if(a!=b)
{
std::cout<<"Dimensiunea pozei nu este egala, doriti sa:\n 0 : Selectati alta poza\n 1 : Continuati cu modificarea diagonalei principale?\n";
std::cin>>h;
}
if (h==1)
{
for(int i=0;i<p1.picture.getSize().x;i+=1)
for(int j=0;j<p1.picture.getSize().y;j+=1)
if(i==j)
{
picture1.setPixel(i,j,sf::Color::Yellow);
}
}
else
{
goto A;
}
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
//system("CLS");
}
/* if(h==3)
{
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 1";
Sleep(3000);
return -1;
}
}*/
//sf::Image picture2;
//sf::Image picture3;
if(h==2)
{
int a,b,c,d;
std::cout<<"Crop size?";
C: std::cin>>a;
if(a<0 || a>p1.picture.getSize().x)
{
std::cout<<"invalid input; valoarea introdusa este mai mare decat permite poza sau mai mica ca 0, introduceti o alta valoare:\n";
goto C;
}
D: std::cin>>b;
if(b<0 || b>p1.picture.getSize().y)
{
std::cout<<"invalid input; valoarea introdusa este mai mare decat permite poza sau mai mica ca 0, introduceti o alta valoare:\n";
goto D;
}
std::cout<<"Crop starting point?";
E: std::cin>>c;
if(c<0 || c>p1.picture.getSize().x-a)
{
std::cout<<"invalid input, valoarea introdusa este mai mare decat permite poza sau mai mica ca 0, introduceti o alta valoare:\n ";
goto E;
}
F: std::cin>>d;
if(d<0 || d>p1.picture.getSize().y-b)
{
std::cout<<"invalid input, valoarea introdusa este mai mare decat permite poza sau mai mica ca 0, introduceti o alta valoare:\n";
goto F;
}
picture1.create(a,b,sf::Color::White);
picture1.copy(p1.picture,c,d);
if(!picture1.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
std::cout<<"Doriti sa continuati prelucrarea pozei?(Da/Nu)\n";
std::cin>>o;
if((o[0]=='D'||o[0]=='d') && (o[1]=='A'||o[1]=='a') && o[2]==0)
{
goto B;
}
}
/*if(h==2)
{
if(!picture1.saveToFile("result3.jpg"))
{
std::cout<<"This window will close in 3 sec. 3";
Sleep(3000);
return -1;
}
}
if(h==1 or h==0)
{*/
//system("PAUSE");
picture3.create(p1.picture.getSize().x,p1.picture.getSize().y,sf::Color::Black);
picture3.copy(p1.picture,0,0);
//picture3.copy(p2.picture,0,0);
if(!picture3.saveToFile("result.jpg"))
{
std::cout<<"This window will close in 3 sec. 4";
Sleep(3000);
return -1;
}
return EXIT_SUCCESS;
}
Compared to when I first posted I changed the code to only use p1 and only save the result using another object, p3 that will copy p1 and save it in result.jpg; No change..