Compare commits

..

8 Commits

Author SHA1 Message Date
tth
21a6d792d5 do not be verbose on that... 2019-09-29 00:12:31 +02:00
tth
adc08ce777 better parsing of type, and add on "gray" type 2019-09-29 00:11:18 +02:00
tth
bacf6ecd94 moving debug 2019-09-29 00:09:59 +02:00
tth
d672d02173 bla 2019-09-29 00:06:05 +02:00
tth
6c3b33dad1 add a new function - part 2 2019-09-28 23:55:45 +02:00
tth
4945bb1c53 add a new function 2019-09-28 23:54:14 +02:00
tth
252d5c62e0 fix a critical precision issue 2019-09-28 23:45:51 +02:00
tth
98043bbe0c update -h verbiage 2019-09-27 12:25:09 +02:00
7 changed files with 87 additions and 23 deletions

View File

@ -50,7 +50,11 @@ 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++) {
@ -59,11 +63,12 @@ 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);

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 73
#define FIMG_VERSION 74
/*
* in memory descriptor
@ -46,6 +46,7 @@ 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);

View File

@ -164,6 +164,28 @@ 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;
}
/* --------------------------------------------------------------------- */

View File

@ -47,21 +47,24 @@ 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(means, 0, 4*sizeof(float));
memset(accus, 0, 4*sizeof(double));
for (idx=0; idx<surface; idx++) {
means[0] += head->R[idx];
accus[0] += head->R[idx];
if (head->type > 2) {
means[1] += head->G[idx];
means[2] += head->B[idx];
accus[1] += head->G[idx];
accus[2] += head->B[idx];
}
}
for (idx=0; idx<4; idx++) means[idx] /= (float)surface;
for (idx=0; idx<4; idx++) {
means[idx] = (float)(accus[idx]/(double)surface);
}
return 0;
}

View File

@ -164,10 +164,12 @@ 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 {

View File

@ -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) {

View File

@ -9,19 +9,37 @@
int verbosity;
/* --------------------------------------------------------------------- */
#define T_BLACK 0
#define T_DRAND48 1
#define T_RGB_0 2
#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" }
};
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) )
if TEST("black") return T_BLACK;
if TEST("drand48") return T_DRAND48;
// #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;
}
}
return -1;
}
@ -29,7 +47,12 @@ return -1;
static void help(int lj)
{
puts("Usage:\n\tmkfimg [options] quux.fimg width height\n");
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");
if (verbosity) fimg_print_version(1);
@ -41,8 +64,9 @@ int main(int argc, char *argv[])
int foo, opt;
int width, height;
char *fname;
float fvalue = 0.00001;
int type = 0;
float fvalue = 0.01;
int type = T_BLACK;
char *tname = "wtf?";
FloatImg fimg;
@ -50,7 +74,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(optarg); break;
case 't': type = get_type(tname=optarg); break;
case 'v': verbosity++; break;
}
}
@ -66,6 +90,11 @@ 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]);
@ -76,13 +105,15 @@ srand48(getpid() ^ time(NULL));
foo = fimg_create(&fimg, width, height, 3);
if (foo) {
fprintf(stderr, "create floatimg -> %d\n", foo);
exit(1);
exit(3);
}
switch(type) {
default:
case T_BLACK: fimg_clear(&fimg); break;
case T_DRAND48: fimg_drand48(&fimg, 1.0); break;
case T_DRAND48: fimg_drand48(&fimg, fvalue); break;
case T_GRAY: fimg_rgb_constant(&fimg, fvalue, fvalue, fvalue);
break;
}
foo = fimg_dump_to_file(&fimg, fname, 0);