Compare commits

..

3 Commits

Author SHA1 Message Date
tth
f3e30ea3bb third massive import batch 2022-06-27 00:48:18 +02:00
tth
96d7a5399f moving files around... 2022-06-26 22:55:56 +02:00
tth
75a06cf5b4 the great code shaking party 2022-06-26 12:22:12 +02:00
136 changed files with 5884 additions and 66 deletions

4
.gitignore vendored
View File

@ -1,5 +1,9 @@
*.o *.o
libimage.a
foo foo
Lib/foo
Lib/t_t16x24

139
Lib/Makefile Normal file
View File

@ -0,0 +1,139 @@
#-----------------------------------------------------------------
#
# The infamous *LIBTTHIMAGE* 20 juin 2022
#
#-----------------------------------------------------------------
include ../Paramakes.mk
DEPS = ../tthimage.h Makefile
STATICLIB = "../libimage.a"
#-----------------------------------------------------------------
basic_io.o: basic_io.c $(DEPS)
bitblt.o: bitblt.c $(DEPS)
calcluts.o:
calculs.o: calculs.c $(DEPS)
classif.o: classif.c $(DEPS)
col_xyz.o: col_xyz.c $(DEPS)
combine.o: combine.c $(DEPS)
combine2.o: combine2.c $(DEPS)
combine3.o: combine3.c $(DEPS)
combine4.o: combine4.c $(DEPS)
combine5.o: combine5.c $(DEPS)
combine6.o: combine6.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)
drawing.o: drawing.c $(DEPS)
effects.o: effects.c $(DEPS)
effects2.o: effects2.c $(DEPS)
effects3.o: effects3.c $(DEPS)
filtres.o: filtres.c $(DEPS)
halfsize.o: halfsize.c $(DEPS)
image.o: image.c $(DEPS)
imprime.o: imprime.c $(DEPS)
luts15bits.o: luts15bits.c $(DEPS)
marques.o: marques.c $(DEPS)
mircol.o: mircol.c $(DEPS)
msglib.o: msglib.c $(DEPS)
mustopen.o: mustopen.c $(DEPS)
operat.o: operat.c $(DEPS)
op2x2.o: op2x2.c $(DEPS)
patterns.o: patterns.c $(DEPS)
patterns2.o: patterns2.c $(DEPS)
patterns3.o: patterns3.c $(DEPS)
patterns4.o: patterns4.c $(DEPS)
pht.o: pht.c $(DEPS)
pixeliz.o: pixeliz.c $(DEPS)
pixels.o: pixels.c $(DEPS)
plotteur.o: plotteur.c $(DEPS)
pov_hf15a.o: pov_hf15a.c $(DEPS)
pov_hf15b.o: pov_hf15b.c $(DEPS)
pov_hf15c.o: pov_hf15c.c $(DEPS)
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)
rgbmask.o: rgbmask.c $(DEPS)
scale.o: scale.c $(DEPS)
sobel4.o: sobel4.c $(DEPS)
tamppool.o: tamppool.c $(DEPS)
television.o: television.c $(DEPS)
text0.o: text0.c $(DEPS)
text1.o: text1.c $(DEPS)
text16x24.o: text16x24.c $(DEPS)
tga.o: tga.c $(DEPS)
tools.o: tools.c $(DEPS)
vignetize.o: vignetize.c $(DEPS)
warp0.o: warp0.c $(DEPS)
warp1.o: warp1.c $(DEPS)
warp2.o: warp2.c $(DEPS)
warp3.o: warp3.c $(DEPS)
#-----------------------------------------------------------------
OBJECTS = basic_io.o bitblt.o \
calculs.o classif.o col_xyz.o \
combine.o combine2.o combine3.o combine4.o combine5.o \
dither.o dither2.o dither3.o dither4.o \
doublesz.o drawing.o \
effects.o effects2.o effects3.o \
filtres.o \
halfsize.o \
image.o imprime.o \
luts15bits.o \
marques.o mircol.o msglib.o mustopen.o \
operat.o op2x2.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 \
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
$(STATICLIB): $(OBJECTS)
$(AR) vrs $@ $?
$(RANLIB) $@
#-----------------------------------------------------------------
foo: foo.c $(DEPS) $(STATICLIB)
gcc $(CFLAGS) $< $(STATICLIB) -o $@
t_t16x24: t_t16x24.c $(DEPS) $(STATICLIB)
gcc $(CFLAGS) $< $(STATICLIB) -o $@
#-----------------------------------------------------------------
essais.o: essais.c $(DEPS) essais.h
gcc $(CFLAGS) $< -c
testtga: testtga.c $(DEPS) $(STATICLIB) essais.o
gcc $(CFLAGS) $< $(STATICLIB) essais.o -lm -o $@
#-----------------------------------------------------------------

4
Lib/README.md Normal file
View File

@ -0,0 +1,4 @@
# The tTh image processind library
Ugly software born around 1995 on a MS-Dos 286 computer.

View File

@ -21,7 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int Image_basicIO_teste_boutisme(char *txt) int Image_basicIO_teste_boutisme(char *txt)

View File

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -10,7 +10,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "tthimage.h" #include "../tthimage.h"
#define VERSION_STRING "5 octobre 2015" #define VERSION_STRING "5 octobre 2015"
@ -248,7 +248,7 @@ if (NULL==(fp=fopen(fname, "w")))
} }
fprintf(fp, "P1\n%d %d\n", bp->width, bp->height); fprintf(fp, "P1\n%d %d\n", bp->width, bp->height);
fprintf(fp, "# written by libimage v %s\n# bitplane module '%s'\n", fprintf(fp, "# written by libtthimage v %s\n# bitplane module '%s'\n",
IMAGE_VERSION_STRING, VERSION_STRING); IMAGE_VERSION_STRING, VERSION_STRING);
chariot = 0; chariot = 0;

View File

View File

@ -9,7 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* pour les performances, cette fonction /* pour les performances, cette fonction

View File

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int

View File

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
#ifndef min #ifndef min
#define min(a,b) ((a)<(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b))

View File

@ -8,7 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -8,7 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* nouveau 28 fevrier 2014 / ave StExupery */ /* nouveau 28 fevrier 2014 / ave StExupery */

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* ya pas un probleme d'offset dans ces tables ? XXX */ /* ya pas un probleme d'offset dans ces tables ? XXX */

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int

154
Lib/doublesz.c Normal file
View File

@ -0,0 +1,154 @@
/*
doublesz.c
----------------
see also: scale.c halfsize.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* cette fonction alloue une _nouvelle_ image
*
* méthodes:
* 0: primitive.
* 1: semblant d'interpolation.
*
*/
Image_Desc *
Image_MakeDoubleSize(Image_Desc *image, int methode)
{
int largeur, hauteur, x, y, xx, yy;
Image_Desc *sortie;
int v1, v2, v3, v4;
largeur = image->width * 2;
hauteur = image->height * 2;
sortie = Image_alloc(largeur, hauteur, image->type);
#if DEBUG_LEVEL
fprintf(stderr, "Image double size: %d %d -> %p\n", largeur, hauteur, sortie);
#endif
if ( sortie == NULL )
{
fprintf(stderr, "Image make double size: no memory\n");
exit(5);
}
/*
* transfert de certains attributs...
*/
sortie->modified = 0;
sortie->errmsg = image->errmsg; /* XXX pointeur fou ? */
if (methode == 0)
{
for (x=0; x<image->width; x++)
{
xx = x * 2;
for (y=0; y<image->height; y++)
{
yy = y * 2;
Image_pixel_copy(image, x, y, sortie, xx, yy);
Image_pixel_copy(image, x, y, sortie, xx+1, yy);
Image_pixel_copy(image, x, y, sortie, xx, yy+1);
Image_pixel_copy(image, x, y, sortie, xx+1, yy+1);
}
}
}
else
{
for (x=0; x<image->width-1; x++)
{
xx = x * 2;
for (y=0; y<image->height-1; y++)
{
yy = y * 2;
v1 = (image->Rpix[y])[x];
v2 = (image->Rpix[y])[x+1];
v3 = (image->Rpix[y+1])[x];
v4 = (image->Rpix[y+1])[x+1];
(sortie->Rpix[yy])[xx] = v1;
(sortie->Rpix[yy])[xx+1] = (v1+v2)/2;
(sortie->Rpix[yy+1])[xx] = (v1+v3)/2;
(sortie->Rpix[yy+1])[xx+1] = (v1+v2+v3+v4)/4;
v1 = (image->Gpix[y])[x];
v2 = (image->Gpix[y])[x+1];
v3 = (image->Gpix[y+1])[x];
v4 = (image->Gpix[y+1])[x+1];
(sortie->Gpix[yy])[xx] = v1;
(sortie->Gpix[yy])[xx+1] = (v1+v2)/2;
(sortie->Gpix[yy+1])[xx] = (v1+v3)/2;
(sortie->Gpix[yy+1])[xx+1] = (v1+v2+v3+v4)/4;
v1 = (image->Bpix[y])[x];
v2 = (image->Bpix[y])[x+1];
v3 = (image->Bpix[y+1])[x];
v4 = (image->Bpix[y+1])[x+1];
(sortie->Bpix[yy])[xx] = v1;
(sortie->Bpix[yy])[xx+1] = (v1+v2)/2;
(sortie->Bpix[yy+1])[xx] = (v1+v3)/2;
(sortie->Bpix[yy+1])[xx+1] = (v1+v2+v3+v4)/4;
}
} /* finbo x */
} /* endif */
sortie->modified = 0;
return sortie;
}
/*::------------------------------------------------------------------::*/
Image_Desc *
Image_MakeDoubleSize_H(Image_Desc *image, int methode)
{
Image_Desc *sortie;
int largeur, x, y, r, g, b;
int r2, g2, b2;
#if DEBUG_LEVEL
fprintf(stderr, "*** %s is experimental. method: %d\n", __func__, methode);
#endif
largeur = image->width * 2;
fprintf(stderr, "%s ---> %d x %d\n", __func__, largeur, image->height);
sortie = Image_alloc(largeur, image->height, image->type);
if ( sortie == NULL )
{
fprintf(stderr, "Image make double size H: no memory\n");
exit(5);
}
#if DEBUG_LEVEL
Image_dump_descriptor(sortie, "double largeur");
#endif
switch (methode)
{
case 0:
for (x=0; x<image->width; x++)
{
for (y=0; y<image->height; y++)
{
Image_getRGB(image, x, y, &r, &g, &b);
Image_plotRGB(sortie, x, y, r, g, b);
Image_plotRGB(sortie, x+1, y, r, g, b);
}
}
break;
case 1:
break;
}
sortie->modified = 1;
return sortie;
}
/*::------------------------------------------------------------------::*/

240
Lib/drawing.c Normal file
View File

@ -0,0 +1,240 @@
/*
primitives graphiques premier module (back in 1999)
---------------------------------------------------
*/
#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
/*::------------------------------------------------------------------::*/
static int
iSign(int a)
{
if (a<0) return -1;
if (a>0) return 1;
return 0;
}
/*::------------------------------------------------------------------::*/
static void symmetry(int x, int y, int xc, int yc, RGBA *g, Image_Desc *i)
{
int x_start, x_end;
int y_start, y_end;
x_start = x; y_start = y;
x_end = x + 1; y_end = y + 1;
Image_plotRGB(i, x+xc, y+yc, 100, 100, 100);
fprintf(stderr, "sym %d %d\n", x, y);
}
/* le paramètre 'wrap' ne sert à rien */
int
Image_draw_circle(Image_Desc *i, int xc, int yc, int rayon, RGBA *q, int wrap)
{
int x, y, d;
#if DEBUG_LEVEL
fprintf(stderr, "%s : centre %d %d, rayon %d\n", __func__, xc, yc, rayon);
#endif
y = rayon;
d = 3 - 2 * rayon;
for ( x=0; x<y; )
{
symmetry(x, y, xc, yc, q, i);
if (d<0)
{
d += 4 * x + 6;
}
else
{
d += 4 * (y - x) * 10;
--y;
}
++x;
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* l'appel a la fonction isign devrait disparaitre pour optimiser
* la vitesse du bouzin.
*/
int
Image_draw_line(Image_Desc *i, int x1, int y1, int x2, int y2, RGBA *q)
{
int dx, dy, ix, iy, inc;
int foo, plotx, ploty, x, y;
int plot;
#if DEBUG_LEVEL > 1
printf("%s %4d %4d -----> %4d %4d\n", __func__, x1, y1, x2, y2);
#endif
dx = x2 - x1; dy = y2 - y1;
ix = abs(dx); iy = abs(dy);
inc = ix<iy ? iy : ix;
#if DEBUG_LEVEL > 1
printf("d %4d %4d i %4d %4d ^ %4d\n", dx, dy, ix, iy, inc);
#endif
plotx = x1;
ploty = y1;
x = y = 0;
for (foo=0; foo<=inc; ++foo)
{
x += ix;
y += iy;
plot = 0;
if (x > inc)
{
plot = 42;
x -= inc;
plotx += iSign(dx);
}
if (y > inc)
{
plot = 42;
y -= inc;
ploty += iSign(dy);
}
if (plot)
{
/* printf("%5d %5d %5d\n", foo, plotx, ploty ); */
Image_plotRGB(i, plotx, ploty, q->r, q->g, q->b);
}
}
return 0;
}
/*::------------------------------------------------------------------::*/
/*
* XXX si je veux remplacer 'plotRGB' par un accès direct
* XXX dans les buffers, il faut soigner les controles
*/
int
Image_paint_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b)
{
int xd, yd, xf, yf, x, y;
#if DEBUG_LEVEL > 2
fprintf(stderr, "Paint Rect : image %d x %d\n", img->width, img->height);
Image_dump_rect(rect, "in 'paint a rect'", 0);
#endif
xd = max(0, rect->x);
yd = max(0, rect->y);
xf = min((img->width), (rect->x+rect->w));
yf = min((img->height), (rect->y+rect->h));
/*
* 24 Juin 2002: est-ce que le code ci-dessus a é sérieusement validé ?
* 24 Avril 2008: NON !
* 26 janvier 2014 : toujours non...
*/
#if DEBUG_LEVEL > 2
fprintf(stderr, "Paint Rect: %4d < X < %4d %4d < Y < %4d\n",
xd, xf, yd, yf);
#endif
for (x=xd; x<xf; x++)
{
for (y=yd; y<yf; y++)
{
/* Image_plotRGB(img, x, y, r, g, b); */
(img->Rpix[y])[x] = r;
(img->Gpix[y])[x] = g;
(img->Bpix[y])[x] = b;
}
}
return 0;
}
/*::------------------------------------------------------------------::*/
/*
* 27 Juin 2001: there was an off-by-one error in this func...
* See also 'drawpatt.c' for others things.
*/
int
Image_draw_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b)
{
int foo;
int xd, yd, xf, yf;
xd = max(0, rect->x);
yd = max(0, rect->y);
xf = min((img->width-1), ((rect->x+rect->w)));
yf = min((img->height-1), ((rect->y+rect->h)));
#if DEBUG_LEVEL > 1
Image_dump_rect(rect, "draw a rect", 0);
fprintf(stderr, "Draw a Rect: xd:%4d yd:%4d xf:%4d yf:%4d\n",
xd, yd, xf, yf);
#endif
for (foo=xd; foo<xf; foo++)
{
/* if ( (rect->y >= 0) && (rect->y < img->height) ) */
Image_plotRGB(img, foo, rect->y, r, g, b);
/* if ( (rect->y+rect->h >= 0) && (rect->y+rect->h < img->height) ) */
Image_plotRGB(img, foo, rect->y+rect->h-1, r, g, b);
}
for (foo=yd; foo<yf; foo++)
{
/* if ( (rect->x >= 0) && (rect->x < img->width) ) */
Image_plotRGB(img, rect->x, foo, r, g, b);
/* if ( (rect->x+rect->w >= 0) && (rect->x+rect->w < img->width) ) */
Image_plotRGB(img, rect->x+rect->w-1, foo, r, g, b);
}
return 0;
}
/*::------------------------------------------------------------------::*/
/* new 10 octobre 2008 - zone de Monredon (Betatech) */
int
Image_noise_rect(Image_Desc *img, Image_Rect *rect, int r, int g, int b)
{
int xd, yd, xf, yf, x, y;
fprintf(stderr, "%s: i=%p r=%p %d %d %d\n", __func__, img, rect, r, g, b);
xd = max(0, rect->x);
yd = max(0, rect->y);
xf = min((img->width-1), (rect->x+rect->w));
yf = min((img->height-1), (rect->y+rect->h));
#if DEBUG_LEVEL
fprintf(stderr, "%s: %d %d %d %d\n", __func__, xd, yd, xf, yf);
#endif
for (x=xd; x<xf; x++)
{
for (y=yd; y<yf; y++)
{
(img->Rpix[y])[x] = rand() % r;
(img->Gpix[y])[x] = rand() % g;
(img->Bpix[y])[x] = rand() % b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* kikoo lol a tous les goret-codeurs, et en particulier Mr Spleyt.
*/

View File

@ -15,7 +15,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -12,7 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -13,7 +13,7 @@
#include <string.h> #include <string.h>
#include <math.h> /* yo ! */ #include <math.h> /* yo ! */
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
@ -33,7 +33,7 @@ if ( (fp=fopen(nom, "w")) == NULL )
} }
fputs("%!PS-Adobe-2.0 EPSF-1.2\n%%\n", fp); fputs("%!PS-Adobe-2.0 EPSF-1.2\n%%\n", fp);
fprintf(fp, "%%%% Generator: libimage v %s\n", IMAGE_VERSION_STRING); fprintf(fp, "%%%% Generator: libtthimage v %s\n", IMAGE_VERSION_STRING);
time(&temps); time(&temps);
fprintf(fp, "%%%% Date: %s\n", ctime(&temps)); fprintf(fp, "%%%% Date: %s\n", ctime(&temps));
fclose(fp); fclose(fp);

View File

@ -14,7 +14,7 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include "tthimage.h" #include "../tthimage.h"
#include "essais.h" #include "essais.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/

View File

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
void void

View File

@ -3,10 +3,12 @@
#include <unistd.h> #include <unistd.h>
#include <stdint.h> #include <stdint.h>
#include "tthimage.h" #include "../tthimage.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Image_print_version(2); Image_print_version(2);
Image_print_sizeof_structs("foo");
return 0; return 0;
} }

105
Lib/halfsize.c Normal file
View File

@ -0,0 +1,105 @@
/*
halfsize.c
------------------
see also: scale.c doublesz.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* Fabrication d'une image moitié de l'image source.
*
* cette fonction alloue une _nouvelle_ image
* ==========
* méthodes:
* 0: primitive.
* 1: semblant d'interpolation.
*
*/
Image_Desc *
Image_MakeHalfSize(Image_Desc *image, int methode)
{
int largeur, hauteur, x, y, xx, yy;
Image_Desc *demi;
largeur = image->width / 2; hauteur = image->height / 2;
if (image->type != IMAGE_RGB)
{
fprintf(stderr, "Image HalfSize: bad image type %d\n", image->type);
return NULL;
}
#if DEBUG_LEVEL
fprintf(stderr, "MakeHalfSize: from %dx%d, method %d -> %d x %d\n",
image->width, image->height, methode, largeur, hauteur);
#endif
demi = Image_alloc(largeur, hauteur, image->type);
if ( demi == NULL )
{
fprintf(stderr, "Image make half size: no memory\n");
exit(5);
}
/*
* ne faudrait-il pas transmettre certains des attributs de
* l'image originale à la nouvelle image ?
*/
demi->modified = 0;
demi->errmsg = image->errmsg;
for (y=0; y<hauteur; y++)
{
yy = y * 2;
for (x=0; x<largeur; x++)
{
xx = x * 2;
switch(methode)
{
case 0:
(demi->Rpix[y])[x] = (image->Rpix[yy])[xx];
(demi->Gpix[y])[x] = (image->Gpix[yy])[xx];
(demi->Bpix[y])[x] = (image->Bpix[yy])[xx];
break;
case 1:
(demi->Rpix[y])[x] = ( (image->Rpix[yy])[xx] +
(image->Rpix[yy+1])[xx] +
(image->Rpix[yy])[xx+1] +
(image->Rpix[yy+1])[xx+1] ) / 4;
(demi->Gpix[y])[x] = ( (image->Gpix[yy])[xx] +
(image->Gpix[yy+1])[xx] +
(image->Gpix[yy])[xx+1] +
(image->Gpix[yy+1])[xx+1] ) / 4;
(demi->Bpix[y])[x] = ( (image->Bpix[yy])[xx] +
(image->Bpix[yy+1])[xx] +
(image->Bpix[yy])[xx+1] +
(image->Bpix[yy+1])[xx+1] ) / 4;
break;
default:
/*
* et ici, un message d'erreur ?
*/
break;
}
}
}
demi->modified = 1;
return demi; /* demi is a pointer to an Image_Desc ! */
}
/*::------------------------------------------------------------------::*/

View File

@ -1,6 +1,6 @@
/* /*
fonctions de bases pour la librairie 'libimage' fonctions de bases pour la librairie 'libtthimage'
----------------------------------------------- --------------------------------------------------
(g) 1992,2003 - Thierry Boudet - aka Oulala (g) 1992,2003 - Thierry Boudet - aka Oulala
@ -10,7 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
void void
@ -19,7 +19,7 @@ Image_print_version(int flag)
char *ptr; char *ptr;
fflush(stdout); fflush(stdout);
printf("-+- This is the `image' library v%s (dwtfywl 2022) tTh\n", printf("-+- This is the `tthimage' library v%s (dwtfywl 2022) tTh\n",
IMAGE_VERSION_STRING); IMAGE_VERSION_STRING);
if (flag) if (flag)
{ {
@ -38,15 +38,15 @@ fflush(stdout);
/* OMFG, this is a gnuism ! */ /* OMFG, this is a gnuism ! */
if ( (ptr=getenv("MALLOC_CHECK_")) != NULL) if ( (ptr=getenv("MALLOC_CHECK_")) != NULL)
{ {
fprintf(stderr, "-+- libimage: malloc check is set to %s\n", ptr); fprintf(stderr, "-+- libtthimage: malloc check is set to %s\n", ptr);
} }
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, fprintf(stderr,
"Warning! this version of libimage is compiled with DEBUG_LEVEL=%d\n", "Warning! this version of libtthimage is compiled with DEBUG_LEVEL=%d\n",
DEBUG_LEVEL); DEBUG_LEVEL);
#if FORCE_ABORT #if FORCE_ABORT
fprintf(stderr, "Warning! this version of libimage is compiled with FORCE_ABORT!\n"); fprintf(stderr, "Warning! this version of libtthimage is compiled with FORCE_ABORT!\n");
#endif #endif
#endif #endif
} }
@ -183,7 +183,7 @@ switch (type)
if (getenv("MALLOC_CHECK_") != NULL) if (getenv("MALLOC_CHECK_") != NULL)
{ {
fprintf(stderr, "-+- libimage %s %d: alloc %p\n", fprintf(stderr, "-+- libtthimage %s %d: alloc %p\n",
__FILE__, __LINE__, header); __FILE__, __LINE__, header);
} }
@ -576,7 +576,7 @@ Image_DeAllocate(Image_Desc *im)
int line; int line;
if (getenv("MALLOC_CHECK_") != NULL) { if (getenv("MALLOC_CHECK_") != NULL) {
fprintf(stderr, "-+- libimage %s %d: free %p\n", fprintf(stderr, "-+- libtthimage %s %d: free %p\n",
__FILE__, __LINE__, im); __FILE__, __LINE__, im);
} }

View File

@ -4,7 +4,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int
@ -60,7 +60,7 @@ printf("\n");
printf("basic types : short=%d int=%d long=%d ptr=%d\n", printf("basic types : short=%d int=%d long=%d ptr=%d\n",
sizeof(short), sizeof(int), sizeof(long), sizeof(void *)); sizeof(short), sizeof(int), sizeof(long), sizeof(void *));
/* examen des tructures de la libimage */ /* examen des tructures de la libtthimage */
printf("Image_Desc : %5u\n", sizeof(Image_Desc)); printf("Image_Desc : %5u\n", sizeof(Image_Desc));
printf("Image_Rect : %5u\n", sizeof(Image_Rect)); printf("Image_Rect : %5u\n", sizeof(Image_Rect));
printf("RGBA : %5u\n", sizeof(RGBA)); printf("RGBA : %5u\n", sizeof(RGBA));

View File

@ -12,7 +12,7 @@
#include <alloca.h> #include <alloca.h>
#endif #endif
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int Image_lut15_fill_0(int r[32768], int *g, int *b) int Image_lut15_fill_0(int r[32768], int *g, int *b)

View File

@ -9,7 +9,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int
@ -52,7 +52,7 @@ if (txt != NULL)
Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte", Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte",
&fond, &encre); &fond, &encre);
Image_trace_chaine_1(dst, "Libimage de tTh", 270, 370, "libimage.fonte", Image_trace_chaine_1(dst, "Libtthimage de tTh", 270, 370, "libimage.fonte",
&fond, &encre); &fond, &encre);
Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 385, NULL, &fond, &encre); Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 385, NULL, &fond, &encre);
Image_trace_chaine_1(dst, __DATE__, 270, 400, NULL, &fond, &encre); Image_trace_chaine_1(dst, __DATE__, 270, 400, NULL, &fond, &encre);
@ -94,7 +94,7 @@ encre.r = 255; encre.g = 255; encre.b = 255; encre.a = 255;
/* ya pas moyen de mettre ces textes dans des jolies boites ? */ /* ya pas moyen de mettre ces textes dans des jolies boites ? */
Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte", &fond, &encre); Image_trace_chaine_1(dst, txt, 270, 270, "libimage.fonte", &fond, &encre);
Image_trace_chaine_1(dst, "Libimage de tTh", 270, 370, NULL, &fond, &encre); Image_trace_chaine_1(dst, "Libtthimage de tTh", 270, 370, NULL, &fond, &encre);
Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 390, NULL, &fond, &encre); Image_trace_chaine_1(dst, IMAGE_VERSION_STRING, 270, 390, NULL, &fond, &encre);
return FUNC_IS_ALPHA; return FUNC_IS_ALPHA;

View File

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* for abort() */ #include <stdlib.h> /* for abort() */
#include <time.h> #include <time.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
char * char *

View File

@ -16,7 +16,7 @@
#include <alloca.h> #include <alloca.h>
#endif #endif
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
@ -68,7 +68,7 @@ if ( (path=getenv(ENV_LIBIMAGE_PATH)) != NULL)
/* /*
Ahem, trying with the hardcoded path to shared file Ahem, trying with the hardcoded path to shared file
of libimage. Hop this help. of libtthimage. Hop this help.
*/ */
path = SHAREDIR "/"; /* don't forget the trailing '/' */ path = SHAREDIR "/"; /* don't forget the trailing '/' */
@ -166,7 +166,7 @@ else
/* /*
* Ahem, trying with the hardcoded path to shared file * Ahem, trying with the hardcoded path to shared file
* of libimage. Hope this help. * of libtthimage. Hope this help.
*/ */
path = SHAREDIR "/"; /* don't forget the trailing '/' */ path = SHAREDIR "/"; /* don't forget the trailing '/' */

View File

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* pour abs() */ #include <stdlib.h> /* pour abs() */
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

View File

@ -20,7 +20,7 @@
#include <alloca.h> #include <alloca.h>
#endif #endif
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*

175
Lib/patterns.c Normal file
View File

@ -0,0 +1,175 @@
/*
patterns.c
------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int
Image_pattern_000(Image_Desc *img, int foo)
{
int x, y, xx, yy, r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "%s : foo = %d\n", __func__, foo);
#endif
for (x=0; x<img->width; x++)
{
xx = (x * 256) / img->width;
for (y=0; y<img->height; y++)
{
yy = (y * 256) / img->height;
r = xx & yy & foo;
g = ((xx * yy) & 0xf8 );
b = xx ^ yy;
Image_plotRGB(img, x, y, r, g, b);
}
}
/*
sometime, a newbie ask me: "why use intermediate vars: r, g, and b ?"
my answer was: "clarity of code, small scarabée".
*/
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_001(Image_Desc *img, int foo)
{
int x, y;
#if DEBUG_LEVEL
fprintf(stderr, "%s : foo is %d\n", __func__, foo);
#endif
for (x=0; x<img->width; x++)
for (y=0; y<img->height; y++)
Image_plotRGB(img, x, y, x^y^foo, (x*y)>>4, x&y);
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_002(Image_Desc *img, int foo)
{
int x, y, x2, y2;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 002: %d\n", foo);
#endif
for (x=0; x<img->width; x++)
{
x2 = (x * 256) / img->width;
for (y=0; y<img->height; y++)
{
y2 = (y * 256) / img->height;
Image_plotRGB(img, x, y, (x2/2)&(y2/2)&foo, (x2*y2)>>3, x2^y2);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_003(Image_Desc *img, int foo)
{
int x, x2, y, y2;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 003: foo is %d\n", foo);
#endif
/* added some ugly code the 28 february 2008 */
for (x=0; x<img->width; x++)
{
x2 = (x * 256) / img->width;
for (y=0; y<img->height; y++)
{
y2 = (y * 256) / img->height;
Image_plotRGB(img, x, y, (x2/4)&(y2/4)&foo, (x2*y2)>>5, x2^y2);
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_004(Image_Desc *img, int a, int b, int c, int d)
{
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 004: %d, %d, %d, %d\n", a, b, c, d);
#endif
fprintf(stderr, "NO CODE HERE\n");
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int Image_pattern_005(Image_Desc *img, RGB_map *map)
{
int x, y;
double fx, fy;
int idx;
if (NULL == map) {
fprintf(stderr, "in %s:%s, map is NULL\n",
__FILE__, __func__);
return NULL_POINTER;
}
for (y=0; y<img->height; y++)
{
fy = (double)y;
for (x=0; x<img->width; x++)
{
fx = (double)x;
idx = (int)(127.0+(sin(fx)*cos(fy)*254.99));
idx &= 0xff;
(img->Gpix[y])[x] = map->green[idx];
(img->Bpix[y])[x] = map->blue[idx];
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_042(Image_Desc *img, int foo)
{
int x, y, r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 042: threshold level is %d\n", foo);
#endif
r = g = b = 42;
for (x=0; x<img->width; x++)
{
for (y=0; y<img->height; y++)
{
r += rand() % 4;
if (r > foo) r = 0;
g += rand() % 4;
if (g > foo) g = 0;
b += rand() % 4;
if (b > foo) b = 0;
/* Image_plotRGB(img, x, y, r, g, b); */
(img->Rpix[y])[x] = r;
(img->Gpix[y])[x] = g;
(img->Bpix[y])[x] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/

121
Lib/patterns2.c Normal file
View File

@ -0,0 +1,121 @@
/*
patterns2.c
------------------
various random patterns.
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int
Image_texture_0(Image_Desc *dst, int bas, int haut)
{
int foo;
fprintf(stderr, "Texture 0: obsolete! use 'Image_gray_noise_0' now!\n");
foo = Image_gray_noise_0(dst, bas, haut);
return foo;
}
/*::------------------------------------------------------------------::*/
int
Image_texture_1(Image_Desc *dst, int bas, int haut)
{
int x, y, r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "Texture 1: %d %d\n", bas, haut);
#endif
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
r = rand()%(haut-bas) + bas;
g = rand()%(haut-bas) + bas;
b = rand()%(haut-bas) + bas;
(dst->Rpix[y])[y] = r;
(dst->Gpix[y])[y] = g;
(dst->Bpix[y])[y] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* en cours de mise au point ? à quoi servent les paramètres ?
* ou est la doc ? mais que fait tTh ? il moule dans une tribune ?
*/
int
Image_texture_2(Image_Desc *dst, int bas, int haut, int mod)
{
int x, y, r, g, b, foo;
#if DEBUG_LEVEL
fprintf(stderr, "Image texture 2: this func is experimental ;)\n");
#endif
if (mod == 0)
{
fprintf(stderr, "Image texture 2: 'mod' must be positive.\n");
return DIVISOR_IS_ZERO;
}
r = g = b = 127;
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
foo = rand() % mod;
switch(foo)
{
case 0: r = rand()%(haut-bas) + bas; break;
case 1: g = rand()%(haut-bas) + bas; break;
case 2: b = rand()%(haut-bas) + bas; break;
case 3: r = b = g = haut; break;
case 4: r = b = g = bas; break;
case 5: r = 0; break;
case 6: g = 0; break;
case 7: b = 0; break;
/*
* à partir de , il y a beaucoup de 'case'
* qui se ressemblent trop...
*/
case 8: r = (x * rand()) & 0xff; break;
case 9: g = (x * rand()) & 0xff; break;
case 10: b = (x * rand()) & 0xff; break;
case 11: r = (y * rand()) & 0xff; break;
case 12: g = (y * rand()) & 0xff; break;
case 13: b = (y * rand()) & 0xff; break;
}
(dst->Rpix[y])[x] = r;
(dst->Gpix[y])[x] = g;
(dst->Bpix[y])[x] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* bon sang, j'ai le prototype sous les yeux, mais je n'ai pas
* la moindre idée de ce que doit faire la fonction !
*/
int
Image_texture_3(Image_Desc *dst, int bas, int haut, char *ctl, int quux)
{
int x, y;
fprintf(stderr, "Texture 3 is not here\n");
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/

142
Lib/patterns3.c Normal file
View File

@ -0,0 +1,142 @@
/*
patterns3.c
------------------
see also 'patterns.c' & 'patterns2.c'
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* c'est quasiment impossible de documenter cette fonction.
*/
int
Image_pattern_100(Image_Desc *dst, int kr, int kg, int kb)
{
int x, y, r,g, b;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = abs(x+y-(dst->width/3)) * kr;
g = abs(x-y-(dst->height/3)) * kg;
b = (rand() % 42) + kb;
Image_plotRGB(dst, x, y, r, g, b);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_101(Image_Desc *dst, int kr, int kg, int kb)
{
int x, y, r,g, b;
if (kr == 0) kr = 1;
if (kg == 0) kg = 1;
if (kb == 0) kb = 1;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
if (x < dst->width/2)
{ r=x/kr; g=y/kg; b=x/kb; }
else
{ r=y/kr; g=x/kg; b=y/kb; }
Image_plotRGB(dst, x, y, r, g, b);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int
Image_pattern_102(Image_Desc *dst, int param, int kr, int kg, int kb)
{
int x, y, r,g, b;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = x ^ kr;
g = y ^ kg;
b = (x+y) ^ kb;
Image_plotRGB(dst, x, y, r, g, b);
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/* hop, 31 mars 2008, une petite evolution stochastique de base...
* */
int
Image_pattern_103(Image_Desc *dst, int param, int kr, int kg, int kb)
{
int x, y, r, g, b;
long surface;
double dx, dy;
#if DEBUG_LEVEL
fprintf(stderr, "%s: acting on image %p\n", __func__, dst);
#endif
surface = dst->width * dst->height;
for (x=0; x<dst->width; x++)
{
dx = (double)x / (double)dst->width;
for (y=0; y<dst->height; y++)
{
dy = (double)x / (double)dst->height;
r = (int)round(256.0 * sqrt(dx * dy));
g = b = rand() & 0xf0;
Image_plotRGB(dst, x, y, r, g, b);
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* new 10 juillet 2003
*/
int
Image_pattern_104(Image_Desc *dst, int sx, int sy, RGBA *a, RGBA *b)
{
int x, y, fx, fy;
for (x=0; x<dst->width; x++)
{
fx = x % sx;
for (y=0; y<dst->height; y++)
{
fy = y % sy;
if (fx==1 && fy==1)
{
Image_plotRGB(dst, x, y, a->r, a->g, a->b);
}
else
{
Image_plotRGB(dst, x, y, b->r, b->g, b->b);
}
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "%05d\r", x);
#endif
}
return FUNC_IS_ALPHA;
}
/*::------------------------------------------------------------------::*/

233
Lib/patterns4.c Normal file
View File

@ -0,0 +1,233 @@
/*
patterns4.c
------------------
some random noises
see also 'patterns.c' & 'patterns2.c'
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* bruit monochrome
*/
int
Image_gray_noise_0(Image_Desc *dst, int low, int high)
{
int x, y, v, delta;
delta = high - low;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
v = (rand() % delta) + low;
(dst->Rpix[y])[x] = v;
(dst->Gpix[y])[x] = v;
(dst->Bpix[y])[x] = v;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
int
Image_rgb_noise_0(Image_Desc *dst, int low, int high)
{
int x, y, r, g, b, delta;
delta = high - low;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = (rand() % delta) + low;
g = (rand() % delta) + low;
b = (rand() % delta) + low;
(dst->Rpix[y])[x] = r;
(dst->Gpix[y])[x] = g;
(dst->Bpix[y])[x] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
int
Image_rgba_noise_0(Image_Desc *dst, int low, int high)
{
int x, y, r, g, b, a, delta;
if (dst->type != IMAGE_RGBA)
{
fprintf(stderr, "RGBA noise 0: image is not RGBA (%d)\n", dst->type);
return IMAGE_BAD_TYPE;
}
if (dst->Apix == NULL)
{
fprintf(stderr, "RGBA noise 0: %p: no alpha buffer ?\n", dst);
return NO_ALPHA_CHANNEL;
}
delta = high - low;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = (rand() % delta) + low;
g = (rand() % delta) + low;
b = (rand() % delta) + low;
a = (rand() % delta) + low;
Image_plotRGBA(dst, x, y, r, g, b, a);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* new 21 mars 2002 - need more doc
*/
int
Image_rgb_noise_1(Image_Desc *dst, RGBA *low, RGBA *high)
{
int minr, ming, minb;
int maxr, maxg, maxb;
int dltr, dltg, dltb;
int x, y, r, g, b;
#if DEBUG_LEVEL
Image_print_rgba("rgb noise 1: low", low, 0);
Image_print_rgba("rgb noise 1: high", high, 0);
#endif
minr = (low->r < high->r) ? low->r : high->r;
ming = (low->g < high->g) ? low->g : high->g;
minb = (low->b < high->b) ? low->b : high->b;
maxr = (low->r > high->r) ? low->r : high->r;
maxg = (low->g > high->g) ? low->g : high->g;
maxb = (low->b > high->b) ? low->b : high->b;
dltr = maxr - minr;
dltg = maxg - ming;
dltb = maxb - minb;
#if DEBUG_LEVEL
printf("\n");
printf("rgb noise 1: min %3d %3d %3d\n", minr, ming, minb);
printf("rgb noise 1: max %3d %3d %3d\n", maxr, maxg, maxb);
printf("rgb noise 1: delta %3d %3d %3d\n", dltr, dltg, dltb);
#endif
if ( dltr==0 || dltg==0 || dltb==0 )
{
fprintf(stderr, "Rgb noise 1: a delta is zero...\n");
return DIVISOR_IS_ZERO;
}
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = (rand() % dltr) + minr;
g = (rand() % dltg) + ming;
b = (rand() % dltb) + minb;
(dst->Rpix[y])[x] = r;
(dst->Gpix[y])[x] = g;
(dst->Bpix[y])[x] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* pour avoir une courbe de répartition en cloche, j'utilise
* l'algo du "lancement de deux dés", mais ce n'est probablement
* pas très rigoureux :)
*/
int
Image_gray_noise_2(Image_Desc *dst, int low, int high)
{
int x, y, v, delta;
delta = (high - low) / 2;
#if DEBUG_LEVEL
fprintf(stderr, "Gray noise 2: low=%d high=%d delta=%d\n", low, high, delta);
#endif
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
v = (rand()%delta) + (rand()%delta) + low;
(dst->Rpix[y])[x] = v;
(dst->Gpix[y])[x] = v;
(dst->Bpix[y])[x] = v;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* hop, clonage du commentaire de la func du dessus :)
*
* pour avoir une courbe de répartition en cloche, j'utilise
* l'algo du "lancement de deux dés", mais ce n'est probablement
* pas très rigoureux :)
*/
int
Image_rgb_noise_2(Image_Desc *dst, RGBA *low, RGBA *high)
{
int x, y, r, g, b;
int minr, ming, minb;
int maxr, maxg, maxb;
int dltr, dltg, dltb;
#if DEBUG_LEVEL
Image_print_rgba("rgb noise 2: low", low, 0);
Image_print_rgba("rgb noise 2: high", high, 0);
#endif
minr = (low->r < high->r) ? low->r : high->r;
ming = (low->g < high->g) ? low->g : high->g;
minb = (low->b < high->b) ? low->b : high->b;
maxr = (low->r > high->r) ? low->r : high->r;
maxg = (low->g > high->g) ? low->g : high->g;
maxb = (low->b > high->b) ? low->b : high->b;
dltr = maxr - minr;
dltg = maxg - ming;
dltb = maxb - minb;
#if DEBUG_LEVEL
printf("\n");
printf("rgb noise 2: min %3d %3d %3d\n", minr, ming, minb);
printf("rgb noise 2: max %3d %3d %3d\n", maxr, maxg, maxb);
printf("rgb noise 2: delta %3d %3d %3d\n", dltr, dltg, dltb);
#endif
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
r = (rand()%dltr) + (rand()%dltr) + minr;
g = (rand()%dltg) + (rand()%dltg) + ming;
b = (rand()%dltb) + (rand()%dltb) + minb;
(dst->Rpix[y])[x] = r;
(dst->Gpix[y])[x] = g;
(dst->Bpix[y])[x] = b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/

View File

View File

@ -27,13 +27,13 @@
------------------------------------------ ------------------------------------------
NEW: 12 Sept 2001. NEW: 12 Sept 2001.
je commence à modifier pour que ce soit indépendant du je commence a modifier pour que ce soit independant du
boutisme, et les premiers essais seront fait sur Sparc. boutisme, et les premiers essais seront fait sur Sparc.
*/ */
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int int

84
Lib/pixeliz.c Normal file
View File

@ -0,0 +1,84 @@
/*
* pixeliz.c
* ---------
*
* nouveau 23 Juin 2003, je ne sais pas quoi mettre dedans...
* 14 mars 2007: je ne sais toujours pas...
*
*/
#include <stdio.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int
Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
{
int x, y, foo, N;
int r, g, b;
int xmax, ymax;
Image_Rect zone;
#if DEBUG_LEVEL
fprintf(stderr, "Pixeliz 0: en chantier w %d h %d\n", w, h);
#endif
if ( (foo=Image_compare_desc(src, dst)) ) {
fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo;
}
zone.w = w;
zone.h = h;
xmax = src->width - w;
ymax = src->height - h;
for (x=0; x<=xmax; x+=w) {
zone.x = x;
for (y=0; y<=ymax; y+=h) {
zone.y = y;
/* Image_dump_rect(&zone, "z", 0); */
foo = Image_stats_zone_0(src, &zone, &r, &g, &b, &N, &N, &N);
foo = Image_paint_rect(dst, &zone, r, g, b);
}
}
dst->modified = 1;
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* fonction d'appel de test
*/
int
Image_pixeliz_X(Image_Desc *src, Image_Desc *dst)
{
int foo;
fprintf(stderr, "Pixeliz X: appel de test, pas finalise.\n");
foo = Image_pixeliz_0(src, dst, 5, 13);
fprintf(stderr, "Pixeliz X: valeur obtenue: %d\n", foo);
return foo;
}
/*::------------------------------------------------------------------::*/
/*
* fonction d'appel de test
*/
int
Image_pixeliz_Y(Image_Desc *src, Image_Desc *dst)
{
int foo;
fprintf(stderr, "Pixeliz Y: appel de test, pas finalise.\n");
foo = Image_pixeliz_0(src, dst, 13, 5);
fprintf(stderr, "Pixeliz Y: valeur obtenue: %d\n", foo);
return foo;
}
/*::------------------------------------------------------------------::*/

38
Lib/pixels.c Normal file
View File

@ -0,0 +1,38 @@
/*
* PIXELS dot C
*/
#include <stdio.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int
Image_XOR_pixel(Image_Desc *img, int x, int y, int r, int g, int b)
{
int pr, pg, pb, a;
if ( (x<0) || (y<0) || (x>=img->width) || (y>=img->height) )
{
fprintf(stderr, "%s : out of pic (%d, %d)\n", __func__, x, y);
return OUT_OF_IMAGE;
}
img->Rpix[y][x] ^= r;
img->Gpix[y][x] ^= g;
img->Bpix[y][x] ^= b;
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
int Image_rot_pixel(Image_Desc *img, int x, int y, int r, int g, int b)
{
if ( (x<0) || (y<0) || (x>=img->width) || (y>=img->height) )
{
fprintf(stderr, "%s : out of pic (%d, %d)\n", __func__, x, y);
return OUT_OF_IMAGE;
}
return 42;
}
/*::------------------------------------------------------------------::*/

552
Lib/plotteur.c Normal file
View File

@ -0,0 +1,552 @@
/*
plotteur.c
----------
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef NEED_ALLOCA_H
#include <alloca.h>
#endif
#include "../tthimage.h"
#define SOMBRE 26 /* pourquoi ces valeurs sont codées en */
#define CLAIR 242 /* dur ? et ~/.tth/libimagerc alors ? */
/*::------------------------------------------------------------------::*/
static void vline(Image_Desc *i, int x, int y1, int y2, char c, int v)
{
int haut, bas, foo;
if (y1 > y2) { bas = y2; haut = y1; }
else { bas = y1; haut = y2; }
for (foo=bas; foo<=haut; foo++)
Image_plot_channel(i, c, x, foo, v);
}
/*::------------------------------------------------------------------::*/
/* new 20 mars 2002
*/
int
Image_plot_luts(char *nomtga, int *lr, int *lg, int *lb, char *texte)
{
Image_Desc *img;
int foo;
RGBA paper, ink;
int vr, vg, vb, ovr, ovg, ovb;
if ( (img = Image_alloc(400, 300, 3)) == NULL )
{
#if DEBUG_LEVEL
fprintf(stderr, "Plot Luts: alloc of img failed, file=%s\n", nomtga);
#endif
return IMAGE_NO_MEM;
}
Image_clear(img, SOMBRE, SOMBRE, SOMBRE);
ovr = ovg = ovb = 0; /* warning suppressor */
for (foo=0; foo<256; foo++)
{
vr = lr[foo];
vg = lg[foo];
vb = lb[foo];
if (foo)
{
vline(img, foo+60, 290-vr, 290-ovr, 'r', CLAIR);
vline(img, foo+60, 290-vg, 290-ovg, 'g', CLAIR);
vline(img, foo+60, 290-vb, 290-ovb, 'b', CLAIR);
}
ovr = vr; ovg = vg; ovb = vb;
}
if (texte != NULL)
{
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
Image_trace_chaine_1(img, texte, 5, 5, "libimage.fonte", &paper, &ink);
}
Image_cadre_A(img);
foo=Image_TGA_save(nomtga, img, 0);
Image_DeAllocate(img); free(img);
return foo;
}
/*::------------------------------------------------------------------::*/
/*
* fevrier 2009 : je constate avec amertume que cette fonction ne
* remplit plus vraiment son role face aux exigences
* de buzzwording du monde moderne. un revamping me
* semble vraiment necessaire.
*/
int
Image_plot_histo(char *nomtga, long *hr, long *hg, long *hb, char *txt)
{
Image_Desc *img;
int foo, vr, vg, vb, ovr, ovg, ovb;
long maxhisto;
RGBA paper, ink;
char chaine[120];
if ( (img = Image_alloc(400, 300, 3)) == NULL )
{
#if DEBUG_LEVEL
fprintf(stderr, "Plot Histo: alloc of img failed, file=%s\n", nomtga);
#endif
return IMAGE_NO_MEM;
}
maxhisto = 0;
for (foo=0; foo<256; foo++)
{
if (hr[foo] > maxhisto) maxhisto = hr[foo];
if (hg[foo] > maxhisto) maxhisto = hg[foo];
if (hb[foo] > maxhisto) maxhisto = hb[foo];
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "plot histo: max rgb = %ld\n", maxhisto);
#endif
Image_clear(img, SOMBRE, SOMBRE, SOMBRE); /* ou est SOMBRE ? */
ovr = ovg = ovb = 0; /* warning suppressor */
for (foo=0; foo<256; foo++)
{
vr = (hr[foo]*256)/maxhisto;
vg = (hg[foo]*256)/maxhisto;
vb = (hb[foo]*256)/maxhisto;
if (foo)
{
vline(img, foo+60, 290-vr, 290-ovr, 'r', CLAIR);
vline(img, foo+60, 290-vg, 290-ovg, 'g', CLAIR);
vline(img, foo+60, 290-vb, 290-ovb, 'b', CLAIR);
}
ovr = vr; ovg = vg; ovb = vb;
}
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
#if DEBUG_LEVEL > 1
fprintf(stderr, "taille txt %d\n", strlen(txt));
#endif
Image_trace_chaine_1(img, txt, 5, 5, "libimage.fonte", &paper, &ink);
#if DEBUG_LEVEL > 1
fprintf(stderr, "[%s] tracée...\n", txt);
#endif
sprintf(chaine, "max rgb = %ld", maxhisto);
Image_trace_chaine_1(img, chaine, 5, 15, NULL, &paper, &ink);
#if DEBUG_LEVEL > 1
fprintf(stderr, "[%s] tracée...\n", chaine);
#endif
Image_cadre_A(img);
foo=Image_TGA_save(nomtga, img, 0);
Image_DeAllocate(img); free(img);
return foo;
}
/*::------------------------------------------------------------------::*/
/* mmmmm, pas tres sexy, ce truc-la...
*/
int
Image_calc_plot_histo(Image_Desc *img, char *tganame)
{
long hr[256], hg[256], hb[256];
int foo;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %p --> '%s'\n", __func__, img, tganame);
#endif
foo = Image_histo_RGB(img, hr, hg, hb);
Image_print_error("calc plot histo: calc", foo);
foo = Image_plot_histo(tganame, hr, hg, hb, tganame);
Image_print_error("calc plot histo: plot", foo);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* fabrique dans une image une petite bande a partir d'une palette
* cette bande est horizontale.
*/
int
Image_plot_h_Map(Image_Desc *img, RGB_map *map, int xpos, int ypos, int h)
{
int x, y, v;
for (x=0; x<256; x++)
{
for (y=0; y<h; y++)
{
if ( ((y>>2)+(x>>2)) & 1) v = SOMBRE;
else v = CLAIR;
Image_plotRGB(img, x+xpos, y+ypos, v, v, v);
}
}
#if DEBUG_LEVEL
fprintf(stderr, "Image plot h Map: %d colors\n", map->nbre);
#endif
for (x=0; x<map->nbre; x++)
{
for (y=0; y<h; y++)
{
Image_plotRGB(img, x+xpos, y+ypos,
map->red[x], map->green[x], map->blue[x]);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* fabrique dans une image une petite bande a partir d'une palette
* cette bande est verticale.
*/
int
Image_plot_v_Map(Image_Desc *img, RGB_map *map, int xpos, int ypos, int l)
{
int x, y, v;
for (y=0; y<256; y++)
{
for (x=0; x<l; x++)
{
if ( ((y>>2)+(x>>2)) & 1) v = SOMBRE;
else v = CLAIR;
Image_plotRGB(img, x+xpos, y+ypos, v, v, v);
}
}
#if DEBUG_LEVEL
fprintf(stderr, "Image plot v Map: %d colors\n", map->nbre);
#endif
for (y=0; y<map->nbre; y++)
{
for (x=0; x<l; x++)
{
Image_plotRGB(img, x+xpos, y+ypos,
map->red[y], map->green[y], map->blue[y]);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* fabrique une petite TGA horizontale avec une palette dedans
*/
#define LITTLE_DIM 42
int
Image_plot_little_h_Map(char *nom, RGB_map *map, char *texte)
{
Image_Desc *img;
int foo;
if ( (img=Image_alloc(260, LITTLE_DIM+4, 3)) == NULL)
{
return IMAGE_NO_MEM;
}
foo = Image_plot_h_Map(img, map, 2, 2, LITTLE_DIM);
#if DEBUG_LEVEL
fprintf(stderr, "Plot little H map: ret plot = %d, %s\n",
foo, Image_err2str(foo));
#endif
(void)Image_cadre_A(img);
if (texte != NULL) Image_set_comment(img, texte);
foo = Image_TGA_save(nom, img, 0);
fprintf(stderr, "plot little H map: save %s: %d\n", nom, foo);
Image_DeAllocate(img); free(img);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* 20 Février 2002.
* fabrique une petite TGA verticale avec une palette dedans
*/
int
Image_plot_little_v_Map(char *nom, RGB_map *map, char *texte)
{
Image_Desc *img;
int foo;
if ( (img=Image_alloc(LITTLE_DIM+4, 260, 3)) == NULL)
{
return IMAGE_NO_MEM;
}
foo = Image_plot_v_Map(img, map, 2, 2, LITTLE_DIM);
(void)Image_cadre_A(img);
if (texte != NULL) Image_set_comment(img, texte);
foo = Image_TGA_save(nom, img, 0);
fprintf(stderr, "plot little V map: save '%s': %d\n", nom, foo);
Image_DeAllocate(img); free(img);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* new 2 decembre 2009 - ave St Exupery
*/
int
Image_plot_square_Map(char *fname, RGB_map *map, char *texte, int k)
{
int x, y, foo;
int r, g, b;
Image_Desc *img;
Image_Rect rect;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( '%s' %p '%s' %d )\n", __func__,
fname, map, texte, k);
#endif
if ( (img = Image_alloc(512, 512, 3)) == NULL )
{
#if DEBUG_LEVEL
fprintf(stderr, "Plot MAP: alloc of img failed, file=%s\n", fname);
#endif
return IMAGE_NO_MEM;
}
Image_clear(img, 0, 0, 0);
rect.h = rect.w = 31;
for (foo=0; foo<256; foo++)
{
x = ( foo & 0x0f ) * 32;
y = ( foo & 0xf0 ) * 2;
#if DEBUG_LEVEL > 1
printf("%4d : %3d %3d ", foo, x, y);
#endif
rect.x = x;
rect.y = y;
if (foo < map->nbre)
{
r = map->red[foo];
g = map->green[foo];
b = map->blue[foo];
#if DEBUG_LEVEL > 1
printf(" %3d %3d %3d\n", r, g, b);
#endif
Image_paint_rect(img, &rect, r, g, b);
}
else /* on est au dela de la fin de la palette */
{
#if DEBUG_LEVEL > 1
printf(" xxx\n");
#endif
/* Image_gadrct_Hsweep_0(img, &rect, 0); */
Image_gadrct_cross(img, &rect, 0);
}
}
foo=Image_TGA_save(fname, img, 0);
Image_DeAllocate(img); free(img);
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/*
* plotte une palette 'a la fractint'
*/
int
Image_plot_Map(char *nomtga, RGB_map *map , char *txt)
{
Image_Desc *img;
int foo, x;
RGBA paper, ink;
Image_Rect rect;
if ( (img = Image_alloc(400, 300, 3)) == NULL )
{
#if DEBUG_LEVEL
fprintf(stderr, "Plot MAP: alloc of img failed, file=%s\n", nomtga);
#endif
return IMAGE_NO_MEM;
}
Image_clear(img, SOMBRE, SOMBRE, SOMBRE);
for (foo=0; foo<map->nbre; foo++)
{
Image_plotRGB(img, foo+90, 120, 255, 255, 255);
Image_plotRGB(img, foo+90, 200, 255, 255, 255);
Image_plotRGB(img, foo+90, 280, 255, 255, 255);
Image_plotRGB(img, foo+90, 120-(map->red[foo]/5), 255, 0, 0);
Image_plotRGB(img, foo+90, 200-(map->green[foo]/5), 0, 255, 0);
Image_plotRGB(img, foo+90, 280-(map->blue[foo]/5), 0, 0, 255);
}
rect.x = 20; rect.y = 30;
rect.h = 258; rect.w = 31;
Image_draw_rect(img, &rect, CLAIR/2, CLAIR/2, CLAIR/2);
#if DEBUG_LEVEL > 1
fprintf(stderr, "Plot MAP: the text is '%s'\n", txt);
#endif
for (foo=0; foo<map->nbre; foo++)
{
for (x=21; x<50; x++)
{
Image_plotRGB(img, x, foo+31,
map->red[foo], map->green[foo], map->blue[foo]);
}
}
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
foo = Image_trace_chaine_1(img, txt, 15, 7, "8x8thin", &paper, &ink);
#if DEBUG_LEVEL > 1
fprintf(stderr, "Plot MAP: retour trace chaine = %d\n", foo);
#endif
Image_cadre_A(img);
if ( (foo=Image_TGA_save(nomtga, img, 0)) )
{
Image_DeAllocate(img); free(img);
return foo;
}
Image_DeAllocate(img); free(img);
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* new 23 oct 2001
* parameters 'p1' and 'p2' are not used, and must be 0 !
*/
int
Image_plot_histo_hf15(Image_Desc *img, char *nom, char *txt, int p1, int p2)
{
Image_Desc *plot;
long *histo, maximum;
double diviseur;
int x, y, foo, h, h2, epic_fail;
RGBA paper, ink;
char chaine[200];
#if DEBUG_LEVEL
fprintf(stderr, "%s: img %p ! work in progress !\n", __func__, img);
#endif
if ( (histo=alloca(sizeof(long)*32768)) == NULL)
{
fprintf(stderr, "Plot histo hf15: no mem for buffer\n");
#if FORCE_ABORT
abort();
#endif
return BUFFER_NO_MEM;
}
if ( (plot = Image_alloc(800, 600, 3)) == NULL )
{
#if DEBUG_LEVEL
fprintf(stderr, "Plot histo hf15: alloc img failed\n");
#endif
return IMAGE_NO_MEM;
}
Image_clear(plot, SOMBRE, SOMBRE, SOMBRE);
for (foo=0; foo<32768; foo++) histo[foo] = 0L;
#if DEBUG_LEVEL > 1
fprintf(stderr, "Plot histo hf15: buffers allocated, computing now...\n");
#endif
epic_fail = 0;
for (y=0; y<img->height; y++)
{
for (x=0; x<img->width; x++)
{
h = Image_hf15_height(img, x, y);
if (h<0 || h>32767)
epic_fail++;
else
histo[h]++;
}
}
if (epic_fail)
{
fprintf(stderr, "%s : %d epic fail is epic\n", __func__, epic_fail);
#if FORCE_ABORT
abort();
#endif
}
/* recherche du maximum de l'histogramme, pour faire la mise a l'echelle */
maximum = 0L;
for (foo=0; foo<32768; foo++)
if (histo[foo] > maximum)
maximum = histo[foo];
diviseur = (double)maximum/400.0;
if (diviseur==0) diviseur=1.0; /* XXX workaround */
fprintf(stderr, "%s: maximum = %ld, diviseur = %g\n", __func__,
maximum, diviseur);
h2 = 0;
for (foo=0; foo<32768; foo+=4)
{
h = (int)((double)histo[foo] / diviseur);
x = (foo/64)+60;
if (foo) /* pourquoi ? */
{
vline(plot, x, 590-h, 290-h2, 'g', CLAIR);
h2 = h;
}
Image_plotRGB(plot, x, 590-h, CLAIR, SOMBRE, SOMBRE);
Image_plotRGB(plot, x, 590, SOMBRE, CLAIR, SOMBRE);
}
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
/* Image_trace_chaine_0(plot, txt, 5, 5, &paper, &ink, 0); */
Image_trace_chaine_1(plot, chaine, 5, 5, NULL, &paper, &ink);
sprintf(chaine, "max %ld", maximum);
/* Image_trace_chaine_0(plot, chaine, 5, 15, &paper, &ink, 0); */
Image_trace_chaine_1(plot, chaine, 5, 15, NULL, &paper, &ink);
sprintf(chaine, "div %g", diviseur);
/* Image_trace_chaine_0(plot, chaine, 5, 25, &paper, &ink, 0); */
Image_trace_chaine_1(plot, chaine, 5, 25, NULL, &paper, &ink);
Image_cadre_A(plot);
foo=Image_TGA_save(nom, plot, 0);
Image_DeAllocate(plot); free(plot);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/

View File

View File

@ -18,7 +18,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "tthimage.h" #include "../tthimage.h"
#define TAILLE_MAX_LIGNE 75 #define TAILLE_MAX_LIGNE 75
#define VERSION_STRING "December 2009" #define VERSION_STRING "December 2009"
@ -58,7 +58,7 @@ else
} }
fprintf(fp, "P1\n %d %d\n", im->width, im->height); fprintf(fp, "P1\n %d %d\n", im->width, im->height);
fprintf(fp, "# written by libimage v %s, pnm module %s\n", fprintf(fp, "# written by libtthimage v %s, pnm module %s\n",
IMAGE_VERSION_STRING, VERSION_STRING); IMAGE_VERSION_STRING, VERSION_STRING);
if (strlen(im->name) > 0) if (strlen(im->name) > 0)
@ -172,7 +172,7 @@ else
} }
fprintf(fp, "P3\n%d %d\n255\n", im->width, im->height); fprintf(fp, "P3\n%d %d\n255\n", im->width, im->height);
fprintf(fp, "# written by libimage v %s, ppm module '%s'\n\n", fprintf(fp, "# written by libtthimage v %s, ppm module '%s'\n\n",
IMAGE_VERSION_STRING, VERSION_STRING); IMAGE_VERSION_STRING, VERSION_STRING);
if (strlen(im->name) > 0) if (strlen(im->name) > 0)
@ -249,7 +249,7 @@ else
} }
fprintf(fp, "P2\n%d %d\n255\n", im->width, im->height); fprintf(fp, "P2\n%d %d\n255\n", im->width, im->height);
fprintf(fp, "\n# written by libimage v %s\n# pnm module %s\n\n", fprintf(fp, "\n# written by libtthimage v %s\n# pnm module %s\n\n",
IMAGE_VERSION_STRING, VERSION_STRING); IMAGE_VERSION_STRING, VERSION_STRING);
for (y=0; y<im->height; y++) for (y=0; y<im->height; y++)

438
Lib/pov_hf15a.c Normal file
View File

@ -0,0 +1,438 @@
/*
pov_hf15.c
==========
Un 'height_field' de POVray est une image au format TGA
qui stocke des altitudes sur 15 bits, avec les poids
forts dans la composante rouge et les poids faibles dans
la composante verte. Pour le bleu, je ne sais pas ce
qu'il en est, donc on va le forcer a 0.
2 oct 2001: adding a function for writing a PGM 15 bits file.
16 oct 2001: the 'read pgm hf' func of Povray seems bogus, so we have
to wait for POV 3.5 for testing my func :(
23 oct 2001: all references to 16 bits are supersedes by reference
to 15 bits. after all, it's better ?
-------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* que faire si l'altitude est negative ? on clampe !-)
* ... et rappelons qu'il faut sauver en TGA pour que Pov
* retrouve ses 2^15 valeurs d'altitude.
*/
int Image_hf15_plot(Image_Desc *im, int x, int y, int h)
{
int r, g;
if (h < 0) h = 0; /* On clampe ... */
if (h > 32767) h = 32767;
if ((x<0) || (y<0) || (x>=im->width) || (y>im->height))
{
#if DEBUG_LEVEL
fprintf(stderr, "%s : %d,%d out of image\n", __func__, x, y);
#endif
return OUT_OF_IMAGE;
}
r = (h >> 8) & 0xff; /* les poids forts */
g = h & 0xff; /* les poids faibles */
(im->Rpix[y])[x] = r;
(im->Gpix[y])[x] = g;
(im->Bpix[y])[x] = 0; /* valeur 'secure', on pourrait y mettre */
/* autre chose. voir les sources de pov ? */
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* recuperer la hauteur stockée dans une image 'hf15'
* en cas de dépassement, la valeur est silencieusement limitée.
*/
int Image_hf15_height(Image_Desc *img, int x, int y)
{
register int a, b;
int h;
if ((x<0) || (y<0) || (x>=img->width) || (y>img->height))
{
#if DEBUG_LEVEL
fprintf(stderr, "%s : %d,%d out of image\n", __func__, x, y);
#endif
/* VERY BAD BUG HERE */
return OUT_OF_IMAGE;
}
/* 28 mars 2007 : optimization for speed -> use direct access
h = (Image_R_pixel(img, x, y) << 8) + Image_G_pixel(img, x, y);
*/
a = (img->Rpix[y])[x];
b = (img->Gpix[y])[x];
h = ( a << 8) + b;
return h & 0x7fff;
}
/*::------------------------------------------------------------------::*/
/*
* parameter 'mode' is not used. set it to 0, please.
*/
int Image_hf15_hf2gray(Image_Desc *src, Image_Desc *dst, int mode)
{
int x, y, h;
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y) >> 7;
Image_plotRGB(dst, x, y, h, h, h);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* il y a peut-etre une maniere plus astucieuse de choisr ces
* coeeficients que de prendre des valeurs arbitraires... */
#define K_R 65
#define K_G 42 /* il faut bien le caser, le 42 */
#define K_B 19
#define K_TOT (K_R+K_G+K_B)
/* parameter 'mode' is not used at this time. please use 0 ! */
int Image_hf15_rgb2hf(Image_Desc *src, Image_Desc *dst, int mode)
{
int x, y, h, hmax, hmin;
#if DEBUG_LEVEL > 1
fprintf(stderr, "RGB -> HF: k_tot = %d\n", K_TOT);
fprintf(stderr, " max_v = %d\n", K_R*255+K_G*255+K_B*255);
#endif
if (0 != mode)
{
fprintf(stderr, "when calling %s, mode must be 0\n", __func__);
#if FORCE_ABORT
abort();
#endif
}
hmax = -9999; hmin = 424242;
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_R_pixel(src, x, y) * K_R +
Image_G_pixel(src, x, y) * K_G +
Image_B_pixel(src, x, y) * K_B ;
#if DEBUG_LEVEL
if (h > hmax) hmax = h;
if (h < hmin) hmin = h;
#endif
Image_hf15_plot(dst, x, y, h);
}
}
#if DEBUG_LEVEL
fprintf(stderr, " h min = %d, h max = %d\n", hmin, hmax);
#endif
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* Warning: this 15 bit (valid?) pgm file can't be loaded
* by POVray. I've send a bug report, but get no answer
* from the POV team....
* May be we have to wait for the release of v3.5 ?
*/
#define VERSION_STRING "PGM hf15 / Janv 2010"
#define TAILLE_BUFFER 65536
int Image_hf15_save_PGM(char *nom, Image_Desc *img, char *comment)
{
FILE *fp;
int x, y, h, foo;
int par_ligne, nbr_overshoot;
char buffer[TAILLE_BUFFER];
#if DEBUG_LEVEL
fprintf(stderr, "%s: saving %p as file '%s'\n", __func__, img, nom);
#endif
if ((fp=fopen(nom, "w")) == NULL)
{
fprintf(stderr, "ecriture PGM hf15 %s err fopen\n", nom);
return FILE_CREATE_ERR;
}
foo = setvbuf(fp, buffer, _IOFBF, TAILLE_BUFFER);
#if DEBUG_LEVEL
fprintf(stderr, "%s: setvbuf -> %d\n", __func__, foo);
#endif
fprintf(fp, "P2\n%d %d\n32767\n", img->width, img->height);
fprintf(fp, "#\n# written by libimage v %s, %s\n",
IMAGE_VERSION_STRING, VERSION_STRING);
if (comment != NULL)
fprintf(fp, "# %s\n", comment);
fputs("#\n", fp);
nbr_overshoot = 0;
par_ligne = 0;
for (y=0; y<img->height; y++)
{
for (x=0; x<img->width; x++)
{
h = Image_R_pixel(img, x, y) * 256 +
Image_G_pixel(img, x, y);
if (h > 32767)
{
fprintf(stderr, "overshoot at %d,%d -> %d\n",
x, y, h);
if (nbr_overshoot > 42)
{
#if FORCE_ABORT
abort();
#endif
}
nbr_overshoot++;
h = 32767;
}
foo = fprintf(fp, "%d ", h);
par_ligne += foo;
if (par_ligne > 65) /* magic value ? */
{
fputs("\n", fp);
par_ligne = 0;
}
}
#if DEBUG_LEVEL > 1
fprintf(fp, "\n# end of src pixline %d\n", y);
#endif
}
fputs("\n", fp);
#if DEBUG_LEVEL > 1
fprintf(stderr, "Pov hf15 save PGM: %p %s: a re-tester...\n", img, nom);
#endif
fclose(fp);
if (nbr_overshoot)
fprintf(stderr, "in %s, on a eu %d overshoots\n",
__func__, nbr_overshoot);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
static struct
{
int x, y;
} deltas[] =
{ { -1, -1, },
{ 0, -1, },
{ 1, -1, },
{ -1, 0, },
{ 0, 0, },
{ 1, 0, },
{ -1, 1, },
{ 0, 1, },
{ 1, 1 }
};
#define PRECISION 42 /* à quoi ça sert ? */
int
Image_hf15_lissage(Image_Desc *s, Image_Desc *d, int coef, int flag)
{
int x, y, h, cumul, foo;
int r, g;
long temps, nbpix=0L;
#if DEBUG_LEVEL
double ttp;
int under, over;
#endif
if (flag)
{
fprintf(stderr, "Warning! Lissage hf15: flag (%d) must be 0\n", flag);
#if FORCE_ABORT
abort();
#endif
}
#if DEBUG_LEVEL
fprintf(stderr, ">>> Lissage hf15 : %p -> %p : coef %d, flag 0x%04x\n",
s, d, coef, flag);
#endif
#if DEBUG_LEVEL > 1
Image_start_chrono("lissage hf15", 15);
#endif
/* BIG FIX at night, the 7 january 2010 */
/* we _must_ clean the border of the target image buffer */
Image_raz_sides(d);
#if DEBUG_LEVEL
under = over = 0;
#endif
for (y=1; y<s->height-1; y++)
{
for (x=1; x<s->width-1; x++)
{
cumul = 0;
for (foo=0; foo<9; foo++)
{
/* XXX attention optimisation dangeureuse.
h = Image_R_pixel(s, x+deltas[foo].x, y+deltas[foo].y) * 256 +
Image_G_pixel(s, x+deltas[foo].x, y+deltas[foo].y);
XXX car on utilise un acces 'insecure' a la memoire image */
h = (s->Rpix[y+deltas[foo].y])[x+deltas[foo].x] * 256;
h += (s->Gpix[y+deltas[foo].y])[x+deltas[foo].x];
h &= 0x7fff;
h *= PRECISION;
if (foo==4) cumul += (h*coef);
else cumul += h;
}
cumul /= ((8+coef)*PRECISION);
if (cumul > 32767)
{
cumul = 32767;
#if DEBUG_LEVEL
over++;
#endif
}
if (cumul < 0)
{
cumul = 0;
#if DEBUG_LEVEL
under++;
#endif
}
r = (cumul >> 8) & 0x7f;
g = cumul & 0xff;
(d->Rpix[y])[x] = r;
(d->Gpix[y])[x] = g;
(d->Bpix[y])[x] = 0;
nbpix++;
}
}
#if DEBUG_LEVEL
if (under || over)
fprintf(stderr, "%s : under=%d over=%d\n", __func__, under, over);
#endif
#if DEBUG_LEVEL > 1
temps = Image_stop_chrono(NULL, 15);
ttp = ((double)temps / (double)nbpix)*1000000.0;
fprintf(stderr, "Lissage hf15: %.4f µs/pixel\n", ttp);
#endif
d->modified = 1;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* WARNING! experimental: prototype may change!
*/
int
Image_hf15_calc_minmax(Image_Desc *img, char *txt, int *pmin, int *pmax)
{
int x, y, h, minH, maxH;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p, '%s', %p, %p )\n", __func__, img, txt, pmin, pmax);
#endif
minH = 99999999; maxH = -99999999;
for (y=1; y<img->height-1; y++)
{
for (x=1; x<img->width-1; x++)
{
h = (Image_R_pixel(img, x, y) << 8) +
Image_G_pixel(img, x, y);
if (h > maxH) maxH = h;
if (h < minH) minH = h;
}
}
if (txt != NULL)
{
fprintf(stderr, "* hf15 @ %p * %s : min=%d max=%d\n",
img, txt, minH, maxH);
}
if (pmin != NULL) *pmin = minH;
if (pmax != NULL) *pmax = maxH;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* new 6 Nov 2001 */
/*
* Need more doc !
*/
int
Image_hf15_mul_add(Image_Desc *src, Image_Desc *dst, int mul, int add)
{
int x, y, h;
fprintf(stderr, "Pov hf15: mul %d & add %d\n", mul, add);
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y);
h = (h * mul) + add;
Image_hf15_plot(dst, x, y, h);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* new 6 Nov 2001 */
int
Image_hf15_invert(Image_Desc *src, Image_Desc *dst)
{
int x, y, h;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %p --> %p\n", __func__, src, dst);
#endif
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = 32768 - Image_hf15_height(src, x, y);
Image_hf15_plot(dst, x, y, h);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/

Some files were not shown because too many files have changed in this diff Show More