new func: fimg_halfsize_1

This commit is contained in:
tth 2021-04-09 19:04:59 +02:00
parent b8a4514773
commit 27af6d5282
5 changed files with 73 additions and 8 deletions

View File

@ -4,7 +4,7 @@
* http://la.buvette.org/photos/cumul
*/
#define FIMG_VERSION 131
#define FIMG_VERSION 132
/*
* in memory descriptor
@ -158,6 +158,7 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused);
/* module funcs/geometry.c */
int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused);
int fimg_halfsize_1(FloatImg *src, FloatImg *dst, int notused);
int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags);

View File

@ -26,7 +26,7 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
/* no magic check here ? */
if (dst->width || dst->height) {
fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst);
fimg_describe(dst, "destination halfsize");
fimg_describe(dst, "destination halfsize 0");
return -2;
}
@ -55,3 +55,51 @@ for (y=0; y<hd; y++) {
return 0;
}
/* --------------------------------------------------------------------- */
int fimg_halfsize_1(FloatImg *src, FloatImg *dst, int notused)
{
int wd, hd;
int foo, x, y, x2, y2;
float ac;
if (dst->width || dst->height) {
fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst);
fimg_describe(dst, "destination halfsize 1");
return -2;
}
wd = src->width / 2; hd = src->height / 2;
if ( (foo = fimg_create(dst, wd, hd, FIMG_TYPE_RGB)) ) {
fprintf(stderr, "%s: err create %d\n", __func__, foo);
return -3;
}
#define WS (src->width)
#define WD (dst->width)
for (y=0; y<hd; y++) {
y2 = y * 2;
for (x=0; x<wd; x++) {
x2 = x * 2;
ac = src->R[(y2*WS)+x2] + src->R[(y2*WS)+x2+1] +
src->R[((1+y2)*WS)+x2] + src->R[((1+y2)*WS)+x2+1];
dst->R[y*WD +x] = ac / 4.0;
ac = src->G[(y2*WS)+x2] + src->G[(y2*WS)+x2+1] +
src->G[((1+y2)*WS)+x2] + src->G[((1+y2)*WS)+x2+1];
dst->G[y*WD +x] = ac / 4.0;
ac = src->B[(y2*WS)+x2] + src->B[(y2*WS)+x2+1] +
src->B[((1+y2)*WS)+x2] + src->B[((1+y2)*WS)+x2+1];
dst->B[y*WD +x] = ac / 4.0;
}
}
#undef WS
#undef WD
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -21,7 +21,8 @@ float global_fvalue;
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
Displace, ReadPNG, Plasmas, Hilight, OpenEXR };
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
Geometrie };
typedef struct {
char *name;
int Cmd;
@ -46,6 +47,7 @@ Command commands[] = {
{ "plasma", Plasmas },
{ "hilight", Hilight },
{ "openexr", OpenEXR },
{ "geometrie", Geometrie, },
{ NULL, 0 }
} ;
@ -202,6 +204,9 @@ switch(opt) {
case OpenEXR:
foo = essai_openexr(filename, outfile, 0x55);
break;
case Geometrie:
foo = essai_geometrie(filename, 0);
break;
default:
fprintf(stderr, "'%s' is a bad command\n", command);
exit(1);

View File

@ -498,7 +498,7 @@ fimg_destroy(&fimg);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_geometrie(char *infile)
int essai_geometrie(char *infile, int notused)
{
FloatImg fimg, result;
int foo;
@ -516,19 +516,29 @@ else {
fimg_draw_something(&fimg);
}
foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
// foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
memset(&result, 0, sizeof(FloatImg));
foo = fimg_halfsize_0(&fimg, &result, 0);
fprintf(stderr, "retour halfsize -> %d\n", foo);
fprintf(stderr, "retour halfsize 0 -> %d\n", foo);
if (foo) {
return -2;
}
if (verbosity) fimg_describe(&result, "result after halfsize 0");
foo = fimg_save_as_pnm(&result, "halfsize0.pnm", 0);
if (verbosity) fimg_describe(&result, "result after halfsize");
fimg_destroy(&result);
foo = fimg_halfsize_1(&fimg, &result, 0);
fprintf(stderr, "retour halfsize 1 -> %d\n", foo);
if (foo) {
return -2;
}
if (verbosity) fimg_describe(&result, "result after halfsize 1");
foo = fimg_save_as_pnm(&result, "halfsize1.pnm", 0);
foo = fimg_save_as_pnm(&result, "something.pnm", 0);
/* hop, un peu de nettoyage */
fimg_destroy(&result); fimg_destroy(&fimg);
return 0;
}

View File

@ -19,6 +19,7 @@ int essai_ecriture_tiff(char *infile);
int fimg_essai_hsv(char *infile);
int essai_classif(char *infile, char *outfile, float fvalue);
int essai_contour_2x2(char *filename, char *outfile);
int essai_geometrie(char *infile, int notused);
int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */
int essai_histogramme(char *fname, int k);