I'm trying to edit an image by multiplying the red component of each pixel by 10 and leaving the other components (green and blue) untouched. I'm not really sure how I'm supposed to edit the pixels one by one. I have this so far. I think there is something wrong with my ppm header as well. Is there a way to make a ppm header without specifying the bounds so that it conforms to the image you are putting in?
#include <stdlib.h>
#include <stdio.h>
#define PICTURE_FILE 1
#define MIN_ARGS 2
#define h 768
#define w 1024
void solve(FILE *in_picture, FILE *out_picture)
{
printf("P3 1024 768 255\n");
double r, g, b, row, col;
int ret = fscanf(in_picture, "%lf %lf %lf ", &r, &g, &b);
while(ret != EOF)
{
for(row=1; row <= h; row++)
{
for(col=1; col <= w; col++)
{
fprintf(out_picture, "%lf %lf %lf ", r*10 , g, b);
}
ret = fscanf(in_picture, "%lf %lf %lf ", &r, &g, &b);
}
}
}
FILE *open_file(const char name[], const char mode[])
{
FILE *file = fopen(name, mode);
if(file == NULL)
{
perror(name);
exit(1);
}
return file;
}
void check_args(int argc, char *argv[])
{
if(argc < MIN_ARGS)
{
fprintf(stderr, "%s: not enough arguments \n", argv[0]);
exit(1);
}
}
int main(int argc, char *argv[])
{
check_args(argc, argv);
FILE *in_picture = open_file(argv[PICTURE_FILE], "r");
FILE *out_picture = open_file("hidden.ppm", "w");
solve(in_picture, out_picture);
fclose(in_picture);
fclose(out_picture);
}