libtthimage/Tools/tga_equalize.c

147 lines
3.2 KiB
C
Raw Permalink Normal View History

2022-06-28 21:25:31 +11:00
/*
----------------------------------------------
utilitaire pour egalizer (uh?) une image
----------------------------------------------
http://la.buvette.org/devel/libimage/
----------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define EQ_STD 4
#define EQ_GRAY 8
2023-09-18 07:36:08 +11:00
#define EQ_COS01 9
2024-04-10 07:20:46 +11:00
#define EQ_COS010 10
2022-06-28 21:25:31 +11:00
#define EQ_2X2 12
#define EQ_LUMIN 14
#define EQ_SQUARE 16
#define EQ_SQROOT 17
#define EQ_GAMMA 20
2022-07-01 05:33:31 +11:00
#define EQ_MULT 21
2022-06-28 21:25:31 +11:00
mot_clef mots_clef[] =
{
{ "std", EQ_STD, "", "standard method" },
{ "rgb", EQ_STD, "", "same as 'std'" },
{ "gray", EQ_GRAY, "", "gray based" },
2023-09-18 07:36:08 +11:00
{ "cos01", EQ_COS01, "", "cosinus 0->1" },
2024-04-10 07:20:46 +11:00
{ "cos010", EQ_COS010, "", "cosinus 0-1-0" },
2022-06-28 21:25:31 +11:00
{ "2x2", EQ_2X2, "", "2x2 matrix" },
2022-07-01 05:33:31 +11:00
{ "lumin", EQ_LUMIN, "i", "param: ident is 256" },
/* { "gamma", EQ_GAMMA, "d", "not implemented" },*/
2022-06-28 21:25:31 +11:00
{ "square", EQ_SQUARE, "", "pix**2" },
{ "sqroot", EQ_SQROOT, "", "sqr(pix)" },
2022-07-01 05:33:31 +11:00
{ "mult", EQ_MULT, "d", "multiply by const" },
2022-06-28 21:25:31 +11:00
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage()
{
2024-07-18 17:56:48 +11:00
fprintf(stderr, "* tga_equalize v 0.0.25 [%s] (dwtfywl) tonton Th\n",
2022-06-28 21:25:31 +11:00
TGA_OUTILS_VERSION);
fprintf(stderr, " compiled %s at %s\n", __DATE__, __TIME__);
fprintf(stderr, "usage:\n\ttga_equalize avant.tga mode apres.tga [params]\n");
liste_mots_clefs(mots_clef, 42);
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 < 4) usage();
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
if (idx < 0)
{
fprintf(stderr, "tga_equalize: mot-clef %s inconnu...\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_equalize: err load %s\n", argv[1]);
exit(5);
}
if ( (dst=Image_clone(src, 0)) == NULL )
{
fprintf(stderr, "no mem for image cloning\n");
exit(5);
}
switch (commande)
{
case EQ_STD:
foo = Image_egalise_RGB(src, dst, 0);
break;
case EQ_GRAY:
foo = Image_egalise_mono_0(src, dst, 0);
break;
case EQ_2X2:
foo = Image_2x2_contrast(src, dst);
break;
case EQ_LUMIN:
foo = Image_luminance(src, dst, GIP(0));
break;
case EQ_SQUARE:
foo = Image_pix_square(src, dst, 0);
break;
case EQ_SQROOT:
foo = Image_pix_sqroot(src, dst, 0);
break;
2023-09-18 07:36:08 +11:00
case EQ_COS01:
foo = Image_egalise_cos01(src, dst, 0);
break;
2024-04-10 07:20:46 +11:00
case EQ_COS010:
foo = Image_egalise_cos010(src, dst, 0);
break;
2022-06-28 21:25:31 +11:00
case EQ_GAMMA:
fprintf(stderr, "no gamma func in %d\n", getpid());
foo = FULL_NUCKED;
break;
2022-07-01 05:33:31 +11:00
case EQ_MULT:
foo = PASTIS;
break;
2022-06-28 21:25:31 +11:00
default:
2024-07-18 17:56:48 +11:00
fprintf(stderr, "unexpected command #%d\n", commande);
2022-06-28 21:25:31 +11:00
foo=-1;
break;
}
2023-09-22 23:15:52 +11:00
if (foo) {
fprintf(stderr, "%s: retour = %d, %s\n", argv[0],
foo, Image_err2str(foo));
}
2022-06-28 21:25:31 +11:00
foo = Image_TGA_save(argv[3], dst, 0);
2023-09-22 23:15:52 +11:00
2022-06-28 21:25:31 +11:00
return 0;
}
/*::------------------------------------------------------------------::*/