Compare commits

..

No commits in common. "44165c0a0305e28f2e87af9c3a1e400879915588" and "62285334793c66ec6f11182f26c17dc1d92ae461" have entirely different histories.

4 changed files with 17 additions and 131 deletions

View File

@ -4,8 +4,7 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.o \
hsv.o
equalize.o fimg-fits.o saturation.o histogram.o
#---------------------------------------------------------------
@ -58,8 +57,5 @@ sfx0.o: sfx0.c $(DEPS)
rampes.o: rampes.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $<
utils.o: utils.c $(DEPS)
gcc $(COPT) -c $<

View File

@ -48,43 +48,37 @@ return -66;
}
/* --------------------------------------------------------------------- */
int fimg_essai_histo(FloatImg *src, char *outpic, int nbslices)
#define NSLICES 1000
int fimg_essai_histo(FloatImg *src, char *outpic, int k)
{
long *histo;
long histo[NSLICES];
int foo;
FILE *pipe;
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outpic, nbslices);
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outpic, k);
if (NULL==(histo=calloc(nbslices, sizeof(long)))) {
fprintf(stderr, "OUT OF MEMORY\n");
abort();
}
memset(histo, 0, NSLICES*sizeof(long));
foo = fimg_calcul_histo(src, histo, nbslices);
foo = fimg_calcul_histo(src, histo, NSLICES);
// for (foo=0; foo<NSLICES; foo++) {
// printf("%7d %ld\n", foo, histo[foo]);
// }
pipe = popen("gnuplot", "w");
if (NULL==pipe) {
fprintf(stderr, "%s: error running gnuplot\n", __func__);
return -17;
}
fprintf(pipe, "set term png size 1024,512\n");
fprintf(pipe, "set grid\n");
fprintf(pipe, "set output \"%s\"\n", outpic);
fprintf(pipe, "plot '/dev/stdin' with lines\n");
for (foo=0; foo<nbslices; foo++) {
for (foo=0; foo<NSLICES; foo++) {
fprintf(pipe, "%d %ld\n", foo, histo[foo]);
}
pclose(pipe); // and not fclose (see man page)
fclose(pipe);
free(histo);
return 0;
return -1;
}
/* --------------------------------------------------------------------- */

View File

@ -1,95 +0,0 @@
/*
* FloatImg library
* HUE - SATURATION - VALUE
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
extern int verbosity;
/* --------------------------------------------------------------------- */
/* helper functions */
static float maxi3f(float a, float b, float c)
{
return ((a > b)? (a > c ? a : c) : (b > c ? b : c));
}
static float mini3f(float a, float b, float c)
{
return ((a < b)? (a < c ? a : c) : (b < c ? b : c));
}
static int pseudoeq(float a, float b)
{
return (fabsf(a-b)<0.00000000000001); // UGLY HACK ???
}
/* --------------------------------------------------------------------- */
/*
* WARNING : ALL THIS CODE IS SHIT
*/
int fimg_rgb2hsv(float rgb[3], float hsv[3], float scale)
{
// float h, s, v;
float cmin, cmax, diff;
// scale input value to [0..1]
rgb[0] /= scale; rgb[1] /= scale; rgb[2] /= scale;
hsv[0] = hsv[1] = hsv[2] = -12345.6789;
cmin = mini3f(rgb[0], rgb[1], rgb[2]);
cmax = maxi3f(rgb[0], rgb[1], rgb[2]);
diff = cmax - cmin;
if (pseudoeq(cmax, cmin)) hsv[0] = 0.0;
else if (pseudoeq(cmax, rgb[0]))
hsv[0] = fmod((60 * ((rgb[1] - rgb[2]) / diff) + 360), 360.0);
else if (pseudoeq(cmax, rgb[1]))
hsv[0] = fmod((60 * ((rgb[2] - rgb[0]) / diff) + 120), 360.0);
else if (pseudoeq(cmax, rgb[2]))
hsv[0] = fmod((60 * ((rgb[0] - rgb[1]) / diff) + 240), 360.0);
if (pseudoeq(cmax, 0.0)) hsv[1] = 0.0;
else hsv[1] = (diff / cmax) / 100.0;
hsv[2] = cmax * 100.0; /* WHAT THE FUCK ? */
#if DEBUG_LEVEL
fprintf(stderr, "cmin/cmax %f %f\n", cmin, cmax);
#endif
return 0;
}
/* --------------------------------------------------------------------- */
int fimg_essai_hsv(char *fname)
{
float colors[3], values[3];
int foo, r, g, b;
#define INC 16
for (r=0; r<255; r+=INC) {
for (g=0; g<255; g+=INC) {
for (b=0; b<255; b+=INC) {
printf("%4d %4d %4d ", r, g, b);
colors[0] = (float)r;
colors[1] = (float)g;
colors[2] = (float)b;
foo = fimg_rgb2hsv(colors, values, 255.0);
if (foo) {
exit(1);
}
printf(" %9.5f %9.5f %9.5f\n",
values[0], values[1], values[2]);
}
}
}
return -1;
}
/* --------------------------------------------------------------------- */

View File

@ -402,16 +402,13 @@ return 0;
}
/* --------------------------------------------------------------------- */
int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */
int fimg_essai_hsv(char *fname); /* hsv.c */
/* func in histogram.c */
int fimg_essai_histo(FloatImg *src, char *outpic, int k);
int essai_histogramme(char *fname, int k)
{
FloatImg fimg;
int foo;
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k);
foo = fimg_create_from_dump(fname, &fimg);
@ -422,19 +419,17 @@ if (foo) {
foo = fimg_essai_histo(&fimg, "out.png", k);
if (foo) {
fprintf(stderr, "essai_histo -> error %d\n", foo);
fprintf(stderr, "essai_histo -> %d\n", foo);
return foo;
}
fimg_destroy(&fimg);
fprintf(stderr, "\\o/ end of %s\n", __func__);
return 0;
return -1;
}
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv };
Histo };
typedef struct {
char *name;
int Cmd;
@ -450,7 +445,6 @@ Command commands[] = {
{ "wpng", Wpng },
{ "wtiff", Wtiff },
{ "histo", Histo },
{ "hsv", Hsv },
{ NULL, 0 }
} ;
@ -542,10 +536,7 @@ switch(opt) {
foo = essai_ecriture_tiff(filename);
break;
case Histo:
foo = essai_histogramme(filename, 98765);
break;
case Hsv:
foo = fimg_essai_hsv(filename);
foo = essai_histogramme(filename, 0);
break;
default:
fprintf(stderr, "%s : bad command\n", command);