importing the exporter :)

This commit is contained in:
tth 2022-06-28 21:28:22 +02:00
parent c87f70c5f2
commit 81611a3491
7 changed files with 223 additions and 5 deletions

2
.gitignore vendored
View File

@ -6,12 +6,14 @@ libtthimage.a
Lib/foo Lib/foo
Lib/testtga Lib/testtga
Lib/t_t16x24 Lib/t_t16x24
Lib/testbmp
Tools/genplot2 Tools/genplot2
Tools/tga_cadre Tools/tga_cadre
Tools/tga_combine Tools/tga_combine
Tools/tga_dither Tools/tga_dither
Tools/tga_export
Tools/tga_tools Tools/tga_tools
Tools/tga_effects Tools/tga_effects
Tools/tga_equalize Tools/tga_equalize

View File

@ -16,6 +16,7 @@ all: foo testtga
basic_io.o: basic_io.c $(DEPS) basic_io.o: basic_io.c $(DEPS)
bitblt.o: bitblt.c $(DEPS) bitblt.o: bitblt.c $(DEPS)
bmp.o: bmp.c $(DEPS) bmp.h
cadres.o: cadres.c $(DEPS) cadres.o: cadres.c $(DEPS)
cadres2.o: cadres2.c $(DEPS) cadres2.o: cadres2.c $(DEPS)
@ -89,6 +90,7 @@ pht.o: pht.c $(DEPS)
pixeliz.o: pixeliz.c $(DEPS) pixeliz.o: pixeliz.c $(DEPS)
pixels.o: pixels.c $(DEPS) pixels.o: pixels.c $(DEPS)
plotteur.o: plotteur.c $(DEPS) plotteur.o: plotteur.c $(DEPS)
pnm.o: pnm.c $(DEPS)
pov_hf15a.o: pov_hf15a.c $(DEPS) pov_hf15a.o: pov_hf15a.c $(DEPS)
pov_hf15b.o: pov_hf15b.c $(DEPS) pov_hf15b.o: pov_hf15b.c $(DEPS)
pov_hf15c.o: pov_hf15c.c $(DEPS) pov_hf15c.o: pov_hf15c.c $(DEPS)
@ -126,7 +128,7 @@ zoom.o: zoom.c $(DEPS)
#----------------------------------------------------------------- #-----------------------------------------------------------------
OBJECTS = 7seg.o \ OBJECTS = 7seg.o \
basic_io.o bitblt.o \ basic_io.o bitblt.o bmp.o \
cadres2.o cadres3.o cadres4.o cadres84.o cadresbox.o \ cadres2.o cadres3.o cadres4.o cadres84.o cadresbox.o \
cadres.o \ cadres.o \
calculs.o classif.o \ calculs.o classif.o \
@ -149,6 +151,7 @@ OBJECTS = 7seg.o \
palettes.o \ palettes.o \
patterns.o patterns2.o patterns3.o patterns4.o \ patterns.o patterns2.o patterns3.o patterns4.o \
photomaton.o pht.o pixeliz.o pixels.o plotteur.o \ photomaton.o pht.o pixeliz.o pixels.o plotteur.o \
pnm.o \
pov_hf15a.o pov_hf15b.o pov_hf15c.o pov_hf15d.o \ pov_hf15a.o pov_hf15b.o pov_hf15c.o pov_hf15d.o \
pov_hf15e.o pov_hf15e.o pov_hf15f.o pov_synth.o \ pov_hf15e.o pov_hf15e.o pov_hf15f.o pov_synth.o \
ptlist.o \ ptlist.o \
@ -168,10 +171,14 @@ OBJECTS = 7seg.o \
#----------------------------------------------------------------- #-----------------------------------------------------------------
foo: foo.c $(DEPS) ../libtthimage.a foo: foo.c $(DEPS) ../libtthimage.a
gcc $(CFLAGS) $< ../libimage.a -o $@ gcc $(CFLAGS) $< ../libtthimage.a -o $@
t_t16x24: t_t16x24.c $(DEPS) ../libtthimage.a t_t16x24: t_t16x24.c $(DEPS) ../libtthimage.a
gcc $(CFLAGS) $< ../libimage.a-o $@ gcc $(CFLAGS) $< ../libtthimage.a -o $@
testbmp: testbmp.c $(DEPS) ../libtthimage.a
gcc $(CFLAGS) $< ../libtthimage.a -lm -o $@
#----------------------------------------------------------------- #-----------------------------------------------------------------

View File

@ -14,7 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
#include "bmp.h" /* maybe I can hardcoded bmp.h here ? */ #include "bmp.h" /* maybe I can hardcoded bmp.h here ? */

30
Lib/bmp.h Normal file
View File

@ -0,0 +1,30 @@
/*
* header file for BMP functions
* -----------------------------
* 'tthimage.h' must be included before this file.
*
*/
#pragma pack(1) /* est-ce encore utile ? */
typedef struct
{
char id[2];
long filesize;
uint16_t reserved[2];
long headerSize;
long infoSize;
long width;
long height;
short planes;
short bits;
long compression;
long SizeImage;
long xpixpermeter;
long ypixpermeter;
long clrused;
long clrimportant;
} BMPHEAD;
#pragma pack()

56
Lib/testbmp.c Normal file
View File

@ -0,0 +1,56 @@
/*
* essais sur le format BMP
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* Ther was a nasty bug in the 'save' function, staying here from the
* previous century. Try to fix it in October 2009
*/
int essai_largeur(int k)
{
int w;
Image_Desc *img;
char filename[100], chaine[110];
Image_load_fnt8x8("libimage.fonte", NULL, 0);
for (w=160; w<180; w++)
{
sprintf(filename, "tmp/aaaa-%03d-%d.bmp", w, w&3);
fprintf(stderr, "---- building '%s'\n", filename);
img = Image_alloc(w, 100, 3);
if (NULL==img)
{ exit(1); }
Image_pattern_001(img, 100);
Image_marque_0(img, 0);
sprintf(chaine, " w = %3d %d ", w, w&3);
Image_trace_chaine_1(img, chaine, 14, 14, NULL, NULL, NULL);
Image_BMP_save_24(filename, img, 0);
snprintf(chaine, 100, "display %s", filename);
fprintf(stderr, "running [%s]\n", chaine);
system(chaine);
Image_DeAllocate(img); free(img);
}
return 0;
}
/*::------------------------------------------------------------------::*/
int main(int argc, char *argv[])
{
int foo;
Image_print_version(1);
foo = essai_largeur(20);
return 0;
}
/*::------------------------------------------------------------------::*/

View File

@ -10,7 +10,7 @@ DEPS = ../tthimage.h Makefile tga_outils.h ../libtthimage.a
all: genplot2 \ all: genplot2 \
tga_cadre tga_effects tga_filtres tga_remap tga_tools \ tga_cadre tga_effects tga_filtres tga_remap tga_tools \
tga_combine \ tga_combine tga_export \
tga_television tga_dither tga_applymap tga_makehf15 \ tga_television tga_dither tga_applymap tga_makehf15 \
tga_mires tga_incrust tga_pattern tga_equalize tga_mires tga_incrust tga_pattern tga_equalize
@ -37,6 +37,9 @@ tga_cadre: tga_cadre.c $(DEPS) fonctions.o
tga_combine: tga_combine.c $(DEPS) fonctions.o tga_combine: tga_combine.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
tga_export: tga_export.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
tga_dither: tga_dither.c $(DEPS) fonctions.o tga_dither: tga_dither.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@

120
Tools/tga_export.c Normal file
View File

@ -0,0 +1,120 @@
/*
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
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" },
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "*** tga_export v 0.0.9 [%s] %s\n",
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
fprintf(stderr, "tga_export source.tga format destination.xxx [params]\n\n");
if (flag)
{
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é */
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
if (idx < 0)
{
fprintf(stderr, "tga_export: format %s inconnu...\n", argv[2]);
exit (5);
}
if ( (argc-nbargs) != FIRST_PARAM )
{
fprintf(stderr, "%s: bad number of parameters\n", argv[0]);
exit(5);
}
/* analyse des paramètres */
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM);
if ( (img=Image_TGA_alloc_load(argv[1]))==NULL )
{
fprintf(stderr, "tga_export: can't load '%s'\n", argv[1]);
exit(5);
}
switch (commande)
{
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;
}
if (foo)
{
fprintf(stderr, "tga_export (%s) ", argv[2]);
Image_print_error("ecriture fichier", foo);
}
return 0;
}
/*::------------------------------------------------------------------::*/