Compare commits

...

4 Commits

Author SHA1 Message Date
tonton Th
a811beee8a pimping fimg2png 2020-01-22 18:53:55 +01:00
tonton Th
57ef940536 a new function : fimg_desaturate 2020-01-22 18:16:26 +01:00
tonton Th
1b2355f046 added "extern" to verbosity 2020-01-22 18:15:29 +01:00
tonton Th
e46f54a8fc typo... 2020-01-22 13:46:01 +01:00
5 changed files with 62 additions and 12 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 87
#define FIMG_VERSION 88
/*
* in memory descriptor
@ -57,7 +57,6 @@ int fimg_print_version(int k);
void fimg_printhead(FloatImg *h);
int fimg_describe(FloatImg *head, char *txt);
char *fimg_str_type(int type);
int fimg_fileinfo(char *fname, int *datas);
int fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b);
int fimg_clear(FloatImg *fimg);
int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b);
@ -91,6 +90,7 @@ int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval);
int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
int fimg_desaturate(FloatImg *src, FloatImg *dst, int k);
/* module funcs/rampes.c */
int fimg_hdeg_a(FloatImg *img, double dcoef);

View File

@ -52,6 +52,28 @@ for (foo=0; foo<nbb; foo++) {
return 0;
}
/* --------------------------------------------------------------------- */
int fimg_desaturate(FloatImg *src, FloatImg *dst, int k)
{
int foo, nbb;
float fval;
/* we must check the validity of our parameters */
if (FIMG_TYPE_RGB != src->type || FIMG_TYPE_RGB != dst->type) {
fprintf(stderr, "%s : bad image type\n", __func__, src->type, src);
return -18;
}
/* entering the main processing loop */
nbb = src->width * src->height;
for (foo=0; foo<nbb; foo++) {
dst->R[foo] = dst->G[foo] = dst->B[foo] =
(src->R[foo] + src->G[foo] + src->B[foo]) / 3.0;
}
return -99;
}
/* --------------------------------------------------------------------- */

View File

@ -10,7 +10,7 @@
#include "../floatimg.h"
int verbosity;
extern int verbosity;
/* ---------------------------------------------------------------- */
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
@ -18,7 +18,6 @@ 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]);
}

View File

@ -11,7 +11,7 @@
int verbosity;
/* ----------------------------------------------------------------- */
int convertir_fimg_en_PNG(char *srcname, char *dstname, int notused)
int convertir_fimg_en_PNG(char *srcname, char *dstname, int grisaille)
{
int foo, infos[3];
FloatImg fimg;
@ -22,7 +22,10 @@ fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
#endif
foo = fimg_fileinfos(srcname, infos);
if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); }
if (foo) {
if (verbosity) fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo);
return foo;
}
if (verbosity) {
fprintf(stderr, "image '%s' is %d x %d %s\n",
@ -36,6 +39,10 @@ if (foo) {
return -1;
}
if (grisaille) {
foo = fimg_desaturate(&fimg, &fimg, 0);
}
foo = fimg_save_as_png(&fimg, dstname, 0);
if (foo) {
fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo);
@ -47,19 +54,40 @@ fimg_destroy(&fimg);
return 0;
}
/* ----------------------------------------------------------------- */
void help(int k)
{
puts("usage:\n\tfimg2png [options] foo.fimg bar.png");
puts("options:");
puts("\t-g\tconvert to gray");
puts("\t-v\tincrease verbosity");
if (verbosity) fimg_print_version(1);
exit(0);
}
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
int foo, opt;
int to_gray = 0;
if (3 != argc) {
fimg_print_version(1);
fprintf(stderr, "usage:\n\t%s foo.fimg bar.pnm\n", argv[0]);
while ((opt = getopt(argc, argv, "ghv")) != -1) {
switch(opt) {
case 'g': to_gray = 1; break;
case 'v': verbosity++; break;
case 'h': help(1); exit(1);
}
}
if (2 != argc-optind) {
fprintf(stderr, "error: %s need two filenames\n", argv[0]);
exit(1);
}
foo = convertir_fimg_en_PNG(argv[1], argv[2], 0);
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
foo = convertir_fimg_en_PNG(argv[optind], argv[optind+1], to_gray);
if (verbosity)
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
return 0;
}

View File

@ -43,6 +43,7 @@ if (0 != foo) {
pr_v4l2_format("after ioctl VIDIOC_G_FMT", &fmt);
/* this function is bugged */
return k;
}