add tga_extract

This commit is contained in:
tTh 2023-09-12 18:19:12 +02:00
parent d260117865
commit bef1c6c5e3
4 changed files with 112 additions and 3 deletions

2
Tools/.gitignore vendored
View File

@ -2,3 +2,5 @@
*.tga *.tga
*.scratch *.scratch
tga_extract

View File

@ -10,7 +10,7 @@ DEPS = ../tthimage.h Makefile tga_outils.h ../libtthimage.a
all: genplot2 \ all: genplot2 \
tga_cadre tga_effects tga_filtres tga_remap tga_tools \ 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_television tga_dither tga_applymap tga_makehf15 \
tga_mires tga_incrust tga_pattern tga_equalize 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 tga_incrust: tga_incrust.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -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 # tga_info: tga_info.c $(DEPS) fonctions.o
# gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ # gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@

103
Tools/tga_extract.c Normal file
View File

@ -0,0 +1,103 @@
/*
TGA EXTRACTOR
-------------
http://www.chez.com/oulala/libimage/
*/
#include <stdio.h>
#include <stdlib.h>
#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;
}
/*::------------------------------------------------------------------::*/

View File

@ -1,10 +1,10 @@
/* /*
tthimage.h tthimage.h
---------- ----------
http:///la.buvette.org/devel/libimage/ http://la.buvette.org/devel/libimage/
*/ */
#ifndef IMAGE_VERSION_STRING #ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 43" #define IMAGE_VERSION_STRING "0.4.51 pl 46"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*