From 87dfa5b2a66b9fb7ebf7fcbbaf6a3d63369214f9 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Fri, 23 Nov 2018 10:31:47 +0100 Subject: [PATCH] Debug prints now only in debug builds --- src/common.c | 23 ++++++++++++----------- src/main.c | 4 +++- src/ppm.c | 4 +++- src/utilities.c | 4 +++- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/common.c b/src/common.c index 97c0938..ca30c08 100644 --- a/src/common.c +++ b/src/common.c @@ -106,24 +106,25 @@ darray* imgToZones(Image* t_img) { } void compress(const char *input_file) { - Image* img; + Image *img; darray *zones; img = newImage(); imageLoadPPM(input_file, img); zones = imgToZones(img); - printf("Detected %zu zones\n", darraySize(zones)); - for(size_t i = 0; i < darraySize(zones); ++i) { - Zone* zone = darrayGet(zones, i); - printf("\n=== Zone %zu (%d %d %d) ===\n", i, zone->r, zone->g, zone->b); - for(size_t j = 0; j < darraySize(zone->segments); ++j) { - Segment* segm = darrayGet(zone->segments, j); - printf("[%d: %d, %d]\t", segm->y, segm->xg, segm->xd); + /* print segments for debug ************************************************/ + DEBUG { + printf("Detected %zu zones\n", darraySize(zones)); + for (size_t i = 0; i < darraySize(zones); ++i) { + Zone *zone = darrayGet(zones, i); + printf("\n=== Zone %zu (%d %d %d) ===\n", i, zone->r, zone->g, zone->b); + for (size_t j = 0; j < darraySize(zone->segments); ++j) { + Segment *segm = darrayGet(zone->segments, j); + printf("[%zu: %d, %d]\t", segm->xg / img->x, segm->xg, segm->xd); + } } + printf("\n"); } - printf("\n"); - deleteImage(img); - printf("test\n"); } diff --git a/src/main.c b/src/main.c index 4f85229..c41c88b 100644 --- a/src/main.c +++ b/src/main.c @@ -122,7 +122,9 @@ int main(int argc, char **argv) { fprintf(stderr, "ERROR: no input file."); help(ARGERROR); } - printf("input: %s\noutput: %s\n", argresults.input, argresults.output); + DEBUG { + printf("input: %s\noutput: %s\n", argresults.input, argresults.output); + } if(argresults.compress) { compress(argresults.input); } else { diff --git a/src/ppm.c b/src/ppm.c index 0b20f0a..54119ba 100644 --- a/src/ppm.c +++ b/src/ppm.c @@ -111,7 +111,9 @@ unsigned long read_data(FILE *t_fp, Image *t_img, unsigned char **t_data, unsigned long size; /* allocation memoire */ size = t_img->x * t_img->y * 3; - printf("Size image %lu %lu => %lu\n", t_img->x, t_img->y, size); + DEBUG { + printf("Size image %lu %lu => %lu\n", t_img->x, t_img->y, t_img->x * t_img->y); + } *t_data = (unsigned char *)malloc((size_t)size * sizeof(unsigned char)); assert(*t_data); /* read pixel data from file */ diff --git a/src/utilities.c b/src/utilities.c index bb49a12..7a81042 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -63,7 +63,9 @@ Image *newImage() { * \param[in] self Conteneur d’image à détruire */ void deleteImage(Image *t_self) { - printf("deleted all pixels\n"); + DEBUG { + printf("deleted all pixels\n"); + } darrayDelete(t_self->pixels); free(t_self); }