1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Image_PPM* Reduire_La_Taille(Image_PPM* im, int reduc_X, int reduc_Y, Pix* f(unsigned char*, int, int, int, int, int, int)) {
if (im != NULL) {
long max = im->NbColonne * im->NbLigne * 3,
maxNouveau = max / (reduc_X*reduc_Y);
unsigned char* matrice = (unsigned char*) malloc(sizeof(unsigned char) *
maxNouveau);
if (matrice == NULL) return NULL; // gestion d'erreur à mettre ici
// envoyer un message windows à afficher ...
long i = 0, j = 0, cpt = 0,
nbc = im->NbColonne/reduc_X, nbl = im->NbLigne/reduc_Y;
Pix* p = NULL;
for (cpt = 0; cpt < maxNouveau; cpt+=3) {
i = ((cpt / 3) % nbc);// X
j = ((cpt / 3) / nbc);// Y
p = f(im->Couleur, im->NbColonne, im->NbLigne, nbc, nbl, i, j);
matrice[cpt] = p->Rouge;
matrice[cpt+1] = p->Vert;
matrice[cpt+2] = p->Bleu;
LibererPix(p);
}
LibererDonnees(im);
im->NbColonne = nbc;
im->NbLigne = nbl;
im->Couleur = matrice;
return im;
}
return NULL;
}
Pix* Prendre_Max_Du_Groupe(unsigned char* mat, int t_X, int t_Y, int nt_X, int nt_Y, int pos_X, int pos_Y) {
if (mat != NULL) {
long //i = 0 , j = 0,
avance_X = t_X / nt_X,
avance_Y = t_Y / nt_Y;
Pix* p = CreerPix3(mat[(pos_X*avance_X*3)+(pos_Y*avance_Y*t_X*3)],
mat[(pos_X*avance_X*3)+(pos_Y*avance_Y*t_X*3)+1],
mat[(pos_X*avance_X*3)+(pos_Y*avance_Y*t_X*3)+2]);
/*
for (i = 0; i < avance_X; i++) {
for(j = 0; j < avance_Y; j++) {
if ((p->Bleu + p->Rouge + p->Vert) <
(mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)] +
mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)+1] +
mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)+2])) {
p->Rouge = mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)];
p->Vert = mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)+1];
p->Bleu = mat[((pos_X+i)*avance_X*3)+((pos_Y+j)*avance_Y*t_X*3)+2];
}
}
}*/
return p;
}
return NULL;
} |