Compare commits

..

17 Commits

Author SHA1 Message Date
tTh
58b8fa878c add new ugly tools 2024-11-17 10:44:07 +01:00
tTh
d298f63e7e add 2 missing tools 2024-11-15 17:47:09 +01:00
tTh
0b8cf14126 add missing binaries 2024-11-15 16:45:52 +01:00
tTh
b3da0e6ec0 cosmetic 2024-11-15 11:35:39 +01:00
tTh
97ad716bd2 little work on documentation 2024-11-14 10:11:11 +01:00
tTh
ae54fb932a + Test_Classif 2024-08-16 18:13:36 +02:00
tTh
5418e01820 cosmetic 2024-08-16 13:30:19 +02:00
tTh
24b3d4de11 tweaking... 2024-08-16 13:10:58 +02:00
tTh
5ffc94c17d more blabla 2024-08-16 13:09:18 +02:00
tTh
6fddb97ee4 re-enable tga_info 2024-08-16 13:06:51 +02:00
tTh
725ccf3c87 tweaking the speedtest 2024-08-16 03:22:55 +02:00
tTh
f4c3825186 nice fail, bro 2024-08-15 20:40:01 +02:00
tTh
d6877097d0 + rgb decomp 2024-08-15 15:18:10 +02:00
tTh
8c30ea844f add warning 2024-08-15 14:18:47 +02:00
tTh
82a7050d07 public version of crazy benchmarking 2024-08-15 13:43:12 +02:00
tTh
1b442ece82 add patterns files 2024-08-15 13:39:00 +02:00
tTh
1750225cf9 enable optimize 2024-08-15 13:36:35 +02:00
29 changed files with 1187 additions and 150 deletions

View File

@@ -3,3 +3,14 @@
But du jeu : traiter la séquence d'image complète d'une vidéo live,
sans devoir attendre 107 ans que le job soit fait.
## Current status
- [rgb_decomp.c](rgb_decomp.c)
## Film at 11.
See you soon.

87
Contribs/rgb_decomp.c Normal file
View File

@@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <tthimage.h>
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
int rgb_process_by_filename(char *inf, char *outf)
{
Image_Desc *src, *dst;
int foo;
int x, y, larg, offs;
int r, g, b;
if ( (src=Image_TGA_alloc_load(inf)) == NULL )
{
fprintf(stderr, "%s: err load %s\n", __func__, inf);
exit(5);
}
printf("source '%s' %dx%d\n", inf, src->width, src->height);
if ( (dst=Image_clone(src, 0)) == NULL )
{
fprintf(stderr, "%s: no mem for image cloning\n", __func__);
exit(5);
}
Image_clear(dst, 160, 60, 60);
/*
* calcul de la zone à traiter
*/
larg = src->width / 3;
offs = (src->width - larg) / 2;
printf("largeur %d offset %d\n", larg, offs);
for (y=0; y<src->height; y++) {
for (x=0; x<larg; x++) {
Image_getRGB(src, x+offs, y, &r, &g, &b);
Image_plotRGB(dst, x, y, r, r, r);
Image_plotRGB(dst, x+offs, y, g, g, g);
Image_plotRGB(dst, x+(2*offs), y, b, b, b);
}
}
Image_egalise_cos010(dst, dst, 0);
foo = Image_TGA_save(outf, dst, 0);
if (foo) {
fprintf(stderr, "%s: error %d saving %s\n", __func__, foo, outf);
exit(5);
}
return 0;
}
/* -------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
if (3 != argc)
{
exit(1);
}
foo = rgb_process_by_filename(argv[1], argv[2]);
if (foo) {
fprintf(stderr, "process by filename -> %d\n", foo);
}
return 0;
}
/* -------------------------------------------------------- */

View File

@@ -1,4 +1,4 @@
# libtthimage
# libtthimage, la doc
Les fichiers [HTML](html/) que vous avez ici sont des versions historiques,
qui seront peut-être mise à jour au prochain grand refactoring.
@@ -13,11 +13,11 @@ Certaines options de compilation sont dans le fichier de
[paramètres](../Paramakes.mk) pour les différents fichiers make.
Je vous conseille de vérifier leurs pertinences, et en particulier
les options `-p` et `-pg` que j'oublie parfois d'enlever avant
le _/push_.
le _push_.
Le script [build.sh](../build.sh) tente d'automatiser les
compilations de la bibilothèque, des tests et des outils
en ligne de commande.
en ligne de commande. Il est encore loin d'être parfait.
## Installation
@@ -28,4 +28,4 @@ dans le fichier Paramakes.mk !
## Utilisation
???
??? *Insérez ici quelques exemples d'utilisation des tools.*

4
Lib/.gitignore vendored
View File

@@ -1,4 +1,6 @@
*.png
cflow.txt
*.gif
cflow.txt
reduce.map

View File

@@ -1,8 +1,9 @@
# The tTh image processing library
Ugly software born around 1995 on a MS-Dos 286 computer.
Look at the `Makefile` for no more explanations.
Look at the [`Makefile`](Makefile) for no more explanations.
More pertinent informations can be found in
[`tthimage.h`](../tthimage.h).
## Text primitives

View File

@@ -51,13 +51,13 @@ static int compare_teinte(struct elem *p1, struct elem *p2)
{
int r1, g1, b1, r2, b2, g2;
r1 = (( (p1->rgb) >>8)&0xf)<<4;
g1 = (( (p1->rgb) >>4)&0xf)<<4;
b1 = ( (p1->rgb) &0xf)<<4;
r1 = (( (p1->rgb) >>8)&0xf) <<4;
g1 = (( (p1->rgb) >>4)&0xf) <<4;
b1 = ( (p1->rgb) &0xf) <<4;
r2 = (( (p2->rgb) >>8)&0xf)<<4;
g2 = (( (p2->rgb) >>4)&0xf)<<4;
b2 = ( (p2->rgb) &0xf)<<4;
r2 = (( (p2->rgb) >>8)&0xf) <<4;
g2 = (( (p2->rgb) >>4)&0xf) <<4;
b2 = ( (p2->rgb) &0xf) <<4;
/* printf("%8d %8d\n", p1->compte, p2->compte);
return (p1->rgb - p2->rgb); */
@@ -66,7 +66,9 @@ return ( (r1+g1+b1) - (r2+g2+b2) );
}
/*::------------------------------------------------------------------::*/
/*
* XXX please explain parameters usage !
*/
#define TAILLE (1<<12)
int Image_calc_Map_4bits(Image_Desc *img, RGB_map *map, int nbre)
{
@@ -80,13 +82,13 @@ fprintf(stderr, " Calc map 4 bits: nbre = %d\n", nbre);
#endif
if ( (nbre<1) || (nbre>255) ) {
fprintf(stderr, "Calc map 4 bits: nbre %d out of range\n", nbre);
fprintf(stderr, "%s: nbre %d out of range\n", __func__, nbre);
return BAD_COLOR_NUMBER;
}
surface = img->width * img->height;
#if DEBUG_LEVEL
fprintf(stderr, " calc Map 4 bits: surface de l'image = %ld pixels\n", surface);
fprintf(stderr, "%s: surface de l'image = %ld pixels\n", __func__, surface);
#endif
for (x=0; x<TAILLE; x++) {
@@ -112,7 +114,7 @@ for (x=0; x<img->width; x++) {
}
}
#if DEBUG_LEVEL
fprintf(stderr, " Map4bits: compte maximum = %ld\n", maxi);
fprintf(stderr, "%s: compte maximum = %ld\n", __func__, maxi);
#endif
/*
@@ -123,7 +125,7 @@ qsort(elems, TAILLE, sizeof(struct elem), compare_compteur);
/*
* trier la palette, certe, mais dans quel ordre ?
* 28 Jan 2002: why ?
* 28 Jan 2002: why ?
*/
qsort(elems, nbre, sizeof(struct elem), compare_teinte);

View File

@@ -8,6 +8,8 @@
#include "../tthimage.h"
#define DEBUG_LEVEL 1
/*::------------------------------------------------------------------::*/
/*
* ATTENTION: cette fonction sert à faire des essais, et ne doit
@@ -16,8 +18,7 @@
*
* n is the number of wanted colors
*/
int
Image_essai_col_reduce(Image_Desc *src, Image_Desc *dst, int n, int t)
int Image_essai_col_reduce(Image_Desc *src, Image_Desc *dst, int n, int t)
{
RGB_map map;
int foo;

View File

@@ -216,18 +216,17 @@ if (NULL==(src=Image_TGA_alloc_load(srcname))) {
}
/* on va creer le receptacle des horreurs */
if (NULL==(dst=Image_clone(src, 0))) {
fprintf(stderr, "%s: err clone\n", __func__);
exit(5);
}
/* ah bravo ! enfin un test unitaire appelable
* depuis le test unitaire */
for (idx=0; idx<20; idx++)
{
for (idx=0; idx<20; idx++) {
foo = Image_essai_col_reduce(src, dst, 133, idx);
printf("le retour de l'essai_col_reduce %d est %d\n", idx, foo);
if (OLL_KORRECT==foo)
{
sprintf(fname, "Pictures/aaaa-colredux-%02d.tga", idx);
if (OLL_KORRECT==foo) {
sprintf(fname, "aaaa-colredux-%02d.tga", idx);
Image_TGA_save(fname, dst, 0);
}
}
@@ -582,32 +581,30 @@ int foo, ax, ay;
printf("====== essais Warping sur %s (k=%d) ====\n", srcname, k);
if (NULL == (src = Image_TGA_alloc_load(srcname)) )
{
if (NULL == (src = Image_TGA_alloc_load(srcname)) ) {
fprintf(stderr, "Err loading '%s'\n", srcname);
exit(5);
}
dst = Image_clone(src, 0);
foo = Image_warp_essai_0(src, dst, 33.5, 100, 100);
Image_TGA_save("Pictures/warp-essai-0.tga", dst, 0);
Image_TGA_save("warp-essai-0.tga", dst, 0);
foo = Image_center_rotate(src, dst, 21.5);
Image_TGA_save("Pictures/warp-center-rotate.tga", dst, 0);
Image_TGA_save("warp-center-rotate.tga", dst, 0);
ax = (src->width * 2) / 3;
ay = (src->height * 2) / 3;
foo = Image_shift_xy(src, dst, ax, ay);
Image_TGA_save("Pictures/warp-shift-xy.tga", dst, 0);
Image_TGA_save("warp-shift-xy.tga", dst, 0);
foo = Image_shift_x(src, dst, ax);
Image_TGA_save("Pictures/warp-shift-x.tga", dst, 0);
Image_TGA_save("warp-shift-x.tga", dst, 0);
foo = Image_shift_y(src, dst, ay);
Image_TGA_save("Pictures/warp-shift-y.tga", dst, 0);
Image_TGA_save("warp-shift-y.tga", dst, 0);
Image_DeAllocate(src); free(src);
Image_DeAllocate(dst); free(dst);
return 42;
}
/*::------------------------------------------------------------------::*/
@@ -795,7 +792,7 @@ Image_DeAllocate(dst); free(dst);
return 42;
}
/*::------------------------------------------------------------------::*/
int Test_classif(char *srcname, int k)
int Test_Classif(char *srcname, int k)
{
Image_Desc *src, *dst;
int foo;
@@ -812,8 +809,7 @@ static Une_Classe_Sph classs[] =
{ 0, 255, 0, DC, 0, 255, 0 }
};
if (NULL == (src = Image_TGA_alloc_load(srcname)) )
{
if (NULL == (src = Image_TGA_alloc_load(srcname)) ) {
fprintf(stderr, "Err loading '%s'\n", srcname);
exit(5);
}
@@ -821,11 +817,11 @@ dst = Image_clone(src, 0);
foo = Image_classif_0(src, dst);
Image_print_error("essai classif 0", foo);
Image_TGA_save("Pictures/aaaa-classif0.tga", dst, 0);
Image_TGA_save("aaaa-classif0.tga", dst, 0);
foo = Image_classif_1(src, dst, classs, 5, 0);
Image_print_error("essai classif 1", foo);
Image_TGA_save("Pictures/aaaa-classif1.tga", dst, 0);
Image_TGA_save("aaaa-classif1.tga", dst, 0);
Image_DeAllocate(src); free(src);
Image_DeAllocate(dst); free(dst);
@@ -1159,7 +1155,7 @@ Image_dump_descriptor(source, "just after load");
* est-ce bien necessaire ?
*/
/* Image_egalise_RGB(source, source, 0); */
wf = source->width; hf = (source->height) * 4;
wf = source->width; hf = (source->height) * 3;
x2 = source->width / 2; y2 = source->height / 2;
rect.w = x2; rect.h = y2;
rect.x = 0; rect.y = 0;
@@ -1353,8 +1349,7 @@ Image_DeAllocate(finale); free(finale);
return 42;
}
/*::------------------------------------------------------------------::*/
int
Test_des_tamppools(char *imgname, int param)
int Test_des_tamppools(char *imgname, int param)
{
void *ptr;
int foo;
@@ -1377,7 +1372,7 @@ int Test_des_filtres(char *srcname, int k)
Image_Desc *src, *dst;
int foo;
printf("=============== LES FILTRES =====[ %s ]====[ %d ]====\n", srcname, k);
printf("=============== Filtres =====[ %s ]====[ %d ]====\n", srcname, k);
src = Image_TGA_alloc_load(srcname);
if (NULL == src) {
@@ -1397,8 +1392,11 @@ foo = Image_filtre_Prewitt(src, dst, 5);
Image_TGA_save("filtre-prewitt-5.tga", dst, 0);
foo = Image_filtre_passe_haut(src, dst);
Image_TGA_save("filtre-passe-haut.tga", dst, 0);
/*
foo = Image_filtre_Sobel_4(src, dst, 0);
Image_TGA_save("filtre-sobel-4.tga", dst, 0);
*/
Image_DeAllocate(src); free(src);
Image_DeAllocate(dst); free(dst);
@@ -1494,3 +1492,17 @@ Image_DeAllocate(dst); free(dst);
return -1;
}
/*::------------------------------------------------------------------::*/
/* ============================== */
void essai_gradients(void)
{
int foo;
foo = Image_plot_H_gradient("foo.tga", 640, 200);
fprintf(stderr, "plot h gradient -> %d\n", foo);
foo = Image_plot_V_gradient("foo.tga", 900, 200);
fprintf(stderr, "plot v gradient -> %d\n", foo);
}
/* ============================== */
/*::------------------------------------------------------------------::*/

View File

@@ -27,6 +27,8 @@ int Essai_des_lut15bits(char *srcname, int k);
int Essai_des_mires(char *, int, int);
int Essai_des_zooms(char *srcname, int k);
int Test_Classif(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);

View File

@@ -15,39 +15,62 @@
* ix, iy: coordinate of the pixel in this pic.
* op, ox, oy : same things for output picture
*/
#define PIXEL_COPY(ip, ix, iy, op, ox, oy) \
do { \
\
#define PIXEL_COPY(ip, ix, iy, op, ox, oy) \
do { \
(op->Rpix[oy])[ox] = (ip->Rpix[iy])[ix]; \
(op->Gpix[oy])[ox] = (ip->Gpix[iy])[ix]; \
(op->Bpix[oy])[ox] = (ip->Bpix[iy])[ix]; \
} while (0)
#define SZPIC 7777
#define SZPIC 4096
double tthi_dtime(void);
void essai_pixcopy(void)
void essai_pixcopy(int usemacro)
{
Image_Desc *alice, *bob;
int x, y;
double T0, T1;
int x, y, foo;
double T0, T1, perpix;
long count;
char *fname;
alice = Image_alloc(SZPIC, SZPIC, IMAGE_RGB);
bob = Image_alloc(SZPIC, SZPIC, IMAGE_RGB);
Image_pattern_000(alice, 0);
Image_TGA_save("alice.tga", alice, 0);
T0 = tthi_dtime();
count = 0L;
for (y=0; y<SZPIC; y++) {
for (x=0; x<SZPIC; x++) {
Image_pixel_copy(alice, x, y, bob, x, y);
count++;
if (usemacro) {
for (y=0; y<SZPIC; y++) {
for (x=0; x<SZPIC; x++) {
PIXEL_COPY(alice, x, y, bob, x, y);
count++;
}
}
fname = "bob1.tga";
}
else {
for (y=0; y<SZPIC; y++) {
for (x=0; x<SZPIC; x++) {
Image_pixel_copy(alice, x, y, bob, x, y);
count++;
}
}
fname = "bob0.tga";
}
T1 = tthi_dtime();
fprintf(stderr, "count %ld, elapsed %g\n", count, T1-T0);
foo = Image_TGA_save(fname, bob, 0);
if (foo) {
fprintf(stderr, "%s: save -> %d\n", __func__, foo);
}
perpix = ((T1-T0) / (double)count) * 1e6;
fprintf(stderr, "%s : %10ld pixels, elapsed %9.6f seconds ==> %9.6f µs/pix\n",
usemacro ? "macro" : "func ",
count, T1-T0, perpix);
/* end */
}
@@ -56,8 +79,9 @@ fprintf(stderr, "count %ld, elapsed %g\n", count, T1-T0);
int main(int argc, char *argv[])
{
int i;
fprintf(stderr, "*** %s is running\n", argv[0]);
fprintf(stderr, "*********** %s ************\n", argv[0]);
if (argc > 1) {
fprintf(stderr, "argument: %s\n", argv[1]);
@@ -65,7 +89,10 @@ if (argc > 1) {
Image_print_sizeof_structs("foo");
}
else {
essai_pixcopy();
for (i=0; i<5; i++) {
essai_pixcopy(0);
essai_pixcopy(1);
}
}
/*

View File

@@ -93,8 +93,7 @@ return 0;
* on the structure who describe the image.
* - - - > don't "free" this pointer, please.
*/
Image_Desc *
Image_alloc(int width, int height, int type)
Image_Desc * Image_alloc(int width, int height, int type)
{
Image_Desc *header;
int foo;
@@ -192,19 +191,18 @@ return header;
/*
This fonction build another image from a model.
*/
Image_Desc *
Image_clone (Image_Desc *src, int copy)
Image_Desc * Image_clone (Image_Desc *src, int copy)
{
Image_Desc *image;
if ( src==NULL )
if ( NULL == src )
{
fprintf(stderr, "Image_clone: source descriptor is NULL\n");
exit(5);
}
image = Image_alloc(src->width, src->height, src->type);
if ( image==NULL )
if ( NULL == image )
{
fprintf(stderr, "Image_clone: cloned descriptor is NULL\n");
exit(5);
@@ -246,20 +244,16 @@ return FUNC_IS_ALPHA;
* Helas, cette fonction ne marche que sur les images RGB
* et comment la rendre compatible tout-types sans tout casser ?
*/
int
Image_clear( Image_Desc *image, int r, int g, int b )
int Image_clear( Image_Desc *image, int r, int g, int b )
{
int x, y;
if (image->type == IMAGE_RGB)
{
for (y=0; y<image->height; y++)
{
if (image->type == IMAGE_RGB) {
for (y=0; y<image->height; y++) {
/*
* XXX here we can go faster with a few memset
*/
for (x=0; x<image->width; x++)
{
for (x=0; x<image->width; x++) {
(image->Rpix[y])[x] = r;
(image->Gpix[y])[x] = g;
(image->Bpix[y])[x] = b;
@@ -269,12 +263,9 @@ if (image->type == IMAGE_RGB)
return 0; /* ok, this 'return' here is a "spleyterie" :) */
}
if (image->type == IMAGE_RGBA)
{
for (y=0; y<image->height; y++)
{
for (x=0; x<image->width; x++)
{
if (image->type == IMAGE_RGBA) {
for (y=0; y<image->height; y++) {
for (x=0; x<image->width; x++) {
(image->Rpix[y])[x] = r;
(image->Gpix[y])[x] = g;
(image->Bpix[y])[x] = b;
@@ -309,6 +300,7 @@ if (IMAGE_RGB != img->type) {
for (y=0; y<img->height; y++) {
for (x=0; x<img->width; x++) {
/* please, use memset here */
(img->Rpix[y])[x] = rgba->r;
(img->Gpix[y])[x] = rgba->g;
(img->Bpix[y])[x] = rgba->b;
@@ -321,8 +313,7 @@ return FUNC_IS_BETA;
* every image in memory have a comment field, who is writen
* in TGA and PNM file when image is saved.
*/
int
Image_set_comment(Image_Desc *image, char *text)
int Image_set_comment(Image_Desc *image, char *text)
{
if (strlen(text) > IMG_OBJCOMMENT_LEN)
return STRING_TOO_LONG;
@@ -331,8 +322,7 @@ return OLL_KORRECT;
}
/* 10 nov 2001: no #define for this not-so-magic 254 value ? */
/*::------------------------------------------------------------------::*/
int
Image_plot_gray(Image_Desc *img, int x, int y, int v)
int Image_plot_gray(Image_Desc *img, int x, int y, int v)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
@@ -352,8 +342,7 @@ int Image_plotRGB(Image_Desc *img, int x, int y, int r, int g, int b)
fprintf(stderr, "PLOTRGB %d %d\n", x, y);
#endif
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "Errplot RGB X=%d, Y=%d %d, %d, %d\n", x, y, r, g, b);
#if FORCE_ABORT
abort();
@@ -368,8 +357,7 @@ return OLL_KORRECT;
int Image_plotRGBA(Image_Desc *img, int x, int y, int r, int g, int b, int a)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
/* may be an #if DEBUG_LEVEL here ? */
fprintf(stderr, "Errplot RGBA X %4d Y %4d %d, %d, %d, %d\n",
x, y, r, g, b, a);
@@ -387,11 +375,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
int
Image_getRGB(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb)
int Image_getRGB(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
/* may be an #if DEBUG_LEVEL here ? */
fprintf(stderr, "ERR GETRGB X %4d Y %4d\n", x, y);
#if FORCE_ABORT
@@ -407,11 +393,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
int
Image_getRGBA(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb, int *pa)
int Image_getRGBA(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb, int *pa)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "ERR GETRGBA X %4d Y %4d\n", x, y);
#if FORCE_ABORT
abort();
@@ -419,10 +403,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
return OUT_OF_IMAGE;
}
if (img->type != IMAGE_RGBA)
{
fprintf(stderr, "Image get RGBA: bad image type: %d, %s\n",
img->type, Image_type2str(img->type));
if (img->type != IMAGE_RGBA) {
fprintf(stderr, "%s: bad image type: %d, %s\n",
__func__, img->type, Image_type2str(img->type));
#if FORCE_ABORT
abort();
#endif
@@ -443,16 +426,14 @@ return OLL_KORRECT;
*/
int Image_plot_channel(Image_Desc *img, char channel, int x, int y, int value)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
#if DEBUG_LEVEL
fprintf(stderr, "ERR PLOTCHANNEL X %4d Y %4d\n", x, y);
#endif
return OUT_OF_IMAGE;
}
switch (channel)
{
switch (channel) {
case 'r': case 'R': (img->Rpix[y])[x] = (uint8_t)(value&0xff); break;
case 'g': case 'G': (img->Gpix[y])[x] = (uint8_t)(value&0xff); break;
case 'b': case 'B': (img->Bpix[y])[x] = (uint8_t)(value&0xff); break;
@@ -466,44 +447,36 @@ return OLL_KORRECT;
/*
lecture d'une des composantes de l'image.
*/
int
Image_R_pixel(Image_Desc *img, int x, int y)
int Image_R_pixel(Image_Desc *img, int x, int y)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "ERR READ R PIX X%d Y%d\n", x, y);
return OUT_OF_IMAGE;
}
return (int)((img->Rpix[y])[x]);
}
int
Image_G_pixel(Image_Desc *img, int x, int y)
int Image_G_pixel(Image_Desc *img, int x, int y)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "ERR READ G PIX X%d Y%d\n", x, y);
return OUT_OF_IMAGE;
}
return (int)((img->Gpix[y])[x]);
}
int
Image_B_pixel(Image_Desc *img, int x, int y)
int Image_B_pixel(Image_Desc *img, int x, int y)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "ERR READ B PIX X%d Y%d\n", x, y);
return OUT_OF_IMAGE;
}
return (int)((img->Bpix[y])[x]);
}
int
Image_A_pixel(Image_Desc *img, int x, int y)
int Image_A_pixel(Image_Desc *img, int x, int y)
{
if ( x<0 || y<0 || x>=img->width || y>=img->height )
{
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
fprintf(stderr, "ERR A PIX X%d Y%d\n", x, y);
return OUT_OF_IMAGE;
}
@@ -545,7 +518,7 @@ return 0;
}
/*::------------------------------------------------------------------::*/
/*
* no boundary control ?
* no boundary control ? XXX
*/
int Image_pixel_copy(Image_Desc *s, int x, int y, Image_Desc *d, int i, int j)
{
@@ -563,18 +536,16 @@ return OLL_KORRECT;
*/
int Image_compare_desc(Image_Desc *a, Image_Desc *b)
{
char *fmt = "Image at %p have no 'Dead Beef' in it\n";
char *fmt = "%s: Image at %p have no 'Dead Beef' in it\n";
if ( (a==NULL) || (b==NULL) ) return NULL_DESCRIPTOR;
if ( a->magic != MAGIC_OF_IMAGE )
{
fprintf(stderr, fmt, a);
if ( a->magic != MAGIC_OF_IMAGE ) {
fprintf(stderr, fmt, __func__, a);
return NOT_AN_IMAGE_DESC;
}
if ( b->magic != MAGIC_OF_IMAGE )
{
fprintf(stderr, fmt, a);
if ( b->magic != MAGIC_OF_IMAGE ) {
fprintf(stderr, fmt, __func__, a);
return NOT_AN_IMAGE_DESC;
}
@@ -592,8 +563,7 @@ return OLL_KORRECT;
c'est qu'il reste un pointeur fou chez
l'appelant ...
*/
int
Image_DeAllocate(Image_Desc *im)
int Image_DeAllocate(Image_Desc *im)
{
int line;

View File

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

View File

@@ -53,7 +53,7 @@ else
Image_start_chrono("Essai", 0);
for (idx=0; idx<1; idx++) {
for (idx=0; idx<10; idx++) {
foo = Test_Egalisations(fichier, 0);
fprintf(stderr, " essai egalisation -> %d\n", foo);
foo = Essai_Televisions(fichier, 10);
@@ -64,17 +64,24 @@ for (idx=0; idx<1; idx++) {
fprintf(stderr, " essai filtres -> %d\n", foo);
foo = Test_RGBmask(fichier);
fprintf(stderr, " essai rgb mask -> %d\n", foo);
foo = Test_Classif(fichier, 0);
fprintf(stderr, " essai classif -> %d\n", foo);
foo = Test_des_warpings(fichier, 0);
fprintf(stderr, " essai warping -> %d\n", foo);
foo = Essai_color_2_map(fichier, idx);
fprintf(stderr, " essai col2map -> %d\n", foo);
fprintf(stderr, "********* %s: fin passe %d\n", argv[0], idx);
fprintf(stderr, "\n*************** %s: fin passe %d ******\n\n",
argv[0], idx);
}
#if 0
foo = test_du_jpeg_reader("in.jpeg");
fprintf(stderr, " essai lecture jpeg -> %d\n", foo);
foo = Test_Dithering(fichier, 17);
fprintf(stderr, "essai dithering -> %d\n", foo);
Test_des_patterns("/tmp/pattt", 0, 0);
foo = Essai_des_jauges(fichier, 17);

View File

@@ -28,6 +28,9 @@ printf("%c\r", batons[foo&0x03]); fflush(stdout);
/*::------------------------------------------------------------------::*/
/*
* I think that the 'chrono' system is full broken
*
* You have to look at 'functions.c' for more timing functions.
*
*/
#define NB_CHRONOS 42

View File

@@ -3,7 +3,8 @@
set -e
SRC="testtga.c essais.c operat.c image.c effects.c tele_2.c calculs.c"
SRC="$SRC dither.c television.c"
SRC="$SRC dither.c television.c rgbmask.c sobel4.c tga.c patterns*.c"
echo $SRC ; echo
FLOW="cflow.txt"

View File

@@ -14,12 +14,13 @@ HTML_DIR=$(DESTDIR)/html
# pour tracer plein de trucs: -DDEBUG_LEVEL=1
# if IMGCOMMENT, the image comment is written to the TGA file,
# but this files can't be loaded by Xv...
#
# pour coredumper dans les situations graves: -DABORT=1
#
# use -Wmissing-prototypes ?
LIBIMG_OPT=-DFORCE_ABORT=0 -DDEBUG_LEVEL=0 -DIMGCOMMENT=0
CC_OPTS=-Wall -W -g -ansi -O0 -fPIC -no-pie
CC_OPTS=-Wall -W -g -ansi -O1 -fPIC -no-pie
CC_HACKS=-DNEED_ALLOCA_H
CFLAGS= $(CC_OPTS) \

View File

@@ -1,14 +1,20 @@
# Some useless tests
# Some useless tests ?
Tester, c'est douter.
<u>Tester, c'est douter.</u>
## État des lieux
Pas grand chose.
Pas grand chose pour le moment. Mais comme j'utilise régulièrement
et depuis très longtemps cet amas de fonctions, on peut dire que
les tests sont fait *in-vivo* sans formalisme formalisé.
Allez quand même voir `config.sh` et `functions.sh` pour avoir une idée
du désastre actuel. Il reste beaucoup de choses à faire.
## Mais encore ?
Dans le répertoire `Lib/` il y a un `essais.c` assez prometteur.
Dans le répertoire `Lib/` il y a un `essais.c` assez
[prometteur](../Lib/essais.c) et en constante évolution.
Il manque à son [driver](../Lib/testtga.c) une gestion plus
fluide de la sélection
des essais à faire tourner.

4
Tools/.gitignore vendored
View File

@@ -4,3 +4,7 @@
tga_extract
tga_to_text
tga_plothisto
tga_plotmap
tga_resize
tga_fractales

View File

@@ -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 $@
@@ -81,8 +98,8 @@ tga_extract: tga_extract.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
# tga_info: tga_info.c $(DEPS) fonctions.o
# gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_info: tga_info.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@
tga_pattern: tga_pattern.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@

View File

@@ -50,9 +50,9 @@ La gestion de la ligne de commande est désastreuse. **À REFAIRE**
## tga_cadre
Pas mal de façons de mettre un cadre sur l'image.
Niveau de kitchitude assez élevé.
Paramètres mal documentés.
Il existe pas mal de façons de mettre un cadre sur l'image,
avec un niveau de kitchitude assez élevé.
Les paramètres sont mal documentés.
## tga_combine
@@ -61,7 +61,8 @@ Usage:
tga_combine s1.tga s2.tga MODE d.tga [PARAMS]
```
Il existe plein de façon de combiner deux images, la commande
`testtga list` vous les fera découvrir, la cinquième va vous étonner.
`tga_combine list` vous les fera découvrir, la cinquième va vous étonner.
Les paramètres sont mal documentés.
## tga_dither
@@ -77,11 +78,16 @@ Attendu avec impatience, il aura le support complet des PNG. Un jour...
## tga_filtres
UTSL : [tga_filtres.c](caractère \textbf{invisible})
## tga_incrust
## tga_makehf15
Pour les POViste acharnés.
Pour les POViste acharnés. De façon étrange,
[Povray](https://povray.org/) a choisi de stocker des
champs d'altitude dans les images Targa, en n'utilisant que
15 bits pour la valeur.
## tga_to_text
@@ -102,6 +108,11 @@ vraiment trop nulle...
## tga_remap
Usage: `tga_remap M <src.tga> <color.map> <dst.tga>`
Le paramètre `M` peut prendre les valeurs 0, 1, 2, 11, 12 ou 13.
Je ne sais plus à quoi ça correspond.
## tga_television
## tga_tools

384
Tools/fractales.c Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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;
}
/*::------------------------------------------------------------------::*/

View File

@@ -15,7 +15,8 @@ cp -v Datas/*.map $DESTDIR/share/libimage/
liste="genplot2 tga_cadre tga_effects tga_filtres tga_remap tga_tools \
tga_combine tga_television tga_dither tga_applymap tga_makehf15 \
tga_mires tga_incrust tga_pattern tga_equalize tga_alpha \
tga_to_text"
tga_to_text tga_plotmap tga_resize tga_extract tga_2x2contrast \
tga_plothisto tga_export tga_fractales"
for binaire in $liste
do

View File

@@ -4,7 +4,7 @@
http://la.buvette.org/devel/libimage/
*/
#ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 85"
#define IMAGE_VERSION_STRING "0.4.51 pl 91"
/*::------------------------------------------------------------------::*/
/*
@@ -315,10 +315,15 @@ int Image_G_pixel(Image_Desc *img, int x, int y);
int Image_B_pixel(Image_Desc *img, int x, int y);
int Image_A_pixel(Image_Desc *img, int x, int y);
/* Mon Aug 12 2024 : this function may be rewrited with a macro ? */
int Image_pixel_copy(Image_Desc *s, int x, int y, Image_Desc *d, int i, int j);
int Image_compare_desc(Image_Desc *a, Image_Desc *b);
/*::------------------------------------------------------------------::*/
/* module functions.c */
double tthi_dtime(void);
/*::------------------------------------------------------------------::*/
/* module pixels.c */