Fixed ppm format, now creates image identical to original image
This commit is contained in:
		
							parent
							
								
									a88c108d41
								
							
						
					
					
						commit
						7d99a626e1
					
				@ -212,7 +212,7 @@ void imageSavePPM(const char *t_filename, Image *t_img, uint8_t *t_data) {
 | 
			
		||||
  /* write the header file */
 | 
			
		||||
  fprintf(fp, "P6\n");                                  /* image format */
 | 
			
		||||
  fprintf(fp, "# Created by %s\n", CREATOR);            /* comments */
 | 
			
		||||
  fprintf(fp, "%lu %lu\n", t_img->sizeY, t_img->sizeY); /* image size */
 | 
			
		||||
  fprintf(fp, "%lu %lu\n", t_img->sizeX, t_img->sizeY); /* image size */
 | 
			
		||||
  fprintf(fp, "%d\n", RGB_COMPONENT_COLOR); /* rgb component depth */
 | 
			
		||||
  fwrite(t_data, (size_t)1, (size_t)(3 * t_img->sizeX * t_img->sizeY), fp);
 | 
			
		||||
  free(t_data);
 | 
			
		||||
 | 
			
		||||
@ -72,33 +72,23 @@ uint8_t *zones_to_data(darray *t_zones, Image *t_img) {
 | 
			
		||||
  Zone *current_zone;
 | 
			
		||||
  Segment *current_segment;
 | 
			
		||||
  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 (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 (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) {
 | 
			
		||||
        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;
 | 
			
		||||
}
 | 
			
		||||
@ -123,11 +113,8 @@ void uncompress(const char *t_input_file, const char *t_output_file) {
 | 
			
		||||
  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) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user