Fixed the indexing issue, but now the output ppm file is not valid

This commit is contained in:
Phuntsok Drak-pa 2018-11-27 12:47:28 +01:00
parent 96660f9bef
commit a88c108d41
No known key found for this signature in database
GPG Key ID: 9CB34B6827C66D22
1 changed files with 17 additions and 8 deletions

View File

@ -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;
}