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
| #include <cstdlib>
#include <cstdio>
#include <iostream>
#include "SDL/SDL.h"
#include "prototypes.h"
const int LARGEUR_ECRAN = 640;
const int HAUTEUR_ECRAN = 480;
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *Tampon = NULL;
SDL_Rect position;
SDL_Event event;
int i = 0;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
Tampon = SDL_LoadBMP("./image.bmp");
ecran = SDL_SetVideoMode(Tampon->w, Tampon->h, 32, SDL_HWSURFACE);
position.x = 0;
position.y = 0;
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
Manipulation(Tampon);
SDL_BlitSurface(Tampon, NULL, ecran, &position);
SDL_Flip(ecran);
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE)
{
continuer = 0;
break;
}
}
}
SDL_FreeSurface(Tampon);
SDL_Quit();
return EXIT_SUCCESS;
}
void Manipulation(SDL_Surface* surface)
{
int x, y;
Uint8 r_s, g_s, b_s, a_s;
Uint32 pixel_s;
SDL_LockSurface(surface);
for (y = 0 ; y < surface->h; y ++)
{
for ( x = 0 ; x < surface->w; x ++)
{
pixel_s = getPixel(surface, x, y);
SDL_GetRGBA(pixel_s, surface->format, &r_s, &g_s, &b_s, &a_s);
Uint8 Moyenne = (r_s + g_s + b_s) / 3;
if(Moyenne < 123)
{
r_s = 0;
g_s = 0;
b_s = 0;
}
else if(Moyenne >= 124)
{
r_s = 255;
g_s = 255;
b_s = 255;
}
pixel_s=SDL_MapRGBA(surface->format, r_s, g_s, b_s, a_s);
setPixel(surface, x, y, pixel_s);
}
}
SDL_UnlockSurface(surface);
}
Uint8 Verifier_valeur(Uint8 valeur)
{
if(valeur < 123)
{
valeur = 0;
}
if(valeur > 123)
{
valeur = 255;
}
return valeur;
} |
Partager