coding style + initial compression algorithm
This commit is contained in:
		
							parent
							
								
									477f702870
								
							
						
					
					
						commit
						fa42564c17
					
				@ -7,7 +7,7 @@ set(TGT "surfaces-unies")
 | 
			
		||||
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-qual -Wcast-align -Wconversion -Wshadow -Wredundant-decls -Wdouble-promotion -Winit-self -Wswitch-default -Wswitch-enum -Wundef -Winline")
 | 
			
		||||
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_RELEASE "${CC_COVERAGE_COMPILE_FLAGS} -O3")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								TODOs.org
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								TODOs.org
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
* Development
 | 
			
		||||
** TODO Test if the zones detection works
 | 
			
		||||
** TODO Add compressed file output
 | 
			
		||||
** TODO Add file uncompression
 | 
			
		||||
** TODO Add tolerance parameter
 | 
			
		||||
* Tests
 | 
			
		||||
** TODO Add tests for darray
 | 
			
		||||
** TODO Add tests for zones
 | 
			
		||||
** TODO Add tests for files reading
 | 
			
		||||
** TODO Add tests for file comparison after compression and uncompression
 | 
			
		||||
							
								
								
									
										70
									
								
								src/common.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								src/common.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,70 @@
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
bool sameColor(Pixel_t t_pixel, Zone_t t_zone) {
 | 
			
		||||
  return t_pixel->r == t_zone->r && t_pixel->g == t_zone->g &&
 | 
			
		||||
         t_pixel->b == t_zone->b;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Adds a pixel to a zone, since the pixel isn't in a zone, then it isn't
 | 
			
		||||
   part of a segment either, hence we can confidently add pixels next to the
 | 
			
		||||
   original as parts of the segment and add the segment itself to the zone */
 | 
			
		||||
void addPixelToSelectedZone(Image_t t_img, int t_idx, Zone_t t_zone) {
 | 
			
		||||
  Pixel_t current_pixel;
 | 
			
		||||
  int xd, xg;
 | 
			
		||||
  current_pixel = darrayGet(t_img->pixels, t_idx);
 | 
			
		||||
  if (current_pixel->visited || t_idx >= (int)darraySize(t_img->pixels) ||
 | 
			
		||||
      t_idx < 0 || !sameColor(current_pixel, t_zone)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  (*current_pixel).visited = true;
 | 
			
		||||
  for(xd = t_idx; xd % (int)t_img->x != 0; ++xd) { /* fetch right limit of segment */
 | 
			
		||||
    current_pixel = darrayGet(t_img->pixels, xd);
 | 
			
		||||
    if(!sameColor(current_pixel, t_zone)) {
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    (*current_pixel).visited = true;
 | 
			
		||||
  }
 | 
			
		||||
  for(xg = t_idx; xg % t_img->x >= 0; --xg) { /* fetch right limit of segment */
 | 
			
		||||
    current_pixel = darrayGet(t_img->pixels, xd);
 | 
			
		||||
    if(!sameColor(current_pixel, t_zone)) {
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    (*current_pixel).visited = true;
 | 
			
		||||
  }
 | 
			
		||||
  /* Add segment to its zone */
 | 
			
		||||
  darrayPushBack(t_zone->segments, newSegment(t_idx / t_img->x, xd, xg));
 | 
			
		||||
  for(; xg <= xd; ++xg) { /* process every pixel up and down the segment */
 | 
			
		||||
    addPixelToSelectedZone(t_img, t_idx + t_img->x, t_zone);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Selects the zone related to the pixel, skip tests if pixel has
 | 
			
		||||
 already been visited */
 | 
			
		||||
void chooseZoneForPixel(Image_t t_img, int t_idx, darray_t zones) {
 | 
			
		||||
  Zone_t current_zone;
 | 
			
		||||
  Pixel_t pixel;
 | 
			
		||||
  size_t i;
 | 
			
		||||
  pixel = darrayGet(t_img->pixels, t_idx);
 | 
			
		||||
  if (pixel->visited)
 | 
			
		||||
    return;
 | 
			
		||||
  for (i = 0; i < darraySize(zones); ++i) {
 | 
			
		||||
    current_zone = darrayGet(zones, i);
 | 
			
		||||
    if (sameColor(pixel, current_zone)) {
 | 
			
		||||
      addPixelToSelectedZone(t_img, t_idx, current_zone);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* converts an image to zones */
 | 
			
		||||
darray_t imgToZones(Image_t t_img) {
 | 
			
		||||
  darray_t zones;
 | 
			
		||||
  const size_t nb_pixels = darraySize(t_img->pixels);
 | 
			
		||||
  size_t i;
 | 
			
		||||
  zones = darrayNew(sizeof(Zone));
 | 
			
		||||
 | 
			
		||||
  for (i = 0; i < nb_pixels; ++i) {
 | 
			
		||||
    chooseZoneForPixel(t_img, i, zones);
 | 
			
		||||
  }
 | 
			
		||||
  return zones;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								src/common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/common.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
#ifndef COMMON_H
 | 
			
		||||
#define COMMON_H
 | 
			
		||||
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
#endif /* COMMON_H */
 | 
			
		||||
							
								
								
									
										28
									
								
								src/darray.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/darray.c
									
									
									
									
									
								
							@ -13,7 +13,7 @@
 | 
			
		||||
 * de connaître l’espace mémoire à allouer à chacun des éléments dans le
 | 
			
		||||
 * tableau. Cela implique qu’un objet \ref darray_t ne peut contenir que des
 | 
			
		||||
 * éléments du même type.
 | 
			
		||||
 * \param element_size Taille des objets stockés
 | 
			
		||||
 * \param[in] element_size Taille des objets stockés
 | 
			
		||||
 * \return Pointeur sur le nouvel objet \ref darray_t
 | 
			
		||||
 */
 | 
			
		||||
darray_t darrayNew(size_t t_element_size) {
 | 
			
		||||
@ -32,9 +32,9 @@ darray_t darrayNew(size_t t_element_size) {
 | 
			
		||||
 * pen d’un cran vers la fin du tableau et insérera à l’endroit pointé le nouvel
 | 
			
		||||
 * élément. Cette fonction modifie les membres `begin` et `end` et
 | 
			
		||||
 * potentiellement `capacity` de `self`.
 | 
			
		||||
 * \param self Objet \ref darray_t dans lequel on souhaite insérer un nouvel élément
 | 
			
		||||
 * \param pos Position à laquelle on souhaite insérer un nouvel élément
 | 
			
		||||
 * \param elem Élément que l’on souhaite insérer
 | 
			
		||||
 * \param[in] self Objet \ref darray_t dans lequel on souhaite insérer un nouvel élément
 | 
			
		||||
 * \param[in] pos Position à laquelle on souhaite insérer un nouvel élément
 | 
			
		||||
 * \param[in] elem Élément que l’on souhaite insérer
 | 
			
		||||
 */
 | 
			
		||||
void darrayInsert(darray_t t_self, void *t_pos, void *t_elem) {
 | 
			
		||||
  char *itr;
 | 
			
		||||
@ -55,7 +55,7 @@ void darrayInsert(darray_t t_self, void *t_pos, void *t_elem) {
 | 
			
		||||
 *  sa capacité par deux. Si la réallocation mémoire ne réussit pas, le
 | 
			
		||||
 *  programme s’arrête immédiatement, renvoyant la valeur de \ref PTR_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 *  \param self L'objet darray_t à étendre
 | 
			
		||||
 *  \param[in] self L'objet darray_t à étendre
 | 
			
		||||
 */
 | 
			
		||||
void darrayExtend(darray_t t_self) {
 | 
			
		||||
  void *new_array;
 | 
			
		||||
@ -79,8 +79,8 @@ void darrayExtend(darray_t t_self) {
 | 
			
		||||
 * vers le début du tableau de manière à ce qu’il n’y aie pas d’élément vide
 | 
			
		||||
 * entre les membres `begin` et `end` de `self`. Par ailleurs, le membre `end`
 | 
			
		||||
 * de `self` se retrouve modifié par la fonction.
 | 
			
		||||
 * \param self Objet \ref `darray_t` dont on souhaite supprimer un élément
 | 
			
		||||
 * \param pos Élément de `self` que l’on souhaite supprimer
 | 
			
		||||
 * \param[out] self Objet \ref `darray_t` dont on souhaite supprimer un élément
 | 
			
		||||
 * \param[in] pos Élément de `self` que l’on souhaite supprimer
 | 
			
		||||
 */
 | 
			
		||||
void darrayErase(darray_t t_self, void *t_pos) {
 | 
			
		||||
  memmove(t_pos, (char *)t_pos + t_self->element_size,
 | 
			
		||||
@ -92,8 +92,8 @@ void darrayErase(darray_t t_self, void *t_pos) {
 | 
			
		||||
/**
 | 
			
		||||
 * `darrayPushBack` ajoute un nouvel élément `elem` à l’objet `self` à la fin du
 | 
			
		||||
 * tableau de ce dernier. Cette fonction modifie le membre `end` de `self`.
 | 
			
		||||
 * \param self Objet \ref darray_t à la fin duquel on souhaite ajouter un nouvel élément
 | 
			
		||||
 * \param elem Élément que l’on souhaite ajouter à la fin de `self`
 | 
			
		||||
 * \param[out] self Objet \ref darray_t à la fin duquel on souhaite ajouter un nouvel élément
 | 
			
		||||
 * \param[in] elem Élément que l’on souhaite ajouter à la fin de `self`
 | 
			
		||||
 */
 | 
			
		||||
void darrayPushBack(darray_t t_self, void *t_elem) {
 | 
			
		||||
  darrayInsert(t_self, t_self->end, t_elem);
 | 
			
		||||
@ -103,7 +103,7 @@ void darrayPushBack(darray_t t_self, void *t_elem) {
 | 
			
		||||
 * `darrayPopBack` permet de supprimer le dernier élément de l’objet \ref
 | 
			
		||||
 * darray_t passé en argument. Cette fonction modifie le membre `end` de ce
 | 
			
		||||
 * dernier objet.
 | 
			
		||||
 * \param self Objet dont on souhaite supprimer le dernier élément
 | 
			
		||||
 * \param[out] self Objet dont on souhaite supprimer le dernier élément
 | 
			
		||||
 */
 | 
			
		||||
void darrayPopBack(darray_t t_self) {
 | 
			
		||||
  darrayErase(t_self, (char *)t_self->end - t_self->element_size);
 | 
			
		||||
@ -114,7 +114,7 @@ void darrayPopBack(darray_t t_self) {
 | 
			
		||||
 * passé en argument avant de libérer la mémoire occupée par l’objet lui-même.
 | 
			
		||||
 * L’objet passé en argument ne sera plus utilisable après utilisation de cette
 | 
			
		||||
 * fonction.
 | 
			
		||||
 * \param self Objet \ref darray_t à supprimer
 | 
			
		||||
 * \param[out] self Objet \ref darray_t à supprimer
 | 
			
		||||
 */
 | 
			
		||||
void darrayDelete(darray_t t_self) {
 | 
			
		||||
  free(t_self->begin);
 | 
			
		||||
@ -125,7 +125,7 @@ void darrayDelete(darray_t t_self) {
 | 
			
		||||
 * `darraySize` renvoie le nombre d’éléments contenu dans le \ref darray_t
 | 
			
		||||
 * `self` passé en arguments. Cette fonction ne modifie pas l’élément passé en
 | 
			
		||||
 * argument.
 | 
			
		||||
 * \param self Objet \ref darray_t dont on souhaite connaître le nombre d’éléments
 | 
			
		||||
 * \param[out] self Objet \ref darray_t dont on souhaite connaître le nombre d’éléments
 | 
			
		||||
 * \return Nombre d’éléments contenus dans `self`
 | 
			
		||||
 */
 | 
			
		||||
size_t darraySize(darray_t t_self) {
 | 
			
		||||
@ -139,8 +139,8 @@ size_t darraySize(darray_t t_self) {
 | 
			
		||||
 * le pointeur `NULL` sera renvoyé, sinon un pointeur de type `void*` pointant
 | 
			
		||||
 * sur l’élément correspondant sera renvoyé. Cette fonction ne modifie pas
 | 
			
		||||
 * l’objet `self`.
 | 
			
		||||
 * \param self Objet \ref darray_t duquel on souhaite obtenir un pointeur sur l’élément à l’index `idx`
 | 
			
		||||
 * \param idx Index de l’élément que l’on souhaite récupérer
 | 
			
		||||
 * \param[out] self Objet \ref darray_t duquel on souhaite obtenir un pointeur sur l’élément à l’index `idx`
 | 
			
		||||
 * \param[in] idx Index de l’élément que l’on souhaite récupérer
 | 
			
		||||
 * \return Pointeur de type `void*` pointant sur l’élément si l’index est valide, sur NULL sinon.
 | 
			
		||||
 */
 | 
			
		||||
void *darrayGet(darray_t t_self, size_t t_idx) {
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@
 | 
			
		||||
#ifndef DARRAY_H
 | 
			
		||||
#define DARRAY_H
 | 
			
		||||
 | 
			
		||||
#include "errorcodes.h"
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								src/errorcodes.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/errorcodes.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
#ifndef ERRORCODES_H
 | 
			
		||||
#define ERRORCODES_H
 | 
			
		||||
 | 
			
		||||
/// Pas d’erreur
 | 
			
		||||
#define NOERROR 0
 | 
			
		||||
/// Constante pour les erreurs liées aux arguments
 | 
			
		||||
#define ARGERROR 1
 | 
			
		||||
/// Constante pour les erreurs liées à \ref darray_t
 | 
			
		||||
#define PTR_ERROR 2
 | 
			
		||||
/// Constante pour les erreurs liées à la lecture et écriture de fichiers
 | 
			
		||||
#define FILE_IO_ERROR 3
 | 
			
		||||
#define FILE_FORMAT_ERROR 4
 | 
			
		||||
 | 
			
		||||
#endif /* ERRORCODES_H */
 | 
			
		||||
							
								
								
									
										92
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										92
									
								
								src/main.c
									
									
									
									
									
								
							@ -1,10 +1,18 @@
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
#include <getopt.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
 | 
			
		||||
#define NOERROR 0
 | 
			
		||||
#define ARGERROR 1
 | 
			
		||||
 | 
			
		||||
void help(int exit_code) {
 | 
			
		||||
/**
 | 
			
		||||
 *  \brief Affiche un message d'aide
 | 
			
		||||
 *
 | 
			
		||||
 *  Affiche un message d'aide pour le logiciel ainsi que son utilisation, puis
 | 
			
		||||
 *  termine le processus avec le code de sortie indiqué par l'argument de la
 | 
			
		||||
 *  fonction.
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[in] t_exit_code Code de sortie du processus
 | 
			
		||||
 */
 | 
			
		||||
void help(int t_exit_code) {
 | 
			
		||||
  puts("Usage:");
 | 
			
		||||
  puts("surfaces-unies -i path [-o path] [-options]\n");
 | 
			
		||||
  puts("The default action is to compress the mandatory input image to a .sf");
 | 
			
		||||
@ -17,30 +25,61 @@ void help(int exit_code) {
 | 
			
		||||
  puts("\tpath to the output file (if the file already exists, it will be\n");
 | 
			
		||||
  puts("-c --compress\n\tcompress the input file");
 | 
			
		||||
  puts("-u --uncompress\n\tuncompresses the input file to the output file.");
 | 
			
		||||
  exit(exit_code);
 | 
			
		||||
  exit(t_exit_code);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  \struct Argres
 | 
			
		||||
 *  \brief Résultats du traitement des arguments du processus
 | 
			
		||||
 *
 | 
			
		||||
 *  Cette structure est utilisée pour consolider ensemble les résultats du
 | 
			
		||||
 *  traitement des arguments et les renvoyer en une fois au lieu d'avoir à
 | 
			
		||||
 *  utiliser des variables globales ou des pointeurs en arguments
 | 
			
		||||
 *  supplémentaires aux fonctions.
 | 
			
		||||
 */
 | 
			
		||||
struct Argres {
 | 
			
		||||
  char *input;
 | 
			
		||||
  char *output;
 | 
			
		||||
  bool compress;
 | 
			
		||||
  char *input;   /*!< Nom du fichier d'entrée */
 | 
			
		||||
  char *output;  /*!< Nom du fichier de sortie */
 | 
			
		||||
  bool compress; /*!< Le fichier d'entrée doit-il être compressé ? */
 | 
			
		||||
};
 | 
			
		||||
typedef struct Argres Argres;
 | 
			
		||||
 | 
			
		||||
void get_args(Argres *args, int *c) {
 | 
			
		||||
  switch (*c) {
 | 
			
		||||
/**
 | 
			
		||||
 *  \brief Processes independently the arguments of the process
 | 
			
		||||
 *
 | 
			
		||||
 *  Each option and switch will be processed here and will modify appropriately
 | 
			
		||||
 *  the parameter `args`
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[out] t_args Result of the arguments processing
 | 
			
		||||
 *  \param[in] t_c Switch or option passed
 | 
			
		||||
 */
 | 
			
		||||
void get_args(Argres *t_args, int *t_c) {
 | 
			
		||||
  switch (*t_c) {
 | 
			
		||||
  case 0:   break;
 | 
			
		||||
  case 'h': help(NOERROR); break;
 | 
			
		||||
  case 'i': (*args).input = optarg;   break;
 | 
			
		||||
  case 'o': (*args).output = optarg;  break;
 | 
			
		||||
  case 'c': (*args).compress = true;  break;
 | 
			
		||||
  case 'u': (*args).compress = false; break;
 | 
			
		||||
  case 'i': (*t_args).input = optarg;   break;
 | 
			
		||||
  case 'o': (*t_args).output = optarg;  break;
 | 
			
		||||
  case 'c': (*t_args).compress = true;  break;
 | 
			
		||||
  case 'u': (*t_args).compress = false; break;
 | 
			
		||||
  case '?':
 | 
			
		||||
  default: help(ARGERROR);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Argres process_args(int t_argc, char *t_argv[]) {
 | 
			
		||||
/**
 | 
			
		||||
 *  \brief Traite les arguments passés au processus
 | 
			
		||||
 *
 | 
			
		||||
 *  Les arguments passés au processus seront traités ici. Les arguments passés
 | 
			
		||||
 *  dans cette fonction ne subiront aucune modification. La fonction renvoie une
 | 
			
		||||
 *  structure \ref Argres contenant le nom de fichier d’entrée et de sortie
 | 
			
		||||
 *  ainsi qu’un booléen indiquant si le fichier d’entrée doit être compressé ou
 | 
			
		||||
 *  décompressé.
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[in] t_argc Nombre d’arguments reçus
 | 
			
		||||
 *  \param[in] t_argv Arguments reçus par le processus
 | 
			
		||||
 *  \return structure \ref Argres
 | 
			
		||||
 */
 | 
			
		||||
Argres process_args(const int t_argc, char *t_argv[]) {
 | 
			
		||||
  Argres res;
 | 
			
		||||
  res.input = NULL;
 | 
			
		||||
  res.output = NULL;
 | 
			
		||||
@ -57,18 +96,31 @@ Argres process_args(int t_argc, char *t_argv[]) {
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  \brief Fonction `main` lancée avec le processus
 | 
			
		||||
 *
 | 
			
		||||
 *  This function is launched with the process. It will analyze the arguments it
 | 
			
		||||
 *  received, and depending on them will either compress or uncompress the input
 | 
			
		||||
 *  file, or will throw an error and stop in case of incorrect arguments.
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[in] argc Nombre d’arguments reçus par le processus
 | 
			
		||||
 *  \param[in] argv Tableau des arguments reçus par le processus
 | 
			
		||||
 *  \return Code de status du processus
 | 
			
		||||
 */
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
  Argres argresults = process_args(argc, argv);
 | 
			
		||||
  if (argresults.input) {
 | 
			
		||||
    printf("input: %s\n", argresults.input);
 | 
			
		||||
  } else {
 | 
			
		||||
  if (NULL == argresults.input) {
 | 
			
		||||
    fprintf(stderr, "ERROR: no input file.");
 | 
			
		||||
    help(ARGERROR);
 | 
			
		||||
  }
 | 
			
		||||
  if (!argresults.output) {
 | 
			
		||||
    argresults.output = "output.fs";
 | 
			
		||||
  }
 | 
			
		||||
  printf("output: %s\n", argresults.output);
 | 
			
		||||
  printf("Compress? %s\n", (argresults.compress) ? "true" : "false");
 | 
			
		||||
  printf("input: %s\noutput: %s\n", argresults.input, argresults.output);
 | 
			
		||||
  if(argresults.compress) {
 | 
			
		||||
    puts("Compressing...");
 | 
			
		||||
  } else {
 | 
			
		||||
    puts("Uncompressing...");
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -194,7 +194,7 @@ int ImageLoadPPM(char *t_filename, Image *t_img) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  Ouvre le fichier image avec son nom de fichier passé par le paramètre
 | 
			
		||||
() *  Ouvre le fichier image avec son nom de fichier passé par le paramètre
 | 
			
		||||
 *  `filename` et y écrit les informations trouvées dans l’objet `img`.
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[in] filename Nom du fichier image à ouvrir
 | 
			
		||||
 | 
			
		||||
@ -141,3 +141,7 @@ void deleteZone(Zone_t t_self) {
 | 
			
		||||
  darrayDelete(t_self->segments);
 | 
			
		||||
  free(t_self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Pixel_t imgAt(Image_t t_img, int t_x, int t_y) {
 | 
			
		||||
  return (Pixel_t)darrayGet(t_img->pixels, t_x + t_y * t_img->x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -32,16 +32,6 @@
 | 
			
		||||
  printf
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/// Pas d’erreur
 | 
			
		||||
#define NOERROR 0
 | 
			
		||||
/// Constante pour les erreurs liées aux arguments
 | 
			
		||||
#define ARGERROR 1
 | 
			
		||||
/// Constante pour les erreurs liées à \ref darray_t
 | 
			
		||||
#define PTR_ERROR 2
 | 
			
		||||
/// Constante pour les erreurs liées à la lecture et écriture de fichiers
 | 
			
		||||
#define FILE_IO_ERROR 3
 | 
			
		||||
#define FILE_FORMAT_ERROR 4
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************/
 | 
			
		||||
/*                             STRUCT DECLARATION                            */
 | 
			
		||||
/*****************************************************************************/
 | 
			
		||||
@ -72,9 +62,9 @@ typedef Segment *Segment_t;
 | 
			
		||||
 *  dans un tableau dynamique \ref darray_t.
 | 
			
		||||
 */
 | 
			
		||||
struct Image {
 | 
			
		||||
  uint64_t x;       /*!< Largeur de l’image */
 | 
			
		||||
  uint64_t y;       /*!< Hauteur de l’image */
 | 
			
		||||
  darray_t pixels; /*!< Vecteur de pixels */
 | 
			
		||||
  uint64_t x;      /*!< Largeur de l’image */
 | 
			
		||||
  uint64_t y;      /*!< Hauteur de l’image */
 | 
			
		||||
  darray_t pixels; /*!< Vecteur à une dimention de pixels */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -122,20 +112,22 @@ struct Segment {
 | 
			
		||||
/*****************************************************************************/
 | 
			
		||||
 | 
			
		||||
/// \brief Création d’un nouveau pixel
 | 
			
		||||
Pixel_t newPixel(uint8_t r, uint8_t g, uint8_t b);
 | 
			
		||||
Pixel_t newPixel(uint8_t t_r, uint8_t t_g, uint8_t t_b);
 | 
			
		||||
/// \brief Destruction d’un pointeur de pixel
 | 
			
		||||
void deletePixel(Pixel_t self);
 | 
			
		||||
void deletePixel(Pixel_t t_self);
 | 
			
		||||
/// \brief Création d’une nouvelle image
 | 
			
		||||
Image_t newImage();
 | 
			
		||||
/// \brief Destructeur d’une image
 | 
			
		||||
void deleteImage(Image_t self);
 | 
			
		||||
void deleteImage(Image_t t_self);
 | 
			
		||||
/// \brief Constructeur d’un segment de couleur unie
 | 
			
		||||
Segment_t newSegment(uint16_t y, uint16_t xd, uint16_t xg);
 | 
			
		||||
Segment_t newSegment(uint16_t t_y, uint16_t t_xd, uint16_t t_xg);
 | 
			
		||||
/// \brief Destructeur d’un segment de couleur unie
 | 
			
		||||
void deleteSegment(Segment_t self);
 | 
			
		||||
void deleteSegment(Segment_t t_self);
 | 
			
		||||
/// \brief Constructeur de conteneur de zone
 | 
			
		||||
Zone_t newZone(uint8_t r, uint8_t g, uint8_t b);
 | 
			
		||||
Zone_t newZone(uint8_t t_r, uint8_t t_g, uint8_t t_b);
 | 
			
		||||
/// \brief Destructeur de conteneur de zone
 | 
			
		||||
void deleteZone(Zone_t self);
 | 
			
		||||
void deleteZone(Zone_t t_self);
 | 
			
		||||
/// \brief Renvoie un pixel aux coordonnées `(x, y)` dans une image
 | 
			
		||||
Pixel_t imgAt(Image_t t_img, int t_x, int t_y);
 | 
			
		||||
 | 
			
		||||
#endif /* UTILITIES_H */
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user