six more tools added...

This commit is contained in:
tth 2022-06-27 23:39:52 +02:00
parent 4ce5241411
commit 99c3ee1166
11 changed files with 822 additions and 4 deletions

6
.gitignore vendored
View File

@ -10,8 +10,14 @@ Lib/testtga
Lib/t_t16x24 Lib/t_t16x24
Tools/tga_cadre Tools/tga_cadre
Tools/tga_dither
Tools/tga_tools Tools/tga_tools
Tools/tga_effects Tools/tga_effects
Tools/tga_filtres Tools/tga_filtres
Tools/tga_remap
Tools/tga_television Tools/tga_television
Tools/genplot2
Tools/tga_applymap
Tools/tga_makehf15
Tools/tga_mires

View File

@ -6,10 +6,11 @@
include ../Paramakes.mk include ../Paramakes.mk
DEPS = ../tthimage.h Makefile DEPS = ../tthimage.h Makefile tga_outils.h
all: tga_cadre tga_effects tga_filtres tga_tools \ all: tga_cadre tga_effects tga_filtres tga_remap tga_tools \
tga_television tga_television tga_dither tga_applymap tga_makehf15 \
tga_mires
#----------------------------------------------------------------- #-----------------------------------------------------------------
@ -18,15 +19,35 @@ fonctions.o: fonctions.c $(DEPS)
#----------------------------------------------------------------- #-----------------------------------------------------------------
genplot2: genplot2.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
#-----------------------------------------------------------------
tga_applymap: tga_applymap.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_cadre: tga_cadre.c $(DEPS) fonctions.o tga_cadre: tga_cadre.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_dither: tga_dither.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_effects: tga_effects.c $(DEPS) fonctions.o tga_effects: tga_effects.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_filtres: tga_filtres.c $(DEPS) fonctions.o tga_filtres: tga_filtres.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_makehf15: tga_makehf15.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_mires: tga_mires.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_remap: tga_remap.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_television: tga_television.c $(DEPS) fonctions.o tga_television: tga_television.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@

View File

@ -90,6 +90,8 @@ int parse_int_param(char *str, int *pval, int k)
long lfoo; long lfoo;
int val; int val;
if (k) fprintf(stderr, "%s: k %d\n", __func__, k);
val = (int)(lfoo = strtol(str, NULL, 0)); val = (int)(lfoo = strtol(str, NULL, 0));
#if DEBUG_LEVEL #if DEBUG_LEVEL
@ -408,6 +410,8 @@ int set_new_seed(int k)
char *ptr; char *ptr;
long seed; long seed;
if (k) fprintf(stderr, "%s: k %d\n", __func__, k);
if (NULL==(ptr=getenv("FIXED_SEED"))) { if (NULL==(ptr=getenv("FIXED_SEED"))) {
/* no fixed seed in context, doing semi-random */ /* no fixed seed in context, doing semi-random */
srand(getpid()); srand(getpid());

180
Tools/genplot2.c Normal file
View File

@ -0,0 +1,180 @@
/*
Bon, c'est tres bien tout c,a mais il faudrait
faire une page de man pour expliquer comment
ce machin fonctionne...
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
#define XMIN 0
#define YMIN 0
#define XMAX 4096 /* constant from a 'dddd' */
#define YMAX 4096 /* constant from a 'dddd' */
/*::------------------------------------------------------------------::*/
static Image_Desc *image;
static RGB_map map;
static int curX, curY;
/*::------------------------------------------------------------------::*/
int initgr(int largeur, int hauteur)
{
int foo, r, v, b, dummy;
if ((image=Image_alloc(largeur, hauteur, 3))==NULL)
{
fprintf(stderr, "hu hu, 'man addswap' :)\n");
exit(3);
}
printf("\n\tinitgr %d %d\n", largeur, hauteur);
for (foo=0; foo<8; foo++)
{
printf("\tPal(%d) = ", foo);
r = foo & 1 ? 255 : 0;
v = foo & 2 ? 255 : 0;
b = foo & 4 ? 255 : 0;
printf("%02X %02X %02X\n", r, v, b);
map.red[foo] = r;
map.green[foo] = v;
map.blue[foo] = b;
}
map.nbre = 8;
return 0;
}
/*::------------------------------------------------------------------::*/
int move(int x, int y)
{
#if DEBUG_LEVEL
printf("\tMOVE %5d %5d\n", x, y);
#endif
curX = x; curY = y;
return 0;
}
int draw(int x, int y, int color)
{
RGBA rgba;
int idx;
#if DEBUG_LEVEL
printf("\tDRAW %5d %5d to %5d %5d\n", curX, curY, x, y);
#endif
idx = color % 8;
if (idx != color) {
fprintf(stderr, "%s %s : color %d out of range\n",
__FILE__, __func__, color);
}
rgba.r = map.red[color];
rgba.g = map.green[color];
rgba.b = map.blue[color];
Image_draw_line(image, curX, curY, x, y, &rgba);
curX = x; curY = y;
return 0;
}
/*::------------------------------------------------------------------::*/
int endgr(char *filename)
{
fprintf(stderr, "saving '%s'\n", filename);
Image_TGA_save(filename, image, 0);
return 0;
}
/*::------------------------------------------------------------------::*/
int main(int argc, char *argv[])
{
char *filename, *image;
FILE *fp;
double x, y, xmin, ymin, xmax, ymax;
double fx, fy, f, X, Y;
double xC, yC, XC, YC, c1, c2;
int v, nbp;
/*---------- processing command line arguments */
if (argc<=1) filename = "a.scratch";
else filename = argv[1];
if (argc<=2) image = "image.tga";
else image = argv[2];
fprintf(stderr, "*** Genplot2 v 1.0.4 [%s] (dwtfywl) 1995,2010 TontonTh \n",
TGA_OUTILS_VERSION);
/*----------- giving to the yuser some useless informations --- */
fprintf(stderr, "hardcoded picsize : %d %d\n", XMAX, YMAX);
/*----------- opening input file and getting MIN and MAX values */
if ((fp = fopen(filename, "r"))==NULL)
{
perror("fichier d'entree");
exit(1);
}
nbp = 0;
xmin = 9999999; xmax = -9999999;
ymin = 9999999; ymax = -9999999;
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 )
{
nbp++;
if (x > xmax) xmax = x;
if (x < xmin) xmin = x;
if (y > ymax) ymax = y;
if (y < ymin) ymin = y;
}
fclose(fp);
if (nbp == 0)
{
fprintf(stderr, "omg, I'v found _ZERO_ points for plotting...\n");
exit(2);
}
fprintf(stderr, "Genplot2: found %d points\n", nbp);
/*---------- computing coefficients (temporary hack !-) */
fx = (XMAX-XMIN-1)/(xmax-xmin);
fy = (YMAX-YMIN-1)/(ymax-ymin);
fprintf(stderr, "\nfc = %12f fy = %12f\n", fx, fy);
f = (fx<fy?fx:fy);
xC = 0.5*(xmin+xmax); yC = 0.5*(ymin+ymax);
XC = 0.5*(XMIN+XMAX); YC = 0.5*(YMIN+YMAX);
c1 = XC-f*xC; c2 = YC-f*yC;
fprintf(stderr, "c1 = %12f c2 = %12f\n", c1, c2);
/*------------- and now, plotting the image ! */
initgr(XMAX, YMAX);
fp = fopen(filename, "r");
puts("");
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 )
{
#if DEBUG_LEVEL
fprintf(stderr, "%12f %12f %d\n", x, y, v);
#endif
X = f*x+c1; Y = f*y+c2;
if (v < 0) move(X, Y);
else draw(X, Y, v);
}
endgr(image);
return 0;
}

92
Tools/tga_applymap.c Normal file
View File

@ -0,0 +1,92 @@
/*
WARNING! this prog is bogus!
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "* tga_applymap v 0.0.14 [%s] (dwtfywl) Krabulator 1910\n",
TGA_OUTILS_VERSION);
fprintf(stderr, "Usage: tga_applymap M src.tga color.map dst.tga\n");
fprintf(stderr, " M is 1 or 2\n");
Image_print_version(0);
exit(5);
}
/*::------------------------------------------------------------------::*/
int main(int argc, char *argv[])
{
Image_Desc *src, *dst;
int foo;
RGB_map map;
dump_command_line(argc, argv, 0);
if (argc==2 && !strcmp(argv[1], "-?")) usage(1);
if (argc != 5) usage(0);
if ( (src=Image_TGA_alloc_load(argv[2])) == NULL )
{
fprintf(stderr, "can't load '%s'\n", argv[2]);
exit(1);
}
if ( (foo=Image_load_color_Map(argv[3], "map", &map)) )
{
fprintf(stderr, "%s: %s: err%d %s\n", argv[0], argv[3],
foo, Image_err2str(foo));
exit(1);
}
if (must_be_verbose())
{
fprintf(stderr, "il y a %d couleurs dans la palette '%s'\n",
map.nbre, argv[3]);
}
if ( (dst=Image_clone(src, 0))==NULL )
{
fprintf(stderr, "can't clone %p, exiting...\n", src);
exit(2);
}
/* ----------- */
switch (argv[1][0])
{
default:
case '1':
foo=Image_apply_Map(src, dst, &map);
break;
case '2':
foo=Image_gray_Map(src, dst, &map);
break;
case '3':
fprintf(stderr, "Not implemented\n");
exit(5);
}
/* ----------- */
if (foo)
{
fprintf(stderr, "%s: apply map: erreur %d: %s\n",
argv[0], foo, Image_err2str(foo));
}
foo = Image_TGA_save(argv[4], dst, 0);
if (foo)
{
fprintf(stderr, "%s: TGA_save: err #%d\n\t\t %s\n",
argv[0], foo, Image_err2str(foo));
exit(1);
}
fprintf(stderr, "apply map ok\n");
exit (0);
}
/*::------------------------------------------------------------------::*/

145
Tools/tga_dither.c Normal file
View File

@ -0,0 +1,145 @@
/*
----------------------------------------------
utilitaire pour ditherizer (uh?) une image
----------------------------------------------
http://krabulator.free.fr/devel/libimage.html
----------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define DI_2X2 2
#define DI_3X3_0 11
#define DI_3X3_1 12
#define DI_BAYER0 16
#define DI_ATKINSON 18
#define DI_CRUDE 30
#define DI_DBLTR 38
#define DI_ERROR 45
#define DI_RANDOM 60
#define DI_BYR8RND 70
#define DI_XPER 100
mot_clef mots_clef[] =
{
{ "2x2", DI_2X2, "", "not working" },
{ "3x3_0", DI_3X3_0, "", "" },
{ "3x3_1", DI_3X3_1, "", "" },
{ "bayer0", DI_BAYER0, "", "" },
{ "atkinson", DI_ATKINSON, "i", "mmmm ?" },
{ "crude", DI_CRUDE, "i", "" },
{ "dbltresh", DI_DBLTR, "ii", "hi & low tresholds" },
{ "error", DI_ERROR, "", "simple err diffusion" },
{ "random", DI_RANDOM, "i", "random treshold" },
{ "byr8rnd", DI_BYR8RND, "ii", "new 29 nov 2013" },
{ "xper", DI_XPER, "i", "param: 1..254" },
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "* tga_dither v 0.0.26 [%s] (dwtfywl 2022) tTh\n",
TGA_OUTILS_VERSION);
fprintf(stderr, "usage:\n\ttga_dither avant.tga mode avant.tga [params]\n");
if (flag)
liste_mots_clefs(mots_clef, 42);
else
Image_print_version(0);
exit(5);
}
/*::------------------------------------------------------------------::*/
int main (int argc, char *argv[])
{
Image_Desc *src, *dst;
int foo;
int commande, nbargs, idx;
dump_command_line(argc, argv, 0);
if ( argc==2 && !strcmp(argv[1], "list") ) usage(1);
if ( argc < 4) usage(0);
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
if (idx < 0)
{
fprintf(stderr, "tga_dither: keyword %s unknow.\n", argv[2]);
exit(5);
}
#if DEBUG_LEVEL
fprintf(stderr, "idx %d commande %d nbargs %d argc %d\n",
idx, commande, nbargs, argc);
#endif
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, 4);
if ( (src=Image_TGA_alloc_load(argv[1])) == NULL )
{
fprintf(stderr, "tga_dither: err load %s\n", argv[1]);
exit(5);
}
if ( (dst=Image_clone(src, 1)) == NULL )
{
fprintf(stderr, "no mem for image cloning\n");
exit(5);
}
switch (commande)
{
case DI_2X2:
foo = Image_dither_2x2(src, dst, 255);
break;
case DI_3X3_0:
foo = Image_dither_3x3_0(src, dst, 127);
break;
case DI_3X3_1:
foo = Image_dither_3x3_1(src, dst, 255);
break;
case DI_BAYER0:
foo = Image_dither_Bayer_0(src, dst, 255);
break;
case DI_ATKINSON:
foo = Image_dither_atkinson(src, dst, 255);
break;
case DI_CRUDE:
foo = Image_dither_crude(src, dst, GIP(0));
break;
case DI_DBLTR:
foo = Image_dither_double_seuil(src, dst, GIP(0), GIP(1), 255);
break;
case DI_ERROR:
foo = Image_dither_simple_error(src, dst, 255);
break;
case DI_RANDOM:
foo = Image_dither_seuil_random(src, dst, 255);
break;
case DI_BYR8RND:
srand(getpid());
foo = Image_dither_bayer8x8rnd(src, dst, GIP(0), GIP(1));
break;
case DI_XPER:
foo = Image_dither_3x3_1(src, dst, GIP(0));
break;
default:
fprintf(stderr, "dithering method not implemented\n");
foo=-1;
break;
}
#if DEBUG_LEVEL
if (foo)
fprintf(stderr, "dither %d retour = %d, %s\n", commande,
foo, Image_err2str(foo));
#endif
foo = Image_TGA_save(argv[3], dst, 0);
return 0;
}
/*::------------------------------------------------------------------::*/

55
Tools/tga_makehf15.c Normal file
View File

@ -0,0 +1,55 @@
/*
convert a TGA image to a POVRAY height_field
----------------------------------------------------
This operation is also implemented in 'povhf_tools' (dec 2009)
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
void usage()
{
fprintf(stderr, "* tga_makehf15 v 0.0.6 [%s] (dwtfywl) tontonTh\n",
TGA_OUTILS_VERSION);
fprintf(stderr, "Usage:\n\ttga_makehf15 source.tga hf.tga\n");
fprintf(stderr, "\tno parameters, no options... but stay tuned :)\n\n");
Image_print_version(0);
exit(5);
}
/*::------------------------------------------------------------------::*/
int main (int argc, char *argv[])
{
Image_Desc *img, *hf15;
int foo;
dump_command_line(argc, argv, 0);
if (argc != 3) usage();
if ( (img=Image_TGA_alloc_load(argv[1]))==NULL )
{
fprintf(stderr, "can't load '%s'\n", argv[1]);
exit(5);
}
if ( (hf15=Image_clone(img, 0))==NULL )
{
fprintf(stderr, "can't clone %p\n", img);
exit(5);
}
/*
* et c'est quoi le paramètre qui est à 0 ?
*/
foo = Image_hf15_rgb2hf(img, hf15, 0);
Image_print_error("hf15 rgb2hf", foo);
foo = Image_TGA_save(argv[2], hf15, 0);
return 0;
}
/*::------------------------------------------------------------------::*/

196
Tools/tga_mires.c Normal file
View File

@ -0,0 +1,196 @@
/*
FABRIQUEUR DE MIRES
===================
http://krabulator.free.fr/devel/libimage.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define MIRCOL0 2
#define MIRCOL1 3
#define MIRCOL2 4
#define MIRCOL3 5
#define MIRCOL4 6
#define DECOMP 10
#define RGB0 14
#define RGBSTRIP 15 /* mmmm, c'est quoi ? */
#define GRAY0 16
#define FNT16X24 20
mot_clef mots_clef[] =
{
{ "mircol0", MIRCOL0, "s", "free text" },
{ "mircol1", MIRCOL1, "s", "texte libre" },
{ "mircol2", MIRCOL2, "iis", "dims & free text" },
{ "mircol3", MIRCOL3, "iiis", "dims, flag & free text" },
{ "mircol4", MIRCOL4, "iiis", "dims, flag & free text" },
{ "decomp", DECOMP, "", "mysterious operation" },
{ "rgb0", RGB0, "", "" },
{ "gray0", GRAY0, "i", "param: height" },
{ "fnt16x24", FNT16X24, "s", "param: font name" },
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "* tga_mires v 0.0.24 [%s] (dwtfywl 2015) tonton Th\n",
TGA_OUTILS_VERSION);
fprintf(stderr, "usage:\n\ttga_mires type image.tga [params]\n");
if (flag)
liste_mots_clefs(mots_clef, 42);
else
Image_print_version(0);
exit(5);
}
/*::------------------------------------------------------------------::*/
/* code selon ma methode de la rache le 25 avril 2007 */
int
mire_grise(Image_Desc *img)
{
int x, y;
if (256 != img->width) abort();
for (x=0; x<256; x++)
for (y=0; y<img->height; y++)
Image_plotRGB(img, x, y, x, x, x);
return 0;
}
/*::------------------------------------------------------------------::*/
int do_mircol_2(Image_Desc *img, char *texte)
{
int foo;
foo = Image_mircol_2(img, texte, 0);
return foo;
}
/*::------------------------------------------------------------------::*/
int do_mircol_3(Image_Desc *img, char *texte, int mode)
{
int foo;
fprintf(stderr, "%s : mode is %d\n", __func__, mode);
foo = Image_mircol_3(img, texte, mode);
return foo;
}
/*::------------------------------------------------------------------::*/
int do_mircol_4(Image_Desc *img, char *texte, int mode)
{
int foo;
fprintf(stderr, "%s : mode is %d\n", __func__, mode);
foo = Image_mircol_4(img, texte, mode);
return foo;
}
/*::------------------------------------------------------------------::*/
int main (int argc, char *argv[])
{
Image_Desc *dst;
int foo;
int commande, nbargs, idx;
char *cptr, *argument;
int width, height;
dump_command_line(argc, argv, 0);
if ( argc==2 && !strcmp(argv[1], "list") ) usage(1);
if ( argc < 3) usage(0);
idx = cherche_mot_clef(argv[1], mots_clef, &commande, &nbargs);
if (idx < 0)
{
fprintf(stderr, "tga_mires: mot-clef %s inconnu...\n", argv[1]);
exit(5);
}
#if DEBUG_LEVEL
fprintf(stderr, "idx %d commande %d nbargs %d argc %d\n",
idx, commande, nbargs, argc);
#endif
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, 3);
#if DEBUG_LEVEL
print_parametres();
#endif
dst = NULL;
switch (commande)
{
case MIRCOL0:
dst = Image_alloc(512, 512, 3);
foo = Image_mircol_0(dst, GSP(0), 0);
break;
case MIRCOL1:
dst = Image_alloc(512, 512, 3);
foo = Image_mircol_1(dst, GSP(0), 0);
break;
case MIRCOL2:
width = GIP(0);
height = GIP(1);
fprintf(stderr, "mircol2 sur %dx%d\n", width, height);
dst = Image_alloc(width, height, 3);
foo = do_mircol_2(dst, GSP(2));
break;
case MIRCOL3:
width = GIP(0);
height = GIP(1);
#if DEBUG_LEVEL
fprintf(stderr, "mircol3 sur %dx%d\n", width, height);
#endif
dst = Image_alloc(width, height, 3);
foo = do_mircol_3(dst, GSP(3), GIP(2));
break;
case MIRCOL4:
width = GIP(0);
height = GIP(1);
fprintf(stderr, "mircol4 sur %dx%d\n", width, height);
dst = Image_alloc(width, height, 3);
foo = do_mircol_3(dst, GSP(3), GIP(2));
break;
case RGB0:
dst = Image_alloc(256, 256, 3);
foo = Image_mirRGB_0(dst, 0);
break;
case GRAY0:
foo = GIP(0);
fprintf(stderr, "hauteur = %d\n", foo);
dst = Image_alloc(256, foo, 3);
foo = mire_grise(dst);
break;
case FNT16X24:
#if DEBUG_LEVEL
fprintf(stderr, "generation image fonte 16x24\n");
#endif
cptr = argv[2];
argument = GSP(0);
fprintf(stderr, "image fonte 16x24 %s -> %s\n",
cptr, argument);
foo = Image_t16x24_chars_map(cptr, argument, 0);
break;
default:
fprintf(stderr, "method not implemented\n");
foo=-1;
break;
}
if (foo)
fprintf(stderr, "retour = %d, %s\n", foo, Image_err2str(foo));
if (dst != NULL)
{
foo = Image_TGA_save(argv[2], dst, 0);
Image_DeAllocate(dst);
}
#if DEBUG_LEVEL
puts("");
#endif
return 0;
}
/*::------------------------------------------------------------------::*/

View File

@ -7,7 +7,7 @@
#include "../tthimage.h" #include "../tthimage.h"
#define TGA_OUTILS_VERSION "0.58" #define TGA_OUTILS_VERSION "0.59"
/* /*
* 13 Dec 2001: v0.11 a cause du 'mustopen' pour les palettes. * 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) * 11 Fev 2002: v0.12 a cause du '-ansi' (hein Kerdeuzz, on y vient)

117
Tools/tga_remap.c Normal file
View File

@ -0,0 +1,117 @@
/*
_
| |_ __ _ __ _ _ __ ___ _ __ ___ __ _ _ __
| __/ _` |/ _` | | '__/ _ \ '_ ` _ \ / _` | '_ \
| || (_| | (_| | | | | __/ | | | | | (_| | |_) |
\__\__, |\__,_|___|_| \___|_| |_| |_|\__,_| .__/
|___/ |_____| |_|
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "* tga_remap v 0.1.21 [%s] %s\n",
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
fprintf(stderr, "Usage: tga_remap M <src.tga> <color.map> <dst.tga>\n");
fprintf(stderr, " tga_remap -? for more infos...\n");
if (flag)
{
PERL;
PERR("valid values for 'M'");
PERR(" 0 minimal distance");
PERR(" 1 min of R or G or B dist");
PERR(" 2 ???");
PERR(" 11 minimal dist for R");
PERR(" 12 minimal dist for G");
PERR(" 13 minimal dist for B");
PERL;
Image_print_version(2);
}
else
{
Image_print_version(0);
}
exit(5);
}
/*::------------------------------------------------------------------::*/
int main(int argc, char *argv[])
{
Image_Desc *src, *dst;
int foo, type;
RGB_map map;
long t_debut, t_fin;
dump_command_line(argc, argv, 0);
if (argc==2 && !strcmp(argv[1], "-?")) usage(1);
if (argc != 5) usage(0);
if ( (src=Image_TGA_alloc_load(argv[2])) == NULL )
{
fprintf(stderr, "can't load '%s'\n", argv[2]);
exit(1);
}
if ( (foo=Image_load_color_Map(argv[3], "map", &map)) )
{
fprintf(stderr, "%s: %s: err %d '%s'\n", argv[0], argv[3],
foo, Image_err2str(foo));
exit(1);
}
if (must_be_verbose())
{
fprintf(stderr, "Il y a %d couleurs dans la palette '%s'\n",
map.nbre, argv[3]);
}
/*
* que faire si le nombre de couleurs dans la palette est pas bon ???
*/
if ( (dst=Image_clone(src, 0))==NULL )
{
fprintf(stderr, "can't clone %p, exiting...\n", src);
exit(2);
}
/* ---------- determiner le type de remap demande */
if ( (sscanf(argv[1], "%d", &type)) != 1 ) type = 0;
#if DEBUG_LEVEL
t_debut = time(NULL);
#endif
if ( (foo=Image_colors_2_Map(src, dst, &map, type)) )
{
fprintf(stderr, "%s: color->map: erreur %d: %s\n", argv[0],
foo, Image_err2str(foo));
/* Oulala ! c'est pas un peu brutal ? */
exit(1);
}
#if DEBUG_LEVEL
t_fin = time(NULL);
fprintf(stderr, " remap : %ld secondes\n", t_fin-t_debut);
#endif
foo = Image_TGA_save(argv[4], dst, 0);
if (foo)
{
fprintf(stderr, "%s: TGA_save: err %d %s\n",
argv[0], foo, Image_err2str(foo));
exit(1);
}
exit (0);
}
/*::------------------------------------------------------------------::*/

View File

@ -2,9 +2,11 @@
cd Lib cd Lib
echo "========== in $PWD"
make testtga make testtga
cd .. cd ..
cd Tools cd Tools
echo "========== in $PWD"
make make
cd .. cd ..