salut, ce programme fait le rehaussement d'empreintes digitales , le problème lorsque je l'exécute il me détecte cette erreur : violation d'adresse 7C911278 dans le module 'ntdll.dll'. lecture d'adresse 00000001 ok alors c'est en c++ builder 6 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
 
//---------------------------------------------------------------------------
 
#include <vcl.h>
#pragma hdrstop
 #include <stdlib.h>
#include <stdio.h>
 #include <math.h>
 #include <string.h>
#include "Unit1.h"
//*********************************
 #include "stdio.h"
 #include "stdafx.h"
#include "image.h"
#include "fvstypes.h"
#include "config.h"
#include "file.h"
#include "string.h"
#include "floatfield.h"
#include "img_base.h"
#include "imagemanip.h"
 
 //*******************************************************
#define P(x,y)      p[((x)+(y)*pitch)]
 //****************************************************
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
 
#include "fmt_auto.cpp"
#include "fmt_jpeg.cpp"
#include "fmt_bitmap.h"
 
 
//------------------------------------------------------------------------------
//                         Déclaration des variables
//------------------------------------------------------------------------------
 
 
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 
}
 
 
 //***************************************
 
 
 void __fastcall TForm1::Button1Click(TObject *Sender)
{
try{
                if(OpenPictureDialog1->Execute())
                {
                        bitmap1->LoadFromFile(OpenPictureDialog1->FileName);
 
                         Image1->Canvas->StretchDraw(Rect1, bitmap1);
                }
 
        }
        catch(...)
           {
                ShowMessage(  "Impossible d'ouvrir l'image");
           }
 
       Image1->Visible=true;
 
 
       Form1->Panel1->Visible=true;
       Form1->Label1->Visible=true;
     //  Form1->Button2->Enabled=true;
}
 
//---------------------------------------------------------------------------
 
 
 
void __fastcall TForm1::FormCreate(TObject *Sender)
{
bitmap1=new Graphics::TBitmap;
bitmap2=new Graphics::TBitmap;
 
bitmap1->Width=TIM;
bitmap1->Height=TIM;
bitmap2->Width=TIM;
bitmap2->Height=TIM;
 
Rect1=Rect(0,0,Image1->Width,Image1->Height);
Rect2=Rect(0,0,Image2->Width,Image2->Height);
 
 
Image1->Visible=false;
 
  FvsImage_t image;
 
Panel1->Visible=true;
Label1->Visible=true;
Panel2->Visible=true;
Label2->Visible=true;
 
 
 
 
Form1->Button1->Enabled=true;
//Form1->Button2->Enabled=false;
 
 
}
//---------------------------------------------------------------------------
 
//********************* fonction pr image**************
 
typedef struct iFvsImage_t
{
    FvsByte_t      *pimg;          /* 8 bit image array */    
    FvsInt_t        w;             /* width of image */
    FvsInt_t        h;             /* height of image */
    FvsInt_t        pitch;         /* pitch */
    FvsImageFlag_t  flags;         /* flags */
} iFvsImage_t;
 
 
FvsImage_t ImageCreate()
{
    iFvsImage_t* p = NULL;
 
    p = ( iFvsImage_t* ) (FvsImage_t)malloc(sizeof(iFvsImage_t));
    if (p!=NULL)
    {
        p->h        = 0;
        p->w        = 0;
        p->pitch    = 0;
        p->pimg     = NULL;
        p->flags    = FvsImageGray; /* default flag */    
    }
    return (FvsImage_t)p;
}
 
 
void ImageDestroy(FvsImage_t image)
{
    iFvsImage_t* p = NULL;
    if (image==NULL)
        return;
    (void)ImageSetSize(image, 0, 0);
    p = ( iFvsImage_t* )image;
    free(p);
}
 
 
FvsError_t ImageSetFlag(FvsImage_t img, const FvsImageFlag_t flag)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    image->flags = flag; 
    return FvsOK;
}
 
 
FvsImageFlag_t ImageGetFlag(const FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    return image->flags; 
}
 
 
FvsError_t ImageSetSize(FvsImage_t img, const FvsInt_t width, FvsInt_t height)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    FvsError_t nRet = FvsOK;
    FvsInt_t newsize = width*height;
 
    /* special case for zero size */
    if (newsize==0)
    {
        if (image->pimg!=NULL)
        {
            free(image->pimg);
            image->pimg = NULL;
            image->w = 0;
            image->h = 0;
            image->pitch = 0;
        }
        return FvsOK;
    }
 
    if (image->h*image->w != newsize)
    {
        free(image->pimg);
        image->w = 0;
        image->h = 0;
        image->pitch = 0;
        /* This allocates the amount of memory need for the image structure */
        image->pimg = (uint8_t*)malloc((size_t)newsize);
    }
 
    if (image->pimg == NULL)
        nRet = FvsMemory;
    else
    {
        image->h = height;
        image->w = width;
        image->pitch = width;
    }
    return nRet;
}
 
 
FvsError_t ImageCopy(FvsImage_t destination, const FvsImage_t source)
{
    iFvsImage_t* dest = (iFvsImage_t*)destination;
    iFvsImage_t* src  = (iFvsImage_t*)source;
    FvsError_t nRet = FvsOK;
 
    nRet = ImageSetSize(dest, src->w, src->h);
 
    if (nRet==FvsOK)
        memcpy(dest->pimg, src->pimg, (size_t)src->h*src->w);
 
    /* copy the flag */
    dest->flags = src->flags;
 
    return nRet;
}
 
 
FvsError_t ImageClear(FvsImage_t img)
{
    return ImageFlood(img, 0);
}
 
 
FvsError_t ImageFlood(FvsImage_t img, const FvsByte_t value)
{
    FvsError_t nRet = FvsOK;
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return FvsMemory;
    if (image->pimg!=NULL)
        memset(image->pimg, (int)value, (size_t)(image->h*image->w));
    return nRet;
}
 
 
/* set a pixel value in the picture */
void ImageSetPixel(FvsImage_t img, const FvsInt_t x, const FvsInt_t y, const FvsByte_t val)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    int address = y * image->w + x;
    image->pimg[address] = val;
}
 
 
/* This function returns the pixel for the x and y value */
FvsByte_t ImageGetPixel(const FvsImage_t img, const FvsInt_t x, const FvsInt_t y)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    /* position in array */
    int address = y * image->pitch + x;
    return image->pimg[address];
}
 
 
/* returns a pointer to the image buffer */
FvsByte_t* ImageGetBuffer(FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return NULL;
    return image->pimg;
}
 
 
/* retrieve width and height */
FvsInt_t ImageGetWidth(const FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return -1;
    return image->w;
}
 
 
FvsInt_t ImageGetHeight(const FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return -1;
    return image->h;
}
 
 
FvsInt_t ImageGetSize(const FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return 0;
    return image->h * image->w;
}
 
/* get the pitch pixel(x,y) pos is at x + y * pitch */
FvsInt_t ImageGetPitch(const FvsImage_t img)
{
    iFvsImage_t* image = (iFvsImage_t*)img;
    if (image==NULL) return -1;
    return image->pitch;
}
 
FvsBool_t ImageCompareSize(const FvsImage_t image1, const FvsImage_t image2)
{
    if (ImageGetWidth(image1)!=ImageGetWidth(image2))
        return FvsFalse;
    if (ImageGetHeight(image1)!=ImageGetHeight(image2))
        return FvsFalse;
    return FvsTrue;
}
 
 
//***********************************image irode******//
 
FvsError_t ImageDilate(FvsImage_t image)
{
    FvsInt_t w      = ImageGetWidth (image);
    FvsInt_t h      = ImageGetHeight(image);
    FvsInt_t pitch  = ImageGetPitch (image);
    FvsInt_t size   = ImageGetSize  (image);
    FvsByte_t* p    = ImageGetBuffer(image);
    FvsInt_t x,y;
 
   if (p==NULL)
      return FvsMemory;
 
    for (y=1; y<h-1; y++)
    for (x=1; x<w-1; x++)
    {
        if (P(x,y)==0xFF)
        {
            P(x-1, y) |= 0x80;
            P(x+1, y) |= 0x80;
            P(x, y-1) |= 0x80;
            P(x, y+1) |= 0x80;
        }
    }
 
    for (y=0; y<size; y++)
        if (p[y])
            p[y] = 0xFF;
 
    return FvsOK;
}
  //************************* fin imge dilate***********///
 
//*******************************image eroder**********//
FvsError_t ImageErode(FvsImage_t image)
{
    FvsInt_t w      = ImageGetWidth (image);
    FvsInt_t h      = ImageGetHeight(image);
    FvsInt_t pitch  = ImageGetPitch (image);
    FvsInt_t size   = ImageGetSize  (image);
    FvsByte_t* p    = ImageGetBuffer(image);
    FvsInt_t x,y;
 
    if (p==NULL)
      return FvsMemory;
 
    for (y=1; y<h-1; y++)
    for (x=1; x<w-1; x++)
    {
        if (P(x,y)==0x0)
        {
            P(x-1, y) &= 0x80;
            P(x+1, y) &= 0x80;
            P(x, y-1) &= 0x80;
            P(x, y+1) &= 0x80;
        }
    }
 
    for (y=0; y<size; y++)
        if (p[y]!=0xFF)
            p[y] = 0x0;
 
    return FvsOK;
}
 
//*********************fin eroder*****************
 
//**************************************
 
 //**********************file **************************
 
 
 
 
 
 
typedef struct iFvsFile_t
{
    FILE    *pf;        /* file pointer */
} iFvsFile_t;
 
 
FvsFile_t FileCreate()
{
    iFvsFile_t* p = NULL;
    p = (iFvsFile_t*)malloc(sizeof(iFvsFile_t));
    if (p!=NULL)
        p->pf = NULL;
    return (FvsFile_t)p;
}
 
 
void FileDestroy(FvsFile_t file)
{
    iFvsFile_t* p = NULL;
    if (file==NULL)
        return;
    /* close file if it was still open */
    (void)FileClose(file);
    p = (iFvsFile_t* )file;
    free(p);
}
 
 
FvsBool_t FileIsOpen(const FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    return (p->pf!=NULL)?FvsTrue:FvsFalse;
}
 
 
 
 
FvsError_t FileOpen(FvsFile_t file, const FvsString_t name, const FvsFileOptions_t flags)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    char strFlags[10];
    int nflags = (int)flags;
    /* close eventually already open file */
    (void)FileClose(p);
 
    strcpy(strFlags, "");
    if ( (nflags & FvsFileRead)!=0   &&
         (nflags & FvsFileWrite)!=0 )
        strcat(strFlags, "rw");
    else
    {
        if ((nflags & FvsFileRead)!=0)
            strcat(strFlags, "r");
        if ((nflags & FvsFileWrite)!=0)
            strcat(strFlags, "w");
    }    
    strcat(strFlags, "b");
    if ((nflags & FvsFileCreate)!=0)
        strcat(strFlags, "+");
 p->pf = fopen(name, strFlags);
 
    if (FileIsOpen(file)==FvsTrue)
 
        return FvsOK;
           ShowMessage("hello");
 
    return FvsFailure;
}
 
 
FvsError_t FileClose(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    int nerr = -1;
    if (p->pf!=NULL)
    {
        nerr = fclose(p->pf);
        p->pf = NULL;
    }
    if (nerr==0)
        return FvsOK;
    return FvsFailure;
}
 
 
 
 
FvsBool_t FileIsAtEOF(const FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    if (FileIsOpen(p)==FvsFalse)
        return FvsFalse;
    return (feof(p->pf)!=0)?FvsTrue:FvsFalse;
}
 
 
FvsError_t FileCommit(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    return (fflush(p->pf)==0)?FvsOK:FvsFailure;
}
 
 
FvsError_t FileSeekToBegin(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    if (FileIsOpen(p)==FvsTrue)
    {
        if (fseek(p->pf, 0, SEEK_SET)!=0)
            return FvsFailure;
        return FvsOK;
    }
    return FvsFailure;
}
 
 
FvsError_t FileSeekToEnd(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    if (FileIsOpen(p)==FvsTrue)
    {
        if (fseek(p->pf, 0, SEEK_END)!=0)
            return FvsFailure;
        return FvsOK;
    }
    return FvsFailure;
}
 
 
FvsUint_t FileGetPosition(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    if (FileIsOpen(p)==FvsTrue)
        return (FvsUint_t)ftell(p->pf);
    return 0;
}
 
 
FvsError_t FileSeek(FvsFile_t file, const FvsUint_t position)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    if (FileIsOpen(p)==FvsTrue)
    {
        if (fseek(p->pf, (long int)position, SEEK_SET)!=0)
            return FvsFailure;
        return FvsOK;
    }
    return FvsFailure;
}
 
 
FvsUint_t FileRead(FvsFile_t file, FvsPointer_t data, const FvsUint_t length)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    return (FvsUint_t)fread(data, (size_t)1, (size_t)length, p->pf);
}
 
 
FvsUint_t FileWrite(FvsFile_t file, const FvsPointer_t data, const FvsUint_t length)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    return (FvsUint_t)fwrite(data, (size_t)1, (size_t)length, p->pf);
}
 
 
FvsByte_t FileGetByte(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    return (FvsByte_t)fgetc(p->pf);
}
 
 
FvsWord_t FileGetWord(FvsFile_t file)
{
    iFvsFile_t* p = (iFvsFile_t*)file;
    FvsWord_t w = (FvsWord_t)fgetc(p->pf);
    return (w<<8)+fgetc(p->pf);
}
 
 
TCHAR  BitmapFilename[256];
TCHAR  outputFilename[256];
 
 
 //***************end file *********************
 
 
void __fastcall TForm1::Button3Click(TObject *Sender)
{
 Close();
 
}
//---------------------------------------------------------------------------
 
 
//*********************************************
typedef struct iFvsHistogram_t
{
    FvsUint_t       ptable[256];    /* 8 bit image histogram */
    FvsInt_t        ncount;         /* number of points in the histogram */
    FvsInt_t        nmean;          /* -1 = not computed yet */
    FvsInt_t        nvariance;      /* -1 = not computed yet */
} iFvsHistogram_t;
 
 
 
FvsHistogram_t HistogramCreate()
{
    iFvsHistogram_t* p = NULL;
    p = (iFvsHistogram_t*) (FvsHistogram_t)malloc(sizeof(iFvsHistogram_t));
 
    if (p!=NULL)
    {
        /* reset the table */
        HistogramReset(p);
    }
    return (FvsHistogram_t)p;
}
 
 
void HistogramDestroy(FvsHistogram_t histogram)
{
    iFvsHistogram_t* p = NULL;
    if (histogram==NULL)
        return;
    p = (iFvsHistogram_t*) histogram;
    free(p);
}
 
 
FvsError_t HistogramReset(FvsHistogram_t hist)
{
    iFvsHistogram_t* histogram = (iFvsHistogram_t*)hist;
    int i;
    for (i = 0; i < 256; i++)
        histogram->ptable[i] = 0;
    histogram->ncount    = 0;
    histogram->nmean     = -1;
    histogram->nvariance = -1;
    return FvsOK;
}
 
 
FvsError_t HistogramCompute(FvsHistogram_t hist, const FvsImage_t image)
{
    iFvsHistogram_t* histogram = (iFvsHistogram_t*)hist;
    FvsError_t nRet = FvsOK;
    FvsInt_t w      = ImageGetWidth(image);
    FvsInt_t h      = ImageGetHeight(image);
    FvsInt_t pitch  = ImageGetPitch(image);
    uint8_t* p      = ImageGetBuffer(image);
    FvsInt_t x, y;
 
    if (histogram==NULL || p==NULL)
        return FvsMemory;
 
    /* reset the histogram first */
    nRet = HistogramReset(hist);
    /* now compute the histogram */
    if (nRet==FvsOK)
    {
        FvsInt_t pos;
        for (y=0; y<h; y++)
        {
            pos = pitch*y;
            for (x=0; x<w; x++)
            {
                histogram->ptable[p[pos++]]++;
            }
        }
        histogram->ncount = w*h;
    }
 
    return nRet;
}
 
 
/* Get the mean of an histogram */
FvsByte_t HistogramGetMean(const FvsHistogram_t hist)
{
    iFvsHistogram_t* histogram = (iFvsHistogram_t*)hist;
    FvsInt_t val, i;
                    ShowMessage("hi");
    val = histogram->nmean;
    if (val==-1)
    {
        val = 0;
        for (i = 1; i < 255; i++)
            val += i*histogram->ptable[i];
 
        i = histogram->ncount;
        if (i>0)
            val = val/i;
        else
            val = 0;
 
        histogram->nmean = val;
    }
    return (uint8_t)val;
}
 
 
/* Get the variance of an histogram */
FvsUint_t HistogramGetVariance(const FvsHistogram_t hist)
{
    iFvsHistogram_t* histogram = (iFvsHistogram_t*)hist;
    FvsInt_t val;
    FvsInt_t i;
    uint8_t mean;
 
    val = histogram->nvariance;
    if (val==-1)
    {
        /* we need the mean value */
        mean = HistogramGetMean(hist);
        val  = 0;
        for (i = 0; i < 255; i++)
            val += histogram->ptable[i]*(i - mean)*(i - mean);
 
        i = histogram->ncount;
        if (i>0)
            val = val/i;
        else
            val = 0;
 
        histogram->nvariance = val;
    }
    return (FvsUint_t)val;
}
 
//*****************************************
             //**NORMALISATION**************//
//*************************************
 
FvsError_t ImageNormalize(FvsImage_t image, const FvsByte_t mean, const FvsUint_t variance)
{
    FvsByte_t* p = ImageGetBuffer(image);
    FvsInt_t   w = ImageGetWidth (image);
    FvsInt_t   h = ImageGetHeight(image);
    FvsInt_t   pitch = ImageGetPitch (image);
    FvsInt_t   x,y;
    FvsFloat_t fmean, fsigma, fmean0, fsigma0, fgray;
    FvsFloat_t fcoeff = 0.0;
 
    FvsHistogram_t histogram = NULL;
    FvsError_t nRet;
 
    if (p==NULL)
        return FvsMemory;
    histogram = HistogramCreate();
    if (histogram!=NULL)
    {
    ShowMessage("allo");
        /* compute histogram */
        nRet = HistogramCompute(histogram, image);
        if (nRet==FvsOK)
        {
            /* first compute sigma and mean */
            fmean   = (FvsFloat_t)HistogramGetMean(histogram);
            fsigma  = sqrt((FvsFloat_t)HistogramGetVariance(histogram));
 
            fmean0  = (FvsFloat_t)mean;
            fsigma0 = sqrt((FvsFloat_t)variance);
            if (fsigma>0.0)
                fcoeff = fsigma0/fsigma;
            for (y = 0; y < h; y++)
            for (x = 0; x < w; x++)
            {
                fgray = (FvsFloat_t)P(x,y);
                fgray = fmean0 + fcoeff*(fgray - mean);
                if (fgray < 0.0)    fgray = 0.0;
                if (fgray > 255.0)  fgray = 255.0;
                P(x,y)= (uint8_t)fgray;
            }
        }
        HistogramDestroy(histogram);
    }
    return nRet;
}
//**********************END NORMALISATION*************
 
//---------------------------------------------------------------------------
 //*************************low passs filter **///////////
  static FvsError_t FingerprintDirectionLowPass(FvsFloat_t* theta, FvsFloat_t* out,
            FvsInt_t nFilterSize, FvsInt_t w, FvsInt_t h)
{
    FvsError_t nRet = FvsOK;
    FvsFloat_t* filter = NULL;
    FvsFloat_t* phix   = NULL;
    FvsFloat_t* phiy   = NULL;
    FvsFloat_t* phi2x  = NULL;
    FvsFloat_t* phi2y  = NULL;
    FvsInt_t fsize  = nFilterSize*2+1;
    size_t nbytes = (size_t)(w*h*sizeof(FvsFloat_t));
    FvsFloat_t nx, ny;
    FvsInt_t val;
    FvsInt_t i, j, x, y;
 
    filter= (FvsFloat_t*)malloc((size_t)fsize*fsize*sizeof(FvsFloat_t));
    phix  = (FvsFloat_t*)malloc(nbytes);
    phiy  = (FvsFloat_t*)malloc(nbytes);
    phi2x = (FvsFloat_t*)malloc(nbytes);
    phi2y = (FvsFloat_t*)malloc(nbytes);
 
    if (filter==NULL || phi2x==NULL || phi2y==NULL || phix==NULL || phiy==NULL)
        nRet = FvsMemory;
    else
    {
        /* reset all fields to 0 */
        memset(filter, 0, (size_t)fsize*fsize*sizeof(FvsFloat_t));
        memset(phix,   0, nbytes);
        memset(phiy,   0, nbytes);
        memset(phi2x,  0, nbytes);
        memset(phi2y,  0, nbytes);
 
        /* 4 - Compute a continuous field from theta */
        for (y = 0; y < h; y++)
        for (x = 0; x < w; x++)
        {
            val = x+y*w;
            phix[val] = cos(theta[val]);
            phiy[val] = sin(theta[val]);
        }
        /* build the low-pass filter */
        nx = 0.0;
        for (j = 0; j < fsize; j++)
        for (i = 0; i < fsize; i++)
        {
            filter[j*fsize+i] = (FvsFloat_t)(fsize - (abs(nFilterSize-i)+abs(nFilterSize-j)));
            nx += filter[j*fsize+i]; /* sum of coefficients */
        }
        if (nx>1.0)
        {
            for (j = 0; j < fsize; j++)
            for (i = 0; i < fsize; i++)
                /* normalize the result */
                filter[j*fsize+i] /= nx;
        }
        /* low-pass on the result arrays getting phi2 */
        for (y = 0; y < h-fsize; y++)
        for (x = 0; x < w-fsize; x++)
        {
            nx = 0.0;
            ny = 0.0;
            for (j = 0; j < fsize; j++)
            for (i = 0; i < fsize; i++)
            {
                val = (x+i)+(j+y)*w;
                nx += filter[j*fsize+i]*phix[val];
                ny += filter[j*fsize+i]*phiy[val];
            }
            val = x+y*w;
            phi2x[val] = nx;
            phi2y[val] = ny;
        }
        /* we do not need phix, phiy anymore, delete them */
        if (phix!=NULL) { free(phix); phix=NULL; }
        if (phiy!=NULL) { free(phiy); phiy=NULL; }
 
        /* 5 - local ridge orientation -> theta */
        for (y = 0; y < h-fsize; y++)
        for (x = 0; x < w-fsize; x++)
        {
            val = x+y*w;
            out[val] = atan2(phi2y[val], phi2x[val])*0.5;
        }
    }
 
    if (phix!=NULL)  free(phix);
    if (phiy!=NULL)  free(phiy);
    if (phi2x!=NULL) free(phi2x);
    if (phi2y!=NULL) free(phi2y);
    if (filter!=NULL)free(filter);
 
    return nRet;
}
 
//*********************end low pass**************////
 //*****************************************************
 
 //**********************FLOAT**************///////////
                        /*########################################################################
 
########################################################################*/
 
 
 
/*!
  A fingerprint floating point field structure.
*/
typedef struct iFvsFloatField_t
{
    FvsFloat_t      *pimg;          /* floating point field array */
    FvsInt_t         w;             /* width of field */
    FvsInt_t         h;             /* height of field */
    FvsInt_t         pitch;         /* pitch */
} iFvsFloatField_t;
 
 
FvsFloatField_t FloatFieldCreate()
{
    iFvsFloatField_t* p = NULL;
    p = ( iFvsFloatField_t* ) (FvsFloatField_t)malloc(sizeof(iFvsFloatField_t));
 
    if (p!=NULL)
    {
        p->h        = 0;
        p->w        = 0;
        p->pitch    = 0;
        p->pimg     = NULL;
    }
 
    return (FvsFloatField_t)p;
}
 
 
void FloatFieldDestroy(FvsFloatField_t field)
{
    iFvsFloatField_t* p = NULL;
 
    if (field==NULL)
        return;
 
    p = ( iFvsFloatField_t* )field;
    (void)FloatFieldSetSize(field, 0, 0);
    free(p);
}
 
 
FvsError_t FloatFieldSetSize(FvsFloatField_t img, const FvsInt_t width, const FvsInt_t height)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    FvsError_t nRet = FvsOK;
    FvsInt_t newsize = (FvsInt_t)(width*height*sizeof(FvsFloat_t));
 
    /* special case for zero size */
    if (newsize==0)
    {
        if (field->pimg!=NULL)
        {
            free(field->pimg);
            field->pimg = NULL;
            field->w = 0;
            field->h = 0;
            field->pitch = 0;
        }
        return FvsOK;
    }
 
    if ((FvsInt_t)(field->h*field->w*sizeof(FvsFloat_t)) != newsize)
    {
        free(field->pimg);
        field->w = 0;
        field->h = 0;
        field->pitch = 0;
        /* This allocates the amount of memory need for the field structure */
        field->pimg = (FvsFloat_t*)malloc((size_t)newsize);
    }
 
    if (field->pimg == NULL)
        nRet = FvsMemory;
    else
    {
        field->h = height;
        field->w = width;
        field->pitch = width;
    }
    return nRet;
}
 
 
FvsError_t FloatFieldCopy(FvsFloatField_t destination, const FvsFloatField_t source)
{
    iFvsFloatField_t* dest = (iFvsFloatField_t*)destination;
    iFvsFloatField_t* src  = (iFvsFloatField_t*)source;
    FvsError_t nRet = FvsOK;
 
    nRet = FloatFieldSetSize(dest, src->w, src->h);
 
    if (nRet==FvsOK)
        memcpy(dest->pimg, src->pimg, src->h*src->w*sizeof(FvsFloat_t));
 
    return nRet;
}
 
 
FvsError_t FloatFieldClear(FvsFloatField_t img)
{
    return FloatFieldFlood(img, 0.0);
}
 
 
FvsError_t FloatFieldFlood(FvsFloatField_t img, const FvsFloat_t value)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    FvsError_t nRet = FvsOK;
    FvsInt_t i;
    if (field->pimg!=NULL)
    {
        for (i=0; i<field->h*field->w; i++)
            field->pimg[i] = value;
    }
    return nRet;
}
 
 
/* set a pixel value in the picture */
void FloatFieldSetValue(FvsFloatField_t img, const FvsInt_t x, const FvsInt_t y, const FvsFloat_t val)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    int address = y * field->w + x;
    field->pimg[address] = val;
}
 
 
/* This function returns the pixel for the x and y value */
FvsFloat_t FloatFieldGetValue(FvsFloatField_t img, const FvsInt_t x, const FvsInt_t y)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    /* position in array */
    int address = y * field->pitch + x;
    return field->pimg[address];
}
 
 
/* returns a pointer to the field buffer */
FvsFloat_t* FloatFieldGetBuffer(FvsFloatField_t img)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    return field->pimg;
}
 
 
/* retrieve width and height */
FvsInt_t FloatFieldGetWidth(const FvsFloatField_t img)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    return field->w;
}
 
 
FvsInt_t FloatFieldGetHeight(const FvsFloatField_t img)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    return field->h;
}
 
 
/* get the pitch pixel(x,y) pos is at x + y * pitch */
FvsInt_t FloatFieldGetPitch(const FvsFloatField_t img)
{
    iFvsFloatField_t* field = (iFvsFloatField_t*)img;
    return field->pitch;
}
 
 
 
 
 //*********************
 
 
          //*********ORIENTATION************////////
 
 //****************************************************
 
FvsError_t FingerprintGetDirection(const FvsImage_t image, FvsFloatField_t field,
            const FvsInt_t nBlockSize, const FvsInt_t nFilterSize)
{
    /* width & height of the input image */
    FvsInt_t w       = ImageGetWidth (image);
    FvsInt_t h       = ImageGetHeight(image);
    FvsInt_t pitch   = ImageGetPitch (image);
    FvsByte_t* p     = ImageGetBuffer(image);
    FvsInt_t i, j, u, v, x, y;
	 const temp = nBlockSize*2+1;
    FvsInt_t dx[100][100];// = new FvsInt_t[(nBlockSize*2+1)][(nBlockSize*2+1)];
    FvsInt_t dy[100][100];// = new FvsInt_t[(nBlockSize*2+1)][(nBlockSize*2+1)];
    FvsFloat_t nx, ny;
    FvsFloat_t* out;
    FvsFloat_t* theta  = NULL;
    FvsError_t nRet = FvsOK;
 
    /* (re-)allocate the output image */
    nRet = FloatFieldSetSize(field, w, h);
    if (nRet!=FvsOK) return nRet;
    nRet = FloatFieldClear(field);
    if (nRet!=FvsOK) return nRet;
    out = FloatFieldGetBuffer(field);
 
    /* allocate memory for the orientation values */
    if (nFilterSize>0)
    {
        theta = (FvsFloat_t*)malloc(w * h * sizeof(FvsFloat_t));
        if (theta!=NULL)
            memset(theta, 0, (w * h * sizeof(FvsFloat_t)));
    }
 
    /* detect any allocation error */
    if (out==NULL || (nFilterSize>0 && theta==NULL))
        nRet = FvsMemory;
    else
    {
        /* 1 - divide the image in blocks */
        for (y = nBlockSize+1; y < h-nBlockSize-1; y++)
        for (x = nBlockSize+1; x < w-nBlockSize-1; x++)
        {
            /* 2 - for the block centered at x,y compute the gradient */
            for (j = 0; j < (temp); j++)
            for (i = 0; i < (temp); i++)
            {
                dx[i][j] = (FvsInt_t)
                           (P(x+i-nBlockSize,   y+j-nBlockSize) -
                            P(x+i-nBlockSize-1, y+j-nBlockSize));
                dy[i][j] = (FvsInt_t)
                           (P(x+i-nBlockSize,   y+j-nBlockSize) -
                            P(x+i-nBlockSize,   y+j-nBlockSize-1));
            }
 
            /* 3 - compute orientation */
            nx = 0.0;
            ny = 0.0;
            for (v = 0; v < (nBlockSize*2+1); v++)
            for (u = 0; u < (nBlockSize*2+1); u++)
            {
                nx += 2 * dx[u][v] * dy[u][v];
                ny += dx[u][v]*dx[u][v] - dy[u][v]*dy[u][v];
            }
            /* compute angle (-pi/2 .. pi/2) */
            if (nFilterSize>0)
                theta[x+y*w] = atan2(nx, ny);
            else
                out[x+y*w] = atan2(nx, ny)*0.5;
        }
        if (nFilterSize>0)
            nRet = FingerprintDirectionLowPass(theta, out, nFilterSize, w, h);
    }
 
    if (theta!=NULL) free(theta);
    return nRet;
}
 
 
//*****************************************************
 
//**********************END ORIENTATION****************///
 
 //***************************************************
 
        //****** get frequency************///////////
 
 
 
FvsError_t FingerprintGetFrequency(const FvsImage_t image, const FvsFloatField_t direction,
           FvsFloatField_t frequency)
{
    /* width & height of the input image */
    FvsError_t nRet = FvsOK;
    FvsInt_t w      = ImageGetWidth (image);
    FvsInt_t h      = ImageGetHeight(image);
    FvsInt_t pitchi = ImageGetPitch (image);
    FvsByte_t* p    = ImageGetBuffer(image);
    FvsFloat_t* out;
    FvsFloat_t* freq;
    FvsFloat_t* orientation = FloatFieldGetBuffer(direction);
 
    FvsInt_t x, y, u, v, d, k;
    size_t size;
 
    if (p==NULL)
        return FvsMemory;
 
    /* (re-)allocate the output image */
    nRet = FloatFieldSetSize(frequency, w, h);
    if (nRet!=FvsOK) return nRet;
    (void)FloatFieldClear(frequency);
    freq = FloatFieldGetBuffer(frequency);
    if (freq==NULL)
        return FvsMemory;
 
    /* allocate memory for the output */
    size = w*h*sizeof(FvsFloat_t);
    out  = (FvsFloat_t*)malloc(size);
    if (out!=NULL)
    {
        FvsFloat_t dir = 0.0;
        FvsFloat_t cosdir = 0.0;
        FvsFloat_t sindir = 0.0;
 
        FvsInt_t peak_pos[BLOCK_L]; /* peak positions */
        FvsInt_t peak_cnt;          /* peak count     */
        FvsFloat_t peak_freq;         /* peak frequence */
        FvsFloat_t Xsig[BLOCK_L];     /* x signature    */
        FvsFloat_t pmin, pmax;
 
        memset(out,  0, size);
        memset(freq, 0, size);
 
        /* 1 - Divide G into blocks of BLOCK_W x BLOCK_W - (16 x 16) */
        for (y = BLOCK_L2; y < h-BLOCK_L2; y++)
        for (x = BLOCK_L2; x < w-BLOCK_L2; x++)
        {
            /* 2 - oriented window of size l x w (32 x 16) in the ridge dir */
            dir = orientation[(x+BLOCK_W2) + (y+BLOCK_W2)*w];
            cosdir = -sin(dir);
            sindir = cos(dir);
 
           /* 3 - compute the x-signature X[0], X[1], ... X[l-1] */
            for (k = 0; k < BLOCK_L; k++)
            {
                Xsig[k] = 0.0;
                for (d = 0; d < BLOCK_W; d++)
                {
                    u = (FvsInt_t)(x + (d-BLOCK_W2)*cosdir + (k-BLOCK_L2)*sindir);
                    v = (FvsInt_t)(y + (d-BLOCK_W2)*sindir - (k-BLOCK_L2)*cosdir);
 
                    if (u<0) u = 0; else if (u>w-1) u = w-1;
                    if (v<0) v = 0; else if (v>h-1) v = h-1;
                    Xsig[k] += p[u + (v*pitchi)];
                }
                Xsig[k] /= BLOCK_W;
            }
 
 
            peak_cnt = 0;
 
            pmax = pmin = Xsig[0];
            for (k = 1; k < BLOCK_L; k++)
            {
                if (pmin>Xsig[k]) pmin = Xsig[k];
                if (pmax<Xsig[k]) pmax = Xsig[k];
            }
            if ((pmax - pmin)>64.0)
            {
                for (k = 1; k < BLOCK_L-1; k++)
                if ((Xsig[k-1] < Xsig[k]) && (Xsig[k] >= Xsig[k+1]))
                {
                    peak_pos[peak_cnt++] = k;
                }
            }
            /* compute mean value */
            peak_freq = 0.0;
            if (peak_cnt>=2)
            {
                for (k = 0; k < peak_cnt-1; k++)
                    peak_freq += peak_pos[k+1]-peak_pos[k];
                peak_freq /= peak_cnt-1;
            }
            /* 4 - must lie in a certain range [1/3, 1/25] */
            if (peak_freq > 25.0)
                out[x+y*w] = 0.0;
            else if (peak_freq < 3.0)
                out[x+y*w] = 0.0;
            else
                out[x+y*w] = 1.0/peak_freq;
        }
        /* 5 - interpolated ridge period for the unknown points */
/*
        for (y = BLOCK_L2; y < h-BLOCK_L2; y++)
        for (x = BLOCK_L2; x < w-BLOCK_L2; x++)
        {
            if (out[x+y*w]<EPSILON)
            {
                if (out[x+(y-1)*w]>EPSILON)
                {
                    out[x+(y*w)] = out[x+(y-1)*w];
                }
                else
                {
                    if (out[x-1+(y*w)]>EPSILON)
                        out[x+(y*w)] = out[x-1+(y*w)];
                }
            }
        }
*/
        /* 6 - Inter-ridges distance change slowly in a local neighbourhood */
        for (y = BLOCK_L2; y < h-BLOCK_L2; y++)
        for (x = BLOCK_L2; x < w-BLOCK_L2; x++)
        {
            k = x + y*w;
            peak_freq = 0.0;
            for ( v = -LPSIZE; v <= LPSIZE; v++)
            for ( u = -LPSIZE; u <= LPSIZE; u++)
                peak_freq += out[(x+u)+(y+v)*w];
            freq[k] = peak_freq*LPFACTOR;
/*            freq[k] = out[k];*/
        }
        free(out);
    }
    return nRet;
}
 
 
        //********** fin de calcule de la fraquence *****************//////
 
  //****************** calcule le  mask****////////////////
 
FvsError_t FingerprintGetMask(const FvsImage_t image, /*@unused@*/ const FvsFloatField_t direction,
           const FvsFloatField_t frequency, FvsImage_t mask)
{
    FvsError_t nRet = FvsOK;
    FvsFloat_t freqmin = 1.0 / 25;
    FvsFloat_t freqmax = 1.0 / 3;
 
    /* width & height of the input image */
    FvsInt_t w      = ImageGetWidth (image);
    FvsInt_t h      = ImageGetHeight(image);
    FvsByte_t* out;
    FvsInt_t pitchout;
    FvsInt_t pos, posout, x, y;
    FvsFloat_t* freq = FloatFieldGetBuffer(frequency);
 
    if (freq==NULL)
        return FvsMemory;
 
    /* TODO: add sanity checks for the direction and mask */
    nRet = ImageSetSize(mask, w, h);
    if (nRet==FvsOK)
        nRet = ImageClear(mask);
    out = ImageGetBuffer(mask);
    if (out==NULL)
        return FvsMemory;
    if (nRet==FvsOK)
    {
    pitchout = ImageGetPitch(mask);
 
    for (y = 0; y < h; y++)
        for (x = 0; x < w; x++)
        {
            pos    = x + y * w;
            posout = x + y * pitchout;
            out[posout] = 0;
            if (freq[pos] >= freqmin && freq[pos] <= freqmax)
            {
/*              out[posout] = (uint8_t)(10.0/freq[pos]);*/
                out[posout] = 255;
            }
        }
    /* fill in the holes */
    for (y = 0; y < 4; y++)
        (void)ImageDilate(mask);
    /* remove borders */
    for (y = 0; y < 12; y++)
        (void)ImageErode(mask);
    }
    return nRet;
}
 //***********************fin de mask*******************//
 
 //******************************************************
 
//*****************************fonction suppl pr calcule filtre de gabor*****//
 
 inline FvsFloat_t EnhanceGabor(FvsFloat_t x, FvsFloat_t y, FvsFloat_t phi, FvsFloat_t f)
{
    static FvsFloat_t dy2 = 1.0/(4.0*4.0);
    static FvsFloat_t dx2 = 1.0/(4.0*4.0);
    FvsFloat_t x2, y2;
    phi += M_PI/2;
    x2 = -x*sin(phi) + y*cos(phi);
    y2 =  x*cos(phi) + y*sin(phi);
    return exp(-0.5*(x2*x2*dx2 + y2*y2*dy2))*cos(2*M_PI*x2*f);
}
 
 
 
static FvsError_t ImageEnhanceFilter
    (
    FvsImage_t        normalized,
    const FvsImage_t  mask,
    const FvsFloat_t* orientation,
    const FvsFloat_t* frequence
    )
{
    FvsInt_t Wg2 = 5; /* from -5 to 5 are 11 */
    FvsInt_t i,j, u,v;
    FvsError_t nRet  = FvsOK;
    FvsImage_t enhanced = NULL;
 
    FvsInt_t w        = ImageGetWidth (normalized);
    FvsInt_t h        = ImageGetHeight(normalized);
    FvsInt_t pitchG   = ImageGetPitch (normalized);
    FvsByte_t* pG     = ImageGetBuffer(normalized);
    FvsFloat_t sum, f, o;
 
 
    enhanced = ImageCreate();
    if (enhanced==NULL || pG==NULL)
        return FvsMemory;
    if (nRet==FvsOK)
        nRet = ImageSetSize(enhanced, w, h);
    if (nRet==FvsOK)
    {
        FvsInt_t pitchE  = ImageGetPitch (enhanced);
        FvsByte_t* pE    = ImageGetBuffer(enhanced);
        if (pE==NULL)
            return FvsMemory;
        (void)ImageClear(enhanced);
        for (j = Wg2; j < h-Wg2; j++)
        for (i = Wg2; i < w-Wg2; i++)
        {
            if (ImageGetPixel(mask, i, j)!=0)
            {
                sum = 0.0;
                o = orientation[i+j*w];
                f = frequence[i+j*w];
                for (v = -Wg2; v <= Wg2; v++)
                for (u = -Wg2; u <= Wg2; u++)
                {
                    sum += EnhanceGabor((FvsFloat_t)u,(FvsFloat_t)v,o,f)*
                                 pG[(i-u)+(j-v)*pitchG];
                }
                /* printf("%6.1f ", sum);*/
                if (sum>255.0) sum = 255.0;
                if (sum<0.0)   sum = 0.0;
                pE[i+j*pitchE] = (uint8_t)sum;
            }
        }
        nRet = ImageCopy(normalized, enhanced);
    }
    (void)ImageDestroy(enhanced);
    return nRet;
}
 
 
 
 
 
//*****************************end fonction  supplimentaire pour calculer le filtre de gabor*******/
 
//************************export import image**********//
 static void ExportImage(const FvsImage_t image, const FvsString_t filename)
{
    FvsFile_t file = FileCreate();
    if (file!=NULL)
    {
        //AfxMessageBox(CString("exporting resulting image to ")+CString(filename));
        (void)FileOpen    (file, filename, FvsFileWrite);
        (void)BitmapExport(file, image);
        (void)FileClose   (file);
        FileDestroy(file);
    }
}
 
static void ImportImage(FvsImage_t image, const FvsString_t filename)
{
    FvsFile_t file = FileCreate();
    if (file!=NULL)
    {
      /// MessageBox(CString("Opening file  ")+CString(filename));
        (void)FileOpen  (file, filename, FvsFileRead);
        (void)AutoImport(file, image);
        (void)FileClose (file);
        FileDestroy(file);
    }
}
 
   //**************************************************
 
 //************* le filtre de gabor********************
 
 FvsError_t ImageEnhanceGabor(FvsImage_t image, const FvsFloatField_t direction,
            const FvsFloatField_t frequency, const FvsImage_t mask)
{
    FvsError_t nRet = FvsOK;
    FvsFloat_t * image_orientation = FloatFieldGetBuffer(direction);
    FvsFloat_t * image_frequence   = FloatFieldGetBuffer(frequency);
 
    if (image_orientation==NULL || image_frequence==NULL)
        return FvsMemory;
 
    nRet = ImageEnhanceFilter(image, mask, image_orientation, image_frequence);
    return nRet;
}
 
 //*****************end filtre de gabor*********************
 
void __fastcall TForm1::Button4Click(TObject *Sender)
{
 char *input;
      char *output;
      int i,j, pix;
FvsImage_t mask;
    FvsImage_t image;
    FvsFloatField_t direction;
    FvsFloatField_t frequency;
//enhancement *enh;
//	enh->m_prog.SetRange32(0,100);
    /* check if all parameters are there */
/*  if (argc!=3)
    {
        printf("Usage: fvs input.bmp output.bmp\n");
        return -1;
    }
*/
    mask      = ImageCreate();
    image     = ImageCreate();
    direction = FloatFieldCreate();
    frequency = FloatFieldCreate();
 
 
    if (mask!=NULL && image!=NULL && direction!=NULL && frequency!=NULL)
    {
 
    //  remplissage de la matrice emp associée à l'image empreinte
 
 
 
 
      ImportImage(image, input);
 
        /* normalize the image */
        (void)ImageNormalize(image, (FvsByte_t)128, (FvsUint_t)128*128);
 
 
        (void)FingerprintGetDirection(image, direction, 7, 2);
 
 
        (void)FingerprintGetFrequency(image, direction, frequency);
 
 
        (void)FingerprintGetMask(image, direction, frequency, mask);
 
        (void)ImageEnhanceGabor(image, direction, frequency, mask);
 
 
	      	ExportImage(image, output);
 
 
    }
 
 
}
//---------------------------------------------------------------------------
merci