Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int IsColonne(SDL_Surface *image,int x)
- {
- Uint8 r;
- Uint8 g;
- Uint8 b;
- int res = 1;
- for(int y = 0; y<image->h-1;++y)
- {
- Uint32 p = (getpixel(image,(unsigned)x,(unsigned)y));
- SDL_GetRGB(p,image->format,&r,&g,&b);
- if( g == 0)
- {
- res = 0;
- }
- }
- return res;
- }
- //Test si la ligne est totalement blanche
- int IsLine(SDL_Surface *image, int y)
- { Uint8 r;
- Uint8 g;
- Uint8 b;
- int res = 1;
- for(int x = 0; x<image->w;++x)
- {
- Uint32 p = (getpixel(image,(unsigned)x,(unsigned)y));
- SDL_GetRGB(p,image->format,&r,&g,&b);
- if(b == 0)
- {
- res = 0;
- }
- }
- return res;
- }
- // Dessine une ligne autour des blocs (Pour mieux visualiser)
- void LineMarker(SDL_Surface *image,int y)
- {
- Uint8 r;
- Uint8 g;
- Uint8 b;
- for( int x = 0 ; x <image->w; ++x)
- {
- r = 255;
- g=1;
- b=1;
- putpixel(image,(unsigned)x,(unsigned)y,SDL_MapRGB(image->format,r,g,b));
- }
- }
- //Un truc qui marque les colonnes...En rouge, parce que c'est moche le rouge.
- void ColumnMarker(SDL_Surface *image,int x)
- {
- Uint8 r;
- Uint8 g;
- Uint8 b;
- for( int y = 0 ; y < image->h; ++y)
- {
- r = 255;
- g=1;
- b=1;
- putpixel(image,(unsigned)x,(unsigned)y,SDL_MapRGB(image->format,r,g,b));
- }
- }
- //Thx Vicky again ?!
- void OnceAgainLine(SDL_Surface *image)
- {
- for(int y = 0;y<image->h; ++y)
- {
- if(IsLine(image,y) == 0)
- {
- LineMarker(image,y);
- y = image->h -1;
- }
- }
- for(int y = image->h -1; y>0;--y)
- {
- if(IsLine(image,y) == 0)
- {
- LineMarker(image,y);
- y = 0;
- }
- }
- }
- void OnceAgainColumn(SDL_Surface *image)
- {
- for(int x = 0; x<image->w;++x)
- {
- if(IsColonne(image,x) == 0)
- {
- ColumnMarker(image,x);
- x = image->w-1;
- }
- }
- for(int x = image->w -1; x>0; --x)
- {
- if(IsColonne(image,x) == 0)
- {
- ColumnMarker(image,x);
- x = 0;
- }
- }
- }
- //Fonction qui-fait-tout
- int BW(SDL_Surface *image)
- {
- Uint8 r;
- Uint8 g;
- Uint8 b;
- for(int x = 0; x < image->w;x++)
- {
- for(int y = 0; y < image->h;y++)
- {
- Uint32 p = getpixel(image,(unsigned)x,(unsigned)y);
- SDL_GetRGB(p,image->format,&r,&g,&b);
- r= g = b = (float)r * 0.3 + (float)g * 0.59 + (float)b * 0.11;
- int lim = 255/2;
- if(r>lim) { r = g = b = 255; }
- else{ r = g = b = 0;}
- putpixel(image,(unsigned)x,(unsigned)y,SDL_MapRGB(image->format,r,g,b));
- }
- }
- OnceAgainLine(image);
- OnceAgainColumn(image);
- image = display_image(image);
- SDL_FreeSurface(image);
- return 0;
- }
- //Vraiment besoin d'un commentaire pour le main ?
- int main(int argc,char *argv[])
- {
- if(argc>1){
- init_sdl();
- SDL_Surface* image = load_image(argv[1]);
- image = display_image(image);
- SDL_FreeSurface(image);
- image = load_image(argv[1]);
- BW(image);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement