Add main file

- Specify image in args
- Override support
- SDL usage
This commit is contained in:
Mylloon 2022-05-08 15:57:00 +02:00
parent f00cbff45a
commit 487354a9c6
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

46
src/main.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <SDL_image.h>
#include <iostream>
#include <fstream>
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<int>(SDL_MapRGB(s->format, 0, 0, 0)), static_cast<size_t>(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;
}