FloatImg/lib/t.c

89 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* ---------------------------------------------------------------- */
int petit_dessin(FloatImg *img)
{
int x, y;
float r, g, b;
for (y=0; y<img->height; y++) {
r = (float)y / (float)img->height;
for (x=0; x<img->width; x++) {
g = (float)x / (float)img->width;
b = 0.0;;
fimg_plot_rgb(img, x, y, r, g, b);
}
}
return -1;
}
/* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname)
{
int foo;
FloatImg gray;
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname);
foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY);
if (foo) {
fprintf(stderr, "%s : err %d on fimg create\n", __func__, foo);
exit(1);
}
foo = fimg_mk_gray_from(picz, &gray, 0);
if (foo) {
fprintf(stderr, "%s : err %d on fimg mk_gray_from\n", __func__, foo);
exit(1);
}
foo = fimg_save_as_pnm(&gray, outname, 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1);
}
fimg_destroy(&gray);
return 0;
}
/* ---------------------------------------------------------------- */
#define W 2048
#define H 2048
int main(int argc, char *argv[])
{
int foo;
FloatImg dessin, noise, result;
verbosity = 1;
fimg_print_version(1);
foo = fimg_create(&dessin, W, H, 3);
petit_dessin(&dessin);
foo = fimg_create(&noise, W, H, 3);
fimg_drand48(&noise, 0.1);
foo = fimg_create(&result, W, H, 3);
foo = fimg_mul(&dessin, &noise, &result);
essai_2gray(&result, "gray.pnm");
fimg_destroy(&dessin), fimg_destroy(&noise), fimg_destroy(&result);
return 0;
}