Compare commits
2 Commits
f3e30ea3bb
...
0175102393
Author | SHA1 | Date | |
---|---|---|---|
|
0175102393 | ||
|
24ad5b4a4a |
216
Lib/7seg.c
Normal file
216
Lib/7seg.c
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* afficheurs a 7 segments - 8 nov 2008 - avenue St Exupery
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_7seg_m0v(Image_Desc *img, int xpos, int ypos, int bits, int k)
|
||||
{
|
||||
Image_Rect r;
|
||||
int foo, numbit, mask;
|
||||
int failed;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p, <%d,%d>, 0x%x, %d )\n", __func__,
|
||||
img, xpos, ypos, bits, k);
|
||||
#endif
|
||||
|
||||
/* ==> check the parameters */
|
||||
|
||||
/* ==> tag the plotting zone */
|
||||
r.x = xpos; r.y = ypos;
|
||||
r.h = 19; r.w = 43;
|
||||
foo = Image_paint_rect(img, &r, 25, 21, 42);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, " %s : paint rect -> %d\n", __func__, foo);
|
||||
#endif
|
||||
|
||||
foo = Image_draw_rect(img, &r, 125, 101, 232);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, " %s : draw rect -> %d\n", __func__, foo);
|
||||
#endif
|
||||
|
||||
failed = 0;
|
||||
|
||||
/* draw the lighten segments */
|
||||
for (numbit=0; numbit<8; numbit++)
|
||||
{
|
||||
mask = 1 << numbit;
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s numbit %2d mask %02x\n", __func__, numbit, mask);
|
||||
#endif
|
||||
if ( ! (mask & bits) )
|
||||
{
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%d skip %d\n", numbit, mask);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
r.x = -1; /* mark as 'no plot that'*/
|
||||
switch (mask)
|
||||
{
|
||||
case 0x01:
|
||||
r.x = xpos+6; r.y = ypos+2;
|
||||
r.h = 15; r.w = 4;
|
||||
break;
|
||||
case 0x02:
|
||||
r.x = xpos+9; r.y = ypos + 14;
|
||||
r.h = 4; r.w = 13;
|
||||
break;
|
||||
case 0x04:
|
||||
r.x = xpos+9; r.y = ypos +1;
|
||||
r.h = 4; r.w = 13;
|
||||
break;
|
||||
case 0x08:
|
||||
r.x = xpos+22; r.y = ypos+2;
|
||||
r.h = 15; r.w = 4;
|
||||
break;
|
||||
case 0x10:
|
||||
r.x = xpos+25; r.y = ypos+14;
|
||||
r.h = 4; r.w = 13;
|
||||
break;
|
||||
case 0x20:
|
||||
r.x = xpos+25; r.y = ypos+1;
|
||||
r.h = 4; r.w = 13;
|
||||
break;
|
||||
case 0x40:
|
||||
r.x = xpos+38; r.y = ypos+2;
|
||||
r.h = 15; r.w = 4;
|
||||
break;
|
||||
case 0x80:
|
||||
/* le point */
|
||||
r.x = xpos+1; r.y = ypos+1;
|
||||
r.h = 6; r.w = 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "segfaulting in %s\n", __func__);
|
||||
abort();
|
||||
break; /* ah ah ah ah */
|
||||
}
|
||||
if (r.x >= 0)
|
||||
{
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, " painting...\n");
|
||||
#endif
|
||||
Image_paint_rect(img, &r, 200, mask, 50);
|
||||
}
|
||||
else
|
||||
{
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed > 0)
|
||||
{
|
||||
fprintf(stderr, "%s : failed = %d\n", __func__, failed);
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_7seg_digv(Image_Desc *img, int xpos, int ypos, char chiffre, int k)
|
||||
{
|
||||
static int patterns[] =
|
||||
{ 0x77, 0x24, 0x5d, 0x6d, 0x2e, 0x6b, 0xfb, 0x25, 0x7f, 0x6f };
|
||||
/* 0 1 2 3 4 5 6 7 8 9 */
|
||||
int foo, idx, bits;
|
||||
|
||||
#if DEBEUG_LEVEL > 1
|
||||
fprintf(stderr, "%s digit 0x%2x sizeof(patterns) -> %d\n", __func__,
|
||||
chiffre, sizeof(patterns));
|
||||
#endif
|
||||
|
||||
if (0 != k)
|
||||
fprintf(stderr, "in %s, k was %d. It's bad.\n", __func__, k);
|
||||
|
||||
if ( ! isdigit(chiffre) )
|
||||
{
|
||||
fprintf(stderr, "*** in %s, value 0x%x is not a digit\n", __func__,
|
||||
chiffre);
|
||||
abort();
|
||||
}
|
||||
idx = chiffre - '0';
|
||||
bits = patterns[idx];
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s patterns[%d] -> 0x%x\n", __func__, idx, bits);
|
||||
#endif
|
||||
|
||||
foo = Image_7seg_m0v(img, xpos, ypos, bits, 0);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "foooooo ----> %d\n", foo);
|
||||
#endif
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_7seg_tag0(Image_Desc *img, char *numstr, int k)
|
||||
{
|
||||
int len, idx;
|
||||
int foo;
|
||||
char digit;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s ( %p, '%s', %d )\n", __func__, img, numstr, k);
|
||||
#endif
|
||||
|
||||
len = strlen(numstr);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, " len = %d\n", len);
|
||||
#endif
|
||||
|
||||
for (idx=0; idx<len; idx++)
|
||||
{
|
||||
foo = len-idx-1;
|
||||
digit = numstr[foo];
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, " %s %d->%d '%c'\n", __func__, idx, foo, digit);
|
||||
#endif
|
||||
foo = Image_7seg_digv(img, 10, 10+(idx*21), digit, k);
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* this is purely a test/demo routine - don't use in production !
|
||||
*/
|
||||
int Image_7_segments(Image_Desc *img, int nbre, int k)
|
||||
{
|
||||
int foo, bar;
|
||||
int iter;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">> %s ( %p, %d, 0x%x )\n", __func__, img, nbre, k);
|
||||
#endif
|
||||
|
||||
iter = 0; /* safe value */
|
||||
|
||||
for (iter=0; iter<nbre; iter++)
|
||||
{
|
||||
printf("----%s passe %d -----\n", __func__, iter);
|
||||
bar = 1 << iter;
|
||||
foo = Image_7seg_m0v(img, 20, 5+(iter*22), bar, 0);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "7seg_m0v %d 0x%02x -> %d\n", iter, bar, foo);
|
||||
#endif
|
||||
|
||||
bar = '0' + iter;
|
||||
foo = Image_7seg_digv(img, 80, 5+(iter*22), bar, 0);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "7seg_digv %d 0x%02x -> %d\n", iter, bar, foo);
|
||||
#endif
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
63
Lib/Makefile
63
Lib/Makefile
@ -6,19 +6,30 @@
|
||||
|
||||
include ../Paramakes.mk
|
||||
|
||||
DEPS = ../tthimage.h Makefile
|
||||
|
||||
STATICLIB = "../libimage.a"
|
||||
DEPS = ../tthimage.h ../Paramakes.mk Makefile
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
7seg.o: 7seg.c $(DEPS)
|
||||
|
||||
basic_io.o: basic_io.c $(DEPS)
|
||||
bitblt.o: bitblt.c $(DEPS)
|
||||
|
||||
calcluts.o:
|
||||
cadres.o: cadres.c $(DEPS)
|
||||
cadres2.o: cadres2.c $(DEPS)
|
||||
cadres3.o: cadres3.c $(DEPS)
|
||||
cadres4.o: cadres4.c $(DEPS)
|
||||
cadres84.o: cadres84.c $(DEPS)
|
||||
cadresbox.o: cadresbox.c $(DEPS)
|
||||
|
||||
calcluts.o: calcluts.c $(DEPS)
|
||||
calculs.o: calculs.c $(DEPS)
|
||||
classif.o: classif.c $(DEPS)
|
||||
col4bits.o: col4bits.c $(DEPS)
|
||||
col_reduc.o: col_reduc.c $(DEPS)
|
||||
col_xyz.o: col_xyz.c $(DEPS)
|
||||
colors.o: colors.c $(DEPS)
|
||||
colors2.o: colors2.c $(DEPS)
|
||||
combine.o: combine.c $(DEPS)
|
||||
combine2.o: combine2.c $(DEPS)
|
||||
combine3.o: combine3.c $(DEPS)
|
||||
@ -26,12 +37,15 @@ combine4.o: combine4.c $(DEPS)
|
||||
combine5.o: combine5.c $(DEPS)
|
||||
combine6.o: combine6.c $(DEPS)
|
||||
|
||||
distances.o: distances.c $(DEPS)
|
||||
dither.o: dither.c $(DEPS)
|
||||
dither2.o: dither2.c $(DEPS)
|
||||
dither3.o: dither3.c $(DEPS)
|
||||
dither4.o: dither4.c $(DEPS)
|
||||
doublesz.o: doublesz.c $(DEPS)
|
||||
drawalpha.o: drawalpha.c $(DEPS)
|
||||
drawing.o: drawing.c $(DEPS)
|
||||
drawpatt.o: drawpatt.c $(DEPS)
|
||||
|
||||
effects.o: effects.c $(DEPS)
|
||||
effects2.o: effects2.c $(DEPS)
|
||||
@ -39,6 +53,8 @@ effects3.o: effects3.c $(DEPS)
|
||||
|
||||
filtres.o: filtres.c $(DEPS)
|
||||
|
||||
gadgrect.o: gadgrect.c $(DEPS)
|
||||
|
||||
halfsize.o: halfsize.c $(DEPS)
|
||||
|
||||
image.o: image.c $(DEPS)
|
||||
@ -48,12 +64,15 @@ luts15bits.o: luts15bits.c $(DEPS)
|
||||
|
||||
marques.o: marques.c $(DEPS)
|
||||
mircol.o: mircol.c $(DEPS)
|
||||
morpho.o: morpho.c $(DEPS)
|
||||
mosaic.o: mosaic.c $(DEPS)
|
||||
msglib.o: msglib.c $(DEPS)
|
||||
mustopen.o: mustopen.c $(DEPS)
|
||||
|
||||
operat.o: operat.c $(DEPS)
|
||||
op2x2.o: op2x2.c $(DEPS)
|
||||
|
||||
palettes.o: palettes.c $(DEPS)
|
||||
patterns.o: patterns.c $(DEPS)
|
||||
patterns2.o: patterns2.c $(DEPS)
|
||||
patterns3.o: patterns3.c $(DEPS)
|
||||
@ -69,6 +88,7 @@ pov_hf15d.o: pov_hf15d.c $(DEPS)
|
||||
pov_hf15e.o: pov_hf15e.c $(DEPS)
|
||||
pov_hf15f.o: pov_hf15f.c $(DEPS)
|
||||
pov_synth.o: pov_synth.c $(DEPS)
|
||||
ptlist.o: ptlist.c $(DEPS)
|
||||
|
||||
rgbmask.o: rgbmask.c $(DEPS)
|
||||
|
||||
@ -90,50 +110,61 @@ warp1.o: warp1.c $(DEPS)
|
||||
warp2.o: warp2.c $(DEPS)
|
||||
warp3.o: warp3.c $(DEPS)
|
||||
|
||||
zoom.o: zoom.c $(DEPS)
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
OBJECTS = basic_io.o bitblt.o \
|
||||
calculs.o classif.o col_xyz.o \
|
||||
OBJECTS = 7seg.o \
|
||||
basic_io.o bitblt.o \
|
||||
cadres2.o cadres3.o cadres4.o cadres84.o cadresbox.o \
|
||||
cadres.o \
|
||||
calculs.o classif.o \
|
||||
col4bits.o colors.o colors2.o col_reduc.o col_xyz.o \
|
||||
combine.o combine2.o combine3.o combine4.o combine5.o \
|
||||
distances.o \
|
||||
dither.o dither2.o dither3.o dither4.o \
|
||||
doublesz.o drawing.o \
|
||||
doublesz.o drawalpha.o drawing.o drawpatt.o \
|
||||
effects.o effects2.o effects3.o \
|
||||
filtres.o \
|
||||
gadgrect.o \
|
||||
halfsize.o \
|
||||
image.o imprime.o \
|
||||
luts15bits.o \
|
||||
marques.o mircol.o msglib.o mustopen.o \
|
||||
marques.o mircol.o morpho.o mosaic.o msglib.o \
|
||||
mustopen.o \
|
||||
operat.o op2x2.o \
|
||||
palettes.o \
|
||||
patterns.o patterns2.o patterns3.o patterns4.o \
|
||||
pht.o pixeliz.o pixels.o plotteur.o \
|
||||
pov_hf15a.o pov_hf15b.o pov_hf15c.o pov_hf15d.o \
|
||||
pov_hf15e.o pov_hf15e.o pov_hf15f.o pov_synth.o \
|
||||
ptlist.o \
|
||||
rgbmask.o \
|
||||
scale.o sobel4.o \
|
||||
tamppool.o television.o text0.o text1.o text16x24.o \
|
||||
tga.o tools.o \
|
||||
vignetize.o \
|
||||
warp0.o warp1.o warp2.o warp3.o
|
||||
warp0.o warp1.o warp2.o warp3.o \
|
||||
zoom.o
|
||||
|
||||
$(STATICLIB): $(OBJECTS)
|
||||
../libimage.a: $(OBJECTS)
|
||||
$(AR) vrs $@ $?
|
||||
$(RANLIB) $@
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
foo: foo.c $(DEPS) $(STATICLIB)
|
||||
gcc $(CFLAGS) $< $(STATICLIB) -o $@
|
||||
foo: foo.c $(DEPS) ../libimage.a
|
||||
gcc $(CFLAGS) $< ../libimage.a -o $@
|
||||
|
||||
t_t16x24: t_t16x24.c $(DEPS) $(STATICLIB)
|
||||
gcc $(CFLAGS) $< $(STATICLIB) -o $@
|
||||
t_t16x24: t_t16x24.c $(DEPS) ../libimage.a
|
||||
gcc $(CFLAGS) $< ../libimage.a-o $@
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
essais.o: essais.c $(DEPS) essais.h
|
||||
gcc $(CFLAGS) $< -c
|
||||
|
||||
testtga: testtga.c $(DEPS) $(STATICLIB) essais.o
|
||||
gcc $(CFLAGS) $< $(STATICLIB) essais.o -lm -o $@
|
||||
testtga: testtga.c $(DEPS) ../libimage.a essais.o
|
||||
gcc $(CFLAGS) $< essais.o ../libimage.a -lm -o $@
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
474
Lib/cadres.c
Normal file
474
Lib/cadres.c
Normal file
@ -0,0 +1,474 @@
|
||||
/*
|
||||
fabrication de cadres dans des images.
|
||||
--------------------------------------
|
||||
new 24 Janvier 2000
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* l'epaisseur de ce cadre est de DEUX pixels, et cette valeur
|
||||
* ne doit pas changer, car d'autres fonctions en dependent.
|
||||
*/
|
||||
int
|
||||
Image_cadre_A(Image_Desc *im)
|
||||
{
|
||||
int x, y;
|
||||
int a, b;
|
||||
|
||||
a = 0; b = 255;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
(im->Rpix[0])[x] = a;
|
||||
(im->Gpix[0])[x] = a;
|
||||
(im->Bpix[0])[x] = a;
|
||||
Image_plotRGB(im, x, im->height-1, a, a, a);
|
||||
}
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
(im->Rpix[y])[0] = a;
|
||||
(im->Gpix[y])[0] = a;
|
||||
(im->Bpix[y])[0] = a;
|
||||
Image_plotRGB(im, im->width-1, y, a, a, a);
|
||||
}
|
||||
for (x=1; x<im->width-1; x++)
|
||||
{
|
||||
(im->Rpix[1])[x] = b;
|
||||
(im->Gpix[1])[x] = b;
|
||||
(im->Bpix[1])[x] = b;
|
||||
Image_plotRGB(im, x, im->height-2, b, b, b);
|
||||
}
|
||||
for (y=1; y<im->height-1; y++)
|
||||
{
|
||||
(im->Rpix[y])[1] = b;
|
||||
(im->Gpix[y])[1] = b;
|
||||
(im->Bpix[y])[1] = b;
|
||||
Image_plotRGB(im, im->width-2, y, b, b, b);
|
||||
}
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* 30 septembre 2008: Image_cadre_B devient Image_cadre_cracra :)
|
||||
*/
|
||||
int
|
||||
Image_cadre_cracra(Image_Desc *im, int largeur, int k)
|
||||
{
|
||||
int x, y, r, g, b;
|
||||
|
||||
if (im->width < (largeur+5) || im->height < (largeur+5))
|
||||
return IMAGE_TOO_SMALL;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: k is $%04x\n", __func__, k);
|
||||
#endif
|
||||
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
for (x=0; x<largeur; x++)
|
||||
{
|
||||
r = rand() % (10 + x * 20);
|
||||
g = rand() % (11 + x * 10);
|
||||
b = rand() % (10 + x * 12);
|
||||
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
for (x=0; x<largeur; x++)
|
||||
{
|
||||
r = rand() % (10 + (largeur-x) * 20);
|
||||
g = rand() % (10 + (largeur-x) * 10);
|
||||
b = rand() % (10 + (largeur-x) * 12);
|
||||
Image_plotRGB(im, x+im->width-largeur, y, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
for (y=0; y<largeur; y++)
|
||||
{
|
||||
r = rand() % (10 + y * 10);
|
||||
g = rand() % (10 + y * 12);
|
||||
b = rand() % (10 + y * 20);
|
||||
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
for (y=0; y<largeur; y++)
|
||||
{
|
||||
r = rand() % (10 + (largeur-y) * 10);
|
||||
g = rand() % (10 + (largeur-y) * 12);
|
||||
b = rand() % (10 + (largeur-y) * 20);
|
||||
|
||||
(im->Rpix[y+im->height-largeur])[x] = r;
|
||||
(im->Gpix[y+im->height-largeur])[x] = g;
|
||||
(im->Bpix[y+im->height-largeur])[x] = b;
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT; /* OK, this func is really finishd */
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* killing this func - 30 sept 2008 - ave St Exupery
|
||||
*/
|
||||
int Image_cadre_B(Image_Desc *im, int larg)
|
||||
{
|
||||
int foo;
|
||||
fprintf(stderr, "****** Image_cadre_B is obsolete ******\n");
|
||||
fprintf(stderr, "****** Use Image_cadre_cracra !! ******\n");
|
||||
foo = Image_cadre_cracra(im, larg, 0);
|
||||
|
||||
return foo;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* --------------------------------------------------
|
||||
* 3 octobre 2009 : il faudra la renommer pour etre XXX
|
||||
* en accord avec 'tga_cadre' qui la nomme "sweep". XXX
|
||||
*/
|
||||
int
|
||||
Image_cadre_C(Image_Desc *im, int r, int g, int b, int n)
|
||||
{
|
||||
int x, y, x2, y2, ir, ig, ib;
|
||||
float fx, fy;
|
||||
float d, fn, coef;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s : %d %d %d / %d\n", __func__, r, g, b, n);
|
||||
#endif
|
||||
|
||||
fn = (float)(n*n);
|
||||
x2 = im->width / 2;
|
||||
y2 = im->height / 2;
|
||||
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
/*
|
||||
* distance au bord HAUT BAS le plus proche
|
||||
*/
|
||||
if (y < y2) fy = (float)y;
|
||||
else fy = (float)((im->height - y)-1);
|
||||
fy = fy*fy;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
/*
|
||||
* distance au bord DROITE GAUCHE le plus proche
|
||||
*/
|
||||
if (x < x2) fx = (float)x;
|
||||
else fx = (float)((im->width - x)-1);
|
||||
fx = fx*fx;
|
||||
|
||||
/* XXX un peu plus d'explications ici */
|
||||
if (fx < fy) d = fx;
|
||||
else d = fy;
|
||||
|
||||
if (d < fn)
|
||||
{
|
||||
coef = d / fn;
|
||||
ir = (im->Rpix[y])[x];
|
||||
ig = (im->Gpix[y])[x];
|
||||
ib = (im->Bpix[y])[x];
|
||||
|
||||
ir=(int)(((float)ir * coef) + ((float)r * (1.0-coef)));
|
||||
ig=(int)(((float)ig * coef) + ((float)g * (1.0-coef)));
|
||||
ib=(int)(((float)ib * coef) + ((float)b * (1.0-coef)));
|
||||
/* Image_plotRGB(im, x, y, ir, ig, ib); */
|
||||
(im->Rpix[y])[x] = ir;
|
||||
(im->Gpix[y])[x] = ig;
|
||||
(im->Bpix[y])[x] = ib;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* this function was the successor of the 'C' cadre. Need a rename.
|
||||
*/
|
||||
int
|
||||
Image_cadre_bruit(Image_Desc *im, int r, int g, int b, int n)
|
||||
{
|
||||
int x, y, x2, y2, ir, ig, ib;
|
||||
float fx, fy;
|
||||
float d, fn, level;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %d %d %d / %d\n", __func__, r, g, b, n);
|
||||
#endif
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, " %s : current random is %d\n", __func__, rand());
|
||||
#endif
|
||||
|
||||
fn = (float)(n*n);
|
||||
x2 = im->width / 2;
|
||||
y2 = im->height / 2;
|
||||
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
/*
|
||||
* distance au bord HAUT BAS le plus proche
|
||||
*/
|
||||
if (y < y2) fy = (float)y;
|
||||
else fy = (float)((im->height - y)-1);
|
||||
fy = fy*fy;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
/*
|
||||
* distance au bord DROITE GAUCHE le plus proche
|
||||
*/
|
||||
if (x < x2) fx = (float)x;
|
||||
else fx = (float)((im->width - x)-1);
|
||||
fx = fx*fx;
|
||||
|
||||
if (fx < fy) d = fx;
|
||||
else d = fy;
|
||||
|
||||
if (d < fn)
|
||||
{
|
||||
level = (int)((d / fn) * 1000.0);
|
||||
if ( (rand()%1000) < level )
|
||||
{
|
||||
Image_getRGB(im, x, y, &ir, &ig, &ib);
|
||||
}
|
||||
else
|
||||
{
|
||||
ir = r; ig = g; ib = b;
|
||||
}
|
||||
/* Image_plotRGB(im, x, y, ir, ig, ib); */
|
||||
(im->Rpix[y])[x] = ir;
|
||||
(im->Gpix[y])[x] = ig;
|
||||
(im->Bpix[y])[x] = ib;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* inventee pour blablanux :) */
|
||||
int
|
||||
Image_cadre_E(Image_Desc *im, int v1, int v2, int v3, int dim)
|
||||
{
|
||||
int foo, bar;
|
||||
Image_Rect rect;
|
||||
|
||||
for (foo=0; foo<dim; foo++)
|
||||
{
|
||||
bar = 1 << (foo%8);
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "cadre E: foo is %d, bar is 0x%x\n", foo, bar);
|
||||
#endif
|
||||
rect.x = foo;
|
||||
rect.y = foo;
|
||||
rect.w = im->width - foo*2;
|
||||
rect.h = im->height - foo*2;
|
||||
Image_draw_rect(im, &rect, v1^bar, v2^bar, v3^bar);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 5 Fev 2001
|
||||
* pas de dégradé
|
||||
*/
|
||||
int
|
||||
Image_cadre_pattern_0(Image_Desc *im, Image_Desc *pat, int larg)
|
||||
{
|
||||
int x, y, r, g, b;
|
||||
|
||||
/*
|
||||
* Tiens, je la supposais plus facile a ecrire...
|
||||
*/
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
for (x=0; x<larg; x++)
|
||||
{
|
||||
Image_getRGB(pat, x%pat->width, y%pat->height, &r, &g, &b);
|
||||
/* Image_plotRGB(im, x, y, r, g, b); */
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
for (x=im->width-larg; x<im->width; x++)
|
||||
{
|
||||
Image_getRGB(pat, x%pat->width, y%pat->height, &r, &g, &b);
|
||||
/* Image_plotRGB(im, x, y, r, g, b); */
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
}
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
for (y=0; y<larg; y++)
|
||||
{
|
||||
Image_getRGB(pat, x%pat->width, y%pat->height, &r, &g, &b);
|
||||
/* Image_plotRGB(im, x, y, r, g, b); */
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
for (y=im->height-larg; y<im->height; y++)
|
||||
{
|
||||
Image_getRGB(pat, x%pat->width, y%pat->height, &r, &g, &b);
|
||||
/* Image_plotRGB(im, x, y, r, g, b); */
|
||||
(im->Rpix[y])[x] = r;
|
||||
(im->Gpix[y])[x] = g;
|
||||
(im->Bpix[y])[x] = b;
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 12 Feb 2001
|
||||
* dégradé propotionnel à la distance
|
||||
*/
|
||||
int
|
||||
Image_cadre_pattern_1(Image_Desc *im, Image_Desc *pat, int n)
|
||||
{
|
||||
int x, y, x2, y2, ir, ig, ib, jr, jg, jb, r, g, b;
|
||||
float fx, fy;
|
||||
float d, fn, level;
|
||||
int lmax;
|
||||
|
||||
fn = (float)(n*n);
|
||||
fx = fy = 0.0; /* warning shutter */
|
||||
x2 = im->width / 2;
|
||||
y2 = im->height / 2;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "*** cadre pattern 1 : fn = %f\n", fn);
|
||||
#endif
|
||||
|
||||
lmax = 0;
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
/*
|
||||
* distance au bord HAUT BAS le plus proche
|
||||
*/
|
||||
if (y < y2) fy = (float)y;
|
||||
else fy = (float)((im->height - y)-1);
|
||||
fy = fy*fy;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
|
||||
/*
|
||||
* distance au bord DROITE GAUCHE le plus proche
|
||||
*/
|
||||
if (x < x2) fx = (float)x;
|
||||
else fx = (float)((im->width - x)-1);
|
||||
fx = fx*fx;
|
||||
|
||||
/*
|
||||
* we take the smallest of the two distances
|
||||
*/
|
||||
if (fx < fy) d = fx;
|
||||
else d = fy;
|
||||
|
||||
if (d < fn)
|
||||
{
|
||||
level = (int)(100 * d / fn);
|
||||
if (level > lmax)
|
||||
{
|
||||
lmax = level;
|
||||
}
|
||||
|
||||
Image_getRGB(im, x, y, &ir, &ig, &ib);
|
||||
Image_getRGB(pat, x%pat->width, y%pat->height,
|
||||
&jr, &jg, &jb);
|
||||
|
||||
r = (ir * level) + (jr * (100-level));
|
||||
g = (ig * level) + (jg * (100-level));
|
||||
b = (ib * level) + (jb * (100-level));
|
||||
/* Image_plotRGB(im, x, y, r/100, g/100, b/100); */
|
||||
(im->Rpix[y])[x] = r / 100;
|
||||
(im->Gpix[y])[x] = g / 100;
|
||||
(im->Bpix[y])[x] = b / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "cadre pattern 1 : lmax = %d\n", lmax);
|
||||
#endif
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_cadre_pattern_2(Image_Desc *im, Image_Desc *pat, int n)
|
||||
{
|
||||
int x, y, x2, y2, ir, ig, ib;
|
||||
int xp, yp;
|
||||
float fx, fy;
|
||||
float d, fn, level;
|
||||
int lmax;
|
||||
|
||||
fn = (float)(n*n);
|
||||
fx = fy = 0.0; /* warning shutter */
|
||||
x2 = im->width / 2;
|
||||
y2 = im->height / 2;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "*** cadre pat 2 : fn = %f\n", fn);
|
||||
fprintf(stderr, "*** cadre pat 2 : pat: %d x %d\n", pat->width, pat->height);
|
||||
#endif
|
||||
|
||||
lmax = 0;
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
/* distance au bord HAUT BAS le plus proche */
|
||||
if (y < y2) fy = (float)y;
|
||||
else fy = (float)((im->height - y)-1);
|
||||
fy = fy*fy;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
/* distance au bord DROITE GAUCHE le plus proche */
|
||||
if (x < x2) fx = (float)x;
|
||||
else fx = (float)((im->width - x)-1);
|
||||
fx = fx*fx;
|
||||
/* we take the smallest of the two distances */
|
||||
if (fx < fy) d = fx;
|
||||
else d = fy;
|
||||
|
||||
if (d < fn)
|
||||
{
|
||||
level = (int)((d / fn) * 1000.0);
|
||||
if ( (rand()%1000) < level )
|
||||
{
|
||||
Image_getRGB(im, x, y, &ir, &ig, &ib);
|
||||
}
|
||||
else
|
||||
{
|
||||
xp = x % pat->width;
|
||||
yp = y % pat->height;
|
||||
Image_getRGB(pat, xp, yp, &ir, &ig, &ib);
|
||||
}
|
||||
/* Image_plotRGB(im, x, y, ir, ig, ib); */
|
||||
(im->Rpix[y])[x] = ir;
|
||||
(im->Gpix[y])[x] = ig;
|
||||
(im->Bpix[y])[x] = ib;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* et maintenant ? on peut aller voir 'cadres2.c' ? */
|
||||
/*::------------------------------------------------------------------::*/
|
190
Lib/cadres2.c
Normal file
190
Lib/cadres2.c
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
cadres2.c
|
||||
=========
|
||||
more specific 'cadres' around images.
|
||||
work in progress, you have to wait (a long time ?)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* je sais pas trop encore quoi faire, là...
|
||||
* probablement poser l'image sur un fond avec une ombre en
|
||||
* dessous...
|
||||
*/
|
||||
int
|
||||
Image_cadre2_soft_1(Image_Desc *src, Image_Desc *dst, RGBA *fond, RGBA *cadre,
|
||||
int larg, int v1, int v2, int v3, int v4)
|
||||
{
|
||||
int foo;
|
||||
Image_Rect rect;
|
||||
|
||||
(void)cadre; (void)larg;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Cadre2 soft 1: work in progress...\n");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ze kontrol !
|
||||
*/
|
||||
if (src == dst)
|
||||
{
|
||||
fprintf(stderr, "Cadre2 soft 1: source==destination\n");
|
||||
return IMG_OVERWRITE;
|
||||
}
|
||||
|
||||
foo = Image_clear(dst, fond->r, fond->g, fond->b);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "cadre2 soft 1: clear: %d\n", foo);
|
||||
#endif
|
||||
|
||||
/* -------- on copie la partie de l'image source */
|
||||
fprintf(stderr, "Cadre2 soft 1: copy image source\n");
|
||||
rect.x = v1; rect.y = v2;
|
||||
rect.w = src->width;
|
||||
rect.h = src->height;
|
||||
#if DEBUG_LEVEL > 1
|
||||
Image_dump_rect(&rect, "cadre2 soft 1", 0);
|
||||
Image_TGA_save("aaaa-a.tga", src, 0);
|
||||
#endif
|
||||
|
||||
foo = Image_copy_rect(src, &rect, dst, rect.x, rect.y);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Cadre2 soft 1: retour copy rect = %d pixels\n", foo);
|
||||
#endif
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* fonction en chantier: coredump probable
|
||||
*/
|
||||
int
|
||||
Image_cadre2_pixx(Image_Desc *src, Image_Desc *dst, int p1, int p2)
|
||||
{
|
||||
int x, y, foo;
|
||||
int r, g, b;
|
||||
int p;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s : %s : is a wip (%d,%d)\n", __FILE__, __func__, p1, p2);
|
||||
#endif
|
||||
|
||||
if ( p1==0 || p2==0 )
|
||||
{
|
||||
fprintf(stderr, "Cadres 2: pixx: no zero parameters, please.\n");
|
||||
return DIVISOR_IS_ZERO;
|
||||
}
|
||||
|
||||
if ( (p1 > src->width/3) || (p1 > src->height/3) )
|
||||
{
|
||||
fprintf(stderr, "Cadres 2: pixx: p1 %d out of range.\n", p1);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
foo = rand() % p1;
|
||||
for (y=0; y<foo; y++)
|
||||
{
|
||||
Image_getRGB(src, x, y, &r, &g, &b);
|
||||
r ^= (rand()%p2);
|
||||
g ^= (rand()%p2);
|
||||
b ^= (rand()%p2);
|
||||
|
||||
(dst->Rpix[y])[x] = r;
|
||||
(dst->Gpix[y])[x] = g;
|
||||
(dst->Bpix[y])[x] = b;
|
||||
}
|
||||
foo = rand() % p1;
|
||||
for (y=0; y<foo; y++)
|
||||
{
|
||||
Image_getRGB(src, x, (src->height-1)-y, &r, &g, &b);
|
||||
r ^= (rand()%p2);
|
||||
g ^= (rand()%p2);
|
||||
b ^= (rand()%p2);
|
||||
|
||||
p = (dst->height-1)-y;
|
||||
(dst->Rpix[p])[x] = r;
|
||||
(dst->Gpix[p])[x] = g;
|
||||
(dst->Bpix[p])[x] = b;
|
||||
}
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
foo = rand() % p1;
|
||||
for (x=0; x<foo; x++)
|
||||
{
|
||||
Image_getRGB(src, x, y, &r, &g, &b);
|
||||
r ^= (rand()%p2);
|
||||
g ^= (rand()%p2);
|
||||
b ^= (rand()%p2);
|
||||
|
||||
(dst->Rpix[y])[x] = r;
|
||||
(dst->Gpix[y])[x] = g;
|
||||
(dst->Bpix[y])[x] = b;
|
||||
}
|
||||
foo = rand() % p1;
|
||||
for (x=0; x<foo; x++)
|
||||
{
|
||||
Image_getRGB(src, (dst->width-1)-x, y, &r, &g, &b);
|
||||
r ^= (rand()%p2);
|
||||
g ^= (rand()%p2);
|
||||
b ^= (rand()%p2);
|
||||
|
||||
p = (dst->width-1)-x;
|
||||
(dst->Rpix[y])[p] = r;
|
||||
(dst->Gpix[y])[p] = g;
|
||||
(dst->Bpix[y])[p] = b;
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* this func is a derivative of the _original_ cadre function
|
||||
* named 'Image_cadre_A' and located in file 'cadres.c'
|
||||
*/
|
||||
int
|
||||
Image_cadre_f(Image_Desc *im, int a, int b)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (x=0; x<im->width; x++)
|
||||
{
|
||||
(im->Rpix[0])[x] = a;
|
||||
(im->Gpix[0])[x] = a;
|
||||
(im->Bpix[0])[x] = a;
|
||||
Image_plotRGB(im, x, im->height-1, a, a, a);
|
||||
}
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
(im->Rpix[y])[0] = a;
|
||||
(im->Gpix[y])[0] = a;
|
||||
(im->Bpix[y])[0] = a;
|
||||
Image_plotRGB(im, im->width-1, y, a, a, a);
|
||||
}
|
||||
for (x=1; x<im->width-1; x++)
|
||||
{
|
||||
(im->Rpix[1])[x] = b;
|
||||
(im->Gpix[1])[x] = b;
|
||||
(im->Bpix[1])[x] = b;
|
||||
Image_plotRGB(im, x, im->height-2, b, b, b);
|
||||
}
|
||||
for (y=1; y<im->height-1; y++)
|
||||
{
|
||||
(im->Rpix[y])[1] = b;
|
||||
(im->Gpix[y])[1] = b;
|
||||
(im->Bpix[y])[1] = b;
|
||||
Image_plotRGB(im, im->width-2, y, b, b, b);
|
||||
}
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
127
Lib/cadres3.c
Normal file
127
Lib/cadres3.c
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
cadres3.c
|
||||
=========
|
||||
|
||||
floating points 'cadres' around images.
|
||||
work in progress, you have to wait (a long time ?)
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* 8 Dec 2001: this cadre was first designed for my ExPOVsition
|
||||
*/
|
||||
int
|
||||
Image_cadre_waves_0(Image_Desc *img, int perx, int pery, RGBA *rgb, int amp)
|
||||
{
|
||||
int x, y, val, foo;
|
||||
double dx, dy, dw, dh, damp;
|
||||
double kx, ky;
|
||||
|
||||
if ( amp>=img->width/2 || amp>=img->height/2 )
|
||||
{
|
||||
fprintf(stderr, "Image cadre waves 0: amp (%d) is too big\n", amp);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
damp = (double)amp;
|
||||
dw = (double)img->width;
|
||||
dh = (double)img->height;
|
||||
|
||||
kx = (M_PI * 2.0 * (double)perx) / dw;
|
||||
ky = (M_PI * 2.0 * (double)pery) / dh;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
printf("Cadre3 waves 0: px %d py %d amp %d\n", perx, pery, amp);
|
||||
printf(" dw %f kx %f\n", dw, kx);
|
||||
printf(" dh %f ky %f\n", dh, ky);
|
||||
#endif
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
dx = ((double)x * kx) - (M_PI/2);
|
||||
val = (int)((sin(dx)*damp)+damp)+1;
|
||||
|
||||
for (foo=0; foo<val; foo++)
|
||||
{
|
||||
Image_plotRGB(img, x, foo, rgb->r, rgb->g, rgb->a);
|
||||
Image_plotRGB(img, img->width-x-1, img->height-foo-1,
|
||||
rgb->r, rgb->g, rgb->a);
|
||||
}
|
||||
}
|
||||
|
||||
for (y=0; y<img->height; y++)
|
||||
{
|
||||
dy = (double)y * ky - (M_PI/2);
|
||||
val = (int)((sin(dy)*damp)+damp);
|
||||
|
||||
for (foo=0; foo<val; foo++)
|
||||
{
|
||||
Image_plotRGB(img, foo, y, rgb->r, rgb->g, rgb->a);
|
||||
Image_plotRGB(img, img->width-foo-1, y,
|
||||
rgb->r, rgb->g, rgb->a);
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* celui-ci, il faudra l'inventer un de ces jours....
|
||||
*/
|
||||
int
|
||||
Image_cadre_waves_1(Image_Desc *img, int perx, int pery, RGBA *rgb, int amp)
|
||||
{
|
||||
int x, y, val, foo;
|
||||
|
||||
if ( amp>=img->width/2 || amp>=img->height/2 )
|
||||
{
|
||||
fprintf(stderr, "Image cadre waves 1: amp (%d) is too big\n", amp);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* celui-ci, il faudra l'inventer un de ces jours....
|
||||
*/
|
||||
int
|
||||
Image_cadre_waves_2(Image_Desc *img, int perx, int pery, int amp)
|
||||
{
|
||||
int x, y, val, foo;
|
||||
double dx, dy, dw, dh, damp;
|
||||
double kx, ky;
|
||||
int r, g, b;
|
||||
|
||||
if ( amp>=img->width/2 || amp>=img->height/2 )
|
||||
{
|
||||
fprintf(stderr, "Image cadre waves 2: amp (%d) is too big\n", amp);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
damp = (double)amp;
|
||||
dw = (double)img->width;
|
||||
dh = (double)img->height;
|
||||
|
||||
kx = (M_PI * 2.0 * (double)perx) / dw;
|
||||
ky = (M_PI * 2.0 * (double)pery) / dh;
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
dx = ((double)x * kx) - (M_PI/2);
|
||||
val = (int)((sin(dx)*damp)+damp)+1;
|
||||
for (foo=0; foo<val; foo++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
235
Lib/cadres4.c
Normal file
235
Lib/cadres4.c
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
cadres4.c
|
||||
=========
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* fonction en chantier -> coredump probable
|
||||
* je ne sais pas à quoi va servir le paramètre 'flags' ...
|
||||
* 7 nov 2007:
|
||||
* le flag a disparu, il contient maintenant la valeur de
|
||||
* la composante verte. lol.
|
||||
*/
|
||||
int
|
||||
Image_cadre_burp_0(Image_Desc *img, int p1, int p2, int gval)
|
||||
{
|
||||
int x, y, zz, v;
|
||||
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s p1=%d p2=%d flg=0x%02x\n", __func__, p1, p2, gval);
|
||||
#endif
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
v = (x * 256) / img->width;
|
||||
for (zz=0; zz<p1; zz++)
|
||||
{
|
||||
y = zz;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = gval;
|
||||
(img->Bpix[y])[x] = v;
|
||||
|
||||
y = img->height-zz-1;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = gval;
|
||||
(img->Bpix[y])[x] = 255-v;
|
||||
}
|
||||
}
|
||||
|
||||
for (y=p1; y<img->height-p1; y++)
|
||||
{
|
||||
v = (y * 256) / img->height;
|
||||
for (zz=0; zz<p2; zz++)
|
||||
{
|
||||
x = zz;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = gval;
|
||||
(img->Bpix[y])[x] = v;
|
||||
|
||||
x = img->width-zz-1;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = gval;
|
||||
(img->Bpix[y])[x] = 255-v;
|
||||
}
|
||||
}
|
||||
|
||||
img->modified = 1;
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* 13 Juin 2002: grosse colère, je vais faire du codage à la Gruuik.
|
||||
*/
|
||||
int
|
||||
Image_cadre_burp_1(Image_Desc *img, int p1, int p2, int flags)
|
||||
{
|
||||
int x, xx, y, yy, v;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %d %d $%x )\n", __func__, img, p1, p2, flags);
|
||||
#endif
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
v = (x * 256) / img->width;
|
||||
#if DEBUG_LEVEL > 1
|
||||
printf("%s : debug %d %d\n", __func__, x, v);
|
||||
#endif
|
||||
for (yy=0; yy<p1; yy++)
|
||||
{
|
||||
y = yy;
|
||||
(img->Rpix[y])[x] = 255-v;
|
||||
(img->Gpix[y])[x] = 255;
|
||||
(img->Bpix[y])[x] = v;
|
||||
|
||||
y = img->height-yy-1;
|
||||
(img->Rpix[y])[x] = v;
|
||||
(img->Gpix[y])[x] = 255;
|
||||
(img->Bpix[y])[x] = 255-v;
|
||||
}
|
||||
}
|
||||
|
||||
for (y=p1; y<img->height-p1; y++)
|
||||
{
|
||||
v = (y * 256) / img->height;
|
||||
for (xx=0; xx<p2; xx++)
|
||||
{
|
||||
x = xx;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = 255;
|
||||
(img->Bpix[y])[x] = v;
|
||||
|
||||
x = img->width-xx-1;
|
||||
(img->Rpix[y])[x] = 0;
|
||||
(img->Gpix[y])[x] = 255;
|
||||
(img->Bpix[y])[x] = 255-v;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & 1)
|
||||
{
|
||||
fprintf(stderr, "plop from %s\n", __func__);
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* new 10 decembre 2007 - ave St Exupery - fait pour l'affichage web
|
||||
* des exemples des objets POV de tTh
|
||||
*/
|
||||
int
|
||||
Image_cadre_burp_2(Image_Desc *img, int taille, int pr, int pg, int pb)
|
||||
{
|
||||
int x, y, zz;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: sz %d, rgb %d %d %d\n", __func__, taille, pr, pg, pb);
|
||||
#endif
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
for (zz=0; zz<taille; zz++)
|
||||
{
|
||||
y = zz;
|
||||
(img->Rpix[y])[x] |= pr;
|
||||
(img->Gpix[y])[x] ^= pg;
|
||||
(img->Bpix[y])[x] &= pb;
|
||||
|
||||
y = img->height-zz-1;
|
||||
(img->Rpix[y])[x] |= pr;
|
||||
(img->Gpix[y])[x] ^= pg;
|
||||
(img->Bpix[y])[x] &= pb;
|
||||
}
|
||||
}
|
||||
|
||||
for (y=taille; y<img->height-taille; y++)
|
||||
{
|
||||
for (zz=0; zz<taille; zz++)
|
||||
{
|
||||
x = zz;
|
||||
(img->Rpix[y])[x] |= pr;
|
||||
(img->Gpix[y])[x] ^= pg;
|
||||
(img->Bpix[y])[x] &= pb;
|
||||
|
||||
x = img->width-zz-1;
|
||||
(img->Rpix[y])[x] |= pr;
|
||||
(img->Gpix[y])[x] ^= pg;
|
||||
(img->Bpix[y])[x] &= pb;
|
||||
}
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_cadre_burp_3(Image_Desc *img, int taille, int pr, int pg, int pb)
|
||||
{
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Cadre burp3 on %p\n", img);
|
||||
#endif
|
||||
|
||||
foo = Image_cadre_burp_2(img, taille, pr, pg, pb);
|
||||
foo = Image_cadre_burp_2(img, taille/2, pr/2, pg/2, pb/2);
|
||||
|
||||
img->modified = 2;
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_rasta_0(Image_Desc *img, int taille)
|
||||
{
|
||||
Image_Rect rect;
|
||||
int foo;
|
||||
int r, g, b;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : img at %p, taille=%d\n", __func__, img, taille);
|
||||
#endif
|
||||
|
||||
#define RASTA_RAND 2
|
||||
|
||||
rect.x = rect.y = 0;
|
||||
rect.w = img->width;
|
||||
rect.h = img->height;
|
||||
|
||||
for (foo=0; foo<taille; foo++)
|
||||
{
|
||||
r = 220 + (rand() % RASTA_RAND);
|
||||
b = 10 + (rand() % RASTA_RAND);
|
||||
Image_draw_rect(img, &rect, r, 10, b);
|
||||
rect.x++; rect.y++;
|
||||
rect.h-=2; rect.w-=2;
|
||||
}
|
||||
for (foo=0; foo<taille; foo++)
|
||||
{
|
||||
r = 220 + (rand() % RASTA_RAND);
|
||||
g = 200 + (rand() % RASTA_RAND);
|
||||
Image_draw_rect(img, &rect, r, g, 10);
|
||||
rect.x++; rect.y++;
|
||||
rect.h-=2; rect.w-=2;
|
||||
}
|
||||
for (foo=0; foo<taille; foo++)
|
||||
{
|
||||
g = 220 + (rand() % RASTA_RAND);
|
||||
b = 10 + (rand() % RASTA_RAND);
|
||||
Image_draw_rect(img, &rect, 10, g, b);
|
||||
rect.x++; rect.y++;
|
||||
rect.h-=2; rect.w-=2;
|
||||
}
|
||||
|
||||
img->modified = 1;
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
93
Lib/cadres84.c
Normal file
93
Lib/cadres84.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* cadres84.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_b84_a(Image_Desc *img, int parX, int parY, int k)
|
||||
{
|
||||
int h, w, x, y, foo;
|
||||
|
||||
h = img->height; w = img->width;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: %p px=%d py=%d k=%d\n", __func__, img, parX, parY, k);
|
||||
#endif
|
||||
|
||||
for (y=0; y<h; y++)
|
||||
{
|
||||
for (foo=0; foo<parX; foo++)
|
||||
{
|
||||
Image_plot_channel(img, 'r', foo, y, k);
|
||||
Image_plot_channel(img, 'g', foo, y, 256-k);
|
||||
Image_plot_channel(img, 'b', (w-foo)-1, y, k);
|
||||
Image_plot_channel(img, 'r', (w-foo)-1, y, 256-k);
|
||||
}
|
||||
}
|
||||
|
||||
return BAD_CADRE;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* mise en place 9 avril 2010 */
|
||||
int Image_cadre_b84_b(Image_Desc *img, int k0, int k1)
|
||||
{
|
||||
int x, y, r, g, b;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %d %d )\n", __func__, img, k0, k1);
|
||||
#endif
|
||||
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
for (foo=0; foo<k1; foo++)
|
||||
{
|
||||
y = 0 + foo;
|
||||
Image_getRGB(img, x, y, &r, &g, &b);
|
||||
if (rand() & 0x1180)
|
||||
{
|
||||
r = (r/2) + 127; g = b / 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
r ^= rand(); g ^= rand(); b ^= rand();
|
||||
}
|
||||
Image_plotRGB(img, x, y, r, g, b);
|
||||
|
||||
y = img->height - (foo+1);
|
||||
Image_getRGB(img, x, y, &r, &g, &b);
|
||||
if (rand() & 0x1180)
|
||||
{
|
||||
r = (r/2) + 127; g = b / 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
r ^= rand(); g ^= rand(); b ^= rand();
|
||||
}
|
||||
Image_plotRGB(img, x, y, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_b84_c(Image_Desc *img, int k0, int k1, int k2)
|
||||
{
|
||||
int h, w, x, y, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: %p %d * %d %d\n", __func__, img, k0, k1, k2);
|
||||
#endif
|
||||
|
||||
fprintf(stderr, " +------------------------------+\n");
|
||||
fprintf(stderr, " | SOFTWARE FAILURE - TASK HELD |\n");
|
||||
fprintf(stderr, " | FINISH ALL DISK ACTIVITIES |\n");
|
||||
fprintf(stderr, " +------------------------------+\n");
|
||||
|
||||
return BAD_CADRE;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
99
Lib/cadresbox.c
Normal file
99
Lib/cadresbox.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* cadresbox.c - new 30 janvier 2014
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_box_0(Image_Desc *img, int t1, RGBA *color)
|
||||
{
|
||||
int foo;
|
||||
Image_Rect rect;
|
||||
RGBA tmpcol;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %d )\n", __func__, img, t1);
|
||||
#endif
|
||||
|
||||
/* in first action, we make left & right borders of the picz */
|
||||
rect.w = t1; rect.h = img->height;
|
||||
rect.x = rect.y = 0;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
rect.x = img->width - t1;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
|
||||
/* next part : top and bottom borders */
|
||||
rect.h = t1; rect.w = img->width;
|
||||
rect.x = rect.y = 0;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
rect.y = img->height - t1;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
|
||||
tmpcol.r = color->r ^ 0x80;
|
||||
tmpcol.g = color->b ^ 0x80;
|
||||
tmpcol.b = color->b ^ 0x80;
|
||||
rect.x = t1; rect.y = t1;
|
||||
rect.w = img->width - (t1 * 2);
|
||||
rect.h = img->height - (t1 * 2);
|
||||
foo = Image_draw_rect(img, &rect, tmpcol.r, tmpcol.g, tmpcol.b);
|
||||
|
||||
return FUNC_IS_ALPHA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_4coins_0(Image_Desc *img, int taille, RGBA *color)
|
||||
{
|
||||
int foo;
|
||||
Image_Rect rect;
|
||||
RGBA tmpcol;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %d )\n", __func__, img, taille);
|
||||
#endif
|
||||
|
||||
tmpcol.r = color->r ^ 0x80;
|
||||
tmpcol.g = color->b ^ 0x80;
|
||||
tmpcol.b = color->b ^ 0x80;
|
||||
|
||||
rect.w = rect.h = taille;
|
||||
|
||||
rect.x = rect.y = 0;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
foo = Image_draw_rect(img, &rect, tmpcol.r, tmpcol.g, tmpcol.b);
|
||||
|
||||
rect.x = img->width - taille;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "********* %s ***********\n", __func__);
|
||||
#endif
|
||||
foo = Image_draw_rect(img, &rect, tmpcol.r, tmpcol.g, tmpcol.b);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, " ********* ---> %d\n", foo);
|
||||
#endif
|
||||
|
||||
rect.y = img->height - taille;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
foo = Image_draw_rect(img, &rect, tmpcol.r, tmpcol.g, tmpcol.b);
|
||||
|
||||
rect.x = 0;
|
||||
foo = Image_paint_rect(img, &rect, color->r, color->g, color->b);
|
||||
foo = Image_draw_rect(img, &rect, tmpcol.r, tmpcol.g, tmpcol.b);
|
||||
|
||||
return FUNC_IS_ALPHA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_cadre_box4c_0(Image_Desc *img, int t1, int t2, RGBA *color)
|
||||
{
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %d %d %p )\n", __func__, img, t1, t2, color);
|
||||
#endif
|
||||
|
||||
foo = Image_cadre_box_0(img, t1, color);
|
||||
foo = Image_cadre_4coins_0(img, t2, color);
|
||||
|
||||
return 666;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
162
Lib/col4bits.c
Normal file
162
Lib/col4bits.c
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
col4bits.c
|
||||
|
||||
this module is dedicated to functions who works on
|
||||
4096 colors images. You got four bits by components.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_col4bits_and(Image_Desc *src, Image_Desc *dst)
|
||||
{
|
||||
int foo;
|
||||
|
||||
if ((foo=Image_compare_desc(src, dst))) {
|
||||
fprintf(stderr, "%s : images not compatibles\n", __func__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = Image_copy(src, dst);
|
||||
if (foo) {
|
||||
fprintf(stderr, "In %s: copy: err #%d %s\n", __func__,
|
||||
foo, Image_err2str(foo));
|
||||
return foo;
|
||||
}
|
||||
foo = Image_and_pix(dst, 0xf0, 0xf0, 0xf0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "In %s: and pix: err #%d %s\n", __func__,
|
||||
foo, Image_err2str(foo));
|
||||
return foo;
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
struct elem
|
||||
{
|
||||
long compte;
|
||||
int rgb;
|
||||
};
|
||||
|
||||
static int compare_compteur(struct elem *p1, struct elem *p2)
|
||||
{
|
||||
/* printf("%8d %8d\n", p1->compte, p2->compte); */
|
||||
return (p2->compte - p1->compte);
|
||||
}
|
||||
static int compare_teinte(struct elem *p1, struct elem *p2)
|
||||
{
|
||||
int r1, g1, b1, r2, b2, g2;
|
||||
|
||||
r1 = (( (p1->rgb) >>8)&0xf)<<4;
|
||||
g1 = (( (p1->rgb) >>4)&0xf)<<4;
|
||||
b1 = ( (p1->rgb) &0xf)<<4;
|
||||
|
||||
r2 = (( (p2->rgb) >>8)&0xf)<<4;
|
||||
g2 = (( (p2->rgb) >>4)&0xf)<<4;
|
||||
b2 = ( (p2->rgb) &0xf)<<4;
|
||||
|
||||
/* printf("%8d %8d\n", p1->compte, p2->compte);
|
||||
return (p1->rgb - p2->rgb); */
|
||||
|
||||
return ( (r1+g1+b1) - (r2+g2+b2) );
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
#define TAILLE (1<<12)
|
||||
int
|
||||
Image_calc_Map_4bits(Image_Desc *img, RGB_map *map, int nbre)
|
||||
{
|
||||
long surface, maxi;
|
||||
int x, y, r, g, b, idx;
|
||||
|
||||
struct elem elems[TAILLE];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, " Calc map 4 bits: nbre = %d\n", nbre);
|
||||
#endif
|
||||
|
||||
if ( (nbre<1) || (nbre>255) )
|
||||
{
|
||||
fprintf(stderr, "Calc map 4 bits: nbre %d out of range\n", nbre);
|
||||
return BAD_COLOR_NUMBER;
|
||||
}
|
||||
|
||||
surface = img->width * img->height;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, " calc Map 4 bits: surface de l'image = %ld pixels\n", surface);
|
||||
#endif
|
||||
|
||||
for (x=0; x<TAILLE; x++)
|
||||
{
|
||||
elems[x].compte = 0L;
|
||||
elems[x].rgb = x;
|
||||
}
|
||||
|
||||
maxi = 0L;
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
for (y=0; y<img->height; y++)
|
||||
{
|
||||
r = (img->Rpix[y])[x] >> 4;
|
||||
g = (img->Gpix[y])[x] >> 4;
|
||||
b = (img->Bpix[y])[x] >> 4;
|
||||
idx = (r<<8) | (g<<4) | b;
|
||||
|
||||
if (idx >= TAILLE)
|
||||
{
|
||||
fprintf(stderr, "FATAL ERROR in %s\n", __func__);
|
||||
exit(5);
|
||||
}
|
||||
elems[idx].compte++;
|
||||
if (elems[idx].compte > maxi)
|
||||
maxi = elems[idx].compte;
|
||||
}
|
||||
}
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, " Map4bits: compte maximum = %ld\n", maxi);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* trier la table pour avoir les couleurs les plus
|
||||
* frequentes en haut.
|
||||
*/
|
||||
qsort(elems, TAILLE, sizeof(struct elem), compare_compteur);
|
||||
|
||||
/*
|
||||
* trier la palette, certe, mais dans quel ordre ?
|
||||
*
|
||||
* 28 Jan 2002: why ?
|
||||
*/
|
||||
qsort(elems, nbre, sizeof(struct elem), compare_teinte);
|
||||
|
||||
/*
|
||||
* recopier les 'nbre' entrees hautes dans la palette
|
||||
*/
|
||||
for(x=0; x<nbre; x++)
|
||||
{
|
||||
y = elems[x].rgb;
|
||||
|
||||
r = ((y>>8)&0xf)<<4;
|
||||
g = ((y>>4)&0xf)<<4;
|
||||
b = (y&0xf)<<4;
|
||||
|
||||
/* printf("%06x %02x %02x %02x\n", x, r, g, b); */
|
||||
map->red[x] = r;
|
||||
map->green[x] = g;
|
||||
map->blue[x] = b;
|
||||
}
|
||||
map->nbre = nbre;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Image_calc_Map_4bits: fini!\n");
|
||||
#endif
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
@ -13,7 +13,7 @@
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
#include "tthimage.h"
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
#include "tthimage.h"
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* nouveau 20 janvier 2010 */
|
||||
|
79
Lib/distances.c
Normal file
79
Lib/distances.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* CALCULS DE LA DISTANCE ENTRE DEUX IMAGES
|
||||
*
|
||||
* new 12 janvier 2009 - avenue St Exupery - dans un etat de grosse fatique
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
*/
|
||||
int
|
||||
Image_distance_0(Image_Desc *ia, Image_Desc *ib,
|
||||
double *dr, double *dg, double *db)
|
||||
{
|
||||
int foo, x, y;
|
||||
int ra, ga, ba, rb, gb, bb;
|
||||
|
||||
if ( (foo=Image_compare_desc(ia, ib)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
*dr = *dg = *db = 0.0;
|
||||
|
||||
for (y=0; y<ia->height; y++)
|
||||
{
|
||||
for (x=0; x<ia->width; x++)
|
||||
{
|
||||
ra = (ia->Rpix[y])[x];
|
||||
ga = (ia->Gpix[y])[x];
|
||||
ba = (ia->Bpix[y])[x];
|
||||
rb = (ib->Rpix[y])[x];
|
||||
gb = (ib->Gpix[y])[x];
|
||||
bb = (ib->Bpix[y])[x];
|
||||
*dr += ((double)abs(ra - rb)) / 255.9999999;
|
||||
*dg += ((double)abs(ga - gb)) / 255.9999999;
|
||||
*db += ((double)abs(ba - bb)) / 255.9999999;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s: %12.3f %12.3f %12.3f\n", __func__, *dr, *dg, *db);
|
||||
#endif
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
*/
|
||||
int
|
||||
Image_distance_1(Image_Desc *ia, Image_Desc *ib,
|
||||
double *dr, double *dg, double *db)
|
||||
{
|
||||
int foo, x, y;
|
||||
|
||||
if ( (foo=Image_compare_desc(ia, ib)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
*dr = *dg = *db = 42e42;
|
||||
|
||||
for (y=0; y<ia->height; y++)
|
||||
{
|
||||
for (x=0; x<ia->width; x++)
|
||||
{
|
||||
|
||||
/* FIXME need more code */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_ALPHA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
145
Lib/drawalpha.c
Normal file
145
Lib/drawalpha.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
primitives graphiques deuxieme module (circa 2002)
|
||||
--------------------------------------------------
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.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
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* the easy one.
|
||||
*/
|
||||
int
|
||||
Image_paint_A_rect(Image_Desc *img, Image_Rect *rect, RGBA *rgba)
|
||||
{
|
||||
int xd, yd, xf, yf, x, y;
|
||||
int r, g, b, a0, a1, nbre;
|
||||
|
||||
xd = max(0, rect->x);
|
||||
yd = max(0, rect->y);
|
||||
xf = min((img->width-1), (rect->x+rect->w));
|
||||
yf = min((img->height-1), (rect->y+rect->h));
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Paint Alpha Rect: %d <X< %d %d <Y< %d\n", xd, xf, yd, yf);
|
||||
Image_print_rgba("encre alpha", rgba, 0);
|
||||
#endif
|
||||
|
||||
a0 = 255 - rgba->a;
|
||||
a1 = rgba->a;
|
||||
|
||||
/* printf("a0 = %d a1 = %d\n", a0, a1); */
|
||||
|
||||
nbre = 0;
|
||||
|
||||
for (x=xd; x<xf; x++)
|
||||
{
|
||||
for (y=yd; y<yf; y++)
|
||||
{
|
||||
Image_getRGB(img, x, y, &r, &g, &b);
|
||||
/*
|
||||
* ok, compute now...
|
||||
*/
|
||||
r = ( r*a0 + rgba->r*a1 ) / 255;
|
||||
g = ( g*a0 + rgba->g*a1 ) / 255;
|
||||
b = ( b*a0 + rgba->b*a1 ) / 255;
|
||||
Image_plotRGB(img, x, y, r, g, b);
|
||||
nbre++;
|
||||
}
|
||||
}
|
||||
|
||||
/* fprintf(stderr, "%d points traités\n", nbre); */
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* new 15 Janvier 2003.
|
||||
* première utilisation: l'écriture des titres des
|
||||
* image de l'expovsition.
|
||||
*/
|
||||
int
|
||||
Image_fade_A_rect(Image_Desc *img, Image_Rect *rect, int alpha)
|
||||
{
|
||||
int xd, yd, xf, yf, x, y;
|
||||
int r, g, b ;
|
||||
|
||||
xd = max(0, rect->x);
|
||||
yd = max(0, rect->y);
|
||||
xf = min((img->width-1), (rect->x+rect->w));
|
||||
yf = min((img->height-1), (rect->y+rect->h));
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Fade Alpha Rect: %d < X < %d %d < Y < %d\n",
|
||||
xd, xf, yd, yf);
|
||||
fprintf(stderr, " coefficient alpha = %d\n", alpha);
|
||||
#endif
|
||||
|
||||
for (x=xd; x<xf; x++)
|
||||
{
|
||||
for (y=yd; y<yf; y++)
|
||||
{
|
||||
Image_getRGB(img, x, y, &r, &g, &b);
|
||||
/*
|
||||
* ok, compute now...
|
||||
*/
|
||||
r = ( r*alpha ) / 255;
|
||||
g = ( g*alpha ) / 255;
|
||||
b = ( b*alpha ) / 255;
|
||||
Image_plotRGB(img, x, y, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA; /* need unit testing */
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* nouveau vacances de fevrier 2010 */
|
||||
/*
|
||||
* bon, une fonction pour tamponner une image quelconque avec une
|
||||
* image alpha, il serait temps de la mettre en place, nom ?
|
||||
*/
|
||||
int
|
||||
Image_tampon_alpha_0(Image_Desc *src, Image_Desc *tampon, Image_Desc *dst)
|
||||
{
|
||||
int x, y, rs, gs, bs, rt, gt, bt;
|
||||
int rd, gd, bd, clean_tampon;
|
||||
|
||||
clean_tampon = 0;
|
||||
/* if the 'tampon' is not defined, we have to imagine one */
|
||||
if (NULL==tampon)
|
||||
{
|
||||
tampon = Image_clone(src, 0);
|
||||
fprintf(stderr, "fake tampon @ %p\n", tampon);
|
||||
Image_mirror(src, tampon, 0);
|
||||
clean_tampon = 1;
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
Image_getRGB(src, x, y, &rs, &gs, &bs);
|
||||
Image_getRGB(tampon, x, y, &rt, >, &bt);
|
||||
rd = (rs * rt) / 256;
|
||||
}
|
||||
}
|
||||
|
||||
if (clean_tampon)
|
||||
{
|
||||
fprintf(stderr, "clean %p in %s\n", tampon, __func__);
|
||||
Image_DeAllocate(tampon); free(tampon);
|
||||
}
|
||||
|
||||
return FUNC_IS_ALPHA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
61
Lib/drawpatt.c
Normal file
61
Lib/drawpatt.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* DRAWPATT.C
|
||||
* ==========
|
||||
*
|
||||
* new 1st July 2003
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* ATTENTION CETTE FONCTION COREDUMPE SI LE RECTANGLE
|
||||
* DEPASSE SUR UN BORD DE L'IMAGE !!!
|
||||
*/
|
||||
int
|
||||
Image_draw_rect_from_patt(Image_Desc *img, Image_Rect *rect, Image_Desc *patt)
|
||||
{
|
||||
int x, y, xp, yp, xm, ym;
|
||||
int r, g, b;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>>> %s\n", __func__);
|
||||
#endif
|
||||
|
||||
if ( patt == NULL )
|
||||
{
|
||||
fprintf(stderr, "Badaboum!\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
for (x=0; x<rect->w; x++)
|
||||
{
|
||||
xp = x % patt->width;
|
||||
if (xp > img->width)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (y=0; y<rect->h; y++)
|
||||
{
|
||||
yp = y % patt->height;
|
||||
if (yp > img->height)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Image_getRGB(patt, xp, yp, &r, &g, &b);
|
||||
Image_plotRGB(img, x+rect->x, y+rect->y, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*
|
||||
* ATTENTION CETTE FONCTION COREDUMPE SI LE RECTANGLE
|
||||
* DEPASSE SUR UN BORD DE L'IMAGE !!!
|
||||
*/
|
||||
/*::------------------------------------------------------------------::*/
|
@ -6,7 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "tthimage.h"
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* private variables */
|
||||
|
178
Lib/morpho.c
Normal file
178
Lib/morpho.c
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
morpho.c
|
||||
---------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
static struct
|
||||
{
|
||||
int x, y;
|
||||
} deltas[] =
|
||||
{ { -1, -1, },
|
||||
{ 0, -1, },
|
||||
{ 1, -1, },
|
||||
{ -1, 0, },
|
||||
{ 0, 0, },
|
||||
{ 1, 0, },
|
||||
{ -1, 1, },
|
||||
{ 0, 1, },
|
||||
{ 1, 1 }
|
||||
};
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* n'est-ce pas une dilatation ?
|
||||
* =============================
|
||||
* 23 avril 2007: switched to direct pixel access.
|
||||
*/
|
||||
int
|
||||
Image_expand_max(Image_Desc *src, Image_Desc *dst, int factor)
|
||||
{
|
||||
int foo, x, y, maxr, maxg, maxb;
|
||||
int r, g, b;
|
||||
|
||||
if ( (foo=Image_compare_desc(src, dst)) )
|
||||
{
|
||||
return foo;
|
||||
}
|
||||
|
||||
if ( 0 != factor )
|
||||
{
|
||||
fprintf(stderr, "%s: factor (%d) must be 0\n", __func__, factor);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "expanding MAX %p to %p\n", src, dst);
|
||||
#endif
|
||||
|
||||
for (y=1; y<src->height-1; y++)
|
||||
{
|
||||
for (x=1; x<src->width-1; x++)
|
||||
{
|
||||
maxr = maxg = maxb = 0;
|
||||
for (foo=0; foo<9; foo++)
|
||||
{
|
||||
/* XXX Faster pussy cat !
|
||||
Image_getRGB(src, x+deltas[foo].x, y+deltas[foo].y,
|
||||
&r, &g, &b);
|
||||
*/
|
||||
r = src->Rpix[y+deltas[foo].y][x+deltas[foo].x];
|
||||
g = src->Gpix[y+deltas[foo].y][x+deltas[foo].x];
|
||||
b = src->Bpix[y+deltas[foo].y][x+deltas[foo].x];
|
||||
|
||||
if (maxr < r) maxr = r;
|
||||
if (maxg < g) maxg = g;
|
||||
if (maxb < b) maxb = b;
|
||||
}
|
||||
/* XXX Kill Kill !y cat !
|
||||
Image_plotRGB(dst, x, y, maxr, maxg, maxb);
|
||||
*/
|
||||
dst->Rpix[y][x] = maxr;
|
||||
dst->Gpix[y][x] = maxg;
|
||||
dst->Bpix[y][x] = maxb;
|
||||
}
|
||||
}
|
||||
dst->modified = 1;
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_expand_min(Image_Desc *src, Image_Desc *dst, int factor)
|
||||
{
|
||||
int foo, x, y, minr, ming, minb;
|
||||
int r, g, b;
|
||||
|
||||
if ( (foo=Image_compare_desc(src, dst)) )
|
||||
{
|
||||
return foo;
|
||||
}
|
||||
|
||||
if ( 0 != factor )
|
||||
{
|
||||
fprintf(stderr, "%s: factor (%d) must be 0\n", __func__, factor);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "expanding MIN %p to %p\n", src, dst);
|
||||
#endif
|
||||
|
||||
for (y=1; y<src->height-1; y++)
|
||||
{
|
||||
for (x=1; x<src->width-1; x++)
|
||||
{
|
||||
minr = ming = minb = 1664;
|
||||
for (foo=0; foo<9; foo++)
|
||||
{
|
||||
Image_getRGB(src, x+deltas[foo].x, y+deltas[foo].y,
|
||||
&r, &g, &b);
|
||||
|
||||
if (minr > r) minr = r;
|
||||
if (ming > g) ming = g;
|
||||
if (minb > b) minb = b;
|
||||
|
||||
}
|
||||
Image_plotRGB(dst, x, y, minr, ming, minb);
|
||||
}
|
||||
}
|
||||
dst->modified = 1;
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
struct sort_pixel
|
||||
{
|
||||
int r, g, b;
|
||||
int gris;
|
||||
int rang;
|
||||
};
|
||||
|
||||
static void
|
||||
Image_sortmat_display(FILE *ou, struct sort_pixel *table)
|
||||
{
|
||||
fprintf(ou, "%s ( %p )\n", __func__, table);
|
||||
}
|
||||
|
||||
int
|
||||
Image_Gray_Sorted_Points(Image_Desc *src, Image_Desc *dst, int *filtre)
|
||||
{
|
||||
int x, y, r, g, b;
|
||||
int foo, gris;
|
||||
|
||||
struct sort_pixel pixels[9];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Image Gray Sorted Points: %p -> %p\n", src, dst);
|
||||
#endif
|
||||
|
||||
for (y=1; y<src->height-1; y++)
|
||||
{
|
||||
for (x=1; x<src->width-1; x++)
|
||||
{
|
||||
/* collecte des infos sur les voisins. */
|
||||
for (foo=0; foo<9; foo++)
|
||||
{
|
||||
Image_getRGB(src, x+deltas[foo].x, y+deltas[foo].y,
|
||||
&r, &g, &b);
|
||||
|
||||
pixels[foo].r = r;
|
||||
pixels[foo].g = g;
|
||||
pixels[foo].b = b;
|
||||
pixels[foo].gris = r + g + b;
|
||||
pixels[foo].rang = foo;
|
||||
}
|
||||
|
||||
/* tri des informations collectées. */
|
||||
gris = 0;
|
||||
|
||||
/* application des coeficients */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "**** Ha %p Ha this function is _not_ written ****\n", dst);
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
143
Lib/mosaic.c
Normal file
143
Lib/mosaic.c
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* mosaic.c des mosaiques :)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
<mode rengaine>
|
||||
Et la doc, elle est où ?
|
||||
</mode>
|
||||
<mode #linuxfr>
|
||||
DTC
|
||||
</mode>
|
||||
*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_mosaic_0(Image_Desc *src, Image_Desc *dst, int sx, int sy, int flg)
|
||||
{
|
||||
int w, h, foo;
|
||||
Image_Desc *carre1, *carre2;
|
||||
Image_Rect rect;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s(%p, %p, %d, %d, $%x)\n", __func__, src, dst, sx, sy, flg);
|
||||
#endif
|
||||
|
||||
if ( (carre1=Image_alloc(sx, sy, 3)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "mosaic 0: pas de memoire pour le carre 1\n");
|
||||
exit(5);
|
||||
}
|
||||
if ( (carre2=Image_alloc(sx, sy, 3)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "mosaic 0: pas de memoire pour le carre 2\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s: flag is %d\n", __func__, flg);
|
||||
#endif
|
||||
|
||||
rect.w = sx; rect.h = sy;
|
||||
|
||||
for (h=0; h<src->height; h+=sy)
|
||||
{
|
||||
for (w=0; w<src->width; w+=sx)
|
||||
{
|
||||
rect.x = w; rect.y = h;
|
||||
foo = Image_get_rect(src, &rect, carre1, 0, 0);
|
||||
Image_egalise_mono_0(carre1, carre2, 0);
|
||||
rect.x = 0; rect.y = 0;
|
||||
foo = Image_put_rect(carre2, &rect, dst, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
Image_DeAllocate(carre1); free(carre1);
|
||||
Image_DeAllocate(carre2); free(carre2);
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
#define STEP 32
|
||||
int
|
||||
Image_mosaic_simple(Image_Desc *src, Image_Desc *dst)
|
||||
{
|
||||
int w, h, foo;
|
||||
Image_Desc *carre, *carre2;
|
||||
Image_Rect rect;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s ( %p, %p )\n", __func__, src, dst);
|
||||
#endif
|
||||
|
||||
if ( (carre=Image_alloc(STEP, STEP, 3)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "mosaique simple: pas de memoire pour le carre 1\n");
|
||||
exit(5);
|
||||
}
|
||||
if ( (carre2=Image_alloc(STEP, STEP, 3)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "mosaique simple: pas de memoire pour le carre 2\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
rect.w = STEP; rect.h = STEP;
|
||||
|
||||
for (h=0; h<src->height; h+=STEP)
|
||||
{
|
||||
for (w=0; w<src->width; w+=STEP)
|
||||
{
|
||||
/*
|
||||
* on extrait le petit carre
|
||||
*/
|
||||
Image_clear(carre, 0, 0, 0);
|
||||
rect.x = w; rect.y = h;
|
||||
foo = Image_get_rect(src, &rect, carre, 0, 0);
|
||||
|
||||
Image_egalise_mono_0(carre, carre2, 0);
|
||||
|
||||
/*
|
||||
* et hop, on met le petit carre dans la destination
|
||||
*/
|
||||
rect.x = 0; rect.y = 0;
|
||||
foo = Image_put_rect(carre2, &rect, dst, w, h);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Image_DeAllocate(carre); free(carre);
|
||||
Image_DeAllocate(carre2); free(carre2);
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
void Image_mosaic_prctrl(IMAGE_MOSAIC_CTRL *ctrl, char *txt)
|
||||
{
|
||||
printf(" src: %p\n", ctrl->src);
|
||||
printf(" dst: %p\n", ctrl->dst);
|
||||
printf(" steps: %d %d\n", ctrl->stepx, ctrl->stepy);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_mosaic_iterateur(IMAGE_MOSAIC_CTRL *ctrl, int yo)
|
||||
{
|
||||
|
||||
printf("================= MoZaic IteraTor =====================\n");
|
||||
|
||||
/*
|
||||
* Janvier 2003:
|
||||
* je ne sais toujours pas quoi mettre ici.
|
||||
* Juin 2008:
|
||||
* C'est toujours en standby :)
|
||||
*/
|
||||
Image_mosaic_prctrl(ctrl, "iterateur");
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
37
Lib/operat.c
37
Lib/operat.c
@ -259,43 +259,6 @@ for (foo=0; foo<256; foo++)
|
||||
|
||||
Image_LUT_mono(src, dst, cumul);
|
||||
dst->modified = 1;
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
cette fonction ne marche que si les deux images
|
||||
sont allouees et de meme dimensions.
|
||||
*/
|
||||
int
|
||||
Image_copy(Image_Desc *src, Image_Desc *dst)
|
||||
{
|
||||
int foo;
|
||||
|
||||
if ( (foo=Image_compare_desc(src, dst)) )
|
||||
{
|
||||
fprintf(stderr, "Image_Copy: images are differents %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
for (foo=0; 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
|
||||
>> rgb et peut-être alpha. Mais ce n'est que la partie évident
|
||||
>> d'une image: ses pixels.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
423
Lib/palettes.c
Normal file
423
Lib/palettes.c
Normal file
@ -0,0 +1,423 @@
|
||||
/*
|
||||
palettes.c
|
||||
----------
|
||||
|
||||
for more informations about color maps, you can seek the web
|
||||
from this starting point: http://www.fractint.org/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for rand() */
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* Les colors maps sont censees etre compatible avec celles
|
||||
* de FRACTINT, mais il faudrait verifier.
|
||||
*/
|
||||
int
|
||||
Image_save_color_Map(char *file, char *name, RGB_map *map)
|
||||
{
|
||||
int foo;
|
||||
FILE *fp;
|
||||
|
||||
if ( (fp=fopen(file, "w")) == NULL )
|
||||
{
|
||||
fprintf(stderr, "Save Color Map: err fopen\n");
|
||||
return FILE_CREATE_ERR;
|
||||
}
|
||||
|
||||
if ( map->nbre == 0 )
|
||||
{
|
||||
fprintf(stderr, "Save Color Map: empty map\n");
|
||||
}
|
||||
|
||||
for (foo=0; foo<map->nbre; foo++)
|
||||
{
|
||||
fprintf(fp, "%3d %3d %3d",
|
||||
map->red[foo], map->green[foo], map->blue[foo]);
|
||||
switch (foo)
|
||||
{
|
||||
case 0:
|
||||
if (name != NULL)
|
||||
fprintf(fp, " Name: %s", name);
|
||||
else
|
||||
fprintf(fp, " Anne Onim Colormap");
|
||||
break;
|
||||
case 1:
|
||||
fprintf(fp, " Lib version: %s", IMAGE_VERSION_STRING);
|
||||
break;
|
||||
case 2:
|
||||
fprintf(fp, " Number of colors %d", map->nbre);
|
||||
break;
|
||||
case 3:
|
||||
fprintf(fp, " Bugs -> call Tonton Th");
|
||||
break;
|
||||
case 42:
|
||||
fprintf(fp, " Yes, 42 is _the_ answer");
|
||||
break;
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* Colors map file are (maybe?) compatibles with colors maps
|
||||
* of FRACTINT. More check must be done.
|
||||
*
|
||||
* Les colors maps sont censees etre compatible avec celles
|
||||
* de FRACTINT, mais il faudrait verifier.
|
||||
*
|
||||
* What is the 'right thing' to do when we get more than
|
||||
* 256 lines of data ? return an error ?
|
||||
*/
|
||||
int
|
||||
Image_load_color_Map(char *file, char *name, RGB_map *where)
|
||||
{
|
||||
FILE *fp;
|
||||
int nbre, r, g, b, foo, errcode;
|
||||
char buffer[256];
|
||||
|
||||
if ( name != NULL )
|
||||
{
|
||||
if (strlen(name)>IMG_OBJNAME_LEN)
|
||||
return STRING_TOO_LONG;
|
||||
strcpy(where->name, name);
|
||||
}
|
||||
else strcpy(where->name, "no name");
|
||||
|
||||
/*
|
||||
* patch du 11 Décembre 2001: on utilise une fonction qui recherche le
|
||||
* fichier dans differents endroits. Cf 'musopen.c' pour + de détails.
|
||||
*/
|
||||
if ((fp=Image_must_fopen(file, "r", 0)) == NULL)
|
||||
{
|
||||
/* safety poke */
|
||||
where->nbre = 0;
|
||||
fprintf(stderr, "Load color MAP: %s not found\n", file);
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
nbre = 0; errcode = 0;
|
||||
where->nbre = 0; /* kill bad value */
|
||||
|
||||
while ( fgets(buffer, 250, fp) != NULL )
|
||||
{
|
||||
foo = sscanf(buffer, "%d %d %d", &r, &g, &b);
|
||||
if (foo != 3)
|
||||
{
|
||||
fprintf(stderr, "line %d: [%s]\n", nbre, buffer);
|
||||
errcode = BAD_COLOR_NUMBER; break;
|
||||
}
|
||||
where->red[nbre] = r;
|
||||
where->green[nbre] = g;
|
||||
where->blue[nbre] = b;
|
||||
nbre++;
|
||||
if (nbre > 256)
|
||||
{
|
||||
fprintf(stderr, "load color map: nbre = %d\n", nbre);
|
||||
errcode = MAP_TOO_BIG; break;
|
||||
}
|
||||
}
|
||||
|
||||
where->nbre = nbre;
|
||||
fclose(fp);
|
||||
|
||||
return errcode;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* attach color map a finir...
|
||||
*
|
||||
* XXX voir aussi indexcol.x XXX
|
||||
*/
|
||||
int
|
||||
Image_attach_Map(Image_Desc *im, char *nom_map, int flags)
|
||||
{
|
||||
RGB_map map;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "Image attach Map: cette fonction n'est pas finie\n");
|
||||
foo = Image_load_color_Map(nom_map, "", &map);
|
||||
if (foo == 0)
|
||||
{
|
||||
fprintf(stderr, "Attach Map: foo is zero ?\n");
|
||||
}
|
||||
|
||||
return FUNC_NOT_FINISH;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 31 Juillet 2000 */
|
||||
|
||||
int
|
||||
Image_make_random_Map(char *nom, RGB_map *map, int nbre)
|
||||
{
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "making a random map named '%s'\n", nom);
|
||||
|
||||
if (nbre < 0 || nbre > 255)
|
||||
{
|
||||
fprintf(stderr, "make random map: nbre = %d\n", map->nbre);
|
||||
return BAD_COLOR_NUMBER;
|
||||
}
|
||||
map->nbre = nbre;
|
||||
|
||||
for (foo=0; foo<nbre; foo++)
|
||||
{
|
||||
map->red[foo] = rand() & 0xff;
|
||||
map->green[foo] = rand() & 0xff;
|
||||
map->blue[foo] = rand() & 0xff;
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 21 Sept 2000
|
||||
Make a 2x2x2 color palette.
|
||||
*/
|
||||
int
|
||||
Image_make_222_Map(char *nom, RGB_map *map, int noise)
|
||||
{
|
||||
int foo, r, g, b;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Make 222 map: parameter 'noise' (%d) not used\n", noise);
|
||||
#endif
|
||||
|
||||
strcpy(map->name, "* FMBL roulaize *");
|
||||
|
||||
map->nbre = 64;
|
||||
|
||||
for (foo=0; foo<64; foo++)
|
||||
{
|
||||
r = ((foo >> 0) & 0x03) * 85;
|
||||
g = ((foo >> 2) & 0x03) * 85;
|
||||
b = ((foo >> 4) & 0x03) * 85;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "make 222 map: %3d: %3d %3d %3d\n", foo, r, g, b);
|
||||
#endif
|
||||
map->red[foo] = r;
|
||||
map->green[foo] = g;
|
||||
map->blue[foo] = b;
|
||||
}
|
||||
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 15 Mai 2001
|
||||
* A big classic: the three-sinus color map.
|
||||
* paramètres:
|
||||
* 0,1,2 R,G,B period
|
||||
* 3,4,5 R,G,B phase
|
||||
* 6,7 reserved
|
||||
*/
|
||||
int
|
||||
Image_palette_3sinus(char *nom, RGB_map *ou, double pars[8])
|
||||
{
|
||||
int foo;
|
||||
double dfoo, dra, dga, dba;
|
||||
|
||||
fprintf(stderr, "Palette 3 Sinus: may be bogus ?\n");
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
for (foo=0; foo<8; foo++)
|
||||
fprintf(stderr, " %3d %g\n", foo, pars[foo]);
|
||||
#endif
|
||||
|
||||
for (foo=0; foo<256; foo++)
|
||||
{
|
||||
dfoo = (double)foo / 255.0 * M_PI * 2;
|
||||
dra = sin((pars[0] * dfoo) + pars[3]);
|
||||
dga = sin((pars[1] * dfoo) + pars[4]);
|
||||
dba = sin((pars[2] * dfoo) + pars[5]);
|
||||
ou->red[foo] = (int)(dra * 127.0 + 127.0);
|
||||
ou->green[foo] = (int)(dga * 127.0 + 127.0);
|
||||
ou->blue[foo] = (int)(dba * 127.0 + 127.0);
|
||||
}
|
||||
|
||||
ou->nbre = 256;
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 18 Dec 2001
|
||||
*/
|
||||
int
|
||||
Image_mix_palettes(RGB_map *p1, RGB_map *p2, RGB_map *d, char *txt, int k)
|
||||
{
|
||||
int idx, k2;
|
||||
int r1, g1, b1, r2, g2, b2;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "Image mix palette: work in progress...\n");
|
||||
#endif
|
||||
|
||||
k2 = 10000 - k;
|
||||
|
||||
for (idx=0; idx<256; idx++)
|
||||
{
|
||||
if (idx < p1->nbre)
|
||||
{
|
||||
r1 = p1->red[idx];
|
||||
g1 = p1->green[idx];
|
||||
b1 = p1->blue[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
r1 = g1 = b1 = 0;
|
||||
}
|
||||
|
||||
if (idx < p2->nbre)
|
||||
{
|
||||
r2 = p2->red[idx];
|
||||
g2 = p2->green[idx];
|
||||
b2 = p2->blue[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
r2 = g2 = b2 = 0;
|
||||
}
|
||||
|
||||
d->red[idx] = (r1*k + r2*k2) / 10000;
|
||||
d->green[idx] = (g1*k + g2*k2) / 10000;
|
||||
d->blue[idx] = (b1*k + b2*k2) / 10000;
|
||||
}
|
||||
|
||||
d->nbre = 256;
|
||||
|
||||
if (strlen(txt)<IMG_OBJNAME_LEN)
|
||||
strcpy(d->name, txt);
|
||||
else
|
||||
strcpy(d->name, "mix palettes: TXT is too long");
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 01 aout 2008 */
|
||||
|
||||
/* XXX HACK XXX */
|
||||
double round(double);
|
||||
/* XXX HACK XXX */
|
||||
|
||||
int Image_scale_palette(RGB_map *p, double v, int clip_it)
|
||||
{
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
int maxval = -99999;
|
||||
#endif
|
||||
|
||||
if (p->nbre < 1 || p->nbre > 256)
|
||||
{
|
||||
fprintf(stderr, "%s: RGB_map %p has %d entries ?\n",
|
||||
__func__, p, p->nbre);
|
||||
}
|
||||
|
||||
for (foo=0; foo<p->nbre; foo++)
|
||||
{
|
||||
p->red[foo] = round((double)p->red[foo] * v);
|
||||
p->green[foo] = round((double)p->green[foo] * v);
|
||||
p->blue[foo] = round((double)p->blue[foo] * v);
|
||||
if (clip_it)
|
||||
{
|
||||
if (p->red[foo] < 0) p->red[foo] = 0;
|
||||
if (p->red[foo] > 255) p->red[foo] = 255;
|
||||
if (p->green[foo] < 0) p->green[foo] = 0;
|
||||
if (p->green[foo] > 255) p->green[foo] = 255;
|
||||
if (p->blue[foo] < 0) p->blue[foo] = 0;
|
||||
if (p->blue[foo] > 255) p->blue[foo] = 255;
|
||||
}
|
||||
#if DEBUG_LEVEL
|
||||
if (p->red[foo] > maxval) maxval = p->red[foo];
|
||||
if (p->green[foo] > maxval) maxval = p->green[foo];
|
||||
if (p->blue[foo] > maxval) maxval = p->blue[foo];
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: maxval is %d\n", __func__, maxval);
|
||||
#endif
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* nouveau 10 aout 2008 - avenue St Exupery -
|
||||
*/
|
||||
int Image_scale3_palette(RGB_map *p, double rk, double gk, double bk,
|
||||
int clip_it)
|
||||
{
|
||||
int foo;
|
||||
|
||||
if (p->nbre < 1 || p->nbre > 256)
|
||||
{
|
||||
fprintf(stderr, "%s: RGB_map %p has %d entries ?\n",
|
||||
__func__, p, p->nbre);
|
||||
}
|
||||
|
||||
for (foo=0; foo<p->nbre; foo++)
|
||||
{
|
||||
p->red[foo] = round((double)p->red[foo] * rk);
|
||||
p->green[foo] = round((double)p->green[foo] * gk);
|
||||
p->blue[foo] = round((double)p->blue[foo] * bk);
|
||||
if (clip_it)
|
||||
{
|
||||
if (p->red[foo] < 0) p->red[foo] = 0;
|
||||
if (p->red[foo] > 255) p->red[foo] = 255;
|
||||
if (p->green[foo] < 0) p->green[foo] = 0;
|
||||
if (p->green[foo] > 255) p->green[foo] = 255;
|
||||
if (p->blue[foo] < 0) p->blue[foo] = 0;
|
||||
if (p->blue[foo] > 255) p->blue[foo] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* nouveau 7 juillet 2010 - enregistrement d'une palette dans un fichier
|
||||
* au format PPM - man ppmquant pour plus de details.
|
||||
* premiere mise en oeuvre : les vignettes de l'exPOVsition.
|
||||
*/
|
||||
int Image_map2ppm(RGB_map *p, char *fname, char *comment)
|
||||
{
|
||||
FILE *fp;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s (( %p '%s' '%s' ))\n", __func__, p, fname, comment);
|
||||
#endif
|
||||
|
||||
if (NULL==p)
|
||||
{
|
||||
fprintf(stderr, "in %s, can't gruik au nill map\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "we have %d colors in palette at %p\n", p->nbre, p);
|
||||
#endif
|
||||
|
||||
if ( (fp=fopen(fname, "w")) == NULL )
|
||||
{
|
||||
fprintf(stderr, "%s: err fopen %s\n", __func__, fname);
|
||||
return FILE_CREATE_ERR;
|
||||
}
|
||||
fprintf(fp, "P3\n%d 1\n255\n", p->nbre);
|
||||
for (foo=0; foo<p->nbre; foo++)
|
||||
{
|
||||
fprintf(fp, "%3d %3d %3d\n", p->red[foo], p->green[foo], p->blue[foo]);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
@ -9,7 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tthimage.h"
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "tthimage.h"
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* private variables */
|
||||
|
@ -4,7 +4,7 @@
|
||||
http:///la.buvette.org/devel/libimage/
|
||||
*/
|
||||
#ifndef IMAGE_VERSION_STRING
|
||||
#define IMAGE_VERSION_STRING "0.4.45"
|
||||
#define IMAGE_VERSION_STRING "0.4.46"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user