diff --git a/.gitignore b/.gitignore index 8b34d1b..b41c771 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ Lib/foo Lib/testtga Lib/t_t16x24 +Tools/genplot2 + Tools/tga_cadre Tools/tga_dither Tools/tga_tools @@ -16,8 +18,8 @@ Tools/tga_effects Tools/tga_filtres Tools/tga_remap Tools/tga_television -Tools/genplot2 Tools/tga_applymap Tools/tga_makehf15 Tools/tga_mires - +Tools/tga_incrust +Tools/tga_pattern diff --git a/Tools/Makefile b/Tools/Makefile index d825410..ec52010 100644 --- a/Tools/Makefile +++ b/Tools/Makefile @@ -8,9 +8,12 @@ include ../Paramakes.mk DEPS = ../tthimage.h Makefile tga_outils.h -all: tga_cadre tga_effects tga_filtres tga_remap tga_tools \ +all: genplot2 \ + tga_cadre tga_effects tga_filtres tga_remap tga_tools \ tga_television tga_dither tga_applymap tga_makehf15 \ - tga_mires + tga_mires tga_incrust tga_pattern + +# 'tga_info.c' do not compile yet #----------------------------------------------------------------- @@ -54,5 +57,14 @@ tga_television: tga_television.c $(DEPS) fonctions.o tga_tools: tga_tools.c $(DEPS) fonctions.o gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ +tga_incrust: tga_incrust.c $(DEPS) fonctions.o + gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ + +# tga_info: tga_info.c $(DEPS) fonctions.o +# gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ + +tga_pattern: tga_pattern.c $(DEPS) fonctions.o + gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ + #----------------------------------------------------------------- diff --git a/Tools/tga_incrust.c b/Tools/tga_incrust.c new file mode 100644 index 0000000..aa2d1a2 --- /dev/null +++ b/Tools/tga_incrust.c @@ -0,0 +1,142 @@ +/* + # # # #### ##### # # #### ##### ## ##### # #### # # + # ## # # # # # # # # # # # # # # # ## # + # # # # # # # # # #### # # # # # # # # # # + # # # # # ##### # # # # ###### # # # # # # # + # # ## # # # # # # # # # # # # # # # # ## + # # # #### # # #### #### # # # # # #### # # + */ + +#include +#include +#include + +#include "tga_outils.h" + +/*::------------------------------------------------------------------::*/ + +#define ICRU_POKE 2 +#define ICRU_POKEMIX 3 +#define ICRU_POKEALPHA 4 +#define ICRU_POKESCALE 10 +#define ICRU_RGBXOR 20 +#define ICRU_RECT 30 +#define ICRU_RECT2 32 + +mot_clef mots_clef[] = +{ +{ "poke", ICRU_POKE, "ii", "poke it hardly" }, +{ "pokemix", ICRU_POKEMIX, "iii", "ponderate it" }, +{ "pokealpha", ICRU_POKEALPHA, "ii", "use the alpha channel" }, +{ "pokescale", ICRU_POKESCALE, "ii%", "scale before poking" }, +{ "rgbxor", ICRU_RGBXOR, "ii", "exclusive OR of poked pix" }, +{ "rect", ICRU_RECT, "iir", "only a part of 'what'" }, +{ "rect2", ICRU_RECT2, "iir", "only a part of 'what'" }, +{ NULL, 0, "WTF", NULL }, +}; + +/*::------------------------------------------------------------------::*/ +int usage(int flag) +{ +fprintf(stderr, "* TGA incrustator v 0.1.2 [%s] %s \n", + TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT); + +fprintf(stderr, "tga_incrust orig insert mode out\n"); + +if (flag) { + Image_print_version(0); + liste_mots_clefs(mots_clef, 42); + } + +exit(0); +} + +/*::------------------------------------------------------------------::*/ +/* + * argv[1] image originale + * argv[2] image a incruster + * argv[3] type d'incrustation + * argv[4] image destination +*/ +#define FIRST_PARAM 5 + +int main(int argc, char *argv[]) +{ +Image_Desc *where, *what; +int foo, idx; +int xpos, ypos; +int par[NB_PARAMS], nb_int_par; +int commande, nbargs; + +dump_command_line(argc, argv, 0); + +if (argc==2 && !strcmp(argv[1], "-?")) usage(0); +if (argc==2 && !strcmp(argv[1], "list")) usage(1); +if (argc < 4) usage(0); + +if (must_be_verbose()) + { + fprintf(stderr, "********************************\n"); + fprintf(stderr, "* EXPERIMENTAL CORE DUMPER *\n"); + fprintf(stderr, "********************************\n"); + } + +idx = cherche_mot_clef(argv[3], mots_clef, &commande, &nbargs); +if (idx < 0) + { + fprintf(stderr, "tga_incrust: mot-clef '%s' inconnu...\n", argv[3]); + exit (5); + } +if ( (argc-nbargs) != FIRST_PARAM ) + { + fprintf(stderr, "%s: bad number of parameters\n", argv[0]); +#if DEBUG_LEVEL + fprintf(stderr, "argc=%d nbargs=%d FIRST_PARAM=%d\n", + argc, nbargs, FIRST_PARAM); +#endif + exit(5); + } + +/* analyse des parametres */ +idx = 0; +foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM); +#if DEBUG_LEVEL +fprintf(stderr, "parse params -> %d\n", foo); +#endif + +if (NULL==(where=Image_TGA_alloc_load(argv[1]))) + { + fprintf(stderr, "can't load %s\n", argv[1]); + exit(2); + } + +if (NULL==(what=Image_TGA_alloc_load(argv[2]))) + { + fprintf(stderr, "can't load %s\n", argv[2]); + exit(2); + } + +switch (commande) + { + case ICRU_POKE: + xpos = GIP(0); ypos = GIP(1); + foo = Image_overlay(what, where, xpos, ypos); + if (foo) fprintf(stderr, "overlay -> %d\n", foo); + break; + + default: + fprintf(stderr, "%d bad command\n", commande); + exit(1); + } + +Image_DeAllocate(what); free(what); + +foo = Image_TGA_save(argv[4], where, 0); +if (foo) + { + fprintf(stderr, "save -> %d\n", foo); + } +Image_DeAllocate(where); free(where); + +return 0; +} diff --git a/Tools/tga_info.c b/Tools/tga_info.c new file mode 100644 index 0000000..fd14bd7 --- /dev/null +++ b/Tools/tga_info.c @@ -0,0 +1,80 @@ +/* + ce programme n'est pas pres pour le 'primtime' + il manque une gestion correcte des arguments. + voir aussi 'tga_tools.c' +*/ + + +#include + +#include "../tthimage.h" + +int main(int argc, char *argv[]) +{ +Tga_file_header head; +FILE *fp; +char *ptr; +char comment[257]; +int foo; + +if (argc != 2) + { + fprintf(stderr, "il manque le nom du fichier TGA\n"); + exit(1); + } + +if ((fp=fopen(argv[1], "rb")) == NULL) + { + fprintf(stderr, "erreur ouverture fichier %s\n", argv[1]); + exit(1); + } + +fread(&head, 1, sizeof(head), fp); +if (head.text_size) + { + fread(comment, 1, head.text_size, fp); + comment[head.text_size] = '\0'; + } +fclose(fp); + +printf("file name %s\n", argv[1]); + +if (head.text_size) + { + printf("comment size %d\n", head.text_size); + puts(comment); + } +else puts("no comment."); + +printf("is color map ? %d\n", head.is_color_map); +switch (head.type) + { + case 1: ptr = "8-bit palette"; break; + case 2: ptr = "RGB"; break; + case 3: ptr = "Gray"; break; + case 10: ptr = "rle/rvb"; break; + case 11: ptr = "grey/rle"; break; /* !!! a verifier !!! */ + default: ptr = "???"; break; + } +printf("type %d %s\n", head.type, ptr); +printf("map start %d\n", head.map_start); +printf("map length %d\n", head.map_length); +printf("map bits %d\n", head.map_bits); +printf("x start %d\n", head.x_start); +printf("y start %d\n", head.y_start); +printf("width %d\n", head.width); +printf("height %d\n", head.height); +printf("nbr of bits %d\n", head.bits); + +switch (head.flags>>4) + { + case 0: ptr = "NON"; break; + case 1: ptr = "droite-gauche"; break; + case 2: ptr = "haut-bas"; break; + case 3: ptr = "les deux"; break; + default: ptr = "???"; break; + } + +printf("flags %02x flip: %s\n", head.flags, ptr); +return 0; +} diff --git a/Tools/tga_pattern.c b/Tools/tga_pattern.c new file mode 100644 index 0000000..7ee1147 --- /dev/null +++ b/Tools/tga_pattern.c @@ -0,0 +1,204 @@ +/* + , __ + /|/ \ + |___/ __, _|__|_ _ ,_ _ _ + | / | | | |/ / | / |/ | + | \_/|_/|_/|_/|__/ |_/ | |_/ + +*/ + + +#include +#include +#include + +#include "tga_outils.h" + +/*::------------------------------------------------------------------::*/ +struct type + { + char *nom; + int code; + int nbparams; + }; + +#define REPONSE 1 +#define GRAYNOISE 2 +#define RGBNOISE 3 +#define TEXTURE_1 21 +#define TEXTURE_2 22 +#define TEXTURE_3 23 +#define EXPOV_0 30 +#define PATT_102 32 /* new June 2003 */ +#define GRAYNOISE2 40 +#define RGBNOISE1 50 +#define RGBNOISE2 51 +#define CHECK_BW 80 +#define PATT_000 90 + +static char no_help[] = "no help..."; + +mot_clef mots_clef[] = +{ +{ "graynoise", GRAYNOISE, "ii", "bruit gris" }, +{ "rgbnoise", RGBNOISE, "ii", "bruit RGB" }, +{ "42", REPONSE, "ii", no_help }, +{ "reponse", REPONSE, "ii", no_help }, +{ "text1", TEXTURE_1, "ii", no_help }, +{ "text2", TEXTURE_2, "iii", no_help }, +{ "expov", EXPOV_0, "iii", no_help }, +{ "centdeux", PATT_102, "iiii", no_help }, +{ "first", PATT_000, "i", "byte mask" }, +{ "graynoise2", GRAYNOISE2, "ii", no_help }, +{ "rgbnoise1", RGBNOISE1, "iiiiii", no_help }, +{ "rgbnoise2", RGBNOISE2, "iiiiii", no_help }, +{ "check_bw", CHECK_BW, "iiii", no_help }, +{ NULL, 0, NULL, NULL } +}; + +/*::------------------------------------------------------------------::*/ +void usage(int flag) +{ +fprintf(stderr, "* Tga Pattern v 0.0.25 [%s] %s\n", + TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT); +Image_print_version(flag); + +fprintf(stderr, "\nUsage:\n"); +fprintf(stderr, "\ttga_pattern dest.tga width height type [params]\n"); + +if (flag) + liste_mots_clefs(mots_clef, 42); + +exit(5); +} +/*::------------------------------------------------------------------::*/ +/* + * argv[1] nom du fichier resultat + * argv[2] largeur + * argv[3] hauteur + * argv[4] type du pattern + */ +#define FIRST_PARAM 5 +int main(int argc, char *argv[]) +{ +Image_Desc *dst; +int foo, width, height; +RGBA rgba1, rgba2; +int commande, nbargs, idx; + +dump_command_line(argc, argv, 0); + +srand(getpid()); + +if (argc==1) usage(0); + +if (argc==2 && !strcmp("list", argv[1])) + { + usage(1); + } +if (argc < 5) usage(0); + +idx = cherche_mot_clef(argv[4], mots_clef, &commande, &nbargs); +if (idx < 0) + { + fprintf(stderr, "mot-clef %s inconnu...\n", argv[4]); + exit(5); + } +#if DEBUG_LEVEL +fprintf(stderr, " idx=%d commande=%d nbargs=%d\n", idx, commande, nbargs); +#endif + +foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM); +#if DEBUG_LEVEL +fprintf(stderr, " retour parse parameters = %d\n", foo); +#endif + +/* allocation et preparation de l'image */ +width = atoi(argv[2]); +height = atoi(argv[3]); +if (width<1 || width>16000 || height<1 || height>16000) + { + fprintf(stderr, "%s: hu ho ? invalid dimension\n", argv[0]); + exit(5); + } + +dst = Image_alloc(width, height, 3); + +/* + * calcul de l'image patternelle. + */ +switch(commande) + { + case REPONSE: + foo = Image_pattern_042(dst, GIP(0)); + break; + + case RGBNOISE: + foo = Image_rgb_noise_0(dst, GIP(0), GIP(1)); + break; + + case GRAYNOISE: + foo = Image_gray_noise_0(dst, GIP(0), GIP(1)); + break; + + case TEXTURE_1: + foo = Image_texture_1(dst, GIP(0), GIP(1)); + break; + + case TEXTURE_2: + foo = Image_texture_2(dst, GIP(0), GIP(1), GIP(2)); + break; + + case EXPOV_0: + foo = Image_pattern_100(dst, GIP(0), GIP(1), GIP(2)); + break; + + case PATT_000: + foo = Image_pattern_000(dst, GIP(0)); + break; + + case PATT_102: + foo = Image_pattern_102(dst, GIP(0), GIP(1), GIP(2), GIP(3)); + break; + + case GRAYNOISE2: + foo = Image_gray_noise_2(dst, GIP(0), GIP(1)); + break; + + case RGBNOISE1: + rgba1.r = GIP(0); rgba2.r = GIP(1); + rgba1.g = GIP(2); rgba2.g = GIP(3); + rgba1.b = GIP(4); rgba2.b = GIP(5); + foo = Image_rgb_noise_1(dst, &rgba1, &rgba2); + break; + + case RGBNOISE2: + rgba1.r = GIP(0); rgba2.r = GIP(1); + rgba1.g = GIP(2); rgba2.g = GIP(3); + rgba1.b = GIP(4); rgba2.b = GIP(5); + foo = Image_rgb_noise_2(dst, &rgba1, &rgba2); + break; + + case CHECK_BW: + rgba1.r = rgba1.g = rgba1.b = GIP(2); + rgba2.r = rgba2.g = rgba2.b = GIP(3); + fprintf(stderr, "CHECK_BW : encore en mise au point...\n"); + foo = Image_pattern_104(dst, GIP(0), GIP(1), &rgba1, &rgba2); + break; + + default: + fprintf(stderr, "type #%d not implemented\n", commande); + exit(5); + } + +if (foo) + Image_print_error("fabrication pattern", foo); + +foo = Image_TGA_save(argv[1], dst, 0); + +if (foo) + Image_print_error("sauvegarde pattern", foo); + +return 0; +} +/*::------------------------------------------------------------------::*/