c - Editing an image in ppm format -
i'm trying edit image multiplying red component of each pixel 10 , leaving other components (green , blue) untouched. i'm not sure how i'm supposed edit pixels 1 one. have far. think there wrong ppm header well. there way make ppm header without specifying bounds conforms image 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); }
Comments
Post a Comment