PDA

Voir la version complète : parcourir tous les pixels d'une image


Mad-Math
04/10/2005, 15h30
Bonjour a tous
voici un bout de mon code




typedef struct
{
Uint8 r;
Uint8 v;
Uint8 b;
}couleur;



c'est la structure que j'utilise pout stocker mon image


bitmap = IMG_Load(fichier.c_str());

if(bitmap == NULL)
{
cout<<"Echec du chargement de l'image"<<endl;
return 1;
}
else
{
cout<<"Chargement de l'image terminé"<<endl;
}

cout<<"Début de l'analyse de l'image"<<endl;

SDL_PixelFormat * format = bitmap->format;
SDL_LockSurface(bitmap);

int bitsParPixel = bitmap->format->BytesPerPixel;
int x = bitmap->w;
int y = bitmap->h;

Uint32 temp;
Uint32 pixel;
couleur pixels [x][y];

for(int j=0;j<y;j++)
{
for(int i=0;i<x;i++)
{
cout<<"index="<<index;
pixel=((Uint32*)bitmap->pixels)[i*j]; // indices corects ???
SDL_UnlockSurface(bitmap);

/* Get Red component */
temp=pixel&format->Rmask; /* Isolate red component */
temp=temp>>format->Rshift;/* Shift it down to 8-bit */
temp=temp<<format->Rloss; /* Expand to a full 8-bit number */
pixels[i][j].r=(Uint8)temp;

/* Get Green component */
temp=pixel&format->Gmask; /* Isolate green component */
temp=temp>>format->Gshift;/* Shift it down to 8-bit */
temp=temp<<format->Gloss; /* Expand to a full 8-bit number */
pixels[i][j].v=(Uint8)temp;

/* Get Blue component */
temp=pixel&format->Bmask; /* Isolate blue component */
temp=temp>>format->Bshift;/* Shift it down to 8-bit */
temp=temp<<format->Bloss; /* Expand to a full 8-bit number */
pixels[i][j].b=(Uint8)temp;
}
}


je n'arrive pas a récuperer les pixel de la SDL_SURFACE pour les mettre dans mon tableau de couleur pixel

je pense m'être trompé dans les indices pour parcourir le tableau de pixel

qu'en pensez vous ?
ou est ce que ca cloche ?

Mad-Math
04/10/2005, 15h38
c'est bon j'ai trouvé
:00000014:

Mad-Math
04/10/2005, 21h38
en fait ca marche pas
j'ai simplifié mon code


couleur pixels [x][y];

int index=0;
for(int j=0;j<y;j++)
{
for(int i=0;i<x;i++)
{
cout<<"index="<<index;
pixel=((Uint32*)bitmap->pixels)[index];

SDL_GetRGBA(pixel, format, &(pixels[i][j].r), &(pixels[i][j].v), &(pixels[i][j].b), &(pixels[i][j].a));

index++;
}
}



je sais pas pourquoi mais seul la couleur rouge pure est reconue et saffiche
si mon image contient une autre couleur ou du rouge différent de (255,0,0) alors j'ai du (0,0,0) noir.

quel est le problème dans mon code ??

Mad-Math
04/10/2005, 22h35
C'est bon, en fait c'est a l'affichage que ca ne marchait pas