diff --git a/Tools/.gitignore b/Tools/.gitignore index b6515ce..5da6fce 100644 --- a/Tools/.gitignore +++ b/Tools/.gitignore @@ -3,4 +3,4 @@ *.scratch tga_extract - +tga_to_text diff --git a/Tools/Makefile b/Tools/Makefile index 521158a..ec5ea30 100644 --- a/Tools/Makefile +++ b/Tools/Makefile @@ -28,6 +28,9 @@ genplot2: genplot2.c $(DEPS) fonctions.o #----------------------------------------------------------------- +tga_to_text: tga_to_text.c $(DEPS) fonctions.o + gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ + tga_alpha: tga_alpha.c $(DEPS) fonctions.o gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ diff --git a/Tools/tga_to_text.c b/Tools/tga_to_text.c new file mode 100644 index 0000000..7fb3935 --- /dev/null +++ b/Tools/tga_to_text.c @@ -0,0 +1,58 @@ +/* + * TGA to text + * =========== + * new: Mon Feb 26 23:21:21 UTC 2024 + */ + +#include +#include +#include + +#include "tga_outils.h" + +/*::------------------------------------------------------------------::*/ + +int printf_this_picture(Image_Desc *pic, int flag) +{ +int x, y, r, g, b; + +if (flag) { + /* needed for easy import in R */ + printf(" X Y R G B\n"); + } + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + printf("%5d %5d ", x, y); + Image_getRGB(pic, x, y, &r, &g, &b); + printf("%4d %4d %4d\n", r, g, b); + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +int main (int argc, char *argv[]) +{ +Image_Desc *src; +int foo; + +if (2!=argc) { + fprintf(stderr, "%s need a filename\n", argv[0]); + exit(2); + } + +if ((src = Image_TGA_alloc_load(argv[1]))==NULL) { + fprintf(stderr, "TGA to text: can't load image %s\n", argv[1]); + exit(5); + } + +foo = printf_this_picture(src, 0); +if (foo) { + fprintf(stderr, "printf_this_picture -> %d\n", foo); + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +