From ecd0186b28f4afffa369f3608a9085ad8e0b58c5 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 26 Jun 2022 11:06:35 +0200 Subject: [PATCH] second massive import batch --- .gitignore | 5 + Makefile | 352 ++++++++++++ anamorphose.c | 144 +++++ basic_io.c | 163 ++++++ bitblt.c | 250 +++++++++ bitplanes.c | 277 ++++++++++ bmp.c | 286 ++++++++++ bmp.h | 30 ++ calcluts.c | 119 +++++ calculs.c | 275 ++++++++++ classif.c | 174 ++++++ col_reduc.c | 45 ++ col_xyz.c | 38 ++ colors.c | 694 ++++++++++++++++++++++++ colors2.c | 204 +++++++ combine.c | 449 ++++++++++++++++ combine2.c | 158 ++++++ combine3.c | 161 ++++++ combine4.c | 175 ++++++ combine5.c | 191 +++++++ combine6.c | 120 +++++ combine_rnd.c | 104 ++++ contours.c | 15 + contrast.c | 76 +++ detect.c | 151 ++++++ detect2.c | 43 ++ dither.c | 299 +++++++++++ dither2.c | 190 +++++++ dither3.c | 37 ++ dither4.c | 91 ++++ effects.c | 377 +++++++++++++ effects2.c | 218 ++++++++ effects3.c | 341 ++++++++++++ eps.c | 47 ++ essais.c | 1418 +++++++++++++++++++++++++++++++++++++++++++++++++ essais.h | 83 +++ filtadapt.c | 93 ++++ filtres.c | 467 ++++++++++++++++ gadgrect.c | 202 +++++++ gamma.c | 36 ++ glitch.c | 134 +++++ gray_ops.c | 35 ++ image.c | 38 +- imprime.c | 72 +++ luts15bits.c | 101 ++++ marques.c | 230 ++++++++ mircol.c | 321 +++++++++++ msglib.c | 148 ++++++ mustopen.c | 205 +++++++ octree.c | 41 ++ op2x2.c | 241 +++++++++ operat.c | 688 ++++++++++++++++++++++++ pcx.c | 360 +++++++++++++ pht.c | 140 +++++ png.c | 39 ++ pnm.c | 309 +++++++++++ ptlist.c | 276 ++++++++++ quadpics.c | 185 +++++++ rgbmask.c | 184 +++++++ sobel4.c | 73 +++ tamppool.c | 66 +++ tele_2.c | 316 +++++++++++ television.c | 289 ++++++++++ testtga.c | 99 ++++ tga.c | 629 ++++++++++++++++++++++ tools.c | 387 ++++++++++++++ tthimage.h | 2 +- turtle.c | 61 +++ vignetize.c | 46 ++ zoom.c | 91 ++++ 70 files changed, 14402 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 anamorphose.c create mode 100644 basic_io.c create mode 100644 bitblt.c create mode 100644 bitplanes.c create mode 100644 bmp.c create mode 100644 bmp.h create mode 100644 calcluts.c create mode 100644 calculs.c create mode 100644 classif.c create mode 100644 col_reduc.c create mode 100644 col_xyz.c create mode 100644 colors.c create mode 100644 colors2.c create mode 100644 combine.c create mode 100644 combine2.c create mode 100644 combine3.c create mode 100644 combine4.c create mode 100644 combine5.c create mode 100644 combine6.c create mode 100644 combine_rnd.c create mode 100644 contours.c create mode 100644 contrast.c create mode 100644 detect.c create mode 100644 detect2.c create mode 100644 dither.c create mode 100644 dither2.c create mode 100644 dither3.c create mode 100644 dither4.c create mode 100644 effects.c create mode 100644 effects2.c create mode 100644 effects3.c create mode 100644 eps.c create mode 100644 essais.c create mode 100644 essais.h create mode 100644 filtadapt.c create mode 100644 filtres.c create mode 100644 gadgrect.c create mode 100644 gamma.c create mode 100644 glitch.c create mode 100644 gray_ops.c create mode 100644 imprime.c create mode 100644 luts15bits.c create mode 100644 marques.c create mode 100644 mircol.c create mode 100644 msglib.c create mode 100644 mustopen.c create mode 100644 octree.c create mode 100644 op2x2.c create mode 100644 operat.c create mode 100644 pcx.c create mode 100644 pht.c create mode 100644 png.c create mode 100644 pnm.c create mode 100644 ptlist.c create mode 100644 quadpics.c create mode 100644 rgbmask.c create mode 100644 sobel4.c create mode 100644 tamppool.c create mode 100644 tele_2.c create mode 100644 television.c create mode 100644 testtga.c create mode 100644 tga.c create mode 100644 tools.c create mode 100644 turtle.c create mode 100644 vignetize.c create mode 100644 zoom.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5057b35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +*.o + +foo + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..65c086c --- /dev/null +++ b/Makefile @@ -0,0 +1,352 @@ +#----------------------------------------------------------------- +# 1er Fevrier 2000: Je met une cible pour installer +# les fichiers dans le systeme. C'est assez +# rudimentaire/arbitraire, mais c,a marche +# a peu pres, mieux que le Momo... +# +#----------------------------------------------------------------- + +DESTDIR=/usr/local +SHARED_FILES=$(DESTDIR)/share/libimage +HTML_DIR=$(DESTDIR)/html + +#----------------------------------------------------------------- +# +# pour le debuging: option -g +# pour le profiling: option -pg +# pour tracer plein de trucs: -DDEBUG_LEVEL=1 +# if IMGCOMMENT, the image comment is written to the TGA file, +# but this files can't be loaded by Xv... +# pour coredumper dans les situations graves: -DABORT=1 +# +# --> see file 'PORTING.txt' for porting tips on misc +# architextures (just sparc64 for now) +# + +LIBIMG_OPT=-DFORCE_ABORT=1 -DDEBUG_LEVEL=0 -DIMGCOMMENT=0 +CC_OPTS=-Wall -W -g -ansi -Wmissing-prototypes -fPIC -no-pie +CC_HACKS=-DNEED_ALLOCA_H +CFLAGS= $(CC_OPTS) \ + $(LIBIMG_OPT) \ + $(CC_HACKS) \ + -DDESTDIR=\"$(DESTDIR)\" \ + -DSHAREDIR=\"$(SHARED_FILES)\" \ + -DCC_OPTS=\"'$(CC_OPTS)'\" +LINKOPT=-lm +RANLIB=wc -c + +# modify it 'as you like' +AR=ar + +#-------- essentials targets + +all: testtga libs +libs: libimage.a libimageSO.so +trucs: t_t16x24 fnt8to16 t_png + +#----------------------------------------------------------------- + +image.o: image.c tthimage.h Makefile +filtres.o: filtres.c tthimage.h +filtadapt.o: filtadapt.c tthimage.h +sobel4.o: sobel4.c tthimage.h +showdiff.o: showdiff.c tthimage.h +effects.o: effects.c tthimage.h Makefile +effects2.o: effects2.c tthimage.h +effects3.o: effects3.c tthimage.h +television.o: television.c tthimage.h Makefile +tele_2.o: tele_2.c tthimage.h Makefile +classif.o: classif.c tthimage.h +combine.o: combine.c tthimage.h +combine2.o: combine2.c tthimage.h +combine3.o: combine3.c tthimage.h +combine4.o: combine4.c tthimage.h +combine5.o: combine5.c tthimage.h +combine6.o: combine6.c tthimage.h Makefile +combine_rnd.o: combine_rnd.c tthimage.h +basic_io.o: basic_io.c tthimage.h +pcx.o: pcx.c tthimage.h +png.o: png.c tthimage.h +bmp.o: bmp.c tthimage.h bmp.h +tga.o: tga.c tthimage.h Makefile +eps.o: eps.c tthimage.h +pht.o: pht.c tthimage.h +pnm.o: pnm.c tthimage.h +fits.o: fits.c tthimage.h +zoom.o: zoom.c tthimage.h +gadgrect.o: gadgrect.c tthimage.h +ascii.o: ascii.c tthimage.h +asciiart.o: asciiart.c tthimage.h +glitch.o: glitch.c tthimage.h Makefile +contours.o: contours.c tthimage.h Makefile +calculs.o: calculs.c tthimage.h Makefile +contrast.o: contrast.c tthimage.h Makefile +calcluts.o: calcluts.c tthimage.h +luts15bits.o: luts15bits.c tthimage.h +gamma.o: gamma.c tthimage.h +quadpics.o: quadpics.c tthimage.h Makefile +colors.o: colors.c tthimage.h Makefile +colors2.o: colors2.c tthimage.h +col_xyz.o: col_xyz.c tthimage.h +palettes.o: palettes.c tthimage.h +indexcol.o: indexcol.c tthimage.h +col_reduc.o: col_reduc.c tthimage.h Makefile +drawpatt.o: drawpatt.c tthimage.h +operat.o: operat.c tthimage.h Makefile +stereo.o: stereo.c tthimage.h +tools.o: tools.c tthimage.h +mircol.o: mircol.c tthimage.h +mustopen.o: mustopen.c tthimage.h Makefile +msglib.o: msglib.c tthimage.h Makefile +ptlist.o: ptlist.c tthimage.h Makefile +dither.o: dither.c tthimage.h Makefile +dither2.o: dither2.c tthimage.h Makefile +dither3.o: dither3.c tthimage.h Makefile +dither4.o: dither4.c tthimage.h Makefile +bitblt.o: bitblt.c tthimage.h Makefile +detect.o: detect.c tthimage.h Makefile +detect2.o: detect2.c tthimage.h Makefile +op2x2.o: op2x2.c tthimage.h +morpho.o: morpho.c tthimage.h +recurse.o: recurse.c tthimage.h +drawing.o: drawing.c tthimage.h Makefile +draw_alpha.o: draw_alpha.c tthimage.h +marques.o: marques.c tthimage.h Makefile +pov_hf15.o: pov_hf15.c tthimage.h +pov_hf15b.o: pov_hf15b.c tthimage.h +pov_hf15c.o: pov_hf15c.c tthimage.h +pov_hf15d.o: pov_hf15d.c tthimage.h +pov_hf15e.o: pov_hf15e.c tthimage.h +pov_hf15f.o: pov_hf15f.c tthimage.h +pov_hf_synth.o: pov_hf_synth.c tthimage.h +df3.o: df3.c tthimage.h +df3b.o: df3b.c tthimage.h +cadres.o: cadres.c tthimage.h Makefile +cadres2.o: cadres2.c tthimage.h +cadres3.o: cadres3.c tthimage.h +cadres4.o: cadres4.c tthimage.h +cadres84.o: cadres84.c tthimage.h +cadresbox.o: cadresbox.c tthimage.h Makefile +alpha.o: alpha.c tthimage.h Makefile +alpha2.o: alpha2.c tthimage.h +alpha3.o: alpha3.c tthimage.h +mosaic.o: mosaic.c tthimage.h Makefile +text0.o: text0.c tthimage.h Makefile +text1.o: text1.c tthimage.h Makefile +text2.o: text2.c tthimage.h Makefile +text16x24.o: text16x24.c tthimage.h Makefile +freetype.o: freetype.c tthimage.h +vectfont.o: vectfont.c tthimage.h +scale.o: scale.c tthimage.h +halfsize.o: halfsize.c tthimage.h Makefile +doublesz.o: doublesz.c tthimage.h +levels.o: levels.c tthimage.h +patterns2.o: patterns2.c tthimage.h Makefile +patterns.o: patterns.c tthimage.h +patterns3.o: patterns3.c tthimage.h +patterns4.o: patterns4.c tthimage.h +insert.o: insert.c tthimage.h Makefile +plotteur.o: plotteur.c tthimage.h Makefile +imprime.o: imprime.c tthimage.h Makefile +col4bits.o: col4bits.c tthimage.h Makefile +dumppix.o: dumppix.c tthimage.h +warp0.o: warp0.c tthimage.h +warp1.o: warp1.c tthimage.h +warp2.o: warp2.c tthimage.h +warp3.o: warp3.c tthimage.h +xper.o: xper.c tthimage.h Makefile +dissolve.o: dissolve.c tthimage.h +troisD.o: troisD.c tthimage.h +turtle.o: turtle.c tthimage.h +cjpeg.o: cjpeg.c tthimage.h +rgbmask.o: rgbmask.c tthimage.h +octree.o: octree.c tthimage.h +addborder.o: addborder.c tthimage.h +fill_pat.o: fill_pat.c tthimage.h +vectfont.o: vectfont.c tthimage.h +photomaton.o: photomaton.c tthimage.h Makefile +pixeliz.o: pixeliz.c tthimage.h Makefile +pixels.o: pixels.c tthimage.h Makefile +anamorphose.o: anamorphose.c tthimage.h Makefile +life.o: life.c tthimage.h +tamppool.o: tamppool.c tthimage.h +vignetize.o: vignetize.c tthimage.h +7seg.o: 7seg.c tthimage.h Makefile +bitplanes.o: bitplanes.c tthimage.h Makefile +distances.o: distances.c tthimage.h Makefile +gray_ops.o: gray_ops.c tthimage.h Makefile +extractbits.o: extractbits.c tthimage.h Makefile +jauges.o: jauges.c tthimage.h Makefile + +#----------------------------------------------------------------- + +OBJECTS= image.o filtres.o effects.o operat.o \ + tamppool.o gray_ops.o \ + calculs.o calcluts.o luts15bits.o \ + octree.o filtadapt.o sobel4.o \ + classif.o vignetize.o \ + gamma.o zoom.o gadgrect.o \ + pht.o eps.o pnm.o png.o \ + bmp.o pcx.o tga.o \ + colors.o colors2.o col_reduc.o col_xyz.o \ + tools.o mircol.o imprime.o \ + combine.o combine2.o combine3.o combine4.o combine5.o \ + combine6.o combine_rnd.o \ + turtle.o marques.o rgbmask.o \ + television.o tele_2.o \ + effects2.o effects3.o \ + contrast.o glitch.o \ + basic_io.o mustopen.o ptlist.o \ + anamorphose.o quadpics.o \ + dither.o dither2.o dither3.o dither4.o \ + bitblt.o detect.o op2x2.o detect2.o \ + drawing.o draw_alpha.o drawpatt.o \ + pov_hf15.o pov_hf15b.o pov_hf15c.o pov_hf15d.o \ + pov_hf15e.o pov_hf15f.o \ + pov_hf_synth.o df3.o df3b.o \ + alpha.o alpha2.o alpha3.o \ + text0.o text1.o text2.o text16x24.o \ + freetype.o vectfont.o \ + cadres.o cadres2.o cadres3.o cadres4.o \ + cadres84.o cadresbox.o 7seg.o \ + dissolve.o photomaton.o \ + mosaic.o life.o extractbits.o \ + palettes.o col4bits.o indexcol.o \ + xper.o showdiff.o \ + scale.o halfsize.o doublesz.o \ + levels.o stereo.o jauges.o \ + patterns4.o patterns3.o patterns2.o patterns.o \ + fill_pat.o pixeliz.o pixels.o \ + insert.o addborder.o \ + morpho.o ascii.o plotteur.o dumppix.o asciiart.o \ + warp0.o warp1.o warp2.o warp3.o \ + fits.o recurse.o msglib.o troisD.o \ + cjpeg.o bitplanes.o distances.o + +libimage.a: $(OBJECTS) + $(AR) r libimage.a $? + $(RANLIB) libimage.a + +#----------------------------------------------------------------- +# WARNING !!! +# this is my first trial on shared library, so +# use with care... and what is the "-PIC" option ? +# + +libimageSO.so: $(OBJECTS) + gcc -o libimageSO.so -shared $(OBJECTS) + +#----------------------------------------------------------------- +# +# fabrication du (des) programme(s) de test. +# + +essais.o: essais.c tthimage.h Makefile essais.h +essais2.o: essais2.c tthimage.h Makefile essais.h +all_tests.o: all_tests.c tthimage.h Makefile essais.h +essai3d.o: essai3d.c tthimage.h Makefile + +testtga.o: testtga.c tthimage.h essais.h Makefile + gcc $(CFLAGS) -c testtga.c +testtga: testtga.o libimage.a essais.o essais2.o all_tests.o Makefile + gcc $(CFLAGS) testtga.o essais.o essais2.o all_tests.o libimage.a -lm -o testtga + +testrect.o: testrect.c tthimage.h essais.h Makefile + gcc $(CFLAGS) -c testrect.c +testrect: testrect.o libimage.a Makefile + gcc $(CFLAGS) testrect.o libimage.a -lm -o testrect + +testSO: testtga.o libimageSO.so + gcc testtga.o -o testSO libimageSO.so -lm + +essai3d: essai3d.o libimage.a Makefile + gcc $(CFLAGS) essai3d.o -o essai3d libimage.a -lm + +t_ascii: t_ascii.c libimage.a tthimage.h Makefile + gcc $(CFLAGS) t_ascii.c -o t_ascii libimage.a -lm -g + +t_png: t_png.c libimage.a tthimage.h Makefile + gcc $(CFLAGS) t_png.c -o t_png libimage.a -lm -lpng -g + +t_t16x24.o: t_t16x24.c tthimage.h Makefile + gcc -c $(CFLAGS) t_t16x24.c +t_t16x24: t_t16x24.o libimage.a Makefile + gcc $(CFLAGS) t_t16x24.o -o t_t16x24 libimage.a -lm -g +all16x24chars.tga: bigfont.txt t_t16x24 Makefile + ./t_t16x24 +all16x24chars.png: all16x24chars.tga + convert all16x24chars.tga all16x24chars.png + +testpcx: testpcx.c libimage.a Makefile + gcc $(CFLAGS) -g testpcx.c -o testpcx libimage.a -lm +testbmp: testbmp.c libimage.a Makefile + gcc $(CFLAGS) -g testbmp.c -o testbmp libimage.a -lm + +foo: foo.c Makefile libimage.a + gcc $(CFLAGS) foo.c libimage.a -o foo -lm + +fnt8to16: fnt8to16.c Makefile + gcc -Wall fnt8to16.c -o fnt8to16 + +#----------------------------------------------------------------- +# +# procedure d'installation en chantier... +# + +install_lib: + install -d $(DESTDIR)/lib/ + install libimage.a $(DESTDIR)/lib/libimage.a + install libimageSO.so $(DESTDIR)/lib/ + install -d $(DESTDIR)/include/ + install -m 0644 tthimage.h $(DESTDIR)/include/tthimage.h +# install -m 0644 img77.fi $(DESTDIR)/include/img77.fi + install -d $(SHARED_FILES) + install -m 0644 libimage.fonte $(SHARED_FILES)/ + install -m 0644 8x8thin $(SHARED_FILES)/ + install -m 0644 16x24thin $(SHARED_FILES)/ + install -m 0644 bigfont.txt $(SHARED_FILES)/ + install -m 0644 neon.map $(SHARED_FILES)/neon.map + install -m 0644 volcano.map $(SHARED_FILES)/volcano.map + install -m 0644 primaires.map $(SHARED_FILES)/primaires.map + +install_doc: + install -m 0644 libimage.html $(HTML_DIR)/libimage.html + install -m 0644 img-effets.html $(HTML_DIR)/img-effets.html + install -m 0644 img-fichiers.html $(HTML_DIR)/img-fichiers.html + install -m 0644 img-calculs.html $(HTML_DIR)/img-calculs.html + install -m 0644 img-cadres.html $(HTML_DIR)/img-cadres.html + install -m 0644 img-combine.html $(HTML_DIR)/img-combine.html + install -m 0644 img-couleurs.html $(HTML_DIR)/img-couleurs.html + install -m 0644 img-dither.html $(HTML_DIR)/img-dither.html + install -m 0644 img-filtres.html $(HTML_DIR)/img-filtres.html + install -m 0644 img-povhf15.html $(HTML_DIR)/img-povhf15.html + install -m 0644 img-patterns.html $(HTML_DIR)/img-patterns.html + install -m 0644 img-showdiff.html $(HTML_DIR)/img-showdiff.html + install -m 0644 img-stereo.html $(HTML_DIR)/ + install -m 0644 image77.html $(HTML_DIR)/image77.html + install -m 0644 img-devel.html $(HTML_DIR)/img-devel.html + install -m 0644 img-texte.html $(HTML_DIR)/img-texte.html + install -m 0644 img-alpha.html $(HTML_DIR)/img-alpha.html + install -m 0644 img-operat.html $(HTML_DIR)/img-operat.html + +install: install_lib + @echo + @echo "Use 'make install_doc' for installing doc in " $(HTML_DIR) + @echo + +#----------------------------------------------------------------- + +TXTFILES=*.c *.h Makefile Doc/*.html *.txt \ + neon.map volcano.map primaires.map *.sh *.css *.fonte + +TOTAR=$(TXTFILES) pov.tga 8x8thin machin.bin 16x24thin + +lines: $(TXTFILES) + @wc $^ | sort -g + +tarball: $(TOTAR) + date >> tarball + ls $(TOTAR) | sed 's/^/LibImage\//' > MANIFEST + ( cd .. ; tar zcvf libimage.tar.gz `cat LibImage/MANIFEST` ) + +#----------- fini ------------------------------------------------ diff --git a/anamorphose.c b/anamorphose.c new file mode 100644 index 0000000..378c3cf --- /dev/null +++ b/anamorphose.c @@ -0,0 +1,144 @@ +/* + * ANAMORPHOSES + * + * new 18 octobre 2003 + */ +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_anmo_X(Image_Desc *src, Image_Desc *dst) +{ +int x, y; +double dnormx, dnormy; + +fprintf(stderr, "%s : %p -> %p\n", __func__, src, dst); + +/* + * we scan the destination picture + */ +for (y=0; yheight; y++) + { + dnormy = (double)y/(double)dst->height; + for (x=0; xwidth; x++) + { + dnormx = (double)x/(double)dst->width; + + + } + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* + * warning: this is a test function. prototype may change + * in a near futur. + */ +int +Image_anmo_grille(Image_Desc *dst) +{ +int x, y; + +if (dst->magic != MAGIC_OF_IMAGE) + { + fprintf(stderr, "Grille Anamorphose: need Dead Beef!\n"); + return NOT_AN_IMAGE_DESC; + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* + * warning: this is a test function. prototype may change + * in a not so near futur. + */ + +#define STAT 1 + +int +Image_anmo_essai_0(char *nomtga, int w, int h, int flgtxt) +{ +Image_Desc *image; +int x, y, x2, y2; +double dx, dy; +double angle; +int xorg, yorg; +double xamp, yamp; +#if STAT +long nb_in, nb_out; +#endif + +image = Image_alloc(w, h, 3); +if (image==NULL) + { + fprintf(stderr, "%s: Abend: no mem\n", __FILE__); + exit(5); + } + +fprintf(stderr, "--> %s %s %s\n", __FILE__, __DATE__, __TIME__); + +/* déterminer les parametres de la deformation */ +xorg = w / 2; yorg = h - 10; +xamp = 1.0; yamp = 1.0; + +#if STAT +nb_in = nb_out = 0L; +#endif + +/* + * we scan all the destination picture... + */ +for (x=0; x=0 && y2>=0 && x2Rpix[y])[x] = x2*2; + (image->Gpix[y])[x] = 200; + (image->Bpix[y])[x] = y2*2; +#if STAT + nb_in++; +#endif + } +#if STAT + else + { + nb_out++; + } +#endif + } + } + +#if STAT +fprintf(stderr, " %ld in, %ld out\n", nb_in, nb_out); +#endif + +Image_cadre_A(image); + +if (flgtxt) + { + Image_marque_timestamp(image, "essai anamorphose", NULL, 1); + } + +Image_TGA_save(nomtga, image, 0); + +Image_DeAllocate(image); free(image); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ diff --git a/basic_io.c b/basic_io.c new file mode 100644 index 0000000..f78323b --- /dev/null +++ b/basic_io.c @@ -0,0 +1,163 @@ +/* + BASIC_IO Sept 2001 + -------- --------- + + Ce module a été écrit pour tenter de régler les + problèmes de "boutisme" pour que ça puisse aussi + tourner sur les vrais processeurs, parce que, bon, + les 386, ça suffit, hein... + + Ceci dit, je ne sais pas vraiment comment traiter + le problème. Pour le moment (Septembre 2001) c'est + un peu beaucoup du "try and test". + + D'autre part, comment ça va se passer sur des CPUs + à 64 (ou 128) bits ? + ------------------------------------------------- + + 9 oct 2001: pourquoi pas de fonction pour ecrire des BYTEs ? + +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int Image_basicIO_teste_boutisme(char *txt) +{ +char *unix = "Unix"; +long lfoo; + +fprintf(stderr, "Image:\ttests de 'boutisme'\n\tmerci linux-31@culte.org\n"); +fprintf(stderr, "\t- %s -\n", txt); + +lfoo = * (long *) unix; +fprintf(stderr, "\t%08lx\n", lfoo); + +/* ah ah ah, mais il y a autre chose dans le source 'imprime.c' + * a propos du boutisme... */ + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_read_I_short(FILE *fp, uint16_t *pvalue) +{ +unsigned char byteH, byteL; +int foo = 0; + +foo += fread(&byteL, 1, 1, fp); +foo += fread(&byteH, 1, 1, fp); + +*pvalue = ( (byteH<<8) + byteL ); + +return foo==2 ? OLL_KORRECT : BASIC_IO_RD_ERR; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_read_M_short(FILE *fp, uint16_t *pvalue) +{ +unsigned char byteH, byteL; +int foo = 0; + +foo += fread(&byteH, 1, 1, fp); +foo += fread(&byteL, 1, 1, fp); + +*pvalue = ( (byteH<<8) + byteL ); + +return foo==2 ? OLL_KORRECT : BASIC_IO_RD_ERR; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_write_I_short(FILE *fp, short value) +{ +unsigned char byte; +int foo = 0; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: write I short: %d\n", value); +#endif + +byte = (unsigned short)value & 0xff; +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: low byte = %02x\n", byte); +#endif +foo += fwrite(&byte, 1, 1, fp); + +byte = ((unsigned short)value >> 8) & 0xff; +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: hight byte = %02x\n", byte); +#endif +foo += fwrite(&byte, 1, 1, fp); + +return foo==2 ? OLL_KORRECT : BASIC_IO_WR_ERR; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_write_M_short(FILE *fp, short value) +{ +unsigned char byte; +int foo = 0; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: write M short: %d\n", value); +#endif + +byte = ((unsigned short)value >> 8) & 0xff; +foo += fwrite(&byte, 1, 1, fp); + +byte = (unsigned short)value & 0xff; +foo += fwrite(&byte, 1, 1, fp); + +return foo==2 ? OLL_KORRECT : BASIC_IO_WR_ERR; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_read_I_long(FILE *fp, uint32_t *pvalue) +{ +unsigned char byte; +int foo; +uint32_t value; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: read I long (a tester) !\n"); +#endif + +value = 0L; +for (foo=0; foo<4; foo++) + { + if (1 != fread(&byte, 1, 1, fp)) + { + fprintf(stderr, "bad fread in %s\n", __func__); + abort(); + } + value <<= 8; + value += byte; +#if DEBUG_LEVEL > 2 + fprintf(stderr, " %d %02x %08lx %ld\n", foo, byte, value, value); +#endif + } + +*pvalue = value; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int Image_basicIO_write_I_long(FILE *fp, long value) +{ +unsigned char byte; +int foo, bar; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Basic IO: write I long: %ld\n", value); +#endif + +for (foo=0; foo<4; foo++) + { + bar = foo * 8; + byte = (value >> bar) & 0xff; +#if DEBUG_LEVEL > 2 + fprintf(stderr, " %3d %3d %02x\n", foo, bar, byte); +#endif + fwrite(&byte, 1, 1, fp); + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ diff --git a/bitblt.c b/bitblt.c new file mode 100644 index 0000000..0883e97 --- /dev/null +++ b/bitblt.c @@ -0,0 +1,250 @@ +/* + bitblt.c + -------- + + Dans ce module, il y a énormement d'optimisations de vitesse + à faire. Je le sais. Mais mon neurone est en surcharge... + ------------------------------------------------------- + voir aussi: insert.c + +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * la structure 'z' decrit les pixels sources (dimensions et position) + * et les parametres x et y disent ou recopier les pixels dans l'image + * de destination. + */ +int +Image_get_rect(Image_Desc *s, Image_Rect *z, Image_Desc *d, int x, int y) +{ +int xfoo, yfoo; /* oh! des 'foo' 2D :-) */ +int xs, ys; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "GET RECT src %p %4d, %4d, %4d, %4d\n", + s, z->x, z->y, z->w, z->h); +fprintf(stderr, " dst %p %4d, %4d\n", d, x, y); +#endif + +if ( (z->w > d->width) || (z->h > d->height) ) + { + return 666; + } + +for (yfoo=0; yfooh; yfoo++) + { + ys = yfoo + z->y; + if (ys<0 || ys>s->height-1) + continue; + for (xfoo=0; xfoow; xfoo++) + { + xs = xfoo + z->x; + if (xs<0 || xs>s->width-1) + continue; + + Image_pixel_copy(s, xs, ys, d, x+xfoo, y+yfoo); + } + } +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * recopie d'un rectangle d'une image source par dessus + * une image destination. + */ +int +Image_put_rect(Image_Desc *s, Image_Rect *z, Image_Desc *d, int x, int y) +{ +int xfoo, yfoo; +int xs, ys, xd, yd; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "PUT RECT src %p %4d, %4d, %4d, %4d\n", + s, z->x, z->y, z->w, z->h); +fprintf(stderr, " dst %p %4d, %4d\n", d, x, y); +#endif + +for (yfoo=0; yfooh; yfoo++) + { + ys = yfoo + z->y; + if (ys<0 || ys>s->height-1) + continue; + + yd = yfoo + y; + if (yd<0 || yd>d->height-1) + continue; + + for (xfoo=0; xfoow; xfoo++) + { + xs = xfoo + z->x; + if (xs<0 || xs>s->width-1) + continue; + + xd = xfoo + x; + if (xd<0 || xd>d->width-1) + continue; + + Image_pixel_copy(s, xs, ys, d, xd, yd); + } + } + +return FUNC_IS_ALPHA; +} + +/*::------------------------------------------------------------------::*/ +/* + * coredumper dlmkt ! + */ +int +Image_copy_rect(Image_Desc *s, Image_Rect *z, Image_Desc *d, int x, int y) +{ +int xs, ys, xd, yd, xx, yy; +int foo; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s s=%p z=%p d=%p x,y=%d,%d\n", __func__, + s, z, d, x, y); +#endif + +if (d->magic != MAGIC_OF_IMAGE) + { + fprintf(stderr, "%s: need Dead Beef\n", __func__); + return NOT_AN_IMAGE_DESC; + } + +foo = 0; +for (yy=0; yyh; yy++) + { + ys = yy + z->y; + if (ys<0 || ys>=s->height) + continue; + + yd = y + yy; + if (yd<0 || yd>=d->height) + continue; + + for (xx=0; xxw; xx++) + { + xs = xx + z->x; + if (xs<0 || xs>=s->width) + continue; + + xd = x + xx; + if (xd<0 || xd>=d->width) + continue; + + Image_pixel_copy(s, xs, ys, d, xd, yd); + foo++; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * nouveau 11 jan 00 cree a la rache pour extraitre des images + * 256x256 afin de tester FFTW :-) + * + * 23 dec 01 found a coredump if src image is too small + * + */ +Image_Desc * +Image_create_subimg(Image_Desc *src, Image_Rect *r, int gray) +{ +Image_Desc *clone; +int x,y,xs, ys; + +/* + * sanities controls... + */ +if (src->type != IMAGE_RGB) + { + fprintf(stderr, "'%s' work only on RGB images\n", __func__); + exit(5); + } +if ( (r->x<0) || (r->y<0) ) + { + fprintf(stderr, "create_subimg, rect(%d,%d,%d,%d) iznotgoud\n", + r->x, r->y, r->w, r->h); + exit(5); + } +/* MUST CHECK THAT SOURCE IMAGE IS BIG ENOUGH ! */ + +/* + * now, we allocate the new image... + */ +clone = Image_alloc(r->w, r->h, src->type); +if (clone == NULL) + { + fprintf(stderr, "CreateSubImage: can't alloc memory...\n"); + exit(5); + } + +for (x=0; xw; x++) + { + xs = x + r->x; + for (y=0; yh; y++) + { + ys = y + r->y; + /*printf("dst %4d %4d ", x, y); */ + /*printf("src %4d %4d ", xs, ys); */ + + if (ys<0 || ys>src->width) + { + Image_plotRGB(clone, x, y, gray, gray, gray); + } + else + { + /* XXX calling this func is a nasty cpu sucker, + * so we have to go to a nasty optimize trick */ + /* XXX Image_pixel_copy(src, xs, ys, clone, x, y); */ + (clone->Rpix[y])[x] = (src->Rpix[ys])[xs]; + (clone->Gpix[y])[x] = (src->Gpix[ys])[xs]; + (clone->Bpix[y])[x] = (src->Bpix[ys])[xs]; + + } + } + } + +return clone; +} +/*::------------------------------------------------------------------::*/ +/* +http://highwire.atari-users.net/cgi-bin/cvsweb/~checkout~lib/gemlib/rc_intersect.c?rev=1.2 + */ +#define max(a,b) ((a)>(b)?(a):(b)) +#define min(a,b) ((a)<(b)?(a):(b)) +int +rc_intersect (const Image_Rect * r1, Image_Rect * r2) +{ +int tx, ty, tw, th, ret; + +tx = max (r2->x, r1->x); +tw = min (r2->x + r2->w, r1->x + r1->w) - tx; + +ret = (0 < tw); +if (ret) + { + ty = max (r2->y, r1->y); + th = min (r2->y + r2->h, r1->y + r1->h) - ty; + + ret = (0 < th); + if (ret) + { + r2->x = tx; + r2->y = ty; + r2->w = tw; + r2->h = th; + } + } + +return ret; +} +/*::------------------------------------------------------------------::*/ + diff --git a/bitplanes.c b/bitplanes.c new file mode 100644 index 0000000..783f692 --- /dev/null +++ b/bitplanes.c @@ -0,0 +1,277 @@ +/* + * ESSAIS SUR LES BITPLANES + * + * new 12 janvier 2009 - avenue St Exupery - dans un etat de grosse fatigue + * reprise 17 mars 2010 - meme endroit - epuisement de classe "irpP" + */ + +#include +#include +#include +#include + +#include "tthimage.h" + +#define VERSION_STRING "5 octobre 2015" + +/*::------------------------------------------------------------------::*/ +/*:: private variables */ +static int next_id; +/*::------------------------------------------------------------------::*/ +int Image_dump_BP_head(A_BitPlane *bp, char *txt, int flag) +{ + +printf("-----------: BitPlane %s ----\n", txt); +printf("@bp : %p\n", bp); +printf("magic : $%08x\n", bp->magic); +printf("size : %d x %d\n", bp->width, bp->height); +printf("id : o%o\n", bp->id); +printf("name : %s\n", bp->name); +printf("tagname : $%02x\n", bp->tagname); +printf("@plane : %p\n", bp->plane); +printf("reserved : %d\n", bp->reserved); + +if (flag) puts(" and --> \\FLAG/"); + +puts("."); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +A_BitPlane * Image_give_me_a_BP(int w, int h) +{ +A_BitPlane *bp; +int taille; +uint8_t *pbits; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %d %d )\n", __func__, w, h); +#endif + +/* is there a sanity check on the dimensions ? */ +if ( (w<1) || (h<1) ) { + fprintf(stderr, "w %d or h %d is bad\n", w, h); + return NULL; + } + +if ( NULL==(bp=calloc(sizeof(A_BitPlane), 1)) ) { + perror("getting memory for a bitmap header"); + return NULL; + } +#if DEBUG_LEVEL +fprintf(stderr, "head malloc(%d) -> %p\n", sizeof(A_BitPlane), bp); +#endif + +taille = (w * h) / 8; +if ( NULL == (pbits=calloc(taille, 1)) ) { + perror("getting a plane"); + return NULL; + } +#if DEBUG_LEVEL +fprintf(stderr, "plane malloc(%d) -> %p\n", taille, pbits); +#endif + +/* set some default values */ +bp->magic = MAGIC_BIT_PLANE; +bp->width = w; +bp->height = h; +if (0==next_id) next_id = getpid(); +bp->id = next_id++; +bp->r0 = bp->g0 = bp->b0 = 0; +bp->r1 = bp->g1 = bp->b1 = 255; +bp->plane = pbits; +strcpy(bp->name, "(noname)"); +bp->reserved = 0; + +return bp; +} +/*::------------------------------------------------------------------::*/ +int Image_free_that_BP(A_BitPlane *bp, int k) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %d )\n", __func__, bp, k); +#endif + +if (bp->magic != MAGIC_BIT_PLANE) { + fprintf(stderr, "%s : %p is not a bitplane descriptor\n", + __func__, bp); +#if FORCE_ABORT + abort(); +#endif + return 666; +} + +free(bp->plane); +#if DEBUG_LEVEL +fprintf(stderr, " bp->plane %p freed\n", bp->plane); +#endif +bp->plane = NULL; +bp->magic = 0; + +free(bp); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int Image_BP_setname(A_BitPlane *bp, const char *name) +{ +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p '%s' )\n", __func__, bp, name); +#endif + +if (MAGIC_BIT_PLANE != bp->magic) { + fprintf(stderr, "%s : %p bad magic\n", __func__, bp); + return BAD_MAGIC; + } +if (IMG_OBJNAME_LEN <= strlen(name)) { + fprintf(stderr, "%s : name too long\n", __func__); + return FULL_NUCKED; + } +strcpy(bp->name, name); + +return UNKNOW_ERROR; +} +/*::------------------------------------------------------------------::*/ +int Image_BP_clear(A_BitPlane *bp, int bit) +{ +int bitsize, foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s (( %p ))\n", __func__, bp); +#endif + +(void)bit; + +if (MAGIC_BIT_PLANE != bp->magic) { + fprintf(stderr, "%s : %p bad magic\n", __func__, bp); + return BAD_MAGIC; + } +bitsize = bp->height * bp->width / 8; +#if DEBUG_LEVEL +fprintf(stderr, "%d x %d -> %d\n", bp->width, bp->height, bitsize); +#endif + +for (foo=0; foo 1 +fprintf(stderr, "%s ( %p %4d %4d %c )\n", __func__, bp, x, y, + (bit&1) ? 'X' : '.'); +#endif + +/* we have to do some sanity checks */ +if (MAGIC_BIT_PLANE != bp->magic) { + fprintf(stderr, "%s : %p bad magic\n", __func__, bp); + return BAD_MAGIC; + } +if ( (x<0) || (y<0) || (x>=bp->width) || (y>=bp->height) ) { + fprintf(stderr, "%s : %d,%d out of pic\n", __func__, x, y); + return OUT_OF_IMAGE; + } + +offbyte = ((bp->width*y) + x) / 8; +offbit = x % 8; +#if DEBUG_LEVEL > 1 +fprintf(stderr, " offbyte %d, offbit %d\n", offbyte, offbit); +fprintf(stderr, " avant 0x%02x\n", bp->plane[offbyte]); +#endif +if (bit) + bp->plane[offbyte] |= (1 << offbit); +else + bp->plane[offbyte] &= ~(1 << offbit); + +#if DEBUG_LEVEL > 1 +fprintf(stderr, " apres 0x%02x\n", bp->plane[offbyte]); +#endif + +return UNKNOW_ERROR; +} +/*::------------------------------------------------------------------::*/ +int Image_BP_pget(A_BitPlane *bp, int x, int y, int *pbit) +{ +int offbyte, offbit; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s ( %p %4d %4d %p )\n", __func__, bp, x, y, pbit); +#endif + +/* we have to do some sanity checks */ +if (MAGIC_BIT_PLANE != bp->magic) { + fprintf(stderr, "%s : %p bad magic\n", __func__, bp); + return BAD_MAGIC; + } +if ( (x<0) || (y<0) || (x>bp->width) || (y>bp->height) ) + { + fprintf(stderr, "%s : %d,%d out of pic\n", __func__, x, y); + return OUT_OF_IMAGE; + } + +offbyte = ((bp->width*y) + x) / 8; +offbit = x % 8; +#if DEBUG_LEVEL > 1 +fprintf(stderr, " offbyte %d, offbit %d\n", offbyte, offbit); +#endif + +if (bp->plane[offbyte] & (1 << offbit)) + *pbit = 1; +else + *pbit = 0; + +return UNKNOW_ERROR; +} +/*::------------------------------------------------------------------::*/ +int Image_BP_to_pbm(A_BitPlane *bp, char *fname, int k) +{ +FILE *fp; +int x, y, v; +int chariot; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p '%s' 0x%03x )\n", __func__, bp, fname, k); +#endif + +if (NULL==(fp=fopen(fname, "w"))) + { + fprintf(stderr, "fucked in %s\n", __func__); + return FULL_NUCKED; + } + +fprintf(fp, "P1\n%d %d\n", bp->width, bp->height); +fprintf(fp, "# written by libimage v %s\n# bitplane module '%s'\n", + IMAGE_VERSION_STRING, VERSION_STRING); + +chariot = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_BP_pget(bp, x, y, &v); + if (v) fputc('1', fp); + else fputc('0', fp); + if (chariot++ < 74) + fputc(' ', fp); + else + { + fputc('\n', fp); chariot=0; + } + } + } + +if (k) fputs("\n# gruiked by tth\n", fp); + +fclose(fp); + +return UNKNOW_ERROR; +} +/*::------------------------------------------------------------------::*/ diff --git a/bmp.c b/bmp.c new file mode 100644 index 0000000..52791fb --- /dev/null +++ b/bmp.c @@ -0,0 +1,286 @@ +/* + * lecture des fichiers BMP + * ------------------------ + * + * ou "comment ne jamais se debarrasser de Kro$oft" + * + * Mais bon, le Paintbrush des petits m'incite a perseverer + * sur la route du e-empire. Du moins tant que je n'ai pas + * fait un clone de Paintbrush pour X11. Mais ceci est un + * autre fantasme... + * + * 2 Octobre 2001: le boutisme va être bouté hors de ce module. + */ + +#include +#include +#include "tthimage.h" + +#include "bmp.h" /* maybe I can hardcoded bmp.h here ? */ + +/*::------------------------------------------------------------------::*/ +static void +fatal_error(char *txt) +{ +fprintf(stderr, "BMP: Fatal error: %s\n", txt); +exit(10); +} +/*::------------------------------------------------------------------::*/ +int +Image_BMP_infos(char *nom, int *pw, int *ph, int *pt, int verb) +{ +FILE *fp; +BMPHEAD head; +int foo; + +if (verb) printf("BMP_Infos : '%s'\n", nom); + +if ((fp=fopen(nom, "r")) == NULL) + { + fprintf(stderr, "BMP_Infos: can't open %s\n", nom); + return FILE_NOT_FOUND; + } + +foo = fread(&head, 1, sizeof(head), fp); +fclose(fp); + +if (verb) + { + printf("signature %c%c filesize %8ld\n", + head.id[0], head.id[1], head.filesize); + printf("headerSize %8ld infoSize %8ld\n", + head.headerSize, head.infoSize); + printf("dimensions %ld x %ld x %d\n", + head.width, head.height, head.bits); + printf("colors: used %ld important %ld\n", + head.clrused, head.clrimportant); + printf("taille structure header %d\n", sizeof(BMPHEAD)); + } +/* + * now, return some usefull informations. + */ + +*pw = head.width; *ph = head.height; *pt = head.bits; + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * Allocate memory and read a BMP file. + */ +#define PIX2BYTE(n) ((n+7)/8) + +Image_Desc * +Image_BMP_alloc_load(char *nom, int reserved) +{ +FILE *fp; +BMPHEAD head; +int ligne, foo, larg, col, ligne2; +Image_Desc *image; +uint8_t *buffer; + +if ((fp=fopen(nom, "r")) == NULL) + { + fprintf(stderr, "can't open %s\n", nom); + return NULL; + } + +foo = fread(&head, 1, sizeof(head), fp); +#if DEBUG_LEVEL +fprintf(stderr, "BMP: on a lu %d octets pour le header.\n", foo); +#endif + +if ( head.id[0] != 'B' || head.id[1] != 'M' ) + { + fprintf(stderr, "BMP_Alloc_Load: BAD MAGIC %s\n", nom); + return NULL; + } + +#if DEBUG_LEVEL +fprintf(stderr, "BMP_Alloc_Load: image depth = %d\n", head.bits); +#endif + +/* + * first step: allocating the memory. + */ +switch (head.bits) + { + case 1: case 4: case 8: + fprintf(stderr, "bit depth %d not supported\n", head.bits); + return NULL; + break; + + case 24: + + if ( (image=Image_alloc(head.width, head.height, 3))==NULL) + fatal_error("no memory for picture in 'alloc_load'\n"); + + if ( (buffer=(uint8_t *)malloc(4*head.width))==NULL) + fatal_error("no memory for buffer in 'alloc_load'\n"); + + larg = head.width * 3; + + break; + + default: + fprintf(stderr, "BMP Load: bit depth %d is unreal\n", + head.bits); + return NULL; + break; + } + +/* + * round up to an even dword boundary (?) + */ +if (larg & 0x00000003) + { + larg |= 0x00000003; + larg++; + } + +/* + * second step: load all the pixels. + * + * (no default case, filtered in first step) + */ +switch (head.bits) + { + case 24: + + for (ligne=0; ligneBpix[ligne2])[col] = buffer[ col*3 ]; + (image->Gpix[ligne2])[col] = buffer[ (col*3) + 1 ]; + (image->Rpix[ligne2])[col] = buffer[ (col*3) + 2 ]; + } + } + + break; + + } + +return image; +} +/*::------------------------------------------------------------------::*/ +/* + * Write a 24 bits bmp file. + * + * et cette fois-ci, on va faire gaffe au boutisme :) + */ +int +Image_BMP_save_24(char *filename, Image_Desc *img, int flag) +{ +FILE *fp; +long grand; +short court; +int line, foo, bytes; +uint8_t *Rptr, *Gptr, *Bptr; +uint8_t *buffer, *ptr; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : writing %p to %s, flag=%d\n", __func__, + img, filename, flag); +#endif + +if ((fp=fopen(filename, "w")) == NULL) + { + fprintf(stderr, "can't open %s for writing\n", filename); + return FILE_CREATE_ERR; + } + +/* + * round up to an even dword boundary (?) + */ +bytes = img->width; +fprintf(stderr, "largeur 0 = %d (%d)\n", bytes, bytes & 3); + +/* OLD CODE - DOES NOT WORK AS EXPECTED - FIXME ONE DAY... +if (bytes & 0x3) + { + bytes |= 0x3; + bytes++; + } +*/ +switch (bytes & 0x3) + { + case 0: /* OK */ break; + case 1: bytes+=3; break; + case 2: bytes+=2; break; + case 3: bytes+=1; break; + } + +fprintf(stderr, "largeur 1 = %d\n", bytes); + +/* + * writing the header + */ +fwrite("BM", 1, 2, fp); /* signature */ + +/* grand = 54L + (long)bytes*(long)img->height; */ /* file size */ +grand = 54L + (long)img->width*(long)img->height; /* file size */ +Image_basicIO_write_I_long(fp, grand); + +grand = 0; +fwrite(&grand, 1, 2, fp); /* reserved by micro$oft ? */ +fwrite(&grand, 1, 2, fp); /* reserved by micro$oft ? */ + +grand = 54L; /* ????? */ +Image_basicIO_write_I_long(fp, grand); +grand = 0x28L; /* always this value, but why ? */ +Image_basicIO_write_I_long(fp, grand); + +grand = img->width; Image_basicIO_write_I_long(fp, grand); +grand = img->height; Image_basicIO_write_I_long(fp, grand); + +court = 1; Image_basicIO_write_I_short(fp, court); /* biPlanes */ +court = 24; Image_basicIO_write_I_short(fp, court); /* bits */ +grand = 0L; Image_basicIO_write_I_long(fp, grand); /* biCompression */ + +grand = img->width * img->height * 3; /* biSizeImage */ +/* grand = bytes * img->height * 3; */ /* biSizeImage */ +Image_basicIO_write_I_long(fp, grand); + +grand = 1000; /* pixels per meter */ +Image_basicIO_write_I_long(fp, grand); +Image_basicIO_write_I_long(fp, grand); + +grand = 0; +Image_basicIO_write_I_long(fp, grand); /* color-used */ +Image_basicIO_write_I_long(fp, grand); /* color-important */ + +fflush(fp); + +/* + * now, we can go, and write pixels datas... + */ +if ((buffer=(uint8_t *)malloc(sizeof(uint8_t)*4*img->width)) == NULL) + fatal_error("no memory buffer for BMP24 save operation"); + +for (line=img->height-1; line>=0; line--) + { + ptr = buffer; + Rptr = img->Rpix[line]; + Gptr = img->Gpix[line]; + Bptr = img->Bpix[line]; + for (foo=0; foowidth; foo++) + { + *ptr++ = Bptr[foo]; + *ptr++ = Gptr[foo]; + *ptr++ = Rptr[foo]; + } + fwrite(buffer, 3, bytes, fp); + } + +free(buffer); + +fclose(fp); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/bmp.h b/bmp.h new file mode 100644 index 0000000..7a0d4a8 --- /dev/null +++ b/bmp.h @@ -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() + diff --git a/calcluts.c b/calcluts.c new file mode 100644 index 0000000..be67048 --- /dev/null +++ b/calcluts.c @@ -0,0 +1,119 @@ +/* + calcluts.c + ---------- + + voir aussi: luts15bits.c + +*/ + +#include +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_calclut_lin(int *lut, int v0, int v255) +{ +int foo, quux, delta; + +#if DEBUG_LEVEL +fprintf(stderr, "calclut lin: v0 = %d v255 = %d\n", v0, v255); +#endif + +delta = v255 - v0; +if (delta == 0) + { + return DIVISOR_IS_0; + } + +#if DEBUG_LEVEL +fprintf(stderr, "calclut lin: delta = %d\n", delta); +#endif + +for (foo=0; foo<256; foo++) + { + quux = (foo * delta / 255) + v0; +#if DEBUG_LEVEL + printf("lut(%d) = %d\n", foo, quux); +#endif + lut[foo] = quux; + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_calclut_foo(int *lut, int v0, int v255) +{ +fprintf(stderr, "%s ( %p %d %d )\n", __func__, lut, v0, v255); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_print_lut(int *lut, char *fname, int flag) +{ +FILE *fp; +int foo; + +if (strcmp(fname, "-")) + fp = fopen(fname, "w"); +else + fp = stdout; + +for (foo=0; foo<256; foo++) + { + if (flag) + printf("%d ", foo); + printf("%d\n", lut[foo]); + } + +if (fp!=stdout) + fclose(fp); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_load_lut(int *lut, char *fname, int flag) +{ +FILE *fp; +int value, foo, idx; + +if (flag) { + fprintf(stderr, "in %s, flag must be O, was %d\n", __func__, flag); + return WRONG_FLAG; + } + +#if DEBUG_LEVEL +fprintf(stderr, "load_lut %s in %p\n", fname, lut); +#endif + +if (NULL==(fp=fopen(fname, "r"))) + { + fprintf(stderr, "%s can't fopen %s\n", __func__, fname); + return 666; + } + +/* WARNING : very crude code here (4 nov 1999) */ +for (idx=0; idx<256; idx++) + { + foo = fscanf(fp, "%d", &value); +#if DEBUG_LEVEL + fprintf(stderr, "load lut %3d %3d %d\n", idx, foo, value); +#endif + if (1==foo) lut[idx] = value; + else lut[idx] = -1; + } + +fclose(fp); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ diff --git a/calculs.c b/calculs.c new file mode 100644 index 0000000..03975f8 --- /dev/null +++ b/calculs.c @@ -0,0 +1,275 @@ +/* + calculs.c + --------- + + voir aussi: distances.c +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* pour les performances, cette fonction + pourrait devenir une #macro ? +*/ +int +Image_clamp_pixel(int value) +{ +if (value < 0) return 0; +if (value > 255) return 255; +return value; +} +/*::------------------------------------------------------------------::*/ +/* new, 2001 June + * + * 23 Fev 2002: parfois (recurse ?) on passe plein de fois dans + * cette fonction. Est-il raisonnable d'optimiser en passant par + * les accès direct à la mémoire ? Oui, si on améliore les + * controles de XY ... + */ +int +Image_stats_zone_0(Image_Desc *img, Image_Rect *zone, + int *pmr, int *pmg, int *pmb, + int *pdr, int *pdg, int *pdb) +{ +int x, y; +int r, g, b; +int r0, r1, g0, g1, b0, b1; +long pixels = 0; + +if ( (zone->w < 2) || (zone->h < 2) ) + { + Image_dump_rect(zone, "stat_zone_0: too small!", 0); + return RECT_TOO_SMALL; + } + +*pmr = *pmg = *pmb = 0; +r0 = g0 = b0 = 300; +r1 = g1 = b1 = -10; + +for (x=0; xw; x++) + { + for (y=0; yh; y++) + { + r = (img->Rpix[y+zone->y])[x+zone->x]; + g = (img->Gpix[y+zone->y])[x+zone->x]; + b = (img->Bpix[y+zone->y])[x+zone->x]; + + *pmr += r; + *pmg += g; + *pmb += b; + + if (r > r1) r1 = r; + if (r < r0) r0 = r; + + if (g > g1) g1 = g; + if (g < g0) g0 = g; + + if (b > b1) b1 = b; + if (b < b0) b0 = b; + + pixels ++; + } + } + +#if DEBUG_LEVEL > 3 +fprintf(stderr, "Calc zone 0: sommes %d %d %d\n", *pmr, *pmg, *pmb); +#endif + +*pmr /= (zone->w*zone->h); +*pmg /= (zone->w*zone->h); +*pmb /= (zone->w*zone->h); + +if (NULL != pdr) *pdr = r1 - r0; +if (NULL != pdr) *pdg = g1 - g0; +if (NULL != pdr) *pdb = b1 - b0; + +/* XXX TO BE GARDED ABOUT NULL PTRS +if ( (*pdr<0) || (*pdg<0) || (*pdb<0) ) + { + Image_dump_rect(zone, "negative in stat_zone_0", 0); + fprintf(stderr, "%ld / %d %d %d %d %d %d\n", + pixels, r0, r1, g0, g1, b0, b1); + } +XXX */ +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * reserved for debugging the library. (never finished work :) + */ +int +Image_quelques_calculs(Image_Desc *image) +{ +long surface, somme; +int x, y, r, g, b, idx; +int *compte4bits; + +surface = image->width * image->height; +printf("surface de l'image = %ld pixels\n", surface); + +if ( (compte4bits = (int *)calloc(1<<12, sizeof(int))) == NULL ) + { + fprintf(stderr, "erreur calloc(surface)\n"); + return 1; + } + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + r = (image->Rpix[y])[x] >> 4; + g = (image->Gpix[y])[x] >> 4; + b = (image->Bpix[y])[x] >> 4; + idx = (r<<8) | (g<<4) | b; + compte4bits[idx]++; + } + } + +somme = 0; + +for (idx=0; idx<(1<<12); idx++) + { + if (compte4bits[idx]) somme++; + } +printf("la somme '4bits' est %ld\n", somme); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * on pourrait rapprocher cette fonction de la fonction + * qui calcule la couleur moyenne d'une image. + * son nom est "Image_??????????????" et elle reside + * dans le module "colors.c". + */ +int +Image_minmax_RGB(Image_Desc *img, int *res) +{ +int x, y, r, g, b, minr, ming, minb, maxr, maxg, maxb; + +minr = ming = minb = 300; +maxr = maxg = maxb = -42; + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + r = Image_R_pixel(img, x, y); + if (r > maxr) maxr = r; + else if (r < minr) minr = r; + + g = Image_G_pixel(img, x, y); + if (g > maxg) maxg = g; + else if (g < ming) ming = g; + + b = Image_B_pixel(img, x, y); + if (b > maxb) maxb = b; + else if (b < minb) minb = b; + } + } + +/* + * and now populate the return vector... + */ +res[0] = minr; res[1] = maxr; +res[2] = ming; res[3] = maxg; +res[4] = minb; res[5] = maxb; + +/* + * et c,a serait cool de lui faire traiter le canal alpha... + */ +res[6] = res[7] = -1; + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + 25 Aout 1999. + gaffe, les @ des buffers pour les histogrames + proviennent parfois de 'alloca'... +*/ +int +Image_histo_RGB(Image_Desc *im, long *hr, long *hg, long *hb) +{ +int foo, x, y; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s : %p --> %p %p %p\n", __func__, im, hr, hg, hb); +#endif + +for (foo=0; foo<256; foo++) { + hr[foo] = 0L; + hg[foo] = 0L; + hb[foo] = 0L; + } + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + hr[(im->Rpix[y])[x]]++; + hg[(im->Gpix[y])[x]]++; + hb[(im->Bpix[y])[x]]++; + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * 5 Fev 2001: optimization for spe3ed. + */ +int +Image_LUT_RGB(Image_Desc *src, Image_Desc *dst, int *lr, int *lg, int *lb) +{ +int x, y, foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_LUT_RGB: images differentes %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + dst->Rpix[y][x] = lr[src->Rpix[y][x]]; + dst->Gpix[y][x] = lg[src->Gpix[y][x]]; + dst->Bpix[y][x] = lb[src->Bpix[y][x]]; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ + +int +Image_LUT_mono(Image_Desc *src, Image_Desc *dst, int *lut) +{ +int x, y, foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_LUT_mono: images differentes %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + dst->Rpix[y][x] = lut[src->Rpix[y][x]]; + dst->Gpix[y][x] = lut[src->Gpix[y][x]]; + dst->Bpix[y][x] = lut[src->Bpix[y][x]]; + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* et en parlant de LUTs, il n'y aurait pas un truc pour les LUTs + * avec les height-fields ? */ + diff --git a/classif.c b/classif.c new file mode 100644 index 0000000..9904da0 --- /dev/null +++ b/classif.c @@ -0,0 +1,174 @@ +/* + * classif.c novembre 2002 + * --------- ------------- + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * A vrai dire, je ne sais pas trop comment traiter ce genre + * de truc. Il va falloir que je me documente serieusement. + */ + +static Une_Classe_Sph classes[] = +{ +{ 64, 64, 64, 50, 128, 128, 128 }, +{ 64, 192, 64, 50, 128, 255, 128 }, +{ 64, 64, 192, 50, 128, 128, 255 }, +{ 64, 192, 192, 50, 255, 255, 255 }, + +{ 192, 64, 64, 50, 255, 128, 128 }, +{ 192, 192, 64, 50, 255, 255, 128 }, +{ 192, 64, 192, 50, 255, 128, 255 }, +{ 192, 192, 192, 50, 255, 255, 255 } + +}; + +#define NBC (sizeof(classes)/sizeof(Une_Classe_Sph)) + +#define CUB(x) ((x)*(x)) + +/*::------------------------------------------------------------------::*/ +int +Image_classif_0(Image_Desc *src, Image_Desc *dst) +{ +int foo, x, y, z, r, g, b, plotted; +long nbrplot; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image classif 0: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Classif 0: nombre de classes = %d\n", NBC); +#endif + +nbrplot = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(src, x, y, &r, &g, &b); + + plotted = 0; + for (foo=0; foo<(int)NBC; foo++) + { + z = CUB(r-classes[foo].rc) + + CUB(g-classes[foo].gc) + + CUB(b-classes[foo].bc); + + if (z < CUB(classes[foo].rad)) + { + Image_plotRGB(dst, x, y, + classes[foo].r, classes[foo].g, classes[foo].b); + plotted = 1; + nbrplot++; + break; + } + } + + if ( ! plotted ) Image_plotRGB(dst, x, y, 0, 0, 0); + + } /* fin for x */ + } + +dst->modified = 1; + +#if DEBUG_LEVEL +fprintf(stderr, " plotted: %ld / %d : %4.2f %%\n", nbrplot, + src->width*src->height, + ((float)nbrplot)/(float)(src->width*src->height) * 100.0); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* new 14 mai 2007, avenue St Exupery */ +int +Image_classif_1(Image_Desc *src, Image_Desc *dst, + Une_Classe_Sph *classes, int nbrclasses, int flag) +{ +int foo, x, y, z, r, g, b, plotted; +long nbrplot; + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "Image classif 1: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, " Classif 1: nombre de classes = %d\n", nbrclasses); +fprintf(stderr, " Classif 1: flag is %d\n", flag); +#endif + +nbrplot = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(src, x, y, &r, &g, &b); + + plotted = 0; + for (foo=0; foomodified = 1; + +#if DEBUG_LEVEL +fprintf(stderr, " plotted: %ld / %d\n", nbrplot, src->width*src->height); +#endif + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int Image_display_classes(Une_Classe_Sph *cla, int nbr, char *texte, int flags) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %4d $%04x %s )\n", __func__, cla, nbr, flags, texte); +#endif + +if (flags) { + fprintf(stderr, "%s --> flags 0x%04X !\n", __func__, flags); + /* return error ? */ + } + +for (foo=0; foo */ + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ + diff --git a/col_reduc.c b/col_reduc.c new file mode 100644 index 0000000..69d0819 --- /dev/null +++ b/col_reduc.c @@ -0,0 +1,45 @@ +/* + * COLOR REDUCTION + * new 27 Jan 2002. + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * ATTENTION: cette fonction sert à faire des essais, et ne doit + * pas être utilisé en production. Le prototype et le + * comportement vont bientôt changer. + * + * n is the number of wanted colors + */ +int +Image_essai_col_reduce(Image_Desc *src, Image_Desc *dst, int n, int t) +{ +RGB_map map; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "--------------- essai col reduce ---------------\n"); +fprintf(stderr, "nombre de couleurs demande: %d\n", n); +fprintf(stderr, "type de la reduction: %d\n", t); +#endif + +foo = Image_calc_Map_4bits(src, &map, n); +#if DEBUG_LEVEL +Image_print_error("calc map 4 bits", foo); +Image_plot_Map("/tmp/aaaa-map.tga", &map, "map 4 bits"); +#endif +Image_save_color_Map("reduce.map", "reduce ?", &map); + +foo = Image_colors_2_Map(src, dst, &map, t); +#if DEBUG_LEVEL +fprintf(stderr, "Image_colors_2_Map -> %d\n", foo); +#endif + +return foo; +} +/*::------------------------------------------------------------------::*/ diff --git a/col_xyz.c b/col_xyz.c new file mode 100644 index 0000000..d635cef --- /dev/null +++ b/col_xyz.c @@ -0,0 +1,38 @@ +/* + * Colors in the strange XYZ space. new 9 avr 2007, ave St Exupery + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_pix_rgb2xyz_d(int r, int g, int b, double *px, double *py, double *pz) +{ +double dr, dg, db, dx, dy, dz; + +#if TRACE +fprintf(stderr, "%s (%3d %3d %3d) -> ", __func__, r, g, b); +#endif + +dr = (double)r / 256.0; +dg = (double)g / 256.0; +db = (double)b / 256.0; +dx = 2.7688 * dr + 1.7517 * dg + 1.1301 * db; +dy = 1.0000 * dr + 4.5907 * dg + 0.0601 * db; +dz = 0.0001 * dr + 0.0565 * dg + 5.5942 * db; + +#if TRACE +fprintf(stderr, "(%f, %f, %f)\n", dx, dy, dz); +#endif + +*px = dx, *py = dy, *pz = dz; + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ + diff --git a/colors.c b/colors.c new file mode 100644 index 0000000..c2871c8 --- /dev/null +++ b/colors.c @@ -0,0 +1,694 @@ +/* + colors.c + -------- +*/ + +#include +#include /* for rand() */ +#include +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + echange de deux composantes d'une image RGB + what about swapping with the alpha channel ? + */ +int +Image_swap_colors(Image_Desc *im, char *cols) +{ +uint8_t *buffer; +int y, code; + +#if DEBUG_LEVEL +fprintf(stderr, "Echange de couleurs: [%s] %p\n", cols, im); +#endif + +if (strlen(cols) != 2) + { + fprintf(stderr, "SwapColors: bad control string: '%s'\n", cols); + return INVALID_PARAM; + } + +code = 0; +switch (cols[0]) + { + case 'r': case 'R': code |= 0x10; break; + case 'g': case 'G': code |= 0x20; break; + case 'b': case 'B': code |= 0x30; break; + default: + fprintf(stderr, "SwapColors: bad first color '%c'\n", cols[0]); + return INVALID_PARAM; + } +switch (cols[1]) + { + case 'r': case 'R': code |= 0x1; break; + case 'g': case 'G': code |= 0x2; break; + case 'b': case 'B': code |= 0x3; break; + default: + fprintf(stderr, "SwapColors: bad second color '%c'\n", cols[0]); + return INVALID_PARAM; + } + +if ( (buffer=(uint8_t *)alloca(im->width)) == NULL ) + { + fprintf(stderr, "SwapColors: no mem for buffer\n"); + return BUFFER_NO_MEM; + } + +#if DEBUG_LEVEL +fprintf(stderr, "SwapColors: code is %02x, buffer at %p\n", code, buffer); +#endif + +for (y=0; yheight; y++) + { + switch (code) + { + case 0x12: case 0x21: + memcpy(buffer, im->Rpix[y], im->width); + memcpy(im->Rpix[y], im->Gpix[y], im->width); + memcpy(im->Gpix[y], buffer, im->width); + break; + case 0x13: case 0x31: + memcpy(buffer, im->Rpix[y], im->width); + memcpy(im->Rpix[y], im->Bpix[y], im->width); + memcpy(im->Bpix[y], buffer, im->width); + break; + case 0x23: case 0x32: + memcpy(buffer, im->Bpix[y], im->width); + memcpy(im->Bpix[y], im->Gpix[y], im->width); + memcpy(im->Gpix[y], buffer, im->width); + break; + default: + fprintf(stderr, "SwapColors: code=%02x, Aie.\n", code); + exit(1); + } + } + +im->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + cette func est cense donner une couleur RVB en + fonction de deux parametre [0..1], mais c,a marche + pas terrible, alors je vais faire encore des essais + */ +int +Image_color_x(double v1, double v2, int *pr, int *pg, int *pb) +{ +double s, c; + +s = sin(v1*M_PI) + 1.0; c = cos(v1*M_PI) + 1.0; + +*pr = (int) (s * 127.0); +*pg = (int) (c * 127.0); +*pb = (int) (v2 * 255.0); + +/* printf("%8f %8f %3d %3d %3d\n", v1, v2, *pr, *pg, *pb); */ + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * Calcul de la couleur moyenne sur l'ensemble d'une image + * Il doit exister quelque part la meme fonction pour ce + * calcul sur une zone rectangulaire d'une image. + */ +int +Image_couleur_moyenne(Image_Desc *im, int *pr, int *pg, int *pb) +{ +int x, y; +long sr, sg, sb, surface; + +sr = sg = sb = 0L; + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + sr += im->Rpix[y][x]; + sg += im->Gpix[y][x]; + sb += im->Bpix[y][x]; + } + } + +surface = (long)im->width * (long)im->height; +sr /= surface; sg /= surface; sb /= surface; + +#if DEBUG_LEVEL +fprintf(stderr, "couleurs moyennes : r=%ld g=%ld b=%ld\n", sr, sg, sb); +#endif + +*pr = (int)sr; *pg = (int)sg; *pb = (int)sb; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * nouveau 28 juillet 2008 - avenue St Exupery + */ +int +Image_saturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb) +{ +int x, y, r, g, b; +int foo; +int minmax[6]; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p -> %p\n", __func__, src, dst); +fprintf(stderr, " r=%d g=%d b=%d\n", sr, sb, sg); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image saturate: images are differents %d\n", foo); + return foo; + } + +foo = Image_minmax_RGB(src, minmax); /* pourquoi faire ce truc ici ? */ +#if DEBUG_LEVEL +fprintf(stderr, " calcul minmax -> %d\n", foo); +#endif + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + /* et il faut faire quoi, exactement ? */ + r = src->Rpix[y][x]; + g = src->Rpix[y][x]; + b = src->Rpix[y][x]; + + /* je n'en ai pas la moindre ideee LOL */ + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * nouveau 12 mars 2009 - avenue St Exupery, avec du "Gros plant nantais" + */ +int +Image_desaturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb) +{ +int x, y, r, g, b; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p -> %p : ", __func__, src, dst); +fprintf(stderr, " %d %d %d\n", sr, sg, sb); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image desaturate: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + + if (r < sr) r = sr; + if (g < sg) g = sg; + if (b < sb) b = sb; + + if (r > 256-sr) r = (256-sr); + if (g > 256-sg) g = (256-sg); + if (b > 256-sb) b = (256-sb); + + src->Rpix[y][x] = r; + src->Gpix[y][x] = g; + src->Bpix[y][x] = b; + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + Je ne sais plus d'ou sort cette formule, ni a quoi + elle sert, ni comment faire le calcul inverse. + */ +int +Image_RGB_2_HLS(int r, int g, int b, int *ph, int *pl, int *ps) +{ +double C1, C2, S, L, H; + +C1 = sqrt(1.5) * (double)(r-g); +C2 = b - 0.5 * (double)(r+g); +S = sqrt((C1*C1) + (C2*C2)); +L = (r+g+b) / 3.0; +H = acos(C1/S); +if (C2 < 0.0) H = (2*M_PI) - H; + +*ph = H; *ps = S; *pl = L; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * nouveau 12Jun2001 + * 16 Dec 2001: not fully tested, may be bogus :-( + */ +int Image_color_shift_rgb(Image_Desc *s, Image_Desc *d, int rs, int gs, int bs) +{ +int x, y, r, g, b; +int foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "Shift RGB: src & dst are differents (%d)\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Shift RGB: %d %d %d\n", rs, gs, bs); +#endif + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = (s->Rpix[y][x] + rs) % 256; + g = (s->Gpix[y][x] + gs) % 256; + b = (s->Bpix[y][x] + bs) % 256; + + d->Rpix[y][x] = r; + d->Gpix[y][x] = g; + d->Bpix[y][x] = b; + } + } + +d->modified = 1; + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + dans cette fonction, plein de trucs sont calcules en + 'double float' mais est-ce bien necessaire ? + + * 16 Dec 2001: not fully tested, may be bogus :-( + +*/ +int +Image_colors_recenter_0(Image_Desc *s, Image_Desc *d) +{ +int x, y, r, g, b; +int or, og, ob; +double cr, cg, cb, surface; + +fprintf(stderr, "Image_colors_recenter_0 is a work in progress... ymmv.\n"); + +cr = cg = cb = 0.0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(s, x, y, &r, &g, &b); + cr += (double)r; + cg += (double)g; + cb += (double)b; + } + } +fprintf(stderr, "colors recenter 0: %g %g %g\n", cr, cg, cb); +surface = (double)(s->width*s->height); +fprintf(stderr, "colors recenter 0: surface image %g\n", surface); + +or = (int)(cr / surface); +og = (int)(cg / surface); +ob = (int)(cb / surface); +or -= 127; +og -= 127; +ob -= 127; +fprintf(stderr, "colors recenter 0: %d %d %d\n", or, og, ob); + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(s, x, y, &r, &g, &b); + r = Image_clamp_pixel(r + or); + g = Image_clamp_pixel(g + og); + b = Image_clamp_pixel(b + ob); + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +#define CUB(x) ((x)*(x)) +/* + * XXX manque des explications sur l'usage du parametre 'mode' + */ +int +Image_colors_2_Map(Image_Desc *s, Image_Desc *d, RGB_map * map, int mode) +{ +int foo, x, y, m; +int sr, sg, sb, dr, dg, db; +long mindist, pos, dist; + +if ( (foo=Image_compare_desc(s, d)) ) return foo; + +if ( map->nbre == 0 ) + { + fprintf(stderr, "%s: empty map at %p\n", __func__, map); + /* + * WTF ? we have an empty map ?!? * + */ + return EMPTY_COL_MAP; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Colors 2 Map: %d couleurs dans la map\n", map->nbre); +#endif + +pos = 0; /* XXX verifier a quoi c,a sert ?! */ + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + mindist = 99999999; + sr = s->Rpix[y][x]; + sg = s->Gpix[y][x]; + sb = s->Bpix[y][x]; + + for (m=0; mnbre; m++) + { + switch (mode) + { + case 0: + dist = CUB(sr-map->red[m]) + + CUB(sg-map->green[m]) + + CUB(sb-map->blue[m]); + break; + + /* + * There was probably a bug in this case... + */ + case 1: + dr = abs(sr - map->red[m]); + dg = abs(sg - map->green[m]); + db = abs(sb - map->blue[m]); + dist = dr; + if (dg < dist) dist = dg; + if (db < dist) dist = db; + break; + + case 2: + dr = abs(sr-map->red[m]); + dg = abs(sg-map->green[m]); + db = abs(sb-map->blue[m]); + dist = dr + dg + db; + break; + + case 11: + dist = CUB(sr-map->red[m]); + break; + case 12: + dist = CUB(sg-map->green[m]); + break; + case 13: + dist = CUB(sb-map->blue[m]); + break; + + default: + fprintf(stderr, "Colors To Map: invalid mode %d\n", mode); + return INVALID_PARAM; + } + + if (dist < mindist) + { + pos = m; mindist = dist; + } + } + + (d->Rpix[y])[x] = map->red[pos]; + (d->Gpix[y])[x] = map->green[pos]; + (d->Bpix[y])[x] = map->blue[pos]; + } +#if DEBUG_LEVEL + if ( ! (y % 42) ) + fprintf(stderr, "remapping line %4d / %d\r", y, s->height); +#endif + } + +d->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* ces coeffs viennent de Povray (a verifier) */ + +#define R_COEF 297 +#define G_COEF 589 +#define B_COEF 114 +#define RGB_DIV (R_COEF+G_COEF+B_COEF) + +int +Image_to_gray_k(Image_Desc *s, Image_Desc *d, int kr, int kg, int kb, int flag) +{ +int x, y, r, g, b, v, foo; +int grey, diviseur; +int vmax; + +#if DEBUG_LEVEL +fprintf(stderr, "converting image %p to gray in %p, flag %d\n", s, d, flag); +#endif + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "To Gray: src & dst are differents (%d)\n", foo); + return foo; + } + +diviseur = kr + kg + kb; +#if DEBUG_LEVEL +fprintf(stderr, "to Gray K: %d %d %d %d\n", kr, kg, kb, diviseur); +#endif + +#if DEBUG_LEVEL > 1 +if (flag==1) { + fprintf(stderr, "%s: %d %d %d -> %d\n", __func__, + kr, kg, kb, diviseur); + } +#endif + +if (diviseur==0) { + fprintf(stderr, "%s: divisor is 0\n", __func__); + return DIVISOR_IS_ZERO; + } + +vmax = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = s->Rpix[y][x]; + g = s->Gpix[y][x]; + b = s->Bpix[y][x]; + + grey = (r * kr) + (g * kg) + (b * kb); + v = grey / diviseur; + + if (v > vmax) vmax=v; + + d->Rpix[y][x] = v; + d->Gpix[y][x] = v; + d->Bpix[y][x] = v; + } + } + +#if DEBUG_LEVEL > 1 +if (flag==1) { + fprintf(stderr, "%s: max value is %d\n", __func__, vmax); + } +#endif + +d->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_to_gray(Image_Desc *s, Image_Desc *d, int flag) +{ +int foo; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Image to gray: flag is %d\n", flag); +#endif + +if (flag) + foo=Image_to_gray_k(s, d, 100, 100, 100, flag); +else + foo=Image_to_gray_k(s, d, R_COEF, G_COEF, B_COEF, flag); + +return foo; +} +/*::------------------------------------------------------------------::*/ +/* 8 Jan 2001 + * + * et on fait quoi si il y a pas assez de couleurs dans la MAP ? + * ben, on patche ? + */ +int +Image_apply_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map) +{ +int x, y, r, g, b; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %p )\n", __func__, src, dst, map); +#endif + +if (map->nbre == 0) + { + fprintf(stderr, "%s : no colors in palette ?\n", __func__); + return EMPTY_COL_MAP; + } + +if (map->nbre < 255) + { + fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre); + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = (src->Rpix[y])[x]; + g = (src->Gpix[y])[x]; + b = (src->Bpix[y])[x]; + + r = map->red[r]; + g = map->green[g]; + b = map->blue[b]; + + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } +dst->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* 8 May 2001 + et on fait quoi si il y a pas assez de couleurs dans la MAP ? */ +int +Image_gray_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map) +{ +int x, y, r, g, b, gray; + +if (map->nbre == 0) + { + fprintf(stderr, "%s : no colors in palette ?\n", __func__); + return VERY_STRANGE; + } + +if (map->nbre < 255) + { + fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre); + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = (src->Rpix[y])[x]; + g = (src->Gpix[y])[x]; + b = (src->Bpix[y])[x]; + gray = ((r * R_COEF) + (g * G_COEF) + (b * B_COEF)) / RGB_DIV; + if (gray<0 || gray>255) + { + fprintf(stderr, "%s: GRAY---- %d\n", __func__, gray); + exit(5); + } + r = map->red[gray]; + g = map->green[gray]; + b = map->blue[gray]; + + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } +dst->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 10 janvier 2009 - avenue St Exupery */ +static int parse_3_ints(char *str, int ints[]) +{ +char *cptr, sep[] = " \t,"; +int idx; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p )\n", __func__, str, ints); +#endif + +idx = 0; +cptr = strtok(str, sep); +while (NULL != cptr) { +#if DEBUG_LEVEL + fprintf(stderr, "%3d %p -> %s\n", idx, cptr, cptr); +#endif + ints[idx] = atoi(cptr); + cptr = strtok(NULL, sep); + if (3 == idx) break; + idx ++; + } + +return 0; +} + +int Image_default_RGBA(RGBA *ptr, char *texte, int flags) +{ +char *envptr; +int foo; +int values[4]; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p '%s' 0x%x )\n", __func__, ptr, texte, flags); +#endif + +if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) { +#if DEBUG_LEVEL + fprintf(stderr, "default rgb = '%s'\n", envptr); +#endif + /* got the env var, parse it now */ + foo = parse_3_ints(envptr, values); + ptr->r = values[0]; + ptr->g = values[1]; + ptr->b = values[2]; + ptr->a = values[3]; + } +else { + fprintf(stderr, "no '%s' env var defined\n", ENV_DEFAULT_RGBA); + ptr->r = ptr->g = ptr->b = ptr->a = 142; + } + +/* quick and dirties default values */ +ptr->reserved = 0x42516988; +ptr->reserved2 = time(NULL); + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/colors2.c b/colors2.c new file mode 100644 index 0000000..7c432da --- /dev/null +++ b/colors2.c @@ -0,0 +1,204 @@ +/* + colors2.c + --------- new 18 jan 2010 +*/ + +#include +#include /* for rand() */ +#include +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* nouveau 20 janvier 2010 */ +int +Image_AutoSeuilGray(Image_Desc *s, Image_Desc *d, int *ps) +{ +long *histo, cumul; +int foo, x, y, r, g, b, seuil; +long surf2; + +#define NB_SLOTS (256*3) +if((histo=(long *)alloca(NB_SLOTS*sizeof(long))) == NULL) + return BUFFER_NO_MEM; + +for (foo=0; fooheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(s, x, y, &r, &g, &b); + cumul = (r + g + b); + if (cumul > NB_SLOTS) + { + fprintf(stderr, "%s : cumul is %ld\n", + __func__, cumul); +#if FORCE_ABORT + abort(); +#endif + return FULL_NUCKED; + } + histo[cumul]++; + } + } + +surf2 = (s->width*s->height)/2; +#if DEBUG_LEVEL +fprintf(stderr, "surface : %ld\n", surf2); +#endif + +cumul = 0L; +seuil = 0; +for (foo=0; foo 1 + printf("asg %4d %8ld %8ld\n", foo, histo[foo], cumul); +#endif + } + +*ps = seuil; /* give a nice value to our caller */ + +fprintf(stderr, "$$$$ seuil is %d\n", seuil); + + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(s, x, y, &r, &g, &b); + cumul = (r + g + b); + if (cumul < seuil) + r = g = b = 0; + else + r = g = b = 255; + Image_plotRGB(d, x, y, r, g, b); + } + } + +fprintf(stderr, "end of %s\n", __func__); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 18 janvier 2010 */ +/* parameter k is currently unused */ +int Image_BiColor_0(Image_Desc *src, Image_Desc *dst, int k) +{ +Image_Desc *tmp; +int foo, bar; +int x, y, r, g, b, seuil; +int rb, gb, bb; /* suffix b -> binary */ +int rd, gd, bd; /* suffix d -> destination */ +#if DEBUG_LEVEL +int hit, mess; +#endif + +#if DEBUG_LEVEL +fprintf(stderr, "$$$ %s ( %p %p %d )\n", __func__, src, dst, k); +#endif + +/* calculer le(s) seuil(s) de binarisation */ +tmp = Image_clone(src, 0); +if (NULL==tmp) + { + fprintf(stderr, "can't clone in %s\n", __func__); + abort(); /* FIXME */ + } + +foo = Image_AutoSeuilGray(src, tmp, &seuil); +fprintf(stderr, "seuil auto -> %d, v=%d\n", foo, seuil); + +#if DEBUG_LEVEL > 1 +Image_TGA_save("aaaa-bicolor0-a.tga", tmp, 0); +fprintf(stderr, "Ah ah, %s, pic 'a' saved\n", __func__); +#endif + +#if DEBUG_LEVEL +hit = mess = 0; +#endif + +/* and now, this is the big loop over all our pixels */ +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + /* lecture de la source */ + Image_getRGB(src, x, y, &r, &g, &b); + + /* lecture du masque binaire XXX */ + Image_getRGB(tmp, x, y, &rb, &gb, &bb); + + /* construction de l'image destination */ + rd = gd = bd = 0; + + if (0 != rb) + { +#if DEBUG_LEVEL + hit++; +#endif + rd = r; + gd = (g*3) / 2; + } + else + { +#if DEBUG_LEVEL + mess++; +#endif + gd = g; + bd = (b*3) / 2; + } + + Image_plotRGB(dst, x, y, rd, gd, bd); + } + } + +#if DEBUG_LEVEL > 1 +Image_TGA_save("aaaa-bicolor0-b.tga", dst, 0); +fprintf(stderr, "Ah ah, %s, pic 'b' saved\n", __func__); +#endif + +#if DEBUG_LEVEL +fprintf(stderr, "hit: %d mess:%d\n", hit, mess); +fprintf(stderr, "$$$ end of %s\n", __func__); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 23 janvier 2010 */ +/* parameters ka & kb are currently unused */ +int Image_BiColor_1(Image_Desc *src, Image_Desc *dst, int ka, int kb) +{ +Image_Desc *tmp; +int foo, seuil; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d %d )\n", __func__, src, dst, ka, kb); +#endif + +/* calculer le(s) seuil(s) de binarisation */ +tmp = Image_clone(src, 0); +if (NULL==tmp) + { + fprintf(stderr, "can't clone in %s\n", __func__); + abort(); /* FIXME */ + } +foo = Image_AutoSeuilGray(src, tmp, &seuil); +fprintf(stderr, "in %s, seuil auto -> %d, v=%d\n", __func__, foo, seuil); + + +return WTF_OSEF; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ + diff --git a/combine.c b/combine.c new file mode 100644 index 0000000..9512650 --- /dev/null +++ b/combine.c @@ -0,0 +1,449 @@ +/* + combine.c others effects + ========= -------------- + + made by Thierry Boudet, aka "Oulala", aka "Tonton Th". + + ces fonctions combinent de diverses façons deux images + de memes dimensions. on pourra, par exemple, les utiliser + pour comparer deux traitements. +*/ + +#include +#include + +#include "tthimage.h" + +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#endif + +/*::------------------------------------------------------------------::*/ +/* + * le paramètre 'zak' n'est pas utilisé et doit être mis à 0 + */ +int +Image_combine_lines(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int sy, int oy, int zak) +{ +int foo, x, y, my, r, g, b; + +if (sy == 0) + { + fprintf(stderr, "Combine Lines: sy is zer0 and zak is %d\n", zak); + return DIVISOR_IS_ZERO; + } +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Lines: sources are differents (%d)\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Combine lines: %d %d\n", sy, oy); +#endif +for (y=0; yheight; y++) + { + my = (y+oy) / sy; + for (x=0; xwidth; x++) + { + if ( my&1 ) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + else + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * le paramètre 'zak' n'est pas utilisé et doit être mis à 0 + */ +int +Image_combine_columns(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int sx, int ox, int zak) +{ +int foo, x, y, mx, r, g, b; + +if (sx == 0) + { + fprintf(stderr, "Combine Columns: sx is zer0\n"); + return DIVISOR_IS_ZERO; + } +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Lines: sources are differents (%d)\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Combine columns: %d %d\n", sx, ox); +#endif + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + mx = (x+ox) / sx; + if ( mx&1 ) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + else + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +d->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * 28 Jan 2001: pourquoi ne pas introduire un calcul automatique + * des coefficients ox & oy pour obtenir le centrage ? + * + * 'zak' parameter is not used, and must be 0. + */ +int +Image_combine_checker(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int sx, int sy, int ox, int oy, int zak) +{ +int foo, r, g, b; +int x, y, mx, my; + +#if DEBUG_LEVEL +fprintf(stderr, "Checker (%p, %p) -> %p [%d,%d] [%d,%d]\n", + s1, s2, d, sx, sy, ox, oy); +#endif + +if (zak) + { + fprintf(stderr, "%s: param 'zak' = %d, must be 0.\n", __func__, + zak); + } + +if ( sx==0 || sy==0 ) + { + fprintf(stderr, "Combine Checker: sx or sy is Zero\n"); + return DIVISOR_IS_ZERO; + } + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Checker: sources are differents (%d)\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + my = (y+oy) / sy; + for (x=0; xwidth; x++) + { + mx = (x+ox) / sx; + if ( (mx&1) != (my&1) ) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + else + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/* + * houba, celle-ci va me donner du mal, et on peut la + * considerer comme pas finie, c'est a dire, entre autre, + * que le prototype risque de changer. + * + * Toutes les suggestions sont les bienvenues, surtout si + * elles viennent de glandeur06 et son UltraSparc. + * + * Tiens, le parametre 'yo' ne sert a rien ? + */ +int +Image_combine_cercle_flou(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, int yo) +{ +int foo; +int xcenter, ycenter; +int x, y, r1, v1, b1, r2, b2, v2; +float fx2, fy2, dmax, coef; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Cercle Flou: differents sources (%d)\n", foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, d)) ) + { + fprintf(stderr, "Combine Cercle Flou: source != dest (%d)\n", foo); + return foo; + } + +xcenter = (s1->width) / 2; +ycenter = (s1->height) / 2; +dmax = (float)(xcenter*xcenter) + (float)(ycenter*ycenter); +dmax /= 1.732; + +#if DEBUG_LEVEL +fprintf(stderr, "\tcentre: %d, %d\n", xcenter, ycenter); +fprintf(stderr, "\tdmax: %f\n", dmax); +fflush(stderr); /* vraiment necessaire ? */ +#endif + +for (y=0; yheight; y++) + { + fy2 = (float)((y-ycenter)*(y-ycenter)); + for (x=0; xwidth; x++) + { + fx2 = (float)((x-xcenter)*(x-xcenter)); + + r1 = (s1->Rpix[y])[x]; + v1 = (s1->Gpix[y])[x]; + b1 = (s1->Bpix[y])[x]; + + r2 = (s2->Rpix[y])[x]; + v2 = (s2->Gpix[y])[x]; + b2 = (s2->Bpix[y])[x]; + + coef = (fx2+fy2)/dmax; + + if (coef < 0.0) coef = 0.0; + if (coef > 1.0) coef = 1.0; + + (d->Rpix[y])[x] = (int)(r1*(1.0-coef)+r2*coef); + (d->Gpix[y])[x] = (int)(v1*(1.0-coef)+v2*coef); + (d->Bpix[y])[x] = (int)(b1*(1.0-coef)+b2*coef); + + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * le flag 'yo' decide quelle image sera en haut à droite. + * les paramètres p1 & p2 ne sont pas utilisés. + */ +int +Image_combine_diagonale(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int yo, int p1, int p2) +{ +int foo; +int x, y, r, g, b; +int vertical, offset; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Diagonale: differents sources (%d)\n", foo); + return foo; + } + +if (s1->height > s1->width) + { + vertical = 1; + offset = (s1->height - s1->width) / 2; + } +else + { + vertical = 0; + offset = (s1->width - s1->height) / 2; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if ( vertical ) + { + if (x > (y-offset)) foo=1; + else foo=0; + } + else + { + if ((x-offset) > y) foo=1; + else foo=0; + } + + foo = yo ? !foo : foo; /* strange hack */ + + if (foo) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + else + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } +/* + * 30 sept 2008 : est-ce que cette fonction a subi un bon fuzzing ? + */ +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* 15 Nov 2000 + + we put in the destination image the min/max value + of the RGB componants. + */ +int +Image_combine_minmax(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, int flg) +{ +int foo, x, y, r, g, b; +int r1, r2, g1, g2, b1, b2; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine MinMax: differents sources (%d)\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r1 = (s1->Rpix[y])[x]; + g1 = (s1->Gpix[y])[x]; + b1 = (s1->Bpix[y])[x]; + + r2 = (s2->Rpix[y])[x]; + g2 = (s2->Gpix[y])[x]; + b2 = (s2->Bpix[y])[x]; + + if (flg) + { + r = max(r1, r2); + g = max(g1, g2); + b = max(b1, b2); + } + else + { + r = min(r1, r2); + g = min(g1, g2); + b = min(b1, b2); + } + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * fonction faite pour le finisseur de DBvsEE + * + * 6 oct 2001: une version qui permettrait de spécifier les + * seuils en r,g et b serait assez pratique aussi. + */ +int +Image_combine_if_not_black(Image_Desc *s1, Image_Desc *s2, Image_Desc *d) +{ +int foo, x, y, r, g, b; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine If Not Black: differents sources (%d)\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + /* XXX Image_getRGB(s1, x, y, &r, &g, &b); */ + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + + if ( r==0 && g==0 && b==0 ) + { + /* XXX Image_getRGB(s2, x, y, &r, &g, &b); */ + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + + /*Image_plotRGB(d, x, y, r, g, b);*/ + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return FUNC_IS_BETA; /* XXX c'est pas du OLL_KORRECT ? */ +} +/*::------------------------------------------------------------------::*/ +/* + * gni ? + */ +int +Image_poke_2zones(Image_Desc *src, Image_Desc *ia, Image_Desc *ib, + Image_Rect *za, Image_Rect *zb, + Image_Desc *dst) +{ +int foo; +/* Image_Rect rect; */ + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Poke 2 Zone: src & dst: %d %s\n", + foo, Image_err2str(foo)); + return foo; + } + +Image_copy(src, dst); + +fprintf(stderr, "Image Poke 2 Zones: ben, ya rien...\n"); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ diff --git a/combine2.c b/combine2.c new file mode 100644 index 0000000..d7c5cff --- /dev/null +++ b/combine2.c @@ -0,0 +1,158 @@ +/* + combine2.c + mixages... + ---------- +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + Le coefficient K va de 0 a 10000 ! +*/ +int +Image_mix(Image_Desc *a, Image_Desc *b, Image_Desc *c, int k) +{ +int x, y; +int ra, rb, mk; +uint8_t *pra, *prb, *prk, *pga, *pgb, *pgk, *pba, *pbb, *pbk; +int foo; + +if ( (foo=Image_compare_desc(a, b)) || + (foo=Image_compare_desc(a, c)) ) + { + fprintf(stderr, "Image mix: images differentes %s\n", Image_err2str(foo)); + fprintf(stderr, " a %dx%d b %dx%d c %dx%d\n", + a->width, a->height, + b->width, b->height, + c->width, c->height); + return IMG_ARE_DIFFERENT; + } + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Mixing: %p and %p to %p, k=%d\n", a, b, c, k); +#endif + +mk = 10000 - k; +for (y=0; yheight; y++) + { + pra = a->Rpix[y]; prb = b->Rpix[y]; prk = c->Rpix[y]; + pga = a->Gpix[y]; pgb = b->Gpix[y]; pgk = c->Gpix[y]; + pba = a->Bpix[y]; pbb = b->Bpix[y]; pbk = c->Bpix[y]; + + for (x=0; xwidth; x++) + { + ra = pra[x]; + rb = prb[x]; + prk[x] = ((ra * k) + (rb * mk)) / 10000; + + ra = pga[x]; + rb = pgb[x]; + pgk[x] = ((ra * k) + (rb * mk)) / 10000; + + ra = pba[x]; + rb = pbb[x]; + pbk[x] = ((ra * k) + (rb * mk)) / 10000; + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* new 6 nov 2001 + Les coefficients K[rgb] vont de 0 a 10000 ! +*/ +int +Image_mix_rgb(Image_Desc *a, Image_Desc *b, Image_Desc *c, + int kr, int kg, int kb) +{ +int foo, x, y; +uint8_t *pra, *prb, *prk, *pga, *pgb, *pgk, *pba, *pbb, *pbk; +int ra, rb, mkr, mkg, mkb; + +if ( (foo=Image_compare_desc(a, b)) || + (foo=Image_compare_desc(a, c)) ) + { + fprintf(stderr, "Image mix: images differentes %s\n", Image_err2str(foo)); + fprintf(stderr, " a %dx%d b %dx%d c %dx%d\n", + a->width, a->height, + b->width, b->height, + c->width, c->height); + return IMG_ARE_DIFFERENT; + } + +mkr = 10000 - kr; +mkg = 10000 - kg; +mkb = 10000 - kb; +for (y=0; yheight; y++) + { + pra = a->Rpix[y]; prb = b->Rpix[y]; prk = c->Rpix[y]; + pga = a->Gpix[y]; pgb = b->Gpix[y]; pgk = c->Gpix[y]; + pba = a->Bpix[y]; pbb = b->Bpix[y]; pbk = c->Bpix[y]; + + for (x=0; xwidth; x++) + { + ra = pra[x]; + rb = prb[x]; + prk[x] = ((ra * kr) + (rb * mkr)) / 10000; + + ra = pga[x]; + rb = pgb[x]; + pgk[x] = ((ra * kg) + (rb * mkg)) / 10000; + + ra = pba[x]; + rb = pbb[x]; + pbk[x] = ((ra * kb) + (rb * mkb)) / 10000; + + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * les deux images sources (a & b) et l'image de destination (d) + * doivent avoir les mêmes largeur et hauteur. quand à l'image + * de 'ratio', ses dimensions peuvent être différentes. + * + * XXX mettre en place un test unitaire !!! + */ +int +Image_trimix(Image_Desc *a, Image_Desc *b, Image_Desc *c, Image_Desc *d, char w) +{ +int x, y, rv, gv, bv, cx, cy; +int ra, ga, ba, rb, gb, bb, rc, gc, bc; + +fprintf(stderr, "Image tri mix (%02X) : NO SANITY CONTROL\n", w); + +/* + * YES, I know that i can optimize this func for speed. + * I do that when a got a zen-er life. Sorry. man vi, man gcc. + */ +for (y=0; yheight; y++) + { + cy = y % c->height; + for (x=0; xwidth; x++) + { + cx = x % c->width; + Image_getRGB(a, x, y, &ra, &ga, &ba); + Image_getRGB(b, x, y, &rb, &gb, &bb); + Image_getRGB(c, cx, cy, &rc, &gc, &bc); + + rv = (ra * rb) + (rc * (256-rb)); + gv = (ga * gb) + (gc * (256-gb)); + bv = (ba * bb) + (bc * (256-bb)); + + (d->Rpix[y])[x] = rv/256; + (d->Gpix[y])[x] = gv/256; + (d->Bpix[y])[x] = bv/256; + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ diff --git a/combine3.c b/combine3.c new file mode 100644 index 0000000..9337592 --- /dev/null +++ b/combine3.c @@ -0,0 +1,161 @@ +/* + combine3.c + ---------- +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * un kludge en chantier. programmation à la 'Gruiik' en vue. + */ +int +Image_combine_waou(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst, + int a, int b, int c, int d) +{ +int x, y, foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %p %d : %d %d (%d) )\n", + __func__, s1, s2, dst, a, b, c, d); +#endif + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s : sources are differents %d\n", __func__, foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, dst)) ) + { + fprintf(stderr, "%s : destination bad dims %d\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if (d) + { + /* canonical function */ + (dst->Rpix[y])[x] = (x & (s1->Rpix[y])[x]) | a; + (dst->Gpix[y])[x] = x | b; + (dst->Bpix[y])[x] = (y & (s2->Rpix[y])[x]) | c; + } + else + { + /* new 9 mars 2010 - ave St Ex */ + (dst->Rpix[y])[x] = (x & (s1->Rpix[y])[x]) ^ a; + (dst->Gpix[y])[x] = x ^ b; + (dst->Bpix[y])[x] = (y & (s2->Gpix[y])[x]) ^ c; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * un kludge en chantier. programmation à la 'Gruiik' en vue. + */ +int +Image_combine_wauo(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst, + int flag) +{ +int x, y, foo; + +if ( flag ) + fprintf(stderr, "Combine Wauo: flag = %d ?\n", flag); + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Wauo: sources are differents %d\n", foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, dst)) ) + { + fprintf(stderr, "Combine Wauo: destination bad dims %d\n", foo); + return foo; + } + +for (y=1; yheight-1; y++) + { + for (x=1; xwidth-1; x++) + { + (dst->Rpix[y])[x] = (s1->Rpix[y][x] + s2->Rpix[y][x])/2; + + if (s1->Rpix[y][x] > s2->Rpix[y][x]) + { + (dst->Gpix[y])[x] = (s1->Gpix[y])[x]; + (dst->Bpix[y])[x] = (s2->Bpix[y])[x]; + } + else + { + (dst->Gpix[y])[x] = (s2->Gpix[y])[x]; + (dst->Bpix[y])[x] = (s1->Bpix[y])[x]; + } + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * threshold values (sr, sg, sb) are in the pix range [0..255] + */ +int +Image_combine_seuils(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst, + int sr, int sb, int sg) +{ +int x, y, foo; +int r, g, b; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "Combine Seuils: sources are differents %d\n", foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, dst)) ) + { + fprintf(stderr, "Combine Seuils: destination bad dims %d\n", foo); + return foo; + } + +sr*=2; sg*=2; sb*=2; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if ( (s1->Rpix[y][x] + s2->Rpix[y][x]) > sr ) + r = s1->Rpix[y][x]; + else + r = s2->Rpix[y][x]; + + if ( (s1->Gpix[y][x] + s2->Gpix[y][x]) > sg ) + g = s1->Gpix[y][x]; + else + g = s2->Gpix[y][x]; + + if ( (s1->Bpix[y][x] + s2->Bpix[y][x]) > sb ) + b = s1->Bpix[y][x]; + else + b = s2->Bpix[y][x]; + + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } + +dst->modified = 1; +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/combine4.c b/combine4.c new file mode 100644 index 0000000..9643d4b --- /dev/null +++ b/combine4.c @@ -0,0 +1,175 @@ +/* + combine4.c + ---------- +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * + */ +int +Image_combine_4img_0( Image_Desc *s1, Image_Desc *s2, + Image_Desc *s3, Image_Desc *s4, + Image_Desc *dst) +{ +int x, y; +int r, g, b; + +fprintf(stderr, "Image combine 4img 0: NO SANITY CONTROL !\n"); + +r = g = b = 0; /* warning killer */ + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if ( (x&1) && (y&1) ) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + if ( !(x&1) && (y&1) ) + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + if ( (x&1) && !(y&1) ) + { + r = (s3->Rpix[y])[x]; + g = (s3->Gpix[y])[x]; + b = (s3->Bpix[y])[x]; + } + if ( !(x&1) && !(y&1) ) + { + r = (s4->Rpix[y])[x]; + g = (s4->Gpix[y])[x]; + b = (s4->Bpix[y])[x]; + } + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * first step : 10 avril 2009 + */ +int +Image_combine_4img_1( Image_Desc *s1, Image_Desc *s2, + Image_Desc *s3, Image_Desc *s4, + Image_Desc *dst) +{ +Image_Desc *source; +int x, y, alea; +int r, g, b; + +fprintf(stderr, "%s: NO SANITY CONTROL !\n", __func__); + +r = g = b = 0; /* warning killer */ +source = NULL; /* another warning killer */ + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + alea = rand() % 4; + switch (alea) + { + case 0: source=s1; break; + case 1: source=s2; break; + case 2: source=s3; break; + case 3: source=s4; break; + } + r = (source->Rpix[y])[x]; + g = (source->Gpix[y])[x]; + b = (source->Bpix[y])[x]; + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } + +return 9999; +} +/*::------------------------------------------------------------------::*/ +/* + * hacked the 11 april 2009 - avenue ST Exupery + */ +int +Image_combine_4img_2( Image_Desc *s1, Image_Desc *s2, + Image_Desc *s3, Image_Desc *s4, + Image_Desc *dst, int meth_reduc) +{ +Image_Desc *r1, *r2, *r3, *r4; +int x, y; +int h2, w2; + +fprintf(stderr, "*** %s: NO SANITY CONTROL !\n", __func__); + +r1 = Image_MakeHalfSize(s1, meth_reduc); +r2 = Image_MakeHalfSize(s2, meth_reduc); +r3 = Image_MakeHalfSize(s3, meth_reduc); +r4 = Image_MakeHalfSize(s4, meth_reduc); + +#if DEBUG_LEVEL +fprintf(stderr, "reduced pictures: %p %p %p %p\n", r1, r2, r3, r4); +#endif + +h2 = r1->height; +w2 = r1->width; + +for (y=0; yRpix[y])[x] = (r1->Rpix[y])[x]; + (dst->Rpix[y])[x+w2] = (r2->Rpix[y])[x]; + (dst->Rpix[y+h2])[x] = (r3->Rpix[y])[x]; + (dst->Rpix[y+h2])[x+w2] = (r4->Rpix[y])[x]; + + (dst->Gpix[y])[x] = (r1->Gpix[y])[x]; + (dst->Gpix[y])[x+w2] = (r2->Gpix[y])[x]; + (dst->Gpix[y+h2])[x] = (r3->Gpix[y])[x]; + (dst->Gpix[y+h2])[x+w2] = (r4->Gpix[y])[x]; + + (dst->Bpix[y])[x] = (r1->Bpix[y])[x]; + (dst->Bpix[y])[x+w2] = (r2->Bpix[y])[x]; + (dst->Bpix[y+h2])[x] = (r3->Bpix[y])[x]; + (dst->Bpix[y+h2])[x+w2] = (r4->Bpix[y])[x]; + } + } + +Image_DeAllocate(r1); free(r1); +Image_DeAllocate(r2); free(r2); +Image_DeAllocate(r3); free(r3); +Image_DeAllocate(r4); free(r4); + +return 9999; +} +/*::------------------------------------------------------------------::*/ +int +Image_combine_4img_3( Image_Desc *s1, Image_Desc *s2, + Image_Desc *s3, Image_Desc *s4, + Image_Desc *dst, int k) +{ +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p %p %p %p --> %p\n", __func__, + s1, s2, s3, s4, dst); +#endif + +fprintf(stderr, "%s: NO SANITY CONTROL !\n", __func__); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/combine5.c b/combine5.c new file mode 100644 index 0000000..a5210df --- /dev/null +++ b/combine5.c @@ -0,0 +1,191 @@ +/* + combine5.c + ---------- + dégradés linéaires divers. + avec des erreurs d'arrondi dedans. +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_combine_Vdegrade(Image_Desc *s1, Image_Desc *s2, + Image_Desc *dst, int sens) +{ +int x, y, foo; +int r1, g1, b1; +int r2, g2, b2; +int rd, gd, bd; +double k, ka, kb; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "V degrade: sources err: %s\n", Image_err2str(foo)); + return foo; + } + +for (y=0; yheight; y++) + { + k = (double)y/(double)s1->height; + if (sens) { ka = k; kb = 1.0 - ka; } + else { kb = k; ka = 1.0 - kb; } + + for (x=0; xwidth; x++) + { + Image_getRGB(s1, x, y, &r1, &g1, &b1); + Image_getRGB(s2, x, y, &r2, &g2, &b2); + rd = (int)((double)r1*ka+(double)r2*(kb)); + gd = (int)((double)g1*ka+(double)g2*(kb)); + bd = (int)((double)b1*ka+(double)b2*(kb)); + Image_plotRGB(dst, x, y, rd, gd, bd); + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_combine_Hdegrade( Image_Desc *s1, Image_Desc *s2, + Image_Desc *dst, int sens) +{ +int x, y, foo; +int r1, g1, b1; +int r2, g2, b2; +int rd, gd, bd; +double k, ka, kb; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "H degrade: sources err: %s\n", Image_err2str(foo)); + return foo; + } + +for (x=0; xwidth; x++) + { + k = (double)x/(double)s1->width; + if (sens) { ka = k; kb = 1.0-ka; } + else { kb = k; ka = 1.0-kb; } + for (y=0; yheight; y++) + { + Image_getRGB(s1, x, y, &r1, &g1, &b1); + Image_getRGB(s2, x, y, &r2, &g2, &b2); + rd = (int)((double)r1*ka+(double)r2*(kb)); + gd = (int)((double)g1*ka+(double)g2*(kb)); + bd = (int)((double)b1*ka+(double)b2*(kb)); + Image_plotRGB(dst, x, y, rd, gd, bd); + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * bon, là, on va essayer de faire ça en diagonale, mais + * je pense que ça ne va pas être simple, car il faut traiter + * le cas des images qui ne sont pas carrées... + */ +int +Image_combine_Ddegrade( Image_Desc *s1, Image_Desc *s2, + Image_Desc *dst, int sens) +{ +int foo; + +fprintf(stderr, "%s:%d:%s: no such function or procedure\n", + __FILE__, __LINE__, __func__); + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "D degrade: sources err: %s\n", Image_err2str(foo)); + return foo; + } +if ( (foo=Image_compare_desc(s1, dst)) ) + { + fprintf(stderr, "D degrade: dst err: %s\n", Image_err2str(foo)); + return foo; + } + +fprintf(stderr, "%s : sens=%d\n", __func__, sens); /* XXX */ + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 29 novembre 2013 +*/ +int Image_combine_Vsplit(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int xv, int uh) +{ +int foo, x, y; + +#if DEBUG_LEVEL +fprintf(stderr, "%s (%p %p %p %d %d)\n", __func__, s1, s2, d, xv, uh); +#endif + +if (0 != uh) + fprintf(stderr, "%s : uh must be 0 and not %d\n", __func__, uh); + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s : src err: %s\n", __func__, Image_err2str(foo)); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if (xRpix[y])[x] = (s1->Rpix[y])[x]; + (d->Gpix[y])[x] = (s1->Gpix[y])[x]; + (d->Bpix[y])[x] = (s1->Bpix[y])[x]; + } + else + { + (d->Rpix[y])[x] = (s2->Rpix[y])[x]; + (d->Gpix[y])[x] = (s2->Gpix[y])[x]; + (d->Bpix[y])[x] = (s2->Bpix[y])[x]; + } + + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 29 novembre 2013 +*/ +int Image_combine_Hsplit(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int yv, int uh) +{ +int x, y; + +#if DEBUG_LEVEL +fprintf(stderr, "%s (%p %p %p %d %d)\n", __func__, s1, s2, d, yv, uh); +#endif + +if (0 != uh) + fprintf(stderr, "*** %s : uh must be 0 and not %d\n", __func__, uh); + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + if (yRpix[y])[x] = (s1->Rpix[y])[x]; + (d->Gpix[y])[x] = (s1->Gpix[y])[x]; + (d->Bpix[y])[x] = (s1->Bpix[y])[x]; + } + else + { + (d->Rpix[y])[x] = (s2->Rpix[y])[x]; + (d->Gpix[y])[x] = (s2->Gpix[y])[x]; + (d->Bpix[y])[x] = (s2->Bpix[y])[x]; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/combine6.c b/combine6.c new file mode 100644 index 0000000..e33dea3 --- /dev/null +++ b/combine6.c @@ -0,0 +1,120 @@ +/* + combine6.c + ---------- +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* nouveau 28 fevrier 2014 / ave StExupery */ +int Image_combine_power(Image_Desc *s1, Image_Desc *s2, Image_Desc *d) +{ +int x, y; +int foo; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s: sources are differents (%d)\n", __func__, foo); + return foo; + } + +#define D1(pix) ( ((double)pix)/256.0 ) + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + d->Rpix[y][x] = (int)(pow( D1(s1->Rpix[y][x]), + D1(s2->Rpix[y][x]) ) * 255.0); + d->Gpix[y][x] = (int)(pow( D1(s1->Gpix[y][x]), + D1(s2->Gpix[y][x]) ) * 255.0); + d->Bpix[y][x] = (int)(pow( D1(s1->Gpix[y][x]), + D1(s2->Bpix[y][x]) ) * 255.0); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 13 mars 2014 / Mixart-Myrys */ +int Image_combine_power_m(Image_Desc *s1, Image_Desc *s2, Image_Desc *d) +{ +int x, y; +int foo; +double v; + +#if DEBUG_LEVEL +fprintf(stderr, "---> %s ( %p %p %p )\n", __func__, s1, s2, d); +#endif + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s: sources are differents (%d)\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + v = (double)(s2->Rpix[y][x] + s2->Gpix[y][x] + s2->Bpix[y][x]); + v /= (256.0 * 3.0); + d->Rpix[y][x] = (int)(pow( D1(s1->Rpix[y][x]), v) * 255.0); + d->Gpix[y][x] = (int)(pow( D1(s1->Gpix[y][x]), v) * 255.0); + d->Bpix[y][x] = (int)(pow( D1(s1->Bpix[y][x]), v) * 255.0); + } + } + +d->modified = 3; + +#if DEBUG_LEVEL +fprintf(stderr, "fin %s\n", __func__); +#endif + +return 666; +} +/*::------------------------------------------------------------------::*/ +/* + * XOR entre images, nouveau 25 septembre 2018, dans le DD2 + * pour le timelapse de streetpack... + */ + +int Image_XOR(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, int k) +{ +int foo, x, y; + +#if DEBUG_LEVEL +fprintf(stderr, "---> %s ( %p %p %p %d)\n", __func__, s1, s2, d, k); +#endif + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s: sources are differents (%d)\n", __func__, foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, d)) ) + { + fprintf(stderr, "%s: source & destinationa are differents (%d)\n", + __func__, foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + d->Rpix[y][x] = s1->Rpix[y][x] ^ s2->Rpix[y][x]; + d->Gpix[y][x] = s1->Gpix[y][x] ^ s2->Gpix[y][x]; + d->Bpix[y][x] = s1->Bpix[y][x] ^ s2->Bpix[y][x]; + } + } + +d->modified = 3; + +return OLL_KORRECT; +} diff --git a/combine_rnd.c b/combine_rnd.c new file mode 100644 index 0000000..aceeae5 --- /dev/null +++ b/combine_rnd.c @@ -0,0 +1,104 @@ +/* + combine_rnd.c random effects + ============= -------------- + + made by Thierry Boudet, aka "Oulala", aka "Tonton Th". + +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * on va prendre au hasard un point sur une des deux images + * le parametre 'yo' doit etre entre 0 et 10000 + */ +int +Image_combine_random_point(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int yo) +{ +int foo, x, y, r, g, b; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s: sources are differents (%d)\n", __func__, foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, d)) ) + { + fprintf(stderr, "%s: destination different (%d)\n", __func__, foo); + return foo; + } + +if (yo > 10000) yo = 10000; +else if (yo < 0) yo = 0; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if ( (rand()%10000) > yo ) + { + r = (s1->Rpix[y])[x]; + g = (s1->Gpix[y])[x]; + b = (s1->Bpix[y])[x]; + } + else + { + r = (s2->Rpix[y])[x]; + g = (s2->Gpix[y])[x]; + b = (s2->Bpix[y])[x]; + } + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 7 mars 2010 */ +int +Image_combine_random_rgb(Image_Desc *s1, Image_Desc *s2, Image_Desc *d, + int yo) +{ +int foo, x, y, r, g, b, r7, g7, b7; + +if ( (foo=Image_compare_desc(s1, s2)) ) + { + fprintf(stderr, "%s: sources are differents (%d)\n", __func__, foo); + return foo; + } + +if ( (foo=Image_compare_desc(s1, d)) ) + { + fprintf(stderr, "%s: destination different (%d)\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if ( (rand()%100) > yo ) r = (s1->Rpix[y])[x]; + else r = (s2->Rpix[y])[x]; + if ( (rand()%100) > yo ) g = (s1->Gpix[y])[x]; + else g = (s2->Gpix[y])[x]; + if ( (rand()%100) > yo ) b = (s1->Bpix[y])[x]; + else b = (s2->Bpix[y])[x]; + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/contours.c b/contours.c new file mode 100644 index 0000000..d266786 --- /dev/null +++ b/contours.c @@ -0,0 +1,15 @@ +/* + * contours.c - new StEx 11 oct 2014 + */ + +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * http://www.palkeo.com/projets/traitement_images/index.html + */ + +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/contrast.c b/contrast.c new file mode 100644 index 0000000..cef3f2b --- /dev/null +++ b/contrast.c @@ -0,0 +1,76 @@ +/* + * contrast.c - 31 dec 2013 + */ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * cette fonction peut etre utilisee avec la meme image + * en source et en destination. + */ +int Image_pix_square(Image_Desc *source, Image_Desc *but, int k) +{ +int x, y, r, g, b, foo; +float fr, fg, fb; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p -> %p\n", __func__, source, but); +#endif + +if ( (foo=Image_compare_desc(source, but)) ) { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + fr = ((float)(source->Rpix[y])[x]) / 255.0; + fg = ((float)(source->Gpix[y])[x]) / 255.0; + fb = ((float)(source->Bpix[y])[x]) / 255.0; + r = (int)(fr * fr * 255.0); + g = (int)(fg * fg * 255.0); + b = (int)(fb * fb * 255.0); + (but->Rpix[y])[x] = r; + (but->Gpix[y])[x] = g; + (but->Bpix[y])[x] = b; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * cette fonction peut etre utilisee avec la meme image + * en source et en destination. + */ +int Image_pix_sqroot(Image_Desc *source, Image_Desc *but, int k) +{ +int x, y, foo; +float fr, fg, fb; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p -> %p\n", __func__, source, but); +#endif + +if ( (foo=Image_compare_desc(source, but)) ) { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + fr = ((float)(source->Rpix[y])[x]) / 255.0; + fg = ((float)(source->Gpix[y])[x]) / 255.0; + fb = ((float)(source->Bpix[y])[x]) / 255.0; + (but->Rpix[y])[x] = (int)(sqrt(fr) * 255.0); + (but->Gpix[y])[x] = (int)(sqrt(fg) * 255.0); + (but->Bpix[y])[x] = (int)(sqrt(fb) * 255.0); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/detect.c b/detect.c new file mode 100644 index 0000000..a06c7ce --- /dev/null +++ b/detect.c @@ -0,0 +1,151 @@ +/* + detect.c + -------- +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * this function detect all the pixels who the value is + * over the values of all his 8 neight-machin. + */ +int +Image_detect_tops(Image_Desc *src, Image_Desc *dst, int flags) +{ +int x, y, foo, top, r, g, b, rm, gm, bm; +static struct + { + int x, y; + } d[] = + { + { -1, -1 }, + { 0, -1 }, + { 1, -1 }, + { -1, 0 }, + { 1, 0 }, + { -1, 1 }, + { 0, 1 }, + { 1, 1 } + }; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Detect Tops: erreur: %s\n", Image_err2str(foo)); + return foo; + } + +Image_clear(dst, 0, 0, 0); +for (y=1; yheight-1; y++) + { + for (x=1; xwidth-1; x++) + { + top = 0; + for (foo=0; foo<8; foo++) + { + r = Image_R_pixel(src, x+d[foo].x, y+d[foo].y); + if (r > top) top = r; + } + r = Image_R_pixel(src, x, y); + if (r > top) rm = 255; + else rm = 0; + + top = 0; + for (foo=0; foo<8; foo++) + { + g = Image_G_pixel(src, x+d[foo].x, y+d[foo].y); + if (g > top) top = g; + } + g = Image_G_pixel(src, x, y); + if (g > top) gm = 255; + else gm = 0; + + top = 0; + for (foo=0; foo<8; foo++) + { + b = Image_B_pixel(src, x+d[foo].x, y+d[foo].y); + if (b > top) top = b; + } + b = Image_B_pixel(src, x, y); + if (b > top) bm = 255; + else bm = 0; + + Image_plotRGB(dst, x, y, rm, gm, bm); + } + } + +#if DEBUG_LEVEL +fprintf(stderr, "\tok?\n"); +#endif + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * on cherche les endroits ou le niveau de gris est 'plat'. + * + * le paramètre 'r1' n'est pas utilise et doit etre mis à 0 + */ +int +Image_detect_flat_gray(Image_Desc *src, Image_Desc *dst, int param, int r1) +{ +int x, y, foo, r, g, b, gris, mini, maxi; +static struct + { + int x, y; + } d[] = + { + { -1, -1 }, + { 0, -1 }, + { 1, -1 }, + { -1, 0 }, + { 1, 0 }, + { -1, 1 }, + { 0, 1 }, + { 1, 1 } + }; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Detect Flat Gray: erreur: %s\n", Image_err2str(foo)); + return foo; + } + +if (0 != r1) + { + fprintf(stderr, "%s : ah ah r1 is %d, a bad value\n", __func__, r1); + } + +for (y=1; yheight-1; y++) + { + for (x=1; xwidth-1; x++) + { + mini = 999999; + maxi = -42; + for (foo=0; foo<8; foo++) + { + Image_getRGB(src, x+d[foo].x, y+d[foo].y, &r, &g, &b); + gris = r + g + b; + if (gris > maxi) maxi = gris; + else if (gris < mini) mini = gris; + } + if (maxi-mini < param) + Image_plotRGB(dst, x, y, 255, 255, 255); + else + Image_plotRGB(dst, x, y, 0, 0, 0); + } + } +/* + * hop, en finale, on efface les bords, et on + * marque l'image "modifiée". + */ +(void)Image_raz_sides(dst); +dst->modified = 1; + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ + diff --git a/detect2.c b/detect2.c new file mode 100644 index 0000000..4f8ae89 --- /dev/null +++ b/detect2.c @@ -0,0 +1,43 @@ +/* + detect2.c + --------- +*/ + +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * Warning: this function can be very expensive in memory use + */ +int +Image_pix2ptl(Image_Desc *img, int seuil, Image_PtList *ptl) +{ +int foo, val; +int x, y; +long nbre; + +nbre = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + val = Image_R_pixel(img, x, y); + if (val > seuil) + { + Image_ptl_add(ptl, x, y, val, 0); + nbre++; + } + } + } + +foo = Image_ptl_write("pixels.ptl", ptl); + +#if DEBUG_LEVEL +fprintf(stderr, "pix2ptl: %ld pixels\n", nbre); +#endif + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ + diff --git a/dither.c b/dither.c new file mode 100644 index 0000000..8932beb --- /dev/null +++ b/dither.c @@ -0,0 +1,299 @@ +/* + dither.c 31 Aout 1999 + -------- ------------ +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + en entree, on doit avoir une image RGB, sinon, "segfault" + le parametre 'uh' represente l'intensite de la couleur 'on' +*/ +int +Image_dither_Bayer_0(Image_Desc *s, Image_Desc *d, int uh) +{ +int dx, dy, x, y, r, g, b; + +/* directement copie de la page 389 de "Bitmapped graphics" de + Steve Rimmer. */ + +static char pattern[8][8] = + { + { 0, 32, 8, 40, 2, 34, 10, 42 }, + { 48, 16, 56, 24, 50, 18, 58, 26 }, + { 12, 44, 4, 36, 14, 46, 6, 38 }, + { 60, 28, 52, 20, 62, 30, 54, 22 }, + { 3, 35, 11, 43, 1, 33, 9, 41 }, + { 51, 19, 59, 27, 49, 17, 57, 25 }, + { 15, 47, 7, 39, 13, 45, 5, 37 }, + { 63, 31, 55, 23, 61, 29, 53, 21 } + }; + +dx = s->width; dy = s->height; + +for (y=0; yRpix[y][x]; + if ((r>>2) > pattern[x&7][y&7]) d->Rpix[y][x] = uh; + else d->Rpix[y][x] = 0; + g = s->Gpix[y][x]; + if ((g>>2) > pattern[x&7][y&7]) d->Gpix[y][x] = uh; + else d->Gpix[y][x] = 0; + b = s->Bpix[y][x]; + if ((b>>2) > pattern[x&7][y&7]) d->Bpix[y][x] = uh; + else d->Bpix[y][x] = 0; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * 19 Juin 2000: dithering on a 2x2 matrice. + * 15 Nov 2001: 'uh' parameter is _now_ working ;-} + */ +int +Image_dither_crude(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, r, g, b; +int som; + +Image_clear(d, 0, 0, 0); + +for (x=0; x<(s->width-1); x+=2) + { + for (y=0; y<(s->height-1); y+=2) + { + r = g = b = 0; + r += Image_R_pixel(s, x, y); + r += Image_R_pixel(s, x+1, y); + r += Image_R_pixel(s, x, y+1); + r += Image_R_pixel(s, x+1, y+1); + + g += Image_G_pixel(s, x, y); + g += Image_G_pixel(s, x+1, y); + g += Image_G_pixel(s, x, y+1); + g += Image_G_pixel(s, x+1, y+1); + + b += Image_B_pixel(s, x, y); + b += Image_B_pixel(s, x+1, y); + b += Image_B_pixel(s, x, y+1); + b += Image_B_pixel(s, x+1, y+1); + + if (r < 512) Image_plotRGB(d, x, y, 0, 0, 0); + else Image_plotRGB(d, x, y, uh, 0, 0); + + if (g < 512) Image_plotRGB(d, x+1, y, 0, 0, 0); + else Image_plotRGB(d, x+1, y, 0, uh, 0); + + if (b < 512) Image_plotRGB(d, x, y+1, 0, 0, 0); + else Image_plotRGB(d, x, y+1, 0, 0, uh); + + som = r + g + b; + + if (som < 2048) + { + Image_plotRGB(d, x+1, y+1, 0, 0, 0); + } + else + { + Image_plotRGB(d, x+1, y+1, uh, uh, uh); + } + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * ça ne marche pas très fort, ce truc... + */ +int +Image_dither_2x2(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, xm, ym; +int r, g, b, v; + +x = s->width; xm = (x&1) ? (x-1) : x; +y = s->height; ym = (y&1) ? (y-1) : y; + +Image_clear(d, 0, 0, 0); + +#if DEBUG_LEVEL +fprintf(stderr, "dither 2x2: %d %d %d %d\n", x, xm, y, ym); +#endif + +for (x=0; xRpix[y][x]; + if (r > 127) Image_plotRGB(d, x, y, uh, 0, 0); + else Image_plotRGB(d, x, y, 0, 0, 0); + + g = s->Gpix[y][x]; + if (g > 127) Image_plotRGB(d, x+1, y, 0, uh, 0); + else Image_plotRGB(d, x+1, y, 0, 0, 0); + + b = s->Bpix[y][x]; + if (b > 127) Image_plotRGB(d, x, y+1, 0, 0, uh); + else Image_plotRGB(d, x, y+1, 0, 0, 0); + + v = 0xf0 & ((r+g+b)/3); + Image_plotRGB(d, x+1, y+1, v, v, v); + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_dither_seuil_random(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, r, g, b; +int foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither seuil random: images are differents %d\n", foo); + return foo; + } + +Image_clear(d, 0, 0, 0); + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if (s->Rpix[y][x] < rand() % 256) r = 0; + else r = uh; + + if (Image_G_pixel(s, x, y) < rand() % 256) g = 0; + else g = uh; + + if (Image_B_pixel(s, x, y) < rand() % 256) b = 0; + else b = uh; + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * algo tire de Interactive Computer Graphics p. 135 + * + * subtle bug: uh _must_ be 255 ? + */ +int +Image_dither_simple_error(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, xa, xb, inc, errR, errG, errB; +int r, g, b, dr, dg, db; +int foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither simple error: images are differents %d\n", foo); + return foo; + } + +Image_clear(d, 0, 0, 0); +errR = errG = errB = 0; + +for (y=0; yheight; y++) + { + if (y & 1) + { + xa = 0; xb = s->width - 1; inc = 1; + } + else + { + xa = s->width - 1; xb = 0; inc = -1; + } + + for (x=xa; x!=xb; x+=inc) + { + r = (s->Rpix[y])[x]; + if ( (r + errR) > 127 ) dr = uh; + else dr = 0; + errR = (r + errR) - dr; + + g = (s->Gpix[y])[x]; + if ( (g + errG) > 127 ) dg = uh; + else dg = 0; + errG = (g + errG) - dg; + + b = (s->Bpix[y])[x]; + if ( (b + errB) > 127 ) db = uh; + else db = 0; + errB = (b + errB) - db; + + (d->Rpix[y])[x] = dr; + (d->Gpix[y])[x] = dg; + (d->Bpix[y])[x] = db; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * parameters 'sa' and 'sb' must be carefully tuned. + * 29 Jan 2002: may be I can buid a func for automagically + * computing of right values ? + */ +int +Image_dither_double_seuil(Image_Desc *s, Image_Desc *d, int sa, int sb, int uh) +{ +int x, y, r, g, b, foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither double seuil: images are differents %d\n", foo); + return foo; + } + +if ( sa >= sb ) + { + fprintf(stderr, "dither double seuil: lo %d > hi %d !\n", sa, sb); + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = (s->Rpix[y])[x]; + if (r < sa) r = 0; + else if (r > sb) r = uh; + else r = (x&1 && y&1) ? 0 : uh; + + g = (s->Gpix[y])[x]; + if (g < sa) g = 0; + else if (g > sb) g = uh; + else g = (!(x&1) && y&1) ? 0 : uh; + + b = (s->Bpix[y])[x]; + if (b < sa) b = 0; + else if (b > sb) b = uh; + else b = (x&1 && !(y&1)) ? 0 : uh; + + (d->Rpix[y])[x] = r; + (d->Gpix[y])[x] = g; + (d->Bpix[y])[x] = b; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ diff --git a/dither2.c b/dither2.c new file mode 100644 index 0000000..2a37154 --- /dev/null +++ b/dither2.c @@ -0,0 +1,190 @@ +/* + dither2.c + --------- +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* ya pas un probleme d'offset dans ces tables ? XXX */ +static +int dx[]= { 0, 0, 0, + 1, 1, 1, + 2, 2, 2 }; +static +int dy[]= { 0, 1, 2, + 0, 1, 2, + 0, 1, 2 }; + +/*::------------------------------------------------------------------::*/ +/* + * I don't know how to do that ;) but I try hardly ;) + */ +int +Image_dither_3x3_0(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, r, g, b; +int foo, sr, sg, sb; + +#if DEBUG_LEVEL +fprintf(stderr, "* %s le seuil est %d\n", __func__, uh); +#endif + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither 3x3 0: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL > 2 +Image_TGA_save("/tmp/aaaa_debug_a.tga", s, 0); +#endif + +Image_clear(d, 0, 0, 0); + +for (y=0; yheight-3; y+=3) + { + for (x=0; xwidth-3; x+=3) + { + /* compute the average of pixels in a 3x3 field */ + sr = sg = sb = 0; + for (foo=0; foo<9; foo++) + { + sr += (s->Rpix[y+dy[foo]])[x+dx[foo]]; + sg += (s->Gpix[y+dy[foo]])[x+dx[foo]]; + sb += (s->Bpix[y+dy[foo]])[x+dx[foo]]; + } + r = sr / 9; + g = sg / 9; + b = sb / 9; + + /* plot all point, with colors based on average values */ + + (d->Rpix[y]) [x] = rRpix[y+1]) [x] = rRpix[y]) [x+1] = rRpix[y+1]) [x+1] = rGpix[y]) [x+1] = gGpix[y+1]) [x+1] = gGpix[y]) [x+2] = gGpix[y+1]) [x+2] = gBpix[y+1]) [x+1] = bBpix[y+2]) [x] = bBpix[y+2]) [x+2] = bBpix[y+2]) [x+3] = b 2 +Image_TGA_save("/tmp/aaaa_debug_b.tga", d, 0); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * 28 mars 2003... + * + * parameter 'uh' is not used. + */ +int +Image_dither_3x3_1(Image_Desc *s, Image_Desc *d, int uh) +{ +int foo, x, y; +int sr, sg, sb; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither 3x3 1: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "* Image_dither_3x3_1 (%s) is experimental\n", __FILE__); +#endif + +Image_clear(d, 0, 0, 0); + +for (y=0; yheight-3; y+=3) + { + for (x=0; xwidth-3; x+=3) + { + /* compute the average of pixels in a 3x3 field */ + sr = sg = sb = 0; + for (foo=0; foo<9; foo++) + { + sr += (s->Rpix[y+dy[foo]])[x+dx[foo]]; + sg += (s->Gpix[y+dy[foo]])[x+dx[foo]]; + sb += (s->Bpix[y+dy[foo]])[x+dx[foo]]; + } + + for (foo=0; foo=9) + { + fprintf(stderr, "overflow\n"); + return 666; + } + (d->Rpix[y+dy[foo]])[x+dx[foo]] = 255; + } + for (foo=0; foo=9) + { + fprintf(stderr, "overflow\n"); + return 666; + } + (d->Gpix[y+dy[foo]])[x+dx[foo]] = 255; + } + for (foo=0; foo=9) + { + fprintf(stderr, "overflow\n"); + return 666; + } + (d->Bpix[y+dy[foo]])[x+dx[foo]] = 255; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int +Image_dither_3x3_2(Image_Desc *s, Image_Desc *d, int uh) +{ +int foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither 3x3 2: images are differents %d\n", foo); + return foo; + } + +Image_clear(d, 0, 0, 0); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int +Image_dither_3x3_3(Image_Desc *s, Image_Desc *d, int uh) +{ +int foo; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither 3x3 3: images are differents %d\n", foo); + return foo; + } + +Image_clear(d, 0, 0, 0); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ diff --git a/dither3.c b/dither3.c new file mode 100644 index 0000000..21af15d --- /dev/null +++ b/dither3.c @@ -0,0 +1,37 @@ +/* + dither3.c + --------- +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_dither_atkinson(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, r, g, b; +int foo, sr, sg, sb; +int old, new; + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +Image_clear(d, 0, 0, 0); +r = g = b = sr = sg = sb = 0; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + + } + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ diff --git a/dither4.c b/dither4.c new file mode 100644 index 0000000..a81dd50 --- /dev/null +++ b/dither4.c @@ -0,0 +1,91 @@ +/* + dither4.c + --------- +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_dither_4x4_0(Image_Desc *s, Image_Desc *d, int uh) +{ +int x, y, r, g, b; +int foo, sr, sg, sb; + +fprintf(stderr, "* Image_dither_4x4_0 (%s) is experimental\n", __FILE__); +fprintf(stderr, "* Image_dither_4x4_0 le parametre est %d\n", uh); + +if ( (foo=Image_compare_desc(s, d)) ) + { + fprintf(stderr, "dither 4x4 0: images are differents %d\n", foo); + return foo; + } + +Image_clear(d, 0, 0, 0); + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + + } + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int +Image_dither_bayer8x8rnd(Image_Desc *s, Image_Desc *d, int shuff, int mono) +{ +uint16_t matrice[16][16]; +int foo, itmp, m, n; +int x, y, r, g, b, pix; + +fprintf(stderr, "%s ( %p %p %d %d )\n", __func__, s, d, shuff, mono); + +/* remplissage de la matrice */ +fprintf(stderr, " init matrice\n"); +for(foo=0; foo<256; foo++) + { + ((uint16_t *)matrice)[foo] = foo; + } +/* brasssage de la matrice */ +fprintf(stderr, " shuffle matrice %d\n", shuff); +for (foo=0; fooheight; y++) + { + for (x=0; xwidth; x++) + { + r = s->Rpix[y][x]; + g = s->Gpix[y][x]; + b = s->Bpix[y][x]; + if (mono) + { + pix = (r + g +b) / 3; + d->Rpix[y][x] = d->Gpix[y][x] = d->Bpix[y][x] = \ + (pix > matrice[x%16][y%16]) * 255; + } + else + { + d->Rpix[y][x] = (r > matrice[x%16][y%16]) * 255; + d->Gpix[y][x] = (g > matrice[x%16][y%16]) * 255; + d->Bpix[y][x] = (b > matrice[x%16][y%16]) * 255; + } + } + } + +fprintf(stderr, " done\n"); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/effects.c b/effects.c new file mode 100644 index 0000000..8b078c5 --- /dev/null +++ b/effects.c @@ -0,0 +1,377 @@ +/* + + +---------------------------------------+ + | Effets speciaux sur les images | + +---------------------------------------+ + + Thierry Boudet + ----------------------------------------- + vous pouvez aussi aller regarder le module 'combine.c' +*/ + +#include +#include +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * cette func a un defaut: le deplacement est randomatiquement + * lineaire, c'est a dire que la probabilite est constante dans + * toute l'intensite. + */ +int +Image_water( Image_Desc *source, Image_Desc *but, int intensite ) +{ +int x, y, nx, ny, r, g, b, foo; + +#if DEBUG_LEVEL +int retry; +#endif + +if ( (foo=Image_compare_desc(source, but)) ) + { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +if (intensite < 1) + { + fprintf(stderr, "%s : bad intensity %d\n", __func__, intensite); + intensite = 1; + } + +if (source == but) + { + fprintf(stderr, "%s : Source & Target are the same image, bad effect expected...\n", __func__ ); + } + +#if DEBUG_LEVEL +retry = 0; +#endif + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + foo = -1; + do + { + nx = x+(rand()%intensite)-(intensite/2); + ny = y+(rand()%intensite)-(intensite/2); + foo++; + } while ( ! ( (nx >= 0) && (ny >=0) && + (nx < source->width) && + (ny < source->height) ) + ); +#if DEBUG_LEVEL + retry += foo; +#endif + r = (source->Rpix[ny])[nx]; + g = (source->Gpix[ny])[nx]; + b = (source->Bpix[ny])[nx]; + + (but->Rpix[y])[x] = r; + (but->Gpix[y])[x] = g; + (but->Bpix[y])[x] = b; + } + } + +#if DEBUG_LEVEL +if (retry > 0) + fprintf(stderr, "image water: %d retries\n", retry); +else + fprintf(stderr, "image water: NO retry !\n"); +#endif +but->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * cette fonction peut etre utilisee avec la meme image + * en source et en destination. + */ +int +Image_noise(Image_Desc *source, Image_Desc *but, int intensite) +{ +int x, y, r, g, b, foo; + +if ( (foo=Image_compare_desc(source, but)) ) + { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +if (intensite < 1) + { + fprintf(stderr, "%s : bad intensity %d\n", __func__, intensite); + intensite = 1; + } + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + r = Image_clamp_pixel((source->Rpix[y])[x] + + (rand()%intensite) - (intensite/2)); + g = Image_clamp_pixel((source->Gpix[y])[x] + + (rand()%intensite) - (intensite/2)); + b = Image_clamp_pixel((source->Bpix[y])[x] + + (rand()%intensite) - (intensite/2)); + + (but->Rpix[y])[x] = r; + (but->Gpix[y])[x] = g; + (but->Bpix[y])[x] = b; + } + } + +but->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* 19 Aout 1999 + + j'ai rapidement besoin de cette fonction alors je code + a la rache :-[ (on appelle aussi c,a le codage 123momo) + */ +int +Image_mirror(Image_Desc *src, Image_Desc *dst, int reserved) +{ +register int x; +uint8_t *buffer; +int foo, largeur, y; + +if (reserved != 0) + fprintf(stderr, "Image_Mirror: reserved must be zero !\n"); + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_Mirror: images are differents %d\n", foo); + return foo; + } +largeur = src->width; + +if ((buffer = (uint8_t *)malloc(largeur)) == NULL) + { + fprintf(stderr, "Image_Mirror: no memory for buffer"); + return BUFFER_NO_MEM; + } + +for (y=0; yheight; y++) + { + if (src->Rpix != NULL) + { + for (x=0; xRpix[y])[x]; + for (x=0; xRpix[y])[x] = buffer[largeur-x-1]; + } + if (src->Gpix != NULL) + { + for (x=0; xGpix[y])[x]; + for (x=0; xGpix[y])[x] = buffer[largeur-x-1]; + } + if (src->Bpix != NULL) + { + for (x=0; xBpix[y])[x]; + for (x=0; xBpix[y])[x] = buffer[largeur-x-1]; + } + if (src->Apix != NULL) + { + for (x=0; xApix[y])[x]; + for (x=0; xApix[y])[x] = buffer[largeur-x-1]; + } + } + +free(buffer); +dst->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 4 Janvier 2000 */ +int +Image_upside_down(Image_Desc *src, Image_Desc *dst, int reserved) +{ +int foo, y; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_UpsideDown: images are differents %d\n", foo); + return foo; + } + +if (0 != reserved) + { + fprintf(stderr, "%s gni ?\n", __func__); + } + +for (y=0; yheight; y++) + { + memcpy(dst->Rpix[y], src->Rpix[src->height-(y+1)], src->width); + memcpy(dst->Gpix[y], src->Gpix[src->height-(y+1)], src->width); + memcpy(dst->Bpix[y], src->Bpix[src->height-(y+1)], src->width); + if (src->Apix != NULL) + memcpy(dst->Apix[y], src->Apix[src->height-(y+1)], src->width); + } +dst->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * je soupc,onne un bug la dedans... XXX + */ +int +Image_scratch ( Image_Desc *source, Image_Desc * but, long nombre ) +{ +int xs, ys, xd, yd; + +#if DEBUG_LEVEL +fprintf(stderr, "Scratching %ld times %p to %p\n", nombre, source, but); +#endif + +Image_copy(source, but); + +while (nombre--) + { + xs = rand() % source->width; + ys = rand() % source->height; + xd = rand() % source->width; + yd = rand() % source->height; + + Image_pixel_copy(source, xs, ys, but, xd, yd); + } + +but->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* 7 Sep 1999 */ +int +Image_swap_lines( Image_Desc *src, Image_Desc * dst ) +{ +int foo, line; + +if (src == dst) + { + fprintf(stderr, "Image swap lines: SRC & DST must be different\n"); + return IMG_OVERWRITE; + } + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image swap lines: images have differents sizes. %d\n", + foo); + return foo; + } + +for (line=0; line<(src->height-1); line+=2) + { + memcpy(dst->Rpix[line+1], src->Rpix[line], src->width); + memcpy(dst->Rpix[line], src->Rpix[line+1], src->width); + memcpy(dst->Gpix[line+1], src->Gpix[line], src->width); + memcpy(dst->Gpix[line], src->Gpix[line+1], src->width); + memcpy(dst->Bpix[line+1], src->Bpix[line], src->width); + memcpy(dst->Bpix[line], src->Bpix[line+1], src->width); + } + +dst->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* 7 Sep 1999 */ +int +Image_swap_cols( Image_Desc *src, Image_Desc * dst ) +{ +int foo, line, col, tmp, wmax; + +if (src == dst) + { + fprintf(stderr, "Image_SwapCols: SRC & DST must be different\n"); + return IMG_OVERWRITE; + } + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_SwapCols: images are differents %d\n", foo); + return foo; + } + +if (src->width & 1) + wmax = src->width - 1; +else + wmax = src->width; +fprintf(stderr, "swap cols %d %d\n", src->width, wmax); + +for (line=0; lineheight; line++) + { + for (col=0; colRpix[line][col]; + dst->Rpix[line][col] = src->Rpix[line][col+1]; + dst->Rpix[line][col+1] = tmp; + + tmp = src->Gpix[line][col]; + dst->Gpix[line][col] = src->Gpix[line][col+1]; + dst->Gpix[line][col+1] = tmp; + + tmp = src->Bpix[line][col]; + dst->Bpix[line][col] = src->Bpix[line][col+1]; + dst->Bpix[line][col+1] = tmp; + } + } + +dst->modified = 1; + +return OLL_KORRECT; +} + +/*::------------------------------------------------------------------::*/ +/* 7 Sep 1999 */ +int +Image_swap_nibbles( Image_Desc *src, Image_Desc * dst ) +{ +int foo; +int x, y; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + dst->Rpix[y][x] = ((src->Rpix[y][x] & 0xf0) >> 4) | + ((src->Rpix[y][x] & 0x0f) << 4); + +#if DEBUG_LEVEL > 1 + printf ("%02x %02x\n", src->Rpix[y][x], dst->Rpix[y][x]); +#endif + dst->Gpix[y][x] = ((src->Gpix[y][x] & 0xf0) >> 4) | + ((src->Gpix[y][x] & 0x0f) << 4); + + dst->Bpix[y][x] = ((src->Bpix[y][x] & 0xf0) >> 4) | + ((src->Bpix[y][x] & 0x0f) << 4); + + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/effects2.c b/effects2.c new file mode 100644 index 0000000..eb98295 --- /dev/null +++ b/effects2.c @@ -0,0 +1,218 @@ +/* + +---------------------------------------+ + | Effets speciaux sur les images | + | deuxieme module | + +---------------------------------------+ + Thierry Boudet + vous pouvez aussi aller regarder 'effects.c' et 'combine.c' +*/ + +#include +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * la parametre 'table' est un tableau de 6 double. d'accord, + * mais quel est donc son contenu ? + */ +int +Image_sinwave_0( Image_Desc *source, Image_Desc * but, double *table ) +{ +#if DEBUG_LEVEL > 1 +int foo; +#endif +int x, y, xb, yb, r, g, b; +long outside = 0; +double fx, fy, cx, cy; + +#if DEBUG_LEVEL > 1 +Image_dump_descriptor(source, "SinWave 0: source"); +#endif +#if DEBUG_LEVEL > 1 +fprintf(stderr, "-- In %s, table is:\n", __func__); +for (foo=0; foo<6; foo++) + fprintf(stderr, "\t%4d --> %12.6f\n", foo, table[foo]); +#endif + +cx = (2.0 * M_PI) / (double)source->width; +cy = (2.0 * M_PI) / (double)source->height; + +for (x=0; xwidth; x++) + { + fx = (double)x + (table[1] * sin(table[4] + (cx * table[0] * (double)x))); + xb = floor(fx + 0.5); + + for (y=0; yheight; y++) + { + fy = (double)y + (table[3] * sin(table[5] + cy * table[2] * (double)y)); + yb = floor(fy + 0.5); + + if ( xb>0 && yb>0 && xbwidth && ybheight ) + { + r = (source->Rpix[yb])[xb]; + g = (source->Gpix[yb])[xb]; + b = (source->Bpix[yb])[xb]; + + (but->Rpix[y])[x] = r; + (but->Gpix[y])[x] = g; + (but->Bpix[y])[x] = b; + } + else + { + outside++; + /* ??? foo = Image_plotRGB(but, x, y, 0, 0, 0); */ + } + } + } + +#if DEBUG_LEVEL +if (outside) + fprintf(stderr, "%s: outside = %ld\n", __func__, outside); +#endif + +but->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * 11 Octobre 1999 + * Bon, sur celui-ci, je vais essayer d'expliquer... + * + * Les parametres sont en deux groupes de 3 dans la table. + * mais franchement, j'arrive plus a savoir a quoi ils servent. + */ +int +Image_sinwave_1( Image_Desc *source, Image_Desc * but, double *table ) +{ +int foo, x, y, xb, yb, r, g, b; +long outside = 0; +double fx, fy, dx, dy; +int ox, oy; +Image_Desc *buffer; + +if ( (foo=Image_compare_desc(source, but)) ) + { + fprintf(stderr, "Image SinWave 1: images are differents %d\n", foo); + return foo; + } + +if ((buffer = Image_clone(source, 0)) == NULL ) + { + fprintf(stderr, "Image SinWave 1: no mem for buffer\n"); + return BUFFER_NO_MEM; + } + +for (y=0; yheight; y++) + { + fy = (double)y / (double)source->height * M_PI; + dy = sin(fy*table[0]) * table[1]; + oy = (int)(dy); + for (x=0; xwidth; x++) + { + xb = x + oy; + if (xb >=0 && xbwidth) + { + r = (source->Rpix[y])[xb]; + g = (source->Gpix[y])[xb]; + b = (source->Bpix[y])[xb]; + } + else + { + r = g = b = 0; + outside++; + } + (buffer->Rpix[y])[x] = r; + (buffer->Gpix[y])[x] = g; + (buffer->Bpix[y])[x] = b; + } + } + +for (x=0; xwidth; x++) + { + fx = (double)x / (double)source->width * M_PI; + dx = sin(fx*table[3]) * table[4]; + ox = (int)(dx); + for (y=0; yheight; y++) + { + yb = y + ox; + if (yb >=0 && ybheight) + { + r = (buffer->Rpix[yb])[x]; + g = (buffer->Gpix[yb])[x]; + b = (buffer->Bpix[yb])[x]; + } + else + { + r = g = b = 0; + outside++; + } + (but->Rpix[y])[x] = r; + (but->Gpix[y])[x] = g; + (but->Bpix[y])[x] = b; + } + } +Image_DeAllocate(buffer); free(buffer); + +but->modified = 1; + +#if DEBUG_LEVEL > 1 +Image_dump_descriptor(but, "SinWave 1: destination"); +#endif + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 10 janvier 2009 - avenue St Exupery */ +int Image_sinwave_2(Image_Desc *source, Image_Desc *but, double table[]) +{ +int foo; + +if ( (foo=Image_compare_desc(source, but)) ) { + fprintf(stderr, "Image SinWave 2: images are differents %d\n", foo); + return foo; + } + +printf(" in %s now\n", __func__); + +for (foo=0; foo<6; foo++) + { + printf(" %d %g\n", foo, table[foo]); + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_degouline_0(Image_Desc *source, Image_Desc *but, int k1, int k2) +{ +int x, y; +int foo; + +fprintf(stderr, "Degouline %d %d\n", k1, k2); + +if ( (foo=Image_compare_desc(source, but)) ) { + fprintf(stderr, "Image Degouline 2: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d %d )\n", __func__, source, but, k1, k2); +#endif + +for (x=0; xwidth; x++) + { + + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* + * bon sang, mais ya personne qui va se plonger dans ce code + * 100% crade, et en sortir une doc (et des exemples) un peu + * utilisables ? + */ +/*::------------------------------------------------------------------::*/ diff --git a/effects3.c b/effects3.c new file mode 100644 index 0000000..9d596a1 --- /dev/null +++ b/effects3.c @@ -0,0 +1,341 @@ +/* + +---------------------------------------+ + | Effets speciaux sur les images | + | troisième module | + +---------------------------------------+ + Thierry Boudet +*/ + +#include +#include +#include +#include +#include +#include /* yo ! */ + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * 11 Fev 2003: que vais-je mettre ici ? + * 5 avr 2007: je commence a en avoir une idee plus precise. + */ +int +Image_effect_x_0(Image_Desc *src, Image_Desc *dst, int kr, int kg, int kb) +{ +int foo, x, y, r, g, b; +int cr, cg, cb; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image effect x 0: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "*** Effect X_0: coeffs: %d %d %d\n", kr, kg, kb); +#endif + +cr = cg = cb = 0; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(src, x, y, &r, &g, &b); + if (r > kr) { + foo = g; g = b; b = foo; + cr ++; + } + if (g > kg) { + foo = r; r = b; b = foo; + cg ++; + } + if (b > kb) { + foo = g; g = r; r = foo; + cb ++; + } + Image_plotRGB(dst, x, y, r, g, b); + } + } + +fprintf(stderr, "* %s : counts: %d %d %d\n", __func__, cr, cg, cb); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* 2 fevrier 2003: je fait du n'importe quoi, la... */ +/* + * 3 avril 2007: je me rend compte que les parametres ne servent a rien. + */ +int +Image_effect_x_1(Image_Desc *src, Image_Desc *dst) +{ +int foo, x, y, r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image effect x 1: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + + /* 2 fevrier 2003: je fait du n'importe quoi, là... */ + dst->Rpix[y][x] = g^b; + dst->Gpix[y][x] = r^b; + dst->Bpix[y][x] = r^g; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * 1er Février 2003: encore une autre expérimentation, qui va être + * basée sur la trigonométrie. + */ +int +Image_effect_x_2(Image_Desc *src, Image_Desc *dst, int kx, int ky, int kv) +{ +int foo, x, y, r, g, b; +double dr, dg, db, ar, ag, ab; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image effect x 2: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + + /* + * je scale chacune des composantes entre 0.0 et 1.0 + */ + dr = ( (double)r ) / 255.0; + dg = ( (double)g ) / 255.0; + db = ( (double)b ) / 255.0; + + /* + * en fait c'est pas du tout ce que je pense faire, + * mais bon, faut tout essayer... + */ + ar = atan2(dg, db); + ag = atan2(dr, db); + ab = atan2(dr, dg); + + /* + * et là, il y a des soucis d'echelle :) + * 15 mars 2005: pourquoi 156 ? (XXX) + */ + r = (int)(ar * 156.0); + g = (int)(ag * 156.0); + b = (int)(ab * 156.0); + + dst->Rpix[y][x] = r; + dst->Gpix[y][x] = g; + dst->Bpix[y][x] = b; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * 30 Jan 2003: hop, j'improvise pendant que les patates cuisent :) + * 4 Fev 2003: et je peaufine pendant que le poulet mijote :) + * 27 Oct 2003: je debugge pendant que le thé infuse :) + * 16 Mai 2005: je commence a ecrire la documentation. + * 29 sept 2015: je devrais finir la doc d'ici 2 ans. + * + */ +int +Image_effect_x_3(Image_Desc *src, Image_Desc *dst, int kx, int ky, char *comp) +{ +int foo, sx, sy; +int x, y, r, g, b; +int cx, cy, dx, dy; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s : kx %d ky %d comp '%s'\n", __func__, kx, ky, comp); +#endif + +if (strlen(comp) != 2) + { + fprintf(stderr, "eff x3: bad comp parameter '%s'\n", comp); + fprintf(stderr, " must be a 2 chars string, from 'rgb'\n"); + return INVALID_PARAM; + } + +/* + * conversion en minuscules des deux lettres de composantes + */ +cx = tolower(comp[0]); cy = tolower(comp[1]); +dx = dy = 0; +sx = sy = 0; + +/* + * ici il faudrait une validation des deux lettres, mais j'ai la + * flemme d'écrire ça maintenant. je vais plutôt aller boofer. + */ + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + + switch(cx) + { + case 'r': dx = r; break; + case 'g': dx = g; break; + case 'b': dx = b; break; + } + switch(cy) + { + case 'r': dy = r; break; + case 'g': dy = g; break; + case 'b': dy = b; break; + } + + sx = x + ((kx * (dx-128)) / 100); + sy = y + ((ky * (dy-128)) / 100); + + if ( sx >= 0 && sx < dst->width && + sy >= 0 && sy < dst->height ) + { + r = src->Rpix[sy][sx]; + g = src->Gpix[sy][sx]; + b = src->Bpix[sy][sx]; + Image_plotRGB(dst, x, y, r, g, b); + } + else + { + Image_plotRGB(dst, x, y, r, r, r); + } + /* + * Je suis vraiment confus, mais je n'y comprend RIEN :) + */ + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_effect_x_4(Image_Desc *src, Image_Desc *dst, int flags) +{ +int foo; +int x, y; +int r, g, b, r2, g2, b2; + +#if DEBUG_LEVEL +fprintf(stderr, "*** effect x4 is not ready for prime time ***\n"); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image effect x 4: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + r2 = r; g2 = g; b2 = b; + + if (flags & 1) { + if (r > g) b2 = (r + g) / 2; + if (b > g) r2 = (b + g) / 2; + if (r > b) g2 = (r + b) / 2; + } + else { + if (r < g) b2 = (r + g) / 2; + if (b < g) r2 = (b + g) / 2; + if (r < b) g2 = (r + b) / 2; + } + + Image_plotRGB(dst, x, y, r2, g2, b2); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* 22 avril 2007: je vais essayer d'inventer un nouveau truc, mais il + * faudrait que les gosses arretent de ma casser les oreilles avec leur + * machine a batailles. putain de gamecube... */ +int +Image_effect_x_5(Image_Desc *src, Image_Desc *dst, int kx, int ky, int kz) +{ +int foo, sx, sy; +int x, y, r, g, b; +int r2, g2, b2; +double dr, dg, db, dr2, dg2, db2; + +fprintf(stderr, "*** effect x5 is not ready for prime time ***\n"); +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d %d %d )\n", __func__, src, dst, + kx, ky, kz); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image effect x 5: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = src->Rpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + dr = (double)r / 255.0; + dg = (double)g / 255.0; + db = (double)b / 255.0; + dr2 = pow(dg, db); + dg2 = pow(db, dr); + db2 = pow(dr, dg); + r2 = (int)(dr2 * 255.0); + g2 = (int)(dg2 * 255.0); + b2 = (int)(db2 * 255.0); +#if DEBUG_LEVEL + if (x==42 && y==42) + { + printf("{{{ pixels %3d %3d %3d }}}\n", r, g, b); + printf("{{{ result %3d %3d %3d }}}\n", r2, g2, b2); + } +#endif + Image_plotRGB(dst, x, y, r2, g2, b2); + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ diff --git a/eps.c b/eps.c new file mode 100644 index 0000000..ca7ba27 --- /dev/null +++ b/eps.c @@ -0,0 +1,47 @@ +/* + + Encapsulated Postscrip + ---------------------- + + 26 Jan 2002: Functions for exporting images to EPS format, + for use in printed version of the story "Life in Slashie". + + --> see pnmtops manpage ? + +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * really don't know how to do that ;-) + */ +int +Image_EPS_save_0(char *nom, Image_Desc *img) +{ +FILE *fp; +time_t temps; + +fprintf(stderr, "Image EPS save 0: %p -> %s\n", img, nom); + +if ( (fp=fopen(nom, "w")) == NULL ) + { + fprintf(stderr, "EPS save 0: err fopen %s\n", nom); + return FILE_CREATE_ERR; + } + +fputs("%!PS-Adobe-2.0 EPSF-1.2\n%%\n", fp); +fprintf(fp, "%%%% Generator: libimage v %s\n", IMAGE_VERSION_STRING); +time(&temps); +fprintf(fp, "%%%% Date: %s\n", ctime(&temps)); +fclose(fp); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* + * really don't know how to do that ;-) + */ +/*::------------------------------------------------------------------::*/ diff --git a/essais.c b/essais.c new file mode 100644 index 0000000..f861928 --- /dev/null +++ b/essais.c @@ -0,0 +1,1418 @@ +/* + ce fichier contient diverses fonctions pour tester + les trucs et puis les machins. + + en general, c'est des fonctions que je met ici et + elles sont appelees par le main dans 'testtga.c'. + + NOTE: il faudrait verifier si les liberations de + memoire sont bien faites... +*/ + +#include +#include +#include +#include + +#include "tthimage.h" +#include "essais.h" + +/*::------------------------------------------------------------------::*/ +/* nouveau vacances de fevrier 2010 */ +int Essayer_les_alphas(char *fname, int k) +{ +Image_Desc *src, *dst; +int foo; + +printf("=========== %s ( '%s' %d ) ===============\n", + __func__, fname, k); + +if (NULL==(src=Image_TGA_alloc_load(fname))) { + fprintf(stderr, "%s : omg, '%s' is not readable.\n", __func__, fname); + exit(1); + } +if (NULL==(dst=Image_clone(src, 0))) { + fprintf(stderr, "%s : omg, %p is not clonable.\n", __func__, src); + exit(5); + } + +foo = Image_tampon_alpha_0(src, NULL, dst); +if (foo) Image_print_error(__func__, foo); + +Image_TGA_save("Pictures/aaaa-tampon.tga", dst, 0); + +Image_DeAllocate(dst); free(dst); +Image_DeAllocate(src); free(src); + +return 42; +} +/*::------------------------------------------------------------------::*/ +int Manipuler_les_couleurs(char *fname, int k) +{ +Image_Desc *src, *dst; +int foo; + +printf("=========== %s ( '%s' %d ) ===============\n", + __func__, fname, k); + +if (NULL==(src=Image_TGA_alloc_load(fname))) { + fprintf(stderr, "%s : omg, '%s' is not readable.\n", __func__, fname); + exit(1); + } +if (NULL==(dst=Image_clone(src, 0))) { + fprintf(stderr, "%s : omg, %p is not clonable.\n", __func__, src); + exit(5); + } + +/* OK, les deux images doivent etre en place */ +fprintf(stderr, "trying %p -> %p\n", src, dst); + +foo = Image_BiColor_0(src, dst, 0); +Image_print_error("BiColor 0", foo); + +foo = Image_BiColor_1(src, dst, 0, 1); +Image_print_error("BiColor 1", foo); + +return WTF_OSEF; +} +/*::------------------------------------------------------------------::*/ +int Essai_luminance(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo; + +fprintf(stderr, "=========== %s ( %s %d )\n", __func__, srcname, k); + +if (NULL==(src=Image_TGA_alloc_load(srcname))) { + fprintf(stderr, "%s : oups, '%s' n'est pas lisible\n", + __func__, srcname); + exit(1); + } +/* on va creer le receptacle des horreurs */ +if (NULL==(dst=Image_clone(src, 0))) { + exit(5); + } + +/* que doit valoir le troisieme parametre ? */ +foo = Image_luminance(src, dst, -50); +Image_TGA_save("Pictures/aaaa-luminance--50.tga", dst, 0); +foo = Image_luminance(src, dst, 128); +Image_TGA_save("Pictures/aaaa-luminance-128.tga", dst, 0); +foo = Image_luminance(src, dst, 200); +Image_TGA_save("Pictures/aaaa-luminance-200.tga", dst, 0); +foo = Image_luminance(src, dst, 500); +if (foo) Image_print_error(__func__, foo); + +Image_TGA_save("Pictures/aaaa-luminance-500.tga", dst, 0); + +Image_DeAllocate(dst); free(dst); +Image_DeAllocate(src); free(src); + +return 0; +} +/*::------------------------------------------------------------------::*/ +int Essais_plot_Map(int k) +{ +RGB_map map; +int foo; + + +printf("=========== %s ( %d ) ===============\n", + __func__, k); + +foo = Image_load_color_Map("volcano.map", "Volcano Map", &map); +Image_print_error("chargement Volcano", foo); +foo = Image_plot_square_Map("Pictures/aaaa-sqrmap-volcano.tga", &map, "yo le monde", 0); +Image_print_error("plot square Map", foo); + +foo = Image_load_color_Map("neon.map", "Neon Map", &map); +Image_print_error("chargement Neon", foo); +foo = Image_plot_square_Map("Pictures/aaaa-sqrmap-neon.tga", &map, "yo le monde", 0); +Image_print_error("plot square Map", foo); + +foo = Image_load_color_Map("primaires.map", "Primaire Map", &map); +Image_print_error("chargement Primaire", foo); +foo = Image_plot_square_Map("Pictures/aaaa-sqrmap-primaires.tga", &map, "yo !", 0); +Image_print_error("plot square Map", foo); + +foo = Image_load_color_Map("reduce.map", "reduce Map", &map); +Image_print_error("chargement reduce", foo); +foo = Image_plot_square_Map("Pictures/aaaa-sqrmap-reduce.tga", &map, "yo !", 0); +Image_print_error("plot square Map", foo); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * raw16bits.c - new 22 septembre 2009 - Petit London + */ +int Essai_raw16bits(char *srcname, int k) +{ + +printf("=========== %s ( '%s' %d ) ===============\n", + __func__, srcname, k); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* new 21 septembre 2009 - essai des reductions chromatiques */ +int Essai_color_2_map(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo, idx; +char fname[200]; + +printf("============== %s ( '%s' %d ) ==================\n", + __func__, srcname, k); + +if (NULL==(src=Image_TGA_alloc_load(srcname))) { + fprintf(stderr, "%s : oups, '%s' n'est pas lisible\n", + __func__, srcname); + exit(1); + } +/* on va creer le receptacle des horreurs */ +if (NULL==(dst=Image_clone(src, 0))) { + exit(5); + } + +/* ah bravo ! enfin un test unitaire appelable + * depuis le test unitaire */ +for (idx=0; idx<20; idx++) + { + foo = Image_essai_col_reduce(src, dst, 133, idx); + printf("le retour de l'essai_col_reduce %d est %d\n", idx, foo); + if (OLL_KORRECT==foo) + { + sprintf(fname, "Pictures/aaaa-colredux-%02d.tga", idx); + Image_TGA_save(fname, dst, 0); + } + } + +Image_DeAllocate(dst); free(dst); +Image_DeAllocate(src); free(src); + +return 666; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 8 septembre 2009 - essai des operations etranges sur le gris */ +int Essai_des_gray_ops(char *srcname, int k) +{ + +printf("================= %s ( '%s' %d ) =============\n", + __func__, srcname, k); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 1 septembre 2009 - ave StExupery */ +int Essai_des_mires(char *texte, int ka, int kb) +{ +Image_Desc *img, *tmp; +int foo; + +printf("================ %s ( '%s' %d %d ) ==============\n", + __func__, texte, ka, kb); + +if (NULL==(img=Image_alloc(800, 480, IMAGE_RGB))) { + fprintf(stderr, "%s : FAIL no memory\n", __func__); + abort(); + } + +foo = Image_mircol_2(img, texte, 0); +Image_print_error("mircol 2", foo); +Image_TGA_save("Pictures/aaaa-mircol-2.tga", img, 0); + +tmp = Image_clone(img, 0); +Image_decompose(img, tmp, 0); +Image_TGA_save("Pictures/aaaa-mircol-2-dec.tga", tmp, 0); +Image_DeAllocate(tmp); free(tmp); + +printf("%s -> mircol_3 0\n", __func__); +foo = Image_mircol_3(img, texte, 0); +Image_print_error("mircol 3 0", foo); +Image_TGA_save("Pictures/aaaa-mircol-3-0.tga", img, 0); +printf("%s -> mircol_3 0\n", __func__); +foo = Image_mircol_3(img, texte, 1); +Image_print_error("mircol 3 1", foo); +Image_TGA_save("Pictures/aaaa-mircol-3-1.tga", img, 0); +printf("%s -> mircol_3 2\n", __func__); +foo = Image_mircol_3(img, texte, 2); +Image_print_error("mircol 3 2", foo); +Image_TGA_save("Pictures/aaaa-mircol-3-2.tga", img, 0); + +return -1; +} +/*::------------------------------------------------------------------::*/ +int Essai_des_lut15bits(char *srcname, int k) +{ +int foo; + +printf("================= %s ( '%s' %d ) =============\n", + __func__, srcname, k); + +foo = Image_lut15_essai(srcname, "aaaa-hf15-lut-0.tga", 0); +Image_print_error("lut 15, 0 = ", foo); + +foo = Image_lut15_essai(srcname, "aaaa-hf15-lut-1.tga", 1); +Image_print_error("lut 15, 1 = ", foo); + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* nouveau - 8 novembre 2009 */ +int Essai_des_bitblt(char *srcname, int k) +{ +Image_Desc *src, *dst; +Image_Rect rectA, rectB; + +printf("================= %s ( '%s' %d ) =============\n", + __func__, srcname, k); + +if ( NULL == (src=Image_TGA_alloc_load(srcname)) ) { + fprintf(stderr, "%s : *PAN* sur %s (not found ?)\n", __func__, srcname); + exit(1); + } + +fprintf(stderr, "source %dx%d\n", src->width, src->height); + +dst = Image_clone(src, 0); + +rectA.w = src->width; +rectA.h = src->height; + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Essai_des_gadgrect(char *srcname, int k) +{ +/* ce truc est nouveau, du 4 fevrier 2009 */ +Image_Desc *image; +Image_Rect coin; +int foo; + +printf("================= %s ( '%s' %d ) =============\n", + __func__, srcname, k); + +if ( NULL == (image=Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "%s : Bang sur %s (not found ?)\n", __func__, srcname); + exit(1); + } + +coin.x = image->width / 3; coin.y = image->height / 3; +coin.w = image->width / 5; coin.h = image->height / 7; +Image_dump_rect(&coin, "le coin(pan)", 0); +foo = Image_gadrct_Hsweep_0(image, &coin, 0); + +Image_TGA_save("Pictures/aaaa-Hsweep0.tga", image, 0); +Image_calc_plot_histo(image, "Pictures/aaaa-lol-mdr.tga"); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Essai_des_zooms(char *srcname, int k) +{ +Image_Desc *origine, *nucked; +int foo; + +printf("================= %s ( '%s' %d ) =============\n", + __func__, srcname, k); + +if ( NULL == (origine=Image_TGA_alloc_load(srcname)) ) { + fprintf(stderr, "%s : pas de '%s' ici\n", __func__, srcname); + exit(1); + } +if ( NULL == (nucked=Image_clone(origine, 1)) ) { + fprintf(stderr, "%s : FailClone of %p\n", __func__, origine); + exit(1); + } + +foo = Image_essai_zoom(origine, nucked, 1.18, 0.42, 0); + +Image_TGA_save("Pictures/aaaa-zoom.tga", nucked, 0); + +Image_DeAllocate(nucked); free(nucked); +Image_DeAllocate(origine); free(origine); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Essai_des_distances(char *srcname, int nbre, int flag) +{ +Image_Desc *src, *dst; +int foo; +double dr, dg, db; + +printf("============ %s ( '%s' %d %d ) ============\n", __func__, + srcname, nbre, flag); + +if ( NULL == (src=Image_TGA_alloc_load(srcname)) ) { + fprintf(stderr, "%s : Bang sur %s\n", __func__, srcname); + exit(1); + } +#if DEBUG_LEVEL +fprintf(stderr, "%s : img @ %p\n", __func__, src); +#endif +if ( NULL == (dst=Image_clone(src, 1)) ) { + fprintf(stderr, "%s : FailClone of %p\n", __func__, src); + exit(1); + } + +dr = dg = db = 0.0; + +for (foo=0; foo %d\n", __FILE__, foo); + Image_TGA_save("Pictures/aaaa-7seg.tga", imgtmp, 0); + Image_DeAllocate(imgtmp); free(imgtmp); + } + +if (flag & 2) + { + imgtmp = Image_clone(origine, 1); + sprintf(buffer, "%04d", 42); + foo = Image_7seg_tag0(imgtmp, buffer, 0); + printf("%s : image 7 seg tag0 -> %d\n", __FILE__, foo); + Image_TGA_save("Pictures/aaaa-7seg-tag0.tga", imgtmp, 0); + Image_DeAllocate(imgtmp); free(imgtmp); + } + +Image_DeAllocate(origine); free(origine); + +printf("fin essai 7 segs\n"); + +return 7; +} +/*::------------------------------------------------------------------::*/ +/* les essais de cadres sont partis dans essais2.c */ +/*::------------------------------------------------------------------::*/ +int Filtre_Directionnel(char *srcname, int flags) +{ +int rotule, foo; +Image_Desc *origine, *imgtmp; +char chaine[100]; +int filtre[11]; +int w3, h3; +Image_Rect rect; + +static int datas_sobel[] = + { + 1, 2, 1, + 0, 0, 0, + -1, -2, -1, + 1, 128 + }; +static int datas_prewitt[] = + { + 1, 1, 1, + 0, 0, 0, + -1, -1, -1, + 1, 128 + }; +static struct offxy + { int x, y; } offsets[] = { + { 1, 0 }, + { 2, 0 }, + { 2, 1 }, + { 2, 2 }, + { 1, 2 }, + { 0, 2 }, + { 0, 1 }, + { 0, 0 } + }; + +printf("========= Filtrage directionnel sur %s =======\n", srcname); + +if ( NULL == (origine=Image_TGA_alloc_load(srcname)) ) { + fprintf(stderr, "%s : Bang sur %s\n", __func__, srcname); + exit(1); + } +printf("image originale @ %p\n", origine); + +imgtmp = Image_clone(origine, 1); + +w3 = origine->width * 3; +h3 = origine->height * 3; + +if (flags) memcpy(filtre, datas_prewitt, sizeof(filtre)); +else memcpy(filtre, datas_sobel, sizeof(filtre)); + +for (rotule=0; rotule<8; rotule++) + { + foo = Image_convolueur_2(origine, imgtmp, filtre, "rgb"); + printf("=== Passe %d retour %d\n", rotule, foo); + + Image_raz_sides(imgtmp); + + sprintf(chaine, "Pictures/aaaa_fildir_%x.tga", rotule); + Image_TGA_save(chaine, imgtmp, 0); + + /* de la scorie ? + rect.x = offsets[rotule].x * origine->width; + rect.y = offsets[rotule].y * origine->height; + Image_dump_rect(&rect, "filtre direct", 0); + */ + + Image_rotate_filtre(filtre); + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 31 aout 2008 - ave St Exupery */ +int Test_des_trucs_2x2(char *srcname, int k) +{ +int foo; +Image_Desc *origine, *imgtmp; + +printf("===== LES TRUCS 2 x 2 ===[ %s ]=[ %d ]=====\n", srcname, k); + +if ( NULL == (origine=Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "%s : Bang sur %s\n", __func__, srcname); + exit(1); + } +printf("image originale @ %p\n", origine); + +imgtmp = Image_clone(origine, 1); +if (NULL == imgtmp) { + fprintf(stderr, "fail in %s - %s\n", __func__, __FILE__); + abort(); + } +foo = Image_2x2_contours_0(imgtmp); +Image_TGA_save("Pictures/aaaa-2x2-a.tga", imgtmp, 0); + +Image_seuil_RGB(origine, imgtmp, 64, 128, 192); +foo = Image_2x2_contours_0(imgtmp); +Image_TGA_save("Pictures/aaaa-2x2-b.tga", imgtmp, 0); + +Image_AutoSeuilRGB(origine, imgtmp); +foo = Image_2x2_contours_0(imgtmp); +Image_TGA_save("Pictures/aaaa-2x2-c.tga", imgtmp, 0); + +Image_DeAllocate(imgtmp); free(imgtmp); +Image_DeAllocate(origine); free(origine); + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* new 14 septembre 2008 /o\ 51 ans... */ +int Test_des_warpings(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo, ax, ay; + +printf("====== essais Warping sur %s (k=%d) ====\n", srcname, k); + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "Err loading '%s'\n", srcname); + exit(5); + } +dst = Image_clone(src, 0); + +foo = Image_warp_essai_0(src, dst, 33.5, 100, 100); +Image_TGA_save("Pictures/warp-essai-0.tga", dst, 0); + +foo = Image_center_rotate(src, dst, 21.5); +Image_TGA_save("Pictures/warp-center-rotate.tga", dst, 0); + +ax = (src->width * 2) / 3; +ay = (src->height * 2) / 3; +foo = Image_shift_xy(src, dst, ax, ay); +Image_TGA_save("Pictures/warp-shift-xy.tga", dst, 0); +foo = Image_shift_x(src, dst, ax); +Image_TGA_save("Pictures/warp-shift-x.tga", dst, 0); +foo = Image_shift_y(src, dst, ay); +Image_TGA_save("Pictures/warp-shift-y.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* new 7 avril 2007, essai des mosaiques */ +int Test_des_mosaiques(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo; + +fprintf(stderr, "============== %s : k %d ======\n", __func__, k); + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "%s : Err loading '%s'\n", __func__, srcname); + exit(5); + } +dst = Image_clone(src, 0); + +foo = Image_mosaic_0(src, dst, 6, 6, 0); +Image_TGA_save("Pictures/aaaa-mosaic-0.tga", dst, 0); +foo = Image_mosaic_simple(src, dst); +Image_TGA_save("Pictures/aaaa-mosaic-s.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +return 42; +} +/* quelque part, il doit aussi y avoir un test des grilles */ + +/*::------------------------------------------------------------------::*/ +/* new 11 decembre 2007 - ave St Exupery */ +static double fonction(int x, int y, int param) +{ +double value; +if (param) + value = 0.333333 + sin((double)x) + cos((double)y); +else + value = 0.333333 + sin((double)x) * cos((double)y); +return value; +} +int Test_hf15_synth_fromfunc(char *fname) +{ +Image_Desc *image; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "in %s, param '%s' not used ?\n", __func__, fname); +#endif + +image = Image_alloc(256, 256, 3); + +foo = Image_hf15_synth_fromfunc0(image, 33, fonction); +fprintf(stderr, "Synth from func %d\n", foo); +Image_TGA_save("Pictures/aaaa-synthfunc.tga", image, 0); + +return 0; +} +/*::------------------------------------------------------------------::*/ +int Test_hf15_synth_fromPtl(char *iname, char *oname) +{ +Image_Desc *src, *dst; +Image_PtList *ptl; +Image_Rect boite; +int x, y, h, foo; +int r, g, b; + +printf("======= Synth from PointList ===========\n"); + +if (NULL == (src = Image_TGA_alloc_load(iname)) ) + { + fprintf(stderr, "%s: Err loading '%s'\n", __func__, iname); + exit(5); + } +dst = Image_clone(src, 0); +ptl = Image_ptl_alloc(300, "pix2ptl"); +printf("point list @ %p\n", ptl); + +for (foo=0; foo<6000; foo++) + { + x = rand() % (src->width - 5); + y = rand() % (src->height - 5); + Image_getRGB(src, x, y, &r, &g, &b); + h = r + g + b; + Image_ptl_add(ptl, x, y, h, 0); + } + +Image_ptl_dump(ptl, "apres randomz"); +memset(&boite, 0, sizeof(Image_Rect)); +foo = Image_ptl_boundingbox(ptl, &boite); +Image_print_error("ptl bounding box", foo); +Image_dump_rect(&boite, "ptl bounding box", 1); + +foo = Image_hf15_synth_1(dst, ptl); +Image_TGA_save("Pictures/aaaa-synthptl.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +Image_ptl_kill(ptl, __func__); + +return 0; +} +/*::------------------------------------------------------------------::*/ +int Test_funcs_hf15(char *srcname, int flag) +{ +Image_Desc *src, *dst; +int foo; +int minimum, maximum; + +fprintf(stderr, "entering ================>> %s\n", __func__); + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "Error loading '%s'\n", srcname); + exit(5); + } + +if (flag) + { + fprintf(stderr, "mmmm flag is %02x, need some debug...\n", flag); + } + +fprintf(stderr, "picture '%s' : %d x %d\n", srcname, src->width, src->height); + +foo = Image_hf15_rgb2hf(src, src, 0); +printf("rgb2hf -> %d\n", foo); +Image_hf15_save_PGM("Pictures/aaaa-hf15-src.pgm", src, "from 'essais.c'"); + +dst = Image_clone(src, 0); +Image_TGA_save("Pictures/aaaa-clone-hf15.tga", dst, 0); + +foo = Image_plot_histo_hf15(src, "aaaa-histo-src.tga", "from essais.c", 0, 0); +fprintf(stderr, "retour plottage de l'histo = %d\n", foo); + +foo = Image_hf15_sqrt(src, dst); +foo = Image_plot_histo_hf15(dst, "aaaa-histo-sqrt.tga", "from essais.c", 0, 0); +Image_hf15_save_PGM("Pictures/aaaa-hf15-sqrt.pgm", src, "from 'essais.c'"); +fprintf(stderr, "Ok, done %d sqrt\n", foo); + +Image_copy(src, dst); +foo = Image_hf15_noise_2(dst, 42, 5, 0, 0); +Image_TGA_save("Pictures/aaaa-hf15-noise2.tga", dst, 0); + +Image_copy(src, dst); +foo = Image_hf15_noise_3(dst, 42.42, 0); +Image_TGA_save("Pictures/aaaa-hf15-noise3.tga", dst, 0); + +Image_copy(src, dst); +foo = Image_hf15_rgb2hf(dst, dst, 0); +/* calculer le min et le max AVANT */ +Image_hf15_calc_minmax(dst, "Avant le sweep", &minimum, &maximum); +foo = Image_hf15_sweep(dst, 42, 400, 0); +/* calculer le min et le max APRES */ +Image_hf15_calc_minmax(dst, "Apres le sweep", &minimum, &maximum); + +Image_TGA_save("Pictures/aaaa-hf15-sweep-c.tga", dst, 0); +Image_hf15_save_PGM("Pictures/aaaa-hf15-sweep-c.pgm", dst, "from essais.c"); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); +return IMAGE_FAIL; +} +/*::------------------------------------------------------------------::*/ +int Test_vignettes(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo; + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "Err loading '%s'\n", srcname); + exit(5); + } +dst = Image_clone(src, 0); + +foo = Image_vignetize_x_0(src, dst, k); +Image_print_error("vignetize_x_0", foo); + +Image_TGA_save("Pictures/aaaa-vignetize_x0.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +return 42; +} +/*::------------------------------------------------------------------::*/ +int Test_classif(char *srcname, int k) +{ +Image_Desc *src, *dst; +int foo; + +fprintf(stderr, "============= %s sur %s =======\n", __func__, srcname); + +#define DC 50 +static Une_Classe_Sph classs[] = + { + { 127, 127, 127, DC, 127, 127, 127 }, + { 255, 255, 255, DC, 255, 255, 255 }, + { 255, 0, 0, DC, 255, 0, 0 }, + { 0, 0, 255, DC, 0, 0, 255 }, + { 0, 255, 0, DC, 0, 255, 0 } + }; + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "Err loading '%s'\n", srcname); + exit(5); + } +dst = Image_clone(src, 0); + +foo = Image_classif_0(src, dst); +Image_print_error("essai classif 0", foo); +Image_TGA_save("Pictures/aaaa-classif0.tga", dst, 0); + +foo = Image_classif_1(src, dst, classs, 5, 0); +Image_print_error("essai classif 1", foo); +Image_TGA_save("Pictures/aaaa-classif1.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* new 24 avril 2007, essais sur le module rgbmask.c */ +int +Test_rgbmask(char *srcname) +{ +Image_Desc *source, *image ; +int foo; + +source = Image_TGA_alloc_load(srcname); +image = Image_clone(source, 0); + +foo = Image_rgbmask_H(source, image, 0); +Image_TGA_save("Pictures/aaaa-rgbmaskH.tga", image, 0); +foo = Image_rgbmask_V(source, image, 0); +Image_TGA_save("Pictures/aaaa-rgbmaskV.tga", image, 0); +foo = Image_rgbmask_2(source, image, 0); +Image_TGA_save("Pictures/aaaa-rgbmask2.tga", image, 0); +foo = Image_rgbmask_R(source, image, 0); +Image_TGA_save("Pictures/aaaa-rgbmaskR.tga", image, 0); + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* new 9 avr 2007, tests du module col_xyz.c */ + +void Test_rgb2xyz(void) +{ +int r, g, b, foo; +double dx, dy, dz; +double minx, maxx, miny, maxy, minz, maxz; + +minx = miny = minz = 999999.9; +maxx = maxy = maxz = -999999.9; + +for (r=0; r<256; r+=1) + { + for (g=0; g<256; g+=1) + { + for (b=0; b<256; b+=1) + { + foo = Image_pix_rgb2xyz_d(r, g, b, &dx, &dy, &dz); + if (dx > maxx) maxx = dx; + if (dx < minx) minx = dx; + if (dy > maxy) maxy = dy; + if (dy < miny) miny = dy; + if (dz > maxz) maxz = dz; + if (dz < minz) minz = dz; + } + } + } +fprintf(stderr, "fin test rgb2xyz\n"); +fprintf(stderr, "%12.6f X %12.6f\n", minx, maxx); +fprintf(stderr, "%12.6f Y %12.6f\n", miny, maxy); +fprintf(stderr, "%12.6f Z %12.6f\n", minz, maxz); +} +/*::------------------------------------------------------------------::*/ +/* added 24 mai 2009, because I need a reliable timestamp utility for + * my big POV project, "Parking Maudit". + */ +int Essai_des_marquages(char *srcname, int nombre, char *texte) +{ +Image_Desc *src, *dst; +int foo; + +if (NULL == (src = Image_TGA_alloc_load(srcname)) ) + { + fprintf(stderr, "Err in %s when loading '%s'\n", __func__, srcname); + exit(5); + } + +printf("le nombre est %d\n", nombre); + +dst = Image_clone(src, 1); + +fprintf(stderr, ">>>> %s : src (%s) %p dst %p\n", __func__, srcname, src, dst); + +foo = Image_marque_timestamp(dst, texte, NULL, 0); +Image_TGA_save("Pictures/aaaa-timestamp-0.tga", dst, 0); + +Image_copy(src, dst); +foo = Image_marque_timestamp(dst, texte, NULL, 1); +Image_TGA_save("Pictures/aaaa-timestamp-1.tga", dst, 0); + +return 42; +} +/*::------------------------------------------------------------------::*/ +void Test_double_size(void) +{ +Image_Desc *src, *dst; + +src = Image_alloc(50, 50, 3); +Image_clear(src, 0, 0, 0); + +Image_marque_0(src, 128); + +Image_plotRGB(src, 11, 2, 255, 255, 255); +Image_plotRGB(src, 12, 2, 255, 255, 255); +Image_plotRGB(src, 13, 2, 255, 255, 255); + +dst = Image_MakeDoubleSize(src, 1); +Image_TGA_save("Pictures/aaaa_dblsz.tga", dst, 0); +Image_DeAllocate(dst); free(dst); + +dst = Image_MakeDoubleSize_H(src, 0); +Image_TGA_save("Pictures/aaaa_dblszh0.tga", dst, 0); +Image_DeAllocate(dst); free(dst); +dst = Image_MakeDoubleSize_H(src, 1); +Image_TGA_save("Pictures/aaaa_dblszh1.tga", dst, 0); +Image_DeAllocate(dst); free(dst); + +Image_DeAllocate(src); free(src); +} +/*::------------------------------------------------------------------::*/ +/* new, around Hallowen 2009 */ +int Test_new_scale(char *fnamesrc, int k) +{ +Image_Desc *src, *dst; +int foo; + +#define WDST 512 +#define HDST 512 + +fprintf(stderr, "============= %s ( '%s' ) ================\n", + __func__, fnamesrc); +src = Image_TGA_alloc_load(fnamesrc); +if (NULL == src) + { + fprintf(stderr, "? %s non existantz ?\n", fnamesrc); + abort(); + } +Image_marque_0(src, 255); +Image_TGA_save("Pictures/aaaa_new_scale_0.tga", src, 0); + +dst = Image_alloc(WDST, HDST, 3); +foo = Image_scale_bilinear(src, dst, 0); +printf("retour scale bilinear -> %d\n", foo); +foo = Image_TGA_save("Pictures/aaaa_new_scale_bilin.tga", dst, 0); +#if DEBUG_LEVEL +fprintf(stderr, "saving in %s -> %d\n", __func__, foo); +#endif +Image_DeAllocate(dst); free(dst); + +dst = Image_alloc(WDST, HDST, 3); +foo = Image_scale_simple(src, dst, 0); +printf("retour scale simple -> %d\n", foo); +Image_TGA_save("Pictures/aaaa_new_scale_simple.tga", dst, 0); + +Image_DeAllocate(dst); free(dst); +Image_DeAllocate(src); free(src); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + */ +int +Test_copie_de_rectangles(char *nomsource) +{ +Image_Desc *source, *image, *finale; +int foo, w, h, x, y; +Image_Rect rect; +char *cptr; + +printf("======= test des copies de rectangles ========\n"); + +source = Image_TGA_alloc_load(nomsource); +if (NULL==source) { + fprintf(stderr, "fail on '%s'\n", nomsource); + return -1; + } +printf("'%s' loaded : %dx%d\n", nomsource, source->width, source->height); + +cptr = "wou.tga"; +image = Image_TGA_alloc_load(cptr); +if (NULL==image) { + fprintf(stderr, "fail on '%s'\n", cptr); + Image_DeAllocate(source); free(source); + return -1; + } + +finale = Image_clone(source, 1); +rect.x = 50; rect.y = 50; +rect.h = 100; rect.w = 160; +foo = Image_copy_rect(image, &rect, finale, 10, 10); +Image_print_error("Image copy rect", foo); + +Image_TGA_save("Pictures/aaaa_copyrect.tga", finale, 0); +Image_DeAllocate(image); free(image); + +/* essai de la fonction 'Image_overlay' */ +w = source->width / 4; +h = source->height / 4; + +image = Image_alloc(w, h, 3); +Image_pattern_000(image, 0x55); +Image_copy(source, finale); +/* orly bad code here */ +for (x=-w; x<=w; x+=w) + { + for (y=-h; y<=h; y+=h) + { + fprintf(stderr, " *** overlaying to %d, %d\n", x, y); + foo = Image_overlay(source, finale, x, 10); + Image_print_error("Image overlay", foo); + } + } +Image_TGA_save("Pictures/aaaa_overlay.tga", finale, 0); + +Image_copy(source, finale); +foo = Image_overlay_mix(source, finale, 30, 40, 5000); +Image_TGA_save("Pictures/aaaa_overlay_mix.tga", finale, 0); + +Image_DeAllocate(image); free(image); +Image_DeAllocate(source); free(source); +Image_DeAllocate(finale); free(finale); + +return 0; +} +/*::------------------------------------------------------------------::*/ +int +Test_Egalisations(char *nomsource, int k) +{ +Image_Desc *image, *deuxieme, *troisieme; +int x, y; + +fprintf(stderr, "============= Egalisations %s %d =====\n", nomsource, k); + +image= Image_TGA_alloc_load(nomsource); +printf("image loaded %p\n", image); + +deuxieme = Image_clone(image, 0); +printf("image 2 cloned %p\n", deuxieme); +Image_egalise_mono_0(image, deuxieme, 0); + +troisieme = Image_clone(image, 0); +printf("image 3 cloned %p\n", troisieme); +Image_egalise_RGB(image, troisieme, 0); + +for (x=0; xwidth; x++) + { + if (x < image->width/3) + { + for (y=0; yheight; y++) + Image_pixel_copy(image, x, y, troisieme, x, y); + } + else + if (x > image->width/3*2) + { + for (y=0; yheight; y++) + Image_pixel_copy(deuxieme, x, y, troisieme, x, y); + } + +#if DEBUG_LEVEL > 2 + printf("%4d\r", x); fflush(stdout); +#endif + } + +printf("saving resultat...\n"); +Image_marque_1(troisieme, "Egalisations", 0); +Image_TGA_save("Pictures/aaaa_egal.tga", troisieme, 0); +Image_DeAllocate(image); free(image); +Image_DeAllocate(deuxieme); free(deuxieme); +Image_DeAllocate(troisieme); free(troisieme); + +return 42; +} +/*::------------------------------------------------------------------::*/ +int +Test_Dithering(char *nomsource, int k) +{ +Image_Desc *source, *image, *deuxieme, *finale; +Image_Rect rect; +int foo; +int x2, y2; +RGBA ink, pap; + +fprintf(stderr, "========== Dithering on %s (%d) =======\n", nomsource, k); + +source = Image_TGA_alloc_load(nomsource); +if (NULL == source) + { + fprintf(stderr, "%s:%s err load %s\n", __FILE__, __func__, nomsource); + exit(5); + } +Image_dump_descriptor(source, "just after load"); + +/* + * est-ce bien necessaire ? + */ +/* Image_egalise_RGB(source, source, 0); */ + +x2 = source->width / 2; y2 = source->height / 2; +rect.w = x2; rect.h = y2; +rect.x = 0; rect.y = 0; + +ink.r = 255, ink.g = 255, ink.b = 100; ink.a = 255; +pap.r = 30, pap.g = 30, pap.b = 155; pap.a = 255; + +finale = Image_alloc(source->width, (source->height)*3, 3); +if (NULL == finale) + { + fprintf(stderr, "%s:%s:%d err alloc image\n", + __FILE__, __func__, __LINE__); + exit(5); + } +printf("image finale allocated %p\n", finale); + +image = Image_MakeHalfSize(source, 0); +if (NULL == image) + { + fprintf(stderr, "%s:%s:%d err halfsize image\n", + __FILE__, __func__, __LINE__); + exit(5); + } + +printf("image Half -> %p\n", image); + +Image_DeAllocate(source); free(source); +Image_copy_rect(image, &rect, finale, 0, 0); + +deuxieme = Image_clone(image, 0); +printf("image 2 cloned %p\n\n", deuxieme); + +foo = Image_dither_Bayer_0(image, deuxieme, 255); +printf("retour Dither_Bayer_0 = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, x2, 0); +Image_txt1_box_0(finale, "Dither_Bayer_0", x2, 0, 4, &pap, &ink, 0); + +foo = Image_dither_seuil_random(image, deuxieme, 255); +printf("retour Seuil_Random = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, x2, y2); +Image_txt1_box_0(finale, "Seuil_Random", x2, y2, 4, &pap, &ink, 0); + +foo = Image_dither_simple_error(image, deuxieme, 255); +printf("retour Dither_SimpleError = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, 0, y2); +Image_txt1_box_0(finale, "Simple_Error", 0, y2, 4, &pap, &ink, 0); + +foo = Image_dither_double_seuil(image, deuxieme, 100, 200, 255); +printf("retour Dither_DoubleSeuil = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, 0, y2*2); +Image_txt1_box_0(finale, "DoubleSeuil", 0, y2*2, 4, &pap, &ink, 0); + +foo = Image_dither_3x3_0(image, deuxieme, 127); +printf("retour Dither_3x3_0 = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, x2, y2*2); +Image_txt1_box_0(finale, "3x3 0", x2, y2*2, 4, &pap, &ink, 0); + +foo = Image_dither_3x3_1(image, deuxieme, 255); +printf("retour Dither_3x3_1 = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, 0, y2*3); +Image_txt1_box_0(finale, "3x3 1", 0, y2*3, 4, &pap, &ink, 0); + +foo = Image_dither_3x3_2(image, deuxieme, 127); +printf("retour Dither_3x3_2 = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, x2, y2*3); +Image_txt1_box_0(finale, "3x3 2", x2, y2*3, 4, &pap, &ink, 0); + +foo = Image_dither_bayer8x8rnd(image, deuxieme, 5000, 0); +printf("retour Dither bayer8x8rnd = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, x2, y2*4); +Image_txt1_box_0(finale, "bayer 8x8 rnd rgb", x2, y2*4, 4, &pap, &ink, 0); + +foo = Image_dither_bayer8x8rnd(image, deuxieme, 5000, 1); +printf("retour Dither bayer8x8rnd = %d\n", foo); +Image_copy_rect(deuxieme, &rect, finale, 0, y2*4); +Image_txt1_box_0(finale, "bayer 8x8 rnd grey", 0, y2*4, 4, &pap, &ink, 0); + +Image_TGA_save("Pictures/aaaa_dithering.tga", finale, 0); +Image_DeAllocate(image); free(image); +Image_DeAllocate(deuxieme); free(deuxieme); +Image_DeAllocate(finale); free(finale); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * test des marquages + */ +int Test_des_marquages(char *srname, int k1, int k2) +{ + +/* + * please insert useless code here + */ + +return -1; +} +/*::------------------------------------------------------------------::*/ +/* new 21 juillet 2007 - ave St Exupery */ +int +Test_Effects_A(char *nomsource, int flag) +{ +Image_Desc *source, *image, *deuxieme, *finale; +int foo; +int x, y, x2, y2; +RGBA ink, pap; + +printf("=== %s %s === %s === %d ===\n", __FILE__, __func__, nomsource, flag); + +if (flag) + { + fprintf(stderr, "%s: flag is %d ?\n", __func__, flag); + } + +ink.r = 255, ink.g = 255, ink.b = 100; ink.a = 255; +pap.r = 30, pap.g = 30, pap.b = 155; pap.a = 255; + +source = Image_TGA_alloc_load(nomsource); +if (NULL==source) + { + fprintf(stderr, "%s : il manque '%s'\n", __func__, nomsource); + exit(1); + } +printf("test effect (%d): image loaded %p\n", flag, source); +/* + * est-ce bien necessaire ? + */ +/* non Image_egalise_RGB(source, source, 0); XXX */ + +x2 = source->width / 2; y2 = source->height / 2; + +finale = Image_clone(source, 0); +printf("image finale cloned %p\n", finale); +image = Image_MakeHalfSize(source, 0); +Image_DeAllocate(source); free(source); + +deuxieme = Image_clone(image, 0); +printf("image 2 cloned %p\n\n", deuxieme); + + /* first shoot */ +foo = Image_water(image, deuxieme, 15); +if (foo) fprintf(stderr, "water -> %d\n", foo); +for (x=0; x %d\n", foo); } +foo = Image_filtre_Prewitt(src, dst, 5); +Image_TGA_save("Pictures/filtre-prewitt-5.tga", dst, 0); +foo = Image_filtre_passe_haut(src, dst); +Image_TGA_save("Pictures/filtre-passe-haut.tga", dst, 0); +foo = Image_filtre_Sobel_4(src, dst, 0); +Image_TGA_save("Pictures/filtre-sobel-4.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + +return 42; +} +/*::------------------------------------------------------------------::*/ +/* + * the parameter 'prefix' will be prepended to the generated filenames. + * you can use somthing like "Pictures/foo" + */ +void Test_des_patterns(char *prefix, int foo, int bar) +{ +Image_Desc *image; +char filename[1000]; +int retc; + +printf("============ test des patterns ================\n"); +printf("%s:%s: prefix [%s], foo %d, bar %d\n", + __FILE__, __func__, prefix, foo, bar); + +image = Image_alloc(320, 200, 3); + +strcpy(filename, prefix); strcat(filename, "_000.tga"); +fprintf(stderr, "--> %s\n", filename); +retc = Image_pattern_000(image, 100); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +strcpy(filename, prefix); strcat(filename, "_001.tga"); +fprintf(stderr, "--> %s\n", filename); +retc = Image_pattern_001(image, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +strcpy(filename, prefix); strcat(filename, "_002.tga"); +fprintf(stderr, "--> %s\n", filename); +retc = Image_pattern_002(image, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +strcpy(filename, prefix); strcat(filename, "_005.tga"); +fprintf(stderr, "--> %s\n", filename); +retc = Image_pattern_005(image, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +strcpy(filename, prefix); strcat(filename, "_042.tga"); +fprintf(stderr, "--> %s\n", filename); +retc = Image_pattern_042(image, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +fprintf(stderr, "===== %s : la serie des 10x ====\n", __func__); + +strcpy(filename, prefix); strcat(filename, "_100.tga"); +retc = Image_pattern_100(image, 0, 0, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); + +strcpy(filename, prefix); strcat(filename, "_101.tga"); +retc = Image_pattern_101(image, 0, 0, 0); +Image_print_error(filename, retc); +Image_TGA_save(filename, image, 0); +} +/*::------------------------------------------------------------------::*/ +/* test des pixelizzzations - 14 octobre 2007 - avenue Sy Exupery + * + */ +int Test_des_pixeliz(char *srcname, int flags) +{ +Image_Desc *src, *dst; +int foo; + +printf("\nPIXELIZ flags= $%04x\n", flags); +src = Image_TGA_alloc_load(srcname); +printf("test pixeliz: image loaded %p\n", src); +dst = Image_clone(src, 0); +printf("test pixeliz: clone @ %p\n", dst); + +foo = Image_pixeliz_X(src, dst); +printf("test pixeliz: X %d\n", foo); +Image_TGA_save("Pictures/aaaa_pixelX.tga", dst, 0); + +foo = Image_pixeliz_Y(src, dst); +printf("test pixeliz: Y %d\n", foo); +Image_TGA_save("Pictures/aaaa_pixelY.tga", dst, 0); + +Image_DeAllocate(src); free(src); +Image_DeAllocate(dst); free(dst); + + +return -1; +} +/*::------------------------------------------------------------------::*/ diff --git a/essais.h b/essais.h new file mode 100644 index 0000000..ea9bf24 --- /dev/null +++ b/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/filtadapt.c b/filtadapt.c new file mode 100644 index 0000000..1669a26 --- /dev/null +++ b/filtadapt.c @@ -0,0 +1,93 @@ +/* + * essais de filtres adaptatifs + * ---------------------------- + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_filtadapt_0(Image_Desc *src, Image_Desc *dst, int param) +{ +int x, y, foo; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +for (y=1; yheight-1; y++) { + for (x=1; xwidth-1; x++) { + Image_getRGB(src, x, y, &r, &g, &b); + + /* ICI IL MANQUE DU CODE */ + + Image_plotRGB(dst, x, y, r, g, b); + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int +Image_filtadapt_1(Image_Desc *src, Image_Desc *dst, int param) +{ +int x, y, foo; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +for (y=1; yheight-1; y++) { + for (x=1; xwidth-1; x++) { + Image_getRGB(src, x, y, &r, &g, &b); + + /* ICI IL MANQUE DU CODE */ + + Image_plotRGB(dst, x, y, r, g, b); + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int +Image_filtadapt_2(Image_Desc *src, Image_Desc *dst, int param) +{ +int foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Filtre adapt 2: images are differents %d\n", foo); + return foo; + } + +fprintf(stderr, "%s:%d missing code for '%s'\n", __FILE__, __LINE__, __func__); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int +Image_filtadapt_3(Image_Desc *src, Image_Desc *dst, int param) +{ +int x, y, foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Filtre adapt 3: images are differents %d\n", foo); + return foo; + } + +fprintf(stderr, "%s:%d missing code for '%s'\n", __FILE__, __LINE__, __func__); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/filtres.c b/filtres.c new file mode 100644 index 0000000..d9a75bb --- /dev/null +++ b/filtres.c @@ -0,0 +1,467 @@ +/* + filtrages sur les images + ------------------------ +*/ + +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +void +Image_filtre_display(FILE *ou, int *mat) +{ +int cumul, foo; + +for (cumul=foo=0; foo<9; foo++) cumul+=mat[foo]; + +fprintf(ou, "\t+------ Filtre ------+----- Coefs ------+\n"); +fprintf(ou, "\t| %4d %4d %4d | divisor: %4d |\n", + mat[0], mat[1], mat[2], mat[9]); +fprintf(ou, "\t| %4d %4d %4d | offset: %4d |\n", + mat[3], mat[4], mat[5], mat[10]); +fprintf(ou, "\t| %4d %4d %4d | cumul: %4d |\n", + mat[6], mat[7], mat[8], cumul); +fprintf(ou, "\t+--------------------+------------------+\n"); + +fflush(ou); +} +/*::------------------------------------------------------------------::*/ +void +Image_rotate_filtre(int *m) +{ +register int foo; + +foo = m[0]; +m[0] = m[3]; +m[3] = m[6]; +m[6] = m[7]; +m[7] = m[8]; +m[8] = m[5]; +m[5] = m[2]; +m[2] = m[1]; +m[1] = foo; +} +/*::------------------------------------------------------------------::*/ +int +Image_convolueur3(Image_Desc *in, Image_Desc *out, int *mat) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "warning: %s is (maybe) obsolete\n", __func__); +#endif +foo = Image_convolueur_2(in, out, mat, "rgb"); + +return foo; +} +/*::------------------------------------------------------------------::*/ +int +Image_convolueur_2(Image_Desc *in, Image_Desc *out, int *mat, char *planes) +{ +int foo, x, y; +long lval; +int masque = 0; + +if (in == out) + { + fprintf(stderr, "convolueur 2: out overwrite in.\n"); + return IMG_OVERWRITE; + } + +if ( (foo=Image_compare_desc(in, out)) ) + { + fprintf(stderr, "Convolueur: images are differents %d\n", foo); + return foo; + } + +#if DEBUG_LEVEL > 1 +Image_dump_descriptor(in, "image d'entree convolueur"); +Image_dump_descriptor(out, "image de sortie convolueur"); +#endif + +#if DEBUG_LEVEL > 2 +Image_filtre_display(stdout, mat); +#endif + +if (mat[9] == 0) + { + fprintf(stderr, "Convolueur: fuck, divisor is ZERO !\n"); + /* + ! c'est sur, avec un message comme c,a je vais pas + ! pouvoir transmettre mon code aux australiens + ! parfois, ils sont tres cons, les australiens :) + */ + return DIVISOR_IS_ZERO; + } + +/* + * preparation of the binary mask from the parameter string + */ +for (foo=0; foo<(int)strlen(planes); foo++) + { + switch (planes[foo]) + { + case 'r': case 'R': + masque |= 8; + break; + case 'g': case 'G': + masque |= 4; + break; + case 'b': case 'B': + masque |= 2; + break; + case 'a': case 'A': + masque |= 1; + break; + } + } + +#if DEBUG_LEVEL > 1 +printf("masque convolueur = %02x\n", masque); +#endif + +if ( (masque & 1) && (in->Apix == NULL) ) + { + fprintf(stderr, "Convolueur2: filtering NULL alpha plane is _bad_\n"); + return WRONG_CHANNEL; + } + +for (y=1; y<((in->height)-1); y++) + { + for (x=1; x<((in->width)-1); x++) + { + if (masque & 8) + { + lval = mat[0] * in->Rpix[y-1][x-1] + + mat[1] * in->Rpix[y-1][x] + + mat[2] * in->Rpix[y-1][x+1] + + mat[3] * in->Rpix[y] [x-1] + + mat[4] * in->Rpix[y] [x] + + mat[5] * in->Rpix[y] [x+1] + + mat[6] * in->Rpix[y+1][x-1] + + mat[7] * in->Rpix[y+1][x] + + mat[8] * in->Rpix[y+1][x+1] ; + + lval = (lval / mat[9]) + mat[10]; + if (lval > 255) lval = 255; + else if (lval < 0) lval = 0; + out->Rpix[y][x] = (uint8_t)lval; + } + + if (masque & 4) + { + lval = mat[0] * in->Gpix[y-1][x-1] + + mat[1] * in->Gpix[y-1][x] + + mat[2] * in->Gpix[y-1][x+1] + + mat[3] * in->Gpix[y] [x-1] + + mat[4] * in->Gpix[y] [x] + + mat[5] * in->Gpix[y] [x+1] + + mat[6] * in->Gpix[y+1][x-1] + + mat[7] * in->Gpix[y+1][x] + + mat[8] * in->Gpix[y+1][x+1] ; + + lval = (lval / mat[9]) + mat[10]; + if (lval > 255) lval = 255; + else if (lval < 0) lval = 0; + out->Gpix[y][x] = (uint8_t)lval; + } + + if (masque & 2) + { + lval = mat[0] * in->Bpix[y-1][x-1] + + mat[1] * in->Bpix[y-1][x] + + mat[2] * in->Bpix[y-1][x+1] + + mat[3] * in->Bpix[y] [x-1] + + mat[4] * in->Bpix[y] [x] + + mat[5] * in->Bpix[y] [x+1] + + mat[6] * in->Bpix[y+1][x-1] + + mat[7] * in->Bpix[y+1][x] + + mat[8] * in->Bpix[y+1][x+1] ; + + lval = (lval / mat[9]) + mat[10]; + if (lval > 255) lval = 255; + else if (lval < 0) lval = 0; + out->Bpix[y][x] = (uint8_t)lval; + } + + if (masque & 1) + { + lval = mat[0] * in->Apix[y-1][x-1] + + mat[1] * in->Apix[y-1][x] + + mat[2] * in->Apix[y-1][x+1] + + mat[3] * in->Apix[y] [x-1] + + mat[4] * in->Apix[y] [x] + + mat[5] * in->Apix[y] [x+1] + + mat[6] * in->Apix[y+1][x-1] + + mat[7] * in->Apix[y+1][x] + + mat[8] * in->Apix[y+1][x+1] ; + + lval = (lval / mat[9]) + mat[10]; + if (lval > 255) lval = 255; + else if (lval < 0) lval = 0; + out->Apix[y][x] = (uint8_t)lval; + } + } + } + +out->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_raz_sides(Image_Desc *im) +{ +int foo; + +for (foo=0; foowidth; foo++) + { + (im->Rpix[0])[foo] = 0; + (im->Gpix[0])[foo] = 0; + (im->Bpix[0])[foo] = 0; + (im->Rpix[im->height-1])[foo] = 0; + (im->Gpix[im->height-1])[foo] = 0; + (im->Bpix[im->height-1])[foo] = 0; + } + +for (foo=0; fooheight; foo++) + { + (im->Rpix[foo])[0] = 0; + (im->Gpix[foo])[0] = 0; + (im->Bpix[foo])[0] = 0; + (im->Rpix[foo])[im->width-1] = 0; + (im->Gpix[foo])[im->width-1] = 0; + (im->Bpix[foo])[im->width-1] = 0; + } + +im->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * Arf, le grand classique :) + */ +int +Image_lissage_3x3(Image_Desc *in, Image_Desc *out) +{ +int foo, x, y; + +if (in == out) + { + fprintf(stderr, "Lissage 3x3: out overwrite in\n"); + return IMG_OVERWRITE; + } + +if ( (foo=Image_compare_desc(in, out)) ) + { + fprintf(stderr, "Lissage 3x3: images have differents size, %d\n", foo); + return foo; + } + +for (y=1; y<((in->height)-1); y++) + { + for (x=1; x<((in->width)-1); x++) + { + + foo = in->Rpix[y-1][x-1] + in->Rpix[y-1][x] + in->Rpix[y-1][x+1] + + in->Rpix[y] [x-1] + in->Rpix[y] [x] + in->Rpix[y] [x+1] + + in->Rpix[y+1][x-1] + in->Rpix[y+1][x] + in->Rpix[y+1][x+1] ; + out->Rpix[y][x] = (uint8_t)(foo / 9); + + foo = in->Gpix[y-1][x-1] + in->Gpix[y-1][x] + in->Gpix[y-1][x+1] + + in->Gpix[y] [x-1] + in->Gpix[y] [x] + in->Gpix[y] [x+1] + + in->Gpix[y+1][x-1] + in->Gpix[y+1][x] + in->Gpix[y+1][x+1] ; + out->Gpix[y][x] = (uint8_t)(foo / 9); + + foo = in->Bpix[y-1][x-1] + in->Bpix[y-1][x] + in->Bpix[y-1][x+1] + + in->Bpix[y] [x-1] + in->Bpix[y] [x] + in->Bpix[y] [x+1] + + in->Bpix[y+1][x-1] + in->Bpix[y+1][x] + in->Bpix[y+1][x+1] ; + out->Bpix[y][x] = (uint8_t)(foo / 9); + + } + } + +Image_raz_sides(out); +out->modified = 1; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * new 14 Jan 2000 + */ +int +Image_filtre_Prewitt(Image_Desc *src, Image_Desc *dst, int rotation) +{ +static int Prewitt[] = + { + 1, 1, 1, + 0, 0, 0, + -1, -1, -1, + 1, 128 + }; + +int filtre[11], foo; + +memcpy(filtre, Prewitt, 11*sizeof(int)); + +for (foo=0; foo +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* private variables */ + +/*::------------------------------------------------------------------::*/ +/* private functions */ + +/*::------------------------------------------------------------------::*/ +int Image_gadrct_premier_essai(Image_Desc *src, Image_Rect *rect, + Image_Desc *dst, int ka, int kb) +{ +int x, y, r, g, b; + +#if DEBUG_LEVEL +fprintf(stderr, "Oups, trapped in '%s'\n", __func__); +#endif + +for (x=0; xw; x++) + { + for (y=0; yh; y++) + { + r = g = b = x ^ y; + } + } +#if DEBUG_LEVEL +fprintf(stderr, "Yooo, back from '%s'\n", __func__); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_gadrct_Hsweep_0(Image_Desc *dst, Image_Rect *rect, int flag) +{ +int x, y, r, g, b, foo; +double val, adder; + +if (dst->magic != MAGIC_OF_IMAGE) + { + fprintf(stderr, "%s: need Dead Beef!\n", __func__); + return NOT_AN_IMAGE_DESC; + } + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Oups, trapped in '%s'\n", __func__); +#endif + +adder = 256.0 / (double)rect->w; +val = 0.0; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, " val=%f adder=%f\n", val, adder); +#endif + +for (x=0; xw; x++) + { + foo = (int)val; + r = g = b = foo; + for (y=0; yh; y++) + { + Image_plotRGB(dst, x+rect->x, y+rect->y, r, g, b); + } + val += adder; + } + + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Yoohoo, back from '%s'\n", __func__); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_gadrct_Vsweep_0(Image_Desc *dst, Image_Rect *rect, int flag) +{ +int x, y, r, g, b, foo; +double val, mult, adder; + +val = adder = 0; +for (x=0; xw; x++) + { + foo = (int)val; + r = g = b = foo; + for (y=0; yh; y++) + { + Image_plotRGB(dst, x+rect->x, y+rect->y, r, g, b); + } + val += adder; + } + + +#if DEBUG_LEVEL +fprintf(stderr, "Yooo, back from '%s'\n", __func__); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* + * attr,yion parametres bizarres + */ +int Image_gadrct_poke_from_tga(char *namesrc, Image_Rect *fromrect, + Image_Desc *dst, int xdst, int ydst, int flags) +{ +Image_Desc *source; +int foo, x, y, r, g, b; +int xs, ys; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : source is %s\n", __func__, namesrc); +#endif + +source = Image_TGA_alloc_load(namesrc); +if (NULL == source) + { + fprintf(stderr, "%s '%s' : FAIL !\n", __func__, namesrc); + return FULL_NUCKED; + } + +xs = fromrect->x; +ys = fromrect->y; + +#if DEBUG_LEVEL > 1 +Image_dump_descriptor(source, "image source poke_from_tga"); +Image_dump_rect(fromrect, "source fragment", 1); +#endif +#if DEBUG_LEVEL +fprintf(stderr, "%s : go to %d %d in %p\n", __func__, xdst, ydst, dst); +#endif + +for (y=0; yw; y++) + { + for (x=0; xh; x++) + { + Image_getRGB(source, x+xs, y+ys, &r, &g, &b); + Image_plotRGB(dst, x+xdst, y+ydst, r, g, b); + } + } + +Image_DeAllocate(source); free(source); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_gadrct_to_gray(Image_Desc *src, Image_Rect *rect, + Image_Desc *dst, int ka, int kb) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %p %d %d\n", __func__, src, rect, dst, ka, kb); +#endif + +if (dst->magic != MAGIC_OF_IMAGE) + { + fprintf(stderr, "%s: DST need Dead Beef!\n", __func__); + return NOT_AN_IMAGE_DESC; + } +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* assombrissement/eclaircissement d'un rectangle dans une image */ +int Image_gadrct_dimmer(Image_Desc *img, Image_Rect *rect, float dimf) +{ +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %f )\n", __func__, img, rect, dimf); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* new 2 decembre 2009 */ +/* first use in "plotteur.c|Image_plot_square_Map" */ + +int Image_gadrct_cross(Image_Desc *img, Image_Rect *rect, int k) +{ +RGBA rgba; +int x1, y1, x2, y2; + +rgba.r = rgba.g = rgba.b = 200; + +x1 = rect->x; y1 = rect->y; +x2 = rect->x + rect->w; +y2 = rect->y + rect->h; +Image_draw_line(img, x1, y1, x2, y2, &rgba); + +x1 = rect->x + rect->w; +y1 = rect->y; +x2 = rect->x; +y2 = rect->y + rect->h; +Image_draw_line(img, x1, y1, x2, y2, &rgba); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ diff --git a/gamma.c b/gamma.c new file mode 100644 index 0000000..1578849 --- /dev/null +++ b/gamma.c @@ -0,0 +1,36 @@ +/* + GAMMA CORRECTION + ---------------- +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * 4 Oct 2003: il serait _vraiment_ temps que je finisse de + * coder cette fonction. fouillage de documentation + * en vue pour la soirée... + */ +int +Image_gamma_calcul(double coef, int table[256]) +{ +int foo; +double a; + +#if DEBUG_LEVEL +fprintf(stderr, "%s: coef = %g\n", __func__, coef); +#endif + +for (foo=0; foo<256; foo++) + { + a = (double)foo; + + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ + +/*::------------------------------------------------------------------::*/ diff --git a/glitch.c b/glitch.c new file mode 100644 index 0000000..baf43f9 --- /dev/null +++ b/glitch.c @@ -0,0 +1,134 @@ +/* + * glitch.c - new sept 2014 - MYRYS + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int Image_GlitchMe(Image_Desc *src, Image_Desc *dst, char code, + int k1, char *txt1) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d '%s' )\n", __func__, src, dst, k1, txt1); +#endif + +switch (code) + { + case 'x' : + foo = Image_Glitch_xor(src, dst, k1); + break; + case 's' : + foo = Image_Glitch_simple(src, dst, k1); + break; + default : + abort(); + break; + } +#if DEBUG_LEVEL +fprintf(stderr, "%s -> %d\n", __func__, foo); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_Glitch_xor(Image_Desc *src, Image_Desc *dst, int k) +{ +int foo; +int nbre; +int x, y, d, v; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +for (nbre=0; nbrewidth; + y = rand() % src->height; + d = rand() & 3; + Image_getRGB(src, x, y, &r, &g, &b); + + switch (d) + { + case 0: + for (v=0; vwidth; v++) + Image_XOR_pixel(dst, v, y, r, g, b); + break; + case 3: + for (v=y; vheight; v++) + Image_XOR_pixel(dst, x, v, r, g, b); + break; + } + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * ok, 12 oct 2014 + */ +int Image_Glitch_simple(Image_Desc *src, Image_Desc *dst, int k) +{ +int foo; +int nbre; +int x, y, d, v; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +for (nbre=0; nbrewidth; + y = rand() % src->height; + d = rand() & 3; +#if 0 + printf("%6d %6d %6d %d\n", nbre, x, y, d); +#endif + Image_getRGB(src, x, y, &r, &g, &b); + + switch (d) + { + case 0: + for (v=0; vwidth; v++) + Image_plotRGB(dst, v, y, r, g, b); + break; + case 3: + for (v=y; vheight; v++) + Image_plotRGB(dst, x, v, r, g, b); + break; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/gray_ops.c b/gray_ops.c new file mode 100644 index 0000000..99c97db --- /dev/null +++ b/gray_ops.c @@ -0,0 +1,35 @@ +/* + * gray_ops.c + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int Image_gray_ops_0(Image_Desc *src, Image_Desc *dst, int k, int mask) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d 0x%x )\n", __func__, src, dst, k, mask); +#endif + +(void)src; (void)dst; (void)k; (void)mask; /* ANTI WARNING */ + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_gray_ops_1(Image_Desc *src, Image_Desc *dst, int k, int mask) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d 0x%x )\n", __func__, src, dst, k, mask); +#endif + +(void)src; (void)dst; (void)k; (void)mask; /* ANTI WARNING */ + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/image.c b/image.c index c1d07dc..5d59e08 100644 --- a/image.c +++ b/image.c @@ -483,6 +483,43 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height ) return (int)((img->Apix[y])[x]); } /*::------------------------------------------------------------------::*/ +/* + cette fonction ne marche que si les deux images + sont allouees et de meme dimensions. + */ +int +Image_copy(Image_Desc *src, Image_Desc *dst) +{ +int foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_Copy: images are differents %d\n", foo); + return foo; + } + +for (foo=0; fooheight; foo++) + { + memcpy(dst->Rpix[foo], src->Rpix[foo], src->width); + memcpy(dst->Gpix[foo], src->Gpix[foo], src->width); + memcpy(dst->Bpix[foo], src->Bpix[foo], src->width); + if (dst->Apix!=NULL && src->Apix!=NULL) + memcpy(dst->Apix[foo], src->Apix[foo], src->width); + } + +dst->modified = 1; +/* + >> 18 Juin 2002 + >> ============ + >> bon, maintenant se pose un grand problème philosophique. + >> on vient juste de copier les octets qui incarnent les pixels + >> rgb et peut-être alpha. Mais ce n'est que la partie évident + >> d'une image: ses pixels. + */ + +return 0; +} +/*::------------------------------------------------------------------::*/ /* * no boundary control ? */ @@ -533,7 +570,6 @@ return OLL_KORRECT; c'est qu'il reste un pointeur fou chez l'appelant ... */ - int Image_DeAllocate(Image_Desc *im) { diff --git a/imprime.c b/imprime.c new file mode 100644 index 0000000..8d7fae1 --- /dev/null +++ b/imprime.c @@ -0,0 +1,72 @@ +/* + imprime.c + --------- +*/ + +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_print_histo_0(long *histo, char *fname, char *texte) +{ +int foo; + +printf("** %s **\n", texte); + +for (foo=0; foo<256; foo++) + { + printf("%7ld ", histo[foo]); + if ((foo % 8)==0) + printf("\n"); + } +printf("\n"); + +return FULL_NUCKED; +} +/* + * je sais même plus pourquoi j'ai commencé cette fonction :) + */ +/*::------------------------------------------------------------------::*/ + +void Image_print_sizeof_structs(char *texte) +{ +unsigned short petit; +unsigned long grand; +unsigned char *ucptr; +int foo; + +if (NULL != texte) + { + printf("============= %s ============\n", texte); + } + +/* examen du boutisme (ah ah ah) */ +petit = 0x1234; printf("petit = %8x -> ", petit); +ucptr = (unsigned char *)&petit; +for (foo=0; foo<(int)sizeof(petit); foo++) + printf(" %02x", ucptr[foo]); +printf("\n"); + +/* trop kikoolol, le boutisme */ +grand = 0x12345678; +printf("grand = %lx -> ", grand); +ucptr = (unsigned char *)&grand; +for (foo=0; foo +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int Image_lut15_fill_0(int r[32768], int *g, int *b) +{ +int foo; + +for (foo=0; foo<32768; foo++) + { + r[foo] = foo; + g[foo] = 0; + b[foo] = 32768 - foo; + } +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int Image_lut15_fill_1(int *r, int *g, int *b) +{ +int foo; + +for (foo=0; foo<32768; foo++) + { + r[foo] = foo; + g[foo] = 12345; + b[foo] = 32768 - foo; + } +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +int Image_lut15_essai(char *hfname, char *tganame, int ka) +{ +Image_Desc *src, *dst; +int x, y, h; +int r, g, b; +int lr[32768]; +int lg[32768]; +int lb[32768]; + +#if DEBUG_LEVEL +fprintf(stderr, "'%s' : premier essai pour les LUTs en 15 bits\n", __func__); +fprintf(stderr, " image source : %s\n", hfname); +fprintf(stderr, " image resultat : %s\n", tganame); +fprintf(stderr, " dummy argument : %d\n", ka); +#endif + +if (ka) { + fprintf(stderr, "%s : ka (%d) not zero !\n", __func__, ka); + return WRONG_FLAG; + } + +if ( NULL==(src=Image_TGA_alloc_load(hfname)) ) + { + fprintf(stderr, "%s: err load %s, aborting\n", __func__, hfname); + abort(); + } + +/* convert the source image to an valid height-field */ +Image_hf15_rgb2hf(src, src, 0); + +/* save a 16 bits pgm for visual check */ +Image_hf15_save_PGM("aaaa-hf15-lut15.pgm", src, __FILE__); + +if ( NULL==(dst=Image_clone(src, 0)) ) + { + abort(); + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + h = Image_hf15_height(src, x, y); + r = lr[h] / 256; + g = lg[h] / 255; + b = lb[h] / 255; + Image_plotRGB(dst, x, y, r, g, b); + } + } + +Image_TGA_save(tganame, dst, 0); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ + + diff --git a/marques.c b/marques.c new file mode 100644 index 0000000..b1a170d --- /dev/null +++ b/marques.c @@ -0,0 +1,230 @@ +/* + marques.c + ________________ + Routines pour deposer des marques sur des images. + Nouveau: 12 Nov 2001. +*/ + +#include +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * dessine deux lignes grises sur les diagonales de l'image + */ +int +Image_marque_0(Image_Desc *img, int val) +{ +int foo; +RGBA rgba; + +rgba.r = rgba.g = rgba.b = val; +rgba.a = 0; /* goof value ? */ +foo = Image_draw_line(img, 0, 0, img->width-1, img->height-1, &rgba); +foo = Image_draw_line(img, 0, img->height-1, img->width-1, 0, &rgba); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * place un label dans le coin en haut à gauche de l'image. + */ +int +Image_marque_1(Image_Desc *img, char *texte, int flags) +{ +RGBA papier, encre; +int len; + +#if DEBUG_LEVEL +if (flags) + { + fprintf(stderr, "*** %s 'flags' must be ZERO ***\n", __func__); + } +#endif + +len = strlen(texte); +if (len < 1) return FULL_NUCKED; + +papier.r = 255; papier.g = 255; papier.b = 255; +encre.r = 220; encre.g = 100; encre.b = 20; +papier.a = encre.a = 255; + +Image_trace_chaine_1(img, texte, 2, 2, "8x8thin", &papier, &encre); +Image_trace_chaine_1(img, IMAGE_VERSION_STRING, 2, 11, "8x8thin", + &papier, &encre); +img->modified = 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ + +/* FORK OF : Image_marque_0 */ + +int +Image_marque_2(Image_Desc *img, char *txt, RGBA *rgba, int k1, int k2) +{ +int foo; + +fprintf(stderr, "%s : %p '%s' %p %d %d\n", __func__, img, txt, rgba, k1, k2); + +foo = Image_draw_line(img, 0, 0, img->width-1, img->height-1, rgba); +foo = Image_draw_line(img, 0, img->height-1, img->width-1, 0, rgba); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * Marquage avec la date et l'heure. + * utilisation des flags: + * bit 0: trace le cadre + */ +int +Image_marque_timestamp(Image_Desc *img, char *texte, RGBA *rgba, int flags) +{ +RGBA papier, encre; +int foo, l1, l2; +time_t temps; +char *ptr; +Image_Rect rect; + +if (NULL==texte) + { + texte = ""; + fprintf(stderr, "%s : using default text : '%s'\n", __func__, texte); + } + +l1 = strlen(texte); +temps = time(NULL); ptr = ctime(&temps); +l2 = strlen(ptr)-1; +if (l2 >= 0) + ptr[l2] = '\0'; + +foo = (l1>l2) ? l1 : l2; + +#if DEBUG_LEVEL +fprintf(stderr, "%s: L=%d T=%ld\n", __func__, foo, temps); +fprintf(stderr, "%s: '%s' %s\n", __func__, texte, ptr); +#endif + +papier.r = papier.g = papier.b = papier.a = 0; +if (rgba == NULL) + { + encre.r = encre.g = encre.b = 90, encre.a = 255; + rgba = &encre; + } + +if (flags & 1) + { + rect.x = rect.y = 3; + rect.h = 11; rect.w = l1*8+2; + Image_paint_rect(img, &rect, 255, 255, 255); + } +Image_trace_chaine_1(img, texte, 5, 6, "libimage.fonte", &papier, rgba); + +if (flags & 1) + { + rect.x = 3; rect.y = 16; + rect.h = 11; rect.w = l2*8+2; + Image_paint_rect(img, &rect, 255, 255, 255); + } + +Image_trace_chaine_1(img, ptr, 5, 18, NULL, &papier, rgba); + +#if DEBUG_LEVEL +fprintf(stderr, "done %s\n", __func__); +#endif + +img->modified = 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * Pour centrer la grille, il faut jouer sur 'ox' et 'oy' ? + */ +int +Image_grille(Image_Desc *im, int stx, int ox, int sty, int oy, RGBA *ink) +{ +int x, y, foo; +RGBA encre; + +/* avoid an infinite loop */ +if ( (stx<1) || (sty<1) ) { + fprintf(stderr, "%s : steps must be > 0\n", __func__); + return BAD_PARAMETER; + } + +if (ink == NULL) { + fprintf(stderr, "%s is using default color values\n", __func__); + encre.r = encre.g = encre.b = encre.a = 0; + ink = &encre; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s X: %d %d Y: %d %d\n", __func__, ox, stx, oy, sty); +#endif + +for (x=ox; xwidth; x+=stx) + { + for (foo=0; fooheight; foo++) + Image_plotRGB(im, x, foo, ink->r, ink->g, ink->b); + } + +for (y=oy; yheight; y+=sty) + { + for (foo=0; foowidth; foo++) + { + Image_plotRGB(im, foo, y, ink->r, ink->g, ink->b); + } + } + +im->modified = 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * Pour centrer la grille, il faut jouer sur 'ox' et 'oy' ? + */ +int +Image_grille_xor(Image_Desc *im, int stx, int ox, int sty, int oy, RGBA *ink) +{ +int x, y, foo; +RGBA encre; + +if (ink == NULL) + { + fprintf(stderr, "%s is using default XOR values\n", __func__); + encre.r = encre.g = encre.b = encre.a = 0xff; + ink = &encre; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s X %d %d Y %d %d\n", __func__, ox, stx, oy, sty); +#endif + +for (x=ox; xwidth; x+=stx) + { + for (foo=0; fooheight; foo++) + { + Image_XOR_pixel(im, x, foo, ink->r, ink->g, ink->b); + } + } + +for (y=oy; yheight; y+=sty) + { + for (foo=0; foowidth; foo++) + { + Image_XOR_pixel(im, foo, y, ink->r, ink->g, ink->b); + } + } + +im->modified = 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ + diff --git a/mircol.c b/mircol.c new file mode 100644 index 0000000..cb7d229 --- /dev/null +++ b/mircol.c @@ -0,0 +1,321 @@ +/* + * mircol.c + * ======== + */ + +#include +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_mircol_0(Image_Desc *dst, char *txt, int flag) +{ +int x, y; +RGBA fond, encre; + +if (dst->width < 512 || dst->height < 512) + { + fprintf(stderr, "Image mircol 0: image %p < 512x512\n", dst); + return IMAGE_TOO_SMALL; + } + +if (0 != flag) + { + fprintf(stderr, "%s -> flag is %d and must be 0\n", __func__, flag); + } +if (NULL != txt) + { + fprintf(stderr, "%s : txt is '%s'\n", __func__, txt); + } + +for (x=0; x<256; x++) + { + for (y=0; y<256; y++) + { + Image_plotRGB(dst, x, y, x, y, 0); + Image_plotRGB(dst, x+256, y, x, 0, y); + Image_plotRGB(dst, x, y+256, 0, x, y); + } + } + +for (x=0; x<256; x++) + for (y=300; y<342; y++) + Image_plotRGB(dst, x+256, y, x, x, x); + +fond.r = 0; fond.g = 0; fond.b = 0; fond.a = 255; +encre.r = 220; encre.g = 255; encre.b = 255; encre.a = 255; + +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", + &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); + +for (x=1; x<256; x++) + for (y=420; y<462; y++) + Image_plotRGB(dst, x+256, y, + rand()%x, rand()%x, rand()%x); + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* a quoi sert ce flag */ +int +Image_mircol_1(Image_Desc *dst, char *txt, int flag) +{ +RGBA fond, encre; +int x, y, r, g, b; + +if (dst->width < 512 || dst->height < 512) + { + fprintf(stderr, "Image mircol 1: image %p < 512x512\n", dst); + return IMAGE_TOO_SMALL; + } + +for (x=0; x<512; x++) + { + for (y=0; y<512; y++) + { + r = x; + g = (x + y) / 2; + b = y; + Image_plotRGB(dst, x, y, r, g, b); + } + } + +fond.r = 0; fond.g = 0; fond.b = 0; fond.a = 255; +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, IMAGE_VERSION_STRING, 270, 390, NULL, &fond, &encre); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* new 31 aout 2009 - ave StEx */ +/* 5 fev 2010 : hacked for "BETA tech" */ +int Image_mircol_2(Image_Desc *dst, char *txt, int mode) +{ +int x, y, r, g, b, kx, ky; +float fx, fy, fd; + +#if DEBUG_LEVEL +fprintf(stderr, ">>>> %s ( %p '%s' %d )\n", __func__, dst, txt, mode); +#endif + +for (y=0; yheight; y++) + { + fy = (float)y / (float)dst->height; + ky = (int)(fy * 256.0); + for (x=0; xwidth; x++) + { + fx = (float)x / (float)dst->width; + kx = (int)(fx * 256.0); + r = kx; + g = ky; + fd = sqrt((fx*fx)+(fy*fy)); + b = (int)(fd * 256.0); +#if DEBUG_LEVEL > 1 + if (x==y) + printf("%4d %4d %7.3f %7.3f %f\n", + x, y, fx, fy, fd); +#endif + Image_plotRGB(dst, x, y, r, g, b); + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 6 fevrier 2010 */ +int Image_mircol_3(Image_Desc *dst, char *txt, int mode) +{ +int x, y, r, g, b; +int *p1, *p2, *p3; +float fx, fx2, fy, dist; +float mystk; + +#if DEBUG_LEVEL +fprintf(stderr, ">>>> %s ( %p '%s' %d )\n", __func__, dst, txt, mode); +#endif + +switch (mode) { + case 0: p1 = &r, p2 = &g, p3 = &b; break; + case 1: p1 = &g, p2 = &b, p3 = &r; break; + case 2: p1 = &b, p2 = &r, p3 = &g; break; + + default: + fprintf(stderr, "switch/case error in %s:%d\n", + __func__, __LINE__); +#if FORCE_ABORT + abort(); +#endif + break; + } + +mystk = 0.90; /* FIXME */ + +for (y=0; yheight; y++) + { + fy = (float)y / (float)dst->height; + for (x=0; xwidth; x++) + { + fx = (float)x / (float)dst->width; + + *p1 = (int)((fx*fy) * 255); + *p2 = (int)(((1.0-fx)*fy) * 255); + + fx2 = fx - 0.5; + dist = sqrt((fx2*fx2)+(fy*fy)) * 255.0 * mystk; + + *p3 = (int)(256.0-dist); + +#if DEBUG_LEVEL + if ((dst->width < 42)&&(dst->height < 42)) + printf("%3d %3d %3d %3d %3d\n", x, y, r, g, b); +#endif + + /* XXX Image_plotRGB(dst, x, y, r, g, b); */ + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s : verifier le resultat, svp.\n", __func__); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* nouveau 10 fevrier 2010 */ +int Image_mircol_4(Image_Desc *dst, char *txt, int mode) +{ +int x, y, r, g, b; +int *p1, *p2, *p3; +float fx, fx2, fy, dist; + +#if DEBUG_LEVEL +fprintf(stderr, ">>>> %s ( %p '%s' %d )\n", __func__, dst, txt, mode); +#endif + +switch (mode) + { + case 0: p1 = &r, p2 = &g, p3 = &b; break; + case 1: p1 = &g, p2 = &b, p3 = &r; break; + case 2: p1 = &b, p2 = &r, p3 = &g; break; + + default: + fprintf(stderr, "switch/case error in %s:%d\n", + __func__, __LINE__); + abort(); + break; + } + +for (y=0; yheight; y++) + { + fy = (float)y / (float)dst->height; + for (x=0; xwidth; x++) + { + fx = (float)x / (float)dst->width; + /* FIXME TODO */ + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int Image_mirRGB_0(Image_Desc *dst, int flag) +{ +int x, y; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p %d\n", __func__, dst, flag); +#endif + +if (dst->width != 256 || dst->height != 256) + { + fprintf(stderr, "Image mire RGB 0: image is not 256x256\n"); + return IMAGE_BAD_DIMS; + } + +for (x=0; x<256; x++) + { + for (y=0; y<256; y++) + { + (dst->Rpix[y])[x] = x; + (dst->Gpix[y])[x] = y; + (dst->Bpix[y])[x] = (y+x)/2; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* le bit 0 du flag controle l'ecriture des noms de composantes */ +int +Image_decompose(Image_Desc *src, Image_Desc *dst, int flag) +{ +int foo, x, y, hx, hy; +Image_Desc *moitie; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: bad dimensions %d\n", __func__, foo); + return foo; + } + +moitie = Image_MakeHalfSize(src, 1); +if (moitie == NULL) + { + fprintf(stderr, "Image Decompose: NO MEM\n"); + exit(5); + } + +if (0 != flag) + fprintf(stderr, "%s : flag is 0x%X\n", __func__, flag); + +hx = moitie->width; +hy = moitie->height; + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + Image_getRGB(moitie, x, y, &r, &g, &b); + Image_plotRGB(dst, x, y, r, r, r); + Image_plotRGB(dst, x+hx, y, g, g, g); + Image_plotRGB(dst, x, y+hy, b, b, b); + Image_plotRGB(dst, x+hx, y+hy, r, g, b); + } + } + +/* faire le menage */ +Image_DeAllocate(moitie); free(moitie); + +if (flag & 1) + { + RGBA ink, pap; /* hu ho ? local vars here ? */ + Image_load_fnt8x8("libimage.fonte", NULL, 0); + pap.a = 0; ink.a = 255; + ink.r = 255; ink.b = 0; ink.g = 0; + Image_trace_chaine_1(dst, "RED", 2, 2, NULL, &pap, &ink); + ink.r = 0; ink.g = 255; ink.b = 0; + Image_trace_chaine_1(dst, "GREEN", 2+hx, 2, NULL, &pap, &ink); + ink.r = 10; ink.g = 10; ink.b = 255; + Image_trace_chaine_1(dst, "BLUE", 2, 2+hy, NULL, &pap, &ink); + } + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ diff --git a/msglib.c b/msglib.c new file mode 100644 index 0000000..6d37aea --- /dev/null +++ b/msglib.c @@ -0,0 +1,148 @@ +/* + conversion of numeric codes to text messages + -------------------------------------------- +*/ + +#include +#include /* for abort() */ +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +char * +Image_type2str(int type) +{ +char *pstr; + +switch (type) + { + case IMAGE_RGB: pstr = "RGB"; break; + case IMAGE_RGBA: pstr = "RGBA"; break; + case IMAGE_GRAY: pstr = "Gray"; break; + case IMAGE_PAL: pstr = "Palet"; break; + case IMAGE_NONE: pstr = "(none)"; break; + case IMAGE_ALPHA: pstr = "alpha"; break; + case IMAGE_PORTNAWAK: pstr = "portnawak"; break; + default: pstr = "Uh?"; break; + } + +return pstr; +} +/*::------------------------------------------------------------------::*/ +char * +Image_err2str(int codeerr) +{ +char *pstr; +static char chaine[100]; + +switch (codeerr) + { + case -1: pstr = "error: invalid error"; break; + case OLL_KORRECT: pstr = "no error"; break; + case 42: pstr = "Universal answer"; break; + case 406: pstr = "Mort de Peur :)"; break; + case 666: pstr = "The devil is coming"; break; + + case DIFFERENT_WIDTH: pstr = "different width"; break; + case DIFFERENT_HEIGHT: pstr = "different height"; break; + case NOT_AN_IMAGE_DESC: pstr = "not an image desc"; break; + case IMAGE_NO_MEM: pstr = "no mem for image"; break; + case IMAGE_TOO_SMALL: pstr = "image too small"; break; + case UNKNOW_ERROR: pstr = "unknow error"; break; + case STRING_ERROR: pstr = "string error"; break; + case IMAGE_BAD_TYPE: pstr = "image bad type"; break; + case STRING_TOO_LONG: pstr = "string too long"; break; + case NULL_DESCRIPTOR: pstr = "null descriptor"; break; + case VERY_STRANGE: pstr = "very strange error"; break; + case DIVISOR_IS_ZERO: pstr = "zero divide, reboot universe"; break; + case FULL_NUCKED: pstr = "...ahem, yu'r nucked"; break; + case BUFFER_NO_MEM: pstr = "no memory for buffer"; break; + case FILE_NOT_FOUND: pstr = "file not found"; break; + case OUT_OF_IMAGE: pstr = "out of image"; break; + case WRONG_CHANNEL: pstr = "wrong channel"; break; + case BAD_COLOR_NUMBER: pstr = "bad color number"; break; + case MAP_TOO_BIG: pstr = "color map is too big"; break; + case SRC_TOO_SMALL: pstr = "Src is too small"; break; + case DST_TOO_SMALL: pstr = "Dst is too small"; break; + case BAD_MAGIC: pstr = "Bad magic number"; break; + case IMG_OVERWRITE: pstr = "Dst overwrite Src"; break; + case INVALID_PARAM: pstr = "Invalid parameter"; break; + case RECT_TOO_SMALL: pstr = "Rect is too small"; break; + case NO_ALPHA_CHANNEL: pstr = "_no_ alpha channel"; break; + case NO_BETA_CHANNEL: pstr = "rah: no beta channel"; break; + case FILE_CREATE_ERR: pstr = "err on file creation"; break; + case WRONG_FLAG: pstr = "wrong flag value"; break; + case NOT_3D_IMG: pstr = "not a 3d valid img"; break; + case INVALID_RGB: pstr = "invalid RGB values"; break; + case TOO_MUCH_VALUES: pstr = "too much values"; break; + case INVALID_PT_LIST: pstr = "invalid points list"; break; + case INVALID_POINT: pstr = "invalid point"; break; + case NULL_POINTER: pstr = "null pointer"; break; + case PIXEL_OVERFLOW: pstr = "pixel overflow"; break; + case PIXEL_UNDERFLOW: pstr = "pixel underflow"; break; + case INVALID_GAMMA: pstr = "invalid gamma"; break; + case INVALID_HF15: pstr = "invalid HF 15"; break; + case BAD_FILE_NAME: pstr = "bad file name"; break; + case EMPTY_COL_MAP: pstr = "empty ColMap"; break; + case BAD_CHRONO: pstr = "bad chrono number"; break; + case IMAGE_BAD_DIMS: pstr = "bad image dimensions"; break; + case PASTIS: pstr = "*** Apero Time ***"; break; + case BAD_OPERATOR: pstr = "bad operator"; break; + case BAD_FILTER: pstr = "Ugly Filter !"; break; + case WTF_OSEF: pstr = "omigod, wtf ?..."; break; + case BASIC_IO_RD_ERR: pstr = "BasicIO, Read err"; break; + case BASIC_IO_WR_ERR: pstr = "BasicIO, Write err"; break; + + case FP_GARBAGE: pstr = "garbage in floating point"; break; + case IMG_ARE_DIFFERENT: pstr = "img are differents"; break; + case BAD_ZOOM: pstr = "hu ho, bad zoom ?"; break; + case BAD_GRAY_OP: pstr = "bad gray operation"; break; + case ERR_GARDRECT: pstr = "err on a gadgrect"; break; + + case FUNC_IS_ALPHA: pstr = "func is ALPH@#;~:~."; break; + case FUNC_IS_BETA: pstr = "function in BETA test"; break; + case FUNC_IS_XPER: pstr = "experimental function"; break; + case FUNC_COREDUMP: pstr = "codedumping"; break; + case FUNC_NOT_FINISH: pstr = "function not finish"; break; + case IMAGE_FAIL: pstr = " }{ EPIC FAIL }{ "; break; + + case BAD_CADRE: pstr = "I haz a bad 'cadre'"; break; + + case 9999: pstr = "FORTRAN ro> +#include +#include +#include +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * parameter 'type' is reserved, and must be 0 for now. + * return value is -2 whe the file can't be opened. + */ +int Image_must_open(char *filename, int mode, int type) +{ +int fd; +char *path, *tmp; +int l1, l2; + +if (type != 0) + { + fprintf(stderr, "Image must Open: type (%d) must be 0\n", type); + } + +if ( (fd=open(filename, mode)) >= 0) + { + return fd; + } + +if ( (path=getenv(ENV_LIBIMAGE_PATH)) != NULL) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "LIBIMAGE_PATH is '%s'\n", path); +#endif + l1 = strlen(path); + l2 = strlen(filename); + if ( (tmp=alloca(l1+l2+5)) == NULL ) + { + fprintf(stderr, "%s : no more mem available\n", __func__); + exit(5); + } + strcpy(tmp, path); + if ( path[l1-1] != '/' ) strcat(tmp, "/"); + strcat(tmp, filename); +#if DEBUG_LEVEL > 1 + fprintf(stderr, "Image must Open: --> '%s'\n", tmp); +#endif + if ( (fd=open(tmp, mode)) > 0 ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "found at '%s'\n", tmp); +#endif + return fd; + } + } + +/* + Ahem, trying with the hardcoded path to shared file + of libimage. Hop this help. +*/ +path = SHAREDIR "/"; /* don't forget the trailing '/' */ + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "*** trying standard place '%s'\n", path); +#endif + +l1 = strlen(path); +l2 = strlen(filename); +if ( (tmp=alloca(l1+l2+5)) == NULL ) + { + fprintf(stderr, "Image must Open: KatasTroph on 'share'\n"); + exit(5); + } +strcpy(tmp, path); +strcat(tmp, filename); +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Image must Open: --> %s\n", tmp); +#endif +if ( (fd=open(tmp, mode)) > 0 ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "found at '%s'\n", tmp); +#endif + return fd; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Image must Open: file '%s' not found, sorry...\n", filename); +#endif + +return -2; /* mmm, a magic number ? */ +} +/*::------------------------------------------------------------------::*/ +/* + * parameter 'type' is reserved, and must be 0 for now. + */ +FILE * Image_must_fopen(char *filename, char *mode, int type) +{ +FILE *fp; +char *path, *tmp; +int l1, l2; + +/* filter for the reserved parameter */ +if (type != 0) + { + fprintf(stderr, "Image_must_fopen: type (%d) must be 0\n", type); + } + +if ( (fp=fopen(filename, mode)) != NULL ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "Image_must_fopen: found '%s' in current dir.\n", + filename); +#endif + return fp; + } + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s: searching for '%s'\n", __func__, filename); +#endif + +if ( (path=getenv(ENV_LIBIMAGE_PATH))!=NULL) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "LIBIMAGE_PATH is '%s'\n", path); +#endif + l1 = strlen(path); + l2 = strlen(filename); + if ( (tmp=alloca(l1+l2+5)) == NULL ) + { + fprintf(stderr, "Image must fopen: KatasTroph\n"); + exit(5); + } + strcpy(tmp, path); + if ( path[l1-1] != '/' ) strcat(tmp, "/"); + strcat(tmp, filename); +#if DEBUG_LEVEL > 1 + fprintf(stderr, "Image must fopen: --> '%s'\n", tmp); +#endif + if ( (fp=fopen(tmp, mode)) != NULL ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "found at '%s'\n", tmp); +#endif + return fp; + } + } +#if DEBUG_LEVEL > 1 +else + { + fprintf(stderr, "Image must fopen: LIBIMAGE_PATH is not set ?\n"); + } +#endif + +/* + * Ahem, trying with the hardcoded path to shared file + * of libimage. Hope this help. + */ +path = SHAREDIR "/"; /* don't forget the trailing '/' */ + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "* trying standard place '%s'\n", path); +#endif + +l1 = strlen(path); +l2 = strlen(filename); +if ( (tmp=alloca(l1+l2+5)) == NULL ) + { + fprintf(stderr, "Image must fopen: KatasTroph on 'share'\n"); + exit(5); + } +strcpy(tmp, path); +strcat(tmp, filename); +#if DEBUG_LEVEL > 1 +fprintf(stderr, "Image must fopen: -> %s\n", tmp); +#endif +if ( (fp=fopen(tmp, mode)) != NULL ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "found at '%s'\n", tmp); +#endif + return fp; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Image must fopen: file '%s' not found, sorry...\n", filename); +#endif + +return NULL; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ + diff --git a/octree.c b/octree.c new file mode 100644 index 0000000..eacd043 --- /dev/null +++ b/octree.c @@ -0,0 +1,41 @@ +/* + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + + Octree Color Quantization + + + ------------------------- + + + + + + http://www.cubic.org/~submissive/sorcerer/octree.htm + + + + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +*/ + +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * bon, yapluka, fokon. + */ +int +Image_octree_0(Image_Desc *src, Image_Desc *dst) +{ + +#if DEBUG +fprintf(stderr, "%s ( %p %p )\n", __func__, src, dst); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int +Image_octree_1(Image_Desc *src, Image_Desc *dst) +{ + +#if DEBUG +fprintf(stderr, "%s ( %p %p )\n", __func__, src, dst); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/op2x2.c b/op2x2.c new file mode 100644 index 0000000..6517f00 --- /dev/null +++ b/op2x2.c @@ -0,0 +1,241 @@ +/* + op2x2.c + -------------- + you can also look at 'dither.c' and search for '2x2' +*/ + +#include +#include /* pour abs() */ +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * 6 Fev 2001: on aimerait bien avoir la doc de cette fonction + * 27 Juillet 2008: on attend toujours... + */ +int +Image_2x2_contours_0(Image_Desc *im) +{ +int x, y, q; +int tbl[] = + { + 0, 1, 1, 1, + 1, 1, 0, 1, + 1, 0, 1, 1, + 1, 1, 1, 0 + }; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : w=%d h=%d\n", __func__, im->width, im->height); +#endif + +for (x=0; x<(im->width-1); x++) + { + for (y=0; y<(im->height-1); y++) + { + q = ((im->Rpix[y] [x] ? 0 : 1) << 3 ) | + ((im->Rpix[y] [x+1] ? 0 : 1) << 2 ) | + ((im->Rpix[y+1][x] ? 0 : 1) << 1 ) | + ((im->Rpix[y+1][x+1] ? 0 : 1) ) ; + im->Rpix[y][x] = tbl[q] ? 255 : 0; + + q = ((im->Gpix[y] [x] ? 0 : 1) << 3 ) | + ((im->Gpix[y] [x+1] ? 0 : 1) << 2 ) | + ((im->Gpix[y+1][x] ? 0 : 1) << 1 ) | + ((im->Gpix[y+1][x+1] ? 0 : 1) ) ; + im->Gpix[y][x] = tbl[q] ? 255 : 0; + + q = ((im->Bpix[y] [x] ? 0 : 1) << 3 ) | + ((im->Bpix[y] [x+1] ? 0 : 1) << 2 ) | + ((im->Bpix[y+1][x] ? 0 : 1) << 1 ) | + ((im->Bpix[y+1][x+1] ? 0 : 1) ) ; + im->Bpix[y][x] = tbl[q] ? 255 : 0; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* updated 31 august 2008 */ +/* le seul bit utilise dans l'image source est le bit 7 */ +int +Image_2x2_contours_1(Image_Desc *src, Image_Desc *dst) +{ +int foo; +int x, y, q; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + return foo; + } +#if DEBUG_LEVEL +fprintf(stderr, "*** %s *** catastrophic function :)\n", __func__); +#endif +Image_clear(dst, 0, 0, 0); + +for (x=0; x<(src->width-1); x++) + { + for (y=0; y<(src->height-1); y++) + { + q = ((0x80 & (src->Rpix[y] [x] ) ? 0 : 1) << 3 ) | + ((0x80 & (src->Rpix[y] [x+1]) ? 0 : 1) << 2 ) | + ((0x80 & (src->Rpix[y+1][x] ) ? 0 : 1) << 1 ) | + ((0x80 & (src->Rpix[y+1][x+1]) ? 0 : 1) ) ; + dst->Rpix[y][x] = q; + q = ((0x80 & (src->Gpix[y] [x] ) ? 0 : 1) << 3 ) | + ((0x80 & (src->Gpix[y] [x+1]) ? 0 : 1) << 2 ) | + ((0x80 & (src->Gpix[y+1][x] ) ? 0 : 1) << 1 ) | + ((0x80 & (src->Gpix[y+1][x+1]) ? 0 : 1) ) ; + dst->Gpix[y][x] = q; + q = ((0x80 & (src->Bpix[y] [x] ) ? 0 : 1) << 3 ) | + ((0x80 & (src->Bpix[y] [x+1]) ? 0 : 1) << 2 ) | + ((0x80 & (src->Bpix[y+1][x] ) ? 0 : 1) << 1 ) | + ((0x80 & (src->Bpix[y+1][x+1]) ? 0 : 1) ) ; + dst->Bpix[y][x] = q; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * 6 Fev 2001: on aimerait bien avoir la doc de cette fonction + */ +int +Image_2x2_contrast(Image_Desc *src, Image_Desc *dst) +{ +int foo, x, y, r, g, b; +int mir, mig, mib, mar, mag, mab; + +int dx[4] = { 0, 1, 0, 1 }; +int dy[4] = { 0, 0, 1, 1 }; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + return foo; + } + +for (y=0; yheight-1; y++) + { + for (x=0; xwidth-1; x++) + { + mir = mig = mib = 342; + mar = mag = mab = -42; + for (foo=0; foo<4; foo++) + { + r = (src->Rpix[y+dy[foo]])[x+dx[foo]]; + g = (src->Gpix[y+dy[foo]])[x+dx[foo]]; + b = (src->Bpix[y+dy[foo]])[x+dx[foo]]; + + if (mir>r) mir = r; + if (mig>g) mig = g; + if (mib>b) mib = b; + if (marheight-1; y++) + { + for (x=0; xwidth-1; x++) + { + tir = tig = tib = 0; + for (foo=0; foo<4; foo++) + { + tir += (src->Rpix[y+dy[foo]])[x+dx[foo]]; + tig += (src->Gpix[y+dy[foo]])[x+dx[foo]]; + tib += (src->Bpix[y+dy[foo]])[x+dx[foo]]; + } + (dst->Rpix[y])[x] = tir/4; + (dst->Gpix[y])[x] = tig/4; + (dst->Bpix[y])[x] = tib/4; + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * 8 Feb 2001: another kludge (without doc) + */ +int +Image_2x2_rot4pix(Image_Desc *src, Image_Desc *dst, int rot) +{ +int x, y, foo, bar, r, g, b; + +int dx[4] = { 0, 1, 0, 1 }; +int dy[4] = { 0, 0, 1, 1 }; + +for (y=0; yheight-1; y+=2) + { + for (x=0; xwidth-1; x+=2) + { + for (foo=0; foo<4; foo++) + { + bar = (foo+rot)%4; + r = (src->Rpix[y+dy[foo]])[x+dx[foo]]; + g = (src->Gpix[y+dy[foo]])[x+dx[foo]]; + b = (src->Bpix[y+dy[foo]])[x+dx[foo]]; + } + (dst->Rpix[y])[x] = r; + (dst->Gpix[y])[x] = g; + (dst->Bpix[y])[x] = b; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int Image_2x2_shiftUL(Image_Desc *src, Image_Desc *dst) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "this func (%s) is a kluge\n", __func__); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + return foo; + } + +/* 1er septembre 2008: je n'ai pas la moindre idee de ce que j'ai + * voulu faire ici :) */ + +/* 26 novembre 2009: j'arrive pas a me rappeler du pourquoi de + * ce que doit faire cette fonction */ + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/operat.c b/operat.c new file mode 100644 index 0000000..db5ce61 --- /dev/null +++ b/operat.c @@ -0,0 +1,688 @@ +/* + Operations diverses sur les images + ---------------------------------- + +25 Aout 1999: certaines fonctions utilisent 'alloca'. + +4 Fevrier 2001: je me rend compte que certaines interfaces sont trop + simplistes, et que définir des structures contenant de multiples + paramètres ne serait peut-être pas une mauvaise idée... + +16 Oct 2001: je deplace quelques fonctions dans d'autres modules. + +*/ + +#include +#include +#include + +#ifdef NEED_ALLOCA_H +#include +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * XXX il y a un "Zero Divide" cache dans cette fonction ! + */ +int +Image_adjust_minmax_0(Image_Desc *src, Image_Desc *dst, int yo, + int minstone, int maxstone) +{ +long histR[256], histG[256], histB[256]; +long surface; +int foo; +long mini, maxi, kmini, kmaxi, delta; +int idxmini, idxmaxi, val, lut[256], level; + +if (yo != 0) + { + fprintf(stderr, "Yo is %d\n", yo); + } + +Image_histo_RGB(src, histR, histG, histB); + +surface = (src->width * src->height); +kmini = (minstone * surface) / 100; +kmaxi = (maxstone * surface) / 100; + +#if DEBUG_LEVEL +fprintf(stderr, "adjust minmax:\n"); +fprintf(stderr, " minstone= %d\n", minstone); +fprintf(stderr, " maxstone= %d\n", maxstone); +fprintf(stderr, " surface = %ld\n", surface); +fprintf(stderr, " K mini = %ld\n", kmini); +fprintf(stderr, " K maxi = %ld\n", kmaxi); +#endif + +mini = 0; +idxmini = 0; +for (foo=0; foo<256; foo++) + { + mini += (histR[foo] + histG[foo] + histB[foo]); + if (mini > kmini) + { + fprintf(stderr, "MINI %3d %ld\n", foo, mini); + idxmini = foo; + break; + } + } + +maxi = 0; +idxmaxi = 255; +for (foo=255; foo>=0; foo--) + { + maxi += (histR[foo] + histG[foo] + histB[foo]); + if (maxi > kmaxi) + { + fprintf(stderr, "MAXI %3d %ld\n", foo, maxi); + idxmaxi = foo; + break; + } + } + +delta = idxmaxi - idxmini; +fprintf(stderr, "idxmini=%d idxmaxi=%d delta=%ld\n", idxmini, idxmaxi, delta); + +for (foo=0; foomodified = 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * et une fonction de plus ecrite a la rache, avec un nom qui + * ne veut probablement rien dire :) + */ +int +Image_luminance(Image_Desc *src, Image_Desc *dst, int factor) +{ +int foo; +int x, y; + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s ( %p %p %d )\n", __func__, src, dst, factor); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "Image Luminance: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + dst->Rpix[y][x] = (src->Rpix[y][x] * factor) / 256; + dst->Gpix[y][x] = (src->Gpix[y][x] * factor) / 256; + dst->Bpix[y][x] = (src->Bpix[y][x] * factor) / 256; + } + } + +dst->modified = 1; + +return FUNC_IS_BETA; +} +/* + * p'taing, c'est tellement crade qu'il faut: + * 1) retrouver d'ou ça vient + * 2) la virer illico !... + */ +/*::------------------------------------------------------------------::*/ +/* + ** ne fonctionne que sur les images en RGB, pour le moment. + + 16 jan 2003: il faudrait faire quelque chose pour les + images avec un canal Alpha. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + le parametre 'yoyo' n'est pas utilise actuellement. +*/ +int +Image_egalise_RGB(Image_Desc *src, Image_Desc *dst, int yoyo) +{ +int foo; +long *histr, *histg, *histb; +int *cumlr, *cumlg, *cumlb; +long cr, cg, cb, s; + +if (yoyo != 0) { + fprintf(stderr, "%s: yoyo is %d\n", __func__, yoyo); + } + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "Image Egalise RGB: images are differents %d\n", foo); + return foo; + } + +/* yup, en 2009, il faudrait pas remplacer tout ces 'alloca' par de + * la bonne 'kiss' variable automatique ? + */ +if((histr=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; +if((histg=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; +if((histb=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; +if((cumlr=(int *)alloca(256*sizeof(int))) == NULL) return BUFFER_NO_MEM; +if((cumlg=(int *)alloca(256*sizeof(int))) == NULL) return BUFFER_NO_MEM; +if((cumlb=(int *)alloca(256*sizeof(int))) == NULL) return BUFFER_NO_MEM; + +Image_histo_RGB(src, histr, histg, histb); + +cr = cg = cb = 0L; +s = (src->width * src->height); + +#if DEBUG_LEVEL +fprintf(stderr, "Image Egalise 0: surface = %ld\n", s); +#endif + +for (foo=0; foo<256; foo++) { + cr += histr[foo]; cumlr[foo] = (int)((cr*255)/s); + cg += histg[foo]; cumlg[foo] = (int)((cg*255)/s); + cb += histb[foo]; cumlb[foo] = (int)((cb*255)/s); + } + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "* histo RGB: cumuls: %d %d %d surface: %ld\n", + cumlr[255], cumlg[255], cumlb[255], s); +for (foo=0; foo<256; foo++) + { + fprintf(stderr, "%3d | %7ld %7ld %7ld | %7d %7d %7d\n", + foo, + histr[foo], histg[foo], histb[foo], + cumlr[foo], cumlg[foo], cumlb[foo]); + } +#endif + +Image_LUT_RGB(src, dst, cumlr, cumlg, cumlb); +dst->modified = 1; + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + cette fonction doit absolument etre re-ecrite + pour optimiser l'occupation de la memoire. + et il faudrait aussi explique ce qu'elle fait :) + + le parametre 'yoyo' n'est pas utilise actuellement. +*/ +int +Image_egalise_mono_0(Image_Desc *src, Image_Desc *dst, int yoyo) +{ +int foo; +long c, cc, s3; +long *histr, *histg, *histb; +int cumul[256]; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_Egalise_Mono_0: images are differents %d\n", foo); + return foo; + } + +if (yoyo != 0) + fprintf(stderr, "%s : yoyo must be 0\n", __func__); + +if((histr=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; +if((histg=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; +if((histb=(long *)alloca(256*sizeof(long))) == NULL) return BUFFER_NO_MEM; + +Image_histo_RGB(src, histr, histg, histb); + +/* + * diviseur en fonction de la surface + */ +s3 = (3 * src->width * src->height); + +cc = 0L; +for (foo=0; foo<256; foo++) + { + c = histr[foo] + histg[foo] + histb[foo]; + cc += c; + cumul[foo] = (int)((cc*255) / s3); + } + +Image_LUT_mono(src, dst, cumul); +dst->modified = 1; +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + cette fonction ne marche que si les deux images + sont allouees et de meme dimensions. + */ +int +Image_copy(Image_Desc *src, Image_Desc *dst) +{ +int foo; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image_Copy: images are differents %d\n", foo); + return foo; + } + +for (foo=0; fooheight; foo++) + { + memcpy(dst->Rpix[foo], src->Rpix[foo], src->width); + memcpy(dst->Gpix[foo], src->Gpix[foo], src->width); + memcpy(dst->Bpix[foo], src->Bpix[foo], src->width); + if (dst->Apix!=NULL && src->Apix!=NULL) + memcpy(dst->Apix[foo], src->Apix[foo], src->width); + } + +dst->modified = 1; +/* + >> 18 Juin 2002 + >> ============ + >> bon, maintenant se pose un grand problème philosophique. + >> on vient juste de copier les octets qui incarnent les pixels + >> rgb et peut-être alpha. Mais ce n'est que la partie évident + >> d'une image: ses pixels. + */ + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + complement d'une image complete (c.a.d tous + les canaux contenus dans cette image) + */ +int +Image_negate(Image_Desc *image, Image_Desc *resultat) +{ +int x, y; + +if (image->type == 3) + { + for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + resultat->Rpix[y][x] = image->Rpix[y][x] ^ 0xff; + resultat->Gpix[y][x] = image->Gpix[y][x] ^ 0xff; + resultat->Bpix[y][x] = image->Bpix[y][x] ^ 0xff; + } + } + return 0; + } + +fprintf(stderr, "Image Negate: unknow image type %d, %s\n", + image->type, Image_type2str(image->type)); +return IMAGE_BAD_TYPE; +} + +/*::------------------------------------------------------------------::*/ +int +Image_and_pix( Image_Desc *image, uint8_t ar, uint8_t ag, uint8_t ab ) +{ +int x, y; + +if (image->type == 3) + { + for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + image->Rpix[y][x] &= ar; + image->Gpix[y][x] &= ag; + image->Bpix[y][x] &= ab; + } + } + return 0; + } + +fprintf(stderr, "Image And Pix: unknow image type %d\n", image->type); +return IMAGE_BAD_TYPE; +} +/*::------------------------------------------------------------------::*/ +int +Image_or_pix( Image_Desc *image, int ar, int ag, int ab ) +{ +int x, y; + +if (image->type == 3) + { + for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + image->Rpix[y][x] |= (ar & 0xff); + image->Gpix[y][x] |= (ag & 0xff); + image->Bpix[y][x] |= (ab & 0xff); + } + } + return 0; + } + +fprintf(stderr, "Image_OrPix: unknow image type %d\n", image->type); +return IMAGE_BAD_TYPE; +} +/*::------------------------------------------------------------------::*/ +/* new 11 octobre 2001 */ +int +Image_clear_component(Image_Desc *img, char component, int value) +{ +int x, y; + +if (img->type != 3) + { + fprintf(stderr, "Clear Component: only type 3 img\n"); + return IMAGE_BAD_TYPE; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + switch (component) + { + case 'r': case 'R': + (img->Rpix[y])[x] = value; break; + case 'g': case 'G': + (img->Gpix[y])[x] = value; break; + case 'b': case 'B': + (img->Bpix[y])[x] = value; break; + } + } + } +img->modified = 1; +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * cette func recopie les pixels de la source dont une composante RGB + * est superieure aux seuils dans l'image de destination + * + * 1er Fev 2000: ya quelque chose a faire avec la transparence ? + */ +int +Image_copie_seuil(Image_Desc *s, Image_Desc *d, int sr, int sg, int sb) +{ +int x, y, r, g, b; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + r = Image_R_pixel(s, x, y); + g = Image_G_pixel(s, x, y); + b = Image_B_pixel(s, x, y); + if (r>sr || g>sg || b>sb) + Image_plotRGB(d, x, y, r, g, b); + } + } + +d->modified = 0; /* 2001-02-08 */ + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * pourquoi il n'y a pas de test de debordement ? + * ce truc ne marche pas bien si il y a de l'Alpha + */ +int +Image_overlay(Image_Desc *s, Image_Desc *d, int xpos, int ypos) +{ +int x, y, r, g, b; +int xd, yd; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p on %p at %d,%d )\n", __func__, + s, d, xpos, ypos); +#endif + +for (y=0; yheight; y++) + { + yd = y+ypos; + for (x=0; xwidth; x++) + { + xd = x+xpos; + if ( (xd>=0) && (xdwidth-1) && (yd>=0) && (ydheight-1) ) + { + r = (s->Rpix[y])[x]; + g = (s->Gpix[y])[x]; + b = (s->Bpix[y])[x]; + Image_plotRGB(d, xd, yd, r, g, b); + } + } + } + +d->modified = 1; /* 2001-02-08 */ + +return 0; +} +/*::------------------------------------------------------------------::*/ +int +Image_overlay_mix(Image_Desc *s, Image_Desc *d, int xpos, int ypos, int k) +{ +int x, y, sr, sg, sb; +int xd, yd; + +#if DEBUG_LEVEL < 10 +fprintf(stderr, "%s ( %p on %p at %d,%d )\n", __func__, + s, d, xpos, ypos); +fprintf(stderr, " coef = %d\n", k); +#endif + +for (y=0; yheight; y++) + { + yd = y+ypos; + for (x=0; xwidth; x++) + { + xd = x+xpos; + if ( (xd>=0) && (xdwidth-1) && (yd>=0) && (ydheight-1) ) + { + sr = (s->Rpix[y])[x]; + sg = (s->Gpix[y])[x]; + sb = (s->Bpix[y])[x]; + Image_plotRGB(d, xd, yd, sr, sg, sb); + } + } + } + +d->modified = 1; /* 2001-02-08 */ + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* ce truc sert a quoi ? */ +static uint16_t rotate_left(uint16_t byte) +{ +byte = byte << 1; +if (byte & 0x100) byte |= 1; +else byte &= 0xfe; +return (byte & 0xff); +} + +static uint16_t rotate_right(uint16_t byte) +{ +uint16_t lowbit = byte & 1; +byte = byte >> 1; +if (lowbit) byte |= 0x80; +else byte &= 0x7f; +return (byte & 0xff); +} + +int +Image_operator(Image_Desc *in, char op, int val, Image_Desc *out) +{ +int x, y; +int retval; + +if ( (in->type != 3) || (out->type != 3) ) + { + fprintf(stderr, "Image operator: bad type of image\n"); + return IMAGE_BAD_TYPE; + } + +retval = 0; + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + switch(op) + { + case '+': + out->Rpix[y][x] = in->Rpix[y][x] + val; + out->Gpix[y][x] = in->Gpix[y][x] + val; + out->Bpix[y][x] = in->Bpix[y][x] + val; + break; + + case '/': + out->Rpix[y][x] = in->Rpix[y][x] / val; + out->Gpix[y][x] = in->Gpix[y][x] / val; + out->Bpix[y][x] = in->Bpix[y][x] / val; + break; + + case '&': case 'A': + out->Rpix[y][x] = in->Rpix[y][x] & val; + out->Gpix[y][x] = in->Gpix[y][x] & val; + out->Bpix[y][x] = in->Bpix[y][x] & val; + break; + + case '|': case 'O': + out->Rpix[y][x] = in->Rpix[y][x] | val; + out->Gpix[y][x] = in->Gpix[y][x] | val; + out->Bpix[y][x] = in->Bpix[y][x] | val; + break; + + case '^': + out->Rpix[y][x] = in->Rpix[y][x] ^ val; + out->Gpix[y][x] = in->Gpix[y][x] ^ val; + out->Bpix[y][x] = in->Bpix[y][x] ^ val; + break; + + case '*': + out->Rpix[y][x] = in->Rpix[y][x] * val; + out->Gpix[y][x] = in->Gpix[y][x] * val; + out->Bpix[y][x] = in->Bpix[y][x] * val; + break; + + case '<': + out->Rpix[y][x] = rotate_left(in->Rpix[y][x]); + out->Gpix[y][x] = rotate_left(in->Gpix[y][x]); + out->Bpix[y][x] = rotate_left(in->Bpix[y][x]); + break; + + case '>': + out->Rpix[y][x] = rotate_right(in->Rpix[y][x]); + out->Gpix[y][x] = rotate_right(in->Gpix[y][x]); + out->Bpix[y][x] = rotate_right(in->Bpix[y][x]); + break; + + default: + out->Rpix[y][x] = in->Rpix[y][x]; + out->Gpix[y][x] = in->Gpix[y][x]; + out->Bpix[y][x] = in->Bpix[y][x]; + retval = 1; + break; + } + } + } + +out->modified = 1; /* 2001-09-28 */ +return retval; +} +/*::------------------------------------------------------------------::*/ + +int +Image_seuil_RGB(Image_Desc *s, Image_Desc *d, int r, int g, int b) +{ +int foo, x, y; + +if ( (s->type != 3) || (d->type != 3) ) + { + fprintf(stderr, "Image Seuil RGB: an image is not of type 3\n"); + return IMAGE_BAD_TYPE; + } + +if ( (foo=Image_compare_desc(s, d)) != 0 ) + { + fprintf(stderr, "Image Seuil RGB: images are differents %d\n", foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + if(s->Rpix[y][x] > r) d->Rpix[y][x] = 255; + else d->Rpix[y][x] = 0; + if(s->Gpix[y][x] > g) d->Gpix[y][x] = 255; + else d->Gpix[y][x] = 0; + if(s->Bpix[y][x] > b) d->Bpix[y][x] = 255; + else d->Bpix[y][x] = 0; + } + } +d->modified = 1; /* 2001-02-08 */ +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* XXX a tester et a documenter XXX */ +int +Image_AutoSeuilRGB(Image_Desc *s, Image_Desc *d) +{ +int foo, sr, sg, sb; +long *histr, *histg, *histb; +long surf2, cr, cg, cb; + +if((histr=(long *)alloca(256*sizeof(long))) == NULL) + return BUFFER_NO_MEM; +if((histg=(long *)alloca(256*sizeof(long))) == NULL) + return BUFFER_NO_MEM; +if((histb=(long *)alloca(256*sizeof(long))) == NULL) + return BUFFER_NO_MEM; + +foo = Image_histo_RGB(s, histr, histg, histb); +#if DEBUG_LEVEL +fprintf(stderr, "in %s histo_RGB -> %d\n", __func__, foo); +#endif + +sr = sg = sb = 0; +cr = cg = cb = 0L; +surf2 = (s->width*s->height)/2; +#if DEBUG_LEVEL +fprintf(stderr, "Auto Seuil RGB sur %p - surf2 = %ld\n", s, surf2); +#endif + +for (foo=0; foo<256; foo++) + { + cr += histr[foo]; + if (cr < surf2) sr = foo; + cg += histg[foo]; + if (cg < surf2) sg = foo; + cb += histb[foo]; + if (cb < surf2) sb = foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "Auto Seuil RGB sur %p - seuils calcules: %d %d %d\n", + s, sr, sg, sb); +#endif + +foo = Image_seuil_RGB(s, d, sr, sg, sb); + +/* FIXME : this function need a test framework */ + +return foo; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/pcx.c b/pcx.c new file mode 100644 index 0000000..8ed4728 --- /dev/null +++ b/pcx.c @@ -0,0 +1,360 @@ +/* + pcx.c + ===== + "Euh, pourquoi c,a avance pas ?" + "Ben, parce que le momo me prend la tete..." + "Ah, je comprends." + + 2 Octobre 2001: le boutisme va être pris en compte. pour plus + de détails, allez voir le module 'basic_io.c'. +*/ + +#include +#include +#include +#include /* pour memset() */ + +#ifdef NEED_ALLOCA_H +#include +#endif + +#ifndef DEBUG_LEVEL +#define DEBUG_LEVEL 1 +#endif + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +#define LIBPCX_VERSION "0.0.12" + +typedef struct { + /* + * Attention, cette structure n'est pas directement + * utilsable pour les I/O disques, a cause des problemes + * d'aligmement { pas de #pragma pack(1) disponible } + */ + uint8_t aa; + uint8_t version; + uint8_t encoding; + uint8_t bit_pixel; + uint16_t xmin, ymin; + uint16_t xmax, ymax; + uint16_t hres; + uint16_t vres; + uint8_t palette[48]; + uint8_t reserved; + uint8_t col_planes; + uint16_t byte_lines; + uint16_t palette_type; + char filler[58]; + } Pcx_file_header; + +/*::------------------------------------------------------------------::*/ +static int +Image_PCX_dump_header(Pcx_file_header *ph, int verbose) +{ +if (verbose) + printf("pcx header @ %p\n", ph); + +printf(" aa : %02x\n", ph->aa); +printf(" version : %d\n", ph->version); +printf(" encoding : %d\n", ph->encoding); +printf(" bits/pixels : %d\n", ph->bit_pixel); +printf(" xy min : %5d %5d\n", ph->xmin, ph->ymin); +printf(" xy max : %5d %5d\n", ph->xmax, ph->ymax); +printf(" hv res : %5d %5d\n", ph->hres, ph->vres); +printf(" col/plane : %d\n", ph->col_planes); +printf(" bytes/line : %d\n", ph->byte_lines); +printf(" palette : %d\n", ph->palette_type); + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * 9 Oct 2001: ecriture d'un header PCX sur disque sans problemes + * de boutisme (en principe :) + */ +static int +write_pcx_header(Pcx_file_header *head, FILE *fp) +{ +#if DEBUG_LEVEL +fprintf(stderr, "writing a pcx header (lib v %s)\n", LIBPCX_VERSION); +#endif + +fwrite(&head->aa, 1, 1, fp); +fwrite(&head->version, 1, 1, fp); +fwrite(&head->encoding, 1, 1, fp); +fwrite(&head->bit_pixel, 1, 1, fp); +Image_basicIO_write_I_short(fp, head->xmin); +Image_basicIO_write_I_short(fp, head->ymin); +Image_basicIO_write_I_short(fp, head->xmax); +Image_basicIO_write_I_short(fp, head->ymax); +Image_basicIO_write_I_short(fp, head->hres); +Image_basicIO_write_I_short(fp, head->vres); +fwrite(&head->palette, 1, 48, fp); +fwrite(&head->reserved, 1, 1, fp); +fwrite(&head->col_planes, 1, 1, fp); +Image_basicIO_write_I_short(fp, head->byte_lines); +Image_basicIO_write_I_short(fp, head->palette_type); +fwrite(&head->filler, 1, 58, fp); + +#if DEBUG_LEVEL +Image_PCX_dump_header(head, 1); +#endif + +return 0; +} +/*::------------------------------------------------------------------::*/ +/* new 24 Nov 2001 + * read a PCX header + */ +static int +read_pcx_header(Pcx_file_header *head, FILE *fp) +{ +#if DEBUG_LEVEL +fprintf(stderr, "reading a pcx header (lib v %s)\n", LIBPCX_VERSION); +#endif + +/* effacement de la zone de données */ +memset(head, 0, sizeof(Pcx_file_header)); + +rewind(fp); /* revenir au début */ + +fprintf(stderr, "reading...\n"); + +fread(&head->aa, 1, 1, fp); +fread(&head->version, 1, 1, fp); +fread(&head->encoding, 1, 1, fp); +fread(&head->bit_pixel, 1, 1, fp); +Image_basicIO_read_I_short(fp, &head->xmin); +Image_basicIO_read_I_short(fp, &head->ymin); +Image_basicIO_read_I_short(fp, &head->xmax); +Image_basicIO_read_I_short(fp, &head->ymax); +Image_basicIO_read_I_short(fp, &head->hres); +Image_basicIO_read_I_short(fp, &head->vres); +fread(&head->palette, 1, 48, fp); +fread(&head->reserved, 1, 1, fp); +fread(&head->col_planes, 1, 1, fp); +Image_basicIO_read_I_short(fp, &head->byte_lines); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int +Image_PCX_fileinfo(char *nom) +{ +Pcx_file_header head; +FILE *fp; +int foo; + +fprintf(stderr, "reading '%s'\n", nom); + +if ( (fp=fopen(nom, "rb")) == NULL ) + { + fprintf(stderr, "PCX fileinfo: err fopen %d\n", errno); + return FILE_NOT_FOUND; + } +fprintf(stderr, "fp %p\n", fp); + +read_pcx_header(&head, fp); +fclose(fp); + +printf("PCX infos for file: %s\n", nom); +foo = Image_PCX_dump_header(&head, 0); + +return foo; +} +/*::------------------------------------------------------------------::*/ +/* + * Euh, je prends cette fonction direct de Steve Rimmer, et + * je chercherais a comprendre quand le Momo me laissera la + * cervelle intacte. + */ + +static int +pix2byte_mono(int n) +{ +if (n & 0x0007) return((n >> 3) + 1); +else return(n >> 3); +} +static int +pix2byte_4cols(int n) +{ +if (n & 0x0001) return((n >> 1) + 1); +else return(n >> 1); +} +/*::------------------------------------------------------------------::*/ +/* + from "Bit-mapped graphics" page 101 + */ +static int +write_line(unsigned char *p, int bytes, FILE *fp) +{ +unsigned int i=0, j=0, t=0; + +/* hu ho */ + +do + { + i = 0; + while((p[t+i]==p[t+i+1]) && ((t+i) 0) + { + fputc(i | 0xc0, fp); + fputc(~p[t], fp); + t += i; + j += 2; + } + else + { + if ( ((~p[t])&0xc0)==0xc0 ) + { + fputc(0xc1, fp); + ++j; + } + fputc(~p[t++], fp); + ++j; + } + } while (t < bytes); + +return j; +} +/*::------------------------------------------------------------------::*/ +/* + la, j'ai qu'un mot a dire: + "ou sont les backups de convpht ?" + */ +int +Image_wrPCX_8colors(char *nom, Image_Desc *im) +{ +Pcx_file_header head; +FILE *fp; +uint8_t *line, *compline, the_byte; +int foo, bytes, x, y; +int r, g, b; + +#if DEBUG_LEVEL +fprintf(stderr, "L'ecriture des PCX 8 couleurs est experimentale. YMMV.\n"); +#endif + +/* + * populate the header of the file + */ +memset(&head, ' ', sizeof(head)); + +head.aa = 0x0a; /* toujours 10 */ +head.version = 5; +head.encoding = 1; /* toujours 1. */ +head.bit_pixel = 4; +head.xmin = 0; +head.ymin = 0; +head.xmax = im->width-1; /* A VERIFIER */ +head.ymax = im->height-1; /* A VERIFIER, aussi */ +head.hres = 72; +head.vres = 72; +head.reserved = 0x42; /* what a nice number ! */ +head.col_planes = 1; /* ?????????????????? */ +head.byte_lines = pix2byte_4cols(im->width); +#if DEBUG_LEVEL +fprintf(stderr, "width %d -> byte_lines %d\n", im->width, head.byte_lines); +#endif +head.palette_type = 0; /* we make a 16 color file ? */ +for (foo=0; foo<8; foo++) /* create the palette */ + { + head.palette[foo*3] = (foo & 1) ? 255 : 0; + head.palette[foo*3+1] = (foo & 2) ? 255 : 0; + head.palette[foo*3+2] = (foo & 4) ? 255 : 0; + } + +/* warning, the filler is NOT an asciiz string */ +strncpy(head.filler, "[ PCX writ'd by the libimage (dwtfywl) tontonTh ]", 58); + +/* + * allocate the buffer for the raw bit-map-line, this one + * before the compression... + */ +bytes = pix2byte_4cols(im->width); +#if DEBUG_LEVEL +fprintf(stderr, "PCX: en largeur, %d pixels, donc une ligne de %d octets\n", + im->width, bytes); +#endif +line = (uint8_t *)alloca(bytes * sizeof(uint8_t)); +compline = (uint8_t *)alloca(bytes * 3 * sizeof(uint8_t)); + +/* + * open the file and write the header + */ +if ( (fp = fopen(nom, "w")) == NULL ) + { + fprintf(stderr, "wr pcx 8 colors: err fopen %d\n", errno); + return FILE_CREATE_ERR; + } +(void)write_pcx_header(&head, fp); /* new 9 oct 2001 */ + +/* + * and now, the great show: blast all the picture lines to + * the marvelous PCX compression scheme. + */ +for (y=0; yheight; y++) + { +#if DEBUG_LEVEL + fprintf(stderr, "Wr pcx8: line %d\r", y); +#endif + memset(line, 0, bytes); + for (x=0; xwidth; x++) + { + /* + * read the pixels... + */ + Image_getRGB(im, x, y, &r, &g, &b); + r = (r >> 8) & 1; + g = (g >> 8) & 1; + b = (b >> 8) & 1; + + the_byte = (r<<4) | (r<<3) | (r<<2); + + /* + * build the line + */ + if (x & 1) + { + line[x/2] |= the_byte; + } + else + { + line[x/2] |= (the_byte<<4); + } + + } + foo = write_line(line, bytes, fp); +#if DEBUG_LEVEL + fprintf(stderr, " %d bytes written\n", foo); +#endif + } +#if DEBUG_LEVEL +fputs("................ pcx .....\n", stderr); +#endif + +fclose(fp); +return FULL_NUCKED; /* 24 mars 2002: toujours nucked */ +} +/*::------------------------------------------------------------------::*/ +/* + * Raaahaha p'taing il faudrait le finir un de ces jours ! + * 16 Feb 2001: j'y travaille, j'y travaille... + * 09 Oct 2001: ...et ce sera sans problèmes de boutisme :) + * 22 Jan 2003: ça avance, faut pas s'affoler. + * 17 Oct 2009: c'est encore au point mort. + */ +/*::------------------------------------------------------------------::*/ +/* 19 mars 2010 : arrivee des bitplanes */ +int Image_bp2pcx(A_BitPlane *bp, char *fname, int flags) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p '%s' %d )\n", __func__, bp, fname, flags); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/pht.c b/pht.c new file mode 100644 index 0000000..1cd93d1 --- /dev/null +++ b/pht.c @@ -0,0 +1,140 @@ +/* + + le retour du format PHT !-) + =========================== + + Et je remercie grandemant Guy Marcenac pour toute l'aide + qu'il m'a apporte a la grande epoque du COPAM. + + ------------------------------------------ + + mais c'est quoi le format PHT ? + + z) Il y a fort longtemps, je travaillais dans une + z) boite de traitement d'images medicales, et je + z) me suis retrouve proprietaire d'une Micropix. + z) Carte d'acquisition d'images 512x256x64. + z) J'ai beaucoup joue avec, et j'ai stocke des + z) centaines d'images sur disque. Au format PHT. + z) Format strictement proprietaire, mais dont tous + z) les secrets sont devoiles ici .;-) + + ------------------------------------------ + + il me semble que dans le temps du Copam, on avait aussi un + format de fichier KP0 ? -oui, je m'en souviens... + + ------------------------------------------ + + NEW: 12 Sept 2001. + je commence à modifier pour que ce soit indépendant du + boutisme, et les premiers essais seront fait sur Sparc. +*/ + +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_PHT_save_component(char *name, Image_Desc *img, char color) +{ +FILE *fp; +uint8_t **planeptr; +int foo; + +/* security fixes, because I make buggy soft around PHT files */ +if (name == NULL) + { + fprintf(stderr, "PHT save componant: name ptr is null\n"); + return BAD_FILE_NAME; + } +if (img == NULL) + { + return NULL_DESCRIPTOR; + } + +planeptr = NULL; + +switch (color) + { + case 'R': case 'r': + planeptr = img->Rpix; break; + + case 'G': case 'g': + planeptr = img->Gpix; break; + + case 'B': case 'b': + planeptr = img->Bpix; break; + + case 'A': case 'a': /* canal alpha (transparence) */ + planeptr = img->Apix; break; + + default: + fprintf(stderr, "save image in PHT: bad composante [%c]\n", color); + return WRONG_CHANNEL; + break; + } + +if (planeptr == NULL) + { + fprintf(stderr, "save PHT: planeptr for '%c' is NULL", color); + return WRONG_CHANNEL; + } + +if ( (fp=fopen(name, "wb")) == NULL ) + { + fprintf(stderr, "save PHT: err fopen"); + return FILE_CREATE_ERR; + } + +/* + euh, ya pas un probleme [big/little]endien ici ? + - ben si... + et caisse con fait ? + - on cherche a le regler... + euh, comment ? faudrait acheter une Sparc et une SGI... + +dims[0] = img->width; dims[1] = img->height; +fwrite(dims, sizeof(dims), 1, fp); + + NoN! il faut regarder le module "basic_io.c" :) +*/ +Image_basicIO_write_I_short(fp, img->width); +Image_basicIO_write_I_short(fp, img->height); + +for (foo=0; fooheight; foo++) + { + fwrite(planeptr[foo], img->width, 1, fp); + } + +fclose(fp); +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * Ah, nostalgie, quand tu nous tiens... + */ +Image_Desc * +Image_load_PHT(char *fname) +{ +FILE *fp; +uint16_t width, height; +int foo; + +if ( (fp=fopen(fname, "rb")) == NULL ) + { + fprintf(stderr, "load PHT: err fopen %s", fname); + return NULL; + } + +foo = Image_basicIO_read_I_short(fp, &width); +foo += Image_basicIO_read_I_short(fp, &height); + +fprintf(stderr, "load PHT: width %d, height %d\n", width, height); + +fclose(fp); + +return NULL; +} +/*::------------------------------------------------------------------::*/ diff --git a/png.c b/png.c new file mode 100644 index 0000000..b69aa19 --- /dev/null +++ b/png.c @@ -0,0 +1,39 @@ +/* + + PNG aka "portable network graphics"s. + + + Un vrai merdier, en fait :( + +*/ + +#include +#include +#include + +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +Image_Desc * Image_PNG_alloc_load(char *fname, int k) +{ + + +return 666; +} +/*::------------------------------------------------------------------::*/ +int Image_save_as_PNG(Image_Desc *img, char *fname, int p1, int p2) +{ +FILE *fp; +int x, y; +png_uint_32 pngv; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2); +fprintf(stderr, " png version -> %d\n", png_access_version_number()); +#endif + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/pnm.c b/pnm.c new file mode 100644 index 0000000..92462a4 --- /dev/null +++ b/pnm.c @@ -0,0 +1,309 @@ +/* + + PNM aka "portable net map" functions. + + ------------------------------------------------- + + 14 Feb 2000: I don't know if using '-' as a filename for + means STDOUT is really a good thing ? + + 5 June 2001: a priori, pas de "BOUTISME" dans ces fonctions. + + 2 Oct 2001: voir aussi 'pov_hf15.c' pour une sauvegarde des + height_fields en PGM 15 bits. + +*/ + +#include +#include +#include + +#include "tthimage.h" + +#define TAILLE_MAX_LIGNE 75 +#define VERSION_STRING "December 2009" + +/*::------------------------------------------------------------------::*/ +/* + * this func write a bitmap from the hight bit of the + * selected channel: R, G or B. + * Parameter 'channel' is not case sensitive. + */ +int +Image_wr_pbm_0(char *nom, Image_Desc *im, char channel) +{ +FILE *fp; +int x, y; +int r, g, b; +int par_ligne; + +/* + * maybe we can here make a sanity check on the 'channel' par ? + */ +if ( ! strcmp("-", nom)) + { + fputs("PBM go to stdout...\n", stderr); + fp = stdout; + } +else + { +#if DEBUG_LEVEL + fprintf(stderr, "create the PBM file '%s'\n", nom); +#endif + if ((fp=fopen(nom, "w")) == NULL) + { + fputs("ecriture PBM err fopen\n", stderr); + return FILE_CREATE_ERR; + } + } + +fprintf(fp, "P1\n %d %d\n", im->width, im->height); +fprintf(fp, "# written by libimage v %s, pnm module %s\n", + IMAGE_VERSION_STRING, VERSION_STRING); + +if (strlen(im->name) > 0) + { + fprintf(fp, "# image name: %s\n", im->name); + } + +par_ligne = 0; +for (y=0; yheight; y++) + { + + for (x=0; xwidth; x++) + { + Image_getRGB(im, x, y, &r, &g, &b); + + switch (channel) + { + case 'R': case 'r': + if (r & 0x80) fputs("0", fp); + else fputs("1", fp); + break; + + case 'G': case 'g': + if (g & 0x80) fputs("0", fp); + else fputs("1", fp); + break; + + case 'B': case 'b': + if (b & 0x80) fputs("0", fp); + else fputs("1", fp); + break; + + default: + fprintf(stderr, "bad channel %c\n", channel); + break; + } + + par_ligne += 1; + /* + * logic for limiting length of lines + */ + if (par_ligne > 74) + { + fputs("\n", fp); + par_ligne = 0; + } + } + } + +#if DEBUG_LEVEL +fprintf(fp, "# hello %d times, f.m.b.l folks !\n", getpid()); +#endif + +fputs("\n", fp); +fclose(fp); + +im->modified = 0; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * si mode == 0 alors "ascii" sinon "rawbits" + * que faire si l'image a un canal 'alpha' ? + * + * 27 Jan 2003: En fait, le nom officiel est 'Portable Pix Map', + * donc le nom de la fonction est _très_ mal choisi. + * + */ +int +Image_wr_pnm_0(char *nom, Image_Desc *im, int mode) +{ +fprintf(stderr, "*** WARNING. Use 'Image_wr_ppm_0' now !\n"); +return Image_wr_ppm_0(nom, im, mode); +} +/* + * 27 Jan 2003: je renomme donc la fonction, et je crée un alias + * pour la sacro-sainte compatibilité ascendante :) + */ +#define PPM_BUFSIZE 20000 +int +Image_wr_ppm_0(char *nom, Image_Desc *im, int mode) +{ +FILE *fp; +int par_ligne, foo, x, y, r, g, b; +#if DEBUG_LEVEL +char buffer[PPM_BUFSIZE]; +#endif + +#if DEBUG_LEVEL +fprintf(stderr, "ecriture image %p dans PPM %s (mode %d)\n", im, nom, mode); +#endif + +if ( ! strcmp("-", nom)) + { + fputs("PPM go to stdout...\n", stderr); + fp = stdout; + } +else + { +#if DEBUG_LEVEL + fprintf(stderr, "create a PPM file named '%s'\n", nom); +#endif + if ((fp=fopen(nom, "w")) == NULL) + { + fputs("ecriture PPM err fopen\n", stderr); + return FILE_CREATE_ERR; + } + /* new December 27, 2005 */ + /* setbuffer(fp, buffer, PPM_BUFSIZE);*/ + } + +fprintf(fp, "P3\n%d %d\n255\n", im->width, im->height); +fprintf(fp, "# written by libimage v %s, ppm module '%s'\n\n", + IMAGE_VERSION_STRING, VERSION_STRING); + +if (strlen(im->name) > 0) + { + fprintf(fp, "# image name: %s\n", im->name); + } + +for (y=0; yheight; y++) + { + par_ligne = 0; + + for (x=0; xwidth; x++) + { + /* Image_getRGB(im, x, y, &r, &g, &b); */ + r = (im->Rpix[y])[x]; + g = (im->Gpix[y])[x]; + b = (im->Bpix[y])[x]; + foo = fprintf(fp, "%d %d %d ", r, g, b); + par_ligne += foo; + if (par_ligne > TAILLE_MAX_LIGNE) + { + fputs("\n", fp); + par_ligne = 0; + } + } +#if DEBUG_LEVEL + fprintf(fp, "# end line %d\n", y); +#else + fputs("\n", fp); +#endif + } + +if (fp != stdout) fclose(fp); + +im->modified = 0; + +return 0; +} +/*::------------------------------------------------------------------::*/ +int +Image_ppm_load_0(char *name, Image_Desc *p_ou, int reserved) +{ + +fprintf(stderr, "Image: charger PNM %s dans %p\n", name, p_ou); + +/* + * bon, maintenant, on est au pied du mur, il faut + * parser l'en-tete. + */ + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +int +Image_wr_pgm_0(char *nom, Image_Desc *im, char channel) +{ +FILE *fp; +int x, y, foo, pixel, par_ligne; + +if ( ! strcmp("-", nom)) + { + fputs("PGM go to stdout...\n", stderr); + fp = stdout; + } +else + { + fprintf(stderr, "create a PGM file named '%s'\n", nom); + if ((fp=fopen(nom, "w")) == NULL) + { + fputs("ecriture PGM err fopen\n", stderr); + return FILE_CREATE_ERR; + } + } + +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", + IMAGE_VERSION_STRING, VERSION_STRING); + +for (y=0; yheight; y++) + { + par_ligne = 0; + + for (x=0; xwidth; x++) + { + switch (channel) + { + case 'r': case 'R': + pixel = Image_R_pixel(im, x, y); + break; + case 'g': case 'G': + pixel = Image_G_pixel(im, x, y); + break; + case 'b': case 'B': + pixel = Image_B_pixel(im, x, y); + break; + default: + pixel = 42; + break; + } + + foo = fprintf(fp, "%d ", pixel); + par_ligne += foo; + + if (par_ligne > TAILLE_MAX_LIGNE) + { + fputs("\n", fp); + par_ligne = 0; + } + } +#if DEBUG_LEVEL + fprintf(fp, "\n# end of image line %d\n", y); +#else + fputs("\n", fp); +#endif + } + +if (fp != stdout) fclose(fp); + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * oulala, il reste du travail, là... + */ +int +Image_pgm_alloc_load(char *nom) +{ + +fprintf(stderr, "Image_pgm_alloc_load(%s): pas fait...\n", nom); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/ptlist.c b/ptlist.c new file mode 100644 index 0000000..85a083d --- /dev/null +++ b/ptlist.c @@ -0,0 +1,276 @@ +/* + ptlist.c + ======== + primitives for lists of picture points. + new 1999, 2001 ? +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_print_point(Image_Point *ppt) +{ +printf(" xy %-4d %-4d c %-3d h %d\n", ppt->x, ppt->y, ppt->c, ppt->h); +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_dump(Image_PtList *pl, char *txt) +{ +fprintf(stderr, "---+---------------\n"); +fprintf(stderr, " | %s\n", txt); +fprintf(stderr, " | ptlist @ %p\n", pl); +fprintf(stderr, " | w %d h %d\n", pl->width, pl->height); +fprintf(stderr, " | name '%s'\n", pl->name); +fprintf(stderr, " | nbre %d alloc %d\n", pl->nbre, pl->alloc); +fprintf(stderr, "---+---------------\n"); +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +Image_PtList * +Image_ptl_alloc(int nbre, char *name) +{ +Image_PtList *ptr; + +#if DEBUG_LEVEL +fprintf(stderr, "Image PtList: alloc: %d '%s'\n", nbre, name); +#endif + +if ( (ptr=malloc(sizeof(Image_PtList)))==NULL) + { + fprintf(stderr, "Image PtList: struct malloc failed\n"); +#if FORCE_ABORT + abort(); +#endif + return NULL; + } + +ptr->control = 0xfde9601a; /* oh, a fucking magic number */ +ptr->width = ptr->height = 0; +ptr->nbre = 0; +ptr->alloc = nbre; +if (strlen(name) < IMG_OBJNAME_LEN) + strcpy(ptr->name, name); +else + strcpy(ptr->name, "name too long"); + +if ( (ptr->points=malloc(sizeof(Image_Point)*nbre))==NULL) + { + fprintf(stderr, "Image PtList: array malloc failed\n"); +#if FORCE_ABORT + abort(); +#endif + return NULL; + } + +return ptr; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_add(Image_PtList *ptl, int x, int y, int h, int c) +{ +Image_Point *ptrpt; +int newsize, idx; + +#if DEBUG_LEVEL > 2 +fprintf(stderr, "Image PtList: addpt to %p: %5d %5d %5d %5d\n", + ptl, x, y, h, c); +#endif + +/* in first, we check if this is a valid point list */ + +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "ptl addpt: invalid point list %p\n", ptl); +#if FORCE_ABORT + abort(); +#endif + return FULL_NUCKED; + } +/* + * in second, we check if we have room for the new point. + */ +if (ptl->nbre==ptl->alloc) + { + newsize = ptl->alloc + 200; + fprintf(stderr, "ptl: realloc array %d\n", newsize); + if ((ptrpt=realloc(ptl->points, sizeof(Image_Point)*newsize))==NULL) + { + fprintf(stderr, "%s: REALLOC FAIL\n", __func__); + exit(5); + } + ptl->points = ptrpt; + ptl->alloc = newsize; + } + +idx = ptl->nbre; +ptl->points[idx].x = x; +ptl->points[idx].y = y; +ptl->points[idx].h = h; +ptl->points[idx].c = c; +ptl->nbre = idx + 1; + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * attention, il est _important_ de respecter le format d'écriture + * parce que les fichiers de liste de points sont parfois relus par + * des programmes FORTRAN, beaucoup plus pointilleux sur le + * formatage des données. + */ +int +Image_ptl_write(char *filename, Image_PtList *ptl) +{ +FILE *fp; +int foo; + +if ( (fp=fopen(filename, "w"))==NULL ) + { + fprintf(stderr, "Image PtList: write: fopen fail.\n"); + return FILE_CREATE_ERR; + } + +fprintf(fp, "%8d\n", ptl->nbre); +fprintf(fp, "%08d%08d\n", ptl->width, ptl->height); +fprintf(fp, "%08d%08d\n", 42, 42); /* reserved */ +for (foo=0; foonbre; foo++) + { + fprintf(fp, "%8d%8d%8d%8d\n", + ptl->points[foo].x, ptl->points[foo].y, + ptl->points[foo].h, ptl->points[foo].c); + } + +fclose(fp); + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_read(char *filename, Image_PtList *ptl) +{ +FILE *fp; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( '%s' %p )\n", __func__, filename, ptl); +#endif + +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "%s: no deadbeef in %p\n", __func__, ptl); + return 666; + } + +/* doit-on utiliser un "must_open" ici ? */ + + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* destruction d'une liste de points */ +int +Image_ptl_kill(Image_PtList *ptl, char *msg) +{ +#if DEBUG_LEVEL +fprintf(stderr, "Killing point list %p for '%s'\n", ptl, msg); +#endif + +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "%s: no deadbeef in %p\n", __func__, ptl); + return 666; + } + +/* killing the array */ +free(ptl->points); ptl->points = NULL; +ptl->control = 0; + +/* killing the struct */ +free(ptl); + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_get_size(Image_PtList *ptl, int *nbre, int *alloc) +{ +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "%s: no deadbeef in %p\n", __func__, ptl); + return 666; + } +if (NULL != nbre) *nbre = ptl->nbre; +if (NULL != alloc) *alloc = ptl->alloc; + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_get_point(Image_PtList *ptl, Image_Point *pt, int idx) +{ +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "%s: no deadbeef in %p\n", __func__, ptl); + return 666; + } +if (idx < 0) + { + fprintf(stderr, "%s:%s point idx %d is negative, so bad !\n", + __FILE__, __func__, idx); + return FULL_NUCKED; + } +if (idx>ptl->nbre) + { + fprintf(stderr, "%s:%s point idx %d is too big, so bad !\n", + __FILE__, __func__, idx); + return FULL_NUCKED; + } + +memcpy(pt, &(ptl->points[idx]), sizeof(Image_Point)); + +#if DEBUG_LEVEL > 3 +fprintf(stderr, "%s: %p %d -> %d %d\n", __func__, ptl, idx, pt->x, pt->y); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +int +Image_ptl_boundingbox(Image_PtList *ptl, Image_Rect *box) +{ +int xmin, ymin, xmax, ymax; +int foo; + +if (ptl->control != 0xfde9601a) + { + fprintf(stderr, "%s: no deadbeef in %p\n", __func__, ptl); + return 666; + } + +xmin = ymin = 999999999; +xmax = ymax = -999999999; + +for (foo=0; foonbre; foo++) + { + if (ptl->points[foo].x < xmin) xmin = ptl->points[foo].x; + if (ptl->points[foo].x > xmax) xmax = ptl->points[foo].x; + if (ptl->points[foo].y < ymin) ymin = ptl->points[foo].y; + if (ptl->points[foo].y > ymax) ymax = ptl->points[foo].y; + } + +box->x = xmin; box->y = ymin; +box->w = xmax - xmin; box->h = ymax - ymin; + +#if DEBUG_LEVEL +Image_dump_rect(box, "calcul bounding box of a ptlist", 1); +#endif + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/quadpics.c b/quadpics.c new file mode 100644 index 0000000..584372d --- /dev/null +++ b/quadpics.c @@ -0,0 +1,185 @@ +/* + * quadpics.c - jeux sur les symetries - juin 2014 a Myrys + */ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * fonction de test, ne pas utiliser, le wrapper est un + * peu plus bas. + */ + +int Image_quadpics_proto_0(Image_Desc *img, int k) +{ +Image_Desc *tmp; +int x, y, r, g, b; +int dims; + +#if DEBUG_LEVEL +fprintf(stderr, ">> %s ( %p %d )\n", __func__, img, k); +#endif + +/* duplicate the image */ +if (NULL==(tmp=Image_clone(img, 0))) + { + fprintf(stderr, "in %s, no mem for cloning %p\n", __func__, img); +#if FORCE_ABORT + abort(); +#endif + return IMAGE_NO_MEM; + } + +dims = img->width / 2; + +#if DEBUG_LEVEL +fprintf(stderr, " dim/2 -> %d\n", dims); +#endif +for (y=0; yRpix[y*2][x*2]; + g = img->Gpix[y*2][x*2]; + b = img->Bpix[y*2][x*2]; + + /* upper left */ + tmp->Rpix[y][x] = r; + tmp->Gpix[y][x] = g; + tmp->Bpix[y][x] = b; + + /* upper right */ + tmp->Rpix[y][dims+dims-x-1] = r; + tmp->Gpix[y][dims+dims-x-1] = g; + tmp->Bpix[y][dims+dims-x-1] = b; + + /* lower left */ + tmp->Rpix[dims+dims-y-1][x] = r; + tmp->Gpix[dims+dims-y-1][x] = g; + tmp->Bpix[dims+dims-y-1][x] = b; + + /* lower right */ + tmp->Rpix[dims+dims-y-1][dims+dims-x-1] = r; + tmp->Gpix[dims+dims-y-1][dims+dims-x-1] = g; + tmp->Bpix[dims+dims-y-1][dims+dims-x-1] = b; + + } + } + +/* copy tmp pics to caller's img */ +Image_copy(tmp, img); +/* kill duplicate */ +Image_DeAllocate(tmp); free(tmp); + +return 666; +} +/*::------------------------------------------------------------------::*/ +int Image_quadpics_proto_1(Image_Desc *img, Image_Desc *dst) +{ +int x, y, r, g, b; +int dims; + +#if DEBUG_LEVEL +fprintf(stderr, ">> %s ( %p %p )\n", __func__, img, dst); +#endif + +dims = img->width / 2; + +#if DEBUG_LEVEL +fprintf(stderr, " dim/2 -> %d\n", dims); +#endif +for (y=0; yRpix[y*2][x*2]; + g = img->Gpix[y*2][x*2]; + b = img->Bpix[y*2][x*2]; + + /* upper left */ + dst->Rpix[y][x] = r; + dst->Gpix[y][x] = g; + dst->Bpix[y][x] = b; + + /* upper right */ + dst->Rpix[x][y+dims] = r; + dst->Gpix[x][y+dims] = 0; + dst->Bpix[x][y+dims] = 0; + + /* lower leftt */ + dst->Rpix[x+dims][y] = r; + dst->Gpix[x+dims][y] = g; + dst->Bpix[x+dims][y] = b; + } + } + +return 666; +} +/*::------------------------------------------------------------------::*/ +/* + * wrapper for simplest functions + */ +int Image_quadsym_simple(Image_Desc *src, Image_Desc *dst, int mode) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, mode); +#endif + +/* + * check validity of both images + */ +if ( src->width != src->height ) + { + fprintf(stderr, "in %s, source img %p is not square.\n", __func__, src); +#if FORCE_ABORT + abort(); +#endif + return UNKNOW_ERROR; + } +if ( foo=Image_compare_desc(src, dst) ) + { + fprintf(stderr, "err dims %d\n", foo); + return foo; + } + +/* all things all right ? Ok, go compute 4picz */ + +foo = UNKNOW_ERROR; /* assume broken code */ + +switch (mode) + { + case -1: + fprintf(stderr, "Magic Cow enabled\n"); + break; + + case 0: + Image_copy(src,dst); + foo = Image_quadpics_proto_0(dst, mode); + break; + + case 1: + Image_copy(src,dst); + foo = Image_quadpics_proto_1(src, dst); + break; + + default: + fprintf(stderr, "Magic Cow disabled\n"); + break; + + } + +#if DEBUG_LEVEL +fprintf(stderr, "in %s, action return code was %d\n", __func__, foo); +#endif + +return 666; +} +/*::------------------------------------------------------------------::*/ + diff --git a/rgbmask.c b/rgbmask.c new file mode 100644 index 0000000..b1bc8cd --- /dev/null +++ b/rgbmask.c @@ -0,0 +1,184 @@ + +/* + rgbmask.c + ---------------- + WORK IN PROGRESS + - manque de documentation, toussa - +*/ + +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * horizontal lines + */ +int +Image_rgbmask_H(Image_Desc *src, Image_Desc *dst, int gris) +{ +int foo, x, y; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +Image_copy(src, dst); /* XXX pourquoi cette copie ? */ + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + switch (y%3) + { + case 0: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + case 1: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'b', x, y, gris); + break; + case 2: + Image_plot_channel(dst, 'b', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * vertical lines + */ +int +Image_rgbmask_V(Image_Desc *src, Image_Desc *dst, int gris) +{ +int foo, x, y; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image rgbmask V: images are differents %d\n", foo); + return foo; + } + +Image_copy(src, dst); + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + switch (x%3) + { + case 0: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + case 1: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'b', x, y, gris); + break; + case 2: + Image_plot_channel(dst, 'b', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * sequential dots - _very_ dependant on image dimensions. + */ +int +Image_rgbmask_2(Image_Desc *src, Image_Desc *dst, int gris) +{ +int foo, x, y; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image rgbmask 2: images are differents %d\n", foo); + return foo; + } +Image_copy(src, dst); + +foo = 0; +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + foo++; + switch (foo%3) + { + case 0: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + case 1: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'b', x, y, gris); + break; + case 2: + Image_plot_channel(dst, 'b', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * random dots - VERY BAD RESULTS :( + */ +int +Image_rgbmask_R(Image_Desc *src, Image_Desc *dst, int gris) +{ +int foo, x, y; + +#if DEBUG_LEVEL +fprintf(stderr, "this function, %s(%d), is very buggy...\n", __func__, gris); +#endif + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image rgbmask R: images are differents %d\n", foo); + return foo; + } +Image_copy(src, dst); + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + foo = rand() % 3; /* mmmm pas tres bon :( */ + switch (foo) + { + case 0: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + case 1: + Image_plot_channel(dst, 'r', x, y, gris); + Image_plot_channel(dst, 'b', x, y, gris); + break; + case 2: + Image_plot_channel(dst, 'b', x, y, gris); + Image_plot_channel(dst, 'g', x, y, gris); + break; + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ diff --git a/sobel4.c b/sobel4.c new file mode 100644 index 0000000..e3faed6 --- /dev/null +++ b/sobel4.c @@ -0,0 +1,73 @@ +/* + * Sobel4 new 26 avril 2007 - Fonsegrives + * ====== =============================== + */ + +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_filtre_Sobel_4(Image_Desc *src, Image_Desc *dst, int rotation) +{ +static int Sobel[] = + { + 1, 2, 1, + 0, 0, 0, + -1, -2, -1, + 1, 128 + }; +int filtre[11], foo; +Image_Desc *tmp[4]; +int x, y, r, g, b; + +memcpy(filtre, Sobel, 11*sizeof(int)); + +for (foo=0; foo<4; foo++) + { + fprintf(stderr, "sobel4: pass %d\n", foo); + if (NULL == (tmp[foo] = Image_clone(src, 0))) + { + fprintf(stderr,"Sobel 4: no memory, aborting\n"); + abort(); + } + Image_convolueur_2(src, tmp[foo], filtre, "rgb"); + Image_rotate_filtre(filtre); + Image_rotate_filtre(filtre); + } + +for (x=0; xwidth; x++) + { + for (y=0; yheight; y++) + { + r = ( tmp[0]->Rpix[y][x] + tmp[1]->Rpix[y][x] + + tmp[2]->Rpix[y][x] + tmp[3]->Rpix[y][x]) / 4; + g = ( tmp[0]->Gpix[y][x] + tmp[1]->Gpix[y][x] + + tmp[2]->Gpix[y][x] + tmp[3]->Gpix[y][x]) / 4; + b = ( tmp[0]->Bpix[y][x] + tmp[1]->Bpix[y][x] + + tmp[2]->Bpix[y][x] + tmp[3]->Bpix[y][x]) / 4; + + dst->Rpix[y][x] = r; + dst->Gpix[y][x] = g; + dst->Bpix[y][x] = b; + } + } + +dst->modified = 1; + +for (foo=0; foo<4; foo++) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "%s: freeing %d\n", __func__, foo); +#endif + Image_DeAllocate(tmp[foo]); free(tmp[foo]); + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ + diff --git a/tamppool.c b/tamppool.c new file mode 100644 index 0000000..b87904f --- /dev/null +++ b/tamppool.c @@ -0,0 +1,66 @@ +/* + * tamppool.c new 21 mars 2007 - ave St Exupery + * ------------------------------------------------- + */ + +#include +#include +#include "tthimage.h" +/*::------------------------------------------------------------------::*/ +#define TAMPPOOL_VERSION "0.0.3" +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +void +Image_Pool_infos(int flag) +{ +printf("*** Images Pools v %s, %s\n", TAMPPOOL_VERSION, __DATE__); + +if (flag) + { + printf(" taille des noms: %d\n", IMG_OBJNAME_LEN); + + } +} +/*::------------------------------------------------------------------::*/ +void * +Image_Pool_create(char *name, int nbre, int width, int height) +{ +fprintf(stderr, "Image Pool Create '%s', %d, %d x %d\n", + name, nbre, width, height); + +return NULL; +} +/*::------------------------------------------------------------------::*/ +int +Image_Pool_describe(void *ptr, char *text, int flags) +{ + +printf("+p+ Image Pool describe, explanation '%s'\n", text); +printf("+p+ descriptor is at %p\n", ptr); +if (flags) + printf("+p+ flag is not zero\n"); + +if (NULL == ptr) + { + fprintf(stderr, "Image Pool descriptor is NULL\n"); + return NULL_DESCRIPTOR; + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int +Image_Pool_destroy(void *ptr, char *text, int flags) +{ +fprintf(stderr, "Image Pool %p Destroy '%s'\n", ptr, text); + +if (flags) + { + fprintf(stderr, "%s: flag = %d\n", __func__, flags); + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/tele_2.c b/tele_2.c new file mode 100644 index 0000000..b0ba873 --- /dev/null +++ b/tele_2.c @@ -0,0 +1,316 @@ +/* + tele_2.c + -------- +*/ + +#include +#include +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * comme au bon vieux temps... + */ +int +Image_TV_old(Image_Desc *src, Image_Desc *dst, int p1, int p2, int p3) +{ +int foo; +int x, y, v1, v2; +int resteY; +int sigma; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +sigma = p1 + p2 + p3; +if (!sigma) sigma++; + +resteY = src->height % 3; +resteY /= 2; /* half for the top, half for the bottom */ + +#if DEBUG_LEVEL +fprintf(stderr, "%s : height %d reste Y %d\n", __func__, src->height, resteY); +fprintf(stderr, "%s : %d %d %d -> %d\n", __func__, p1, p2, p3, sigma); +#endif + +for (y=resteY; yheight-resteY-1; y+=3) + { + for (x=0; xwidth; x++) + { + v1 = ( Image_R_pixel(src, x, y) + + Image_R_pixel(src, x, y+1) + + Image_R_pixel(src, x, y+2) + + Image_G_pixel(src, x, y) + + Image_G_pixel(src, x, y+1) + + Image_G_pixel(src, x, y+2) + + Image_B_pixel(src, x, y) + + Image_B_pixel(src, x, y+1) + + Image_B_pixel(src, x, y+2) ) / 9 ; + + v2 = (v1 * p1) / sigma; + Image_plotRGB(dst, x, y, v2, v2, v2); + v2 = (v1 * p2) / sigma; + Image_plotRGB(dst, x, y+1, v2, v2, v2); + v2 = (v1 * p3) / sigma; + Image_plotRGB(dst, x, y+2, v2, v2, v2); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * this is juste a wrapper function - need more work... + */ +int +Image_TV_veryold(Image_Desc *src, Image_Desc *dst, int p1, int p2, int p3) +{ +int foo; + +/* 15 janvier 2007: chasse au coredump... */ +if ( (src->magic!=MAGIC_OF_IMAGE) || (dst->magic!=MAGIC_OF_IMAGE) ) + { + fprintf(stderr, "Image TV veryold: bad image descriptor\n"); + abort(); + } + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "Image TV veryold: images are differents %d\n", foo); + return foo; + } + +foo = Image_TV_old(src, dst, p1, p2, p3); +fprintf(stderr, "%s : ret %d\n", __func__, foo); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * new 10 novembre 2013, in mixart-myrys + */ +int +Image_TV_pix_0(Image_Desc *src, Image_Desc *dst, int w, int h, int grey) +{ +int foo, ox, oy; +int x, y, r, g, b; +int xmax, ymax; +Image_Rect zone; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +#if DEBUG_LEVEL + fprintf(stderr, "%s : w %d h %d grey %d\n", __func__, w, h, grey); +#endif + +if (0==h || 0==w) + { + return BAD_PARAMETER; + } + +zone.w = w-1; zone.h = h-1; +xmax = src->width - w; ymax = src->height - h; +ox = (src->width % w) / 2; +oy = (src->height % h) / 2; +#if DEBUG_LEVEL +fprintf(stderr, "%s : offsets = %d %d\n", __func__, ox, oy); +#endif +Image_clear(dst, grey, grey, grey); + +for (x=ox; xRpix[y][x] & 0xfe; + g = src->Gpix[y][x] & 0xfe; + b = src->Bpix[y][x] & 0xfe; + + Image_paint_rect(dst, &zone, r, g, b); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* + * new 10 novembre 2013, in mixart-myrys + */ +int Image_TV_pix_1(Image_Desc *src, Image_Desc *dst, int w, int h, int p3) +{ +int foo; +int x, y, v1, v2, r, g, b; +int xmax, ymax; +Image_Rect zone; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s : w %d h %d g%d\n", __func__, w, h, p3); +#endif + +if ((0==h) || (0==w)) + { + return BAD_PARAMETER; + } + +zone.w = w-1; +zone.h = h-1; +xmax = src->width - w; +ymax = src->height - h; +v1 = v2 = 0; + +for (x=0; xRpix[y][x]; + g = src->Gpix[y][x]; + b = src->Bpix[y][x]; + + Image_paint_rect(dst, &zone, r, g, b); + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ +/* + * new 3 jan 203 - at Mixart-Myrys + */ +int Image_TV_cplus_v1(Image_Desc *src, Image_Desc *dst, int p) +{ +int foo; +int y, taille; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d )\n", __func__, src, dst, p); +#endif + +if (p <= 1) { + fprintf(stderr, "%s: p must be > 1, but was %d\n", __func__, p); + return BAD_PARAMETER; + } + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "%s : images are differents %d\n", __func__, foo); + return foo; + } + +taille = src->width - (abs(p*2)); +#if DEBUG_LEVEL +fprintf(stderr, "%s: largeur %d, taille %d\n", __func__, src->width, taille); +#endif + +Image_gray_noise_0(dst, 20, 60); + +for (y=0; yheight; y++) + { + switch (rand()%3) { + case 0 : + memcpy((dst->Rpix[y]), src->Rpix[y], taille); + memcpy((dst->Gpix[y]), src->Gpix[y], taille); + memcpy((dst->Bpix[y]), src->Bpix[y], taille); + break; + case 1 : + memcpy((dst->Rpix[y])+p, src->Rpix[y], taille); + memcpy((dst->Gpix[y])+p, src->Gpix[y], taille); + memcpy((dst->Bpix[y])+p, src->Bpix[y], taille); + break; + case 2 : + memcpy((dst->Rpix[y])+p+p, src->Rpix[y], taille); + memcpy((dst->Gpix[y])+p+p, src->Gpix[y], taille); + memcpy((dst->Bpix[y])+p+p, src->Bpix[y], taille); + break; + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* new 28 janvier 2015 - MixartMyrys */ +/* le parametre 'mode' est un flag */ + +int Image_TV_triligne(Image_Desc *src, Image_Desc *dst, int mode) +{ +int x, y, tri, v, idx; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %d ) -> ", __func__, src, dst, mode); +if (mode) fprintf(stderr, " rand\n"); +else fprintf(stderr, " modulo\n"); +#endif + +Image_clear(dst, 60, 60, 60); /* XXX necessaire ? */ + +idx = rand() % 42; + +for (y=0; yheight; y++) + { + if (0==mode) { + tri = (idx + y) % 3; + } + else { + tri = rand() % 3; + } +#if DEBUG_LEVEL > 1 + fprintf(stderr, " %5d -> %d\n", y, tri); +#endif + switch (tri) + { + case 0: + for (x=0; x<(src->width)-1; x++) { + v = (src->Rpix[y][x] + src->Rpix[y][x+1]); + dst->Rpix[y][x] = v / 2; + v = (src->Gpix[y][x] + src->Gpix[y][x+1]); + dst->Gpix[y][x] = v / 2; + v = (src->Bpix[y][x] + src->Bpix[y][x+1]); + dst->Bpix[y][x] = v / 2; + } + break; + case 1: + for (x=1; x<(src->width)-1; x++) { + v = src->Rpix[y][x-1] + src->Rpix[y][x+1]; + dst->Rpix[y][x] = v / 2; + v = src->Gpix[y][x-1] + src->Gpix[y][x+1]; + dst->Gpix[y][x] = v / 2; + v = src->Bpix[y][x-1] + src->Bpix[y][x+1]; + dst->Bpix[y][x] = v / 2; + } + break; + case 2: + for (x=1; xwidth; x++) { + v = src->Rpix[y][x] + src->Rpix[y][x-1]; + dst->Rpix[y][x] = v / 2; + v = src->Gpix[y][x] + src->Gpix[y][x-1]; + dst->Gpix[y][x] = v / 2; + v = src->Bpix[y][x] + src->Bpix[y][x-1]; + dst->Bpix[y][x] = v / 2; + } + break; + default: + /* blam< */ + abort(); + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/ diff --git a/television.c b/television.c new file mode 100644 index 0000000..4c15e02 --- /dev/null +++ b/television.c @@ -0,0 +1,289 @@ +/* + television.c + ------------ +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_TV_grink(Image_Desc *src, Image_Desc *dst, int yo) +{ +int foo; +int x, y, r, g, b; +int resteY; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +resteY = src->height % 3; +#if DEBUG_LEVEL +fprintf(stderr, "Image TV grink: height %d reste Y %d\n", src->height, resteY); +#endif +resteY /= 2; /* half for the top, half for the bottom */ + +for (y=resteY; yheight-resteY-1; y+=3) + { + for (x=0; xwidth; x++) + { + r = ( Image_R_pixel(src, x, y) + + Image_R_pixel(src, x, y+1) + + Image_R_pixel(src, x, y+2) ) / 3; + g = ( Image_G_pixel(src, x, y) + + Image_G_pixel(src, x, y+1) + + Image_G_pixel(src, x, y+2) ) / 3; + b = ( Image_B_pixel(src, x, y) + + Image_B_pixel(src, x, y+1) + + Image_B_pixel(src, x, y+2) ) / 3; + Image_plotRGB(dst, x, y, r, g, b); + if (yo) + { + Image_plotRGB(dst, x, y+1, r, b, g); + Image_plotRGB(dst, x, y+2, r, g, b); + } + else + { + Image_plotRGB(dst, x, y+2, r, b, g); + Image_plotRGB(dst, x, y+1, r, g, b); + } + } + } + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_TV_grok(Image_Desc *src, Image_Desc *dst, int yo) +{ +int foo, x, y; +int r, g, b; + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +for (y=0; yheight; y++) + { + for (x=0; xwidth; x++) + { + Image_getRGB(src, x, y, &r, &g, &b); + if (yo) + Image_plotRGB(dst, x, y, r&0xa0, g&0xa0, b&0xa0); + else + Image_plotRGB(dst, x, y, r&0xf0, g&0xf0, b&0xf0); + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ +/* new 8 jan 2002 + * le paramètre 'yo' ne sert à rien et doit être mis à 0 + */ +int +Image_TV_gruud(Image_Desc *src, Image_Desc *dst, int yo) +{ +int x, y, i, j; +int r, g, b, rc, gc, bc; +int foo; + +if (yo != 0) { + fprintf(stderr, "%s: yo (%d) _must_ be 0\n", __func__, yo); + return INVALID_PARAM; + } + +if ( (foo=Image_compare_desc(src, dst)) ) { + fprintf(stderr, "%s: images are differents %d\n",__func__, foo); + return foo; + } + +for (y=0; yheight-2; y+=3) + { + for (x=0; xwidth-2; x+=3) + { + rc = gc = bc = 0; + for (i=0; i<3; i++) + { + for (j=0; j<3; j++) + { + Image_getRGB(src, x+i, y+j, &r, &g, &b); + rc += r; + gc += g; + bc += b; + } + + } + + rc /= 9; gc /= 9; bc /= 9; + for (i=0; i<3; i++) + { + Image_plotRGB(dst, x, y+i, rc, 0, 0); + Image_plotRGB(dst, x+1, y+i, 0, gc, 0); + Image_plotRGB(dst, x+2, y+i, 0, 0, bc); + } + } + } + +return FUNC_IS_BETA; +} +/*::------------------------------------------------------------------::*/ + +#define GRIIIZ_SIZE 20 + +/* + * le paramètre 'yo' ne sert à rien et doit être mis à 0 + */ +int +Image_TV_griiiz(Image_Desc *src, Image_Desc *dst, int yo) +{ +int foo, r, g, b, cr, cg, cb; +int x, y, i, j, ox, oy; + +int mr[GRIIIZ_SIZE][GRIIIZ_SIZE] = + { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 4, 4, 4, 4, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 9, 9, 9, 9, 9, 9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 9, 9, 9, 9, 9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 9, 9, 9, 9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 7, 7, 9, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 7, 7, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 4, 4, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }; + +int mg[GRIIIZ_SIZE][GRIIIZ_SIZE] = + { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 5, 5, 5, 5, 5, 4, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 6, 6, 6, 6, 6, 6, 6, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 8, 9, 9, 8, 7, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 8, 9, 9, 9, 7, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 8, 9, 9, 7, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 7, 8, 7, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 7, 7, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 6, 6, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 1, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }; + +int mb[GRIIIZ_SIZE][GRIIIZ_SIZE] = + { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 2, 4, 5, 7, 4, 2, 2, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 2, 4, 7, 9, 9, 4, 4, 2, 2, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 2, 4, 0, 9, 9, 9, 9, 4, 4, 2, 2, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 2, 5, 7, 8, 9, 9, 9, 9, 9, 7, 5, 2, 1, 0, 0, 0 }, + { 0, 0, 0, 2, 4, 6, 6, 6, 7, 7, 7, 7, 7, 6, 5, 4, 2, 1, 0, 0 }, + { 0, 0, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 3, 2, 1, 0 }, + { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }; + +int kr, kg, kb; + +if (yo != 0) + { + fprintf(stderr, "Image TV griiiz: yo (%d) _must_ be 0\n", yo); + return INVALID_PARAM; + } + +if ( (foo=Image_compare_desc(src, dst)) ) + { + fprintf(stderr, "%s: images are differents %d\n", __func__, foo); + return foo; + } + +ox = (src->width % GRIIIZ_SIZE) / 2; +oy = (src->height % GRIIIZ_SIZE) / 2; +#if DEBUG_LEVEL +fprintf(stderr, "%s : X %d-%d Y %d-%d\n", __func__, + src->width, ox, src->height, oy); +#endif + +kr = kg = kb = 0; +for (i=0; iwidth-(ox+1); x+=GRIIIZ_SIZE) + { + for (y=oy; yheight-(oy+1); y+=GRIIIZ_SIZE) + { + cr = cb = cg = 0; + for (i=0; i +#include +#include +#include +#include + +#include "tthimage.h" +#include "essais.h" + +/*::------------------------------------------------------------------::*/ + +/*::------------------------------------------------------------------::*/ +int main(int argc, char *argv[]) +{ +char *fichier; +int foo; + +printf("\n========== TestTga %s %s ==========\n", __DATE__, __TIME__); +Image_print_version(2); +/* Image_print_sizeof_structs("tth was here"); */ + +if (argc != 2) + { + printf("no args, using the testfile\n"); + fichier = "wou.tga"; + } +else + { + srand(getpid()); + fichier = argv[1]; + } + +Image_start_chrono("Essai", 0); + + +foo = Test_Dithering(fichier, 17); +fprintf(stderr, "essai dithering -> %d\n", foo); + +#if 0 +/* +Test_des_patterns("/tmp/pattt", 0, 0); +foo = Essai_des_jauges(fichier, 17); + */ + +foo = Essai_Extractbits(fichier, 17); + +Essai_des_Glitches(fichier, 900); +Essai_Television(fichier, 10); + +Essai_des_drawings(fichier, 17); +foo = Test_Effects_A(fichier, 17); +Test_des_warpings(fichier, 17); + +foo = Essai_des_Combines(fichier, 17); +fprintf(stderr, "essai combine -> %d\n", foo); +foo = Test_Dithering(fichier, 17); +Essai_des_Contrastes(fichier, 0); + +Essai_anamorphoses(fichier, 0.666, 42); + +Test_copie_de_rectangles(fichier); +Essai_des_7_segments(fichier, 0x0F); +/* Essai_color_2_map(fichier, 0); */ +Essais_plot_Map(5); + +foo = Essai_des_bitplanes("Grgrgr !", 1600, 1200); +printf("retour essai bitplane -> %d\n", foo); + +Test_hf15_synth_fromPtl(fichier, "aaaa.tga"); + +Test_classif(fichier, 0); +Test_new_scale(fichier, 0); + +Essai_des_cadres(fichier, 0); +Essai_luminance(fichier, 0); +Essayer_les_alphas(fichier, 0); + +foo = Essai_de_la_Recursion(fichier, 0); + +#endif + +Image_stop_chrono("Essai", 0); + +/* + * Warning: this function was a GNU/Linuxism ! + */ +#if DEBUG_LEVEL > 1 +malloc_stats(); +#endif + +return 0; +} +/*::------------------------------------------------------------------::*/ diff --git a/tga.c b/tga.c new file mode 100644 index 0000000..a742b56 --- /dev/null +++ b/tga.c @@ -0,0 +1,629 @@ +/* + tga.c + ===== + 7 Oct 2001: les problèmes de boutisme sont réglés. + +*/ + +#include +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +#define LIBTGA_VERSION "0.2.41" + +typedef struct { + uint8_t text_size; + char is_color_map; /* 0=NO, 1=YES */ + char type; + uint16_t map_start, map_length; + char map_bits; + uint16_t x_start, y_start; + uint16_t width, height; + char bits; /* bits per pixel (8, 24) */ + char o_flags; /* orientation flags ? */ + + } Tga_file_header; +/*::------------------------------------------------------------------::*/ +int +Image_TGA_write_header(FILE *fp, Tga_file_header *head) +{ +fwrite (&head->text_size, 1, 1, fp); +fwrite (&head->is_color_map, 1, 1, fp); +fwrite (&head->type, 1, 1, fp); +Image_basicIO_write_I_short(fp, head->map_start); +Image_basicIO_write_I_short(fp, head->map_length); +fwrite (&head->map_bits, 1, 1, fp); +Image_basicIO_write_I_short(fp, head->x_start); +Image_basicIO_write_I_short(fp, head->y_start); +Image_basicIO_write_I_short(fp, head->width); +Image_basicIO_write_I_short(fp, head->height); +fwrite (&head->bits, 1, 1, fp); +fwrite (&head->o_flags, 1, 1, fp); +return 0; +} +/*::------------------------------------------------------------------::*/ +static void +fatal_error(char *txt) +{ +fprintf(stderr, "TGA: (pid:%d) FATAL ERROR: %s\n", getpid(), txt); +#if FORCE_ABORT +abort(); +#endif +exit(10); +} +/*::------------------------------------------------------------------::*/ +static int +tga_pack_line(void) +{ +/* + * ___TODO___ compressed targa file ! + * + * Novembre 2002: il serait temps de s'y mettre... + * + */ +return -1; +} +/*::------------------------------------------------------------------::*/ +/* + * il manque un grand nombre d'options + * + * - la compression ---> URGENT !!! + * - les images a palettes + */ +int +Image_TGA_save(char *nom, Image_Desc *img, int compress) +{ +int ltxt, line, foo; +Tga_file_header head; +FILE *fp; +uint8_t *Rptr, *Gptr, *Bptr, *Aptr; +uint8_t *buffer, *ptr; + +if (nom == NULL) fatal_error("save image: name ptr is NULL"); +if (img == NULL) fatal_error("save image: descriptor is NULL"); + +/* 5 Dec 2001: add a check on img */ +if (img->magic != MAGIC_OF_IMAGE) { + fprintf(stderr, "TGASAVE: need Dead Beef!\n"); + 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... + */ +if (compress != 0) { + fprintf(stderr, "%s: compress %d not implemented\n", + __func__, compress); + } + +/* + 10 Aout 2000: si le nom est "-", alors on ecrit le fichier + sur STDOUT ce qui permet(tra) de faire des CGI :) + */ +if (strcmp("-", nom)) + { + if ( (fp=fopen(nom, "wb")) == NULL ) + { + fprintf(stderr, "filename %s\n", nom); + fatal_error("save TGA image: error fopen"); + } + } +else + { + fp = stdout; + } + +ltxt = strlen(img->comment); +#if DEBUG_LEVEL > 1 +fprintf(stderr, "text size = %d\n", ltxt); +if (ltxt) + fprintf(stderr, " [%s]\n", img->comment); +#endif + +/* first, we populate the file header... */ + +head.text_size = ltxt; +head.x_start = head.y_start = 0; +head.width = img->width; +head.height = img->height; + +head.o_flags = 0; /* XXX a preciser ... */ + +#if DEBUG_LEVEL > 1 +fprintf(stderr, "TGASAVE: img@ %p nb planes: %d\n", img, img->nb_planes); +#endif + +switch (img->nb_planes) + { + case 1: /* images en niveau de gris */ +#if DEBUG_LEVEL + fputs("*** saving gray level image\n", stderr); +#endif + head.type = 3; + head.bits = 8; + break; + + case 3: + head.type = 2; /* uncompressed RGB image */ + head.bits = 24; + head.is_color_map = 0; /* No */ + head.map_start = 0; /* Color */ + head.map_length = 0; /* Map */ + head.map_bits = 0; /* ? (Aout 1999) */ + break; + + case 4: +#if DEBUG_LEVEL + fputs("*!* saving image with alpha channel\n", stderr); +#endif + head.type = 2; /* uncompressed RGB image with alpha */ + head.bits = 32; + head.is_color_map = 0; /* No */ + head.map_start = 0; /* Color */ + head.map_length = 0; /* Map */ + head.map_bits = 0; + head.o_flags = 0x08; /* fixed by Betatech */ + break; + + default: + fprintf(stderr, "img->nb_planes = %d\n", img->nb_planes); + fatal_error("Tga_save_image: unknow type"); + break; + } + +/* + * 2 octobre 2001 - prise en main du BOUTISME + * +fwrite(&head, sizeof(head), 1, fp); + * + * 5 oct 01: il faudrait faire une fonction genre 'ecrire_header_tga' + */ +fwrite (&head.text_size, 1, 1, fp); +fwrite (&head.is_color_map, 1, 1, fp); +fwrite (&head.type, 1, 1, fp); +Image_basicIO_write_I_short(fp, head.map_start); +Image_basicIO_write_I_short(fp, head.map_length); +fwrite (&head.map_bits, 1, 1, fp); +Image_basicIO_write_I_short(fp, head.x_start); +Image_basicIO_write_I_short(fp, head.y_start); +Image_basicIO_write_I_short(fp, head.width); +Image_basicIO_write_I_short(fp, head.height); +fwrite (&head.bits, 1, 1, fp); +fwrite (&head.o_flags, 1, 1, fp); + +/* if we have a comment, write it to the file */ +if (ltxt) { + fwrite(img->comment, 1, ltxt, fp); + } +if ((buffer=calloc(img->width, 4)) == NULL) { + fatal_error("no memory buffer for save operation"); + } + +/* XXX why ? +memset(buffer, 0x55, sizeof(uint8_t)*4*img->width); +*/ + +/* Ahem, now, write all the picture datas to the file... */ +for (line=(img->height-1); line>=0; line--) + { + switch (img->nb_planes) + { + case 1: + fwrite(img->Rpix[line], 1, img->width, fp); + break; + + case 3: + Rptr = img->Rpix[line]; + Gptr = img->Gpix[line]; + Bptr = img->Bpix[line]; + ptr = buffer; + for (foo=0; foowidth; foo++) + { + *ptr++ = Bptr[foo]; + *ptr++ = Gptr[foo]; + *ptr++ = Rptr[foo]; + } + fwrite(buffer, 3, img->width, fp); + break; + + case 4: + Rptr = img->Rpix[line]; + Gptr = img->Gpix[line]; + Bptr = img->Bpix[line]; + Aptr = img->Apix[line]; + ptr = buffer; + for (foo=0; foowidth; foo++) + { + *ptr++ = Bptr[foo]; + *ptr++ = Gptr[foo]; + *ptr++ = Rptr[foo]; + *ptr++ = Aptr[foo]; + } + fwrite(buffer, 4, img->width, fp); + break; + + default: + fatal_error("TGA save image: unknow type..."); + break; + + } + } + +free(buffer); /* 1 Fev 00 */ +img->modified = 0; +if (fp != stdout) fclose(fp); + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 31 Jan 2002 + * save one of the component as a gray TGA file + * + * 1 mars 2002: in fact, it was a palettized 8 bits file + * + */ +int +Image_TGA_save_component(char *nom, Image_Desc *img, char channel, int comp) +{ +int ltxt, line, foo; +FILE *fp; +uint8_t colormap[256*3]; +Tga_file_header head; + +if (img->magic != MAGIC_OF_IMAGE) { + fprintf(stderr, "TGASAVE: need Dead Beef!\n"); + return NOT_AN_IMAGE_DESC; + } + +if (comp != 0) { + fprintf(stderr, "%s : param 'comp' %d invalid\n", __func__, comp); + return BAD_PARAMETER; + } + +if ( (fp=fopen(nom, "wb")) == NULL ) + { + fatal_error("save image: err fopen"); + } + +ltxt = strlen(img->comment); + +head.text_size = ltxt; +head.x_start = head.y_start = 0; +head.width = img->width; +head.height = img->height; +head.is_color_map = 1; + +head.o_flags = 0; /* XXX a preciser ... */ +head.type = 3; /* Grayscale Image */ +head.map_start = 0; +head.map_length = 256; +head.map_bits = 24; +head.bits = 8; + +fwrite (&head.text_size, 1, 1, fp); +fwrite (&head.is_color_map, 1, 1, fp); +fwrite (&head.type, 1, 1, fp); +Image_basicIO_write_I_short(fp, head.map_start); +Image_basicIO_write_I_short(fp, head.map_length); +fwrite (&head.map_bits, 1, 1, fp); +Image_basicIO_write_I_short(fp, head.x_start); +Image_basicIO_write_I_short(fp, head.y_start); +Image_basicIO_write_I_short(fp, head.width); +Image_basicIO_write_I_short(fp, head.height); +fwrite (&head.bits, 1, 1, fp); +fwrite (&head.o_flags, 1, 1, fp); + +/* if we have a comment, write it to the file */ +if (ltxt) fwrite(img->comment, 1, ltxt, fp); + +/* now, populate the colormap */ +for (foo=0; foo<256; foo++) + { + colormap[foo*3+0] = foo; + colormap[foo*3+1] = foo; + colormap[foo*3+2] = foo; + } +/* and write the colormap */ +fwrite (colormap, 256, 3, fp); + +for (line=(img->height-1); line>=0; line--) + { + switch (channel) + { + case 'r': case 'R': + fwrite(img->Rpix[line], 1, img->width, fp); + break; + case 'g': case 'G': + fwrite(img->Gpix[line], 1, img->width, fp); + break; + case 'b': case 'B': + fwrite(img->Bpix[line], 1, img->width, fp); + break; + } + } + +fclose(fp); +fprintf(stderr, "AIE! this func (tga save component as gray) is bogus\n"); + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* new 16 fevrier 2009 - ave St Exupery */ +static char * tgatype2txt(int type) +{ +switch (type) + { + case 2: return "Uncomp RGB"; + case 3: return "Uncomp Gray"; + case 4: return "Uncomp RGB + alpha"; + } + +return "Gni ?"; +} +/*::------------------------------------------------------------------::*/ +/* new 17 mars 2007 */ +int +Image_TGA_print_header(Tga_file_header *ph) +{ +if (NULL == ph) { + fprintf(stderr, "null head ptr in '%s'\n", __func__); + return 1; + } +printf("+-- TGA v %s header @ %p ---\n", LIBTGA_VERSION, ph); +printf("| comment size %d\n", ph->text_size); +printf("| is color map ? %d\n", ph->is_color_map); +printf("| type %d %s\n", + ph->type, tgatype2txt(ph->type)); +printf("| map start %d\n", ph->map_start); +printf("| map length %d\n", ph->map_length); +printf("| map bits %d\n", ph->map_bits); +printf("| x start %d\n", ph->x_start); +printf("| y start %d\n", ph->y_start); +printf("| width %d\n", ph->width); +printf("| height %d\n", ph->height); +printf("| nbr of bits %d\n", ph->bits); +printf("| o_flags $%02X\n", ph->o_flags); +printf("+---------------------------\n"); +return 0; +} +/*::------------------------------------------------------------------::*/ +/* new 13 mars 2007 */ +int +Image_TGA_read_header(FILE *fp, void *pvoid) +{ +Tga_file_header *phead; +int foo; + +phead = (Tga_file_header *)pvoid; + +foo = fread(&phead->text_size, 1, 1, fp); +if (foo != 1) + { + fprintf(stderr, "TGA READ HEAD: err read first byte of header\n"); + return VERY_STRANGE; + } +fread(&phead->is_color_map, 1, 1, fp); +fread(&phead->type, 1, 1, fp); +foo = Image_basicIO_read_I_short(fp, &phead->map_start); +/* fprintf(stderr, "foo=%d\n", foo); */ +Image_basicIO_read_I_short(fp, &phead->map_length); +fread(&phead->map_bits, 1, 1, fp); +Image_basicIO_read_I_short(fp, &phead->x_start); +Image_basicIO_read_I_short(fp, &phead->y_start); + +phead->width = phead->height = -1; +Image_basicIO_read_I_short(fp, &phead->width); +Image_basicIO_read_I_short(fp, &phead->height); +if ( (phead->width<1) || (phead->width<1) ) + { + fprintf(stderr, "HEAD TGA: dimension < 1: %d %d\n", + phead->width, phead->height); + return VERY_STRANGE; + } + +fread(&phead->bits, 1, 1, fp); +if ( fread(&phead->o_flags, 1, 1, fp) != 1) { + fprintf(stderr, "HEAD TGA: end of file before time...\n"); + return VERY_STRANGE; + } + +#if DEBUG_LEVEL > 1 +Image_TGA_print_header(phead); +#endif + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 1er mai 2007 (la france qui bosse tout le temps) */ +int +Image_TGA_show_header(char *filename, int flag) +{ +FILE *fp; +Tga_file_header header; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p 0x%04x )\n", __func__, filename, flag); +#endif + +if ( NULL == (fp=fopen(filename, "rb")) ) { + fprintf(stderr, "can't open %s\n", filename); + return FILE_NOT_FOUND; + } +foo = Image_TGA_read_header(fp, &header); +if (foo) { + fprintf(stderr, "lecture header -> %d\n", foo); + } + +foo = Image_TGA_print_header(&header); +if (foo) + { + ; + } + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +/* new 13 mars 2007 */ +int +Image_TGA_get_dims(char *path, int *pwidth, int *pheight) +{ +FILE *fp; +Tga_file_header head; +int foo; + +*pwidth = *pheight = 0; + +if ( (fp=fopen(path, "rb")) == NULL ) + { + fprintf(stderr, "TGA READ HEADER: file '%s' is not readable\n", path); + return FILE_NOT_FOUND; + } + +foo = Image_TGA_read_header(fp, &head); +fclose(fp); +if (foo) { + fprintf(stderr, "%s: lecture header '%s' -> %d\n", + __func__, path, foo); + } + +if (OLL_KORRECT != foo) { + *pwidth = *pheight = 0; + return foo; + } + +/* verification de coerence du header lu */ +if (head.is_color_map!=0 && head.is_color_map!=1) + { + fprintf(stderr, "suspicious 'is_color_map' 0x%02x\n", + head.is_color_map); + } + +*pwidth = (int)head.width; +*pheight = (int)head.height; + +#if DEBUG_LEVEL +fprintf(stderr, "%s --> %d x %d\n", path, (int)head.width, (int)head.height); +#endif + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * pour le moment, cette fonction ne charge + * que les images RGB. il manque le GRIS !!! + * ! il manque aussi la decompression ! + */ +Image_Desc * +Image_TGA_alloc_load(char *nom) +{ +Tga_file_header head; +FILE *fp; +Image_Desc *image = NULL; +uint8_t *buffer; +int ligne, ligne2, col, foo, alpha; +int imagetype; + +if ( (fp=fopen(nom, "rb")) == NULL ) + { + fprintf(stderr, "%s : file '%s' not readable\n", __func__, nom); + return NULL; + } + +memset(&head, 0, sizeof(Tga_file_header)); + +foo = Image_TGA_read_header(fp, &head); + +#if DEBUG_LEVEL > 1 +printf("TGA ALLOC LOAD: read header -> %d\n", foo); +printf("comment size %d\n", head.text_size); +printf("is color map ? %d\n", head.is_color_map); +printf("type %d\n", head.type); +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); +#endif + +switch (head.type) + { + case 2: +#if DEBUG_LEVEL > 1 + fprintf(stderr, "load file %s, type 2, %d bits\n", nom, head.map_bits); +#endif + + if (head.bits == 24) { + alpha = 0; imagetype = IMAGE_RGB; + } + else { + alpha = 1; imagetype = IMAGE_RGBA; + } + + if ( (image=Image_alloc(head.width, head.height, 3+alpha))==NULL) + fatal_error("no memory for picture in 'alloc_load'\n"); + if ( (buffer=(uint8_t *)malloc(4*head.width))==NULL) + fatal_error("no memory for buffer in 'alloc_load'\n"); + +#if DEBUG_LEVEL > 1 + fprintf(stderr, " ... mem allocated\n"); + + if (head.o_flags & 0x20) + fprintf(stderr, "flags= 0x%02x Upside-Down ?\n", head.o_flags); + if (head.o_flags & 0x10) + fprintf(stderr, "flags= 0x%02x Left-Right ?\n", head.o_flags); +#endif + + if (head.text_size) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr,"%s: skipping %d bytes of comment\n", + nom, head.text_size); +#endif + fseek(fp, (long)head.text_size, SEEK_CUR); + } + + for (ligne=0; ligneBpix[ligne2])[col] = buffer[ col*(3+alpha) ]; + (image->Gpix[ligne2])[col] = buffer[ col*(3+alpha) + 1 ]; + (image->Rpix[ligne2])[col] = buffer[ col*(3+alpha) + 2 ]; + if (alpha) + (image->Apix[ligne2])[col] = buffer[ col*4 + 3 ]; + + } + } + +#if DEBUG_LEVEL > 1 + fprintf(stderr, " ... image loaded\n\n"); +#endif + break; + + default: + fprintf(stderr, "%s: file '%s' type %d not supported\n\n", + __func__, nom, head.type); + fclose (fp); + return NULL; + + } + +free(buffer); /* added 17 May 2001 :) */ +fclose(fp); + +/*-------- image is in memory... return @ of descriptor to caller. */ + +return image; +} +/*::------------------------------------------------------------------::*/ + /* c'est la fin... drink a beer :) */ diff --git a/tools.c b/tools.c new file mode 100644 index 0000000..ad7421b --- /dev/null +++ b/tools.c @@ -0,0 +1,387 @@ +/* + TOOLS.C outils de mise au point + (debugging tools) +*/ + +#include +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* + * WARNING! this function is not re-entrant! + */ +void +Image_pacifier(char *texte, int div) +{ +static int compteur; +int foo; +char batons[] = "|/-\\"; + +if ( texte != NULL ) printf("%s : ", texte); +else printf("wait "); +if (div<1) div=1; +foo = (compteur++) / div; +printf("%c\r", batons[foo&0x03]); fflush(stdout); +} +/*::------------------------------------------------------------------::*/ + +#define NB_CHRONOS 42 + +static struct + { + int in_use; + time_t debut; + time_t fin; + } chronos[NB_CHRONOS]; + +int +Image_start_chrono(char *texte, int num) +{ +if (num< 0 || num>= NB_CHRONOS) + { + return BAD_CHRONO; + } + +if (NULL != texte) + { + fprintf(stderr, ">>> start chrono(%d) %s\n", num, texte); + } + +time(&chronos[num].debut); +chronos[num].in_use = 1; +return OLL_KORRECT; +} + +long +Image_stop_chrono(char *texte, int num) +{ +long delta_t; + +if (num < 0 || num >= NB_CHRONOS) + { + return -1L; + } +time(&chronos[num].fin); +chronos[num].in_use = 0; +delta_t = chronos[num].fin - chronos[num].debut; +if (texte != NULL) + fprintf(stderr, ">>> chrono(%d): %s: %ld seconds\n", num, texte, delta_t); + +return delta_t; +} +/*::------------------------------------------------------------------::*/ +int +Image_dump_colormap(RGB_map *map, int verbose) +{ +int foo; + +if (map == NULL) + { + fprintf(stderr, "Dump ColorMap: 'map' ptr is NULL\n"); + return NULL_DESCRIPTOR; + } + +printf("+---------------------------\n"); +printf("| nom de la palette : %s\n", map->name); +printf("| nombre de couleurs : %d\n", map->nbre); +printf("+---------------------------\n"); + +if (verbose) + { + for (foo=0; foonbre; foo++) + { + printf("%3d: %3d %3d %3d\n", foo, + map->red[foo], map->green[foo], map->blue[foo]); + } + } + +return 0; +} +/*::------------------------------------------------------------------::*/ +int +Image_dump_descriptor(Image_Desc *im, char *text) +{ +fflush(stdout); +printf("/-------- Descriptor Dump (lib v=%s) -----------\n", + IMAGE_VERSION_STRING); + +printf("| why text: %s\n", text); +printf("| main pointer: %p\n", im); +if ( im==NULL ) + { + printf("!\t\tthis is a null descriptor, good luck, Sir...\n"); + return NULL_DESCRIPTOR; + } +else + { + printf("| name: %s\n", im->name); + printf("| comment: %s\n", im->comment); + printf("| magic: 0x%08lx\n", im->magic); + printf("| dimensions: %d x %d\n", im->width, im->height); + printf("| type/nb_plan: %d (%s), %d\n", im->type, + Image_type2str(im->type), + im->nb_planes); + printf("| planes pointers: %p %p %p %p\n", + im->Rpix, im->Gpix, im->Bpix, im->Apix); + + printf("| errmsg/modified : %d / %d\n", im->errmsg, im->modified); + printf("| xy fenetre : %15f %15f\n", im->fx, im->fy); + printf("| wh fenetre : %15f %15f\n", im->fw, im->fh); + } +printf("\\-----------------------------------------------------------\n"); +fflush(stdout); +return 0; +} +/*::------------------------------------------------------------------::*/ +int +Image_dump_rect(Image_Rect *rect, char *texte, int flag) +{ +printf("Rect: '%s'\n\t%5d %5d %5d %5d $%08lx\n", texte, + rect->x, rect->y, rect->w, rect->h, rect->reserved); +if (flag) { + printf(" coin bas/droite %5d %5d\n", rect->x+rect->w, rect->y+rect->h); + printf(" surface %8ld\n", (long)rect->w * (long)rect->h); + } +fflush(stdout); + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* new 8 octobre 2009 */ +static void ligne_char(char c, int t) +{ +int foo; +for (foo=0; foo len1) len = len2; +else len = len1; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : largeur = %d\n", __func__, len); +fprintf(stderr, "%s : ligne 1 = %s\n", __func__, lig1); +fprintf(stderr, "%s : ligne 2 = %s\n", __func__, lig2); +#endif + +ligne_char(caractere, len+10); +ligne_space(caractere, len+10); +ligne_char(caractere, len+10); + +} +/*::------------------------------------------------------------------::*/ +int +Image_print_rgba(char *txt, RGBA *rgba, int hexa) +{ +char *fmtd = "%-20s: RGBA %4d %4d %4d %4d\n"; +char *fmth = "%-20s: 0xRGBA %02x %02x %02x %02x\n"; +FILE *fp; + +if (*txt == '-') { + fp = stdout; + txt++; /* skip the '-' */ + } +else { + fp = stderr; + } +fprintf(fp, hexa ? fmth : fmtd, txt, rgba->r, rgba->g, rgba->b, rgba->a); +fflush(fp); + +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* affichage d'un descripteur de DF3 - new 28feb2008 - ave St Exupery */ +int +Image_print_DF3head(DensityF3Head *h, char *txt, int flag) +{ +int retval = 0; +int foo; + +if (NULL == h) + { + fprintf(stderr, "%s: null pointer\n", __func__); + return 666; + } +if (h->control != MAGIC_OF_DF3) + { + fprintf(stderr, "%s: bad magic value\n", __func__); + return 666; + } + +printf("+--- DF3head @ %p -- %s --\n", h, txt); +printf("| magic: %08lx\n", h->control); +printf("| name: %s\n", h->name); +printf("| dims: %d %d %d\n", h->xdim, h->ydim, h->zdim); + + +foo = h->nbrbytes; +printf("| nbr bytes: %d ", foo); +if ( (foo!=1) && (foo!=2) && (foo!=4) ) + { + printf("**ERROR**\n"); + retval++; + } +else + { + printf("\n"); + } + +printf("| flags: %08x\n", h->flags); +printf("| scale: %.g\n", h->scale); +printf("| datas @ : %p\n", h->datas); +printf("+------------------------------------\n"); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_Overlay_Palette(Image_Desc *im, int xo, int yo) +{ +int x, y, xx, yy, code; +int r, g, b; + +/* No boundchecking here ? */ + +for (y=0; y<128; y++) + { + yy = y + yo; + if ( (yy >= 0) && (yyheight) ) + { + for (x=0; x<256; x++) + { + xx = x + xo; + if ( (xx >= 0) && (xxwidth) ) + { + code = (y<<8) | x; + + r = (code & 0x1f) * 4; + b = ((code>>5) & 0x1f) * 4; + g = ((code>>10) & 0x1f) * 4; + + Image_plotRGB(im, xx, yy, r, g, b); + } + } + } + } + +im->modified = 1; +return 0; +} +/*::------------------------------------------------------------------::*/ +/* + * this function need more security controls + * see also: mircol.c + */ +int +Image_fabrique_une_mire(Image_Desc *im, RGB_map *map) +{ +int foo, bar; + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p %p\n", __func__, im, map); +#endif +if ( (im->width < 320) || (im->width<200) ) + return IMAGE_TOO_SMALL; + +if (NULL != map) + { + fprintf(stderr, "%s:%s map must be null\n", __FILE__, __func__); + exit(5); + } +Image_Overlay_Palette(im, 50, 10); + +for (foo=0; foo<256; foo++) + { + for (bar=0; bar<10; bar++) + { + Image_plotRGB(im, foo, bar, foo, foo, foo); + Image_plotRGB(im, foo, 190+bar, 256-foo, 256-foo, 256-foo); + } + } + +im->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +/* + * This func make a grid over an image, and need a lot of work. + */ +int +Image_Grille(Image_Desc *im, int stepx, int stepy, int rgb) +{ +int foo, bar; +int r, g, b; + +if (rgb < 0) { + r = rand() % 256; + g = rand() % 256; + b = rand() % 256; + } +else { + r = g = b = rgb; + } + +for (foo=0; foowidth; foo+=stepx) + { + for (bar=0; barheight; bar++) + Image_plotRGB(im, foo, bar, r, g, b); + } + +for (foo=0; fooheight; foo+=stepy) + { + for (bar=0; barwidth; bar++) + Image_plotRGB(im, bar, foo, r, g, b); + } + +im->modified = 1; +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int +Image_print_minmax(Image_Desc *img) +{ +int res[8], foo; + +printf(" R G B A\n"); +foo = Image_minmax_RGB(img, res); +printf("min %4d %4d %4d %4d\n", res[0], res[2], res[4], res[6]); +printf("max %4d %4d %4d %4d\n", res[1], res[3], res[5], res[7]); +return OLL_KORRECT; +} +/*::------------------------------------------------------------------::*/ +int Image_xy_inside(Image_Desc *img, int x, int y) +{ +/* + * 1er mars 2010 : this func need a g77 binding + */ +if ( (x<0) || (y<0) || (x>=img->width) || (y>=img->height) ) + { +#if DEBUG_LEVEL > 1 + fprintf(stderr, "%s : %p %6d %6d --> FAIL\n", __func__, img, x, y); +#endif + return 0; + } + +return 1; +} +/*::------------------------------------------------------------------::*/ diff --git a/tthimage.h b/tthimage.h index 316df03..1e60c99 100644 --- a/tthimage.h +++ b/tthimage.h @@ -294,6 +294,7 @@ void Image_print_version(int verbose); Image_Desc *Image_alloc(int width, int height, int type); Image_Desc *Image_clone(Image_Desc *src, int copy); int Image_clear( Image_Desc *image, int r, int v, int b ); +int Image_copy(Image_Desc *src, Image_Desc *dst); int Image_set_comment(Image_Desc *image, char *text); int Image_copy_comment(Image_Desc *s, Image_Desc *d); @@ -354,7 +355,6 @@ int Image_adjust_minmax_1(Image_Desc *src, Image_Desc *dst, int yo, int Image_egalise_RGB(Image_Desc *, Image_Desc *, int); int Image_egalise_mono_0(Image_Desc *, Image_Desc *, int); int Image_luminance(Image_Desc *, Image_Desc *, int); -int Image_copy(Image_Desc *src, Image_Desc *dst); int Image_negate(Image_Desc *, Image_Desc *); int Image_clear_component(Image_Desc *img, char component, int value); int Image_and_pix( Image_Desc *image, uint8_t ar, uint8_t ag, uint8_t ab); diff --git a/turtle.c b/turtle.c new file mode 100644 index 0000000..51a8644 --- /dev/null +++ b/turtle.c @@ -0,0 +1,61 @@ +/* + turtle.c + --------------- +*/ + +#include +#include + +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +int +Image_turtle_infos(Image_Desc *img, int flags) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, "Image turtle infos: flags = %04x\n", flags); +#endif + +if ( flags & 1 ) + foo = Image_dump_descriptor(img, "turtle infos"); + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +/* + * changer la couleur de l'encre de la tortue. + * + * Q: pourquoi le canal alpha n'est pas pris en compte ? + * A: parce que :) + */ +int +Image_turtle_setcolors(Image_Desc *img, int r, int g, int b) +{ +img->rt = r; img->gt = g; img->bt = b; + +img->at = 0; /* ? bonne valeur ? */ + +return FUNC_IS_ALPHA; +} +/*::------------------------------------------------------------------::*/ +int +Image_turtle_move(Image_Desc *img, double xt, double yt) +{ +img->xt = xt; +img->yt = yt; + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ +int +Image_turtle_draw(Image_Desc *img, double xt, double yt) +{ + +(void)img; + + +return FUNC_NOT_FINISH; +} +/*::------------------------------------------------------------------::*/ diff --git a/vignetize.c b/vignetize.c new file mode 100644 index 0000000..d6883dd --- /dev/null +++ b/vignetize.c @@ -0,0 +1,46 @@ +/* + * +--------------------------------------+ + * | confection de vignettes (primitives) | + * +--------------------------------------+ + */ + +#include +#include "tthimage.h" + +#undef DEBUG_LEVEL +#define DEBUG_LEVEL 1 + +/*::------------------------------------------------------------------::*/ +/* + * need more doc !!! + */ +int +Image_vignetize_x_0(Image_Desc *src, Image_Desc *dst, int prout) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "Vignetize x 0: %p --(%d)--> %p\n", src, prout, dst); +#endif + + +return 666; +} +/*::------------------------------------------------------------------::*/ +/* + * need more doc !!! + */ +int +Image_vignetize_x_1(Image_Desc *src, Image_Desc *dst, int prout) +{ + +#if DEBUG_LEVEL +fprintf(stderr, "Vignetize x 0: %p --(%d)--> %p\n", src, prout, dst); +#endif + + +return 666; +} +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ +/*::------------------------------------------------------------------::*/ diff --git a/zoom.c b/zoom.c new file mode 100644 index 0000000..becfaf0 --- /dev/null +++ b/zoom.c @@ -0,0 +1,91 @@ +/* + Zooms sur les images + -------------------- + new 31 janvier 2009 - avenue Saint Exupery +*/ + +#include +#include +#include +#include +#include "tthimage.h" + +/*::------------------------------------------------------------------::*/ +/* private variables */ +/*::------------------------------------------------------------------::*/ +/* private functions */ +/*::------------------------------------------------------------------::*/ +int Image_essai_zoom(Image_Desc *src, Image_Desc *dst, + double kx, double ky, int flags) +{ +int xd, yd, xs, ys; +int rd, gd, bd; +double dxs, dys; /* destination float position */ +#if DEBUG_LEVEL +long hit, mess; +#endif + +#if DEBUG_LEVEL +fprintf(stderr, "%s : %p -> %p %f %f 0x%x\n", __func__, + src, dst, kx, ky, flags); +#endif + +/* initilaisation de variables de debug/comptage */ +#if DEBUG_LEVEL +hit = mess = 0L; +#endif + +for (xd=0; xdwidth; xd++) + { + dxs = (double)xd * kx; + for (yd=0; ydheight; yd++) + { + rd = gd = bd = 42; + + dys = (double)yd * ky; /* kikoo lol */ + xs = (int)dxs; + ys = (int)dys; + + if ( Image_xy_inside(src, xs, ys) ) + { + Image_getRGB(src, xs, ys, &rd, &gd, &bd); +#if DEBUG_LEVEL + hit++; +#endif + } +#if DEBUG_LEVEL + else mess++; +#endif + Image_plotRGB(dst, xd, yd, rd, gd, bd); + } + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s -> hit=%ld mess=%ld\n", __func__, hit, mess); +#endif + +return BAD_ZOOM; +} +/*::------------------------------------------------------------------::*/ +int Image_zoom_000(Image_Desc *src, Image_Desc *dst, Image_Rect *rect) +{ +int xd, yd, r, g, b; +double fxd, fyd; + +#if DEBUG_LEVEL +fprintf(stderr, "%s ( %p %p %p )\n", __func__, src, dst, rect); +#endif + +for (yd=0; ydheight; yd++) + { + fyd = (double)yd; + for (xd=0; xdheight; xd++) + { + fxd = (double)xd; + + } + } + +return FULL_NUCKED; +} +/*::------------------------------------------------------------------::*/