added a mirror function

This commit is contained in:
tth
2021-04-26 11:43:42 +02:00
parent b3de3b96f7
commit 9ddbef4e91
6 changed files with 87 additions and 5 deletions

View File

@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../floatimg.h"
@@ -135,4 +136,43 @@ for (yd=0; yd<rect->h; yd++) {
return 0;
}
/* --------------------------------------------------------------------- */
int fimg_mirror(FloatImg *src, FloatImg *dst, int notused)
{
float *fptr;
int line, col, offl;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__,
src, dst, notused);
#endif
if (fimg_images_not_compatible(src, dst)) {
fprintf(stderr, "bad karma in %s\n", __func__);
return -9;
}
if (NULL == (fptr=alloca(src->width*sizeof(float)))) {
fprintf(stderr, "%s: no mem available\n", __func__);
#if MUST_ABORT
abort();
#endif
return -11;
}
for (line=0; line<src->height; line++) {
offl = line * src->width;
for (col=0; col<src->width; col++)
fptr[(src->width-1) - col] = src->R[offl+col];
memcpy(dst->R+offl, fptr, src->width*sizeof(float));
for (col=0; col<src->width; col++)
fptr[(src->width-1) - col] = src->G[offl+col];
memcpy(dst->G+offl, fptr, src->width*sizeof(float));
for (col=0; col<src->width; col++)
fptr[(src->width-1) - col] = src->B[offl+col];
memcpy(dst->B+offl, fptr, src->width*sizeof(float));
}
return 0;
}
/* --------------------------------------------------------------------- */

View File

@@ -22,7 +22,7 @@ float global_fvalue;
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
Geometrie, FileType };
Geometrie, FileType, Mirror };
typedef struct {
char *name;
int Cmd;
@@ -49,6 +49,7 @@ Command commands[] = {
{ "openexr", OpenEXR },
{ "geometrie", Geometrie, },
{ "filetype", FileType },
{ "mirror", Mirror },
{ NULL, 0 }
} ;
@@ -211,6 +212,9 @@ switch(opt) {
case FileType:
foo = essai_detect_type();
break;
case Mirror:
foo = essai_miroir(filename, outfile, 0);
break;
default:
fprintf(stderr, "'%s' is a bad command\n", command);
exit(1);

View File

@@ -16,6 +16,39 @@
extern int verbosity;
/* --------------------------------------------------------------------- */
int essai_miroir(char *inf, char *outf, int flags)
{
int foo;
FloatImg src, dst;
fprintf(stderr, ">>> %s ( '%s' '%s' 0x%X )\n", __func__,
inf, outf, flags);
foo = fimg_create_from_dump(inf, &src);
if (0 != foo) {
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
foo, inf);
return foo;
}
fimg_clone(&src, &dst, 0);
/* run the crappy code */
foo = fimg_mirror(&src, &dst, 0);
if (foo) {
fprintf(stderr, "err %d in fimg_mirrot\n", foo);
return -6;
}
foo = fimg_export_picture(&dst, outf, 0);
if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo;
}
return -1;
}
/* --------------------------------------------------------------------- */
/* nouveau 21 mars 2021 - rue d'Aragon */
int essai_openexr(char *inf, char *outf, int flags)

View File

@@ -4,6 +4,7 @@
*/
int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef);
int essai_miroir(char *inf, char *outf, int flags);
int essai_displacement(char *infile, char *outfile);
int essai_qsort_rgb(char *infile, char *outfile);