image_filtering.c
int write_image(char *img_filename, image *img)
{
	FILE *img_file = fopen(img_filename, "wb");
	if (img_file == NULL)
	{
		printf("Cannot open image %s\n", img_filename);
		return ERR_IO;
	}
	char header[100];
	sprintf(header, "P%d\n%d %d\n%d\n", img->type, img->width, img->height, img->maxval);
	fwrite(header, strlen(header), 1, img_file);
	if (img->type == 5) // grayscale
	{
		fwrite((img->gray_image), sizeof(gray_pixel) * img->width * img->height, 1, img_file);
		free(img->gray_image);
		img->gray_image = NULL;
	}
	else // color
	{
		fwrite((img->rgb_image), sizeof(rgb_pixel) * img->width * img->height, 1, img_file);
		free(img->rgb_image);
		img->rgb_image = NULL;
	}
	fclose(img_file);
	return STATUS_SUCCES;
}
// Write image to .pnm file
Write image to .pnm file
Write image to . pnm file
int write_image(char *img_filename, image *img)
{
	FILE *img_file = fopen(img_filename, "wb");
	if (img_file == NULL)
	{
		printf("Cannot open image %s\n", img_filename);
		return ERR_IO;
	}
	char header[100];
	sprintf(header, "P%d\n%d %d\n%d\n", img->type, img->width, img->height, img->maxval);
	fwrite(header, strlen(header), 1, img_file);
	if (img->type == 5) 
	{
		fwrite((img->gray_image), sizeof(gray_pixel) * img->width * img->height, 1, img_file);
		free(img->gray_image);
		img->gray_image = NULL;
	}
	else 
	{
		fwrite((img->rgb_image), sizeof(rgb_pixel) * img->width * img->height, 1, img_file);
		free(img->rgb_image);
		img->rgb_image = NULL;
	}
	fclose(img_file);
	return STATUS_SUCCES;
}
int write_image ( char * img_filename , image * img ) { FILE * img_file = fopen ( img_filename , " " ) ; if ( img_file == NULL ) { printf ( " \n " , img_filename ) ; return ERR_IO ; } char header [ 100 ] ; sprintf ( header , " \n \n \n " , img -> type , img -> width , img -> height , img -> maxval ) ; fwrite ( header , strlen ( header ) , 1 , img_file ) ; if ( img -> type == 5 ) { fwrite ( ( img -> gray_image ) , sizeof ( gray_pixel ) * img -> width * img -> height , 1 , img_file ) ; free ( img -> gray_image ) ; img -> gray_image = NULL ; } else { fwrite ( ( img -> rgb_image ) , sizeof ( rgb_pixel ) * img -> width * img -> height , 1 , img_file ) ; free ( img -> rgb_image ) ; img -> rgb_image = NULL ; } fclose ( img_file ) ; return STATUS_SUCCES ; }
Write image to .pnm file
Write image to . pnm file
// grayscale // color