commit du soir, espoir

This commit is contained in:
tth 2019-09-10 01:31:48 +02:00
parent a7392df682
commit 2aabc8b26b
7 changed files with 140 additions and 47 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 71
#define FIMG_VERSION 72
/*
* 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_images_compatible(FloatImg *a, FloatImg *b);
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef);
/* '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_create_from_dump(char *fname, FloatImg *head);
/* mathematics oprations */
/* mathematics operations */
float fimg_get_maxvalue(FloatImg *head);
int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
void fimg_drand48(FloatImg *fi, float kmul);
/* various funcs modules */

View File

@ -2,10 +2,10 @@
# 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 \
fimg-timers.o operators.o fimg-2gray.o \
interpolate.o
interpolate.o fimg-compare.o
DEPS = Makefile ../floatimg.h
@ -25,6 +25,9 @@ t: t.c ../libfloatimg.a $(DEPS)
fimg-core.o: fimg-core.c $(DEPS)
gcc $(COPT) -c $<
fimg-compare.o: fimg-compare.c $(DEPS)
gcc $(COPT) -c $<
fimg-2gray.o: fimg-2gray.c $(DEPS)
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

View File

@ -103,11 +103,30 @@ 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; nbre++) {
for (idx=0; idx<nbre; idx++) {
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 */
void fimg_drand48(FloatImg *fi, float kmul)
{

View File

@ -1,3 +1,6 @@
/*
* interpolate.c
*/
#include <stdio.h>
#include <stdlib.h>
@ -12,37 +15,53 @@ int verbosity;
/* ---------------------------------------------------------------- */
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;
if (FIMG_TYPE_RGB != s1->type) {
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;
picsize = d->width * d->height;
for (idx=0; idx<picsize; 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;

41
lib/t.c
View File

@ -72,56 +72,65 @@ foo = fimg_create(&dessin, W, H, 3);
petit_dessin(&dessin);
foo = fimg_create(&noise, W, H, 3);
fimg_drand48(&noise, 0.1);
****/
/* ---------------------------------------------------------------- */
#define W 320
#define H 240
int main(int argc, char *argv[])
{
int foo, idx;
int foo, idx, opt;
float coef;
FloatImg dessin, noise, result;
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);
if (foo) {
fprintf(stderr, "s1 load err %d\n", foo);
exit(1);
}
fimg_describe(&dessin, "s1 dessin");
fimg_to_gray(&dessin);
if (verbosity) fimg_describe(&dessin, "s1 dessin");
if (gray) fimg_to_gray(&dessin);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise);
if (foo) {
fprintf(stderr, "s2 load err %d\n", foo);
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);
if (verbosity) fimg_describe(&result, "d result");
#define NBRE 20
for (idx=0; idx<NBRE; idx++) {
coef = (float)idx / (float)NBRE;
coef = (0.5-0.5*cos( 3.141592654*coef));
fprintf(stderr, "running for %d picz\n", nb_img);
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);
printf("%6d %9.6f\n", idx, coef);
// fimg_to_gray(&result);
printf("%6d %9.6f\n", idx, coef);
sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx);
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);
return 0;