From bef1c6c5e3a176445b964ed2a14fe953467e46f9 Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 12 Sep 2023 18:19:12 +0200 Subject: [PATCH] add tga_extract --- Tools/.gitignore | 2 + Tools/Makefile | 6 ++- Tools/tga_extract.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ tthimage.h | 4 +- 4 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 Tools/tga_extract.c diff --git a/Tools/.gitignore b/Tools/.gitignore index a9f7543..b6515ce 100644 --- a/Tools/.gitignore +++ b/Tools/.gitignore @@ -2,3 +2,5 @@ *.tga *.scratch +tga_extract + diff --git a/Tools/Makefile b/Tools/Makefile index cf3c85d..f0d69dc 100644 --- a/Tools/Makefile +++ b/Tools/Makefile @@ -10,7 +10,7 @@ DEPS = ../tthimage.h Makefile tga_outils.h ../libtthimage.a all: genplot2 \ tga_cadre tga_effects tga_filtres tga_remap tga_tools \ - tga_combine tga_export tga_alpha \ + tga_combine tga_export tga_alpha tga_extract \ tga_television tga_dither tga_applymap tga_makehf15 \ tga_mires tga_incrust tga_pattern tga_equalize @@ -73,6 +73,10 @@ tga_tools: tga_tools.c $(DEPS) fonctions.o tga_incrust: tga_incrust.c $(DEPS) fonctions.o gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ +tga_extract: tga_extract.c $(DEPS) fonctions.o + gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ + + # tga_info: tga_info.c $(DEPS) fonctions.o # gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ diff --git a/Tools/tga_extract.c b/Tools/tga_extract.c new file mode 100644 index 0000000..10e278d --- /dev/null +++ b/Tools/tga_extract.c @@ -0,0 +1,103 @@ +/* + TGA EXTRACTOR + ------------- + http://www.chez.com/oulala/libimage/ +*/ + +#include +#include + +#include "tga_outils.h" + +/*::------------------------------------------------------------------::*/ +void usage(void) +{ +fprintf(stderr, "* TGA extractor v 0.0.12 [%s] %s \n", + TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT); +fprintf(stderr, "usage:\n"); +fprintf(stderr, " $ tga_extract source.tga resultat.tga X Y W H\n\n"); +Image_print_version(0); +fprintf(stderr, "\n"); +exit(1); +} +/*::------------------------------------------------------------------::*/ + +#define X 0 +#define Y 1 +#define W 2 +#define H 3 + +int main(int argc, char *argv[]) +{ +Image_Desc *image, *resultat; +int foo, coords[4]; +Image_Rect rect; + +dump_command_line(argc, argv, 0); + +if ( argc != 7 ) { + fprintf(stderr, "argc=%d\n", argc); + usage(); + } + +/* decode and check parameters */ +for (foo=0; foo<4; foo++) { + if ( sscanf(argv[foo+3], "%d", &coords[foo]) != 1 ) { + fprintf(stderr, " '%s' oikk?!\n", argv[foo+3]); + usage(); + } + } + +if ( (coords[X]<0) || (coords[Y]<0) || (coords[W]<0) || (coords[H]<0) ) + { + fprintf(stderr, "%s: no negative parameter, please.\n", argv[0]); + exit(1); + } +if (coords[X]>16000 || coords[Y]>16000 || coords[W]>16000 || coords[H]>16000) + { + fprintf(stderr, "%s: no overburned parameter, please.\n", argv[0]); + exit(1); + } + +/* load the source image ... */ +if ( (image=Image_TGA_alloc_load(argv[1])) == NULL ) { + fprintf(stderr, "%s: no mem for input image '%s'\n", argv[0], argv[1]); + exit(1); + } + +if (must_be_verbose()) { + /* ... so we know source dimensions */ + fprintf(stderr, "tga_extract: src '%s': %d x %d\n", + argv[1], image->width, image->height); + } + +if ( (resultat=Image_alloc(coords[W], coords[H], 3)) == NULL ) { + fprintf(stderr, "%s: no mem for ouput image\n", argv[0]); + exit(1); + } + +rect.x = coords[X]; rect.y = coords[Y]; +rect.w = coords[W]; rect.h = coords[H]; + +foo = Image_get_rect(image, &rect, resultat, 0, 0); if (foo) + { + fprintf(stderr, "tga_extract: get_rect: err %d %s\n", + foo, Image_err2str(foo)); + exit(2); + } +if (must_be_verbose()) { + fprintf(stderr, "tga_extract: dst '%s': %dx%d @%d,%d\n", + argv[2], resultat->width, resultat->height, + rect.x, rect.y); + } + +foo = Image_TGA_save(argv[2], resultat, 0); +if (foo) { + fprintf(stderr, "tga_extract: %s save err %d %s\n", + argv[2], foo, Image_err2str(foo)); + exit(2); + } + +return 0; +} +/*::------------------------------------------------------------------::*/ diff --git a/tthimage.h b/tthimage.h index ffc131f..46bee1c 100644 --- a/tthimage.h +++ b/tthimage.h @@ -1,10 +1,10 @@ /* tthimage.h ---------- - http:///la.buvette.org/devel/libimage/ + http://la.buvette.org/devel/libimage/ */ #ifndef IMAGE_VERSION_STRING - #define IMAGE_VERSION_STRING "0.4.51 pl 43" + #define IMAGE_VERSION_STRING "0.4.51 pl 46" /*::------------------------------------------------------------------::*/ /*