third massive import batch
This commit is contained in:
24
Tools/Makefile
Normal file
24
Tools/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
#-----------------------------------------------------------------
|
||||
#
|
||||
# Fabrication des outils - nouvelle version 26 juin 2022
|
||||
#
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
include ../Paramakes.mk
|
||||
|
||||
DEPS = ../tthimage.h Makefile
|
||||
|
||||
all: tga_tools
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
fonctions.o: fonctions.c
|
||||
gcc $(CFLAGS) -c $<
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
tga_tools: tga_tools.c $(DEPS) fonctions.o
|
||||
gcc $(CFLAGS) $< ../libimage.a fonctions.o -o $@
|
||||
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
430
Tools/fonctions.c
Normal file
430
Tools/fonctions.c
Normal file
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
T G A _ O U T I L S
|
||||
-------------------
|
||||
|
||||
fonctions communes a tous les outils - new 11 juin 2002
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* non portable but useful function */
|
||||
char *strdup(const char *s);
|
||||
|
||||
#define IN_FONCTION
|
||||
#include "tga_outils.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg)
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
idx = 0;
|
||||
while (liste[idx].nom != NULL)
|
||||
{
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "check %12s %8s\n", liste[idx].nom,
|
||||
liste[idx].ptypes);
|
||||
#endif
|
||||
if ( ! strcmp(liste[idx].nom, mot) )
|
||||
{
|
||||
*pmode = liste[idx].code;
|
||||
*pnbarg = strlen(liste[idx].ptypes);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "found! mode %d nbpar %d\n", *pmode, *pnbarg);
|
||||
sleep(1);
|
||||
#endif
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s : %s not found\n", __func__, mot);
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
liste_mots_clefs(mot_clef *liste, int flag)
|
||||
{
|
||||
mot_clef *pmc;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s ( %p %d )\n", __func__, liste, flag);
|
||||
#endif
|
||||
|
||||
if (42 != flag) {
|
||||
fprintf(stderr, "UH ? flag is not the universal answer ?\n");
|
||||
}
|
||||
|
||||
pmc = liste;
|
||||
|
||||
printf(" commande | type arg | explication\n");
|
||||
printf("------------+----------+------------------------------------\n");
|
||||
while (pmc->nom != NULL)
|
||||
{
|
||||
if (pmc->aide != NULL)
|
||||
printf(" %-10s | %-8s | %s\n",
|
||||
pmc->nom, pmc->ptypes, pmc->aide);
|
||||
pmc++;
|
||||
}
|
||||
printf("------------+----------+------------------------------------\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* INPUT str string to scan for an integer
|
||||
* pval pointer to the retrun value
|
||||
* k * not used *
|
||||
*
|
||||
* OUTPUT 1 successfuly make a conversion
|
||||
* 0 strange error occured :(
|
||||
*/
|
||||
int parse_int_param(char *str, int *pval, int k)
|
||||
{
|
||||
long lfoo;
|
||||
int val;
|
||||
|
||||
val = (int)(lfoo = strtol(str, NULL, 0));
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: %s: '%s' -> %ld -> %d\n",
|
||||
__FILE__, __func__, str, lfoo, val);
|
||||
#endif
|
||||
|
||||
*pval = val;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* input: str string to scan for four csv int
|
||||
prect rectangle struct who need datas
|
||||
k * not used *
|
||||
output 1 all correct
|
||||
2 invalid string
|
||||
27 janvier 2014
|
||||
*/
|
||||
int parse_rect_param(char *str, Image_Rect *prect, int k)
|
||||
{
|
||||
char *cptr;
|
||||
int idx, foo, val;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s '%s' to %p\n", __func__, str, prect);
|
||||
#endif
|
||||
|
||||
if (k) fprintf(stderr, "%s : k is %d, but must be 0\n", __func__, k);
|
||||
|
||||
memset(prect, 0, sizeof(Image_Rect));
|
||||
|
||||
cptr = strdup(str);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stder, "copie dans cptr %p\n", cptr);
|
||||
#endif
|
||||
|
||||
idx = 0;
|
||||
cptr = strtok(cptr, ",");
|
||||
while (NULL != cptr) {
|
||||
fprintf(stderr, "%3d %p = '%s'\n", idx, cptr, cptr);
|
||||
foo = sscanf(cptr, "%d", &val);
|
||||
fprintf(stderr, "val = %d\n", val);
|
||||
switch (idx) {
|
||||
case 0: prect->x = val; break;
|
||||
case 1: prect->y = val; break;
|
||||
case 2: prect->w = val; break;
|
||||
case 3: prect->h = val; break;
|
||||
}
|
||||
cptr = strtok(NULL, ",");
|
||||
idx++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
static Param params[NB_PARAMS];
|
||||
|
||||
int
|
||||
parse_parametres(int argc, char *argv[], char *types, int prem)
|
||||
{
|
||||
int foo, idxt;
|
||||
int entier;
|
||||
double flottant;
|
||||
char *cptr;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Parse params: types '%s' debut %d\n", types, prem);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* init de la table des paramètres.
|
||||
*/
|
||||
for (foo=0; foo<NB_PARAMS; foo++) {
|
||||
params[foo].type = '?';
|
||||
}
|
||||
|
||||
for (foo=prem, idxt=0; foo<argc; foo++, idxt++)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "\t%d/%d\t%c\t%s\n", foo, idxt, types[idxt], argv[foo]);
|
||||
#endif
|
||||
switch (types[idxt])
|
||||
{
|
||||
case 'c':
|
||||
if (strlen(argv[foo])!=1)
|
||||
{
|
||||
fprintf(stderr, "bad length of char param\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "char param = %d\n", *argv[foo]);
|
||||
#endif
|
||||
params[idxt].type = 'c';
|
||||
params[idxt].p.i = *argv[foo];
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
/*
|
||||
* En fait, ici, il serait bon de parser aussi les
|
||||
* parametres donnes en hexadecimal.
|
||||
*/
|
||||
if (parse_int_param(argv[foo], &entier, 0)==1)
|
||||
{
|
||||
params[idxt].type = 'i';
|
||||
params[idxt].p.i = entier;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERR parse int param %s\n", argv[foo]);
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: case 's' : %p\n", __func__, argv[foo]);
|
||||
#endif
|
||||
if ((cptr=strdup(argv[foo]))!=NULL)
|
||||
{
|
||||
params[idxt].type = 's';
|
||||
params[idxt].p.s = cptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERR parse param %s\n", argv[foo]);
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
/* the 'd' is for 'double precision', not for 'decimal' */
|
||||
if (sscanf(argv[foo], "%lf", &flottant)==1)
|
||||
{
|
||||
params[idxt].type = 'd';
|
||||
params[idxt].p.d = flottant;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "at foo=%d, val is %f %g\n",
|
||||
foo, flottant, flottant);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"ERR parse float param %s\n",argv[foo]);
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* the 'f' is for 'flag', not for 'float' */
|
||||
switch(argv[foo][0])
|
||||
{
|
||||
case '0': case 'f': case 'F': case 'n': case 'N':
|
||||
params[idxt].type = 'f';
|
||||
params[idxt].p.i = 0;
|
||||
break;
|
||||
case '1': case 't': case 'T': case 'y': case 'Y':
|
||||
params[idxt].type = 'f';
|
||||
params[idxt].p.i = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "bad flag %s\n", argv[foo]);
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
fprintf(stderr, "'Rect' parser not implemented\n");
|
||||
exit(6);
|
||||
|
||||
default:
|
||||
fprintf(stderr, "partype #%d '%c' invalid\n",
|
||||
idxt, types[idxt]);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* affichage de la liste des parametres trouves */
|
||||
|
||||
void print_parametres(void)
|
||||
{
|
||||
int foo;
|
||||
printf(" +------+-----+\n");
|
||||
printf(" | parameters |\n");
|
||||
printf(" +------+-----+\n");
|
||||
for (foo=0; foo<NB_PARAMS; foo++)
|
||||
{
|
||||
printf(" | %2d | %c |\n", foo, params[foo].type);
|
||||
}
|
||||
printf(" +------+-----+\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* fonctions de récuperation d'un paramètre.
|
||||
*/
|
||||
|
||||
int GIP(int rang)
|
||||
{
|
||||
if (rang<0 || params[rang].type!='i')
|
||||
{
|
||||
fprintf(stderr, "erreur GIP %d\n", rang);
|
||||
exit(5);
|
||||
}
|
||||
return params[rang].p.i;
|
||||
}
|
||||
|
||||
int GCP(int rang)
|
||||
{
|
||||
if (rang<0 || params[rang].type!='c')
|
||||
{
|
||||
fprintf(stderr, "erreur GCP %d\n", rang);
|
||||
exit(5);
|
||||
}
|
||||
return params[rang].p.i;
|
||||
}
|
||||
|
||||
/* get an 'int' parameter with a default value */
|
||||
int GIPdef(int rang, int def)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Warning ! %s is not tested\n", __func__);
|
||||
#endif
|
||||
if (rang<0 || params[rang].type!='i')
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return params[rang].p.i;
|
||||
}
|
||||
|
||||
char * GSP(int rang)
|
||||
{
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "GetStringParameter(%d)\n", rang);
|
||||
#endif
|
||||
if (rang<0 || params[rang].type!='s')
|
||||
{
|
||||
fprintf(stderr, "erreur GSP %d\n", rang);
|
||||
exit(5);
|
||||
}
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "GetStringParameter -> %s\n", params[rang].p.s);
|
||||
#endif
|
||||
return params[rang].p.s;
|
||||
}
|
||||
|
||||
double GDP(int rang)
|
||||
{
|
||||
if (rang<0 || params[rang].type!='d')
|
||||
{
|
||||
fprintf(stderr, "erreur GDP %d\n", rang);
|
||||
exit(5);
|
||||
}
|
||||
return params[rang].p.d;
|
||||
}
|
||||
|
||||
int GFP(int rang)
|
||||
{
|
||||
if (rang<0 || params[rang].type!='f')
|
||||
{
|
||||
fprintf(stderr, "erreur GFP %d\n", rang);
|
||||
exit(5);
|
||||
}
|
||||
return params[rang].p.i;
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
must_be_verbose(void)
|
||||
{
|
||||
char *envvar;
|
||||
|
||||
envvar = getenv(NOM_VAR_ENV_VERBOSE);
|
||||
if ((envvar!=NULL) && !strcmp(envvar, "yes"))
|
||||
{
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "HA HA HA ! pid:%d MUST BE VERBOSE !\n", getpid());
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
dump_command_line(int argc, char *argv[], int force)
|
||||
{
|
||||
char *envvar;
|
||||
int flag=0, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %s, argc=%d\n", __func__, argv[0], argc);
|
||||
#endif
|
||||
|
||||
envvar = getenv(NOM_VAR_ENV_VERBOSE);
|
||||
if ( (envvar!=NULL) && !strcmp(envvar, "yes") ) flag = 1;
|
||||
|
||||
if (flag || force)
|
||||
{
|
||||
fprintf(stderr, "TGA(%d) %d arg:", getpid(), argc);
|
||||
for (foo=0; foo<argc; foo++)
|
||||
fprintf(stderr, " %s", argv[foo]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int set_new_seed(int k)
|
||||
{
|
||||
char *ptr;
|
||||
long seed;
|
||||
|
||||
if (NULL==(ptr=getenv("FIXED_SEED"))) {
|
||||
/* no fixed seed in context, doing semi-random */
|
||||
srand(getpid());
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "no FIXED_SEED, first rand is number : %d\n", rand());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
/* try to parse the env var */
|
||||
seed = strtol(ptr, NULL, 0);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : strtol(%s) -> %ld\n",
|
||||
__func__, ptr, seed);
|
||||
#endif
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
return rand();
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
102
Tools/tga_outils.h
Normal file
102
Tools/tga_outils.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
tga_outils.h
|
||||
------------
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
#define TGA_OUTILS_VERSION "0.58"
|
||||
/*
|
||||
* 13 Dec 2001: v0.11 a cause du 'mustopen' pour les palettes.
|
||||
* 11 Fev 2002: v0.12 a cause du '-ansi' (hein Kerdeuzz, on y vient)
|
||||
* 21 Nov 2002: v0.13 a cause du parser de paramètres.
|
||||
* 14 Jan 2006: v0.14 parce que je remet le truc dans le net.
|
||||
* 05 Jan 2007: v0.15 pour etre synchrone avec la doc.
|
||||
* 11 Dec 2007: v0.22 pour le parser de parametres (hexadecimal)
|
||||
* 05 May 2009: v0.36 grand nettoyage du code en chantier
|
||||
* 27 Dec 2009: v0.42 prise en compte des champs d'altitude.
|
||||
* 06 Mar 2010: v0.43 introduction du 'df3 tool'.
|
||||
* 27 Jan 2014: V0.52 added : 'parse_rect_param'.
|
||||
*/
|
||||
|
||||
#define TGA_OUTILS_COPYLEFT "(dwtfywl) TontonTh 2018"
|
||||
#define TGA_WWW_SITE "http://la.buvette.org/devel/libimage/"
|
||||
|
||||
#define PERR(txt) fprintf(stderr, "\t| %s\n", (txt))
|
||||
#define PERL fprintf(stderr, "\t+-----------------------------------------\n")
|
||||
|
||||
#define NOM_VAR_ENV_VERBOSE "TGA_OUTILS_VERBOSE" /* flag ON = "yes" */
|
||||
#define NOM_VAR_ENV_TIMING "TGA_OUTILS_TIMING" /* flag ON = "yes" */
|
||||
|
||||
int must_be_verbose(void);
|
||||
int set_new_seed(int k);
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* structure de description d'un mot-clef
|
||||
* --------------------------------------
|
||||
*
|
||||
* types des parametres (chaine pointée par ptype)
|
||||
*
|
||||
* i entier 32 bits / char parameter
|
||||
* s chaine de caractères
|
||||
* d double flottant
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *nom;
|
||||
int code;
|
||||
char *ptypes; /* type des paramètres */
|
||||
char *aide;
|
||||
char *longhelp;
|
||||
} mot_clef;
|
||||
|
||||
#define NB_PARAMS 16 /* max number of allowed parameters */
|
||||
|
||||
/*
|
||||
* structure contenant un paramètre.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char type;
|
||||
union
|
||||
{
|
||||
int i;
|
||||
char *s;
|
||||
double d;
|
||||
} p;
|
||||
} Param;
|
||||
|
||||
int cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg);
|
||||
|
||||
/* le flag ne sert a rien, mais il faut le mettre a 42 */
|
||||
int liste_mots_clefs(mot_clef *liste, int flag);
|
||||
|
||||
int parse_int_param(char *str, int *pval, int k);
|
||||
int parse_rect_param(char *str, Image_Rect *prect, int k);
|
||||
|
||||
int parse_parametres(int ac, char *av[], char *types, int prem);
|
||||
void print_parametres(void);
|
||||
|
||||
int GIP(int rang);
|
||||
int GCP(int rang);
|
||||
int GIPdef(int rang, int def);
|
||||
char * GSP(int rang);
|
||||
double GDP(int rang);
|
||||
int GFP(int rang); /* get flag */
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* fonctions de bavardage
|
||||
*/
|
||||
int dump_command_line(int argc, char *argv[], int force);
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* pour plus de details, for more informations
|
||||
* http://la.buvette.org/devel/libimage/img-outils.html
|
||||
* ----------------------------------------------------
|
||||
*/
|
||||
|
||||
402
Tools/tga_tools.c
Normal file
402
Tools/tga_tools.c
Normal file
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* TGA_TOOLS
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tga_outils.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
#define VERSION 1
|
||||
#define SURFACE 2
|
||||
#define GETDIMS 4
|
||||
#define GETDIMX 5
|
||||
#define GETDIMPOV 6
|
||||
#define GETDIMW 7
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 9
|
||||
#define MK_RGB 10 /* new 22 jan 2014 */
|
||||
#define MK_NOISE 11 /* new 07 fev 2014 */
|
||||
#define GRMINMAX 17 /* min & max in gray level */
|
||||
#define MESSAGE 20
|
||||
#define STRUCTS 21
|
||||
#define HEADER 33
|
||||
#define TIMESTAMP 34
|
||||
#define PRHISTO 35
|
||||
#define TAG7SEG0 40
|
||||
|
||||
#define ENVIRON 50
|
||||
/*::------------------------------------------------------------------::*/
|
||||
mot_clef commandes[] =
|
||||
{
|
||||
{ "version", VERSION, "", "version de la libimage" },
|
||||
{ "surface", SURFACE, "s", "number of pixels" },
|
||||
{ "getdims", GETDIMS, "s", "dim targa '42 33'" },
|
||||
{ "getdimx", GETDIMX, "s", "dim targa '42x33'" },
|
||||
{ "getdimpov", GETDIMPOV, "s", "dim au format POV opt" },
|
||||
{ "getdimweb", GETDIMW, "s", "dim au format HTML" },
|
||||
{ "width", WIDTH, "s", "width of targa" },
|
||||
{ "height", HEIGHT, "s", "height of targa" },
|
||||
{ "grminmax", GRMINMAX, "si", "image.tga K" },
|
||||
{ "message", MESSAGE, "sis", "tgafname flags 'baratin bla'" },
|
||||
{ "structs", STRUCTS, "", "display sizeof structs" },
|
||||
{ "header", HEADER, "s", "filename of image" },
|
||||
{ "timestamp", TIMESTAMP, "ss", "filename message" },
|
||||
{ "prhisto", PRHISTO, "s", "filename.tga" },
|
||||
{ "tag7", TAG7SEG0, "si", "fname.tga nnn" },
|
||||
{ "environ", ENVIRON, "", "" },
|
||||
{ "mk_rgb", MK_RGB, "siiiii", "fname w h r g b" },
|
||||
};
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
print_tga_dims(char *filename, int flags)
|
||||
{
|
||||
int foo, width, height;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s:%d %s ( %s, %d )\n", __FILE__, __LINE__,
|
||||
__func__, filename, flags);
|
||||
#endif
|
||||
foo = Image_TGA_get_dims(filename, &width, &height);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "something is bad with %s : %d\n", filename, foo);
|
||||
Image_print_error("explanation", foo);
|
||||
}
|
||||
|
||||
switch(flags)
|
||||
{
|
||||
case 0:
|
||||
printf("%8d %8d\n", width, height);
|
||||
break;
|
||||
case 1:
|
||||
printf("%dx%d\n", width, height);
|
||||
break;
|
||||
case 2:
|
||||
printf(" -w%d -h%d\n", width, height);
|
||||
break;
|
||||
case 3:
|
||||
printf("width=%d height=%d\n", width, height);
|
||||
break;
|
||||
case 4:
|
||||
printf("%d\n", width);
|
||||
break;
|
||||
case 5:
|
||||
printf("%d\n", height);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "bad flag %d in %s\n", flags, __func__);
|
||||
abort();
|
||||
break; /* unreached ? */
|
||||
}
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int showheader(char *filename, int flag)
|
||||
{
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Show Header '%s' %d\n", filename, flag);
|
||||
#endif
|
||||
|
||||
foo = Image_TGA_show_header(filename, 0);
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s got %d\n", __func__, foo);
|
||||
#endif
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int make_a_rgb_tga(char *fname, int w, int h, int r, int g, int b)
|
||||
{
|
||||
Image_Desc *img;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s -> %s : %dx%d, rgb %d,%d,%d\n", __func__, fname, w, h,
|
||||
r, g, b);
|
||||
#endif
|
||||
|
||||
if (w < 1 || h < 1)
|
||||
{
|
||||
fprintf(stderr, "%s : img dims %d %d ?\n", __func__, w, h);
|
||||
return 666;
|
||||
}
|
||||
img = Image_alloc(w, h, 3);
|
||||
Image_clear(img, r, g, b);
|
||||
foo = Image_TGA_save(fname, img, 0);
|
||||
|
||||
return 666;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int timestamp(char *fnin, char *fnout, char *txt, int flag)
|
||||
{
|
||||
int foo;
|
||||
Image_Desc *src;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "timestamping '%s' to '%s' with '%s'\n", fnin, fnout, txt);
|
||||
#endif
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
|
||||
fnin, __func__);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
foo = Image_marque_timestamp(src, txt, NULL, 0);
|
||||
#if DEBUG_LEVEL
|
||||
if (foo)
|
||||
Image_print_error("marque timestamp --> ", foo);
|
||||
#endif
|
||||
|
||||
Image_TGA_save(fnout, src, 0);
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int marque_message(char *fnin, char *fnout, char *txt, int flag)
|
||||
{
|
||||
int foo, posx, posy;
|
||||
Image_Desc *src;
|
||||
RGBA ink, pap;
|
||||
|
||||
/* some sane default values */
|
||||
ink.r = 255, ink.g = 255, ink.b = 100; ink.a = 255;
|
||||
pap.r = 30, pap.g = 30, pap.b = 155; pap.a = 255;
|
||||
posx = posy = 6;
|
||||
if (flag) {
|
||||
ink.r = 200, ink.g = 200, ink.b = 200; ink.a = 255;
|
||||
pap.r = 0, pap.g = 0, pap.b = 0; pap.a = 127;
|
||||
posx = posy = 0;
|
||||
}
|
||||
|
||||
if (must_be_verbose())
|
||||
fprintf(stderr, "%s:\n '%s' to '%s' with '%s' flg %d\n", \
|
||||
__func__, fnin, fnout, txt, flag);
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
|
||||
fnin, __func__);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
foo = Image_txt1_box_0(src, txt, posx, posy, 4, &pap, &ink, 0);
|
||||
Image_TGA_save(fnout, src, 0);
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : saving %s\n", __func__, fnout);
|
||||
#endif
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int print_histogramme(char *filename, int flags)
|
||||
{
|
||||
Image_Desc *src;
|
||||
long hr[256], hg[256], hb[256];
|
||||
int foo;
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(filename)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_tools, chargement '%s' failed\n", filename);
|
||||
exit(5);
|
||||
}
|
||||
foo = Image_histo_RGB(src, hr, hb, hg);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_tools, calcul histogramme: %d %s\n",
|
||||
foo, Image_err2str(foo));
|
||||
exit(5);
|
||||
}
|
||||
|
||||
for (foo=0; foo<256; foo++)
|
||||
{
|
||||
printf("%3d %8ld %8ld %8ld\n", foo, hr[foo], hg[foo], hb[foo]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 27 mars 2008 - avenue St Exupery */
|
||||
int print_environ(void)
|
||||
{
|
||||
int foo;
|
||||
char *ptr;
|
||||
char *noms[] =
|
||||
{
|
||||
NOM_VAR_ENV_VERBOSE, NOM_VAR_ENV_TIMING, "LIBIMAGE_PATH",
|
||||
"TTH_CONF_DIR", "LIBIMAGE_DEBUG", "BITMAP_FONTS",
|
||||
"FIXED_SEED", ENV_DEFAULT_RGBA
|
||||
};
|
||||
|
||||
for (foo=0; foo<(sizeof(noms)/sizeof(char *)); foo++)
|
||||
{
|
||||
ptr = getenv(noms[foo]);
|
||||
printf("%5d %-25s %s\n", foo, noms[foo], ptr);
|
||||
}
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int tag_7_segments_0(char *fname, int value)
|
||||
{
|
||||
int foo;
|
||||
Image_Desc *src;
|
||||
char buffer[100];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s:%s %s %d\n", __FILE__, __func__, fname, value);
|
||||
#endif
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(fname)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
|
||||
fname, __func__);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
sprintf(buffer, "%04d", value);
|
||||
foo = Image_7seg_tag0(src, buffer, 0);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : tagging %s -> %d\n", __func__, fname, foo);
|
||||
#endif
|
||||
|
||||
foo = Image_TGA_save(fname, src, 0);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s : saving %s -> %d\n", __func__, fname, foo);
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
int idx, mode, nbarg;
|
||||
char * cptr;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
|
||||
/* new 4 feb 2014 */
|
||||
foo = set_new_seed(42);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "set new seed -> %d\n", foo);
|
||||
#endif
|
||||
|
||||
if (1 == argc)
|
||||
{
|
||||
fprintf(stderr, "* tga_tools v 0.1.31 (%s) *\n", __DATE__);
|
||||
fprintf(stderr, "usage:\n\t%s action f.tga [params]\n", argv[0]);
|
||||
liste_mots_clefs(commandes, 42);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (-1 == (idx=cherche_mot_clef(argv[1], commandes, &mode, &nbarg)) )
|
||||
{
|
||||
fprintf(stderr, "action '%s' inconnue.\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s commande: idx=%d mode=%d nbarg=%d\n",
|
||||
argv[0], idx, mode, nbarg);
|
||||
#endif
|
||||
|
||||
#define FIRST_PARAM 2
|
||||
foo = parse_parametres(argc, argv, commandes[idx].ptypes, FIRST_PARAM);
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case VERSION:
|
||||
printf("Version des outils: %s ", TGA_OUTILS_VERSION);
|
||||
printf("- %s, %s\n", __DATE__, __TIME__);
|
||||
printf("%s is the swiss knife for Targa files\n", argv[0]);
|
||||
Image_print_version(2);
|
||||
break;
|
||||
case GETDIMS:
|
||||
cptr = GSP(0);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "GETDIMS %s\n", cptr);
|
||||
#endif
|
||||
foo = print_tga_dims(cptr, 0);
|
||||
break;
|
||||
case GETDIMX:
|
||||
cptr = GSP(0);
|
||||
foo = print_tga_dims(cptr, 1);
|
||||
break;
|
||||
case GETDIMPOV:
|
||||
cptr = GSP(0);
|
||||
foo = print_tga_dims(cptr, 2);
|
||||
break;
|
||||
case GETDIMW:
|
||||
cptr = GSP(0);
|
||||
foo = print_tga_dims(cptr, 3);
|
||||
break;
|
||||
case WIDTH:
|
||||
foo = print_tga_dims(GSP(0), 4);
|
||||
break;
|
||||
case HEIGHT:
|
||||
foo = print_tga_dims(GSP(0), 5);
|
||||
break;
|
||||
|
||||
case HEADER:
|
||||
foo = showheader(GSP(0), 0);
|
||||
break;
|
||||
|
||||
case PRHISTO:
|
||||
foo = print_histogramme(GSP(0), 0);
|
||||
break;
|
||||
case TIMESTAMP:
|
||||
cptr = GSP(0);
|
||||
foo = timestamp(cptr, GSP(0), GSP(1), 0);
|
||||
break;
|
||||
case MK_RGB:
|
||||
cptr = GSP(0);
|
||||
fprintf(stderr, "MK_RGB -> %s\n", cptr);
|
||||
foo = make_a_rgb_tga(cptr, GIP(1), GIP(2),
|
||||
GIP(3), GIP(4), GIP(5));
|
||||
break;
|
||||
case MK_NOISE:
|
||||
cptr = GSP(0);
|
||||
fprintf(stderr, "MK_NOISE -> %s\n", cptr);
|
||||
foo = make_a_rgb_tga(cptr, GIP(1), GIP(2),
|
||||
GIP(3), GIP(4), GIP(5));
|
||||
break;
|
||||
case TAG7SEG0:
|
||||
foo = tag_7_segments_0(GSP(0), GIP(1));
|
||||
break;
|
||||
|
||||
case MESSAGE:
|
||||
cptr = GSP(0);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "marque message %p\n", cptr);
|
||||
#endif
|
||||
foo = marque_message(cptr, GSP(0), GSP(2), GIP(1));
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "marque message -> %d\n\n", foo);
|
||||
#endif
|
||||
break;
|
||||
case STRUCTS:
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "going to 'Image_print_sizeof_structs'\n");
|
||||
#endif
|
||||
Image_print_sizeof_structs(NULL);
|
||||
break;
|
||||
case ENVIRON:
|
||||
foo = print_environ();
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Hu ho %d ?\n", mode);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
Reference in New Issue
Block a user