Compare commits
2 Commits
0b8cf14126
...
58b8fa878c
Author | SHA1 | Date | |
---|---|---|---|
|
58b8fa878c | ||
|
d298f63e7e |
4
Tools/.gitignore
vendored
4
Tools/.gitignore
vendored
@ -4,3 +4,7 @@
|
||||
|
||||
tga_extract
|
||||
tga_to_text
|
||||
tga_plothisto
|
||||
tga_plotmap
|
||||
tga_resize
|
||||
tga_fractales
|
||||
|
@ -13,7 +13,8 @@ all: genplot2 \
|
||||
tga_combine tga_export tga_alpha tga_extract \
|
||||
tga_television tga_dither tga_applymap tga_makehf15 \
|
||||
tga_mires tga_incrust tga_pattern tga_equalize \
|
||||
tga_to_text
|
||||
tga_to_text tga_resize tga_plotmap tga_plothisto \
|
||||
tga_fractales
|
||||
|
||||
# 'tga_info.c' do not compile yet
|
||||
|
||||
@ -29,6 +30,22 @@ genplot2: genplot2.c $(DEPS) fonctions.o
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
fractales.o: fractales.c fractales.h Makefile
|
||||
gcc $(CFLAGS) -c $<
|
||||
|
||||
tga_fractales: tga_fractales.c $(DEPS) fractales.o fonctions.o
|
||||
gcc $(CFLAGS) $< fractales.o ../libtthimage.a fonctions.o \
|
||||
-lm -o $@
|
||||
|
||||
tga_resize: tga_resize.c $(DEPS) fonctions.o
|
||||
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
|
||||
|
||||
tga_plotmap: tga_plotmap.c $(DEPS) fonctions.o
|
||||
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
|
||||
|
||||
tga_plothisto: tga_plothisto.c $(DEPS) fonctions.o
|
||||
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
|
||||
|
||||
tga_to_text: tga_to_text.c $(DEPS) fonctions.o
|
||||
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
|
||||
|
||||
|
384
Tools/fractales.c
Normal file
384
Tools/fractales.c
Normal file
@ -0,0 +1,384 @@
|
||||
/*
|
||||
fractales.c
|
||||
===========
|
||||
|
||||
*....................................................*
|
||||
. warning, this is a 'work in progress' .
|
||||
. .
|
||||
. don't trust prototypes for building .
|
||||
. serious applications... .
|
||||
*....................................................*
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <tthimage.h>
|
||||
|
||||
#include "fractales.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
void Image_fractales_print_version(int flag)
|
||||
{
|
||||
printf("*** Fractales (%s) v 0.0.12\n", __FILE__);
|
||||
if (flag)
|
||||
{
|
||||
printf("\tcompiled %s , %s\n", __DATE__, __TIME__);
|
||||
}
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* fonction de comparaison de deux variables 'double'
|
||||
*/
|
||||
int compare_double(double a, double b)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* cette fonction a été repompé (sans honte :) du livre de
|
||||
* Roger T. Stevens, "Fractal Programming in C" éditée par
|
||||
* M&T Books.
|
||||
* Ceci dit, elle est un peu trop monolithique, puisque l'équation
|
||||
* à résoudre est codée en dur.
|
||||
*/
|
||||
int Newton_0(Image_Desc *im, int maxiter)
|
||||
{
|
||||
int col, row, i;
|
||||
double dcol, drow;
|
||||
double Xmax, Xmin, Ymax, Ymin;
|
||||
double deltaX, deltaY, denom;
|
||||
double X, Y, Xsquare, Ysquare, Xold, Yold;
|
||||
|
||||
Xmax = Ymax = 3.5; Xmin = Ymin = -3.5;
|
||||
deltaX = (Xmax-Xmin)/(double)im->width;
|
||||
deltaY = (Ymax-Ymin)/(double)im->height;
|
||||
|
||||
for (col=0; col<im->width; col++)
|
||||
{
|
||||
dcol = (double)col;
|
||||
for (row=0; row<im->height; row++)
|
||||
{
|
||||
drow = (double)row;
|
||||
X = Xmin + dcol * deltaX;
|
||||
Y = Ymin + drow * deltaY;
|
||||
Xsquare = 0.0;
|
||||
Ysquare = 0.0;
|
||||
Xold = Yold = 42.0;
|
||||
for (i=0; i<maxiter; i++)
|
||||
{
|
||||
Xsquare = X * X;
|
||||
Ysquare = Y * Y;
|
||||
denom = 3*((Xsquare-Ysquare)*(Xsquare-Ysquare) +
|
||||
4*Xsquare*Ysquare);
|
||||
if (denom < 0.0000001)
|
||||
denom = 0.0000001;
|
||||
|
||||
X = .6666667*X + (Xsquare - Ysquare)/denom;
|
||||
Y = .6666667*Y + 2*X*Y/denom;
|
||||
if ((Xold==X) && (Yold==Y))
|
||||
break;
|
||||
} /* finbo sur maxiter */
|
||||
|
||||
if (X > 0)
|
||||
{
|
||||
Image_plotRGB(im, col, row, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Y > 0)
|
||||
Image_plotRGB(im, col, row, 255, 0, 0);
|
||||
else
|
||||
Image_plotRGB(im, col, row, 0, 0, 255);
|
||||
}
|
||||
}
|
||||
if (0 == col%5)
|
||||
fprintf(stderr, "newton 0: col %5d / %5d\r", col, im->width);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* C'est pas encore fini ce truc ?
|
||||
*/
|
||||
int GingerBreadMan(Image_Desc *im, int maxiter)
|
||||
{
|
||||
double x1, y1, x2, y2;
|
||||
int iter;
|
||||
|
||||
x1 = 10.0;
|
||||
y1 = 0.333;
|
||||
|
||||
for (iter=0; iter<maxiter; iter++)
|
||||
{
|
||||
x2 = 1.0 - y1 + abs(x1);
|
||||
y2 = x1;
|
||||
|
||||
printf("%9g %9g\n", x2, y2);
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
En fait, il faudrait travailler sur deux images...
|
||||
*/
|
||||
int Image_Random_Walker_0(Image_Desc *im, Image_Desc *dst,
|
||||
int nbpass, int nbsteps)
|
||||
{
|
||||
int pass, step, foo;
|
||||
int x, y, ra, ga, ba, rb, gb, bb;
|
||||
|
||||
if ( (foo=Image_compare_desc(im, dst)) )
|
||||
{
|
||||
fprintf(stderr, "Random_Walker_0: images are differents %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
for (pass=0; pass<nbpass; pass++)
|
||||
{
|
||||
x = rand() % im->width;
|
||||
y = rand() % im->height;
|
||||
|
||||
ra = Image_R_pixel(im, x, y);
|
||||
ga = Image_G_pixel(im, x, y);
|
||||
ba = Image_B_pixel(im, x, y);
|
||||
|
||||
/* printf("\tP%d\t\tX%d\tY%d\t%d,%d,%d\n", pass, x, y, ra, ga, ba); */
|
||||
|
||||
for (step=0; step<nbsteps; step++)
|
||||
{
|
||||
x += (rand()%3)-1;
|
||||
if (x<0) x += im->width;
|
||||
if (x>=im->width) x -= im->width;
|
||||
y += (rand()%3)-1;
|
||||
if (y<0) y += im->height;
|
||||
if (y>=im->height) y -= im->height;
|
||||
|
||||
rb = Image_R_pixel(im, x, y);
|
||||
gb = Image_G_pixel(im, x, y);
|
||||
bb = Image_B_pixel(im, x, y);
|
||||
|
||||
Image_plotRGB(dst, x, y,
|
||||
(ra+rb+rb)/3, (ga+gb+gb)/3, (ba+bb+bb)/3);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
#define XMIN (-1.5)
|
||||
#define XMAX (1.5)
|
||||
#define YMIN (-1.5)
|
||||
#define YMAX (1.5)
|
||||
|
||||
int Image_Julia_0_0(Image_Desc *im, RGB_map *pmap, int fuzz,
|
||||
double cx, double cy)
|
||||
{
|
||||
int col, row;
|
||||
double deltaX, deltaY, dx, dy, x2, y2;
|
||||
long debut, fin;
|
||||
int iter, r, g, b, maxiter;
|
||||
|
||||
debut = time(NULL);
|
||||
|
||||
fprintf(stderr, "Julia_0_0: %dx%d\n", im->width, im->height);
|
||||
|
||||
deltaX = (XMAX - XMIN) / im->width;
|
||||
deltaY = (YMAX - YMIN) / im->height;
|
||||
|
||||
maxiter = 0;
|
||||
|
||||
/*
|
||||
* si pas de palette définie, en créer une ?
|
||||
*/
|
||||
for (row=0; row<im->height; row++)
|
||||
{
|
||||
dy = YMIN + (double)row * deltaY;
|
||||
|
||||
for (col=0; col<im->width; col++)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
printf("%5d %5d ", row, col);
|
||||
#endif
|
||||
|
||||
dx = XMIN + (double)col * deltaX;
|
||||
|
||||
iter = 0;
|
||||
x2 = y2 = 0.0;
|
||||
|
||||
while ( (iter < fuzz) &&
|
||||
((x2 + y2) < 4.0) )
|
||||
{
|
||||
x2 = dx * dx;
|
||||
y2 = dy * dy;
|
||||
dx = 2 * dx * dy + cx;
|
||||
dy = x2 - y2 + cy;
|
||||
iter++;
|
||||
}
|
||||
|
||||
if (iter > maxiter)
|
||||
maxiter = iter;
|
||||
|
||||
if (iter >= fuzz)
|
||||
{
|
||||
r = g = b = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = pmap->red[iter%pmap->nbre];
|
||||
g = pmap->green[iter%pmap->nbre];
|
||||
b = pmap->blue[iter%pmap->nbre];
|
||||
}
|
||||
|
||||
Image_plotRGB(im, col, row, r, g, b);
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
printf(" %3d \r", iter);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
fin = time(NULL);
|
||||
|
||||
printf("duree du calcul: %ld secondes, maxiter: %d\n", fin-debut, maxiter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
#define XA -2.0
|
||||
#define XB 2.0
|
||||
#define YA -2.0
|
||||
#define YB 1.3
|
||||
|
||||
int Image_Mandelbrot_0(Image_Desc *image, int maxiter)
|
||||
{
|
||||
int Y, X;
|
||||
int r, g, b;
|
||||
double zr, zi, fx, fy, real, imag, fiter, dist2;
|
||||
long debut, fin, temps; /* pour chronometrer */
|
||||
int iter, out, foo;
|
||||
double tmpr, tmpi;
|
||||
|
||||
debut = time(NULL);
|
||||
|
||||
out = 0;
|
||||
|
||||
for (Y=0; Y<image->height; Y++)
|
||||
{
|
||||
fprintf(stderr, "ligne %4d sur %d\r", Y, image->height);
|
||||
fy = (double)Y;
|
||||
real = ( fy / (double)image->height * (YB-YA) ) + YA;
|
||||
|
||||
for (X=0; X<image->width; X++)
|
||||
{
|
||||
fx = (double)X;
|
||||
imag = ( fx / (double)image->width * (XB-XA) ) + XA;
|
||||
|
||||
iter = 0;
|
||||
zr = zi = 0.0;
|
||||
|
||||
do
|
||||
{
|
||||
iter++;
|
||||
|
||||
dist2 = zr*zr + zi*zi;
|
||||
if (dist2 > 4.0)
|
||||
{
|
||||
out++;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* calculer le mandelbrot
|
||||
* ----------------------
|
||||
* la formule est:
|
||||
* z0 = 0 + 0i
|
||||
* z1 = z0^2 + c;
|
||||
* ...
|
||||
*/
|
||||
tmpr = zr*zr - zi*zi;
|
||||
tmpi = 2.0 * zr * zi;
|
||||
|
||||
zr = tmpr + real;
|
||||
zi = tmpi + imag;
|
||||
|
||||
} while (iter < maxiter);
|
||||
|
||||
fiter = (double)iter / (double)maxiter;
|
||||
|
||||
Image_color_x(zr, zi, &r, &g, &b);
|
||||
Image_plotRGB(image, X, Y, r, g, b);
|
||||
|
||||
}
|
||||
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
fin = time(NULL);
|
||||
|
||||
temps = fin - debut;
|
||||
if (temps < 500)
|
||||
{
|
||||
foo = 's';
|
||||
}
|
||||
else
|
||||
{
|
||||
foo = 'm';
|
||||
temps /= 60;
|
||||
}
|
||||
|
||||
printf("\nMandelbrot_0: temps d'execution = %ld %c\n", temps, foo);
|
||||
printf("Mandelbrot_0: nombre de points dehors = %d\n", out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Lorenz_Orbits(Image_Desc *img, int iters,
|
||||
double a, double b, double c, double dt)
|
||||
{
|
||||
int pass;
|
||||
double dx, dy, dz, dxp, dyp, dzp;
|
||||
FILE *fp;
|
||||
|
||||
if (NULL == (fp=fopen("lorenz.dat", "w"))) {
|
||||
perror("lorenz datafile");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s ( %p %d / %f %f %f %f )\n", __func__, img, iters,
|
||||
a, b, c, dt);
|
||||
|
||||
dx = dy = dz = 0.0001;
|
||||
|
||||
for (pass=0; pass<iters; pass++) {
|
||||
|
||||
fprintf(fp, "%6d %8f %8f %8f\n", pass, dx, dy, dz);
|
||||
|
||||
dxp = dx - (a*dx + a*dy) * dt;
|
||||
dyp = dy + (b*dx - dy - dz*dz) * dt;
|
||||
dzp = dz - (c*dz + dx*dy) * dt;
|
||||
|
||||
dx = dxp, dy = dyp, dz = dzp;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 42;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* et un PopCorn ?
|
||||
*/
|
||||
/*::------------------------------------------------------------------::*/
|
25
Tools/fractales.h
Normal file
25
Tools/fractales.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
fractales.h
|
||||
-----------
|
||||
*....................................................*
|
||||
. warning, this is a 'work in progress' .
|
||||
. don't trust prototypes for building .
|
||||
. serious applications... .
|
||||
*....................................................*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
void Image_fractales_print_version(int flag);
|
||||
|
||||
int GingerBreadMan(Image_Desc *im, int maxiter);
|
||||
|
||||
int Image_Random_Walker_0(Image_Desc *im, Image_Desc *dst,
|
||||
int nbpass, int nbsteps);
|
||||
int Image_Julia_0_0(Image_Desc *, RGB_map *, int, double, double);
|
||||
int Image_Mandelbrot_0(Image_Desc *image, int maxiter);
|
||||
|
||||
int Newton_0(Image_Desc *im, int maxiter);
|
||||
|
||||
int Lorenz_Orbits(Image_Desc *img, int iters,
|
||||
double a, double b, double c, double dt);
|
58
Tools/tga_2x2contrast.c
Normal file
58
Tools/tga_2x2contrast.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
2x2 contrast enhancer
|
||||
---------------------
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::
|
||||
:::::: NEED ACCURATE DOCUMENTATION ::::::
|
||||
:::::::::::::::::::::::::::::::::::::::::
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tga_outils.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "* tga_2x2contrast v 0.18 [%s] %s\n",
|
||||
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
|
||||
fprintf(stderr, "Usage:\n\ttga_2x2contrast <src.tga> <dst.tga>\n");
|
||||
Image_print_version(0);
|
||||
exit(5);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Image_Desc *src, *dst;
|
||||
int foo;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(argv[1])) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_2x2contrast: can't load \"%s\" ...\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( (dst=Image_clone(src, 1)) == NULL )
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = Image_2x2_contrast(src, dst);
|
||||
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_2x2contrast: %d / %s\n", foo, Image_err2str(foo));
|
||||
}
|
||||
|
||||
foo = Image_TGA_save(argv[2], dst, 0);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
128
Tools/tga_fractales.c
Normal file
128
Tools/tga_fractales.c
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
FRACTALES
|
||||
---------
|
||||
|
||||
Il reste beaucoup de travail sur cet outil:
|
||||
|
||||
- plasma
|
||||
- popcorn
|
||||
- newton: oct 2003, c'est en route. janv 2010 pas fini.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tga_outils.h"
|
||||
#include "fractales.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
#define MANDEL0 1
|
||||
#define JULIA00 2
|
||||
#define GINGER 3
|
||||
#define NEWTON0 10
|
||||
#define NEWTON1 11
|
||||
#define LORENZ0 12
|
||||
|
||||
mot_clef mots_clef[] =
|
||||
{
|
||||
{ "ginger", GINGER, "ii", "width & height" },
|
||||
{ "julia00", JULIA00, "ii", "width & height" },
|
||||
{ "mandel0", MANDEL0, "ii", "width & height" },
|
||||
{ "newton0", NEWTON0, "ii", "width & height" },
|
||||
{ "lorenz0", LORENZ0, "ii", "W & H" },
|
||||
{ NULL, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
void usage(int flag)
|
||||
{
|
||||
Image_fractales_print_version(flag);
|
||||
fprintf(stderr, "usage:\n\ttga_fractales type nom.tga [params]\n");
|
||||
if (flag)
|
||||
{
|
||||
Image_print_version(1);
|
||||
liste_mots_clefs(mots_clef, 42);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* argv[1]: type fractale
|
||||
* argv[2]: nom fichier.tga
|
||||
*/
|
||||
#define FIRST_PAR 3
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
Image_Desc *dst;
|
||||
int foo, width, height;
|
||||
int commande, nbargs, idx;
|
||||
RGB_map map;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
if ( argc==2 && !strcmp(argv[1], "list") ) usage(1);
|
||||
if ( argc < 3 ) usage(0);
|
||||
|
||||
idx = cherche_mot_clef(argv[1], mots_clef, &commande, &nbargs);
|
||||
if (idx < 0)
|
||||
{
|
||||
fprintf(stderr, "tga_fractales: mot-clef %s inconnu...\n", argv[1]);
|
||||
exit(5);
|
||||
}
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "code commande %d\n", commande);
|
||||
#endif
|
||||
|
||||
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PAR);
|
||||
|
||||
dst = NULL; /* gcc warning STFU */
|
||||
|
||||
switch (commande)
|
||||
{
|
||||
case MANDEL0:
|
||||
width = GIP(0); height = GIP(1);
|
||||
printf("mandelbrot 0: %dx%d\n", width, height);
|
||||
dst = Image_alloc(width, height, 3);
|
||||
foo = Image_Mandelbrot_0(dst, 300);
|
||||
Image_print_error("mandelbrot 0", foo);
|
||||
break;
|
||||
case JULIA00:
|
||||
width = GIP(0); height = GIP(1);
|
||||
foo = Image_load_color_Map("volcano.map", "plop", &map);
|
||||
Image_print_error("julia00: loadmap", foo);
|
||||
dst = Image_alloc(width, height, 3);
|
||||
Image_Julia_0_0(dst, &map, 3000, 0.333, 0.333);
|
||||
Image_print_error("julia00: calcul", foo);
|
||||
break;
|
||||
case GINGER:
|
||||
width = GIP(0); height = GIP(1);
|
||||
printf("ginger bread man: %dx%d\n", width, height);
|
||||
dst = Image_alloc(width, height, 3);
|
||||
foo = GingerBreadMan(dst, 300);
|
||||
Image_print_error("GingerBreadMan", foo);
|
||||
break;
|
||||
case NEWTON0:
|
||||
width = GIP(0); height = GIP(1);
|
||||
printf("newton 0: %dx%d\n", width, height);
|
||||
dst = Image_alloc(width, height, 3);
|
||||
foo = Newton_0(dst, 42);
|
||||
Image_print_error("proto Newton 0", foo);
|
||||
break;
|
||||
case LORENZ0:
|
||||
width = GIP(0); height = GIP(1);
|
||||
printf("lorenz 0: %dx%d\n", width, height);
|
||||
dst = Image_alloc(width, height, 3);
|
||||
foo = Lorenz_Orbits(dst, 3000, 5.0, 15.0, 1.0, 0.02);
|
||||
Image_print_error("lorenz 0", foo);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Cette fractale n'est pas disponible.\n");
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
foo = Image_TGA_save(argv[2], dst, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
61
Tools/tga_plothisto.c
Normal file
61
Tools/tga_plothisto.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
utilitaire pour plotter les histogrammes d'une image.
|
||||
-----------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tga_outils.h"
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "*** tga_plothisto v 0.1.3 [%s] %s\n",
|
||||
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
|
||||
fprintf(stderr, "\nusage: tga_plothisto image.tga histo.tga [texte]\n\n");
|
||||
Image_print_version(0);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
Image_Desc *src;
|
||||
long hr[256], hg[256], hb[256];
|
||||
int foo;
|
||||
char *texte;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
/*fprintf(stderr, "argc = %d\n", argc);*/
|
||||
usage();
|
||||
}
|
||||
|
||||
if ( (src=Image_TGA_alloc_load(argv[1])) == NULL )
|
||||
{
|
||||
fprintf(stderr, "tga_plothisto, chargement '%s' failed\n", argv[1]);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
foo = Image_histo_RGB(src, hr, hb, hg);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_plothisto, calcul histogramme: %d %s\n",
|
||||
foo, Image_err2str(foo));
|
||||
exit(5);
|
||||
}
|
||||
|
||||
if (argc == 3) texte = argv[1];
|
||||
else texte = argv[3];
|
||||
|
||||
foo = Image_plot_histo(argv[2], hr, hg, hb, texte);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_plothisto, dessin de '%s': %d %s\n",
|
||||
argv[2], foo, Image_err2str(foo));
|
||||
exit(5);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
64
Tools/tga_plotmap.c
Normal file
64
Tools/tga_plotmap.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
----------------------------------------------
|
||||
utilitaire pour tracer une map 'a la fractint'
|
||||
----------------------------------------------
|
||||
http://tth.zouh.org/libimage.html
|
||||
----------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tga_outils.h"
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "* tga_plotmap v 0.1.11 [%s] %s\n",
|
||||
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
|
||||
fprintf(stderr, "usage:\n\ttga_plotmap colors.map graphe.tga [texte]\n\n");
|
||||
Image_print_version(1);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
#define CLASSIC 1
|
||||
#define PAPER 2
|
||||
#define SQUARE 3
|
||||
|
||||
mot_clef mots_clef[] =
|
||||
{
|
||||
{ "classic", CLASSIC, "", "classic" },
|
||||
{ "paper", PAPER, "", "papier" },
|
||||
{ "square", SQUARE, "", "square" },
|
||||
{ NULL, 0, "", NULL }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
RGB_map map;
|
||||
int foo;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
|
||||
if ((argc!=3)&&(argc!=4)) usage();
|
||||
|
||||
foo = Image_load_color_Map(argv[1], "tga_plotmap", &map);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_plotmap, chargement '%s': %d %s\n",
|
||||
argv[1], foo, Image_err2str(foo));
|
||||
exit(5);
|
||||
}
|
||||
|
||||
fprintf(stderr, "map file %s have %d colors\n", argv[1], map.nbre);
|
||||
|
||||
foo = Image_plot_Map(argv[2], &map, argc==4?argv[3]:argv[1]);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "tga_plotmap, dessin de '%s': %d %s\n",
|
||||
argv[2], foo, Image_err2str(foo));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
145
Tools/tga_resize.c
Normal file
145
Tools/tga_resize.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
...............................
|
||||
.redimensionnement d'une image.
|
||||
...............................
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "tga_outils.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
#define HALF_SIZE 1
|
||||
#define DOUBLE_SIZE 2
|
||||
#define PERCENT 3
|
||||
#define NEWSIZE 4
|
||||
|
||||
mot_clef mots_clef[] =
|
||||
{
|
||||
{ "half", HALF_SIZE, "f", "0:crude 1:interpolate" },
|
||||
{ "double", DOUBLE_SIZE, "f", "" },
|
||||
{ "percent", PERCENT, "dii", "%%size, method, 0" },
|
||||
{ "newsize", NEWSIZE, "iii", "newW newH method" }
|
||||
};
|
||||
/*::------------------------------------------------------------------::*/
|
||||
void usage(int flag)
|
||||
{
|
||||
fprintf(stderr, "* Tga Resize v 0.0.13 [%s] %s\n",
|
||||
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
|
||||
|
||||
fprintf(stderr, "usage:\n");
|
||||
fprintf(stderr, "\ttga_resize source.tga methode resultat.tga [params]\n");
|
||||
if (flag)
|
||||
liste_mots_clefs(mots_clef, 42);
|
||||
else
|
||||
Image_print_version(0);
|
||||
exit(5);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* argv[1] source.tga
|
||||
* argv[2] méthode
|
||||
* argv[3] destination.tga
|
||||
*/
|
||||
#define FIRST_PARAM 4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Image_Desc *src, *dst;
|
||||
int foo, idx;
|
||||
int commande, nbargs, interpol;
|
||||
double scale, scaleX, scaleY;
|
||||
int newW, newH;
|
||||
|
||||
dump_command_line(argc, argv, 0);
|
||||
|
||||
if ( argc==2 && !strcmp(argv[1], "list") ) usage(1);
|
||||
if ( argc < 4) usage(0);
|
||||
|
||||
/*
|
||||
* rechercher le mot clef dans la table
|
||||
*/
|
||||
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
|
||||
if (idx < 0)
|
||||
{
|
||||
fprintf(stderr, "keyword %s unknow\n", argv[1]);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
/*
|
||||
* décodage des paramètres
|
||||
*/
|
||||
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "tga_resize: ret parse parameters = %d\n", foo);
|
||||
#endif
|
||||
|
||||
if ((src = Image_TGA_alloc_load(argv[1]))==NULL)
|
||||
{
|
||||
fprintf(stderr, "tga_resize: can't load '%s'\n", argv[1]);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
dst = NULL; /* secure the default case */
|
||||
|
||||
switch (commande)
|
||||
{
|
||||
case HALF_SIZE:
|
||||
if ( (dst=Image_MakeHalfSize(src, GFP(0))) == NULL)
|
||||
{
|
||||
fprintf(stderr, "tga_resize: half: fatal error\n");
|
||||
exit(1);
|
||||
}
|
||||
foo = 0;
|
||||
break;
|
||||
|
||||
case DOUBLE_SIZE:
|
||||
if ( (dst=Image_MakeDoubleSize(src, GFP(0))) == NULL)
|
||||
{
|
||||
fprintf(stderr, "tga_resize: double: fatal error\n");
|
||||
exit(1);
|
||||
}
|
||||
foo = 0;
|
||||
break;
|
||||
|
||||
case PERCENT:
|
||||
scale = GDP(0) / 100.0;
|
||||
interpol = GIP(1);
|
||||
#if DEBUG_LEVEL
|
||||
printf(" scale = %f\n", scale);
|
||||
printf(" interpol = %d\n", interpol);
|
||||
#endif
|
||||
if ((dst = Image_new_scale(src, scale, scale, interpol))==NULL)
|
||||
{
|
||||
fprintf(stderr, "tga_resize: percent: fatal error\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case NEWSIZE:
|
||||
newW = GIP(0);
|
||||
newH = GIP(1);
|
||||
printf("new size: %d x %d\n", newW, newH);
|
||||
scaleX = ((double)newW / (double)src->width);
|
||||
scaleY = ((double)newH / (double)src->height);
|
||||
printf("scales: X %f y %f\n", scaleX, scaleY);
|
||||
|
||||
if ((dst = Image_new_scale(src, scaleX, scaleY, GIP(2)))==NULL)
|
||||
{
|
||||
fprintf(stderr, "tga_resize: newsize: fatal error\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* sauvons vite ce precieux resultat
|
||||
*/
|
||||
if (dst != NULL)
|
||||
foo = Image_TGA_save(argv[3], dst, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
Loading…
Reference in New Issue
Block a user