Implement basic PPM image writer
This commit is contained in:
		
							
								
								
									
										22
									
								
								ppm.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								ppm.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | #include "ppm.h" | ||||||
|  | #include "aliases.h" | ||||||
|  | #include <stdio.h> | ||||||
|  | #include <string.h> | ||||||
|  |  | ||||||
|  | void write_p6_ppm(const char *filepath, u64 width, u64 height, Pixel *data) { | ||||||
|  |   FILE *fp = fopen(filepath, "wb"); | ||||||
|  |   if (!fp) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   char header[1024] = {0}; | ||||||
|  |   sprintf(header, "P6\n%lu %lu\n255\n", width, height); | ||||||
|  |  | ||||||
|  |   u64 length = strlen(header); | ||||||
|  |   fwrite(&header, length, 1, fp); | ||||||
|  |  | ||||||
|  |   u64 pixel_count = width * height; | ||||||
|  |   fwrite(data, sizeof(Pixel), pixel_count, fp); | ||||||
|  |  | ||||||
|  |   fclose(fp); | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user