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 ?
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 ?