libtthimage/Lib/recurse.c

156 lines
3.2 KiB
C
Raw Normal View History

2022-06-27 17:53:59 +11:00
/*
RECURSION 'QUADTREE' SUR LES IMAGES
-----------------------------------
*/
#include <stdio.h>
2024-11-15 21:35:39 +11:00
#include <stdlib.h>
2022-06-27 17:53:59 +11:00
#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 21:01:12 +11:00
/* Private variables */
2022-06-27 17:53:59 +11:00
static Image_Desc *S, *D;
static int seuil;
static int level, maxlevel;
2022-09-17 20:23:21 +11:00
static int recursion(Image_Rect *pRect)
2022-06-27 17:53:59 +11:00
{
Image_Rect rect;
int h1, h2, w1, w2, xx, yy, foo;
int mr, mg, mb, dr, dg, db, s;
2024-08-11 20:21:23 +11:00
level++; /* pourquoi ? */
2022-06-27 17:53:59 +11:00
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);
2024-08-11 20:21:23 +11:00
if (foo) {
fprintf(stderr, "%s: err stat zone %d\n", __func__, foo);
exit(1);
}
2022-06-27 17:53:59 +11:00
s = (dr + dg + db) / 3;
2024-08-11 20:21:23 +11:00
#if 1
printf(" %7d V %3d %3d %3d D %3d %3d %3d S %3d\n",
pRect->w*pRect->h, mr, mg, mb, dr, dg, db, s);
2022-06-27 17:53:59 +11:00
#endif
2022-09-17 20:23:21 +11:00
if ( (s < seuil) || (pRect->w < 6) || (pRect->h < 6) ) {
2022-06-27 17:53:59 +11:00
Image_paint_rect(D, pRect, mr, mg, mb);
/* printf(" paint %d %d %d\n", mr, mg, mb); */
}
2022-09-17 20:23:21 +11:00
else {
2022-06-27 17:53:59 +11: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 20:23:21 +11:00
* a quoi peut bien servir le parametre ?
2022-06-27 17:53:59 +11:00
*/
2022-09-17 20:23:21 +11:00
int Image_call_recursion_0(Image_Desc *image, Image_Desc *dest, int param)
2022-06-27 17:53:59 +11:00
{
Image_Rect rect;
int foo;
2024-08-11 20:21:23 +11:00
#if 1
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, image, dest, param);
#endif
2022-06-27 17:53:59 +11:00
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 09:06:11 +11:00
#if DEBUG_LEVEL
2022-06-27 17:53:59 +11:00
fprintf(stderr, "-> fin recursion: %d, maxlevel=%d\n", foo, maxlevel);
2022-09-21 09:06:11 +11:00
#endif
2022-06-27 17:53:59 +11:00
dest->modified = 1;
2024-08-11 20:21:23 +11:00
return FUNC_IS_BETA;
2022-06-27 17:53:59 +11:00
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/