Compare commits

..

No commits in common. "2aabc8b26bb8bbb59c1d1c85dd3a01c36ea47e3c" and "f109077b507f0f15f4c24d85975b292db8c2bf09" have entirely different histories.

8 changed files with 48 additions and 141 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 72
#define FIMG_VERSION 71
/*
* in memory descriptor
@ -47,8 +47,6 @@ 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 */
@ -71,12 +69,11 @@ 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 operations */
/* mathematics oprations */
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 -pg -no-pie -DDEBUG_LEVEL=0
COPT = -Wall -fpic -g -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 fimg-compare.o
interpolate.o
DEPS = Makefile ../floatimg.h
@ -25,9 +25,6 @@ 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 $<

View File

@ -1,40 +0,0 @@
/*
* 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;
}
printf(" type %d %s\n", head->type, fimg_str_type(head->type));
printf(" dims %d x %d\n",
printf(" type %d %s\n", head->type, fimg_str_type(head->type));
printf(" dims %d x %d\n",
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);
return 0;

0
lib/fimg-core.h Normal file
View File

View File

@ -103,30 +103,11 @@ 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++) {
for (idx=0; idx<nbre; nbre++) {
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,6 +1,3 @@
/*
* interpolate.c
*/
#include <stdio.h>
#include <stdlib.h>
@ -15,53 +12,37 @@ int verbosity;
/* ---------------------------------------------------------------- */
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
int picsize, idx;
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;
return -1;
}
/* ---------------------------------------------------------------- */
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;
int picsize, idx;
foo = fimg_images_compatible(s1, s2);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
if (FIMG_TYPE_RGB != s1->type) {
fprintf(stderr, "%s : bad src 1 type %d on %p\n", __func__,
s1->type, s1);
return -8;
}
foo = fimg_images_compatible(s1, d);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
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++) {
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
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,65 +72,56 @@ 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, opt;
int foo, idx;
float coef;
FloatImg dessin, noise, result;
char outname[100];
int gray = 0;
int nb_img = 42;
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);
verbosity = 1;
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);
}
if (verbosity) fimg_describe(&dessin, "s1 dessin");
if (gray) fimg_to_gray(&dessin);
fimg_describe(&dessin, "s1 dessin");
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);
}
if (verbosity) fimg_describe(&noise, "s2 noise");
fimg_mul_cste(&noise, 0.50);
if (gray) fimg_to_gray(&noise);
fimg_describe(&noise, "s2 noise");
foo = fimg_create(&result, W, H, 3);
if (verbosity) fimg_describe(&result, "d result");
fprintf(stderr, "running for %d picz\n", nb_img);
#define NBRE 20
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);
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);
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;