first shoot

This commit is contained in:
Tonton Th
2019-03-03 16:22:55 +01:00
commit 5a72327882
25 changed files with 1480 additions and 0 deletions

22
funcs/Makefile Normal file
View File

@@ -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 $<

17
funcs/filtrage.c Normal file
View File

@@ -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;
}
/* -------------------------------------------------------------------- */

162
funcs/fimg-png.c Normal file
View File

@@ -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;
}
/* --------------------------------------------------------------------- */

12
funcs/fimg-tiff.c Normal file
View File

@@ -0,0 +1,12 @@
/*
* FLOATIMG
* import/export to/from TIFF files
*/
#include <stdio.h>
#include "../floatimg.h"
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

57
funcs/misc-plots.c Normal file
View File

@@ -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;
}
/* --------------------------------------------------------------------- */