first shoot
This commit is contained in:
29
tools/Makefile
Normal file
29
tools/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# makefile for floatimg tools
|
||||
# use with caution
|
||||
#
|
||||
|
||||
COPT = -Wall -fpic -g -DDEBUG_LEVEL=1
|
||||
DEPS = ../floatimg.h ../libfloatimg.a Makefile
|
||||
|
||||
# ----------
|
||||
|
||||
fimgstats: fimgstats.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -o $@
|
||||
|
||||
mkfimg: mkfimg.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -o $@
|
||||
|
||||
fimg2pnm: fimg2pnm.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -o $@
|
||||
|
||||
fimg2png: fimg2png.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -o $@
|
||||
|
||||
addtga2fimg: addtga2fimg.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -limageSO -lm -o $@
|
||||
|
||||
# if "undefined reference to crc32" then "use -lz"
|
||||
png2fimg: png2fimg.c $(DEPS)
|
||||
gcc -g $< ../libfloatimg.a -lpnglite -o $@
|
||||
|
||||
99
tools/addtga2fimg.c
Normal file
99
tools/addtga2fimg.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* ADDTGA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tthimage.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int add_tga_to_fimg(char *srcname, char *dstname, int notused)
|
||||
{
|
||||
Image_Desc *src;
|
||||
FloatImg dst;
|
||||
int foo, x, y;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %s' )\n", __func__, srcname, dstname);
|
||||
#endif
|
||||
|
||||
if (NULL==(src = Image_TGA_alloc_load(srcname))) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
foo = fimg_create_from_dump(dstname, &dst);
|
||||
if (foo) fprintf(stderr, "create fimg from '%s' -> %d\n", dstname, foo);
|
||||
#if DEBUG_LEVEL
|
||||
fimg_describe(&dst, "created fimg");
|
||||
#endif
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
foo = fimg_add_rgb(&dst, x, y,
|
||||
(float)Image_R_pixel(src, x, y),
|
||||
(float)Image_G_pixel(src, x, y),
|
||||
(float)Image_B_pixel(src, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
foo = fimg_dump_to_file(&dst, dstname, 0);
|
||||
if (foo) { fprintf(stderr, "fimg dump -> %d\n", foo); }
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
int tgaW, tgaH;
|
||||
int infos[3];
|
||||
|
||||
if (3 != argc) {
|
||||
fimg_print_version(1);
|
||||
fprintf(stderr, "usage:\n\t%s img.tga cumul.fimg\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* first, check the TGA file dimensions */
|
||||
// Image_print_version(0);
|
||||
foo = Image_TGA_get_dims(argv[1], &tgaW, &tgaH);
|
||||
if (foo) {
|
||||
fprintf(stderr, "get dims of '%s' -> %d\n", argv[1], foo);
|
||||
Image_print_error("tga get dims", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0==access(argv[2], R_OK|W_OK) ) { /* fimg is readable */
|
||||
// fprintf(stderr, "%s exist\n", argv[2]);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "*** must create '%s' %dx%d first !!!\n",
|
||||
argv[2], tgaW, tgaH);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = fimg_fileinfos(argv[2], infos);
|
||||
// fprintf(stderr, "get dims of '%s' -> %d\n", argv[2], foo);
|
||||
if (foo) {
|
||||
fprintf(stderr, "*** %s is badly broken\n", argv[2]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if ( (tgaW != infos[0]) || (tgaW != infos[0]) ) {
|
||||
fprintf(stderr, " TGA %5d %5d\n", tgaW, tgaH);
|
||||
fprintf(stderr, " FIMG %5d %5d\n", infos[0], infos[1]);
|
||||
fprintf(stderr, " No dimension match.\n");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
foo = add_tga_to_fimg(argv[1], argv[2], 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
||||
21
tools/fimg2png.c
Normal file
21
tools/fimg2png.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
if (3 != argc) {
|
||||
fimg_print_version(1);
|
||||
fprintf(stderr, "usage:\n\t%s foo.fimg bar.pnm\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
62
tools/fimg2pnm.c
Normal file
62
tools/fimg2pnm.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int convertir_fimg_en_pnm(char *srcname, char *dstname, int notused)
|
||||
{
|
||||
int foo, infos[3];
|
||||
FloatImg fimg;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %25s ( '%s' '%s' )\n", __func__, srcname, dstname);
|
||||
#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]);
|
||||
}
|
||||
|
||||
foo = fimg_create_from_dump(srcname, &fimg);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create fimg from '%s' -> %d\n", srcname, foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
print_floatimg(&fimg, "created fimg");
|
||||
#endif
|
||||
|
||||
foo = fimg_save_as_pnm(&fimg, dstname, 0);
|
||||
if(foo) { fprintf(stderr, "%p to '%s' -> %d\n", &fimg, dstname, foo); }
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
if (3 != argc) {
|
||||
fimg_print_version(1);
|
||||
fprintf(stderr, "usage:\n\t%s foo.fimg bar.pnm\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]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
foo = convertir_fimg_en_pnm(argv[1], argv[2], 0);
|
||||
if (foo) fprintf(stderr, "conversion -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
91
tools/fimgstats.c
Normal file
91
tools/fimgstats.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* FIMGSTATS
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
int verbosity; /* global */
|
||||
|
||||
int make_csv;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int various_numbers(FloatImg *fimg, int k)
|
||||
{
|
||||
float moyennes[4];
|
||||
int foo;
|
||||
float fvalue;
|
||||
|
||||
if (verbosity)
|
||||
fprintf(stderr, " numbers from %p :\n", fimg);
|
||||
|
||||
fimg_printhead(fimg);
|
||||
fprintf(stderr, "surface %d\n", fimg->width * fimg->height);
|
||||
|
||||
fimg_meanvalues(fimg, moyennes);
|
||||
fprintf(stderr, "mean values:\n");
|
||||
for (foo=0; foo<4; foo++)
|
||||
printf(" %c %14.6f\n", "RGBA"[foo], moyennes[foo]);
|
||||
|
||||
fvalue = fimg_get_maxvalue(fimg);
|
||||
printf("max value %f\n", fvalue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int various_numbers_from_file(char *fname, int k)
|
||||
{
|
||||
FloatImg fimg;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "----------- numbers from '%s' :\n", fname);
|
||||
|
||||
foo = fimg_create_from_dump(fname, &fimg);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create fimg from '%s' -> %d\n", fname, foo);
|
||||
return -2;
|
||||
}
|
||||
|
||||
various_numbers(&fimg, k);
|
||||
|
||||
fimg_destroy(&fimg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
static void help(int k)
|
||||
{
|
||||
fputs( "usage : fimgstats [options] file.fimg\n"
|
||||
"\t-c\tmake a machinable csv\n"
|
||||
"\t-v\tincrease verbosity\n"
|
||||
, stderr);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt;
|
||||
|
||||
if (argc == 1) {
|
||||
foo = fimg_print_version(1); help(0);
|
||||
exit(0);
|
||||
}
|
||||
while ((opt = getopt(argc, argv, "cv")) != -1) {
|
||||
switch(opt) {
|
||||
case 'c': make_csv++; break;
|
||||
case 'v': verbosity++; break;
|
||||
|
||||
default: help(1); exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
foo = various_numbers_from_file(argv[optind], 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
41
tools/mkfimg.c
Normal file
41
tools/mkfimg.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
int width, height;
|
||||
char *fname;
|
||||
FloatImg fimg;
|
||||
|
||||
if (4 != argc) {
|
||||
fimg_print_version(1);
|
||||
fprintf(stderr, "Usage:\n\t%s quux.fimg width height\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
fname = argv[1];
|
||||
width = atoi(argv[2]); height = atoi(argv[3]);
|
||||
fprintf(stderr, "making %s %d x %d\n", fname, width, height);
|
||||
|
||||
foo = fimg_create(&fimg, width, height, 3);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create floatimg -> %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
fimg_describe(&fimg, "just a black flimg");
|
||||
fimg_clear(&fimg);
|
||||
|
||||
foo = fimg_dump_to_file(&fimg, fname, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "dump floatimg -> %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
39
tools/png2fimg.c
Normal file
39
tools/png2fimg.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* PNG ---> FIMG
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FloatImg fimg;
|
||||
int foo;
|
||||
|
||||
if (3 != argc) {
|
||||
fimg_print_version(1);
|
||||
fprintf(stderr, "usage:\n\t%s foo.fimg bar.png\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(&fimg, 0, sizeof(FloatImg));
|
||||
|
||||
foo = fimg_create_from_png(argv[1], &fimg);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d, abort.\n", argv[0], foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fimg_describe(&fimg, "oups");
|
||||
|
||||
foo = fimg_save_as_pnm(&fimg, "t.pnm", 0);
|
||||
fprintf(stderr, "save as pnm -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
Reference in New Issue
Block a user