Skip to content
Snippets Groups Projects
Commit 8f006628 authored by DUPASQUIER YOANN p2301526's avatar DUPASQUIER YOANN p2301526
Browse files

jesaispas

parent 476a0a38
No related branches found
No related tags found
No related merge requests found
Pipeline #188113 passed with warnings
#include <iostream>
#include "Image.h"
#include <cassert>
using namespace std;
Image::Image() {
dimx=0;
dimy=0;
};
Image::Image(int dimensionX, int dimensionY) {
Pixel noir (0,0,0);
dimx=dimensionX;
dimy=dimensionY;
tab=new Pixel[dimx*dimy];
for (int i=0; i<dimx*dimy; i++) {
tab[i]=noir;
}
};
Image::~Image() {
dimx=0;
dimy=0;
if (tab!=nullptr) {
delete [] tab;
tab=nullptr;}
};
Pixel Image::getPix(int x, int y) {
assert(dimx>=0);
assert(dimy>=0);
return(tab[y*dimx+x]);
};
Pixel Image::getPixc(int x, int y) const {
assert(dimx>=0);
assert(dimy>=0);
Pixel p=tab[y*dimx+x];
return p;
};
void Image::setPix(int x, int y, Pixel couleur) {
assert(dimx>=0);
assert(dimy>=0);
tab[y*dimx+x]=couleur;
};
void Image::dessinerRectangle(int Xmin, int Ymin, int Xmax, int Ymax, Pixel couleur) {
assert(Xmin>=0);
assert(Ymin>=0);
assert(Xmax>=0);
assert(Ymax>=0);
for (int i=Xmin; i<Xmax;i++) {
for (int j=Ymin; j<Ymax; j++) {
setPix(i,j,couleur);
}
}
};
void Image::effacer(Pixel couleur) {
dessinerRectangle(0,0,dimx,dimy,couleur);
};
void Image::testRegression() {
Image i (20,20);
Pixel p1;
Pixel p2(10,20,30) ;
Pixel p3 (24, 55, 68);
Pixel p4 (97, 1, 12);
i.setPix(1,1,p3);
i.setPix(1,1,p4);
cout<<int((i.getPix(1,1)).r)<<"/"<<int((i.getPix(1,1)).g)<<"/"<<int((i.getPix(1,1)).b)<<endl;
cout<<int((i.getPixc(1,2)).r)<<"/"<<int((i.getPixc(1,2)).g)<<"/"<<int((i.getPixc(1,2)).b)<<endl;
Pixel c (1,2,3);
i.dessinerRectangle(1,1,1,1,c);
cout<<int((i.getPix(1,1)).r)<<"/"<<int((i.getPix(1,1)).g)<<"/"<<int((i.getPix(1,1)).b)<<endl;
Pixel n (0,0,0);
i.effacer(n);
cout<<int((i.getPix(1,1)).r)<<"/"<<int((i.getPix(1,1)).g)<<"/"<<int((i.getPix(1,1)).b)<<endl;
cout<<int((i.getPix(1,2)).r)<<"/"<<int((i.getPix(1,2)).g)<<"/"<<int((i.getPix(1,2)).b)<<endl;
};
#ifndef _IMAGE_H
#define _IMAGE_H
#include "Pixel.h"
class Image {
private:
int dimx;
int dimy;
Pixel *tab;
public:
Image();
Image(int dimensionX, int dimensionY);
~Image();
Pixel getPix(int x, int y); //renvoie le piexl original, pas une copie
Pixel getPixc(int x, int y) const;//renvoie une copie du pixel
void setPix(int x, int y, Pixel couleur);
void dessinerRectangle(int Xmin, int Ymin, int Xmax, int Ymax, Pixel couleur);
void effacer(Pixel couleur);
static void testRegression();
};
#endif
#include "Pixel.h"
Pixel::Pixel() {
r=0;
g=0;
b=0;
}
Pixel::Pixel (unsigned char nr,unsigned char ng,unsigned char nb) {
r=nr;
g=ng;
b=nb;
}
#ifndef _PIXEL_H
#define _PIXEL_H
class Pixel {
public:
unsigned char r,g,b; // les composantes du pixel, unsigned char en C++
// Constructeur par défaut de la classe: initialise le pixel à la couleur noire
Pixel();
// Constructeur de la classe: initialise r,g,b avec les paramètres
Pixel (unsigned char nr,unsigned char ng,unsigned char nb);
};
#endif
#include <iostream>
#include "Pixel.h"
#include "Image.h"
using namespace std;
int main() {
Image::testRegression();
return 0;
}
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