2022-06-27 23:39:52 +02:00
|
|
|
/*
|
|
|
|
WARNING! this prog is bogus!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tga_outils.h"
|
|
|
|
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
void usage(int flag)
|
|
|
|
{
|
2024-04-08 05:35:19 +02:00
|
|
|
fprintf(stderr, "* tga_applymap v 0.0.15 [%s] (dwtfywl) Krabulator 1910\n",
|
2022-06-27 23:39:52 +02:00
|
|
|
TGA_OUTILS_VERSION);
|
2022-07-01 02:36:54 +02:00
|
|
|
fprintf(stderr, " compiled %s at %s\n", __DATE__, __TIME__);
|
|
|
|
|
|
|
|
fprintf(stderr, "Usage:\n\ttga_applymap M src.tga color.map dst.tga\n");
|
2023-10-12 12:34:28 +02:00
|
|
|
fprintf(stderr, " M is 1 (color mode) or 2 (gray mode)\n");
|
2022-07-07 12:52:00 +02:00
|
|
|
if (flag) Image_print_version(0);
|
2022-06-27 23:39:52 +02:00
|
|
|
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);
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
if ( (src=Image_TGA_alloc_load(argv[2])) == NULL ) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "can't load '%s'\n", argv[2]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-04-08 05:35:19 +02:00
|
|
|
memset(&map, 0, sizeof(map));
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
if ( (foo=Image_load_color_Map(argv[3], "map", &map)) ) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "%s: %s: err%d %s\n", argv[0], argv[3],
|
|
|
|
foo, Image_err2str(foo));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
if (must_be_verbose()) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "il y a %d couleurs dans la palette '%s'\n",
|
|
|
|
map.nbre, argv[3]);
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
if ( (dst=Image_clone(src, 0))==NULL ) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "can't clone %p, exiting...\n", src);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------- */
|
2022-07-07 12:52:00 +02:00
|
|
|
switch (argv[1][0]) {
|
2022-06-27 23:39:52 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
/* ----------- */
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
if (foo) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "%s: apply map: erreur %d: %s\n",
|
|
|
|
argv[0], foo, Image_err2str(foo));
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = Image_TGA_save(argv[4], dst, 0);
|
2022-07-07 12:52:00 +02:00
|
|
|
if (foo) {
|
2022-06-27 23:39:52 +02:00
|
|
|
fprintf(stderr, "%s: TGA_save: err #%d\n\t\t %s\n",
|
|
|
|
argv[0], foo, Image_err2str(foo));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|