Compare commits
No commits in common. "21a6d792d5db8fa36820426eee04637d7ebf02c1" and "f11bf3aa7139b8dfeeb087f10dc0cd1176117b0a" have entirely different histories.
21a6d792d5
...
f11bf3aa71
7
essai.c
7
essai.c
@ -50,11 +50,7 @@ if (verbosity) fimg_print_version(0);
|
||||
fimg_create(&fimgA, W, H, 3);
|
||||
fimg_create(&fimgB, W, H, 3);
|
||||
|
||||
fimg_clear(&fimgA);
|
||||
|
||||
fimg_drand48(&fimgB, 100.0);
|
||||
foo = fimg_dump_to_file(&fimgB, "B.fimg", 0);
|
||||
|
||||
fimg_timer_set(0);
|
||||
#define NBP 500
|
||||
for (foo=0; foo<NBP; foo++) {
|
||||
@ -63,12 +59,11 @@ for (foo=0; foo<NBP; foo++) {
|
||||
}
|
||||
fait_un_dessin(&fimgB);
|
||||
fimg_add(&fimgA, &fimgB, &fimgA);
|
||||
// fimg_mul(&fimgA, &fimgB, &fimgA);
|
||||
fimg_mul(&fimgA, &fimgB, &fimgA);
|
||||
}
|
||||
tb = fimg_timer_get(0);
|
||||
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
|
||||
foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0);
|
||||
foo = fimg_dump_to_file(&fimgA, "drand48.fimg", 0);
|
||||
|
||||
fimg_destroy(&fimgA);
|
||||
fimg_destroy(&fimgB);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* floatimg.h
|
||||
*/
|
||||
|
||||
#define FIMG_VERSION 74
|
||||
#define FIMG_VERSION 73
|
||||
|
||||
/*
|
||||
* in memory descriptor
|
||||
@ -46,7 +46,6 @@ int fimg_fileinfo(char *fname, int *datas);
|
||||
int fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b);
|
||||
int fimg_clear(FloatImg *fimg);
|
||||
int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b);
|
||||
int fimg_rgb_constant(FloatImg *head, float r, float g, float b);
|
||||
|
||||
|
||||
int fimg_images_compatible(FloatImg *a, FloatImg *b);
|
||||
|
@ -164,28 +164,6 @@ if ( ! fimg_type_is_valid(fimg->type) ) {
|
||||
size = fimg->width * fimg->height * fimg->type * sizeof(float);
|
||||
memset(fimg->R, 0, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_rgb_constant(FloatImg *head, float r, float g, float b)
|
||||
{
|
||||
int idx, size;
|
||||
|
||||
fprintf(stderr, ">>> %-25s ( %p %f %f %f )\n", __func__, head,
|
||||
r, g, b);
|
||||
|
||||
if (head->type != FIMG_TYPE_RGB) {
|
||||
return -21;
|
||||
}
|
||||
|
||||
size = head->width * head->height;
|
||||
|
||||
for (idx=0; idx<size; idx++) {
|
||||
head->R[idx] = r;
|
||||
head->G[idx] = g;
|
||||
head->B[idx] = b;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -47,24 +47,21 @@ return maxval;
|
||||
int fimg_meanvalues(FloatImg *head, float means[4])
|
||||
{
|
||||
int idx, surface;
|
||||
double accus[4];
|
||||
|
||||
surface = head->width * head->height;
|
||||
if (surface < 1) return -1;
|
||||
|
||||
memset(accus, 0, 4*sizeof(double));
|
||||
memset(means, 0, 4*sizeof(float));
|
||||
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
accus[0] += head->R[idx];
|
||||
means[0] += head->R[idx];
|
||||
if (head->type > 2) {
|
||||
accus[1] += head->G[idx];
|
||||
accus[2] += head->B[idx];
|
||||
means[1] += head->G[idx];
|
||||
means[2] += head->B[idx];
|
||||
}
|
||||
}
|
||||
|
||||
for (idx=0; idx<4; idx++) {
|
||||
means[idx] = (float)(accus[idx]/(double)surface);
|
||||
}
|
||||
for (idx=0; idx<4; idx++) means[idx] /= (float)surface;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -164,12 +164,10 @@ switch(head->type) {
|
||||
fprintf(fp, "%s\n%d %d\n", code, head->width, head->height);
|
||||
|
||||
if ( flags & 1 ) {
|
||||
fprintf(stderr, "%s using fval/count %f %d -> %f\n", __func__,
|
||||
head->fval, head->count,
|
||||
head->fval * head->count);
|
||||
fk = (head->fval * head->count) / 65535.0;
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "%s using fval/count %f %d -> %f\n",
|
||||
__func__,
|
||||
head->fval, head->count, fk);
|
||||
}
|
||||
fprintf(fp, "# fval/count %f %d\n", head->fval, head->count);
|
||||
}
|
||||
else {
|
||||
|
@ -46,7 +46,7 @@ int various_numbers_from_file(char *fname, int k)
|
||||
FloatImg fimg;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "------ numbers from '%s' :\n", fname);
|
||||
fprintf(stderr, "----------- numbers from '%s' :\n", fname);
|
||||
|
||||
foo = fimg_create_from_dump(fname, &fimg);
|
||||
if (foo) {
|
||||
|
@ -9,37 +9,19 @@
|
||||
int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
#define T_BLACK 1
|
||||
#define T_DRAND48 2
|
||||
#define T_GRAY 3
|
||||
typedef struct {
|
||||
int code;
|
||||
char *name;
|
||||
} Type;
|
||||
|
||||
Type types[] = {
|
||||
{ T_BLACK, "black" },
|
||||
{ T_DRAND48, "drand48" },
|
||||
{ T_GRAY, "gray" },
|
||||
{ T_GRAY, "grey" }
|
||||
};
|
||||
|
||||
#define T_BLACK 0
|
||||
#define T_DRAND48 1
|
||||
#define T_RGB_0 2
|
||||
static int get_type(char *name)
|
||||
{
|
||||
Type *type;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
||||
#endif
|
||||
|
||||
// #define TEST(str) ( ! strcmp(name, str) )
|
||||
|
||||
for (type = types; type->code; type++) {
|
||||
// printf("\t%-15s %d\n", type->name, type->code);
|
||||
if (!strcmp(name, type->name)) {
|
||||
return type->code;
|
||||
}
|
||||
}
|
||||
#define TEST(str) ( ! strcmp(name, str) )
|
||||
if TEST("black") return T_BLACK;
|
||||
if TEST("drand48") return T_DRAND48;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -47,12 +29,7 @@ return -1;
|
||||
static void help(int lj)
|
||||
{
|
||||
|
||||
puts("Usage:\tmkfimg [options] quux.fimg width height");
|
||||
|
||||
puts("\t-k N.N\tgive a float parameter");
|
||||
puts("\t-t bla\t\thowto make the pic");
|
||||
puts("\t\t\tblack, drand48...");
|
||||
puts("\t-v\tincrease verbosity");
|
||||
puts("Usage:\n\tmkfimg [options] quux.fimg width height\n");
|
||||
|
||||
if (verbosity) fimg_print_version(1);
|
||||
|
||||
@ -64,9 +41,8 @@ int main(int argc, char *argv[])
|
||||
int foo, opt;
|
||||
int width, height;
|
||||
char *fname;
|
||||
float fvalue = 0.01;
|
||||
int type = T_BLACK;
|
||||
char *tname = "wtf?";
|
||||
float fvalue = 0.00001;
|
||||
int type = 0;
|
||||
|
||||
FloatImg fimg;
|
||||
|
||||
@ -74,7 +50,7 @@ while ((opt = getopt(argc, argv, "hk:t:v")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h': help(0); break;
|
||||
case 'k': fvalue = atof(optarg); break;
|
||||
case 't': type = get_type(tname=optarg); break;
|
||||
case 't': type = get_type(optarg); break;
|
||||
case 'v': verbosity++; break;
|
||||
}
|
||||
}
|
||||
@ -90,11 +66,6 @@ if (3 != argc-optind) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (type < 0) {
|
||||
fprintf(stderr, "type '%s' is unknow\n", tname);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
fname = argv[optind];
|
||||
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
|
||||
|
||||
@ -105,15 +76,13 @@ srand48(getpid() ^ time(NULL));
|
||||
foo = fimg_create(&fimg, width, height, 3);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create floatimg -> %d\n", foo);
|
||||
exit(3);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
default:
|
||||
case T_BLACK: fimg_clear(&fimg); break;
|
||||
case T_DRAND48: fimg_drand48(&fimg, fvalue); break;
|
||||
case T_GRAY: fimg_rgb_constant(&fimg, fvalue, fvalue, fvalue);
|
||||
break;
|
||||
case T_DRAND48: fimg_drand48(&fimg, 1.0); break;
|
||||
}
|
||||
|
||||
foo = fimg_dump_to_file(&fimg, fname, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user