#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "image.h"
void rgb2gray(s_image* img, s_image* img2) {
u_color col;
if (!isRGB(img) || !isGray(img2) || img->height != img2->height || img->width != img2->width) {
fprintf(stderr, "pas le bon format");
exit(EXIT_FAILURE);
}
for (int i = 0; i < img->height; i++) {
for (int j = 0; j < img->width; j++) {
col = getPixel(img->pixels, j, i);
col.rgb.red *= 0.299;
col.rgb.green *= 0.587;
col.rgb.blue *= 0.114;
printf("%d\n", col.rgb.blue);
setPixel(img2->pixels, j, i, col);
}
}
}
int main(void){
s_image* image;
s_image* image2;
image = readImage("image.ppm");
image2 = createImage(image->width, image->height, GRAY);
rgb2gray(image, image2);
writeImage("imageGray.ppm", image2);
freeImage(image);
freeImage(image2);
return EXIT_SUCCESS;
}