From a88c108d41080bf4e2210e549a23082238c50520 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Tue, 27 Nov 2018 12:47:28 +0100 Subject: [PATCH] Fixed the indexing issue, but now the output ppm file is not valid --- src/uncompress.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/uncompress.c b/src/uncompress.c index 5501c7a..893a93a 100644 --- a/src/uncompress.c +++ b/src/uncompress.c @@ -67,30 +67,39 @@ void read_compressed_file_meta(FILE *t_file, Image *t_img) { } uint8_t *zones_to_data(darray *t_zones, Image *t_img) { - uint64_t nb_zones, nb_segments, i, j, k, left_limit, right_limit; + uint64_t nb_zones, nb_segments, zoneID, segmentID, k, left_limit, right_limit; uint8_t *data, red, green, blue; Zone *current_zone; Segment *current_segment; - data = (uint8_t *)malloc(sizeof(uint8_t) * t_img->sizeX * t_img->sizeX * 3); + data = (uint8_t *)malloc(sizeof(uint8_t) * t_img->sizeX * t_img->sizeY * 3); + printf("data = (uint8_t *)malloc(%zu * %zu * %zu * 3); /* (%zu) */\n", + sizeof(uint8_t), t_img->sizeX, t_img->sizeY, + sizeof(uint8_t) * t_img->sizeX * t_img->sizeY * 3); nb_zones = darraySize(t_zones); - for(i = 0; i < nb_zones; ++i) { - current_zone = darrayGet(t_zones, i); + for (zoneID = 0; zoneID < nb_zones; ++zoneID) { + printf("Accessing t_zone[%lu]...\n", zoneID); + current_zone = darrayGet(t_zones, zoneID); red = current_zone->red; green = current_zone->green; blue = current_zone->blue; nb_segments = darraySize(current_zone->segments); - for(j = 0; j < nb_segments; ++j) { - current_segment = darrayGet(current_zone->segments, j); + for (segmentID = 0; segmentID < nb_segments; ++segmentID) { + printf("\tAccessing segments[%lu]...\n", segmentID); + current_segment = darrayGet(current_zone->segments, segmentID); left_limit = current_segment->left_limit; right_limit = current_segment->right_limit; - for(k = left_limit; k < right_limit; ++k) { + for (k = left_limit; k < right_limit; ++k) { + printf("\t\tAccessing data[%lu], data[%lu] and data[%lu]... ", k * 3, + k * 3 + 1, k * 3 + 2); data[k * 3] = red; data[k * 3 + 1] = green; data[k * 3 + 2] = blue; + puts("Done."); } + puts("\tDone."); } + puts("Done."); } - return data; }