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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <conio.h>
void pause();
Uint32 obtenirPixel(SDL_Surface *, int , int );
void definirPixel(SDL_Surface *, int , int , Uint32 );
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *imageDeFond = NULL,*imagetransf = NULL;
SDL_Rect positionFond;
SDL_Rect positiontransf;
int x,y,h,w;
Uint32 pixel;
positionFond.x = 0;
positionFond.y = 0;
positiontransf.x = 500;
positiontransf.y = 300;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(1000, 1000, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("Transformation du boulanger", NULL);
imageDeFond = SDL_LoadBMP("rec1.bmp");
for (y=0;y<imageDeFond->h;y++)
{
for (x=0;x<imageDeFond->w;x++)
{
pixel=obtenirPixel(imageDeFond,x,y);
/*là en principe je modifie j'entre de nouvelles valeurs a et b et je les redonne a la fonction definirpixel au lieu de x et y mais ce n'est pas là le prblème*/
definirPixel(&imagetransf,x,y,pixel);
}
}
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);
SDL_BlitSurface(imagetransf, NULL, ecran, &positiontransf);
SDL_Flip(ecran);
pause();
SDL_FreeSurface(imageDeFond);
SDL_FreeSurface(imagetransf);
SDL_Quit();
getch();
return EXIT_SUCCESS;
}
void pause()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
}
Uint32 obtenirPixel(SDL_Surface *surface, int x, int y)
{
int nbOctetsParPixel = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
switch(nbOctetsParPixel)
{
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0;
}
}
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int nbOctetsParPixel = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
switch(nbOctetsParPixel)
{
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
} |
Partager