From 487354a9c62b655d8665820bdb433cd65a4cc95c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 8 May 2022 15:57:00 +0200 Subject: [PATCH] Add main file - Specify image in args - Override support - SDL usage --- src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main.cpp 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; +}