libtthimage/Lib/recurse.c

144 lines
3.0 KiB
C
Raw Normal View History

2022-06-27 08:53:59 +02:00
/*
RECURSION 'QUADTREE' SUR LES IMAGES
-----------------------------------
*/
#include <stdio.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* bon, c'est qu'un essai, mais il me semble prometteur.
* ceci dit, <EFBFBD> l'epoque du Copam, il me semble que j'avais
* fait le meme genre de truc, mais en bien mieux...
*
*/
2024-07-20 12:01:12 +02:00
/* Private variables */
2022-06-27 08:53:59 +02:00
static Image_Desc *S, *D;
static int seuil;
static int level, maxlevel;
2022-09-17 11:23:21 +02:00
static int recursion(Image_Rect *pRect)
2022-06-27 08:53:59 +02:00
{
Image_Rect rect;
int h1, h2, w1, w2, xx, yy, foo;
int mr, mg, mb, dr, dg, db, s;
level++;
if (level > maxlevel)
maxlevel = level;
#if DEBUG_LEVEL > 1
fprintf(stderr, "%5d -> %3d %3d %3d %3d\n",
level, pRect->x, pRect->y, pRect->w, pRect->h);
#endif
foo = Image_stats_zone_0(S, pRect, &mr, &mg, &mb, &dr, &dg, &db);
s = (dr + dg + db) / 3;
#if DEBUG_LEVEL > 1
printf(" %7d V %3d %3d %3d D %3d %3d %3d S %3d (%d)\n",
pRect->w*pRect->h, mr, mg, mb, dr, dg, db, s, foo);
#endif
2022-09-17 11:23:21 +02:00
if ( (s < seuil) || (pRect->w < 6) || (pRect->h < 6) ) {
2022-06-27 08:53:59 +02:00
Image_paint_rect(D, pRect, mr, mg, mb);
/* printf(" paint %d %d %d\n", mr, mg, mb); */
}
2022-09-17 11:23:21 +02:00
else {
2022-06-27 08:53:59 +02:00
Image_paint_rect(D, pRect, 255, 0, 0);
/* Image_dump_rect(pRect, "R", 0); */
if ( pRect->h & 1 ) /* impair */
{
h1 = (pRect->h / 2) + 1;
h2 = (pRect->h / 2);
yy = (pRect->h / 2) + 1;
}
else /* pair */
{
h1 = (pRect->h / 2);
h2 = (pRect->h / 2);
yy = (pRect->h / 2);
}
if ( pRect->w & 1 ) /* impair */
{
w1 = (pRect->w / 2) + 1;
w2 = (pRect->w / 2);
xx = (pRect->w / 2) + 1;
}
else /* pair */
{
w1 = (pRect->w / 2);
w2 = (pRect->w / 2);
xx = (pRect->w / 2);
}
/*
printf(" w1 %3d w2 %3d \n", w1, w2);
printf(" h1 %3d h2 %3d \n", h1, h2);
printf(" xx %3d yy %3d \n", xx, yy);
printf("\n");
*/
rect.x = pRect->x; rect.y = pRect->y;
rect.w = w1; rect.h = h1;
recursion(&rect);
rect.x = pRect->x + xx; rect.y = pRect->y;
rect.w = w2; rect.h = h1;
recursion(&rect);
rect.x = pRect->x; rect.y = pRect->y + yy;
rect.w = w1; rect.h = h2;
recursion(&rect);
rect.x = pRect->x + xx; rect.y = pRect->y + yy;
rect.w = w2; rect.h = h2;
recursion(&rect);
}
level--;
return 0;
}
/*::------------------------------------------------------------------::*/
/*
2022-09-17 11:23:21 +02:00
* a quoi peut bien servir le parametre ?
2022-06-27 08:53:59 +02:00
*/
2022-09-17 11:23:21 +02:00
int Image_call_recursion_0(Image_Desc *image, Image_Desc *dest, int param)
2022-06-27 08:53:59 +02:00
{
Image_Rect rect;
int foo;
rect.x = rect.y = 0;
rect.h = image->height;
rect.w = image->width;
#if DEBUG_LEVEL
fprintf(stderr, "-> demarrage de la recursion\n");
#endif
S = image; D = dest;
seuil = param;
level = maxlevel = 0;
foo = recursion(&rect);
2022-09-21 00:06:11 +02:00
#if DEBUG_LEVEL
2022-06-27 08:53:59 +02:00
fprintf(stderr, "-> fin recursion: %d, maxlevel=%d\n", foo, maxlevel);
2022-09-21 00:06:11 +02:00
#endif
2022-06-27 08:53:59 +02:00
dest->modified = 1;
return FUNC_IS_ALPHA;
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/