Compare commits

...

4 Commits

Author SHA1 Message Date
tth 119ab151bb clean some dirt 2019-09-10 16:03:24 +02:00
tth dc641499cb clean some dirt 2019-09-10 15:39:33 +02:00
tth 3a141c5a17 fimg2pnm can now do on-the-fly to-gray conversion 2019-09-10 15:38:24 +02:00
tth ffc99e6114 enhancing fimg to pnm converter 2019-09-10 12:18:02 +02:00
7 changed files with 78 additions and 21 deletions

View File

@ -41,6 +41,7 @@ int fimg_destroy(FloatImg *fimg);
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);

View File

@ -2,7 +2,7 @@
# building the base library
#
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o \
interpolate.o fimg-compare.o

View File

@ -24,7 +24,7 @@ switch (type) {
return 0;
}
/* --------------------------------------------------------------------- */
static char *fimg_str_type(int type)
char *fimg_str_type(int type)
{
switch (type) {
case FIMG_TYPE_GRAY: return "gray";

View File

@ -26,8 +26,8 @@ fimg2pnm: fimg2pnm.c $(DEPS)
fimg2png: fimg2png.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -o $@
# addtga2fimg: addtga2fimg.c $(DEPS)
# gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@
addtga2fimg: addtga2fimg.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@
addpnm2fimg: addpnm2fimg.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -lm -o $@

View File

@ -67,8 +67,8 @@ if (foo) {
exit(1);
}
if ( 0==access(argv[2], R_OK|W_OK) ) { /* fimg is readable */
// fprintf(stderr, "%s exist\n", argv[2]);
if ( 0==access(argv[2], R_OK) ) { /* fimg is readable */
fprintf(stderr, "%s is ok.\n", argv[2]);
}
else {
fprintf(stderr, "*** must create '%s' %dx%d first !!!\n",

View File

@ -11,21 +11,23 @@
int verbosity;
/* --------------------------------------------------------------------- */
int convertir_fimg_en_pnm(char *srcname, char *dstname, int notused)
int convertir_fimg_en_pnm(char *srcname, char *dstname, int to_gray)
{
int foo, infos[3];
FloatImg fimg;
FloatImg fimg, gris, *outptr;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' )\n", __func__, srcname, dstname);
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
srcname, dstname, to_gray);
#endif
foo = fimg_fileinfos(srcname, infos);
if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); }
if (verbosity) {
fprintf(stderr, "image '%s' is %d x %d\n",
srcname, infos[0], infos[1]);
fprintf(stderr, "image '%s' is %d x %d %s\n",
srcname, infos[0], infos[1],
fimg_str_type(infos[2]));
}
foo = fimg_create_from_dump(srcname, &fimg);
@ -34,32 +36,86 @@ if (foo) {
return -1;
}
outptr = &fimg; /* safe default value */
if (to_gray) {
puts("converting to gray...");
foo = fimg_create(&gris, fimg.width, fimg.height, FIMG_TYPE_GRAY);
if (foo) {
fprintf(stderr, "err create gray %d\n", foo);
return -2;
}
foo = fimg_mk_gray_from(&fimg, &gris, 0);
if (foo) {
fprintf(stderr, "err mk gray %d\n", foo);
return -4;
}
outptr = &gris;
}
#if DEBUG_LEVEL > 1
print_floatimg(&fimg, "created fimg");
print_floatimg(outptr, "created fimg");
#endif
foo = fimg_save_as_pnm(&fimg, dstname, 0);
foo = fimg_save_as_pnm(outptr, dstname, 0);
if(foo) { fprintf(stderr, "%p to '%s' -> %d\n", &fimg, dstname, foo); }
if (to_gray) {
fimg_destroy(&gris);
outptr = NULL;
/* please run valgrind every hour */
}
return 0;
}
/* --------------------------------------------------------------------- */
static void help(int flag)
{
if (flag) {
fprintf(stderr, "conversion FIMG -> PNM 16 bits\n");
fimg_print_version(1);
}
puts("usage :");
puts("\tfimg2pnm [flags] infile.fimg outfile.pnm");
}
/* --------------------------------------------------------------------- */
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]);
if (argc == 1) {
help(0);
exit(0);
}
while ((opt = getopt(argc, argv, "ghv")) != -1) {
switch(opt) {
case 'g': to_gray = 1;
case 'v': verbosity++; break;
case 'h': help(1); exit(1);
}
}
#if DEBUG_LEVEL
/* mmmm, is it the good way ? */
printf("argc %d -> %d\n", argc, argc-optind);
for (foo=optind; foo<argc; foo++) {
printf(" %d %s\n", foo, argv[foo]);
}
#endif
if (2 != argc-optind) {
fprintf(stderr, "error: %s need two filenames\n", argv[0]);
exit(1);
}
if ( 0 != access(argv[1], R_OK|W_OK) ) { /* fimg is NOT readable */
fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[1]);
if ( 0 != access(argv[optind], R_OK) ) { /* fimg is NOT readable */
fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[optind]);
exit(2);
}
foo = convertir_fimg_en_pnm(argv[1], argv[2], 0);
foo = convertir_fimg_en_pnm(argv[optind], argv[optind+1], to_gray);
if (foo) fprintf(stderr, "conversion -> %d\n", foo);
return 0;

View File

@ -75,7 +75,7 @@ if (argc == 1) {
foo = fimg_print_version(1); help(0);
exit(0);
}
while ((opt = getopt(argc, argv, "cv")) != -1) {
while ((opt = getopt(argc, argv, "cv")) != -1) {
switch(opt) {
case 'c': make_csv++; break;
case 'v': verbosity++; break;