fixed compressed file reading, now must fix data conversion

This commit is contained in:
Phuntsok Drak-pa 2018-11-27 10:38:11 +01:00
parent c82a00fbe0
commit 96660f9bef
No known key found for this signature in database
GPG Key ID: 9CB34B6827C66D22
3 changed files with 10 additions and 10 deletions

View File

@ -142,13 +142,11 @@ void write_segments(FILE *t_output, darray *t_segments) {
fwrite(&nb_segments, sizeof(nb_segments), 1, t_output);
for (j = 0; j < darraySize(t_segments); ++j) {
segment = darrayGet(t_segments, j);
fwrite(&segment->right_limit, sizeof(Segment), 1, t_output);
fwrite(&segment->left_limit, sizeof(Segment), 1, t_output);
}
}
/**
* \brief function description
*
* Écrit la taille de limage en abscisse et ordonnées, les deux sous forme de
* `uint64_t` puis le nombre de zones sous forme de `uint64_t`. Puis, pour
* chaque zone son code couleur composé de trois `uint8_t` successifs

View File

@ -19,12 +19,12 @@
* \param[out] t_zone La zone dans laquelle stocker les \ref Segment
*/
void read_segments(FILE *t_file, Zone *t_zone) {
uint32_t nb_segments, i;
uint64_t nb_segments, i;
Segment *segment;
fread(&nb_segments, sizeof(nb_segments), 1, t_file);
for(i = 0; i < nb_segments; ++i) {
segment = newSegment(0, 0);
fread(&segment->left_limit, sizeof(segment->left_limit), 2, t_file);
fread(&segment->left_limit, sizeof(Segment), 1, t_file);
darrayPushBack(t_zone->segments, segment);
}
}
@ -38,7 +38,7 @@ void read_segments(FILE *t_file, Zone *t_zone) {
* \param[out] t_zones Tableau dynamique contenant les zones lues
*/
void read_compressed_zones(FILE *t_file, darray *t_zones) {
uint32_t nb_zones, i;
uint64_t nb_zones, i;
Zone *zone;
/* read number of zones */
fread(&nb_zones, sizeof(nb_zones), 1, t_file);
@ -64,7 +64,6 @@ void read_compressed_zones(FILE *t_file, darray *t_zones) {
void read_compressed_file_meta(FILE *t_file, Image *t_img) {
/* read sizeX and sizeY at once */
fread(&t_img->sizeX, sizeof(t_img->sizeX), 2, t_file);
DEBUG { printf("X: %ld\tY: %ld\n", t_img->sizeX, t_img->sizeY); }
}
uint8_t *zones_to_data(darray *t_zones, Image *t_img) {
@ -112,12 +111,15 @@ void uncompress(const char *t_input_file, const char *t_output_file) {
t_output_file = DEFAULT_UNCOMPRESSED_FILE;
}
img = newImage();
input_file = get_file(t_input_file, "wb");
input_file = get_file(t_input_file, "rb");
read_compressed_file_meta(input_file, img);
read_compressed_zones(input_file, zones);
puts("===== Read compressed data, now converting zones to ppm data =====");
data = zones_to_data(zones, img);
puts("===== Data converted, now saving the PPM file =====");
imageSavePPM(t_output_file, img, data);
puts("===== Saved output image, freeing up memory =====");
fclose(input_file);
/* free memory */
for(i = 0; i < darraySize(zones); ++i) {
Zone *zone = darrayGet(zones, i);

View File

@ -89,8 +89,8 @@ struct Zone {
* à son extrême droite et à son extrême gauche.
*/
struct Segment {
uint32_t right_limit; /*!< extrême droit du segment */
uint32_t left_limit; /*!< extrême gauche du segment */
uint32_t right_limit; /*!< extrême droit du segment */
};
/*****************************************************************************/