I can now write PNG files :)

This commit is contained in:
2019-12-13 18:18:07 +01:00
parent c84a893380
commit 8ce9251dec
9 changed files with 125 additions and 13 deletions

View File

@@ -30,7 +30,7 @@ fimg2pnm: fimg2pnm.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -o $@
fimg2png: fimg2png.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -o $@
gcc $(COPT) $< ../libfloatimg.a -lpnglite -o $@
addtga2fimg: addtga2fimg.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@

View File

@@ -1,13 +1,56 @@
/*
* converting a floatimg to a PNG
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../floatimg.h"
/* --------------------------------------------------------------------- */
int verbosity;
/* ----------------------------------------------------------------- */
int convertir_fimg_en_PNG(char *srcname, char *dstname, int notused)
{
int foo, infos[3];
FloatImg fimg;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
srcname, dstname, notused);
#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 %s\n",
srcname, infos[0], infos[1],
fimg_str_type(infos[2]));
}
foo = fimg_create_from_dump(srcname, &fimg);
if (foo) {
fprintf(stderr, "create fimg from '%s' -> %d\n", srcname, foo);
return -1;
}
foo = fimg_save_as_png(&fimg, dstname, 0);
if (foo) {
fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo);
return -1;
}
fimg_destroy(&fimg);
return -1;
}
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
// int foo;
int foo;
if (3 != argc) {
fimg_print_version(1);
@@ -15,9 +58,10 @@ if (3 != argc) {
exit(1);
}
fprintf(stderr, "ah ah ah, no working code here !\n");
foo = convertir_fimg_en_PNG(argv[1], argv[2], 0);
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
return 0;
}
/* --------------------------------------------------------------------- */
/* ----------------------------------------------------------------- */