trying stuff
This commit is contained in:
parent
33d8e8aac5
commit
41dfd68f09
@ -8,7 +8,7 @@ set(${TGT}_VERSION_MAJOR 0)
|
||||
set(${TGT}_VERSION_MINOR 1)
|
||||
|
||||
set(CC_COVERAGE_COMPILE_FLAGS "-pedantic -Wall -Wextra -Wfloat-equal -Wwrite-strings -Wpointer-arith -Wcast-align -Wshadow -Wredundant-decls -Wdouble-promotion -Winit-self -Wswitch-default -Wswitch-enum -Wundef -Winline")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CC_COVERAGE_COMPILE_FLAGS} -DDebug -g -pg")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CC_COVERAGE_COMPILE_FLAGS} -DDebug -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CC_COVERAGE_COMPILE_FLAGS} -O3")
|
||||
|
||||
set(CMAKE_CC_STANDARD 11)
|
||||
|
@ -70,12 +70,15 @@ darray_t imgToZones(Image_t t_img) {
|
||||
return zones;
|
||||
}
|
||||
|
||||
void compress(char *input_file) {
|
||||
void compress(const char *input_file) {
|
||||
Image_t img;
|
||||
darray_t zones;
|
||||
img = newImage();
|
||||
imageLoadPPM(input_file, img);
|
||||
zones = imgToZones(img);
|
||||
darrayDelete(zones);
|
||||
|
||||
printf("Detected %zu zones\n", darraySize(zones));
|
||||
|
||||
deleteImage(img);
|
||||
}
|
||||
|
@ -6,5 +6,6 @@
|
||||
void addPixelToSelectedZone(Image_t t_img, int t_idx, Zone_t t_zone);
|
||||
void chooseZoneForPixel(Image_t t_img, int t_idx, darray_t zones);
|
||||
darray_t imgToZones(Image_t t_img);
|
||||
void compress(const char*);
|
||||
|
||||
#endif /* COMMON_H */
|
||||
|
@ -8,7 +8,7 @@
|
||||
* des fonctions cœures du programme.
|
||||
*/
|
||||
|
||||
#include "utilities.h"
|
||||
#include "common.h"
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -91,7 +91,7 @@ void get_args(Argres *t_args, int *t_c) {
|
||||
Argres process_args(const int t_argc, char *t_argv[]) {
|
||||
Argres res;
|
||||
res.input = NULL;
|
||||
res.output = NULL;
|
||||
res.output = "output.fs";
|
||||
while (true) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
@ -122,12 +122,10 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "ERROR: no input file.");
|
||||
help(ARGERROR);
|
||||
}
|
||||
if (!argresults.output) {
|
||||
argresults.output = "output.fs";
|
||||
}
|
||||
printf("input: %s\noutput: %s\n", argresults.input, argresults.output);
|
||||
if(argresults.compress) {
|
||||
puts("Compressing...");
|
||||
compress(argresults.input);
|
||||
} else {
|
||||
puts("Uncompressing...");
|
||||
}
|
||||
|
18
src/ppm.c
18
src/ppm.c
@ -23,8 +23,9 @@
|
||||
* \param[in] mode Mode du fichier à ouvrir
|
||||
* \return Pointeur de fichier
|
||||
*/
|
||||
FILE* get_file(char *t_filename, const char* t_mode) {
|
||||
FILE* get_file(const char *t_filename, const char* t_mode) {
|
||||
FILE* fp = fopen(t_filename, t_mode);
|
||||
printf("Opened file... maybe?\n");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Unable to open file '%s'\n", t_filename);
|
||||
exit(FILE_IO_ERROR);
|
||||
@ -39,7 +40,7 @@ FILE* get_file(char *t_filename, const char* t_mode) {
|
||||
* \param[in] fb Fichier ppm où lire les données
|
||||
* \param[in] filename Nom du fichier ouvert
|
||||
*/
|
||||
void read_file_format(FILE* t_fp, char* t_filename) {
|
||||
void read_file_format(FILE* t_fp, const char* t_filename) {
|
||||
char buff[16];
|
||||
if (!fgets(buff, sizeof(buff), t_fp)) {
|
||||
perror(t_filename);
|
||||
@ -76,7 +77,7 @@ void check_for_comments(FILE* t_fp) {
|
||||
* \param[out] img Conteneur d’image où écrire les résultats
|
||||
* \param[in] filename Nom du fichier ouvert
|
||||
*/
|
||||
void read_file_size(FILE* t_fp, Image* t_img, char* t_filename) {
|
||||
void read_file_size(FILE* t_fp, Image* t_img, const char* t_filename) {
|
||||
if (fscanf(t_fp, "%lu %lu", &t_img->x, &t_img->y) != 2) {
|
||||
fprintf(stderr, "Invalid image size (error loading '%s')\n", t_filename);
|
||||
exit(FILE_FORMAT_ERROR);
|
||||
@ -90,7 +91,7 @@ void read_file_size(FILE* t_fp, Image* t_img, char* t_filename) {
|
||||
* \param[in] fp Fichier ppm où lire les données
|
||||
* \param[in] filename Nom du fichier ouvert
|
||||
*/
|
||||
void read_rgb(FILE* t_fp, char* t_filename) {
|
||||
void read_rgb(FILE* t_fp, const char* t_filename) {
|
||||
char d;
|
||||
int rgb_comp_color;
|
||||
/* read rgb component */
|
||||
@ -107,7 +108,7 @@ void read_rgb(FILE* t_fp, char* t_filename) {
|
||||
}
|
||||
|
||||
unsigned long read_data(FILE *t_fp, Image *t_img, GLubyte *t_data,
|
||||
char *t_filename) {
|
||||
const char *t_filename) {
|
||||
unsigned long size;
|
||||
/* allocation memoire */
|
||||
size = t_img->x * t_img->y * 3;
|
||||
@ -136,12 +137,12 @@ unsigned long read_data(FILE *t_fp, Image *t_img, GLubyte *t_data,
|
||||
*/
|
||||
void dataToImage(Image *t_img, GLubyte *t_data, unsigned long t_size) {
|
||||
unsigned long i;
|
||||
printf("Hey 1\n");
|
||||
t_img->pixels = darrayNew(sizeof(Pixel));
|
||||
printf("Hey 2\n");
|
||||
for (i = 0; i < t_size; i += 3) {
|
||||
darrayPushBack(t_img->pixels,
|
||||
newPixel(t_data[i], t_data[i + 1], t_data[i + 2]));
|
||||
darrayPushBack(t_img->pixels,
|
||||
newPixel(t_data[i], t_data[i + 1], t_data[i + 2]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,10 +179,11 @@ GLubyte *imageToData(Image_t t_img) {
|
||||
* \param[out] img Objet \ref Image manipulable
|
||||
* \return Retourne 1 en cas de succès
|
||||
*/
|
||||
int imageLoadPPM(char *t_filename, Image *t_img) {
|
||||
int imageLoadPPM(const char *t_filename, Image *t_img) {
|
||||
FILE *fp;
|
||||
unsigned long size;
|
||||
GLubyte *data = NULL;
|
||||
printf("Hey auie\n");
|
||||
fp = get_file(t_filename, "rb"); /* open PPM file for reading */
|
||||
read_file_format(fp, t_filename); /* read image format */
|
||||
check_for_comments(fp); /* check for comments */
|
||||
|
12
src/ppm.h
12
src/ppm.h
@ -13,23 +13,23 @@
|
||||
#include "utilities.h"
|
||||
|
||||
/// \brief Ouvre un fichier avec les autorisations demandées
|
||||
FILE *get_file(char *filename, const char *mode);
|
||||
FILE *get_file(const char *filename, const char *mode);
|
||||
/// \brief Lit le format d’un fichier ppm ouvert
|
||||
void read_file_format(FILE* fp, char* filename);
|
||||
void read_file_format(FILE* fp, const char* filename);
|
||||
/// \brief Vérifie et ignore d’éventuels commentaires du header d’un fichier
|
||||
void check_for_comments(FILE *fp);
|
||||
/// \brief Lit les dimensions du fichier ppm ouvert
|
||||
void read_file_size(FILE *fp, Image *img, char *filename);
|
||||
void read_file_size(FILE *fp, Image *img, const char *filename);
|
||||
/// \brief Lit et vérifie le format RGB du fichier ppm
|
||||
void read_rgb(FILE *fp, char *filename);
|
||||
void read_rgb(FILE *fp, const char *filename);
|
||||
/// \brief Lit dans le conteneur les données images du fichier ppm
|
||||
unsigned long read_data(FILE *fp, Image *img, GLubyte *data, char *filename);
|
||||
unsigned long read_data(FILE *fp, Image *img, GLubyte *data, const char *filename);
|
||||
/// \brief Convertit les données brutes de fichier vers des conteneurs de pixels
|
||||
void dataToImage(Image *img, GLubyte *data, unsigned long size);
|
||||
/// \brief Convertit les pixels d’une image en tableau natif OpenGL
|
||||
GLubyte *imageToData(Image_t img);
|
||||
/// \brief Ouverture et lecture de l’image d’entrée
|
||||
int imageLoadPPM(char *filename, Image_t img);
|
||||
int imageLoadPPM(const char *filename, Image_t img);
|
||||
/// \brief Ouverture et écriture de l'image de sortie
|
||||
void imageSavePPM(char *filename, Image_t img);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user