Skip to content
Snippets Groups Projects
Commit a31fac7f authored by Jean-Marc's avatar Jean-Marc
Browse files

test reg

parent 4e7d2739
No related branches found
No related tags found
No related merge requests found
Pipeline #190279 failed
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -14,36 +14,47 @@ Image::Image()
}
Image::Image(const unsigned int &x, const unsigned int &y)
Image::Image(unsigned int dimensionX, unsigned int dimensionY)
{
assert (x>0 && y>0);
assert (dimensionX>0 && dimensionY>0);
dimx = x;
dimy = y;
dimx = dimensionX;
dimy = dimensionY;
tab = new Pixel [dimx*dimy];
cout<<"tab alloué v2 : "<<tab<<endl;
for(unsigned int i = 0; i<dimx*dimy; i++)
{
tab[i] = Pixel(0,0,0);
}
}
Image::~Image()
{
dimx = 0;
dimy = 0;
tab = nullptr;
delete [] tab;
if (tab != nullptr)
{
delete [] tab;
tab = nullptr;
}
cout<<"tab détruit : "<<tab<<endl;
}
Pixel & Image::getPix(const unsigned int &x, const unsigned int &y) const
Pixel & Image::getPix(unsigned int x, unsigned int y)
{
assert (x>=0 && y>=0);
assert (x<dimx && y<dimy);
return tab[y*dimx+x];
}
Pixel Image::getPix2(const unsigned int &x, const unsigned int &y) const
Pixel Image::getPix2(unsigned int x, unsigned int y) const
{
assert (x>=0 && y>=0);
assert (x<dimx && y<dimy);
Pixel ret = tab[y*dimx+x];
......@@ -55,9 +66,9 @@ void Image::setPix(const unsigned int &x, const unsigned int &y, const Pixel &co
tab[y*dimx+x] = couleur;
}
void Image::dessinerRectangle(unsigned Xmin, unsigned int Ymin, unsigned int Xmax, unsigned int Ymax, const Pixel & couleur)
void Image::dessinerRectangle(unsigned int Xmin, unsigned int Ymin, unsigned int Xmax, unsigned int Ymax, const Pixel & couleur)
{
unsigned i,j;
unsigned int i,j;
for(i=Xmin;i<Xmax;i++)
{
......@@ -74,6 +85,38 @@ void Image::effacer (const Pixel & couleur)
dessinerRectangle(0,0,dimx,dimy,couleur);
}
void Image::testRegression()
{
cout<<"test de regression : "<<endl;
Image im1;
assert (im1.dimx == 0);
assert (im1.dimy == 0);
Image im2(50,50);
assert (im2.dimx == 50);
assert (im2.dimy == 50);
Pixel p1 = im2.getPix(14,26);
assert(p1.r == 0);
assert(p1.g == 0);
assert(p1.b == 0);
Pixel p2(145,78,153);
im2.dessinerRectangle(10,10,30,30,p2);
p1 = im2.getPix(18,22);
cout<<int(p1.r)<<" "<<int(p1.g)<<" "<<int(p1.b)<<endl;
im2.effacer(Pixel(0,0,0));
p2 = im2.getPix(18,22);
cout<<int(p2.r)<<" "<<int(p2.g)<<" "<<int(p2.b)<<endl;
cout<<"fin test"<<endl;
}
void Image::sauver(const string &filename) const
{
ofstream fichier(filename.c_str());
......@@ -84,7 +127,7 @@ void Image::sauver(const string &filename) const
for (unsigned int y = 0; y < dimy; y++)
for (unsigned int x = 0; x < dimx; x++)
{
Pixel &pix = getPix(x, y);
Pixel pix = getPix2(x, y);
fichier << int(pix.r) << " " << int(pix.g) << " " << int(pix.b) << " ";
//cout<<x<<" , "<<y<<endl;
}
......@@ -117,7 +160,7 @@ void Image::ouvrir(const string &filename)
fichier.close();
cout << "Lecture de l'image " << filename << " ... OK\n";
}
/*
void Image::afficherConsole()const
{
cout << dimx << " " << dimy << endl;
......@@ -131,6 +174,7 @@ void Image::afficherConsole()const
cout << endl;
}
}
*/
Pixel * Image::getTab()const
{
......
......@@ -7,31 +7,26 @@ using namespace std;
class Image
{
private:
unsigned int dimx;///< Entiers non-signés représentant la dimensions X de l'image.
unsigned int dimy;///< Entiers non-signés représentant la dimensions Y de l'image.
Pixel * tab;
private:
unsigned int dimx;///< Entiers non-signés représentant la dimensions X de l'image.
unsigned int dimy;///< Entiers non-signés représentant la dimensions Y de l'image.
Pixel* tab;
public:
Image();
Image(const unsigned int &x, const unsigned int &y);
~Image();
void static testRegression()
{
}
Pixel & getPix(const unsigned int &x, const unsigned int &y) const;
Pixel getPix2(const unsigned int &x, const unsigned int &y)const;
void setPix(const unsigned int &x, const unsigned int &y, const Pixel &couleur);
void dessinerRectangle(unsigned int Xmin, unsigned int Ymin, unsigned int Xmax, unsigned int Ymax, const Pixel & couleur);
void effacer (const Pixel & couleur);
Pixel * getTab()const;
void sauver(const string &filename) const;
void ouvrir(const string &filename);
void afficherConsole()const;
Image();
Image(unsigned int dimensionX, unsigned int dimensionY);
~Image();
static void testRegression();
Pixel & getPix(unsigned int x, unsigned int y);
Pixel getPix2(unsigned int x, unsigned int y)const;
void setPix(const unsigned int &x, const unsigned int &y, const Pixel &couleur);
void dessinerRectangle(unsigned int Xmin, unsigned int Ymin, unsigned int Xmax, unsigned int Ymax, const Pixel & couleur);
void effacer (const Pixel & couleur);
Pixel * getTab()const;
void sauver(const string &filename) const;
void ouvrir(const string &filename);
//void afficherConsole()const;
......
......@@ -19,7 +19,7 @@ Pixel::Pixel(const unsigned int & x,const unsigned int & y, const unsigned int &
b = char(z);
}
Pixel Pixel::operator=(Pixel p)
/*Pixel Pixel::operator=(Pixel p)
{
r = char(p.r);
g = char(p.g);
......@@ -27,5 +27,5 @@ Pixel Pixel::operator=(Pixel p)
return *this;
}
*/
......@@ -35,7 +35,7 @@ class Pixel
Pixel();
Pixel(const unsigned int &ro, const unsigned int &ve, const unsigned int &bl);
Pixel operator=(Pixel p);
///<Pixel operator=(Pixel p);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment