Browse Source

I can now write PNG files :)

master
Tonton Th 3 years ago
parent
commit
8ce9251dec
  1. 1
      .gitignore
  2. 2
      floatimg.h
  3. 2
      funcs/Makefile
  4. 53
      funcs/fimg-png.c
  5. 21
      funcs/t.c
  6. 1
      install.sh
  7. 2
      tools/Makefile
  8. 52
      tools/fimg2png.c
  9. 2
      v4l2/Makefile

1
.gitignore vendored

@ -26,6 +26,7 @@ doc/*.ilg @@ -26,6 +26,7 @@ doc/*.ilg
doc/*.ind
funcs/t
funcs/*.png
scripts/*.fimg
scripts/*.pnm

2
floatimg.h

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 80
#define FIMG_VERSION 81
/*
* in memory descriptor

2
funcs/Makefile

@ -8,7 +8,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ @@ -8,7 +8,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
#---------------------------------------------------------------
t: t.c $(DEPS) ../libfloatimg.a
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -o $@
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lm -o $@
#---------------------------------------------------------------

53
funcs/fimg-png.c

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
/*
* Lecture des images PNG
* L'ecriture est en chantier :}
*/
#include <stdio.h>
@ -175,13 +176,59 @@ png_close_file(&png); @@ -175,13 +176,59 @@ png_close_file(&png);
return 0;
}
/* --------------------------------------------------------------------- */
/* nouveau 13 decembre 2019 */
int fimg_save_as_png(FloatImg *src, char *outname, int flags)
{
png_t png;
png_t png;
int foo, sz, idx;
unsigned char *bytes, *bptr;
double maximum, fk;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %-25s ( %p '%s' %x )\n", __func__, src, outname, flags);
#endif
/* convert ou floating datas to a byte/rgb array */
/* first, alloc a buffer */
sz = src->width * src->height;
bytes = calloc(sz, 3);
if (NULL==bytes) {
fprintf(stderr, "%s : no mem ?\n", __func__);
exit(3);
}
/* compute max value */
maximum = (double)fimg_get_maxvalue(src);
fk = maximum / 255.0;
fprintf(stderr, " max values %g fk %g\n", maximum, fk);
/* massage des pixels */
bptr = bytes;
for (idx=0; idx<sz; idx++) {
*bptr++ = (unsigned char) (src->R[idx] / fk);
*bptr++ = (unsigned char) (src->G[idx] / fk);
*bptr++ = (unsigned char) (src->B[idx] / fk);
}
memset(&png, 0, sizeof(png_t));
png_init(NULL, NULL); /* this is VITAL ! */
return -1;
foo = png_open_file_write(&png, outname);
if (PNG_NO_ERROR != foo) {
fprintf(stderr, "error in '%s' : open_file_write -> %d\n",
__func__, foo);
return foo;
}
foo = png_set_data(&png, src->width, src->height, 8, PNG_TRUECOLOR, bytes);
if (PNG_NO_ERROR != foo) {
fprintf(stderr, "error in '%s' : set_data -> %d\n",
__func__, foo);
return foo;
}
png_close_file(&png);
free(bytes); /* yolo ? */
return 0;
}
/* --------------------------------------------------------------------- */

21
funcs/t.c

@ -48,6 +48,23 @@ printf("%-10s %d\n\n", fname, foo); @@ -48,6 +48,23 @@ printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.xyzzy");
printf("%-10s %d\n\n", fname, foo);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_ecrire_png(char *fname)
{
FloatImg fimg;
int foo;
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
for (foo=0; foo<512; foo++) {
fimg_plot_rgb(&fimg, foo, foo, 17000.0, 8000.0, 11111.1);
}
fimg_save_as_pnm(&fimg, "quux.pnm", 0);
foo = fimg_save_as_png(&fimg, fname, 0);
return 0;
}
/* --------------------------------------------------------------------- */
@ -55,7 +72,9 @@ int main(int argc, char *argv[]) @@ -55,7 +72,9 @@ int main(int argc, char *argv[])
{
int foo;
foo = essai_detect_type();
puts("++++++++++++++++++++++++++++++++");
foo = essai_ecrire_png("dessin.png");
return 0;
}

1
install.sh

@ -4,6 +4,7 @@ cp libfloatimg.a /usr/local/lib @@ -4,6 +4,7 @@ cp libfloatimg.a /usr/local/lib
cp floatimg.h /usr/local/include
cp tools/mkfimg tools/fimg2pnm tools/fimgops \
tools/fimg2png \
tools/png2fimg tools/fimgstats tools/fimgfx \
/usr/local/bin

2
tools/Makefile

@ -30,7 +30,7 @@ fimg2pnm: fimg2pnm.c $(DEPS) @@ -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 $@

52
tools/fimg2png.c

@ -1,13 +1,56 @@ @@ -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) { @@ -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;
}
/* --------------------------------------------------------------------- */
/* ----------------------------------------------------------------- */

2
v4l2/Makefile

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
DEPS = ../floatimg.h ../libfloatimg.a Makefile
all: grabvidseq t

Loading…
Cancel
Save