2019-03-03 16:22:55 +01:00
|
|
|
/*
|
|
|
|
testing some random funcs.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-04-03 12:09:04 +02:00
|
|
|
#include <unistd.h>
|
2019-03-03 16:22:55 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "floatimg.h"
|
|
|
|
|
2019-04-03 12:09:04 +02:00
|
|
|
int verbosity;
|
|
|
|
|
2019-03-03 16:22:55 +01:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int add(FloatImg *a, FloatImg *b)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int offset;
|
|
|
|
double tb;
|
|
|
|
|
|
|
|
fimg_timer_set(0);
|
|
|
|
|
|
|
|
for (x=0; x<a->width; x++) {
|
|
|
|
for (y=0; y<a->height; y++) {
|
|
|
|
offset = x + (y * a->width);
|
|
|
|
a->R[offset] += b->R[offset];
|
|
|
|
a->G[offset] += b->G[offset];
|
|
|
|
a->B[offset] += b->B[offset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tb = fimg_timer_get(0);
|
|
|
|
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void fait_un_dessin(char *fname)
|
|
|
|
{
|
|
|
|
FloatImg dessin;
|
|
|
|
double tb;
|
|
|
|
|
|
|
|
puts("");
|
|
|
|
fimg_timer_set(0);
|
|
|
|
fimg_create(&dessin, 3200, 2400, 3);
|
|
|
|
fimg_draw_something(&dessin);
|
|
|
|
fimg_dump_to_file(&dessin, "dessin.fimg", 0);
|
|
|
|
fimg_destroy(&dessin);
|
|
|
|
tb = fimg_timer_get(0);
|
|
|
|
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
|
|
|
|
|
|
|
|
puts("");
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-04-03 12:09:04 +02:00
|
|
|
int parse_WxH(char *str, int *pw, int *ph)
|
|
|
|
{
|
|
|
|
// char *ptr;
|
|
|
|
int foo, w, h;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__,
|
|
|
|
str, pw, ph);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = sscanf(str, "%dx%d", &w, &h);
|
|
|
|
if (2 != foo) {
|
|
|
|
fprintf(stderr, "%s : arg '%s' is invalid\n", __func__, str);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pw = w; *ph = h;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void help(int k)
|
|
|
|
{
|
|
|
|
puts("Options :");
|
|
|
|
puts("\t-d WxH\timage size");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-03-03 16:22:55 +01:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FloatImg fimgA, fimgB;
|
2019-04-03 12:09:04 +02:00
|
|
|
int foo, opt;
|
|
|
|
int W = 800, H = 600;
|
2019-03-03 16:22:55 +01:00
|
|
|
double tb;
|
|
|
|
|
2019-04-03 12:09:04 +02:00
|
|
|
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'd': parse_WxH(optarg, &W, &H);
|
|
|
|
break;
|
|
|
|
case 'h': help(0); break;
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
|
2019-04-03 12:09:04 +02:00
|
|
|
if (verbosity) fimg_print_version(0);
|
2019-03-03 16:22:55 +01:00
|
|
|
|
|
|
|
fimg_create(&fimgA, W, H, 3);
|
|
|
|
fimg_create(&fimgB, W, H, 3);
|
|
|
|
|
|
|
|
fimg_timer_set(0);
|
|
|
|
fimg_drand48(&fimgB, 100.0);
|
2019-04-03 12:09:04 +02:00
|
|
|
fimg_drand48(&fimgA, 100.0);
|
|
|
|
add(&fimgA, &fimgB);
|
2019-03-03 16:22:55 +01:00
|
|
|
tb = fimg_timer_get(0);
|
|
|
|
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
|
2019-04-03 12:09:04 +02:00
|
|
|
foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0);
|
2019-03-03 16:22:55 +01:00
|
|
|
|
|
|
|
fimg_destroy(&fimgA);
|
|
|
|
fimg_destroy(&fimgB);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|