third massive import batch

This commit is contained in:
tth 2022-06-27 00:48:18 +02:00
parent 96d7a5399f
commit f3e30ea3bb
54 changed files with 4737 additions and 123 deletions

View File

@ -1,6 +1,6 @@
#----------------------------------------------------------------- #-----------------------------------------------------------------
# #
# # The infamous *LIBTTHIMAGE* 20 juin 2022
# #
#----------------------------------------------------------------- #-----------------------------------------------------------------
@ -13,38 +13,112 @@ STATICLIB = "../libimage.a"
#----------------------------------------------------------------- #-----------------------------------------------------------------
basic_io.o: basic_io.c $(DEPS) 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) drawing.o: drawing.c $(DEPS)
essais.o: essais.c $(DEPS) essais.h 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) image.o: image.c $(DEPS)
imprime.o: imprime.c $(DEPS) imprime.o: imprime.c $(DEPS)
luts15bits.o: luts15bits.c $(DEPS)
marques.o: marques.c $(DEPS) marques.o: marques.c $(DEPS)
mircol.o: mircol.c $(DEPS)
msglib.o: msglib.c $(DEPS) msglib.o: msglib.c $(DEPS)
mustopen.o: mustopen.c $(DEPS) mustopen.o: mustopen.c $(DEPS)
pht.o: pht.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) text0.o: text0.c $(DEPS)
text1.o: text1.c $(DEPS) text1.o: text1.c $(DEPS)
text16x24.o: text16x24.c $(DEPS) text16x24.o: text16x24.c $(DEPS)
tga.o: tga.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 \ OBJECTS = basic_io.o bitblt.o \
drawing.o \ calculs.o classif.o col_xyz.o \
essais.o \ combine.o combine2.o combine3.o combine4.o combine5.o \
image.o imprime.o \ dither.o dither2.o dither3.o dither4.o \
marques.o msglib.o mustopen.o \ doublesz.o drawing.o \
pht.o \ effects.o effects2.o effects3.o \
text0.o text1.o text16x24.o tga.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) $(STATICLIB): $(OBJECTS)
$(AR) vrs $@ $? $(AR) vrs $@ $?
$(RANLIB) $@ $(RANLIB) $@
#----------------------------------------------------------------- #-----------------------------------------------------------------
@ -56,7 +130,10 @@ t_t16x24: t_t16x24.c $(DEPS) $(STATICLIB)
#----------------------------------------------------------------- #-----------------------------------------------------------------
testtga: testtga.c $(DEPS) $(STATICLIB) essais.o: essais.c $(DEPS) essais.h
gcc $(CFLAGS) $< $(STATICLIB) -o $@ gcc $(CFLAGS) $< -c
testtga: testtga.c $(DEPS) $(STATICLIB) essais.o
gcc $(CFLAGS) $< $(STATICLIB) essais.o -lm -o $@
#----------------------------------------------------------------- #-----------------------------------------------------------------

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

@ -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;
}
/*::------------------------------------------------------------------::*/

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

@ -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

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

@ -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

@ -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;
}
/*::------------------------------------------------------------------::*/

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;
}
/*::------------------------------------------------------------------::*/

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;
}
/*::------------------------------------------------------------------::*/

134
Lib/pov_hf15b.c Normal file
View File

@ -0,0 +1,134 @@
/*
pov_hf15b.c
===========
for information about this file:
ask Thierry Boudet
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* new 24 oct 2001 - not really crah-proff
*/
int
Image_hf15_normalize(Image_Desc *src, Image_Desc *dst, int low, int high)
{
int x, y, minH, maxH, foo;
int delta, ecart;
double mult, dh;
foo = Image_hf15_calc_minmax(src, NULL, &minH, &maxH);
#if DEBUG_LEVEL
fprintf(stderr, "%s: src %p is %d < H < %d\n", __func__, src, minH, maxH);
#endif
delta = maxH - minH;
ecart = high - low;
if ((0==delta) || (0==ecart))
{
fprintf(stderr, "Pov hf15 normalize: ZERO DIVIDE!\n");
return DIVISOR_IS_ZERO;
}
mult = (double)ecart / (double)delta;
#if DEBUG_LEVEL
fprintf(stderr, "Pov hf15 normalize: delta %d, mult %f\n", delta, mult);
#endif
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
dh = (double)Image_hf15_height(src, x, y);
dh = (dh * mult) + (double)low;
Image_hf15_plot(dst, x, y, (int)dh);
}
}
#if DEBUG_LEVEL
foo = Image_hf15_calc_minmax(dst, NULL, &minH, &maxH);
fprintf(stderr, "Pov hf15 normalize: we got %d < H < %d\n", minH, maxH);
#endif
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/* New: 10 Nov 2001
*
*/
int
Image_hf15_make_colmap_0(Image_Desc *src, Image_Desc *dst, char *mapname)
{
int foo, x, y, h;
RGB_map map;
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Hf15 make colmap 0: differents dimensions %d\n",
foo);
return foo;
}
foo=Image_load_color_Map(mapname, NULL, &map);
if ( foo && foo!=MAP_TOO_BIG )
{
fprintf(stderr, "Hf15 make colmap 0: err load colormap '%s': %d / %s\n",
mapname, foo, Image_err2str(foo));
return foo;
}
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y) / 128;
#if FORCE_ABORT
if (h<0 || h>255) abort();
#endif
Image_plotRGB(dst, x, y, map.red[h], map.green[h], map.blue[h]);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* New: 18 Dec 2001
*
*/
int
Image_hf15_make_colmap_1(Image_Desc *src, Image_Desc *dst, RGB_map *map)
{
int foo, x, y, h;
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Hf15 make colmap 1: differents dims %d\n", foo);
return foo;
}
#if DEBUG_LEVEL
fprintf(stderr, "%s : data@ is %p\n", __func__, map);
#endif
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y) / 128;
#if FORCE_ABORT
if (h<0 || h>255) abort();
#endif
Image_plotRGB(dst, x, y,
map->red[h], map->green[h], map->blue[h]);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/

263
Lib/pov_hf15c.c Normal file
View File

@ -0,0 +1,263 @@
/*
pov_hf15c.c
===========
Mixing operations beetween two height-fields.
---------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* new 10 Décembre 2001
*
* Le coefficient K va de 0 a 10000 !
*/
int
Image_hf15_mix(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst, int k)
{
int foo, x, y, h1, h2, hd;
#if DEBUG_LEVEL
fprintf(stderr, "%s: k = %d\n", __func__, k);
#endif
if ( (foo=Image_compare_desc(s1, s2)) )
{
fprintf(stderr, "hf15 mix: err on sources: %s\n", Image_err2str(foo));
return foo;
}
if ( (foo=Image_compare_desc(s1, dst)) )
{
fprintf(stderr, "hf15 mix: err on dest: %s\n", Image_err2str(foo));
return foo;
}
for (y=0; y<s1->height; y++)
{
for (x=0; x<s1->width; x++)
{
h1 = Image_hf15_height(s1, x, y);
h2 = Image_hf15_height(s2, x, y);
hd = ((h1*k) + (h2*(10000-k))) / 10000;
Image_hf15_plot(dst, x, y, hd);
}
}
#if DEBUG_LEVEL
fprintf(stderr, "Image hf15 mix: done.\n");
#endif
dst->modified = 1;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* new 5 Janvier 2003
* il y a probablement des problemes d'overflow ici.
*/
int
Image_hf15_mult_i(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst)
{
int foo, x, y, h1, h2, hd;
if ( (foo=Image_compare_desc(s1, s2)) )
{
fprintf(stderr, "hf15 mult i: err on srces: %s\n", Image_err2str(foo));
return foo;
}
if ( (foo=Image_compare_desc(s1, dst)) )
{
fprintf(stderr, "hf15 mult: err on dest: %s\n", Image_err2str(foo));
return foo;
}
for (y=0; y<s1->height; y++)
{
for (x=0; x<s1->width; x++)
{
h1 = Image_hf15_height(s1, x, y);
h2 = Image_hf15_height(s2, x, y);
hd = (h1 * h2) / 32768;
Image_hf15_plot(dst, x, y, hd);
}
}
dst->modified = 1;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* nouveau 17 novembre 2009 - avenue St Exupery */
int
Image_hf15_mult_k(Image_Desc *s, Image_Desc *d, float dk)
{
int foo, x, y, h1, h2;
if ( (foo=Image_compare_desc(s, d)) )
{
fprintf(stderr, "hf15 mult k: error: %s\n", Image_err2str(foo));
return foo;
}
for (y=0; y<s->height; y++)
{
for (x=0; x<s->width; x++)
{
h1 = Image_hf15_height(s, x, y);
h2 = (int)( (float)h1 * dk );
Image_hf15_plot(d, x, y, h2);
}
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/* nouveau Juin 2008 - avenue St Exupery */
int
Image_hf15_div_i(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst)
{
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p %p %p )\n", __func__, s1, s2, dst);
#endif
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/* nouveau Juin 2008 - avenue St Exupery */
int
Image_hf15_sqrt(Image_Desc *src, Image_Desc *dst)
{
int x, y, h;
int foo;
float rh, mean_a;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p , %p )\n", __func__, src, dst);
#endif
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "hf15 sqrt: (failed) : %s\n", Image_err2str(foo));
return foo;
}
mean_a = 0.0;
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y);
if (h < 0)
{
fprintf(stderr, "WTF ! %s %p %d,%d %d\n",
__func__,
src, x, y, h);
#if FORCE_ABORT
fflush(stdout);
abort();
#endif
}
rh = (float)h / 32767.0;
mean_a += rh; /* c'est quoi ? */
h = (int)(sqrt(rh) * 32767.0);
Image_hf15_plot(dst, x, y, h);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* nouveau Novembre 2008 - avenue St Exupery */
int
Image_hf15_pow(Image_Desc *src, Image_Desc *dst, double p0w44)
{
int x, y, h;
int foo;
/* hu ho 27 jan 2010 : pourquoi on ne calcule pas en double precision ? */
float rh;
float minh, maxh;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p , %p, %g )\n", __func__, src, dst, p0w44);
#endif
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "%s : (fail) : %s\n", __func__, Image_err2str(foo));
return foo;
}
minh = 999999.99;
maxh = -999999.99;
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y);
rh = (float)h / 32768.0;
rh = pow(rh, p0w44);
if (rh < minh) minh = rh;
if (rh > maxh) maxh = rh;
h = (int)(rh * 32767.0);
Image_hf15_plot(dst, x, y, h);
}
}
fprintf(stderr, "%s -> %f %f\n", __func__, minh, maxh);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int Image_hf15_exp1(Image_Desc *src, Image_Desc *dst)
{
int foo, x, y, h;
/*
* on va calculer en double precision, parce que je suis un dino et
* que ma machine de dev ne connait pas 'expf'
*/
double rh;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p , %p )\n", __func__, src, dst);
#endif
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "%s : (fail) : %s\n", __func__, Image_err2str(foo));
return foo;
}
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
h = Image_hf15_height(src, x, y);
rh = (double)h / 32768.0;
rh = exp(rh) - 1.0;
h = (int)(rh * 32767.0);
Image_hf15_plot(dst, x, y, h);
}
}
return FUNC_IS_ALPHA;
}
int Image_hf15_exp2(Image_Desc *src, Image_Desc *dst)
{
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p , %p )\n", __func__, src, dst);
#endif
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/

215
Lib/pov_hf15d.c Normal file
View File

@ -0,0 +1,215 @@
/*
pov_hf15d.c
===========
bruitages de height-fields.
---------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* le hasard choisi quel pixel on va changer.
* le hasard choisi quelle valeur on va lui affecter, et cette
* valeur sera comprise entre 'hi' et 'lo'.
*/
int
Image_hf15_noise_0(Image_Desc *dst, int hi, int lo, int prob100)
{
int delta;
int x, y, h;
#if DEBUG_LEVEL
fprintf(stderr, ">>>> %s ( %p %d %d %d )\n", __func__,
dst, hi, lo, prob100);
#endif
delta = hi - lo;
if (0 == delta)
{
fprintf(stderr, "%s : delta is zero, fail.\n", __func__);
return DIVISOR_IS_ZERO;
}
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
if ((rand()%100) < prob100)
{
/*
* en fait je ne suis pas content de cette fonction
* de bruit, et je cherche une meilleur solution.
*/
h = (rand()%delta) + lo;
Image_hf15_plot(dst, x, y, h);
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* new 21 avr 2009: the probability use is (mis)used.
*/
int
Image_hf15_noise_1(Image_Desc *dst, int mo, int of, int prob100)
{
int x, y, h, vr;
#if DEBUG_LEVEL
long hit, mess;
float ratio;
#endif
#if DEBUG_LEVEL
fprintf(stderr, "Hf15 noise 1 is very experimental.\n");
hit = mess = 0L;
#endif
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
if (prob100 > rand()%100)
{
#if DEBUG_LEVEL
hit++;
#endif
h = Image_hf15_height(dst, x, y);
vr = (rand()%mo) + of;
h += vr;
Image_hf15_plot(dst, x, y, h);
}
#if DEBUG_LEVEL
else
{
mess++;
}
#endif
}
}
#if DEBUG_LEVEL
if (mess > 0) ratio = (float)hit / (float)mess;
else ratio = -42.42;
fprintf(stderr, "%s: hit %ld mess %ld\n", __func__, hit, mess);
#endif
return FUNC_IS_BETA;
/*
* penser à faire des tests de cette fonction :)
*/
}
/*::------------------------------------------------------------------::*/
/*
* remplacement aléatoire d'un point par un de ses proches voisins
*/
int
Image_hf15_noise_2(Image_Desc *dst, int pr100, int dist, int k1, int k2)
{
Image_Desc *clone;
int x, y, h;
int xs, ys;
int hit, mess;
#if DEBUG_LEVEL
fprintf(stderr, "Hf15 noise 2 is _very_ experimental\n");
#endif
/*
* faire une copie de l'image, qui servira de source.
*/
clone = Image_clone(dst, 1);
hit = mess = 0;
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
if ( pr100 > (rand()%100) )
{
xs = x + (rand() % dist);
ys = y + (rand() % dist);
if (Image_xy_inside(clone, xs, ys))
{
h = Image_hf15_height(clone, xs, ys);
Image_hf15_plot(dst, x, y, h);
hit++;
}
}
else
{
mess++;
}
}
}
/*
* détruire la copie de l'image.
*/
Image_DeAllocate(clone); free(clone);
/* afficher les stats a la con */
fprintf(stderr, "%s : hit=%d mess=%d\n", __func__, hit, mess);
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* deplacement aleatoire d'un point proportionnellement a sa hauteur.
* new 2 juillet 2009 - pour la colline de Sonia dans le Parking Maudit.
*/
int
Image_hf15_noise_3(Image_Desc *dst, double coef, int flag)
{
int x, y, h;
double dh, dh2, dr, maxdh;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p %f 0x%X )\n", __func__, dst, coef, flag);
#endif
if (0 != flag)
{
fprintf(stderr, "%s : flag is 0x%d and _must_ be 0\n",
__func__, flag);
}
maxdh = 0;
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
dh = (double)Image_hf15_height(dst, x, y);
dr = ((double)rand() / (double)RAND_MAX) - 0.50000000;
dh2 = dh + (dr * coef * (dh / 32768.0));
if (dh2 > maxdh)
{
maxdh = dh2;
#if DEBUG_LEVEL > 1
printf("dh is %f, dr is %f, max is %f\n",
dh, dr, maxdh);
#endif
}
/* is the clipping mandatory ? */
h = (int)dh2;
if (h < 0) h = 0;
if (h > 32767) h = 32767;
Image_hf15_plot(dst, x, y, h);
}
}
#if DEBUG_LEVEL
printf("%s : maxdh = %f\n", __func__, maxdh);
#endif
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/

101
Lib/pov_hf15e.c Normal file
View File

@ -0,0 +1,101 @@
/*
pov_hf15e.c
===========
opérations de morphologie mathématique appliquées
aux height-fields.
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
static struct
{
int x, y;
} off[] =
{
{ -1, -1 },
{ 0, -1 },
{ 1, -1 },
{ -1, 0 },
{ 0, 0 },
{ 1, 0 },
{ -1, 1 },
{ 0, 1 },
{ 1, 1 }
};
/*::------------------------------------------------------------------::*/
/*
* le paramètre 'coef' n'est pas utilisé. D'ailleurs, je ne vois
* pas trop quoi y mettre ?
*/
int
Image_hf15_dilate(Image_Desc *src, Image_Desc *dst, int coef)
{
int foo;
int x, y, h, hmax;
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Image hf15 dilate: images differents %d\n", foo);
return foo;
}
for (y=1; y<dst->height-1; y++)
{
for (x=1; x<dst->width-1; x++)
{
hmax = -1664;
for (foo=0; foo<9; foo++)
{
h = Image_hf15_height(src, x+off[foo].x, y+off[foo].y);
if (h > hmax) hmax = h;
}
Image_hf15_plot(dst, x, y, hmax);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* le paramètre 'coef' n'est pas utilisé.
*/
int
Image_hf15_erode(Image_Desc *src, Image_Desc *dst, int coef)
{
int foo;
int x, y, h, hmin;
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Image hf15 erode: images differents %d\n", foo);
return foo;
}
for (y=1; y<dst->height-1; y++)
{
for (x=1; x<dst->width-1; x++)
{
hmin = 42042;
for (foo=0; foo<9; foo++)
{
h = Image_hf15_height(src, x+off[foo].x, y+off[foo].y);
if (h < hmin) hmin = h;
}
Image_hf15_plot(dst, x, y, hmin);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* Et maintenant, il reste à coder le chapeau haut-de-forme
*/
/*::------------------------------------------------------------------::*/

134
Lib/pov_hf15f.c Normal file
View File

@ -0,0 +1,134 @@
/*
pov_hf15f.c
===========
traitement des bords des height-fields.
---------------------------------------
new 3 octobre 2009 - avenue StExupery
*/
#include <stdio.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/* Abaissement graduel des bords d'un height field */
/* Inspiration : 'Image_cadre_C' */
/* TODO : build a real unit test */
/* TODO : expliquer les parametres */
int Image_hf15_sweep(Image_Desc *im, int hfin, int taille, int k)
{
int x, y, x2, y2;
float fhfin, fx, fy, coef, d;
int hit, mess, h, h2;
#if DEBUG_LEVEL
fprintf(stderr, "%s : img=%p hfin=%d taille=%d k=%d\n",
__func__, im, hfin, taille, k);
fprintf(stderr, " pic dims : %d x %d\n", im->width, im->height);
#endif
/* this is really a MESS ! */
fhfin = (float)(hfin*hfin);
x2 = im->width / 2;
y2 = im->height / 2;
#if DEBUG_LEVEL
fprintf(stderr, " fhfin=%f x2=%d y2=%d\n", fhfin, x2, y2);
#endif
hit = mess = 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;
/* XXX un peu plus d'explications ici */
if (fx < fy) d = fx;
else d = fy;
if (d < fhfin)
{
coef = d / fhfin;
h = Image_hf15_height(im, x, y);
h2 = (int)(((float)h*coef) + ((float)hfin*(1.0-coef)));
#if DEBUG_LEVEL > 1
printf("__sweep__ %5d %d\n", h, h2);
#endif
if ( h<0 || h>32767)
{
fprintf(stderr, "%s fail %d %d\n",
__func__, x, y);
abort();
}
Image_hf15_plot(im, x, y, h2);
hit ++;
}
else
{
mess ++;
}
}
}
#if DEBUG_LEVEL
fprintf(stderr, " hit %d mess %d\n", hit, mess);
#endif
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
int Image_hf15_getmin(Image_Desc *s1, Image_Desc *s2, Image_Desc *d)
{
int x, y, h1, h2;
for (y=0; y<d->height; y++)
{
for (x=0; x<d->width; x++)
{
h1 = Image_hf15_height(s1, x, y);
h2 = Image_hf15_height(s2, x, y);
if (h1 < h2)
Image_hf15_plot(d, x, y, h1);
else
Image_hf15_plot(d, x, y, h2);
}
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
int Image_hf15_getmax(Image_Desc *s1, Image_Desc *s2, Image_Desc *d)
{
int x, y, h1, h2;
for (y=0; y<d->height; y++)
{
for (x=0; x<d->width; x++)
{
h1 = Image_hf15_height(s1, x, y);
h2 = Image_hf15_height(s2, x, y);
if (h1 > h2)
Image_hf15_plot(d, x, y, h1);
else
Image_hf15_plot(d, x, y, h2);
}
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/

193
Lib/pov_synth.c Normal file
View File

@ -0,0 +1,193 @@
/*
pov_hf_synth.c
==============
Thierry Boudet
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/* new 6 Jan 2002, pas fini le 6 Jan 2003. */
int
Image_hf15_synth_0(Image_Desc *dst, Image_PtList *ptl)
{
int foo, nb, idx;
int x, y, dist, distmin;
int ptx, pty, xx, yy;
fprintf(stderr, "%s:%d (%s) img %p ptl %p\n", __FILE__, __LINE__, __func__,
dst, ptl);
if (ptl->control != 0xfde9601a)
{
fprintf(stderr, "%p is not a ptlist\n", ptl);
return -1;
}
nb = ptl->nbre;
printf("%s : il y a %d points dans la liste %p\n", __func__, nb, ptl);
for (y=0; y<dst->height; y++)
{
for (x=0; x<dst->width; x++)
{
idx = -9999;
distmin = 99999999;
for (foo=0; foo<nb; foo++)
{
ptx = ptl->points[foo].x;
pty = ptl->points[foo].y;
xx = x - ptx;
yy = y - pty;
dist = (xx*xx) + (yy*yy);
if (dist < distmin)
{
distmin = dist;
idx = foo;
}
}
/* got a value */
Image_hf15_plot(dst, x, y, ptl->points[idx].h);
}
}
return FULL_NUCKED;
}
/*
* pourtant, il me semble qu'il existe un code Fortran qui
* commence à bien fonctionner ?
*/
/*::------------------------------------------------------------------::*/
/*
* remise en chantier de ce truc le 31 janvier 2008 -
*/
static int plot_synth_1(Image_Desc *img, int x, int y, double dh)
{
int ih;
ih = (int)(dh);
#if DEBUG_LEVEL > 1
printf(" (%d,%d) -> %g -> %d\n", x, y, dh, ih);
#endif
Image_hf15_plot(img, x, y, ih);
#define COEF 0.777
ih = (int)(dh*COEF);
Image_hf15_plot(img, x-1, y , ih);
Image_hf15_plot(img, x+1, y , ih);
Image_hf15_plot(img, x , y-1, ih);
Image_hf15_plot(img, x , y+1, ih);
ih = (int)(dh*COEF);
Image_hf15_plot(img, x-1, y-1, ih);
Image_hf15_plot(img, x-1, y+1, ih);
Image_hf15_plot(img, x+1, y-1, ih);
Image_hf15_plot(img, x+1, y+1, ih);
ih = (int)(dh*COEF);
Image_hf15_plot(img, x-2, y , ih);
Image_hf15_plot(img, x+2, y , ih);
Image_hf15_plot(img, x , y-2, ih);
Image_hf15_plot(img, x , y+2, ih);
return 1;
}
/* ++++++++++++++++++++++++++++++++++++ */
int
Image_hf15_synth_1(Image_Desc *dst, Image_PtList *ptl)
{
int idx, nb;
double dbl_h;
printf("**** %s:%s: %p %p\n", __FILE__, __func__, dst, ptl);
if (ptl->control != 0xfde9601a)
{
fprintf(stderr, "%s: %p is not a ptlist\n", __func__, ptl);
return -1;
}
nb = ptl->nbre;
printf("%s : il y a %d points dans la liste %p\n", __func__, nb, ptl);
for (idx=0; idx<nb; idx++)
{
#if DEBUG_LEVEL > 1
printf("point #%d\n", idx);
#endif
dbl_h = (double)ptl->points[idx].h;
plot_synth_1(dst, ptl->points[idx].x, ptl->points[idx].y, dbl_h);
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/* new 11 decembre 2007 - ave St Exupery */
int
Image_hf15_synth_fromfunc0(Image_Desc *dst, int param,
double(*func)(int x, int y, int k))
{
int x, y;
double dx, dy, val;
double minh, maxh, delta;
long surface;
double *array, *ptr;
double a, b;
printf("%s: %p %d\n", __func__, dst, param);
surface = (long)dst->height * (long)dst->width;
printf(" surface image: %ld pixels\n", surface);
array = malloc(sizeof(double)*surface);
if (NULL == array)
{
fprintf(stderr, "no mem at %s:%s:%d\n", __FILE__, __func__, __LINE__);
abort();
}
minh = 9e99;
maxh = -9e99;
ptr = array;
for (x=0; x<dst->width; x++)
{
dx = (double)x;
for (y=0; y<dst->height; y++)
{
dy = (double)y;
val = func(x, y, 51);
*ptr++ = val;
if (val < minh) minh = val;
if (val > maxh) maxh = val;
}
}
delta = maxh - minh;
printf("extremums: %.12g %.12g\n", minh, maxh);
printf("delta: %.12g\n", delta);
a = 32766.9999 / delta;
b = - ( a * minh );
printf(" a & b: %.12g %.12g\n", a, b);
minh = 9e99;
maxh = -9e99;
ptr = array;
for (x=0; x<dst->width; x++)
{
for (y=0; y<dst->height; y++)
{
val = *ptr++;
val = (a * val) + b;
if (val < minh) minh = val;
if (val > maxh) maxh = val;
Image_hf15_plot(dst, x, y, ceil(val));
}
}
printf("altitudes: %.12g %.12g\n", minh, maxh);
free(array);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/

View File

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

227
Lib/scale.c Normal file
View File

@ -0,0 +1,227 @@
/*
scale.c
--------------
I think that I have to make an effort in math studies
for future enhancement of this module :)
see also: halfsize.c doublesz.c
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* do not use in production !-)
*/
int
Image_scale_simple(Image_Desc *src, Image_Desc *dst, int k)
{
float coefX, coefY, fx, fy;
int xd, yd, xs, ys;
int r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "scale simple: %p (%dx%d) -> %p (%dx%d) k:%d \n",
src, src->width, src->height,
dst, dst->width, dst->height, k);
#endif
coefX = (float)dst->width / (float)src->width;
coefY = (float)dst->height / (float)src->height;
#if DEBUG_LEVEL
fprintf(stderr, "coefficients: X %f y %f\n", coefX, coefY);
#endif
/*
* bon, pour les interpolations, il faut que je trouve
* un peu de doc... mais ou ?
*/
for (yd=0; yd<dst->height; yd++)
{
for (xd=0; xd<dst->width; xd++)
{
fx = (float)xd / coefX;
fy = (float)yd / coefY;
xs = (int)fx;
ys = (int)fy;
Image_getRGB(src, xs, ys, &r, &g, &b);
(dst->Rpix[yd])[xd] = r;
(dst->Gpix[yd])[xd] = g;
(dst->Bpix[yd])[xd] = b;
}
}
return FUNC_IS_ALPHA;
}
/*::------------------------------------------------------------------::*/
/* new 2 nov 2009 - ave StEx */
/* I've lost all my mathematical concepts (la vieillesse est un naufrage)
* so I'm going to make some approximations\dots */
static int getpix_bilin(Image_Desc *src, double fx, double fy,
int *pr, int *pg, int *pb)
{
double x11, y11, x22, y22;
int xx, yy;
int r11, g11, b11, r12, g12, b12,
r21, g21, b21, r22, g22, b22;
double drh, drw;
double raa, gaa, baa;
double rbb, gbb, bbb;
double rcc, gcc, bcc;
/* before real ops, set RGB to some know values */
*pr = *pg = *pb = 0;
/* build all the nasty values */
x11 = floor(fx); y11 = floor(fy);
x22 = ceil(fx); y22 = ceil(fy);
drw = fx - x11; drh = fy - y11;
xx = (int)x11; yy = (int)y11;
#if DEBUG_LEVEL > 2
if ( ! (rand() % 40000) )
printf("X %10.3f %10.3f %10.3f %10.3f %4d\n",
fx, x11, x22, drw, xx);
if ( ! (rand() % 40000) )
printf("Y %10.3f %10.3f %10.3f %10.3f %4d\n",
fy, y11, y22, drh, yy);
#endif
if ( ! Image_xy_inside(src, xx, yy) )
return -1;
if ( ! Image_xy_inside(src, xx+1, yy+1) )
return -2;
r11 = src->Rpix[yy][xx]; g11 = src->Gpix[yy][xx]; b11 = src->Bpix[yy][xx];
r12 = src->Rpix[yy][xx+1]; g12 = src->Gpix[yy][xx+1]; b12 = src->Bpix[yy][xx+1];
r22 = src->Rpix[yy+1][xx+1]; g22 = src->Gpix[yy+1][xx+1]; b22 = src->Bpix[yy+1][xx+1];
r21 = src->Rpix[yy+1][xx]; g21 = src->Gpix[yy+1][xx]; b21 = src->Bpix[yy+1][xx];
/* hum hum... */
raa = (double)r11 * (1.0-drw) + (double)r12 * drw;
gaa = (double)g11 * (1.0-drw) + (double)g12 * drw;
baa = (double)b11 * (1.0-drw) + (double)b12 * drw;
if (raa < 0.0) abort();
if (gaa < 0.0) abort();
if (baa < 0.0) abort();
rbb = (double)r21 * (1.0-drw) + (double)r22 * drw;
gbb = (double)g21 * (1.0-drw) + (double)g22 * drw;
bbb = (double)b21 * (1.0-drw) + (double)b22 * drw;
if (rbb < 0.0) abort();
if (gbb < 0.0) abort();
if (bbb < 0.0) abort();
rcc = (raa * (1.0-drh)) + (rbb * drh);
gcc = (gaa * (1.0-drh)) + (gbb * drh);
bcc = (baa * (1.0-drh)) + (bbb * drh);
*pr = (int)rcc; *pg = (int)gcc; *pb = (int)bcc;
return -105;
}
/*::------------------------------------------------------------------::*/
int Image_scale_bilinear(Image_Desc *src, Image_Desc *dst, int k)
{
int xd, yd, xs, ys, r, g, b;
double coefX, coefY;
double fxd, fyd, fxs, fys;
#if DEBUG_LEVEL
fprintf(stderr, "scale bilinear: %p (%dx%d) -> %p (%dx%d) k:%d \n",
src, src->width, src->height,
dst, dst->width, dst->height, k);
#endif
coefX = (double)dst->width / (double)src->width;
coefY = (double)dst->height / (double)src->height;
#if DEBUG_LEVEL
fprintf(stderr, "%s : coefs %lf %lf\n", __func__, coefX, coefY);
#endif
for (yd=0; yd<dst->height; yd++)
{
fyd = (double)yd;
fys = fyd / coefY;
for (xd=0; xd<dst->width; xd++)
{
fxd = (double)xd;
fxs = fxd / coefX;
getpix_bilin(src, fxs, fys, &r, &g, &b);
(dst->Rpix[yd])[xd] = r;
(dst->Gpix[yd])[xd] = g;
(dst->Bpix[yd])[xd] = b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int Image_getpix_bilin(Image_Desc *src, double fx, double fy,
int *pr, int *pg, int *pb)
{
int foo;
foo = getpix_bilin(src, fx, fy, pr, pg, pb);
return foo;
}
/*::------------------------------------------------------------------::*/
/*
* for now, method must be 0 !
*/
Image_Desc * Image_new_scale( Image_Desc *src,
float scaleX, float scaleY,
int methode )
{
float fx, fy;
int nw, nh, foo;
Image_Desc *dst;
#if DEBUG_LEVEL
fprintf(stderr, "image\t%d %d, scale %f %f\n",
src->width, src->height, scaleX, scaleY);
#endif
fx = (float)src->width * scaleX;
fy = (float)src->height * scaleY;
nw = (int)(ceil((double)fx));
nh = (int)(ceil((double)fy));
#if DEBUG_LEVEL
fprintf(stderr, "\t%f %f\n", fx, fy);
fprintf(stderr, "\tnew dims: %d x %d\n", nw, nh);
#endif
if ( (dst = Image_alloc(nw, nh, 3)) == NULL )
{
fprintf(stderr, "Image new/scale: no memory\n");
return NULL;
}
#if DEBUG_LEVEL
fprintf(stderr, "\tnew image @ %p\n", dst);
#endif
foo = Image_scale_simple(src, dst, 0);
return dst;
}
/*::------------------------------------------------------------------::*/

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"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
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"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
#define TAMPPOOL_VERSION "0.0.3" #define TAMPPOOL_VERSION "0.0.3"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/

View File

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

View File

@ -5,7 +5,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "tthimage.h" #include "../tthimage.h"
#undef DEBUG_LEVEL #undef DEBUG_LEVEL
#define DEBUG_LEVEL 1 #define DEBUG_LEVEL 1

87
Lib/warp0.c Normal file
View File

@ -0,0 +1,87 @@
/*
warp0.c
---------------
diverses deformations d'image.
*/
#include <stdio.h>
#include <math.h>
#include "../tthimage.h"
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 1
#endif
/*::------------------------------------------------------------------::*/
/*
* bon, caisse que peut bien faire ce truc ?
*/
int
Image_warp_essai_0(Image_Desc *src, Image_Desc *dst, double angle,
int xc, int yc)
{
int x, y, r, g, b;
long lfoo;
double arad, dheight, dwidth, tmax, dist, va;
int ofx, ofy;
dheight = (double)dst->height;
dwidth = (double)dst->width;
lfoo = ((dst->height*dst->height)+(dst->width*dst->width));
tmax = sqrt((double)lfoo) / 2.0;
va = angle / 360.0;
fprintf(stderr, "%s : %d,%d dh = %f dw = %f tmax = %f\n", __func__,
xc, yc, dheight, dwidth, tmax);
for (y=0; y<dst->height; y++)
{
/*
printf("------- Ligne %d -----------------\n", y);
*/
arad = ((double)y / dheight) * M_PI;
for (x=0; x<dst->width; x++)
{
dist = (double)x / dwidth;
ofx = xc + (int)(sin(arad)*dist*tmax);
ofy = yc + (int)(cos(arad)*dist*tmax);
/*
printf("%15f %15f %6d %6d\n", arad, dist, ofx, ofy);
*/
if ( ofx>=0 && ofx<src->width && ofy>=0 && ofy<src->height )
{
Image_getRGB(src, ofx, ofy, &r, &g, &b);
}
else
{
r = g = b = 0;
}
Image_plotRGB(dst, x, y, r, g, b);
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int
Image_warp_essai_1(Image_Desc *src, Image_Desc *dst, double angle)
{
#if DEBUG_LEVEL
fprintf(stderr, "Warp 1: what I can do here ?\n");
#endif
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* voir aussi les module scale.c et warp1.c
*/
/*::------------------------------------------------------------------::*/

116
Lib/warp1.c Normal file
View File

@ -0,0 +1,116 @@
/*
warp1.c
_______________
*/
#include <stdio.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* Rotation d'image. le parametre 'angle' est en degres.
*/
int
Image_center_rotate(Image_Desc *src, Image_Desc *dst, double angle)
{
int xs, ys, xd, yd;
double arad, fxs, fys, fxd, fyd;
double sincalc, coscalc;
int mx, my;
int r, g, b;
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s : work in progress...\n", __func__);
#endif
arad = angle/180*M_PI;
mx = dst->width / 2;
my = dst->height / 2;
sincalc = sin(arad);
coscalc = cos(arad);
for (xd=0; xd<dst->width; xd++)
{
fxd = (double)(xd-mx);
for (yd=0; yd<dst->height; yd++)
{
fyd = (double)(yd-my);
fxs = fxd * coscalc - fyd * sincalc;
fys = fxd * sincalc + fyd * coscalc;
xs = (int)fxs + mx;
ys = (int)fys + my;
if (xs>=0 && xs<src->width && ys>=0 && ys<src->height)
{
/* Image_getRGB(src, xs, ys, &r, &g, &b); */
r = (src->Rpix[ys])[xs];
g = (src->Gpix[ys])[xs];
b = (src->Bpix[ys])[xs];
}
else
{ r = g = b = 142; }
/* Image_plotRGB(dst, xd, yd, r, g, b); */
(dst->Rpix[yd])[xd] = r;
(dst->Gpix[yd])[xd] = g;
(dst->Bpix[yd])[xd] = b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* La meme chose, en gros...
* Sauf qu'on pourrait theoriquement choisir la position du
* point de rotation.
*
* reste plus qu'à coder...
*/
int
Image_center_rotate_xy(Image_Desc *src, Image_Desc *dst, double angle,
double x, double y)
{
int foo, xd, yd;
double arad, fxs, fys, fxd, fyd;
double sincalc, coscalc;
int mx, my;
#if DEBUG_LEVEL
fprintf(stderr, "Center Rotate XY: work in progress...\n");
#endif
fprintf(stderr, "%s on %p at %g,%g\n", __func__, src, x, y);
arad = angle/180*M_PI;
mx = dst->width / 2;
my = dst->height / 2;
sincalc = sin(arad);
coscalc = cos(arad);
fxs = fys = 0.0; /* ? hein ? */
foo = 0;
for (xd=0; xd<dst->width; xd++)
{
fxd = (double)(xd-mx);
for (yd=0; yd<dst->height; yd++)
{
fyd = (double)(yd-my);
}
}
/* MAIS C'EST PAS ENCORE FINI CE TRUC ? */
/* 4 mai 2007: ben non, ya rien :) */
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/*
* voir aussi les modules scale.c et warp0.c
*/
/*::------------------------------------------------------------------::*/

88
Lib/warp2.c Normal file
View File

@ -0,0 +1,88 @@
/*
warp2.c
---------------
*/
#include <stdio.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* Bon, ça marche avec des déplacements positifs, mais pour
* revenir en arrière, on fait comment ?
*/
int
Image_shift_xy(Image_Desc *src, Image_Desc *dst, int ox, int oy)
{
int x, y;
int x2, y2, foo;
#if DEBUG_LEVEL
fprintf(stderr, "*** Image_shift_xy: work in progress...\n");
fprintf(stderr, "src=%p dst=%p ox=%d oy=%d\n", src, dst, ox, oy);
#endif
if ( src == dst )
{
fprintf(stderr, "Image shift xy: can't overwrite, sorry\n");
return IMG_OVERWRITE;
}
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
return foo;
}
if ( (ox<0) || (ox>=src->width) )
{
fprintf(stderr, "Image shift xy: param ox %d out of range\n", ox);
return INVALID_PARAM;
}
if ( (oy<0) || (oy>=src->height) )
{
fprintf(stderr, "Image shift xy: param oy %d out of range\n", oy);
return INVALID_PARAM;
}
for (y=0; y<dst->height; y++)
{
y2 = (y+oy) % src->height;
for (x=0; x<dst->width; x++)
{
x2 = (x+ox) % src->width;
Image_pixel_copy(src, x, y, dst, x2, y2);
}
}
return FUNC_IS_BETA; /* et elle coredumpe ? */
}
/*::------------------------------------------------------------------::*/
/* OPTIMIZED FOR SPEED */
int Image_shift_x(Image_Desc *src, Image_Desc *dst, int ox)
{
#if DEBUG_LEVEL
fprintf(stderr, "*** %s : work in progress...\n", __func__);
fprintf(stderr, "%p -> sX(%d) -> %p\n", src, ox, dst);
#endif
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/* OPTIMIZED FOR SPEED */
int Image_shift_y(Image_Desc *src, Image_Desc *dst, int oy)
{
#if DEBUG_LEVEL
fprintf(stderr, "*** %s : work in progress...\n", __func__);
fprintf(stderr, "%p -> sY(%d) -> %p\n", src, oy, dst);
#endif
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/*
* voir aussi les modules scale.c et warp[0|1|3].c
*/
/*::------------------------------------------------------------------::*/

62
Lib/warp3.c Normal file
View File

@ -0,0 +1,62 @@
/*
warp3.c
---------------
*/
#include <stdio.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* travail basé sur un PDF dont l'URL a é postée dans la
* tribune de la buvette.
*
* L'auteur est Gernot Hoffmann.
*/
int
Image_interpolate_0(Image_Desc *src, Image_Desc *dst, int ox, int oy)
{
int x, y;
int x2, y2, foo;
fprintf(stderr, "*** Image_interpolate_0: work in progress...\n");
if ( src == dst )
{
fprintf(stderr, "Image interpolate_0: can't overwrite, sorry\n");
return IMG_OVERWRITE;
}
/*
@@@@@@@@@@@@@@
PUTAIN SA RACE
La police du PDF est pas sortie à l'impression :(
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Et comme le code est incomplet et en Pascal, je ne
sais pas trop quoi en faire. Beueueueh.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/* new 11 janvier 2009 - avenue St Exupery */
int
Image_interpolate_2(Image_Desc *src, Image_Desc *dst, RGBA *rgba)
{
int x, y;
if (NULL==rgba)
{
fprintf(stderr, "Using default RGBA in %s...\n", __func__);
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/
/*
* voir aussi les modules scale.c, zoom.c et warp[0|1|2].c
*/
/*::------------------------------------------------------------------::*/

24
Tools/Makefile Normal file
View File

@ -0,0 +1,24 @@
#-----------------------------------------------------------------
#
# Fabrication des outils - nouvelle version 26 juin 2022
#
#-----------------------------------------------------------------
include ../Paramakes.mk
DEPS = ../tthimage.h Makefile
all: tga_tools
#-----------------------------------------------------------------
fonctions.o: fonctions.c
gcc $(CFLAGS) -c $<
#-----------------------------------------------------------------
tga_tools: tga_tools.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -o $@
#-----------------------------------------------------------------

430
Tools/fonctions.c Normal file
View File

@ -0,0 +1,430 @@
/*
T G A _ O U T I L S
-------------------
fonctions communes a tous les outils - new 11 juin 2002
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* non portable but useful function */
char *strdup(const char *s);
#define IN_FONCTION
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
int
cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg)
{
int idx = 0;
idx = 0;
while (liste[idx].nom != NULL)
{
#if DEBUG_LEVEL > 1
fprintf(stderr, "check %12s %8s\n", liste[idx].nom,
liste[idx].ptypes);
#endif
if ( ! strcmp(liste[idx].nom, mot) )
{
*pmode = liste[idx].code;
*pnbarg = strlen(liste[idx].ptypes);
#if DEBUG_LEVEL > 1
fprintf(stderr, "found! mode %d nbpar %d\n", *pmode, *pnbarg);
sleep(1);
#endif
return idx;
}
idx++;
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s : %s not found\n", __func__, mot);
#endif
return -1;
}
/*::------------------------------------------------------------------::*/
int
liste_mots_clefs(mot_clef *liste, int flag)
{
mot_clef *pmc;
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s ( %p %d )\n", __func__, liste, flag);
#endif
if (42 != flag) {
fprintf(stderr, "UH ? flag is not the universal answer ?\n");
}
pmc = liste;
printf(" commande | type arg | explication\n");
printf("------------+----------+------------------------------------\n");
while (pmc->nom != NULL)
{
if (pmc->aide != NULL)
printf(" %-10s | %-8s | %s\n",
pmc->nom, pmc->ptypes, pmc->aide);
pmc++;
}
printf("------------+----------+------------------------------------\n");
return 0;
}
/*::------------------------------------------------------------------::*/
/*
* INPUT str string to scan for an integer
* pval pointer to the retrun value
* k * not used *
*
* OUTPUT 1 successfuly make a conversion
* 0 strange error occured :(
*/
int parse_int_param(char *str, int *pval, int k)
{
long lfoo;
int val;
val = (int)(lfoo = strtol(str, NULL, 0));
#if DEBUG_LEVEL
fprintf(stderr, "%s: %s: '%s' -> %ld -> %d\n",
__FILE__, __func__, str, lfoo, val);
#endif
*pval = val;
return 1;
}
/*::------------------------------------------------------------------::*/
/* input: str string to scan for four csv int
prect rectangle struct who need datas
k * not used *
output 1 all correct
2 invalid string
27 janvier 2014
*/
int parse_rect_param(char *str, Image_Rect *prect, int k)
{
char *cptr;
int idx, foo, val;
#if DEBUG_LEVEL
fprintf(stderr, "%s '%s' to %p\n", __func__, str, prect);
#endif
if (k) fprintf(stderr, "%s : k is %d, but must be 0\n", __func__, k);
memset(prect, 0, sizeof(Image_Rect));
cptr = strdup(str);
#if DEBUG_LEVEL
fprintf(stder, "copie dans cptr %p\n", cptr);
#endif
idx = 0;
cptr = strtok(cptr, ",");
while (NULL != cptr) {
fprintf(stderr, "%3d %p = '%s'\n", idx, cptr, cptr);
foo = sscanf(cptr, "%d", &val);
fprintf(stderr, "val = %d\n", val);
switch (idx) {
case 0: prect->x = val; break;
case 1: prect->y = val; break;
case 2: prect->w = val; break;
case 3: prect->h = val; break;
}
cptr = strtok(NULL, ",");
idx++;
}
return 0;
}
/*::------------------------------------------------------------------::*/
static Param params[NB_PARAMS];
int
parse_parametres(int argc, char *argv[], char *types, int prem)
{
int foo, idxt;
int entier;
double flottant;
char *cptr;
#if DEBUG_LEVEL
fprintf(stderr, "Parse params: types '%s' debut %d\n", types, prem);
#endif
/*
* init de la table des paramètres.
*/
for (foo=0; foo<NB_PARAMS; foo++) {
params[foo].type = '?';
}
for (foo=prem, idxt=0; foo<argc; foo++, idxt++)
{
#if DEBUG_LEVEL
fprintf(stderr, "\t%d/%d\t%c\t%s\n", foo, idxt, types[idxt], argv[foo]);
#endif
switch (types[idxt])
{
case 'c':
if (strlen(argv[foo])!=1)
{
fprintf(stderr, "bad length of char param\n");
}
else
{
#if DEBUG_LEVEL
fprintf(stderr, "char param = %d\n", *argv[foo]);
#endif
params[idxt].type = 'c';
params[idxt].p.i = *argv[foo];
}
break;
case 'i':
/*
* En fait, ici, il serait bon de parser aussi les
* parametres donnes en hexadecimal.
*/
if (parse_int_param(argv[foo], &entier, 0)==1)
{
params[idxt].type = 'i';
params[idxt].p.i = entier;
}
else
{
fprintf(stderr, "ERR parse int param %s\n", argv[foo]);
exit(5);
}
break;
case 's':
#if DEBUG_LEVEL
fprintf(stderr, "%s: case 's' : %p\n", __func__, argv[foo]);
#endif
if ((cptr=strdup(argv[foo]))!=NULL)
{
params[idxt].type = 's';
params[idxt].p.s = cptr;
}
else
{
fprintf(stderr, "ERR parse param %s\n", argv[foo]);
exit(5);
}
break;
case 'd':
/* the 'd' is for 'double precision', not for 'decimal' */
if (sscanf(argv[foo], "%lf", &flottant)==1)
{
params[idxt].type = 'd';
params[idxt].p.d = flottant;
#if DEBUG_LEVEL
fprintf(stderr, "at foo=%d, val is %f %g\n",
foo, flottant, flottant);
#endif
}
else
{
fprintf(stderr,"ERR parse float param %s\n",argv[foo]);
exit(5);
}
break;
case 'f':
/* the 'f' is for 'flag', not for 'float' */
switch(argv[foo][0])
{
case '0': case 'f': case 'F': case 'n': case 'N':
params[idxt].type = 'f';
params[idxt].p.i = 0;
break;
case '1': case 't': case 'T': case 'y': case 'Y':
params[idxt].type = 'f';
params[idxt].p.i = 1;
break;
default:
fprintf(stderr, "bad flag %s\n", argv[foo]);
exit(5);
}
break;
case 'R':
fprintf(stderr, "'Rect' parser not implemented\n");
exit(6);
default:
fprintf(stderr, "partype #%d '%c' invalid\n",
idxt, types[idxt]);
exit(5);
}
}
return 0;
}
/*::------------------------------------------------------------------::*/
/* affichage de la liste des parametres trouves */
void print_parametres(void)
{
int foo;
printf(" +------+-----+\n");
printf(" | parameters |\n");
printf(" +------+-----+\n");
for (foo=0; foo<NB_PARAMS; foo++)
{
printf(" | %2d | %c |\n", foo, params[foo].type);
}
printf(" +------+-----+\n");
fflush(stdout);
}
/*::------------------------------------------------------------------::*/
/*
* fonctions de récuperation d'un paramètre.
*/
int GIP(int rang)
{
if (rang<0 || params[rang].type!='i')
{
fprintf(stderr, "erreur GIP %d\n", rang);
exit(5);
}
return params[rang].p.i;
}
int GCP(int rang)
{
if (rang<0 || params[rang].type!='c')
{
fprintf(stderr, "erreur GCP %d\n", rang);
exit(5);
}
return params[rang].p.i;
}
/* get an 'int' parameter with a default value */
int GIPdef(int rang, int def)
{
#if DEBUG_LEVEL
fprintf(stderr, "Warning ! %s is not tested\n", __func__);
#endif
if (rang<0 || params[rang].type!='i')
{
return def;
}
return params[rang].p.i;
}
char * GSP(int rang)
{
#if DEBUG_LEVEL > 1
fprintf(stderr, "GetStringParameter(%d)\n", rang);
#endif
if (rang<0 || params[rang].type!='s')
{
fprintf(stderr, "erreur GSP %d\n", rang);
exit(5);
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "GetStringParameter -> %s\n", params[rang].p.s);
#endif
return params[rang].p.s;
}
double GDP(int rang)
{
if (rang<0 || params[rang].type!='d')
{
fprintf(stderr, "erreur GDP %d\n", rang);
exit(5);
}
return params[rang].p.d;
}
int GFP(int rang)
{
if (rang<0 || params[rang].type!='f')
{
fprintf(stderr, "erreur GFP %d\n", rang);
exit(5);
}
return params[rang].p.i;
}
/*::------------------------------------------------------------------::*/
int
must_be_verbose(void)
{
char *envvar;
envvar = getenv(NOM_VAR_ENV_VERBOSE);
if ((envvar!=NULL) && !strcmp(envvar, "yes"))
{
#if DEBUG_LEVEL > 1
fprintf(stderr, "HA HA HA ! pid:%d MUST BE VERBOSE !\n", getpid());
#endif
return 1;
}
return 0;
}
/*::------------------------------------------------------------------::*/
int
dump_command_line(int argc, char *argv[], int force)
{
char *envvar;
int flag=0, foo;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %s, argc=%d\n", __func__, argv[0], argc);
#endif
envvar = getenv(NOM_VAR_ENV_VERBOSE);
if ( (envvar!=NULL) && !strcmp(envvar, "yes") ) flag = 1;
if (flag || force)
{
fprintf(stderr, "TGA(%d) %d arg:", getpid(), argc);
for (foo=0; foo<argc; foo++)
fprintf(stderr, " %s", argv[foo]);
fprintf(stderr, "\n");
}
return flag;
}
/*::------------------------------------------------------------------::*/
int set_new_seed(int k)
{
char *ptr;
long seed;
if (NULL==(ptr=getenv("FIXED_SEED"))) {
/* no fixed seed in context, doing semi-random */
srand(getpid());
#if DEBUG_LEVEL
fprintf(stderr, "no FIXED_SEED, first rand is number : %d\n", rand());
#endif
}
else {
/* try to parse the env var */
seed = strtol(ptr, NULL, 0);
#if DEBUG_LEVEL
fprintf(stderr, "%s : strtol(%s) -> %ld\n",
__func__, ptr, seed);
#endif
srand(seed);
}
return rand();
}
/*::------------------------------------------------------------------::*/

102
Tools/tga_outils.h Normal file
View File

@ -0,0 +1,102 @@
/*
tga_outils.h
------------
*/
#include <unistd.h>
#include "../tthimage.h"
#define TGA_OUTILS_VERSION "0.58"
/*
* 13 Dec 2001: v0.11 a cause du 'mustopen' pour les palettes.
* 11 Fev 2002: v0.12 a cause du '-ansi' (hein Kerdeuzz, on y vient)
* 21 Nov 2002: v0.13 a cause du parser de paramètres.
* 14 Jan 2006: v0.14 parce que je remet le truc dans le net.
* 05 Jan 2007: v0.15 pour etre synchrone avec la doc.
* 11 Dec 2007: v0.22 pour le parser de parametres (hexadecimal)
* 05 May 2009: v0.36 grand nettoyage du code en chantier
* 27 Dec 2009: v0.42 prise en compte des champs d'altitude.
* 06 Mar 2010: v0.43 introduction du 'df3 tool'.
* 27 Jan 2014: V0.52 added : 'parse_rect_param'.
*/
#define TGA_OUTILS_COPYLEFT "(dwtfywl) TontonTh 2018"
#define TGA_WWW_SITE "http://la.buvette.org/devel/libimage/"
#define PERR(txt) fprintf(stderr, "\t| %s\n", (txt))
#define PERL fprintf(stderr, "\t+-----------------------------------------\n")
#define NOM_VAR_ENV_VERBOSE "TGA_OUTILS_VERBOSE" /* flag ON = "yes" */
#define NOM_VAR_ENV_TIMING "TGA_OUTILS_TIMING" /* flag ON = "yes" */
int must_be_verbose(void);
int set_new_seed(int k);
/*::------------------------------------------------------------------::*/
/*
* structure de description d'un mot-clef
* --------------------------------------
*
* types des parametres (chaine pointée par ptype)
*
* i entier 32 bits / char parameter
* s chaine de caractères
* d double flottant
*/
typedef struct
{
char *nom;
int code;
char *ptypes; /* type des paramètres */
char *aide;
char *longhelp;
} mot_clef;
#define NB_PARAMS 16 /* max number of allowed parameters */
/*
* structure contenant un paramètre.
*/
typedef struct
{
char type;
union
{
int i;
char *s;
double d;
} p;
} Param;
int cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg);
/* le flag ne sert a rien, mais il faut le mettre a 42 */
int liste_mots_clefs(mot_clef *liste, int flag);
int parse_int_param(char *str, int *pval, int k);
int parse_rect_param(char *str, Image_Rect *prect, int k);
int parse_parametres(int ac, char *av[], char *types, int prem);
void print_parametres(void);
int GIP(int rang);
int GCP(int rang);
int GIPdef(int rang, int def);
char * GSP(int rang);
double GDP(int rang);
int GFP(int rang); /* get flag */
/*::------------------------------------------------------------------::*/
/*
* fonctions de bavardage
*/
int dump_command_line(int argc, char *argv[], int force);
/*::------------------------------------------------------------------::*/
/*
* pour plus de details, for more informations
* http://la.buvette.org/devel/libimage/img-outils.html
* ----------------------------------------------------
*/

402
Tools/tga_tools.c Normal file
View File

@ -0,0 +1,402 @@
/*
* TGA_TOOLS
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define VERSION 1
#define SURFACE 2
#define GETDIMS 4
#define GETDIMX 5
#define GETDIMPOV 6
#define GETDIMW 7
#define WIDTH 8
#define HEIGHT 9
#define MK_RGB 10 /* new 22 jan 2014 */
#define MK_NOISE 11 /* new 07 fev 2014 */
#define GRMINMAX 17 /* min & max in gray level */
#define MESSAGE 20
#define STRUCTS 21
#define HEADER 33
#define TIMESTAMP 34
#define PRHISTO 35
#define TAG7SEG0 40
#define ENVIRON 50
/*::------------------------------------------------------------------::*/
mot_clef commandes[] =
{
{ "version", VERSION, "", "version de la libimage" },
{ "surface", SURFACE, "s", "number of pixels" },
{ "getdims", GETDIMS, "s", "dim targa '42 33'" },
{ "getdimx", GETDIMX, "s", "dim targa '42x33'" },
{ "getdimpov", GETDIMPOV, "s", "dim au format POV opt" },
{ "getdimweb", GETDIMW, "s", "dim au format HTML" },
{ "width", WIDTH, "s", "width of targa" },
{ "height", HEIGHT, "s", "height of targa" },
{ "grminmax", GRMINMAX, "si", "image.tga K" },
{ "message", MESSAGE, "sis", "tgafname flags 'baratin bla'" },
{ "structs", STRUCTS, "", "display sizeof structs" },
{ "header", HEADER, "s", "filename of image" },
{ "timestamp", TIMESTAMP, "ss", "filename message" },
{ "prhisto", PRHISTO, "s", "filename.tga" },
{ "tag7", TAG7SEG0, "si", "fname.tga nnn" },
{ "environ", ENVIRON, "", "" },
{ "mk_rgb", MK_RGB, "siiiii", "fname w h r g b" },
};
/*::------------------------------------------------------------------::*/
int
print_tga_dims(char *filename, int flags)
{
int foo, width, height;
#if DEBUG_LEVEL
fprintf(stderr, "%s:%d %s ( %s, %d )\n", __FILE__, __LINE__,
__func__, filename, flags);
#endif
foo = Image_TGA_get_dims(filename, &width, &height);
if (foo)
{
fprintf(stderr, "something is bad with %s : %d\n", filename, foo);
Image_print_error("explanation", foo);
}
switch(flags)
{
case 0:
printf("%8d %8d\n", width, height);
break;
case 1:
printf("%dx%d\n", width, height);
break;
case 2:
printf(" -w%d -h%d\n", width, height);
break;
case 3:
printf("width=%d height=%d\n", width, height);
break;
case 4:
printf("%d\n", width);
break;
case 5:
printf("%d\n", height);
break;
default:
fprintf(stderr, "bad flag %d in %s\n", flags, __func__);
abort();
break; /* unreached ? */
}
return foo;
}
/*::------------------------------------------------------------------::*/
int showheader(char *filename, int flag)
{
int foo;
#if DEBUG_LEVEL
fprintf(stderr, "Show Header '%s' %d\n", filename, flag);
#endif
foo = Image_TGA_show_header(filename, 0);
#if DEBUG_LEVEL
fprintf(stderr, "%s got %d\n", __func__, foo);
#endif
return foo;
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/
int make_a_rgb_tga(char *fname, int w, int h, int r, int g, int b)
{
Image_Desc *img;
int foo;
#if DEBUG_LEVEL
fprintf(stderr, "%s -> %s : %dx%d, rgb %d,%d,%d\n", __func__, fname, w, h,
r, g, b);
#endif
if (w < 1 || h < 1)
{
fprintf(stderr, "%s : img dims %d %d ?\n", __func__, w, h);
return 666;
}
img = Image_alloc(w, h, 3);
Image_clear(img, r, g, b);
foo = Image_TGA_save(fname, img, 0);
return 666;
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/
int timestamp(char *fnin, char *fnout, char *txt, int flag)
{
int foo;
Image_Desc *src;
#if DEBUG_LEVEL
fprintf(stderr, "timestamping '%s' to '%s' with '%s'\n", fnin, fnout, txt);
#endif
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
{
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fnin, __func__);
exit(5);
}
foo = Image_marque_timestamp(src, txt, NULL, 0);
#if DEBUG_LEVEL
if (foo)
Image_print_error("marque timestamp --> ", foo);
#endif
Image_TGA_save(fnout, src, 0);
return foo;
}
/*::------------------------------------------------------------------::*/
int marque_message(char *fnin, char *fnout, char *txt, int flag)
{
int foo, posx, posy;
Image_Desc *src;
RGBA ink, pap;
/* some sane default values */
ink.r = 255, ink.g = 255, ink.b = 100; ink.a = 255;
pap.r = 30, pap.g = 30, pap.b = 155; pap.a = 255;
posx = posy = 6;
if (flag) {
ink.r = 200, ink.g = 200, ink.b = 200; ink.a = 255;
pap.r = 0, pap.g = 0, pap.b = 0; pap.a = 127;
posx = posy = 0;
}
if (must_be_verbose())
fprintf(stderr, "%s:\n '%s' to '%s' with '%s' flg %d\n", \
__func__, fnin, fnout, txt, flag);
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
{
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fnin, __func__);
exit(5);
}
foo = Image_txt1_box_0(src, txt, posx, posy, 4, &pap, &ink, 0);
Image_TGA_save(fnout, src, 0);
#if DEBUG_LEVEL
fprintf(stderr, "%s : saving %s\n", __func__, fnout);
#endif
return foo;
}
/*::------------------------------------------------------------------::*/
int print_histogramme(char *filename, int flags)
{
Image_Desc *src;
long hr[256], hg[256], hb[256];
int foo;
if ( (src=Image_TGA_alloc_load(filename)) == NULL )
{
fprintf(stderr, "tga_tools, chargement '%s' failed\n", filename);
exit(5);
}
foo = Image_histo_RGB(src, hr, hb, hg);
if (foo)
{
fprintf(stderr, "tga_tools, calcul histogramme: %d %s\n",
foo, Image_err2str(foo));
exit(5);
}
for (foo=0; foo<256; foo++)
{
printf("%3d %8ld %8ld %8ld\n", foo, hr[foo], hg[foo], hb[foo]);
}
return 0;
}
/*::------------------------------------------------------------------::*/
/* new 27 mars 2008 - avenue St Exupery */
int print_environ(void)
{
int foo;
char *ptr;
char *noms[] =
{
NOM_VAR_ENV_VERBOSE, NOM_VAR_ENV_TIMING, "LIBIMAGE_PATH",
"TTH_CONF_DIR", "LIBIMAGE_DEBUG", "BITMAP_FONTS",
"FIXED_SEED", ENV_DEFAULT_RGBA
};
for (foo=0; foo<(sizeof(noms)/sizeof(char *)); foo++)
{
ptr = getenv(noms[foo]);
printf("%5d %-25s %s\n", foo, noms[foo], ptr);
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int tag_7_segments_0(char *fname, int value)
{
int foo;
Image_Desc *src;
char buffer[100];
#if DEBUG_LEVEL
fprintf(stderr, "%s:%s %s %d\n", __FILE__, __func__, fname, value);
#endif
if ( (src=Image_TGA_alloc_load(fname)) == NULL )
{
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fname, __func__);
exit(5);
}
sprintf(buffer, "%04d", value);
foo = Image_7seg_tag0(src, buffer, 0);
#if DEBUG_LEVEL
fprintf(stderr, "%s : tagging %s -> %d\n", __func__, fname, foo);
#endif
foo = Image_TGA_save(fname, src, 0);
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s : saving %s -> %d\n", __func__, fname, foo);
#endif
return -1;
}
/*::------------------------------------------------------------------::*/
int main (int argc, char *argv[])
{
int foo;
int idx, mode, nbarg;
char * cptr;
dump_command_line(argc, argv, 0);
/* new 4 feb 2014 */
foo = set_new_seed(42);
#if DEBUG_LEVEL
fprintf(stderr, "set new seed -> %d\n", foo);
#endif
if (1 == argc)
{
fprintf(stderr, "* tga_tools v 0.1.31 (%s) *\n", __DATE__);
fprintf(stderr, "usage:\n\t%s action f.tga [params]\n", argv[0]);
liste_mots_clefs(commandes, 42);
exit(0);
}
if (-1 == (idx=cherche_mot_clef(argv[1], commandes, &mode, &nbarg)) )
{
fprintf(stderr, "action '%s' inconnue.\n", argv[1]);
exit(1);
}
#if DEBUG_LEVEL
fprintf(stderr, "%s commande: idx=%d mode=%d nbarg=%d\n",
argv[0], idx, mode, nbarg);
#endif
#define FIRST_PARAM 2
foo = parse_parametres(argc, argv, commandes[idx].ptypes, FIRST_PARAM);
switch(mode)
{
case VERSION:
printf("Version des outils: %s ", TGA_OUTILS_VERSION);
printf("- %s, %s\n", __DATE__, __TIME__);
printf("%s is the swiss knife for Targa files\n", argv[0]);
Image_print_version(2);
break;
case GETDIMS:
cptr = GSP(0);
#if DEBUG_LEVEL
fprintf(stderr, "GETDIMS %s\n", cptr);
#endif
foo = print_tga_dims(cptr, 0);
break;
case GETDIMX:
cptr = GSP(0);
foo = print_tga_dims(cptr, 1);
break;
case GETDIMPOV:
cptr = GSP(0);
foo = print_tga_dims(cptr, 2);
break;
case GETDIMW:
cptr = GSP(0);
foo = print_tga_dims(cptr, 3);
break;
case WIDTH:
foo = print_tga_dims(GSP(0), 4);
break;
case HEIGHT:
foo = print_tga_dims(GSP(0), 5);
break;
case HEADER:
foo = showheader(GSP(0), 0);
break;
case PRHISTO:
foo = print_histogramme(GSP(0), 0);
break;
case TIMESTAMP:
cptr = GSP(0);
foo = timestamp(cptr, GSP(0), GSP(1), 0);
break;
case MK_RGB:
cptr = GSP(0);
fprintf(stderr, "MK_RGB -> %s\n", cptr);
foo = make_a_rgb_tga(cptr, GIP(1), GIP(2),
GIP(3), GIP(4), GIP(5));
break;
case MK_NOISE:
cptr = GSP(0);
fprintf(stderr, "MK_NOISE -> %s\n", cptr);
foo = make_a_rgb_tga(cptr, GIP(1), GIP(2),
GIP(3), GIP(4), GIP(5));
break;
case TAG7SEG0:
foo = tag_7_segments_0(GSP(0), GIP(1));
break;
case MESSAGE:
cptr = GSP(0);
#if DEBUG_LEVEL
fprintf(stderr, "marque message %p\n", cptr);
#endif
foo = marque_message(cptr, GSP(0), GSP(2), GIP(1));
#if DEBUG_LEVEL
fprintf(stderr, "marque message -> %d\n\n", foo);
#endif
break;
case STRUCTS:
#if DEBUG_LEVEL
fprintf(stderr, "going to 'Image_print_sizeof_structs'\n");
#endif
Image_print_sizeof_structs(NULL);
break;
case ENVIRON:
foo = print_environ();
break;
default:
fprintf(stderr, "Hu ho %d ?\n", mode);
break;
}
return 0;
}
/*::------------------------------------------------------------------::*/

View File

@ -1,83 +0,0 @@
/*
* Routines de test de machins de la LibImage de tTh
*
* Bien entendu, pas la moindre explication ici :)
*/
int Essai_Extractbits(char *fname, int k);
int Essai_des_Quadpics(char *fsrc, int k);
int Essai_des_drawings(char *fname, int k);
int Essai_des_Combines(char *fname, int k);
int Essai_de_la_Recursion(char *fname, int k);
int Essai_des_Glitches(char *fsrc, int k);
int Essai_anamorphoses(char *fsrc, double dk, int k);
int Essai_des_bitplanes(char *txt, int w, int h);
int Essayer_les_alphas(char *fname, int k);
int Essai_des_bitplanes(char *txt, int w, int h);
int Manipuler_les_couleurs(char *fname, int k);
int Essai_luminance(char *scrname, int k);
int Essais_plot_Map(int k);
int Essai_raw16bits(char *srcname, int k);
int Essai_color_2_map(char *srcname, int k);
int Essai_des_gray_ops(char *srcname, int k);
int Essai_des_Contrastes(char *, int);
int Essai_des_lut15bits(char *srcname, int k);
int Essai_des_mires(char *, int, int);
int Essai_des_zooms(char *srcname, int k);
int Essai_des_7_segments(char *srcname, int flag);
int Essai_des_distances(char *srcname, int nbre, int flag);
int Essai_des_cadres(char *srcname, int flags);
int Filtre_Directionnel(char *srcname, int flags);
int Test_des_trucs_2x2(char *srcname, int k);
int Test_des_warpings(char *srcname, int k);
int Test_des_mosaiques(char *srcname, int k);
int Test_hf15_synth_fromfunc(char *fname);
int Test_hf15_synth_fromPtl(char *fname, char *oname);
int Test_funcs_hf15(char *mntname, int flag);
int Test_des_df3(char *txt, int k);
int Test_vignettes(char *srcname, int k);
int Test_classif(char *srcname, int k);
int Test_rgbmask(char *srcname);
void Test_rgb2xyz(void);
int Essai_des_marquages(char *srcname, int nombre, char *texte);
void Test_double_size(void);
int Test_new_scale(char *fnamesrc, int coef);
int Test_copie_de_rectangles(char *nomsource);
int Test_Egalisations(char *nomsource, int k);
int Test_Dithering(char *nomsource, int k);
int Test_des_marquages(char *srname, int k1, int k2);
int Test_Effects_A(char *nomsource, int flag);
int Test_des_tamppools(char *imgname, int param);
int Essai_export_palettes(char *basename);
int Test_des_filtres(char *srcname, int k);
void Test_des_patterns(char *prefix, int foo, int bar);
int Test_des_pixeliz(char *srcname, int flags);
int Essai_des_bitblt(char *srcname, int k);
int Essai_des_gadgrect(char *srcname, int k);
int Essai_Television(char *source, int k);
/* dans essais2;c */
int Essai_des_big_chars(char *fname, int k);
int Essai_des_jauges(char *fname, int k);
/*
* Le programme principal est 'testtga.c' mais il serait bien de faire
* une fonction qui enchaine tous les Tests et tous les Essais afin
* de pouvoir facilement valgrinder le tout :)
*/