fimg2text can now add column names
This commit is contained in:
parent
c1b6f9ae40
commit
152beddcb7
@ -21,14 +21,10 @@ int x, y;
|
||||
float rgb[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %25s ( %p '%s' %d )\n", __func__,
|
||||
fprintf(stderr, ">>> %s ( %p '%s' 0x%x )\n", __func__,
|
||||
src, fname, flags);
|
||||
#endif
|
||||
|
||||
if (0 != flags) {
|
||||
fprintf(stderr, "bad flags in %s\n", __func__);
|
||||
}
|
||||
|
||||
fp = NULL; /* molly guard */
|
||||
if (strcmp("-", fname)) { /* real file */
|
||||
fprintf(stderr, "real file '%s'\n", fname);
|
||||
@ -38,6 +34,9 @@ else {
|
||||
}
|
||||
|
||||
fp = stdout; /* XXX */
|
||||
|
||||
if (flags & 1) { fputs("X Y R G B\n", fp); }
|
||||
|
||||
for (y=0; y<src->height; y+=steps) {
|
||||
for (x=0; x<src->width; x+=steps) {
|
||||
fimg_get_rgb(src, x, y, rgb);
|
||||
@ -49,6 +48,9 @@ for (y=0; y<src->height; y+=steps) {
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* This function must be in the libfloatimg !
|
||||
*/
|
||||
static int normalize(FloatImg *pimg, float vmax)
|
||||
{
|
||||
float mmv[6], maxi, coef;
|
||||
@ -85,14 +87,15 @@ return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int convertir_fimg_en_machinable(char *srcname, char *dstname,
|
||||
int steps, float norm)
|
||||
int steps, float norm, int header)
|
||||
{
|
||||
int foo, infos[3];
|
||||
int flg;
|
||||
FloatImg fimg;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %25s ( '%s' '%s' %d %f )\n", __func__,
|
||||
srcname, dstname, steps, norm);
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d %f %d )\n", __func__,
|
||||
srcname, dstname, steps, norm, header);
|
||||
#endif
|
||||
|
||||
if (steps < 1) {
|
||||
@ -100,12 +103,14 @@ if (steps < 1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
flg = 0;
|
||||
if (header) flg |= 1;
|
||||
|
||||
foo = fimg_fileinfos(srcname, infos);
|
||||
if (foo) {
|
||||
fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s: image '%s' is %d x %d %s\n",
|
||||
__func__,
|
||||
@ -128,7 +133,7 @@ if (norm > 0.0) {
|
||||
foo = normalize(&fimg, norm);
|
||||
}
|
||||
|
||||
foo = export_as_machinable(&fimg, dstname, steps, 0);
|
||||
foo = export_as_machinable(&fimg, dstname, steps, flg);
|
||||
if (foo) {
|
||||
fprintf(stderr,"%s: err %d on export\n", __func__, foo);
|
||||
}
|
||||
@ -141,9 +146,10 @@ void help(int k)
|
||||
{
|
||||
puts("usage:\n\tfimg2text [options] foo.fimg > bar.csv");
|
||||
puts("options:");
|
||||
puts("\t-v\t\tincrease verbosity");
|
||||
puts("\t-n 3.14\t\tnormalize picture");
|
||||
puts("\t-n Value\tnormalize picture if Value > 0.0");
|
||||
puts("\t-s N\t\tsteps on x & y");
|
||||
puts("\t-T\t\tadd header with colon name");
|
||||
puts("\t-v\t\tincrease verbosity");
|
||||
if (verbosity) {
|
||||
printf("*** compiled: %s at %s\n", __DATE__, __TIME__);
|
||||
fimg_print_version(k);
|
||||
@ -156,15 +162,17 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
int steps = 1;
|
||||
float norm_val = 222.0; /* < 0 : don't normalize */
|
||||
int header = 0;
|
||||
float norm_val = 255.0; /* < 0 : don't normalize */
|
||||
// char separator = ' ';
|
||||
|
||||
while ((opt = getopt(argc, argv, "f:hn:s:v")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "f:hn:s:Tv")) != -1) {
|
||||
switch(opt) {
|
||||
// case 'f': separator = optarg[0]; break;
|
||||
case 'v': verbosity++; break;
|
||||
case 'h': help(1); exit(1);
|
||||
case 's': steps = atoi(optarg); break;
|
||||
case 'T': header = 1; break;
|
||||
case 'n': norm_val = atof(optarg); break;
|
||||
default: exit(1);
|
||||
}
|
||||
@ -175,7 +183,8 @@ if (1 != argc-optind) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = convertir_fimg_en_machinable(argv[optind], "-", steps, norm_val);
|
||||
foo = convertir_fimg_en_machinable(argv[optind], "-",
|
||||
steps, norm_val, header);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user