libtthimage/Tools/tga_export.c

118 lines
2.7 KiB
C
Raw Normal View History

2022-06-29 06:28:22 +11:00
/*
convert a TGA image to various formats
-----------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define PGM0 1
#define PGM1 2
#define PPM0 10
#define PHT 20
#define BMP24 30
#define PCX8 60
#define PCX24 61
#define PGMHF 80
2022-07-07 21:52:00 +11:00
#define TIFF 90
2022-06-29 06:28:22 +11:00
mot_clef mots_clef[] =
{
{ "pgm0", PGM0, "c", "param: color component" },
{ "ppm0", PPM0, "", "portable pixmap (rgb)" },
{ "pht", PHT, "c", "param: color component" },
{ "bmp24", BMP24, "i", "param must be 0" },
{ "pcx8", PCX8, "i", "plop" },
{ "pcx24", PCX24, "i", "plup" },
{ "pgmhf", PGMHF, "", "height fields for POV" },
2022-07-07 21:52:00 +11:00
{ "tiff", TIFF, "", "" },
2022-06-29 06:28:22 +11:00
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
2022-07-07 21:52:00 +11:00
fprintf(stderr, "*** tga_export v 0.0.10 [%s] %s\n",
2022-06-29 06:28:22 +11:00
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
fprintf(stderr, "tga_export source.tga format destination.xxx [params]\n\n");
2022-07-07 21:52:00 +11:00
if (flag) {
2022-06-29 06:28:22 +11:00
liste_mots_clefs(mots_clef, 42);
}
exit(5);
}
/*::------------------------------------------------------------------::*/
/*
* argv[1] source.tga
* argv[2] format d'exportation
* argv[3] destination.???
*/
#define FIRST_PARAM 4
int main (int argc, char *argv[])
{
Image_Desc *img;
int foo;
int idx, commande, nbargs;
dump_command_line(argc, argv, 0);
if (argc < 4) usage(1);
/* recherche du type d'exportation demand<6E> */
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
2022-07-07 21:52:00 +11:00
if (idx < 0) {
2022-06-29 06:28:22 +11:00
fprintf(stderr, "tga_export: format %s inconnu...\n", argv[2]);
exit (5);
}
2022-07-07 21:52:00 +11:00
if ( (argc-nbargs) != FIRST_PARAM ) {
2022-06-29 06:28:22 +11:00
fprintf(stderr, "%s: bad number of parameters\n", argv[0]);
exit(5);
}
/* analyse des param<61>tres */
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM);
2022-07-07 21:52:00 +11:00
if ( (img=Image_TGA_alloc_load(argv[1]))==NULL ) {
2022-06-29 06:28:22 +11:00
fprintf(stderr, "tga_export: can't load '%s'\n", argv[1]);
exit(5);
}
2022-07-07 21:52:00 +11:00
switch (commande) {
2022-06-29 06:28:22 +11:00
case PGM0:
foo = Image_wr_pgm_0(argv[3], img, GCP(0));
break;
case PPM0:
foo = Image_wr_ppm_0(argv[3], img, 0);
break;
case PHT:
foo = Image_PHT_save_component(argv[3], img, GCP(0));
break;
case BMP24:
foo = Image_BMP_save_24(argv[3], img, 0);
break;
case PGMHF:
/* une fonction equivalente est dans 'povhf_tools' et
* il serait bien de mutualiser le code */
foo = Image_hf15_save_PGM(argv[3], img, "Nice try...");
break;
default:
foo = 9999;
break;
}
2022-07-07 21:52:00 +11:00
if (foo) {
2022-06-29 06:28:22 +11:00
fprintf(stderr, "tga_export (%s) ", argv[2]);
Image_print_error("ecriture fichier", foo);
2022-07-07 21:52:00 +11:00
exit(1);
2022-06-29 06:28:22 +11:00
}
return 0;
}
/*::------------------------------------------------------------------::*/