fixed compressed file reading, now must fix data conversion
This commit is contained in:
parent
c82a00fbe0
commit
96660f9bef
@ -142,13 +142,11 @@ void write_segments(FILE *t_output, darray *t_segments) {
|
|||||||
fwrite(&nb_segments, sizeof(nb_segments), 1, t_output);
|
fwrite(&nb_segments, sizeof(nb_segments), 1, t_output);
|
||||||
for (j = 0; j < darraySize(t_segments); ++j) {
|
for (j = 0; j < darraySize(t_segments); ++j) {
|
||||||
segment = darrayGet(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 l’image en abscisse et ordonnées, les deux sous forme de
|
* Écrit la taille de l’image en abscisse et ordonnées, les deux sous forme de
|
||||||
* `uint64_t` puis le nombre de zones sous forme de `uint64_t`. Puis, pour
|
* `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
|
* chaque zone son code couleur composé de trois `uint8_t` successifs
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
* \param[out] t_zone La zone dans laquelle stocker les \ref Segment
|
* \param[out] t_zone La zone dans laquelle stocker les \ref Segment
|
||||||
*/
|
*/
|
||||||
void read_segments(FILE *t_file, Zone *t_zone) {
|
void read_segments(FILE *t_file, Zone *t_zone) {
|
||||||
uint32_t nb_segments, i;
|
uint64_t nb_segments, i;
|
||||||
Segment *segment;
|
Segment *segment;
|
||||||
fread(&nb_segments, sizeof(nb_segments), 1, t_file);
|
fread(&nb_segments, sizeof(nb_segments), 1, t_file);
|
||||||
for(i = 0; i < nb_segments; ++i) {
|
for(i = 0; i < nb_segments; ++i) {
|
||||||
segment = newSegment(0, 0);
|
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);
|
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
|
* \param[out] t_zones Tableau dynamique contenant les zones lues
|
||||||
*/
|
*/
|
||||||
void read_compressed_zones(FILE *t_file, darray *t_zones) {
|
void read_compressed_zones(FILE *t_file, darray *t_zones) {
|
||||||
uint32_t nb_zones, i;
|
uint64_t nb_zones, i;
|
||||||
Zone *zone;
|
Zone *zone;
|
||||||
/* read number of zones */
|
/* read number of zones */
|
||||||
fread(&nb_zones, sizeof(nb_zones), 1, t_file);
|
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) {
|
void read_compressed_file_meta(FILE *t_file, Image *t_img) {
|
||||||
/* read sizeX and sizeY at once */
|
/* read sizeX and sizeY at once */
|
||||||
fread(&t_img->sizeX, sizeof(t_img->sizeX), 2, t_file);
|
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) {
|
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;
|
t_output_file = DEFAULT_UNCOMPRESSED_FILE;
|
||||||
}
|
}
|
||||||
img = newImage();
|
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_file_meta(input_file, img);
|
||||||
read_compressed_zones(input_file, zones);
|
read_compressed_zones(input_file, zones);
|
||||||
|
puts("===== Read compressed data, now converting zones to ppm data =====");
|
||||||
data = zones_to_data(zones, img);
|
data = zones_to_data(zones, img);
|
||||||
|
puts("===== Data converted, now saving the PPM file =====");
|
||||||
imageSavePPM(t_output_file, img, data);
|
imageSavePPM(t_output_file, img, data);
|
||||||
|
puts("===== Saved output image, freeing up memory =====");
|
||||||
|
fclose(input_file);
|
||||||
/* free memory */
|
/* free memory */
|
||||||
for(i = 0; i < darraySize(zones); ++i) {
|
for(i = 0; i < darraySize(zones); ++i) {
|
||||||
Zone *zone = darrayGet(zones, i);
|
Zone *zone = darrayGet(zones, i);
|
||||||
|
@ -89,8 +89,8 @@ struct Zone {
|
|||||||
* à son extrême droite et à son extrême gauche.
|
* à son extrême droite et à son extrême gauche.
|
||||||
*/
|
*/
|
||||||
struct Segment {
|
struct Segment {
|
||||||
uint32_t right_limit; /*!< extrême droit du segment */
|
|
||||||
uint32_t left_limit; /*!< extrême gauche du segment */
|
uint32_t left_limit; /*!< extrême gauche du segment */
|
||||||
|
uint32_t right_limit; /*!< extrême droit du segment */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user