From feb39d05fe929143e38465a6c65975709de344e6 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Fri, 27 Dec 2019 12:25:33 +0100 Subject: [PATCH] adding the copy_data funcs --- floatimg.h | 7 +++++-- funcs/fimg-png.c | 2 +- lib/fimg-compare.c | 3 +-- lib/fimg-core.c | 27 +++++++++++++++++++++++-- lib/t.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/floatimg.h b/floatimg.h index 92a2a1cd..c9276bf2 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 82 +#define FIMG_VERSION 84 /* * in memory descriptor @@ -35,6 +35,8 @@ typedef struct { #define FILE_TYPE_FIMG 1 #define FILE_TYPE_PNM 2 #define FILE_TYPE_PNG 3 +#define FILE_TYPE_TGA 4 +#define FILE_TYPE_TIFF 5 /* lib/contrast.c */ #define CONTRAST_NONE 0 @@ -49,6 +51,7 @@ typedef struct { int fimg_create(FloatImg *fimg, int w, int h, int t); int fimg_destroy(FloatImg *fimg); int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags); +int fimg_copy_data(FloatImg *from, FloatImg *to); int fimg_print_version(int k); void fimg_printhead(FloatImg *h); @@ -60,7 +63,7 @@ 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); - +/* --> lib/fimg-compare.c */ int fimg_images_compatible(FloatImg *a, FloatImg *b); int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef); diff --git a/funcs/fimg-png.c b/funcs/fimg-png.c index 0ff15d02..0eede41e 100644 --- a/funcs/fimg-png.c +++ b/funcs/fimg-png.c @@ -48,7 +48,7 @@ int datasize; fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg); #endif -/* We MUSTclear the fimg destination header first */ +/* We MUST clear the fimg destination header first */ memset(fimg, 0, sizeof(FloatImg)); memset(&png, 0, sizeof(png_t)); diff --git a/lib/fimg-compare.c b/lib/fimg-compare.c index a8f2caf2..dbe1755f 100644 --- a/lib/fimg-compare.c +++ b/lib/fimg-compare.c @@ -1,6 +1,5 @@ /* - * fimg-core.c - * + * fimg-compare.c * */ diff --git a/lib/fimg-core.c b/lib/fimg-core.c index e230bcbe..41b55660 100644 --- a/lib/fimg-core.c +++ b/lib/fimg-core.c @@ -76,7 +76,7 @@ return 0; } /* ---------------------------------------------------------------- */ /* - * + * values for the parameter 't' are defined in 'floatimg.h' */ int fimg_create(FloatImg *fimg, int w, int h, int t) { @@ -142,7 +142,7 @@ if ( ! fimg_type_is_valid(fimg->type) ) { return -2; } if (NULL == fimg->R) { - fprintf(stderr, "%s : %p already freed\n", __func__, fimg); + fprintf(stderr, "%s : %p already freed ?\n", __func__, fimg); return -3; } free(fimg->R); @@ -177,6 +177,27 @@ if (flags & 0x01) { } +return 0; +} +/* --------------------------------------------------------------------- */ +int fimg_copy_data(FloatImg *from, FloatImg *to) +{ +int size; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %-25s ( %p %p )\n", __func__, from, to); +#endif + +foo = fimg_images_compatible(from, to); +if (foo) { + fprintf(stderr, "%s: pics not compatible (%d)\n", __func__, foo); + return foo; + } + +size = from->width * from->height * from->type * sizeof(float); +memcpy(to->R, from->R, size); + return 0; } /* --------------------------------------------------------------------- */ @@ -202,8 +223,10 @@ int fimg_rgb_constant(FloatImg *head, float r, float g, float b) { int idx, size; +#if DEBUG_LEVEL fprintf(stderr, ">>> %-25s ( %p %f %f %f )\n", __func__, head, r, g, b); +#endif if (head->type != FIMG_TYPE_RGB) { return -21; diff --git a/lib/t.c b/lib/t.c index 001adcc7..ea1c87f0 100644 --- a/lib/t.c +++ b/lib/t.c @@ -41,6 +41,51 @@ if (foo) { fimg_destroy(&gray); +return 0; +} +/* ---------------------------------------------------------------- */ + +int essai_clone_et_copy(int unused) +{ +FloatImg A, B, C; +int foo; + +foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s err create A %d\n", __func__, foo); + return foo; + } +foo = fimg_draw_something(&A); +if (foo) { + fprintf(stderr, "%s err drawing A %d\n", __func__, foo); + return foo; + } +foo = fimg_save_as_pnm(&A, "A.pnm", 0); + +if (foo) { + fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); + exit(1); + } + +foo = fimg_clone(&A, &B, 1); +if (foo) { + fprintf(stderr, "%s err clone B %d\n", __func__, foo); + return foo; + } + +foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s err create A %d\n", __func__, foo); + return foo; + } +foo = fimg_copy_data(&A, &C); +if (foo) { + fprintf(stderr, "%s err copydata %d\n", __func__, foo); + return foo; + } +foo = fimg_save_as_pnm(&C, "C.pnm", 0); + + return 0; } /* ---------------------------------------------------------------- */ @@ -95,8 +140,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) { if (verbosity) fimg_print_version(0); -foo = essai_contraste("original.fimg"); -fprintf(stderr, "retour essai contraste -> %d\n", foo); +foo = essai_clone_et_copy(0); +fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo); return 0; }