second massive import batch
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
|
||||
*.o
|
||||
|
||||
foo
|
||||
|
||||
@@ -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 ------------------------------------------------
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ANAMORPHOSES
|
||||
*
|
||||
* new 18 octobre 2003
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<dst->height; y++)
|
||||
{
|
||||
dnormy = (double)y/(double)dst->height;
|
||||
for (x=0; x<dst->width; 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<w; x++)
|
||||
{
|
||||
dx = (double)x;
|
||||
angle = (dx/(double)w * (M_PI/1)) + M_PI;
|
||||
|
||||
for (y=0; y<h; y++)
|
||||
{
|
||||
dy = (double)y;
|
||||
|
||||
x2 = (int)(cos(angle) * (dy*xamp)) + xorg;
|
||||
y2 = (int)(sin(angle) * (dy*yamp)) + yorg;
|
||||
|
||||
if (x2>=0 && y2>=0 && x2<w-1 && y2<h-1)
|
||||
{
|
||||
/* Image_plotRGB(image, x2, y2, x*2, 200, y*2); */
|
||||
(image->Rpix[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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+163
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; yfoo<z->h; yfoo++)
|
||||
{
|
||||
ys = yfoo + z->y;
|
||||
if (ys<0 || ys>s->height-1)
|
||||
continue;
|
||||
for (xfoo=0; xfoo<z->w; 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; yfoo<z->h; 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; xfoo<z->w; 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; yy<z->h; 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; xx<z->w; 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; x<r->w; x++)
|
||||
{
|
||||
xs = x + r->x;
|
||||
for (y=0; y<r->h; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
+277
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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<bitsize; foo++) {
|
||||
/*
|
||||
* clear something here
|
||||
*/
|
||||
}
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_BP_plot(A_BitPlane *bp, int x, int y, int bit)
|
||||
{
|
||||
int offbyte, offbit;
|
||||
|
||||
#if DEBUG_LEVEL > 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; y<bp->height; y++)
|
||||
{
|
||||
for (x=0; x<bp->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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; ligne<head.height; ligne++)
|
||||
{
|
||||
foo=fread(buffer, 1, larg, fp);
|
||||
/* printf("ligne %5d lu %d\n", ligne, foo); */
|
||||
ligne2 = head.height - ligne - 1;
|
||||
for (col=0; col<head.width; col++)
|
||||
{
|
||||
(image->Bpix[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; foo<img->width; foo++)
|
||||
{
|
||||
*ptr++ = Bptr[foo];
|
||||
*ptr++ = Gptr[foo];
|
||||
*ptr++ = Rptr[foo];
|
||||
}
|
||||
fwrite(buffer, 3, bytes, fp);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return FUNC_IS_ALPHA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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()
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
calcluts.c
|
||||
----------
|
||||
|
||||
voir aussi: luts15bits.c
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef NEED_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
calculs.c
|
||||
---------
|
||||
|
||||
voir aussi: distances.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; x<zone->w; x++)
|
||||
{
|
||||
for (y=0; y<zone->h; 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; x<image->width; x++)
|
||||
{
|
||||
for (y=0; y<image->height; 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; x<img->width; x++)
|
||||
{
|
||||
for (y=0; y<img->height; 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; y<im->height; y++) {
|
||||
for (x=0; x<im->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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 ? */
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* classif.c novembre 2002
|
||||
* --------- -------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
Image_getRGB(src, x, y, &r, &g, &b);
|
||||
|
||||
plotted = 0;
|
||||
for (foo=0; foo<nbrclasses; foo++)
|
||||
{
|
||||
z = CUB(r-classes[foo].rc) +
|
||||
CUB(g-classes[foo].gc) +
|
||||
CUB(b-classes[foo].bc);
|
||||
|
||||
if (z < CUB(classes[foo].rad))
|
||||
{
|
||||
if (flag)
|
||||
Image_plotRGB(dst, x, y,
|
||||
classes[foo].r, classes[foo].g, classes[foo].b);
|
||||
else
|
||||
Image_plotRGB(dst, x, y, r, g, b);
|
||||
|
||||
plotted = 1;
|
||||
nbrplot++;
|
||||
break;
|
||||
}
|
||||
} /* fin for classe */
|
||||
|
||||
if ( ! plotted ) Image_plotRGB(dst, x, y, 0, 0, 0);
|
||||
} /* fin for x */
|
||||
}
|
||||
|
||||
dst->modified = 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<nbr; foo++) {
|
||||
printf("%3d '%-20s' ", foo, texte);
|
||||
printf("%5d %5d %5d ", cla[foo].rc, cla[foo].gc, cla[foo].bc) ;
|
||||
puts("");
|
||||
}
|
||||
puts("-- "); /* #include <sigrot.h> */
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* COLOR REDUCTION
|
||||
* new 27 Jan 2002.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Colors in the strange XYZ space. new 9 avr 2007, ave St Exupery
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
@@ -0,0 +1,694 @@
|
||||
/*
|
||||
colors.c
|
||||
--------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for rand() */
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef NEED_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#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; y<im->height; 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; y<im->height; y++) {
|
||||
for (x=0; x<im->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
mindist = 99999999;
|
||||
sr = s->Rpix[y][x];
|
||||
sg = s->Gpix[y][x];
|
||||
sb = s->Bpix[y][x];
|
||||
|
||||
for (m=0; m<map->nbre; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
colors2.c
|
||||
--------- new 18 jan 2010
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for rand() */
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef NEED_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#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; foo<NB_SLOTS; foo++) histo[foo] = 0L;
|
||||
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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<NB_SLOTS; foo++)
|
||||
{
|
||||
cumul += histo[foo];
|
||||
if (cumul < surf2)
|
||||
seuil = foo;
|
||||
#if DEBUG_LEVEL > 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; y<s1->height; y++)
|
||||
{
|
||||
my = (y+oy) / sy;
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
my = (y+oy) / sy;
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
fy2 = (float)((y-ycenter)*(y-ycenter));
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
combine2.c
|
||||
mixages...
|
||||
----------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<a->height; 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; x<a->width; 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; y<a->height; 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; x<a->width; 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; y<a->height; y++)
|
||||
{
|
||||
cy = y % c->height;
|
||||
for (x=0; x<a->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
combine3.c
|
||||
----------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<dst->height-1; y++)
|
||||
{
|
||||
for (x=1; x<dst->width-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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
combine4.c
|
||||
----------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<h2; y++)
|
||||
{
|
||||
for (x=0; x<w2; x++)
|
||||
{
|
||||
(dst->Rpix[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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
combine5.c
|
||||
----------
|
||||
dégradés linéaires divers.
|
||||
avec des erreurs d'arrondi dedans.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; y<s1->height; 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; x<s1->width; 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; x<s1->width; 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; y<s1->height; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; x++)
|
||||
{
|
||||
if (x<xv)
|
||||
{
|
||||
(d->Rpix[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; y<s1->height; y++) {
|
||||
for (x=0; x<s1->width; x++) {
|
||||
if (y<yv)
|
||||
{
|
||||
(d->Rpix[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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
combine6.c
|
||||
----------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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;
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
combine_rnd.c random effects
|
||||
============= --------------
|
||||
|
||||
made by Thierry Boudet, aka "Oulala", aka "Tonton Th".
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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; y<s1->height; y++)
|
||||
{
|
||||
for (x=0; x<s1->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* contours.c - new StEx 11 oct 2014
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* http://www.palkeo.com/projets/traitement_images/index.html
|
||||
*/
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* contrast.c - 31 dec 2013
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#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; y<source->height; y++) {
|
||||
for (x=0; x<source->width; 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; y<source->height; y++) {
|
||||
for (x=0; x<source->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
detect.c
|
||||
--------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; y<src->height-1; y++)
|
||||
{
|
||||
for (x=1; x<src->width-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; y<src->height-1; y++)
|
||||
{
|
||||
for (x=1; x<src->width-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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
detect2.c
|
||||
---------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#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; y<img->height; y++)
|
||||
{
|
||||
for (x=0; x<img->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
dither.c 31 Aout 1999
|
||||
-------- ------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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; y<dy; y++)
|
||||
{
|
||||
for (x=0; x<dx; x++)
|
||||
{
|
||||
r = s->Rpix[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; x<xm; x+=2)
|
||||
{
|
||||
for (y=0; y<ym; y+=2)
|
||||
{
|
||||
/*
|
||||
* bon sang, mais que faire ici ?
|
||||
*/
|
||||
r = s->Rpix[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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; y<s->height; 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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
dither2.c
|
||||
---------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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; y<s->height-3; y+=3)
|
||||
{
|
||||
for (x=0; x<s->width-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] = r<uh ? 0 : 255;
|
||||
(d->Rpix[y+1]) [x] = r<uh ? 0 : 255;
|
||||
(d->Rpix[y]) [x+1] = r<uh ? 0 : 255;
|
||||
(d->Rpix[y+1]) [x+1] = r<uh ? 0 : 255;
|
||||
|
||||
(d->Gpix[y]) [x+1] = g<uh ? 0 : 255;
|
||||
(d->Gpix[y+1]) [x+1] = g<uh ? 0 : 255;
|
||||
(d->Gpix[y]) [x+2] = g<uh ? 0 : 255;
|
||||
(d->Gpix[y+1]) [x+2] = g<uh ? 0 : 255;
|
||||
|
||||
(d->Bpix[y+1]) [x+1] = b<uh ? 0 : 255;
|
||||
(d->Bpix[y+2]) [x] = b<uh ? 0 : 255;
|
||||
(d->Bpix[y+2]) [x+2] = b<uh ? 0 : 255;
|
||||
(d->Bpix[y+2]) [x+3] = b<uh ? 0 : 255;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if DEBUG_LEVEL > 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; y<s->height-3; y+=3)
|
||||
{
|
||||
for (x=0; x<s->width-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<sr/255; foo++)
|
||||
{
|
||||
if (foo>=9)
|
||||
{
|
||||
fprintf(stderr, "overflow\n");
|
||||
return 666;
|
||||
}
|
||||
(d->Rpix[y+dy[foo]])[x+dx[foo]] = 255;
|
||||
}
|
||||
for (foo=0; foo<sg/255; foo++)
|
||||
{
|
||||
if (foo>=9)
|
||||
{
|
||||
fprintf(stderr, "overflow\n");
|
||||
return 666;
|
||||
}
|
||||
(d->Gpix[y+dy[foo]])[x+dx[foo]] = 255;
|
||||
}
|
||||
for (foo=0; foo<sb/255; foo++)
|
||||
{
|
||||
if (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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
dither3.c
|
||||
---------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
dither4.c
|
||||
---------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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; foo<shuff; foo++) /* magic number ? */
|
||||
{
|
||||
m = rand() & 0xff;
|
||||
n = rand() & 0xff;
|
||||
itmp = ((uint16_t *)matrice)[n];
|
||||
((uint16_t *)matrice)[n] = ((uint16_t *)matrice)[m];
|
||||
((uint16_t *)matrice)[m] = itmp;
|
||||
}
|
||||
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
|
||||
+---------------------------------------+
|
||||
| Effets speciaux sur les images |
|
||||
+---------------------------------------+
|
||||
|
||||
Thierry Boudet <oulala@chez.com>
|
||||
-----------------------------------------
|
||||
vous pouvez aussi aller regarder le module 'combine.c'
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; x<source->width; x++)
|
||||
{
|
||||
for (y=0; y<source->height; 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; x<source->width; x++)
|
||||
{
|
||||
for (y=0; y<source->height; 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; y<src->height; y++)
|
||||
{
|
||||
if (src->Rpix != NULL)
|
||||
{
|
||||
for (x=0; x<largeur; x++)
|
||||
buffer[x] = (src->Rpix[y])[x];
|
||||
for (x=0; x<largeur; x++)
|
||||
(dst->Rpix[y])[x] = buffer[largeur-x-1];
|
||||
}
|
||||
if (src->Gpix != NULL)
|
||||
{
|
||||
for (x=0; x<largeur; x++)
|
||||
buffer[x] = (src->Gpix[y])[x];
|
||||
for (x=0; x<largeur; x++)
|
||||
(dst->Gpix[y])[x] = buffer[largeur-x-1];
|
||||
}
|
||||
if (src->Bpix != NULL)
|
||||
{
|
||||
for (x=0; x<largeur; x++)
|
||||
buffer[x] = (src->Bpix[y])[x];
|
||||
for (x=0; x<largeur; x++)
|
||||
(dst->Bpix[y])[x] = buffer[largeur-x-1];
|
||||
}
|
||||
if (src->Apix != NULL)
|
||||
{
|
||||
for (x=0; x<largeur; x++)
|
||||
buffer[x] = (src->Apix[y])[x];
|
||||
for (x=0; x<largeur; x++)
|
||||
(dst->Apix[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; y<src->height; 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; line<src->height; line++)
|
||||
{
|
||||
for (col=0; col<wmax; col+=2)
|
||||
{
|
||||
tmp = src->Rpix[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; x<src->width; x++)
|
||||
{
|
||||
for (y=0; y<src->height; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
+---------------------------------------+
|
||||
| Effets speciaux sur les images |
|
||||
| deuxieme module |
|
||||
+---------------------------------------+
|
||||
Thierry Boudet <oulala@chez.com>
|
||||
vous pouvez aussi aller regarder 'effects.c' et 'combine.c'
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; x<source->width; x++)
|
||||
{
|
||||
fx = (double)x + (table[1] * sin(table[4] + (cx * table[0] * (double)x)));
|
||||
xb = floor(fx + 0.5);
|
||||
|
||||
for (y=0; y<source->height; y++)
|
||||
{
|
||||
fy = (double)y + (table[3] * sin(table[5] + cy * table[2] * (double)y));
|
||||
yb = floor(fy + 0.5);
|
||||
|
||||
if ( xb>0 && yb>0 && xb<but->width && yb<but->height )
|
||||
{
|
||||
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; y<source->height; y++)
|
||||
{
|
||||
fy = (double)y / (double)source->height * M_PI;
|
||||
dy = sin(fy*table[0]) * table[1];
|
||||
oy = (int)(dy);
|
||||
for (x=0; x<source->width; x++)
|
||||
{
|
||||
xb = x + oy;
|
||||
if (xb >=0 && xb<source->width)
|
||||
{
|
||||
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; x<source->width; x++)
|
||||
{
|
||||
fx = (double)x / (double)source->width * M_PI;
|
||||
dx = sin(fx*table[3]) * table[4];
|
||||
ox = (int)(dx);
|
||||
for (y=0; y<source->height; y++)
|
||||
{
|
||||
yb = y + ox;
|
||||
if (yb >=0 && yb<source->height)
|
||||
{
|
||||
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; x<source->width; 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 ?
|
||||
*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
+---------------------------------------+
|
||||
| Effets speciaux sur les images |
|
||||
| troisième module |
|
||||
+---------------------------------------+
|
||||
Thierry Boudet <oulala@chez.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h> /* 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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<dst->height; y++)
|
||||
{
|
||||
for (x=0; x<dst->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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 <stdio.h>
|
||||
#include <time.h>
|
||||
#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 ;-)
|
||||
*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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 :)
|
||||
*/
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* essais de filtres adaptatifs
|
||||
* ----------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#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; y<src->height-1; y++) {
|
||||
for (x=1; x<src->width-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; y<src->height-1; y++) {
|
||||
for (x=1; x<src->width-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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,467 @@
|
||||
/*
|
||||
filtrages sur les images
|
||||
------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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; foo<im->width; 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; foo<im->height; 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<rotation; foo++)
|
||||
Image_rotate_filtre(filtre);
|
||||
|
||||
Image_convolueur_2(src, dst, filtre, "rgb");
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* XXX cette fonction est incorrecte XXX
|
||||
*/
|
||||
int
|
||||
Image_filtre_Sobel(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;
|
||||
|
||||
memcpy(filtre, Sobel, 11*sizeof(int));
|
||||
|
||||
for (foo=0; foo<rotation; foo++)
|
||||
Image_rotate_filtre(filtre);
|
||||
|
||||
Image_convolueur_2(src, dst, filtre, "rgb");
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*
|
||||
* Voir aussi 'sobel4.c' */
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 15 Jan 2000 */
|
||||
int
|
||||
Image_filtre_passe_bas(Image_Desc *src, Image_Desc *dst)
|
||||
{
|
||||
int foo;
|
||||
|
||||
static int PasseBas[] =
|
||||
{
|
||||
1, 2, 1,
|
||||
2, 4, 2,
|
||||
1, 2, 1,
|
||||
16, 0
|
||||
};
|
||||
|
||||
foo = Image_convolueur_2(src, dst, PasseBas, "rgb");
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* nouveau: 18 Janvier 2001
|
||||
moral à zéro, il faut que je fasse pédaler le 486 ! */
|
||||
int
|
||||
Image_filtre_random(Image_Desc *src, Image_Desc *dst, int p1, int p2)
|
||||
{
|
||||
int filtre[11];
|
||||
int foo, somme, v, delta;
|
||||
|
||||
if (p1 == p2)
|
||||
{
|
||||
fprintf(stderr, "%s: p1=%d must be different from p2=%d\n",
|
||||
__func__, p1, p2);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
somme = 0;
|
||||
|
||||
delta = abs(p2 - p1);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: delta is %d\n", __func__, delta);
|
||||
#endif
|
||||
|
||||
for (foo=0; foo<9; foo++)
|
||||
{
|
||||
v = (rand()%delta)+p1;
|
||||
filtre[foo] = v;
|
||||
somme += v;
|
||||
}
|
||||
|
||||
filtre[9] = somme;
|
||||
filtre[10] = 0; /* XXX calcul automatique a faire ! */
|
||||
|
||||
Image_filtre_display(stdout, filtre);
|
||||
|
||||
foo = Image_convolueur_2(src, dst, filtre, "rgb");
|
||||
fprintf(stderr, "retour convolueur = %d\n", foo);
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
/* et en plus, ce _truc_ n'a _aucune_ valeur scientifique... */
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* nouveau: 3 Fevrier 2001
|
||||
on s'inspire de la precedente.
|
||||
*/
|
||||
int
|
||||
Image_filtre_random_2(Image_Desc *src, Image_Desc *dst,
|
||||
int p1, int p2, int p3, int p4)
|
||||
{
|
||||
int filtre[11];
|
||||
int foo, somme, v, delta, deltb;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Filtre Random 2: %d %d / %d %d\n", p1, p2, p3, p4);
|
||||
#endif
|
||||
|
||||
delta = abs(p2 - p1);
|
||||
deltb = abs(p4 - p3);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Filtre Random 2: delta are %d %d\n", delta, deltb);
|
||||
#endif
|
||||
|
||||
somme = 0;
|
||||
for (foo=0; foo<9; foo++)
|
||||
{
|
||||
if (foo != 4)
|
||||
{
|
||||
v = (rand()%delta)+p1;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = (rand()%deltb)+p3;
|
||||
}
|
||||
filtre[foo] = v;
|
||||
|
||||
somme += v;
|
||||
}
|
||||
|
||||
filtre[9] = somme;
|
||||
filtre[10] = 0; /* XXX calcul automatique a faire ! */
|
||||
|
||||
Image_filtre_display(stdout, filtre);
|
||||
|
||||
foo = Image_convolueur_2(src, dst, filtre, "rgb");
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_filtre_passe_haut(Image_Desc *src, Image_Desc *dst)
|
||||
{
|
||||
int foo;
|
||||
static int PasseHaut[] =
|
||||
{
|
||||
-1, -1, -1,
|
||||
-1, 8, -1,
|
||||
-1, -1, -1,
|
||||
1, 0
|
||||
};
|
||||
|
||||
foo = Image_convolueur_2(src, dst, PasseHaut, "rgb");
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* GADGRECT : des gadgets dans des rectangles
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#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; x<rect->w; x++)
|
||||
{
|
||||
for (y=0; y<rect->h; 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; x<rect->w; x++)
|
||||
{
|
||||
foo = (int)val;
|
||||
r = g = b = foo;
|
||||
for (y=0; y<rect->h; 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; x<rect->w; x++)
|
||||
{
|
||||
foo = (int)val;
|
||||
r = g = b = foo;
|
||||
for (y=0; y<rect->h; 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; y<fromrect->w; y++)
|
||||
{
|
||||
for (x=0; x<fromrect->h; 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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
GAMMA CORRECTION
|
||||
----------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* glitch.c - new sept 2014 - MYRYS
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; nbre<k; nbre++)
|
||||
{
|
||||
x = rand() % src->width;
|
||||
y = rand() % src->height;
|
||||
d = rand() & 3;
|
||||
Image_getRGB(src, x, y, &r, &g, &b);
|
||||
|
||||
switch (d)
|
||||
{
|
||||
case 0:
|
||||
for (v=0; v<x; v++)
|
||||
Image_XOR_pixel(dst, v, y, r, g, b);
|
||||
break;
|
||||
case 1:
|
||||
for (v=0; v<y; v++)
|
||||
Image_XOR_pixel(dst, x, v, r, g, b);
|
||||
break;
|
||||
case 2:
|
||||
for (v=x; v<src->width; v++)
|
||||
Image_XOR_pixel(dst, v, y, r, g, b);
|
||||
break;
|
||||
case 3:
|
||||
for (v=y; v<src->height; 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; nbre<k; nbre++)
|
||||
{
|
||||
x = rand() % src->width;
|
||||
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; v<x; v++)
|
||||
Image_plotRGB(dst, v, y, r, g, b);
|
||||
break;
|
||||
case 1:
|
||||
for (v=0; v<y; v++)
|
||||
Image_plotRGB(dst, x, v, r, g, b);
|
||||
break;
|
||||
case 2:
|
||||
for (v=x; v<src->width; v++)
|
||||
Image_plotRGB(dst, v, y, r, g, b);
|
||||
break;
|
||||
case 3:
|
||||
for (v=y; v<src->height; v++)
|
||||
Image_plotRGB(dst, x, v, r, g, b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gray_ops.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -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; foo<src->height; 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
|
||||