diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..54c61ec --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) { + if(argc != 2) { + std::cerr << "Aucune image renseignée." << std::endl; + std::cerr << "Usage : " << argv[0] << " image" << std::endl; + return 1; + } + + SDL_Surface * s; + if((s = IMG_Load(argv[1])) == NULL) { + std::cerr << "Impossible de charger l'image." << std::endl; + return 1; + } + + // TODO: Faire une vraie compression + /* if(SDL_LockSurface(s) == 0) { + SDL_memset(s->pixels, static_cast(SDL_MapRGB(s->format, 0, 0, 0)), static_cast(s->h * s->pitch)); + SDL_UnlockSurface(s); + } else { + std::cerr << "Impossible de modifier l'image (" << SDL_GetError() << ")." << std::endl; + return 1; + } */ + + std::string chemin_image("test.bmp"); + if(std::ifstream(chemin_image).is_open()) { + char choix; + do { + std::cout << "Le fichier existe déjà, voulez vous l'écraser ? y/n" << std::endl; + std::cin >> choix; + choix = tolower(choix); + } while(choix != 'n' && choix != 'y' && choix != 'o'); + if(choix == 'y' || choix == 'o') { + SDL_SaveBMP(s, chemin_image.c_str()); + } else { + std::cout << "Passe..." << std::endl; + } + } else { + SDL_SaveBMP(s, chemin_image.c_str()); + } + + SDL_FreeSurface(s); + return 0; +}