Compare commits

..

2 Commits

Author SHA1 Message Date
tth
2aabc8b26b commit du soir, espoir 2019-09-10 01:31:48 +02:00
tth
a7392df682 cosmetic change 2019-09-09 17:58:10 +02:00
8 changed files with 144 additions and 51 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 71 #define FIMG_VERSION 72
/* /*
* in memory descriptor * in memory descriptor
@ -47,6 +47,8 @@ int fimg_clear(FloatImg *fimg);
int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b); int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b);
int fimg_images_compatible(FloatImg *a, FloatImg *b);
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef); int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef);
/* 'operats' module */ /* 'operats' module */
@ -69,11 +71,12 @@ int fimg_fileinfos(char *fname, int *datas);
int fimg_dump_to_file(FloatImg *head, char *fname, int notused); int fimg_dump_to_file(FloatImg *head, char *fname, int notused);
int fimg_create_from_dump(char *fname, FloatImg *head); int fimg_create_from_dump(char *fname, FloatImg *head);
/* mathematics oprations */ /* mathematics operations */
float fimg_get_maxvalue(FloatImg *head); float fimg_get_maxvalue(FloatImg *head);
int fimg_meanvalues(FloatImg *head, float means[4]); int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head); int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value); void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
void fimg_drand48(FloatImg *fi, float kmul); void fimg_drand48(FloatImg *fi, float kmul);
/* various funcs modules */ /* various funcs modules */

View File

@ -2,10 +2,10 @@
# building the base library # building the base library
# #
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o \ fimg-timers.o operators.o fimg-2gray.o \
interpolate.o interpolate.o fimg-compare.o
DEPS = Makefile ../floatimg.h DEPS = Makefile ../floatimg.h
@ -25,6 +25,9 @@ t: t.c ../libfloatimg.a $(DEPS)
fimg-core.o: fimg-core.c $(DEPS) fimg-core.o: fimg-core.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
fimg-compare.o: fimg-compare.c $(DEPS)
gcc $(COPT) -c $<
fimg-2gray.o: fimg-2gray.c $(DEPS) fimg-2gray.o: fimg-2gray.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

40
lib/fimg-compare.c Normal file
View File

@ -0,0 +1,40 @@
/*
* fimg-core.c
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "string.h"
#include "../floatimg.h"
extern int verbosity; /* must be declared around main() */
/* ---------------------------------------------------------------- */
int fimg_images_compatible(FloatImg *a, FloatImg *b)
{
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, a, b);
#endif
if (a->type != b->type) {
if (verbosity) fprintf(stderr, "%p %p != type\n", a, b);
return -10;
}
if (a->width != b->width) {
if (verbosity) fprintf(stderr, "%p %p != width\n", a, b);
return -11;
}
if (a->height != b->height) {
if (verbosity) fprintf(stderr, "%p %p != height\n", a, b);
return -12;
}
return 0;
}
/* ---------------------------------------------------------------- */

View File

@ -64,12 +64,12 @@ if( ! fimg_type_is_valid(head->type) ) {
return -1; return -1;
} }
printf(" type %d %s\n", head->type, fimg_str_type(head->type)); printf(" type %d %s\n", head->type, fimg_str_type(head->type));
printf(" dims %d x %d\n", printf(" dims %d x %d\n",
head->width, head->height); head->width, head->height);
printf(" fval/count %f %d\n", head->fval, head->count); printf(" fval/count %f %d\n", head->fval, head->count);
printf(" pixels@ %p %p %p %p\n", printf(" pixels@ %p %p %p %p\n",
head->R, head->G, head->B, head->A); head->R, head->G, head->B, head->A);
return 0; return 0;

View File

View File

@ -103,11 +103,30 @@ nbre = fi->width * fi->height * fi->type;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre); fprintf(stderr, "%s, nbre is %d\n", __func__, nbre);
#endif #endif
for (idx=0; idx<nbre; nbre++) { for (idx=0; idx<nbre; idx++) {
fi->R[idx] += value; fi->R[idx] += value;
} }
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
void fimg_mul_cste(FloatImg *fi, float value)
{
int nbre, idx;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return;
}
nbre = fi->width * fi->height * fi->type;
// #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre);
// #endif
for (idx=0; idx<nbre; idx++) {
fi->R[idx] *= value;
}
}
/* ---------------------------------------------------------------- */
/* Warning: this function is _very_ slow */ /* Warning: this function is _very_ slow */
void fimg_drand48(FloatImg *fi, float kmul) void fimg_drand48(FloatImg *fi, float kmul)
{ {

View File

@ -1,3 +1,6 @@
/*
* interpolate.c
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -12,37 +15,53 @@ int verbosity;
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef) static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{ {
return -1;
}
/* ---------------------------------------------------------------- */
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
int picsize, idx; int picsize, idx;
if (FIMG_TYPE_RGB != s1->type) { picsize = d->width * d->height;
fprintf(stderr, "%s : bad src 1 type %d on %p\n", __func__,
s1->type, s1);
return -8;
}
if (FIMG_TYPE_RGB != s2->type) {
fprintf(stderr, "%s : bad src 2 type %d on %p\n", __func__,
s2->type, s2);
return -8;
}
if (FIMG_TYPE_RGB != d->type) {
fprintf(stderr, "%s : bad dst type %d on %p\n", __func__,
d->type, d);
return -9;
}
picsize = d->width * d->height * 3;
for (idx=0; idx<picsize; idx++) { for (idx=0; idx<picsize; idx++) {
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]); d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
}
return 0;
}
/* ---------------------------------------------------------------- */
static int rgb_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
int picsize, idx;
picsize = d->width * d->height * 3; /* rude hack ? */
for (idx=0; idx<picsize; idx++) {
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
}
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
int foo;
foo = fimg_images_compatible(s1, s2);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
foo = fimg_images_compatible(s1, d);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
switch (s1->type) {
case FIMG_TYPE_GRAY:
gray_interpolate(s1, s2, d, coef); break;
case FIMG_TYPE_RGB:
rgb_interpolate(s1, s2, d, coef); break;
default:
fprintf(stderr, "%s, %d is a bad type\n", __func__, s1->type);
return -18;
} }
return 0; return 0;

41
lib/t.c
View File

@ -72,56 +72,65 @@ foo = fimg_create(&dessin, W, H, 3);
petit_dessin(&dessin); petit_dessin(&dessin);
foo = fimg_create(&noise, W, H, 3); foo = fimg_create(&noise, W, H, 3);
fimg_drand48(&noise, 0.1); fimg_drand48(&noise, 0.1);
****/ ****/
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#define W 320 #define W 320
#define H 240 #define H 240
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, idx; int foo, idx, opt;
float coef; float coef;
FloatImg dessin, noise, result; FloatImg dessin, noise, result;
char outname[100]; char outname[100];
int gray = 0;
int nb_img = 42;
verbosity = 1; while ((opt = getopt(argc, argv, "gn:v")) != -1) {
switch(opt) {
case 'g': gray++; break;
case 'n': nb_img=atoi(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) fimg_print_version(0);
fimg_print_version(1);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &dessin); foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &dessin);
if (foo) { if (foo) {
fprintf(stderr, "s1 load err %d\n", foo); fprintf(stderr, "s1 load err %d\n", foo);
exit(1); exit(1);
} }
fimg_describe(&dessin, "s1 dessin"); if (verbosity) fimg_describe(&dessin, "s1 dessin");
fimg_to_gray(&dessin); if (gray) fimg_to_gray(&dessin);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise); foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise);
if (foo) { if (foo) {
fprintf(stderr, "s2 load err %d\n", foo); fprintf(stderr, "s2 load err %d\n", foo);
exit(1); exit(1);
} }
fimg_describe(&noise, "s2 noise"); if (verbosity) fimg_describe(&noise, "s2 noise");
fimg_mul_cste(&noise, 0.50);
if (gray) fimg_to_gray(&noise);
foo = fimg_create(&result, W, H, 3); foo = fimg_create(&result, W, H, 3);
if (verbosity) fimg_describe(&result, "d result");
#define NBRE 20 fprintf(stderr, "running for %d picz\n", nb_img);
for (idx=0; idx<NBRE; idx++) {
coef = (float)idx / (float)NBRE;
coef = (0.5-0.5*cos( 3.141592654*coef));
for (idx=0; idx<nb_img; idx++) {
coef = (float)idx / (float)nb_img;
// coef = (0.5-0.5*cos(4*3.141592654*coef));
foo = fimg_interpolate(&dessin, &noise, &result, coef); foo = fimg_interpolate(&dessin, &noise, &result, coef);
printf("%6d %9.6f\n", idx, coef); printf("%6d %9.6f\n", idx, coef);
// fimg_to_gray(&result);
sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx); sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx);
foo = fimg_save_as_pnm(&result, outname, 0); foo = fimg_save_as_pnm(&result, outname, 0);
} }
// essai_2gray(&result, "gray.pnm");
/* yes, we can cleanup after work */
fimg_destroy(&dessin), fimg_destroy(&noise), fimg_destroy(&result); fimg_destroy(&dessin), fimg_destroy(&noise), fimg_destroy(&result);
return 0; return 0;