1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
// tout le code ayant trait à "marques" n'est ici que pour ne pas l'oublier par la suite.
#include <stdio.h>
#include <stdlib.h>
#define TAILLEX 20
#define TAILLEY 20
#define BUFSIZE TAILLEX*TAILLEY
#define AF_ -TAILLEX-1
#define BF_ -TAILLEX
#define CF_ -TAILLEX+1
#define DF_ -1
#define EF_ +1
#define FF_ TAILLEX-1
#define GF_ TAILLEX
#define HF_ TAILLEX+1
typedef unsigned char uchar;
typedef struct bitBuffer {
int w;
int h;
int size;
char *layer;
} bitBuffer;
typedef struct zone {
int x1, y1, x2, y2;
} zone;
bitBuffer matrice;
bitBuffer marques;
uchar *ptr_matrice;
uchar *ptr_marques;
unsigned int ptroffset=0;
int init_BitBuffer(bitBuffer aim)
{
aim.w=TAILLEX;
aim.h=TAILLEY;
aim.size = aim.w*aim.h;
if(!(aim.layer = (char *)realloc(aim.layer, aim.size)))
{
return 0;
}
else
{
}
}
int main()
{
int i;
uchar ptr[BUFSIZE]=
{ 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,
0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0,
0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,
0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,0,
0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
if((init_BitBuffer(matrice)) & (init_BitBuffer(marques)))
{
ptr_matrice = matrice.layer; // Pointeur sur le début du segment de matrice
ptr_marques = marques.layer; // Pointeur sur le début du segment de marques
matrice.layer=ptr;
}
//parcour();
return 0;
}
void parcour()
{
int i;
for (i=0; i<=BUFSIZE; i++)
{
if(!SegFault(i))
{
if ((*(ptr_matrice+i) > 0) & (*(ptr_marques+i)) < 1)
{
if (touche(i) > 20) //une tache !!!!!!!!
{
printf("TACHE !!!\n");
}
}
}
else
{
}
}
}
int touche(int offset)
{
if ((*(ptr_matrice+offset) < 1) | ((*(ptr_marques+offset)) > 0) ) /* si il n'y a rien ou si deja compté ou si or périmetre : return 0 */
{
return 0;
}
else
{
*(ptr_matrice+offset) == 1;
//maxmin(x,y); //on verifie si nouveau min/nouveaumax
return 1 +
touche(offset+AF_) +
touche(offset+BF_) +
touche(offset+CF_) +
touche(offset+DF_) +
touche(offset+EF_) +
touche(offset+FF_) +
touche(offset+GF_) +
touche(offset+HF_) ;
}
}
int SegFault(int offset)
{
if(
(ptr_matrice + offset > ptr_matrice) &
(ptr_matrice + offset < matrice.size)&
(ptr_marques + offset > ptr_marques) &
(ptr_marques + offset < marques.size)
)
{
return 0;
}
else
{
return 1;
}
} |
Partager