diff --git a/.gitignore b/.gitignore index 5057b35..3082b68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ *.o +libimage.a + foo +Lib/foo +Lib/t_t16x24 diff --git a/Lib/Makefile b/Lib/Makefile index 9e06f8a..624f005 100644 --- a/Lib/Makefile +++ b/Lib/Makefile @@ -8,16 +8,55 @@ include ../Paramakes.mk DEPS = ../tthimage.h Makefile +STATICLIB = "../libimage.a" + #----------------------------------------------------------------- +basic_io.o: basic_io.c $(DEPS) + +drawing.o: drawing.c $(DEPS) + +essais.o: essais.c $(DEPS) essais.h image.o: image.c $(DEPS) +imprime.o: imprime.c $(DEPS) +marques.o: marques.c $(DEPS) msglib.o: msglib.c $(DEPS) +mustopen.o: mustopen.c $(DEPS) + +pht.o: pht.c $(DEPS) + +text0.o: text0.c $(DEPS) +text1.o: text1.c $(DEPS) +text16x24.o: text16x24.c $(DEPS) +tga.o: tga.c $(DEPS) #----------------------------------------------------------------- -foo: foo.c $(DEPS) image.o msglib.o - gcc $(CFLAGS) $< image.o msglib.o -o $@ +OBJECTS = basic_io.o \ + drawing.o \ + essais.o \ + image.o imprime.o \ + marques.o msglib.o mustopen.o \ + pht.o \ + text0.o text1.o text16x24.o tga.o + +$(STATICLIB): $(OBJECTS) + $(AR) vrs $@ $? + $(RANLIB) $@ + +#----------------------------------------------------------------- + +foo: foo.c $(DEPS) $(STATICLIB) + gcc $(CFLAGS) $< $(STATICLIB) -o $@ + +t_t16x24: t_t16x24.c $(DEPS) $(STATICLIB) + gcc $(CFLAGS) $< $(STATICLIB) -o $@ + +#----------------------------------------------------------------- + +testtga: testtga.c $(DEPS) $(STATICLIB) + gcc $(CFLAGS) $< $(STATICLIB) -o $@ #----------------------------------------------------------------- diff --git a/Lib/basic_io.c b/Lib/basic_io.c index f78323b..e57fbd8 100644 --- a/Lib/basic_io.c +++ b/Lib/basic_io.c @@ -21,7 +21,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ int Image_basicIO_teste_boutisme(char *txt) diff --git a/Lib/bitplanes.c b/Lib/bitplanes.c index 783f692..9f76c72 100644 --- a/Lib/bitplanes.c +++ b/Lib/bitplanes.c @@ -10,7 +10,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" #define VERSION_STRING "5 octobre 2015" @@ -248,7 +248,7 @@ if (NULL==(fp=fopen(fname, "w"))) } fprintf(fp, "P1\n%d %d\n", bp->width, bp->height); -fprintf(fp, "# written by libimage v %s\n# bitplane module '%s'\n", +fprintf(fp, "# written by libtthimage v %s\n# bitplane module '%s'\n", IMAGE_VERSION_STRING, VERSION_STRING); chariot = 0; diff --git a/Lib/drawing.c b/Lib/drawing.c new file mode 100644 index 0000000..58f269a --- /dev/null +++ b/Lib/drawing.c @@ -0,0 +1,240 @@ +/* + primitives graphiques premier module (back in 1999) + --------------------------------------------------- +*/ + +#include +#include + +#include "../tthimage.h" + +/*::------------------------------------------------------------------::*/ +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#endif +/*::------------------------------------------------------------------::*/ +static int +iSign(int a) +{ +if (a<0) return -1; +if (a>0) return 1; +return 0; +} +/*::------------------------------------------------------------------::*/ +static void symmetry(int x, int y, int xc, int yc, RGBA *g, Image_Desc *i) +{ +int x_start, x_end; +int y_start, y_end; + +x_start = x; y_start = y; +x_end = x + 1; y_end = y + 1; + +Image_plotRGB(i, x+xc, y+yc, 100, 100, 100); + +fprintf(stderr, "sym %d %d\n", x, y); +} + +/* le paramètre 'wrap' ne sert à rien */ +int +Image_draw_circle(Image_Desc *i, int xc, int yc, int rayon, RGBA *q, int wrap) +{ +int x, y, d; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : centre %d %d, rayon %d\n", __func__, xc, yc, rayon); +#endif + +y = rayon; +d = 3 - 2 * rayon; + +for ( x=0; x 1 +printf("%s %4d %4d -----> %4d %4d\n", __func__, x1, y1, x2, y2); +#endif + +dx = x2 - x1; dy = y2 - y1; +ix = abs(dx); iy = abs(dy); +inc = ix 1 +printf("d %4d %4d i %4d %4d ^ %4d\n", dx, dy, ix, iy, inc); +#endif + +plotx = x1; +ploty = y1; +x = y = 0; + +for (foo=0; foo<=inc; ++foo) + { + x += ix; + y += iy; + plot = 0; + if (x > inc) + { + plot = 42; + x -= inc; + plotx += iSign(dx); + } + if (y > inc) + { + plot = 42; + y -= inc; + ploty += iSign(dy); + } + if (plot) + { + /* printf("%5d %5d %5d\n", foo, plotx, ploty ); */ + Image_plotRGB(i, plotx, ploty, q->r, q->g, q->b); + } + + } +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * XXX si je veux remplacer 'plotRGB' par un accès direct + * XXX dans les buffers, il faut soigner les controles + */ +int +Image_paint_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b) +{ +int xd, yd, xf, yf, x, y; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Paint Rect : image %d x %d\n", img->width, img->height); +Image_dump_rect(rect, "in 'paint a rect'", 0); +#endif + +xd = max(0, rect->x); +yd = max(0, rect->y); +xf = min((img->width), (rect->x+rect->w)); +yf = min((img->height), (rect->y+rect->h)); +/* + * 24 Juin 2002: est-ce que le code ci-dessus a été sérieusement validé ? + * 24 Avril 2008: NON ! + * 26 janvier 2014 : toujours non... + */ + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Paint Rect: %4d < X < %4d %4d < Y < %4d\n", + xd, xf, yd, yf); +#endif + +for (x=xd; xRpix[y])[x] = r; + (img->Gpix[y])[x] = g; + (img->Bpix[y])[x] = b; + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * 27 Juin 2001: there was an off-by-one error in this func... + * See also 'drawpatt.c' for others things. + */ +int +Image_draw_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b) +{ +int foo; +int xd, yd, xf, yf; + +xd = max(0, rect->x); +yd = max(0, rect->y); +xf = min((img->width-1), ((rect->x+rect->w))); +yf = min((img->height-1), ((rect->y+rect->h))); + +#if DEBUG_LEVEL > 1 +Image_dump_rect(rect, "draw a rect", 0); +fprintf(stderr, "Draw a Rect: xd:%4d yd:%4d xf:%4d yf:%4d\n", + xd, yd, xf, yf); +#endif + +for (foo=xd; fooy >= 0) && (rect->y < img->height) ) */ + Image_plotRGB(img, foo, rect->y, r, g, b); + /* if ( (rect->y+rect->h >= 0) && (rect->y+rect->h < img->height) ) */ + Image_plotRGB(img, foo, rect->y+rect->h-1, r, g, b); + } + +for (foo=yd; foox >= 0) && (rect->x < img->width) ) */ + Image_plotRGB(img, rect->x, foo, r, g, b); + /* if ( (rect->x+rect->w >= 0) && (rect->x+rect->w < img->width) ) */ + Image_plotRGB(img, rect->x+rect->w-1, foo, r, g, b); + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* new 10 octobre 2008 - zone de Monredon (Betatech) */ +int +Image_noise_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b) +{ +int xd, yd, xf, yf, x, y; + +fprintf(stderr, "%s: i=%p r=%p %d %d %d\n", __func__, img, rect, r, g, b); + +xd = max(0, rect->x); +yd = max(0, rect->y); +xf = min((img->width-1), (rect->x+rect->w)); +yf = min((img->height-1), (rect->y+rect->h)); + +#if DEBUG_LEVEL +fprintf(stderr, "%s: %d %d %d %d\n", __func__, xd, yd, xf, yf); +#endif + +for (x=xd; xRpix[y])[x] = rand() % r; + (img->Gpix[y])[x] = rand() % g; + (img->Bpix[y])[x] = rand() % b; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * kikoo lol a tous les goret-codeurs, et en particulier Mr Spleyt. + */ + diff --git a/Lib/eps.c b/Lib/eps.c index ca7ba27..cd2c123 100644 --- a/Lib/eps.c +++ b/Lib/eps.c @@ -12,7 +12,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ /* @@ -33,7 +33,7 @@ if ( (fp=fopen(nom, "w")) == NULL ) } fputs("%!PS-Adobe-2.0 EPSF-1.2\n%%\n", fp); -fprintf(fp, "%%%% Generator: libimage v %s\n", IMAGE_VERSION_STRING); +fprintf(fp, "%%%% Generator: libtthimage v %s\n", IMAGE_VERSION_STRING); time(&temps); fprintf(fp, "%%%% Date: %s\n", ctime(&temps)); fclose(fp); diff --git a/Lib/essais.c b/Lib/essais.c index f861928..1310579 100644 --- a/Lib/essais.c +++ b/Lib/essais.c @@ -14,7 +14,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" #include "essais.h" /*::------------------------------------------------------------------::*/ diff --git a/Lib/essais.h b/Lib/essais.h new file mode 100644 index 0000000..ea9bf24 --- /dev/null +++ b/Lib/essais.h @@ -0,0 +1,83 @@ +/* + * Routines de test de machins de la LibImage de tTh + * + * Bien entendu, pas la moindre explication ici :) + */ + +int Essai_Extractbits(char *fname, int k); +int Essai_des_Quadpics(char *fsrc, int k); +int Essai_des_drawings(char *fname, int k); +int Essai_des_Combines(char *fname, int k); +int Essai_de_la_Recursion(char *fname, int k); +int Essai_des_Glitches(char *fsrc, int k); +int Essai_anamorphoses(char *fsrc, double dk, int k); + +int Essai_des_bitplanes(char *txt, int w, int h); +int Essayer_les_alphas(char *fname, int k); +int Essai_des_bitplanes(char *txt, int w, int h); + +int Manipuler_les_couleurs(char *fname, int k); +int Essai_luminance(char *scrname, int k); +int Essais_plot_Map(int k); +int Essai_raw16bits(char *srcname, int k); +int Essai_color_2_map(char *srcname, int k); +int Essai_des_gray_ops(char *srcname, int k); +int Essai_des_Contrastes(char *, int); +int Essai_des_lut15bits(char *srcname, int k); +int Essai_des_mires(char *, int, int); +int Essai_des_zooms(char *srcname, int k); + +int Essai_des_7_segments(char *srcname, int flag); +int Essai_des_distances(char *srcname, int nbre, int flag); +int Essai_des_cadres(char *srcname, int flags); +int Filtre_Directionnel(char *srcname, int flags); + +int Test_des_trucs_2x2(char *srcname, int k); +int Test_des_warpings(char *srcname, int k); +int Test_des_mosaiques(char *srcname, int k); + +int Test_hf15_synth_fromfunc(char *fname); +int Test_hf15_synth_fromPtl(char *fname, char *oname); +int Test_funcs_hf15(char *mntname, int flag); +int Test_des_df3(char *txt, int k); + +int Test_vignettes(char *srcname, int k); + +int Test_classif(char *srcname, int k); +int Test_rgbmask(char *srcname); +void Test_rgb2xyz(void); + +int Essai_des_marquages(char *srcname, int nombre, char *texte); +void Test_double_size(void); +int Test_new_scale(char *fnamesrc, int coef); + +int Test_copie_de_rectangles(char *nomsource); +int Test_Egalisations(char *nomsource, int k); +int Test_Dithering(char *nomsource, int k); +int Test_des_marquages(char *srname, int k1, int k2); +int Test_Effects_A(char *nomsource, int flag); + +int Test_des_tamppools(char *imgname, int param); +int Essai_export_palettes(char *basename); + +int Test_des_filtres(char *srcname, int k); + +void Test_des_patterns(char *prefix, int foo, int bar); +int Test_des_pixeliz(char *srcname, int flags); + +int Essai_des_bitblt(char *srcname, int k); +int Essai_des_gadgrect(char *srcname, int k); + +int Essai_Television(char *source, int k); + +/* dans essais2;c */ +int Essai_des_big_chars(char *fname, int k); +int Essai_des_jauges(char *fname, int k); + + +/* + * Le programme principal est 'testtga.c' mais il serait bien de faire + * une fonction qui enchaine tous les Tests et tous les Essais afin + * de pouvoir facilement valgrinder le tout :) + */ + diff --git a/Lib/foo.c b/Lib/foo.c index 6f42125..9b16c66 100644 --- a/Lib/foo.c +++ b/Lib/foo.c @@ -3,10 +3,12 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" int main(int argc, char *argv[]) { Image_print_version(2); +Image_print_sizeof_structs("foo"); + return 0; } diff --git a/Lib/image.c b/Lib/image.c index 5d59e08..0ab063c 100644 --- a/Lib/image.c +++ b/Lib/image.c @@ -1,6 +1,6 @@ /* - fonctions de bases pour la librairie 'libimage' - ----------------------------------------------- + fonctions de bases pour la librairie 'libtthimage' + -------------------------------------------------- (g) 1992,2003 - Thierry Boudet - aka Oulala @@ -10,7 +10,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ void @@ -19,7 +19,7 @@ Image_print_version(int flag) char *ptr; fflush(stdout); -printf("-+- This is the `image' library v%s (dwtfywl 2022) tTh\n", +printf("-+- This is the `tthimage' library v%s (dwtfywl 2022) tTh\n", IMAGE_VERSION_STRING); if (flag) { @@ -38,15 +38,15 @@ fflush(stdout); /* OMFG, this is a gnuism ! */ if ( (ptr=getenv("MALLOC_CHECK_")) != NULL) { - fprintf(stderr, "-+- libimage: malloc check is set to %s\n", ptr); + fprintf(stderr, "-+- libtthimage: malloc check is set to %s\n", ptr); } #if DEBUG_LEVEL fprintf(stderr, - "Warning! this version of libimage is compiled with DEBUG_LEVEL=%d\n", + "Warning! this version of libtthimage is compiled with DEBUG_LEVEL=%d\n", DEBUG_LEVEL); #if FORCE_ABORT -fprintf(stderr, "Warning! this version of libimage is compiled with FORCE_ABORT!\n"); +fprintf(stderr, "Warning! this version of libtthimage is compiled with FORCE_ABORT!\n"); #endif #endif } @@ -183,7 +183,7 @@ switch (type) if (getenv("MALLOC_CHECK_") != NULL) { - fprintf(stderr, "-+- libimage %s %d: alloc %p\n", + fprintf(stderr, "-+- libtthimage %s %d: alloc %p\n", __FILE__, __LINE__, header); } @@ -576,7 +576,7 @@ Image_DeAllocate(Image_Desc *im) int line; if (getenv("MALLOC_CHECK_") != NULL) { - fprintf(stderr, "-+- libimage %s %d: free %p\n", + fprintf(stderr, "-+- libtthimage %s %d: free %p\n", __FILE__, __LINE__, im); } diff --git a/Lib/imprime.c b/Lib/imprime.c index 8d7fae1..2559593 100644 --- a/Lib/imprime.c +++ b/Lib/imprime.c @@ -4,7 +4,7 @@ */ #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ int @@ -60,7 +60,7 @@ printf("\n"); printf("basic types : short=%d int=%d long=%d ptr=%d\n", sizeof(short), sizeof(int), sizeof(long), sizeof(void *)); -/* examen des tructures de la libimage */ +/* examen des tructures de la libtthimage */ printf("Image_Desc : %5u\n", sizeof(Image_Desc)); printf("Image_Rect : %5u\n", sizeof(Image_Rect)); printf("RGBA : %5u\n", sizeof(RGBA)); diff --git a/Lib/marques.c b/Lib/marques.c index b1a170d..3eac7af 100644 --- a/Lib/marques.c +++ b/Lib/marques.c @@ -9,7 +9,7 @@ #include #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ /* diff --git a/Lib/mircol.c b/Lib/mircol.c index cb7d229..70b687b 100644 --- a/Lib/mircol.c +++ b/Lib/mircol.c @@ -7,7 +7,7 @@ #include #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ int @@ -52,7 +52,7 @@ if (txt != NULL) Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte", &fond, &encre); -Image_trace_chaine_1(dst, "Libimage de tTh", 270, 370, "libimage.fonte", +Image_trace_chaine_1(dst, "Libtthimage de tTh", 270, 370, "libimage.fonte", &fond, &encre); Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 385, NULL, &fond, &encre); Image_trace_chaine_1(dst, __DATE__, 270, 400, NULL, &fond, &encre); @@ -94,7 +94,7 @@ encre.r = 255; encre.g = 255; encre.b = 255; encre.a = 255; /* ya pas moyen de mettre ces textes dans des jolies boites ? */ Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte", &fond, &encre); -Image_trace_chaine_1(dst, "Libimage de tTh", 270, 370, NULL, &fond, &encre); +Image_trace_chaine_1(dst, "Libtthimage de tTh", 270, 370, NULL, &fond, &encre); Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 390, NULL, &fond, &encre); return FUNC_IS_ALPHA; diff --git a/Lib/msglib.c b/Lib/msglib.c index 6d37aea..96fe4e7 100644 --- a/Lib/msglib.c +++ b/Lib/msglib.c @@ -6,7 +6,7 @@ #include #include /* for abort() */ #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ char * diff --git a/Lib/mustopen.c b/Lib/mustopen.c index cfc015d..db69516 100644 --- a/Lib/mustopen.c +++ b/Lib/mustopen.c @@ -16,7 +16,7 @@ #include #endif -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ /* @@ -68,7 +68,7 @@ if ( (path=getenv(ENV_LIBIMAGE_PATH)) != NULL) /* Ahem, trying with the hardcoded path to shared file - of libimage. Hop this help. + of libtthimage. Hop this help. */ path = SHAREDIR "/"; /* don't forget the trailing '/' */ @@ -166,7 +166,7 @@ else /* * Ahem, trying with the hardcoded path to shared file - * of libimage. Hope this help. + * of libtthimage. Hope this help. */ path = SHAREDIR "/"; /* don't forget the trailing '/' */ diff --git a/Lib/pht.c b/Lib/pht.c index 1cd93d1..dc91e90 100644 --- a/Lib/pht.c +++ b/Lib/pht.c @@ -27,13 +27,13 @@ ------------------------------------------ NEW: 12 Sept 2001. - je commence à modifier pour que ce soit indépendant du + je commence a modifier pour que ce soit independant du boutisme, et les premiers essais seront fait sur Sparc. */ #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ int diff --git a/Lib/pnm.c b/Lib/pnm.c index 92462a4..dcff825 100644 --- a/Lib/pnm.c +++ b/Lib/pnm.c @@ -18,7 +18,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" #define TAILLE_MAX_LIGNE 75 #define VERSION_STRING "December 2009" @@ -58,7 +58,7 @@ else } fprintf(fp, "P1\n %d %d\n", im->width, im->height); -fprintf(fp, "# written by libimage v %s, pnm module %s\n", +fprintf(fp, "# written by libtthimage v %s, pnm module %s\n", IMAGE_VERSION_STRING, VERSION_STRING); if (strlen(im->name) > 0) @@ -172,7 +172,7 @@ else } fprintf(fp, "P3\n%d %d\n255\n", im->width, im->height); -fprintf(fp, "# written by libimage v %s, ppm module '%s'\n\n", +fprintf(fp, "# written by libtthimage v %s, ppm module '%s'\n\n", IMAGE_VERSION_STRING, VERSION_STRING); if (strlen(im->name) > 0) @@ -249,7 +249,7 @@ else } fprintf(fp, "P2\n%d %d\n255\n", im->width, im->height); -fprintf(fp, "\n# written by libimage v %s\n# pnm module %s\n\n", +fprintf(fp, "\n# written by libtthimage v %s\n# pnm module %s\n\n", IMAGE_VERSION_STRING, VERSION_STRING); for (y=0; yheight; y++) diff --git a/Lib/t_t16x24.c b/Lib/t_t16x24.c new file mode 100644 index 0000000..0d2d814 --- /dev/null +++ b/Lib/t_t16x24.c @@ -0,0 +1,50 @@ +/* + Proggy de test pour les fontes 16x24 - new 4 mai 2007, a StEx. +*/ + +#include +#include +#include + +#include "../tthimage.h" + +/*::------------------------------------------------------------------::*/ +int essai_f1(char *tgasrc, char *tgadst, char *texte) +{ +Image_Desc *img; +int foo; +RGBA encre, papier; + +img = Image_TGA_alloc_load(tgasrc); + +foo = Image_t16x24_txtload("16x24thin", NULL, 0); + +encre.r = 0; encre.g = 255; encre.b = 100; encre.a = 255; +papier.r = 255; papier.b = 0; papier.g = 0; papier.a = 200; + +foo = Image_t16x24_pltstr_1(img, texte, 2, 42, &papier, &encre, 0); + +foo = Image_TGA_save(tgadst, img, 0); + +return -1; +} +/*::------------------------------------------------------------------::*/ +int main(int argc, char *argv[]) +{ +char *fichier; +int foo; +Image_Desc *image; + +fprintf(stderr, "-------------- %s ------------\n", argv[0]); +foo = Image_t16x24_chars_map("16x24thin", "all16x24chars.tga", 0); +foo = Image_t16x24_chars_map("bigfont.txt", "all16X24chars.tga", 0); +fprintf(stderr, "--------------------------\n"); +Image_print_error("Essai fonte 16x24", foo); + +foo = essai_f1("pov.tga", "/tmp/aaaa_plop.tga", "0123456789"); +if (foo) { + fprintf(stderr, " ---> %d\n", foo); + } +return 0; +} +/*::------------------------------------------------------------------::*/ diff --git a/Lib/testtga.c b/Lib/testtga.c index c07dfa3..1e1b69c 100644 --- a/Lib/testtga.c +++ b/Lib/testtga.c @@ -10,7 +10,7 @@ #include #include -#include "tthimage.h" +#include "../tthimage.h" #include "essais.h" /*::------------------------------------------------------------------::*/ diff --git a/Lib/text0.c b/Lib/text0.c new file mode 100644 index 0000000..db610ee --- /dev/null +++ b/Lib/text0.c @@ -0,0 +1,290 @@ +/* + text0.c + ------- + + ce module est en phase de 'reflexion'. je n'ai pas la moindre + idee sur l'organisation de la chose. je pense utiliser les + fontes bitmap de la console PC. + + 28 Fev 2001: now the standard font is loaded from the file + /usr/local/share/libimage.fonte + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../tthimage.h" + +#define T_FONTE 2048 + +static uint8_t priv_fonte[T_FONTE]; + +/*::------------------------------------------------------------------::*/ +/* + * for now, parameter *ou must be NULL + */ +int +Image_load_fnt8x8(char *nomfnt, uint8_t *ou, int flags) +{ +int fd, foo; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s: %s %p %d\n", __func__, nomfnt, ou, flags); +#endif + +if (NULL != ou) + fprintf(stderr, "in %s, 'ou' (%p) must be NULL\n", __func__, ou); +if (0 != flags) + fprintf(stderr, "in %s, 'flags' (%d) must be 0\n", __func__, flags); + +/* patch du 24 septembre 2015 */ +if (NULL == nomfnt) { + nomfnt = "libimage.fonte"; + fprintf(stderr, "%s : using default font '%s'\n", __func__, nomfnt); + } +/* on pourrait aussi mettre la fonte par ddefaut dans l'environ */ + +if ( (fd=Image_must_open(nomfnt, O_RDONLY, 0)) < 0 ) + { + perror (nomfnt); + exit(5); + } + +foo = read(fd, priv_fonte, T_FONTE); +if ( foo != T_FONTE ) + { + fprintf(stderr, "%s: error when reading font datas\n", __func__); + exit(5); + } +close(fd); + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s : font '%s' loaded\n", __func__, nomfnt); +#endif + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * XXX nasty bug in the alpha channel gestion XXX + */ +int +Image_trace_caractere_2(Image_Desc *im, uint8_t *fnt, int x, int y, int code, + RGBA *paper, RGBA *ink) +{ +int foo, bar, xi, yi; +int rp, gp, bp, rs, gs, bs; +uint8_t octet; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "trace car 2: xy= %4d %4d c= %c\n", x, y, + isprint(code) ? code : ' '); +#endif + +if (NULL==fnt) + { + fnt = priv_fonte; /* use local static storage */ + } + +for (foo=0; foo<8; foo++) + { + yi = y+foo; + octet = fnt[(code*8)+foo]; + for (bar=0; bar<8; bar++) + { + xi = x+7-bar; + + /* lecture contenu image */ + rs = (im->Rpix[yi])[xi]; + gs = (im->Gpix[yi])[xi]; + bs = (im->Bpix[yi])[xi]; + + if (octet & 1) /* ENCRE */ + { + rp = ((rs*(255-ink->a))+(ink->r*ink->a)) / 255; + gp = ((gs*(255-ink->a))+(ink->g*ink->a)) / 255; + bp = ((bs*(255-ink->a))+(ink->b*ink->a)) / 255; + } + else /* PAPIER */ + { + rp = ((rs*(255-paper->a))+(paper->r*paper->a)) / 255; + gp = ((gs*(255-paper->a))+(paper->g*paper->a)) / 255; + bp = ((bs*(255-paper->a))+(paper->b*paper->a)) / 255; + } + (im->Rpix[yi])[xi] = rp; + (im->Gpix[yi])[xi] = gp; + (im->Bpix[yi])[xi] = bp; + + octet >>= 1; + } + } +return 42; +} +/*::------------------------------------------------------------------::*/ +/* + * fonction très primitive... + */ +int +Image_trace_caractere(Image_Desc *im, int x, int y, int code) +{ +int foo, bar; +uint8_t octet; + +for (foo=0; foo<8; foo++) + { + octet = priv_fonte[(code*8)+foo]; + for (bar=0; bar<8; bar++) + { + if (octet & 1) + Image_plotRGB(im, x+8-bar, y+foo, 255, 255, 255); + else + Image_plotRGB(im, x+8-bar, y+foo, 0, 0, 5); + octet >>= 1; + } + } + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* + * trace d'une chaine. (param 'flag' not used) + * OBSOLETE FUNCTION ! + */ +int Image_trace_chaine_0(Image_Desc *im, char *txt, int x, int y, + RGBA *paper, RGBA *ink, int flags) +{ +int foo; + +fprintf(stderr, "THE FUNCTION '%s' IS OBSOLETE\n", __func__); +if (0 != flags) + fprintf(stderr, "in %s, 'flags' (%d) must be 0\n", __func__, flags); +foo = Image_trace_chaine_1(im, txt, x, y, "libimage.fonte", paper, ink); + +return foo; +} +/*::------------------------------------------------------------------::*/ +/* + * trace d'une chaine avec choix eventuel de la fonte par le + * nom du fichier. Si celui-ci est NULL, c'est la fonte actuelle + * qui est utilise. + */ +int Image_trace_chaine_1(Image_Desc *im, char *txt, int x, int y, + char *nomfonte, RGBA *paper, RGBA *ink) +{ +int posx, posy, t_texte, foo; +int octet; +uint8_t *ptrtxt; +RGBA blanc = { 255, 255, 255, 255, 0, 0 }; +RGBA noir = { 0, 0, 0, 64, 0, 0 }; + +if (nomfonte==NULL) { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "trace chaine 1: using loaded font\n"); +#endif + } +else { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "trace chaine 1: loading font '%s'\n", nomfonte); +#endif + foo = Image_load_fnt8x8(nomfonte, NULL, 0); + } + +if (NULL==paper) paper = &blanc; +if (NULL==ink) ink = &noir; + +#if DEBUG_LEVEL > 1 +Image_print_rgba("encre", ink, 0); +Image_print_rgba("papier", paper, 0); +#endif + +t_texte = strlen(txt); +ptrtxt = (uint8_t *)txt; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "texte %3d %s\n", t_texte, txt); +fprintf(stderr, "papier %3d %3d %3d %3d\n", paper->r, paper->g, paper->b, paper->a); +fprintf(stderr, "encre %3d %3d %3d %3d\n", ink->r, ink->g, ink->b, ink->a); +#endif + +posx = x; posy = y; +for (foo=0; foo (im->width-8)) + { + fprintf(stderr, "can't plot char '%c' at x=%d\n", octet, posx); + break; + } + Image_trace_caractere_2(im, priv_fonte, posx, posy, octet, paper, ink); + posx += 8; + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* new --> Sun Feb 2 20:17:34 CET 2014 */ +/* + * Don't forget to load a font, eg : + * Image_load_fnt8x8("8x8thin", NULL, 0); + */ +int +Image_trace_big_char_0(Image_Desc *im, int x, int y, int code, int kx, int ky) +{ +int foo, bar; +uint8_t octet; +Image_Rect rect; +RGBA paper, ink; + +#if DEBUG_LEVEL +char buff[20]; +if (isprint(code)) sprintf(buff, "'%c'", code); +else sprintf(buff, "%02xh", code); +fprintf(stderr, "%s ( %p %4d %4d %s %d %d )\n", __func__, im, + x, y, buff, kx, ky); +#endif + +if ( (code < 0) || (code > 255)) + { + fprintf(stderr, "in %s, code (%d) is invalid\n", __func__, code); + return BAD_PARAMETER; + } + +Image_load_fnt8x8("8x8thin", NULL, 0); + +paper.r = paper.g = paper.b = 0; +ink.r = ink.g = ink.b = 255; + +rect.w = kx, rect.h = ky; + +for (foo=0; foo<8; foo++) /* 8 scan lines */ + { + octet = priv_fonte[(code*8)+foo]; + rect.y = (foo * ky) + y; + for (bar=0; bar<8; bar++) + { + rect.x = (bar * kx) + x; + rect.x = ((8-bar)*kx) + x; + if (octet & 1) + { +#if DEBUG_LEVEL > 1 + Image_plotRGB(im, x+8-bar, y+foo, 255, 255, 255); +#endif + Image_paint_rect(im, &rect, 255, 198, 0); + Image_draw_rect(im, &rect, 0, 0, 80); + } + octet >>= 1; + } + } + +im->modified++; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/Lib/text1.c b/Lib/text1.c new file mode 100644 index 0000000..a3fe92c --- /dev/null +++ b/Lib/text1.c @@ -0,0 +1,98 @@ +/* + text1.c + ------- +*/ + +#include +#include +#include +#include + +#include "../tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * parameter 'flags' is not used (reserved), must be 0. + */ +int +Image_txt1_box_0(Image_Desc *img, char *txt, int x, int y, int w, + RGBA *paper, RGBA *ink, int flags) +{ +int foo, lstr; +Image_Rect rect; + +if (flags != 0) + { + fprintf(stderr, "%s : wrong flags: 0x%x\n", __func__, flags); + return WRONG_FLAG; + } +if (w < 0) + { + fprintf(stderr, "Ahem, w (%d) is < 0 ?\n", w); + } + +lstr = strlen(txt); + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Txt1 box 0: taille texte: %d\n", lstr); +Image_print_rgba("Papier", paper, 0); +Image_print_rgba("Encre", ink, 0); +#endif + +rect.x = x; rect.y = y; +rect.h = 8 + (w*2); +rect.w = (lstr*8) + (w*2); + +foo = Image_paint_rect(img, &rect, paper->r, paper->g, paper->b); +if (foo) + Image_print_error("txt box 0: paint rect: ", foo); + +foo = Image_trace_chaine_1(img, txt, x+w, y+w, "libimage.fonte", paper, ink); +if (foo) + Image_print_error("txt box 0: trace chaine 0: ", foo); + +foo = Image_draw_rect(img, &rect, ink->r, ink->g, ink->b); +if (foo) + Image_print_error("txt box 0: draw rect: ", foo); + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* new --> Sun Feb 2 20:12:07 CET 2014 */ +/* + * Don't forget to load a font, eg : + * Image_load_fnt8x8("8x8thin", NULL, 0); + */ +int Image_txt1_big_0(Image_Desc *im, char *txt, int x, int y, + int xf, int yf) +{ +int foo, idx, len; +int xpos; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p \"%s\" %d %d %d %d )\n", __func__, im, + txt, x, y, xf, yf); +#endif + +len = strlen(txt); +#if DEBUG_LEVEL +fprintf(stderr, " len = %d\n", len); +#endif + +xpos = x; +for (idx=0; idx 2 + fprintf(stderr, " idx %3d ch 0x%02x x %d\n", + idx, txt[idx], xpos); +#endif + foo = Image_trace_big_char_0(im, xpos, y, txt[idx], xf, yf); +#if DEBUG_LEVEL + fprintf(stderr, "Image_trace_big_char_0 -> %d\n", foo); +#endif + xpos += (xf * 8); + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/Lib/text16x24.c b/Lib/text16x24.c new file mode 100644 index 0000000..6dcde6b --- /dev/null +++ b/Lib/text16x24.c @@ -0,0 +1,327 @@ +/* + * textes en 16x24 + * --------------- + */ + +#include +#include +#include +#include +#include "../tthimage.h" + +/*::------------------------------------------------------------------::*/ +typedef struct { + short flags; + uint16_t bits[24]; + } Char_16x24; + +/* go, go, go, have a global var */ +Char_16x24 chars_16x24[256]; + +/*::------------------------------------------------------------------::*/ +/* + il n'y a encore rien dans cette fonction, car je suis en train + de construire un éditeur de fonte adapté a _mes_ besoins. + dès qu'il commencera à être utilisable, et surtout dès que les + spécifications du format de fichier seront relativement figées, + je commencerais à coder la chose. +*/ +int Image_t16x24_binload(char *fontname, uint8_t *zone, int flag) +{ + +fprintf(stderr, "Don't know how to load '%s' in binary mode\n", fontname); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* WARNING: this function is a work in progress */ + +int Image_t16x24_txtload(char *fontname, uint8_t *zone, int flags) +{ +FILE *fp; +int numchar; +int foo, bar, x, y, eol, mask; +char ligne[20+1]; +uint16_t mot; + +if ( NULL == (fp=Image_must_fopen(fontname, "r", 0)) ) + { + fprintf(stderr, "can't open %s\n", fontname); + return FILE_NOT_FOUND; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s: trying to load '%s' (%d)\n", __func__, fontname, flags); +#endif + +/* 16 juin 2015 : now we can erase the whole font by + setting bit 0 of flags to one */ +if (flags & 1) { + fprintf(stderr, "erasing 16x24 font at %p\n", chars_16x24); + memset(chars_16x24, 0, sizeof(chars_16x24)); + } + +while ( 1 == fscanf(fp, "%d\n", &numchar) ) + { + if ( (numchar<0) || (numchar>255) ) + { + fprintf(stderr, "char %d out of range\n", numchar); + break; + } +#if DEBUG_LEVEL > 1 + fprintf(stderr, "------- Char %3d '%c'\n", numchar, + isprint(numchar) ? numchar : ' '); +#endif + + for (y=0; y<24; y++) + { + /* lecture d'une ligne d'ascii-pixels */ + memset(ligne, '\0', 20); + if ( NULL==fgets(ligne, 20, fp) ) + { + fprintf(stderr, "EOF ?\n"); + } + foo = strlen(ligne); + eol = ligne[16]; + if (foo!=17 || eol!='\n') + { + fprintf(stderr, "%s: bad line: %3d %3d %3d\n", + __func__, y, foo, eol); + fprintf(stderr, " [%s]\n", ligne); + abort(); /* very hard, no ? XXX */ + } + mask = 0x8000; + mot = 0; + for (x=0; x<16; x++) + { + if (ligne[x]=='*' || ligne[x]=='0') + { + mot |= mask; +#if DEBUG_LEVEL > 1 + putchar('O'); +#endif + } +/* ahem, ne serait-il pas bon de filtrer un peu plus les + * caracteres indesirables ? */ +#if DEBUG_LEVEL > 1 + else + putchar(' '); +#endif + mask >>= 1; + } +#if DEBUG_LEVEL > 1 + printf(" | %04x\n", mot); +#endif + chars_16x24[numchar].bits[y] = mot; + } + /* fin de la boucle sur les caracteres dans le fichier */ + } + +fclose(fp); + +return 0; +} +/*::------------------------------------------------------------------::*/ +int Image_t16x24_pltch_exp(Image_Desc *img, int lettre, int xpos, int ypos) +{ +int x, y; +uint16_t mask; + + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s: lettre %3d '%c' %4d %4d\n", __func__, lettre, + isprint(lettre) ? lettre : ' ', xpos, ypos); +#endif + +for (x=0; x<16; x++) + for (y=0; y<24; y++) + Image_plotRGB(img, x+xpos, y+ypos, 60, 60, 80); +for (y=0; y<24; y++) + { + mask = 0x8000; + for (x=0; x<16; x++) + { + if (chars_16x24[lettre].bits[y] & mask) + { +#if DEBUG_LEVEL > 2 + putchar('X'); +#endif + Image_plotRGB(img, x+xpos, y+ypos, 200, 200, 250); + } +#if DEBUG_LEVEL > 2 + else putchar('-'); +#endif + mask >>= 1; + } +#if DEBUG_LEVEL > 2 + putchar('\n'); +#endif + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int Image_t16x24_pltch_1(Image_Desc *img, int lettre, int xpos, int ypos, + RGBA *pap, RGBA *ink, int flags) +{ +int x, y, rs, gs, bs; +int rp, gp, bp; +int x2, y2; +uint16_t mask; + +/* safety plug */ + + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s: ltr %3d '%c' %4d %4d\n", __func__, lettre, + isprint(lettre) ? lettre : ' ', xpos, ypos); +#endif + +for (y=0; y<24; y++) + { + mask = 0x8000; + y2 = y + ypos; + for (x=0; x<16; x++) + { + x2 = x + xpos; + Image_getRGB(img, x2, y2, &rs, &gs, &bs); + if (chars_16x24[lettre].bits[y] & mask) + { +#if DEBUG_LEVEL > 1 + putchar('O'); +#endif + rp = ((rs*(255-ink->a))+(ink->r*ink->a)) / 255; + gp = ((gs*(255-ink->a))+(ink->g*ink->a)) / 255; + bp = ((bs*(255-ink->a))+(ink->b*ink->a)) / 255; + } + else + { +#if DEBUG_LEVEL > 1 + putchar('.'); +#endif + rp = ((rs*(255-pap->a))+(pap->r*pap->a)) / 255; + gp = ((gs*(255-pap->a))+(pap->g*pap->a)) / 255; + bp = ((bs*(255-pap->a))+(pap->b*pap->a)) / 255; + } + Image_plotRGB(img, x2, y2, rp, gp, bp); + mask >>= 1; + } /* finbo x */ +#if DEBUG_LEVEL > 1 + putchar('\n'); +#endif + } /* finbo y */ + +return FUNC_IS_ALPHA;/* BETIC ? */ +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +int Image_t16x24_pltstr_1(Image_Desc *img, char *str, int x, int y, + RGBA *paper, RGBA *ink, int flags) +{ +int len, foo; + +len = strlen(str); +#if DEBUG_LEVEL +fprintf(stderr, "%s: '%s' at %d,%d\n", __func__, str, x, y); +#endif + +for (foo=0; foo 1 + fprintf(stderr, "%4d %c\n", foo, str[foo]); +#endif + Image_t16x24_pltch_1(img, str[foo], x+(foo*16), y, paper, ink, flags); + } + +return FUNC_IS_ALPHA; /* BETIC ? */ +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +#define T_ZONE (256*24*2) /* please explain this magic number */ + +int Image_t16x24_essai(char *fontname, char *texte, char *tganame) +{ +Image_Desc *img; +int foo; +int ltxt, largeur; + +fprintf(stderr, "*** essai fonte 16x24: %s -> %s\n", fontname, tganame); +fprintf(stderr, " texte -> '%s'\n", texte); + +foo = Image_t16x24_txtload(fontname, NULL, 0); +Image_print_error("fonte 16x24, txtload", foo); + +ltxt = strlen(texte); +largeur = 16 * ltxt; + +img = Image_alloc(largeur, 24, 3); +if (NULL == img) + { + abort(); + } +Image_clear(img, 0, 0, 0); + +for (foo=0; foo #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ #define LIBTGA_VERSION "0.2.41" @@ -91,8 +91,8 @@ if (img->magic != MAGIC_OF_IMAGE) { return NOT_AN_IMAGE_DESC; } /* - * mais ça marche pas à tous les coups. il faudrait pouvoir tester si - * le pointeur 'img' est cohérent, mais je sais pas comment faire... + * mais ça marche pas a tous les coups. il faudrait pouvoir tester si + * le pointeur 'img' est coherent, mais je sais pas comment faire... */ if (compress != 0) { fprintf(stderr, "%s: compress %d not implemented\n", diff --git a/Lib/tools.c b/Lib/tools.c index ad7421b..95ec4ba 100644 --- a/Lib/tools.c +++ b/Lib/tools.c @@ -7,7 +7,7 @@ #include #include #include -#include "tthimage.h" +#include "../tthimage.h" /*::------------------------------------------------------------------::*/ /* diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..50c107e --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + + +cd Lib +make foo +cd .. diff --git a/tthimage.h b/tthimage.h index 1e60c99..9618985 100644 --- a/tthimage.h +++ b/tthimage.h @@ -4,7 +4,7 @@ http:///la.buvette.org/devel/libimage/ */ #ifndef IMAGE_VERSION_STRING - #define IMAGE_VERSION_STRING "0.4.43" + #define IMAGE_VERSION_STRING "0.4.45" /*::------------------------------------------------------------------::*/ /*