adding the copy_data funcs

This commit is contained in:
Tonton Th 2019-12-27 12:25:33 +01:00
parent 746e8d12f6
commit feb39d05fe
5 changed files with 79 additions and 9 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 82 #define FIMG_VERSION 84
/* /*
* in memory descriptor * in memory descriptor
@ -35,6 +35,8 @@ typedef struct {
#define FILE_TYPE_FIMG 1 #define FILE_TYPE_FIMG 1
#define FILE_TYPE_PNM 2 #define FILE_TYPE_PNM 2
#define FILE_TYPE_PNG 3 #define FILE_TYPE_PNG 3
#define FILE_TYPE_TGA 4
#define FILE_TYPE_TIFF 5
/* lib/contrast.c */ /* lib/contrast.c */
#define CONTRAST_NONE 0 #define CONTRAST_NONE 0
@ -49,6 +51,7 @@ typedef struct {
int fimg_create(FloatImg *fimg, int w, int h, int t); int fimg_create(FloatImg *fimg, int w, int h, int t);
int fimg_destroy(FloatImg *fimg); int fimg_destroy(FloatImg *fimg);
int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags); int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags);
int fimg_copy_data(FloatImg *from, FloatImg *to);
int fimg_print_version(int k); int fimg_print_version(int k);
void fimg_printhead(FloatImg *h); 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_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_rgb_constant(FloatImg *head, float r, float g, float b);
/* --> lib/fimg-compare.c */
int fimg_images_compatible(FloatImg *a, FloatImg *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);

View File

@ -1,6 +1,5 @@
/* /*
* fimg-core.c * fimg-compare.c
*
* *
*/ */

View File

@ -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) int fimg_create(FloatImg *fimg, int w, int h, int t)
{ {
@ -142,7 +142,7 @@ if ( ! fimg_type_is_valid(fimg->type) ) {
return -2; return -2;
} }
if (NULL == fimg->R) { if (NULL == fimg->R) {
fprintf(stderr, "%s : %p already freed\n", __func__, fimg); fprintf(stderr, "%s : %p already freed ?\n", __func__, fimg);
return -3; return -3;
} }
free(fimg->R); 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; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
@ -202,8 +223,10 @@ int fimg_rgb_constant(FloatImg *head, float r, float g, float b)
{ {
int idx, size; int idx, size;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %-25s ( %p %f %f %f )\n", __func__, head, fprintf(stderr, ">>> %-25s ( %p %f %f %f )\n", __func__, head,
r, g, b); r, g, b);
#endif
if (head->type != FIMG_TYPE_RGB) { if (head->type != FIMG_TYPE_RGB) {
return -21; return -21;

49
lib/t.c
View File

@ -41,6 +41,51 @@ if (foo) {
fimg_destroy(&gray); 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; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
@ -95,8 +140,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) {
if (verbosity) fimg_print_version(0); if (verbosity) fimg_print_version(0);
foo = essai_contraste("original.fimg"); foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai contraste -> %d\n", foo); fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo);
return 0; return 0;
} }