
commit
5a72327882
25 changed files with 1480 additions and 0 deletions
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
|
||||
lib/*.o |
||||
funcs/*.o |
||||
|
||||
*.a |
||||
|
||||
tools/fimg2png |
||||
tools/fimg2pnm |
||||
tools/fimgstats |
||||
tools/mkfimg |
||||
tools/png2fimg |
||||
tools/addtga2fimg |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
|
||||
# Before running make, you must have
|
||||
# a look to the 'build.sh' script !
|
||||
|
||||
COPT = -Wall -fpic -g -pg -DDEBUG_LEVEL=0 |
||||
LDOPT = libfloatimg.a -pg -lm |
||||
|
||||
all: essai |
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
exemple: exemple.c libfloatimg.a floatimg.h Makefile |
||||
gcc $(COPT) $< $(LDOPT) -o $@ |
||||
|
||||
essai: essai.c libfloatimg.a floatimg.h Makefile |
||||
gcc $(COPT) $< $(LDOPT) -lpnglite -o $@ |
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
TOTAR = *.[ch] Makefile *.sh *.txt doc/*.tex \
|
||||
funcs/*.[ch] funcs/Makefile \
|
||||
tools/*.[ch] tools/Makefile \
|
||||
lib/*.[ch] lib/Makefile |
||||
|
||||
lines: $(TOTAR) |
||||
@wc $(TOTAR) | sort -n |
||||
|
||||
tarball: $(TOTAR) |
||||
date > tarball |
||||
ls $(TOTAR) | sed 's/^/Fimg\//' > MANIFEST |
||||
( cd .. ; tar zcvf floatimg.tar.gz `cat Fimg/MANIFEST` ) |
||||
|
||||
#---------------------------------------------------------------
|
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash |
||||
|
||||
cd lib |
||||
echo EEEEEEEEEE we are in $PWD |
||||
make |
||||
error=$? |
||||
if [ 0 -ne $error ]; then |
||||
printf "in %s err %d in %s\n" $PWD $error $0 |
||||
exit $error |
||||
fi |
||||
cd .. |
||||
|
||||
cd funcs |
||||
echo EEEEEEEEEE we are in $PWD |
||||
make |
||||
error=$? |
||||
if [ 0 -ne $error ]; then |
||||
printf "in %s err %d in %s\n" $PWD $error $0 |
||||
exit $error |
||||
fi |
||||
cd .. |
||||
|
||||
cd tools |
||||
echo |
||||
make fimg2pnm addtga2fimg mkfimg png2fimg fimgstats fimg2png |
||||
error=$? |
||||
cd .. |
||||
|
||||
echo |
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
testing some random funcs. |
||||
|
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <math.h> |
||||
#include <string.h> |
||||
|
||||
#include "floatimg.h" |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
int add(FloatImg *a, FloatImg *b) |
||||
{ |
||||
int x, y; |
||||
int offset; |
||||
double tb; |
||||
|
||||
fimg_timer_set(0); |
||||
|
||||
for (x=0; x<a->width; x++) { |
||||
for (y=0; y<a->height; y++) { |
||||
offset = x + (y * a->width); |
||||
a->R[offset] += b->R[offset]; |
||||
a->G[offset] += b->G[offset]; |
||||
a->B[offset] += b->B[offset]; |
||||
} |
||||
} |
||||
|
||||
tb = fimg_timer_get(0); |
||||
fprintf(stderr, "%s = %f seconds\n", __func__, tb); |
||||
|
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
void fait_un_dessin(char *fname) |
||||
{ |
||||
FloatImg dessin; |
||||
double tb; |
||||
|
||||
puts(""); |
||||
fimg_timer_set(0); |
||||
fimg_create(&dessin, 3200, 2400, 3); |
||||
fimg_draw_something(&dessin); |
||||
fimg_dump_to_file(&dessin, "dessin.fimg", 0); |
||||
fimg_destroy(&dessin); |
||||
tb = fimg_timer_get(0); |
||||
fprintf(stderr, "%s = %f seconds\n", __func__, tb); |
||||
|
||||
puts(""); |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
FloatImg fimgA, fimgB; |
||||
int foo; |
||||
double tb; |
||||
|
||||
fimg_print_version(0); |
||||
|
||||
#define W 2000 |
||||
#define H 1700 |
||||
|
||||
fait_un_dessin("dessin.fimg"); |
||||
|
||||
fimg_create(&fimgA, W, H, 3); |
||||
fimg_create(&fimgB, W, H, 3); |
||||
|
||||
fimg_draw_something(&fimgA); |
||||
|
||||
fimg_timer_set(0); |
||||
fimg_drand48(&fimgB, 100.0); |
||||
tb = fimg_timer_get(0); |
||||
fprintf(stderr, "%s = %f seconds\n", __func__, tb); |
||||
|
||||
foo = fimg_save_as_pnm(&fimgB, "drand48.pnm", 0); |
||||
|
||||
/*
|
||||
fimg_printhead(&fimgA); fimg_printhead(&fimgB); |
||||
fimg_describe(&fimgA, "image A"); |
||||
*/ |
||||
|
||||
add(&fimgA, &fimgB); |
||||
|
||||
foo = fimg_save_as_pnm(&fimgA, "t.pnm", 0); |
||||
fprintf(stderr, "save as pnm -> %d\n", foo); |
||||
foo = fimg_dump_to_file(&fimgA, "t.fimg", 0); |
||||
fprintf(stderr, "save as fimg -> %d\n", foo); |
||||
|
||||
fimg_destroy(&fimgA); |
||||
fimg_destroy(&fimgB); |
||||
|
||||
|
||||
return 0; |
||||
} |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
|
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* floatimg.h |
||||
*/ |
||||
|
||||
#define FIMG_VERSION 58 |
||||
|
||||
/*
|
||||
* in memory descriptor |
||||
*/ |
||||
typedef struct { |
||||
int width; |
||||
int height; |
||||
int type; |
||||
float fval; |
||||
int count; |
||||
|
||||
float *R, *G, *B, *A; |
||||
|
||||
int reserved; |
||||
} FloatImg; |
||||
|
||||
/*
|
||||
* fimg file header |
||||
*/ |
||||
typedef struct { |
||||
// char magic[8];
|
||||
int w, h, t; |
||||
} FimgFhead; |
||||
|
||||
/*
|
||||
* core module |
||||
*/ |
||||
int fimg_create(FloatImg *fimg, int w, int h, int t); |
||||
int fimg_destroy(FloatImg *fimg); |
||||
|
||||
int fimg_print_version(int k); |
||||
void fimg_printhead(FloatImg *h); |
||||
int fimg_describe(FloatImg *head, char *txt); |
||||
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); |
||||
int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b); |
||||
|
||||
/* PNM files module */ |
||||
int fimg_save_as_pnm(FloatImg *head, char *fname, int notused); |
||||
|
||||
double fimg_timer_set(int whot); |
||||
double fimg_timer_get(int whot); |
||||
|
||||
|
||||
/* FIMG files module */ |
||||
int fimg_fileinfos(char *fname, int *datas); |
||||
int fimg_dump_to_file(FloatImg *head, char *fname, int notused); |
||||
int fimg_create_from_dump(char *fname, FloatImg *head); |
||||
|
||||
/* mathematics oprations */ |
||||
float fimg_get_maxvalue(FloatImg *head); |
||||
int fimg_meanvalues(FloatImg *head, float means[4]); |
||||
int fimg_to_gray(FloatImg *head); |
||||
void fimg_add_cste(FloatImg *fi, float value); |
||||
void fimg_drand48(FloatImg *fi, float kmul); |
||||
|
||||
/* variuos funcs modules */ |
||||
int fimg_load_from_png(char *filename, FloatImg *fimg); |
||||
int fimg_create_from_png(char *filename, FloatImg *fimg); |
||||
int fimg_save_as_png(FloatImg *src, char *outname, int flags); |
||||
|
||||
int fimg_draw_something(FloatImg *fimg); |
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
#---------------------------------------------------------------
|
||||
|
||||
COPT = -Wall -fpic -g -no-pie -pg -DDEBUG_LEVEL=0 |
||||
DEPS = ../floatimg.h Makefile |
||||
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o |
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
../libfloatimg.a: $(OBJS) |
||||
$(AR) r $@ $? |
||||
|
||||
fimg-png.o: fimg-png.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
fimg-tiff.o: fimg-tiff.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
misc-plots.o: misc-plots.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
filtrage.o: filtrage.c $(DEPS) |
||||
gcc $(COPT) -c $< |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <fcntl.h> |
||||
#include <float.h> |
||||
|
||||
#include "floatimg.h" |
||||
|
||||
/* -------------------------------------------------------------------- */ |
||||
int fimg_lissage_2x2(FloatImg *img) |
||||
{ |
||||
|
||||
|
||||
return -1; |
||||
} |
||||
/* -------------------------------------------------------------------- */ |
||||
|
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Lecture des images PNG |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
|
||||
#include <pnglite.h> |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
/*
|
||||
* warning : this func has been tested only with |
||||
* RGB (3x8bits) PNG files |
||||
*/ |
||||
int fimg_create_from_png(char *filename, FloatImg *fimg) |
||||
{ |
||||
png_t png; |
||||
int foo, idx; |
||||
unsigned char *datas, *ptr; |
||||
int datasize; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg); |
||||
#endif |
||||
|
||||
memset(&png, 0, sizeof(png_t)); |
||||
png_init(NULL, NULL); /* this is VITAL ! */ |
||||
|
||||
foo = png_open_file_read(&png, filename); |
||||
if (PNG_NO_ERROR != foo) { |
||||
fprintf(stderr, "%s open_file '%s' -> %d\n", __func__, filename, foo); |
||||
return foo; |
||||
} |
||||
#if DEBUG_LEVEL > 1 |
||||
fprintf(stderr, "%s opened\n", filename); |
||||
#endif |
||||
|
||||
datasize = png.width * png.height * png.bpp; |
||||
|
||||
if ( 3 != png.bpp ) { |
||||
fprintf(stderr, "format %d of '%s' not supported\n", |
||||
png.color_type, filename); |
||||
return -21; |
||||
} |
||||
|
||||
#if DEBUG_LEVEL |
||||
printf("\t%s is %d x %d\n", filename, png.width, png.height); |
||||
printf("\tdatalen %d\n", png.png_datalen); |
||||
printf("\tcolor type %d\n", png.color_type); |
||||
printf("\tbyte/pixel %d\n", png.bpp); |
||||
printf("\tdatasize %d\n", datasize); |
||||
puts(""); png_print_info(&png); puts(""); |
||||
#endif |
||||
|
||||
datas = malloc(datasize); |
||||
if (NULL==datas) { |
||||
fprintf(stderr, "%s : fatal memory failure\n", __func__); |
||||
exit(1); |
||||
} |
||||
|
||||
memset(fimg, 0, sizeof(FloatImg)); |
||||
foo = fimg_create(fimg, png.width, png.height, 3); |
||||
if (foo) { |
||||
fprintf(stderr, "can't create fimg\n"); |
||||
exit(1); |
||||
} |
||||
|
||||
foo = png_get_data(&png, datas); |
||||
if (PNG_NO_ERROR != foo) { |
||||
fprintf(stderr, "error in '%s' : read png -> %d\n", |
||||
__func__, foo); |
||||
return foo; |
||||
} |
||||
|
||||
ptr = datas; |
||||
for (idx=0; idx<png.width * png.height; idx++) { |
||||
fimg->R[idx] = (float)*ptr++; |
||||
fimg->G[idx] = (float)*ptr++; |
||||
fimg->B[idx] = (float)*ptr++; |
||||
} |
||||
free(datas); |
||||
|
||||
png_close_file(&png); |
||||
// fprintf(stderr, "png closed...\n");
|
||||
return foo; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
/*
|
||||
* warning : this func has been tested only with |
||||
* RGB (3x8bits) PNG files |
||||
*/ |
||||
int fimg_load_from_png(char *filename, FloatImg *fimg) |
||||
{ |
||||
png_t png; |
||||
int foo, idx, datasize; |
||||
unsigned char *datas, *ptr; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg); |
||||
#endif |
||||
|
||||
memset(&png, 0, sizeof(png_t)); |
||||
png_init(NULL, NULL); /* this is VITAL ! */ |
||||
|
||||
foo = png_open_file_read(&png, filename); |
||||
if (PNG_NO_ERROR != foo) { |
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, "open png -> %d\n", foo); |
||||
#endif |
||||
return foo; |
||||
} |
||||
|
||||
// puts(""); png_print_info(&png); puts("");
|
||||
|
||||
if ( 3 != png.bpp ) { /* TO BE PATCHED */ |
||||
fprintf(stderr, "format of '%s' not supported\n", filename); |
||||
return -21; |
||||
} |
||||
|
||||
/* check if floatimg and PNG have the same size */ |
||||
if ((fimg->width != png.width) || (fimg->height != png.height)) { |
||||
fprintf(stderr, "%s : fatal error on images sizes\n", __func__); |
||||
exit(1); |
||||
} |
||||
|
||||
datasize = png.width * png.height * png.bpp; |
||||
datas = malloc(datasize); |
||||
if (NULL==datas) { |
||||
fprintf(stderr, "%s : fatal memory failure\n", __func__); |
||||
exit(1); |
||||
} |
||||
foo = png_get_data(&png, datas); |
||||
if (PNG_NO_ERROR != foo) { |
||||
fprintf(stderr, "error in '%s' : read png -> %d\n", |
||||
__func__, foo); |
||||
return foo; |
||||
} |
||||
ptr = datas; |
||||
for (idx=0; idx<png.width * png.height; idx++) { |
||||
fimg->R[idx] = (float)*ptr++; |
||||
fimg->G[idx] = (float)*ptr++; |
||||
fimg->B[idx] = (float)*ptr++; |
||||
} |
||||
|
||||
free(datas); |
||||
png_close_file(&png); |
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
int fimg_save_as_png(FloatImg *src, char *outname, int flags) |
||||
{ |
||||
png_t png; |
||||
|
||||
|
||||
|
||||
return -1; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* FLOATIMG |
||||
* import/export to/from TIFF files |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
/* --------------------------------------------------------------------- */ |
||||
/* --------------------------------------------------------------------- */ |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
testing some random funcs. |
||||
|
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <math.h> |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
int fimg_draw_something(FloatImg *fimg) |
||||
{ |
||||
int x, y; |
||||
float fx, fy; |
||||
|
||||
#define K (3.14159*13.456) |
||||
#define M 100.0 |
||||
|
||||
for (x=0; x<fimg->width; x++) { |
||||
fimg_plot_rgb(fimg, x, 0, |
||||
(float)x, |
||||
(float)x + 5.678, |
||||
(float)x * 1.33333); |
||||
} |
||||
|
||||
for (y=1; y<fimg->height; y++) { |
||||
fy = (float)y / (float)fimg->height; |
||||
for (x=0; x<fimg->width; x++) { |
||||
fx = (float)x / (float)fimg->width; |
||||
fimg_plot_rgb(fimg, x, y, |
||||
M*(cos(fx*K)+1.2), |
||||
M*(cos(fy*K)+1.2), |
||||
M*(cos(fx*fy)+1.2)); |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
int fimg_multirandom(FloatImg *fimg) |
||||
{ |
||||
int foo, x, y; |
||||
|
||||
#define RI ( (rand()/7) + (rand()/9) ) |
||||
#define RD ( (drand48()/7) + (drand48()/7) ) |
||||
|
||||
for (foo=0; foo<100000000; foo++) |
||||
{ |
||||
x = RI % fimg->width; |
||||
y = RI % fimg->height; |
||||
fimg_add_rgb(fimg, x, y, RD, RD, RD); |
||||
} |
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash |
||||
|
||||
cp libfloatimg.a /usr/local/lib |
||||
cp floatimg.h /usr/local/include |
||||
|
||||
cp tools/mkfimg tools/fimg2pnm tools/addtga2fimg \ |
||||
tools/png2fimg tools/fimgstats \ |
||||
/usr/local/bin |
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# building the base library
|
||||
#
|
||||
|
||||
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0 |
||||
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
|
||||
fimg-timers.o |
||||
DEPS = Makefile ../floatimg.h |
||||
|
||||
# modify it 'as you like'
|
||||
AR=ar |
||||
|
||||
all: $(OBJS) ../libfloatimg.a |
||||
|
||||
# --------------------------------------------
|
||||
|
||||
../libfloatimg.a: $(OBJS) |
||||
$(AR) r $@ $? |
||||
|
||||
fimg-core.o: fimg-core.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
fimg-pnm.o: fimg-pnm.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
fimg-file.o: fimg-file.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
fimg-math.o: fimg-math.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
fimg-timers.o: fimg-timers.c $(DEPS) |
||||
gcc $(COPT) -c $< |
||||
|
||||
# --------------------------------------------
|
@ -0,0 +1,189 @@
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* fimg-core.c |
||||
* |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include "string.h" |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
extern int verbosity; /* must be declared around main() */ |
||||
|
||||
/* ---------------------------------------------------------------- */ |
||||
static int fimg_type_is_valid(int t) |
||||
{ |
||||
switch (t) { |
||||
case 1: case 3: case 4: return 1; |
||||
} |
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
int fimg_print_version(int k) |
||||
{ |
||||
fprintf(stderr, "*** FloatImg library, alpha v%d (%s, %s)\n", |
||||
FIMG_VERSION, __DATE__, __TIME__); |
||||
|
||||
if (51 == k) { |
||||
puts("+--------------------+"); |
||||
puts("| Pastis is coming. |"); |
||||
puts("+--------------------+"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
void fimg_printhead(FloatImg *h) |
||||
{ |
||||
printf("%5d %5d %2d %p %p %p %p\n", h->width, h->height, h->type, |
||||
h->R, h->G, h->B, h->A); |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
int fimg_describe(FloatImg *head, char *txt) |
||||
{ |
||||
printf("----- '%s' at %p -----\n", txt, head); |
||||
|
||||
if( ! fimg_type_is_valid(head->type) ) { |
||||
fprintf(stderr, "*** %s *** type %d invalid *** %s ***\n", |
||||
__func__, head->type, txt); |
||||
return -1; |
||||
} |
||||
|
||||
printf(" size %d x %d x %d\n", |
||||
head->width, head->height, head->type); |
||||
printf(" fval/count %f %d\n", head->fval, head->count); |
||||
printf(" pixels@ %p %p %p %p\n", |
||||
head->R, head->G, head->B, head->A); |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
|
||||
int fimg_create(FloatImg *fimg, int w, int h, int t) |
||||
{ |
||||
int surface, size; |
||||
float *fptr; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( %p %d %d %d )\n", __func__, fimg, w, h, t); |
||||
#endif |
||||
|
||||
if ( ! fimg_type_is_valid(t) ) { |
||||
return -2; |
||||
} |
||||
memset(fimg, 0, sizeof(FloatImg)); |
||||
|
||||
surface = w * h; |
||||
size = surface * t * sizeof(float); |
||||
#if DEBUG_LEVEL > 1 |
||||
fprintf(stderr, "surface is %d pixels, need %d bytes\n", surface, size); |
||||
#endif |
||||
|
||||
fptr = (float *)malloc(size); |
||||
if (NULL==fptr) { |
||||
fprintf(stderr, "%s : nom mem, exiting.\n", __func__); |
||||
exit(1); |
||||
} |
||||
|
||||
#if DEBUG_LEVEL > 1 |
||||
fprintf(stderr, " got %d bytes at %p\n", size, fptr); |
||||
#endif |
||||
|
||||
fimg->width = w; fimg->height = h; |
||||
fimg->type = t; |
||||
|
||||
fimg->R = fptr; |
||||
if ( (t==3) || (t==4) ) { |
||||
fimg->G = fptr + surface; |
||||
fimg->B = fptr + surface + surface; |
||||
} |
||||
if ( t==4 ) fimg->A = fptr + (3 * surface); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
int fimg_destroy(FloatImg *fimg) |
||||
{ |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( %p )\n", __func__, fimg); |
||||
#endif |
||||
|
||||
if ( ! fimg_type_is_valid(fimg->type) ) { |
||||
return -2; |
||||
} |
||||
|
||||
free(fimg->R); |
||||
memset(fimg, 0, sizeof(FloatImg)); |
||||
|
||||
return 0; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
int fimg_clear(FloatImg *fimg) |
||||
{ |
||||
int size; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( %p )\n", __func__, fimg); |
||||
#endif |
||||
if ( ! fimg_type_is_valid(fimg->type) ) { |
||||
fprintf(stderr, "invalid type %d in %s\n", fimg->type, __func__); |
||||
return -2; |
||||
} |
||||
|
||||
size = fimg->width * fimg->height * fimg->type * sizeof(float); |
||||
memset(fimg->R, 0, size); |
||||
|
||||
return -1; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
int fimg_plot_rgb (FloatImg *head, int x, int y, |
||||
float r, float g, float b) |
||||
{ |
||||
int offset; |
||||
|
||||
if (head->type < 3) { |
||||
#if DEBUG_LEVEL > 1 |
||||
fprintf(stderr, "%s : type %d is bad.\n", __func__, head->type); |
||||
#endif |
||||
return -1; |
||||
} |
||||
|
||||
offset = x + (y * head->width); |
||||
|
||||
#if DEBUG_LEVEL > 1 |
||||
fprintf(stderr, ">>> %s ( %p %d %d %f )\n", __func__, head, x, y, gray); |
||||
fprintf(stderr, " offset %d\n", offset); |
||||
#endif |
||||
|
||||
head->R[offset] = r; |
||||
head->G[offset] = g; |
||||
head->B[offset] = b; |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b) |
||||
{ |
||||
int offset; |
||||
offset = x + (y * head->width); |
||||
head->R[offset] += r; |
||||
head->G[offset] += g; |
||||
head->B[offset] += b; |
||||
return 0; |
||||
} |
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,125 @@
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* fimg-file.c |
||||
* |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include "string.h" |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
extern int verbosity; /* must be declared around main() */ |
||||
|
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_fileinfos(char *fname, int *datas) |
||||
{ |
||||
FILE *fp; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, datas); |
||||
#endif |
||||
|
||||
fp = fopen(fname, "r"); |
||||
if (NULL==fp) { |
||||
perror(fname); |
||||
return -1; |
||||
} |
||||
if (3 != fread(datas, sizeof(int), 3, fp)) { |
||||
fprintf(stderr, "%s: %s short read\n", __func__, fname); |
||||
fclose(fp); |
||||
return -2; |
||||
} |
||||
|
||||
fclose(fp); |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_dump_to_file(FloatImg *head, char *fname, int notused) |
||||
{ |
||||
FILE *fp; |
||||
int foo, nbre, dims[3]; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, head, |
||||
fname, notused); |
||||
#endif |
||||
|
||||
if (3 != head->type) { |
||||
fprintf(stderr, "%s : bat type %d\n", __func__, head->type); |
||||
return -8; |
||||
} |
||||
|
||||
fp = fopen(fname, "w"); |
||||
if (NULL==fp) { |
||||
perror(fname); |
||||
return -1; |
||||
} |
||||
|
||||
dims[0] = head->width; dims[1] = head->height; |
||||
dims[2] = head->type; |
||||
|
||||
foo = fwrite(dims, sizeof(int), 3, fp); |
||||
if (3 != foo) { |
||||
perror(fname); |
||||
fclose(fp); |
||||
return -2; |
||||
} |
||||
nbre = head->width*head->height*3; |
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, " %s : data at %p\n", __func__, head->R); |
||||
#endif |
||||
|
||||
foo = fwrite(head->R, sizeof(float), nbre, fp); |
||||
if (nbre!=foo) { |
||||
perror(fname); |
||||
fclose(fp); |
||||
return -3; |
||||
} |
||||
|
||||
fclose(fp); |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_create_from_dump(char *fname, FloatImg *head) |
||||
{ |
||||
FILE *fp; |
||||
int foo, dims[3]; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head); |
||||
#endif |
||||
|
||||
fp = fopen(fname, "r"); |
||||
if (NULL==fp) { |
||||
perror(fname); |
||||
exit(1); |
||||
} |
||||
|
||||
foo = fread(dims, sizeof(int), 3, fp); |
||||
if (3 != foo) { |
||||
fprintf(stderr, "%s : short read\n", fname); |
||||
fclose(fp); |
||||
return -1; |
||||
} |
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__, |
||||
dims[0], dims[1], dims[2], fname); |
||||
#endif |
||||
|
||||
foo = fimg_create(head, dims[0], dims[1], dims[2]); |
||||
if (foo) { |
||||
fprintf(stderr, "%s : create -> %d\n", __func__, foo); |
||||
return foo; |
||||
} |
||||
|
||||
foo = fread(head->R, sizeof(float), dims[0]*dims[1]*3, fp); |
||||
|
||||
fclose(fp); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* fimg-core.c |
||||
* |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include "string.h" |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
extern int verbosity; /* must be declared around main() */ |
||||
|
||||
/* ---------------------------------------------------------------- */ |
||||
float fimg_get_maxvalue(FloatImg *head) |
||||
{ |
||||
float maxval; |
||||
int foo; |
||||
|
||||
maxval = 0.0; /* no negative values allowed */ |
||||
|
||||
for (foo=0; foo<(head->width*head->height); foo++) { |
||||
if (head->R[foo] > maxval) maxval = head->R[foo]; |
||||
if (head->G[foo] > maxval) maxval = head->G[foo]; |
||||
if (head->B[foo] > maxval) maxval = head->B[foo]; |
||||
} |
||||
|
||||
return maxval; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_meanvalues(FloatImg *head, float means[4]) |
||||
{ |
||||
int idx, surface; |
||||
|
||||
surface = head->width * head->height; |
||||
if (surface < 1) return -1; |
||||
|
||||
memset(means, 0, 4*sizeof(float)); |
||||
|
||||
for (idx=0; idx<surface; idx++) { |
||||
means[0] += head->R[idx]; |
||||
if (head->type > 2) { |
||||
means[1] += head->G[idx]; |
||||
means[2] += head->B[idx]; |
||||
} |
||||
} |
||||
|
||||
for (idx=0; idx<4; idx++) means[idx] /= (float)surface; |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
int fimg_to_gray(FloatImg *head) |
||||
{ |
||||
float add; |
||||
int foo; |
||||
|
||||
for (foo=0; foo<(head->width*head->height); foo++) { |
||||
add = head->R[foo]; |
||||
add += head->G[foo]; |
||||
add += head->B[foo]; |
||||
head->R[foo] = head->G[foo] = head->B[foo] = add; |
||||
} |
||||
return -1; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
void fimg_add_cste(FloatImg *fi, float value) |
||||
{ |
||||
int nbre, idx; |
||||
|
||||
nbre = fi->width * fi->height * fi->type; |
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre); |
||||
#endif |
||||
for (idx=0; idx<nbre; nbre++) { |
||||
fi->R[idx] += value; |
||||
} |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
/* Warning: this function is _very_ slow */ |
||||
void fimg_drand48(FloatImg *fi, float kmul) |
||||
{ |
||||
int nbre, idx; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %s ( %p %g )\n", __func__, fi, kmul); |
||||
#endif |
||||
|
||||
nbre = fi->width * fi->height * fi->type; |
||||
for (idx=0; idx<nbre; idx++) { |
||||
fi->R[idx] = drand48() * kmul; |
||||
} |
||||
|
||||
} |
||||
/* ---------------------------------------------------------------- */ |
||||
|
||||
|
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* fimg-pnm.c |
||||
* |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include "string.h" |
||||
|
||||
#include "../floatimg.h" |
||||
|
||||
extern int verbosity; /* must be declared around main() */ |
||||
|
||||
/* ---------------------------------------------------------------- */ |
||||
/* ---------------------------------------------------------------- */ |
||||
|
||||
int fimg_save_as_pnm(FloatImg *head, char *fname, int notused) |
||||
{ |
||||
FILE *fp; |
||||
float maximum, fk; |
||||
int idx, sz, Rv, Gv, Bv, foo; |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, head, |
||||
fname, notused); |
||||
#endif |
||||
|
||||
if (head->type != 3) { |
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, "%s : type %d is bad.\n", __func__, head->type); |
||||
#endif |
||||
return -1; |
||||
} |
||||
|
||||
if (NULL==(fp=fopen(fname, "w"))) { |
||||
perror(fname); |
||||
return -1; |
||||
} |
||||
|
||||
fprintf(fp, "P3\n%d %d\n", head->width, head->height); |
||||
|
||||
maximum = fimg_get_maxvalue(head); |
||||
fprintf(fp, "# maxval %15f\n", maximum); |
||||
fk = maximum / 65536.0; |
||||
fprintf(fp, "# divisor %15f\n", fk); |
||||
fprintf(fp, "65535\n"); |
||||
sz = head->width*head->height; |
||||
|
||||
foo = 0; |
||||
for (idx=0; idx<sz; idx++) { |
||||
if (fk > 0) { |
||||
Rv = (int)(head->R[idx] / fk); |
||||
Gv = (int)(head->G[idx] / fk); |
||||
Bv = (int)(head->B[idx] / fk); |
||||
} |
||||
else { |
||||
Rv = Gv = Bv = 0; |
||||
} |
||||
foo += fprintf(fp, "%d %d %d", Rv, Gv, Bv); |
||||
if (foo > 60) { |
||||
fputs("\n", fp); foo = 0; |
||||
} |
||||
else { |
||||
fputs(" ", fp); foo++; |
||||
} |
||||
} |
||||
fputs("\n", fp); |
||||
|
||||
|
||||
fclose(fp); |
||||
|
||||
return 0; |
||||
} |
||||
/* ---------------------------------------------------------------- */ |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* timers.c |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <sys/time.h> |
||||
|
||||
extern int verbosity; |
||||
|
||||
/* ----------------------------------------------------------------- */ |
||||
static double dtime(void) |
||||
{ |
||||
struct timeval t; |
||||
double d; |
||||
(void)gettimeofday(&t, NULL); |
||||
d = (double)t.tv_sec + (double)t.tv_usec / 1e6; |
||||
return d; |
||||
} |
||||
/* ----------------------------------------------------------------- */ |
||||
|
||||
|
||||
static double memory_time; |
||||
|
||||
double fimg_timer_set(int whot) |
||||
{ |
||||
double current; |
||||
|
||||
current = dtime(); |
||||
|
||||
#if DEBUG_LEVEL |
||||
fprintf(stderr, "%s ( %d ) -> current %f\n", __func__, whot, current); |
||||
#endif |
||||
memory_time = current; |
||||
return memory_time; |
||||
} |
||||
/* ----------------------------------------------------------------- */ |
||||
double fimg_timer_get(int whot) |
||||
{ |
||||
double current; |
||||
current = dtime(); |
||||
return current - memory_time; |
||||
} |
||||
/* ----------------------------------------------------------------- */ |
@ -0,0 +1,29 @@
@@ -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 $@ |
||||
|
@ -0,0 +1,99 @@
@@ -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; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
|
||||
|
@ -0,0 +1,21 @@
@@ -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; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
||||
|
@ -0,0 +1,62 @@
@@ -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; |
||||
} |
@ -0,0 +1,91 @@
@@ -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; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
@ -0,0 +1,41 @@
@@ -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; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
@ -0,0 +1,39 @@
@@ -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; |
||||
} |
||||
/* --------------------------------------------------------------------- */ |
Loading…
Reference in new issue