byte huge *getdump (long *size,void (* func)(double)) /*********** * Describe : принять дамп памяти прибора в память ЭВМ * Params : word *size - размер принятых данных (в байтах), меньше чем * : размер выделенной памяти, так как он выровнен * : на границу 1024 байта * : PFV func - функция для отображения считывания, ей * : передаем процент считанной информации * Return : byte huge* - указатель на буфер, куда записаны данные * Call : input,waitstart,setaddr,getKbyte,bioscom ***********/ { /* i-текущий адрес */ unsigned long volume,i_long; uint i=0,Imax=1024; /* Imax-макс. адрес */ byte empty,bufer[1024]; /* */ int err=0,rpt=0; /* */ byte huge *ppm=NULL,huge *cur=NULL; /* указатель на буфер */ // считываем базовый адрес порта base_addr = *((unsigned far *)((unsigned far *)0x00400000L+connect_port)); if (base_addr==0) // СОМ1 в 40:00 СОМ2 в 42:00 {printf("\nCOM-%d is absent!",connect_port); return 0; } // bioscom (0,SETTINGS,connect_port); /* инициализируем COM */ outportb (base_addr+3,0x83); // 8byt 1stop N outportb (base_addr,12); // скорость обмена 115200/12=9600 outportb (base_addr+1,0); outportb (base_addr+3,0x03); // конец установки скорости empty = inportb (base_addr+4); outportb (base_addr+4,0); // Запрет прерывания от порта for (i_long=0L;i_long<Imax;i_long+=512L,cur=(byte huge *)cur+1024,i=(uint)i_long) { if (func!=NULL) /* */ func ((double)((double)i_long/(double)Imax)); /* рисуем прогресс */ sleep (1); do /* */ { /* */ setaddr(i); /* посылаем адрес начала */ err=waitstart(); /* ждем строки "STRT" */ if (err==0) /* если не ошибка то */ err=input(&empty); /* принимаем пустой байт */ if (err==0) /* если не ошибка и если */ if (i==0) /* первый Кбайт то */ err=getKbyte(bufer); /* принимаем в буфер */ else /* иначе */ { err=getKbyte(cur); /* принимаем в назначение */ if (*bufer!=*ppm) { printf ("\n There is problem, count = %u",(uint)i); abort (); } } if (err != 0) /* если ошибка */ { /* */ rpt++; /* число повторов */ if (rpt>REPEATS) /* */ { /* */ if (ppm!=NULL) /* освобождаем память */ farfree ((byte far *)ppm); /* если выделена */ printf("\nCommunication ERROR %X",(unsigned)err); return (NULL); /* возвращаем ошибка */ } /* */ } /* */ } /* */ while (err!=0); /* */ /* */ if (i==0) /* если первый Кбайт */ { /* то */ Imax = (uint)bufer[8]+bufer[9]*256; /* вычисляем Imax */ *size = (long)Imax*2L; /* размер в байтах */ volume = (unsigned long)(*size)+1024; /* выделяем 128 Кбайт */ ppm=(byte huge*) farcalloc(volume,sizeof(byte));/* выделяем память */ cur = ppm; if (ppm==NULL) { printf ("\n Imax = %u, size = %ld",Imax,(*size)); printf ("\n No enough memory! Function GETDUMP. "); printf ("\n %ul bytes free. ",farcoreleft()); abort (); } reportmemory(getmaxx(),getmaxy()-textheight("X")-5); memcpy ((byte *)ppm,bufer,1024); /* копируем из буфера */ } /* */ } /* */ if (func!=NULL) /* */ func ((double)1.0); /* рисуем прогресс */ return ((byte huge*) ppm); /* */ } /* */
void ReservaAreas ( void ) { PtrVol = (float far*)farcalloc ( 2 * NUMMAXPONTOSINF + 2 , sizeof ( *PtrVol ) ); areaEsp = (float far*)farcalloc ( NUMMAXPONTOS , sizeof ( *areaEsp ) ); areaVVM = (float far*)farcalloc ( NUMMAXPONTOSINF , sizeof ( *areaVVM ) ); areaTampao = (float far*)farcalloc ( NUMMAXPONTOS , sizeof ( *areaTampao ) ); areaEspInt = (float far*)farcalloc ( NUMMAXPONTOS + 2 , sizeof ( *areaEspInt ) ); areaVVMInt = (float far*)farcalloc ( NUMMAXPONTOSINF + 2 , sizeof ( *areaVVMInt ) ); areaTampaoInt = (float far*)farcalloc ( NUMMAXPONTOS + 2 , sizeof ( *areaTampaoInt ) ); areaFluxPreBD = (float far*)farcalloc ( 2 * NUMMAXPONTOSINF + 2 , sizeof ( *areaFluxPreBD ) ); areaFluxPosBD = (float far*)farcalloc ( 2 * NUMMAXPONTOSINF + 2 , sizeof ( *areaFluxPosBD ) ); Path = (char*)calloc ( 80 , sizeof ( *Path ) ); comentario = (char*)calloc (352 , sizeof ( *comentario ) ); if ((PtrVol == NULL) || (areaEsp == NULL) || (areaVVM == NULL) || (areaTampao == NULL) || (areaEspInt == NULL) || (areaVVMInt == NULL) || (areaTampaoInt == NULL) || (areaFluxPreBD == NULL) || (areaFluxPosBD == NULL) || (Path == NULL) || (comentario == NULL)) ErroFatal (); *ApontEspirometria = NULL; *ApontVVM = NULL; *ApontFluxPreBD = NULL; *ApontFluxPosBD = NULL; }
void main(void) { int gd=CGA, gm=CGAHI, errorcode, size; //CGA графика с высоким разрешением void far *image; FILE *file; initgraph (&gd,&gm,"e:\\bc\\bgi\\"); errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getchar(); exit(-1); /* return with error code */ } //setbkcolor (1); // выбираем цвета setcolor (BLACK); // рисуем картинку bar(0,0,100,100); line(0,0,10,0); line(1,1,7,1); line(2,2,8,2); line(3,3,5,3); line(9,3,10,3); line(4,4,4,4); line(11,4,12,4); //line(10,5,11,5); getchar(); size = imagesize(0,0,12,4); // записываем ее в файл .img image = farcalloc (1,size); getimage(0,0,12,4,image); file = fopen ("scur07.img","wb"); fwrite (image,size,1,file); fclose(file); farfree(image); closegraph(); }
asRecPtr huge *readmemory (asHeadPtr *hdr,void (* func)(double)) /*********** * Describe : Функция чтения памяти высокого уровня * Params : asHeadPtr *hdr - указ. на указ. на asHeader * : void (* func)(double) - функция для отображения считывания, ей * : передаем процент считанной информации * Return : asRecPtr * - массив указателей на записи в памяти * Call : getdump,numrec,addr ***********/ { /* */ uint last,j,i,n,off; /* */ long size; /* */ byte huge *f_s,huge *s_s; asRecPtr huge *rec = NULL; /* массив указ. */ static byte tmp[2048]; /* на запись */ *hdr = (asHeadPtr) getdump (&size,func); /* принимаем */ if (*hdr==NULL) { printf ("\n Error in readmemory 1: No enough memory! "); abort (); } rec = (asRecPtr huge *) farcalloc ((*hdr)->numrec-1,sizeof(asRecPtr)); if (rec==NULL) { printf ("\n Error in readmemory 2: No enough memory! "); abort (); } reportmemory(getmaxx(),getmaxy()-textheight("X")-5); f_s = (byte huge *) (*hdr); /* 1 половина */ s_s = (byte huge *) (*hdr)+65536L; /* 2 половина по */ for (i=0;i<((*hdr)->numrec)-1;i++) /* 64 Кбайта */ { drawprogress ( (double) i / (((*hdr)->numrec) - 1) ); off = (uint)((*hdr)->addr)[i]; /* смещение */ if ((uint)off>(uint)65534) /* нереальный адрес записи */ { rec[i] = (asRecPtr) ((byte huge *)NULL); continue; } if ((uint)off>(uint)32767) /* во 2 пол. */ rec[i] = (asRecPtr) ((byte huge *)s_s+((uint)off-32768)*2);/* */ else /* в 1 пол. */ rec[i] = (asRecPtr) ((byte huge *)f_s+(uint)off*2); /* */ if (rec[i]->number > 2048) rec[i]->number = 2048; if ((issignal(rec[i]))&&(rec[i]!=NULL)) { rec[i]->number = rec[i]->dimfft; for (n=0;n<(rec[i])->number;n+=2) /* четные номера */ tmp[n] = ((byte *)rec[i]->y)[n/2]; for (n=1;n<(rec[i])->number;n+=2) /* нечетные номера */ tmp[n] = ((byte *)rec[i]->y)[(uint)((rec[i])->number+n)/2]; memcpy ((byte *)rec[i]->y,(byte *)tmp,(size_t)(rec[i])->number); } else if (rec[i]!=NULL) rec[i]->mnoj-=3; rec[i]->res1 = 0; /* нулевые байты после имени */ for (last=7;((last>0)&&((rec[i]->name)[last]==' '));last--) ; /* нашли последнюю букву - не пробел */ for (;((last>0)&&((rec[i]->name)[last]!=' '));last--) ; /* нашли последний пробел */ if (last!=0) /* если все же нашли */ for (j=last;(rec[i]->name)[j]!=0;j++) switch ((rec[i]->name)[j]) { case 'a': case 'A': ((rec[i]->name)[j])='x'; break; case 'b': case 'B': ((rec[i]->name)[j])='y'; break; case 'w': case 'W': ((rec[i]->name)[j])='z'; break; default : break; } } drawprogress ((double)1.00); return ((asRecPtr huge *)rec); /* */ } /* */
void PushRect(rect * R, int *err) { /* We don't really use ERR, but its for compatibility */ savelist *lastsave = savetail; long savesize = ImageSize(R); /* And we don't give a shit about size. */ savetail = farcalloc(sizeof(savelist), 1L); savetail->prev = lastsave; savetail->im = NULL; if (memok(savesize)) { safe_alloc = 1; savetail->im = (image far *) farcalloc(savesize, 1L); } savetail->R = farmalloc(sizeof(rect)); *(savetail->R) = *R; if (!savetail->im) { char tbuf[128]; char tbuf2[128]; FILE *fd; image *tmp; char *pathname = getenv("TMP"); unsigned char drive; struct dfree dtable; long dfree; #ifdef AXTDEBUG printf("\nLook out, I'm pushing to disk."); #endif /* Find out if there is enough space left on the thing */ if (pathname && access(pathname,0)) pathname = NULL; if (pathname && pathname[1] == ':') drive = toupper(pathname[0]) - 'A' + 1; else drive = 0; getdfree(drive, &dtable); if (dtable.df_sclus == 0xffff && drive) { drive = 0; getdfree(drive, &dtable); pathname = NULL; /* and so this doesn't happen again */ putenv("TMP="); } dfree = (long) dtable.df_avail * (long) dtable.df_bsec * (long) dtable.df_sclus; if (dfree > savesize) { rect R1; sprintf(tbuf, "%lx.dat", savetail); TempFileName(tbuf2, tbuf); fd = fopen(tbuf2, "wb"); if (fd) { int i; unsigned long cl = farcoreleft(); int lines; long n; if (cl > 2048L) cl -= 2048L; /* Safety margin */ R1 = *R; R1.Ymax = R1.Ymin; i = 1; while (i < R->Ymax) { R1.Ymax = R1.Ymin + i; n = ImageSize(&R1); if (n < cl) { savesize = n; lines = i; } i *= 2; } /* * Let's see how many rows at a time we can * save */ savetail->lines = lines; savetail->blocks = (R->Ymax - R->Ymin + 1) / lines; tmp = farmalloc(savesize); //setvbuf(fd, (char *) tmp, _IOFBF, (size_t) savesize); R1 = *R; R1.Ymax = R1.Ymin + lines - 1; for (i = R->Ymin; i <= R->Ymax; i += lines) { R1.Ymax = min(R1.Ymax, R->Ymax); ReadImage(&R1, tmp); fwrite(tmp, 1, (int) ImageSize(&R1), fd); OffsetRect(&R1, 0, lines); } fclose(fd); farfree(tmp); tmp = NULL; savetail->filename = strdup(tbuf2); *err = 0; return; } } sprintf(tbuf, "Can't allocate %ld bytes", savesize); ErrorBox(tbuf); *err = 1; farfree(savetail->R); savetail->R = NULL; farfree(savetail); savetail = NULL; savetail = lastsave; } else { ReadImage(savetail->R, savetail->im); *err = 0; } }
byte huge *getdump (long *size,void (* func)(double)) /*********** * Describe : принять дамп памяти прибора в память ЭВМ * Params : word *size - размер принятых данных (в байтах), меньше чем * : размер выделенной памяти, так как он выровнен * : на границу 1024 байта * : PFV func - функция для отображения считывания, ей * : передаем процент считанной информации * Return : byte huge* - указатель на буфер, куда записаны данные * Call : input,waitstart,setaddr,getKbyte,bioscom ***********/ { /* i-текущий адрес */ unsigned long volume,i_long; uint i=0,Imax=1024; /* Imax-макс. адрес */ byte bufer[1024]; /* */ int err=0,rpt=0; /* */ byte huge *ppm=NULL,huge *cur=NULL; /* указатель на буфер */ /* */ fout=fopen("memory.bin","rb"); if (fout==NULL) { printf ("\n Can't found file memory.bin. " "\n Try find it in current directory. "); abort (); } for (i_long=0L;i_long<Imax;i_long+=512L,cur=(byte huge *)cur+1024,i=(uint)i_long) { if (func!=NULL) /* */ func ((double)((double)i_long/(double)Imax)); /* рисуем прогресс */ do /* */ { /* */ if (err<=8) /* если не ошибка и если */ if (i==0) /* первый Кбайт то */ err=getKbyte(bufer); /* принимаем в буфер */ else /* иначе */ { err=getKbyte(cur); /* принимаем в назначение */ if (*bufer!=*ppm) { printf ("\n There is problem, count = %u",(uint)i); abort (); } } if (err>8) /* если ошибка */ { /* */ rpt++; /* число повторов */ if (rpt>REPEATS) /* */ { /* */ if (ppm!=NULL) /* освобождаем память */ farfree ((byte far *)ppm); /* если выделена */ return (NULL); /* возвращаем ошибка */ } /* */ } /* */ } /* */ while (err>8); /* */ /* */ if (i==0) /* если первый Кбайт */ { /* то */ Imax=(uint) bufer[8]+bufer[9]*256; /* вычисляем Imax */ *size=(long) Imax*2L; /* размер в байтах */ volume=(unsigned long) (*size)+1024L; /* выравненный по 1024 б */ ppm=(byte huge*) farcalloc(volume,sizeof(byte));/* выделяем память */ cur = ppm; if (ppm==NULL) { printf ("\n Imax = %u, size = %ld",Imax,(*size)); printf ("\n No enough memory! Function GETDUMP. "); printf ("\n %ul bytes free. ",farcoreleft()); abort (); } memcpy ((byte *)ppm,bufer,1024); /* копируем из буфера */ } /* */ } /* */ if (func!=NULL) /* */ func ((double)1.0); /* рисуем прогресс */ fclose (fout); return ((byte huge*) ppm); /* */ } /* */
void main( int argc, char *argv[]) { int gdriver = DETECT, gmode, errorcode; UL pos,m; int x,y,couleur,i; if (argc != 2) { printf("Finger Recognition Module Version 1.01\n"); printf("Usage is : FingRun <file.bmp>\n"); exit(1); } // recopie des paramŠtres xwin = 3; ywin = 3; // initialise le mode graphique initgraph(&gdriver, &gmode, ""); errorcode = graphresult(); if (errorcode != grOk) // erreur d‚tect‚e { Erreur = ErreurGraphique; printf("Erreur Graphique Code Nø %d \n",Erreur); exit(1); } if ((out = fopen("resu.dat", "wt"))== NULL) { fprintf(stderr, "Erreur … l'ouverture de Resu.dat\n"); exit(-1); } MaxX = getmaxx(); MaxY = getmaxy(); // Lecture du fichier image f_lectureFichier (argv[1],&Image); // Allocation de m‚moire pour les images ImageOut = (int huge*) farcalloc(Image.ligne*Image.colonne,(UL)sizeof(int)); if (ImageOut == NULL) { printf("Not enough memory for Image buffer allocation\n"); exit(-4); } Image2 = (int huge*) farcalloc(Image.ligne*Image.colonne,(UL)sizeof(int)); if (Image2 == NULL) { printf("Not enough memory for Image buffer allocation\n"); exit(-4); } // Initialisation de ImageOut, Image2 … z‚ro InitImage(ImageOut); InitImage(Image2); // Affiche ImageOut ViewZoom(ImageInit); // ImageOut=ImageInit CopyImage(ImageOut,ImageInit); // Erosion de ImageInit : r‚sultat = ImageOut erosion(ImageInit,ImageOut); free(ImageInit); // Image2 = ImageOut CopyImage(Image2,ImageOut); // D‚termine contour de ImageOut : r‚sultat dans Image2 contour(ImageOut,Image2); // Groupe pixel 45ø 135ø CopyImage(ImageOut,Image2); groupe(Image2,ImageOut); CopyImage(Image2,ImageOut); // Erosion du contour sur Image2 erosion2(4,Image2); // Init de ImageOut InitImage(ImageOut); // D‚finir le orientations de l'empreinte : r‚sultat dans ImageOut CopyImage(ImageOut,Image2); New_directions2(Image2,ImageOut); // Copie ImageOut dans Image2 CopyImage(Image2,ImageOut); // Erosion de ImageOut : r‚sultat dans Image2 erosion3(ImageOut,Image2); free(ImageOut); free(Image2); lin=Image.ligne; col=Image.colonne; // ZONE GLOBALE nbpix=0; v=0.0; matrix_co4d(Image2,0, 0, lin, col, mat5); for (x=yellow; x<=blue; x++) { for (y=yellow; y<=blue; y++) { if (nbpix) v= (float)mat5[y][x] / (float)nbpix; fprintf(out,"%2.5f ",v); } } // ZONE 1 nbpix=0; v=0.0; matrix_co4d(Image2, 0, 0, lin/2, col/2,mat); for (x=yellow; x<=blue; x++) { for (y=yellow; y<=blue; y++) { if (nbpix) v = (float)mat[y][x] / (float)nbpix; fprintf(out,"%2.5f ",v); } } // ZONE 2 nbpix=0; v=0.0; matrix_co4d(Image2, 0, 1+col/2, lin/2 ,col, mat2); for (x=yellow; x<=blue; x++) { for (y=yellow; y<=blue; y++) { if (nbpix) v= (float)mat2[y][x] / (float)nbpix; fprintf(out,"%2.5f ",v); } } // ZONE 3 nbpix=0; v=0.0; matrix_co4d(Image2,1+lin/2, 0, lin, col/2, mat3); for (x=yellow; x<=blue; x++) { for (y=yellow; y<=blue; y++) { if (nbpix) v= (float)mat3[y][x] / (float)nbpix; fprintf(out,"%2.5f ",v); } } // ZONE 4 nbpix=0; v=0.0; matrix_co4d(Image2,1+lin/2, 1+col/2, lin, col, mat4); for (x=yellow; x<=blue; x++) { for (y=yellow; y<=blue; y++) { if (nbpix) v= (float)mat4[y][x] / (float)nbpix; fprintf(out,"%2.5f ",v); } } message("Tapez une touche"); fprintf(out,"%s\n",argv[1]); fclose(out); closegraph(); system("neuro2 test.con"); system("show.exe"); system("del test.out"); }
// fonction de Lecture d'un fichier image BMP int f_lectureFichier (char* fichier, struct taille *FileImage) { FILE *streamIn; int i,j; int couleur; struct { UL ligne; UL colonne; } dimension; long filesize; unsigned hauteur, largeur; unsigned char *bufferfile=NULL; int nbOctetParLigne; int posdep; UL pos1,pos2; // Contr“le du fichier en entr‚e if ((streamIn = fopen (fichier,"rb")) == NULL) { outtext("Error : cannot open BMP file \n"); exit(-1); } filesize = filelength(fileno(streamIn)); // Allocation m‚moire pour lecture du fichier bufferfile = malloc (30); if (bufferfile == NULL) { printf("Erreur : allocation de m‚moire insuffisante\n"); exit(-3); } if (!fread(bufferfile,30,1,streamIn)) { outtext("Error : reading BMP file"); exit(-2); } // Nombre de colonnes memcpy (&largeur, bufferfile + 18,2); // Nombre de lignes memcpy (&hauteur, bufferfile + 22,2); // Ecriture dans le fichier de sortie // du nombre de lignes et colonnes ( zone entˆte ) dimension.ligne = hauteur; dimension.colonne = largeur; FileImage->colonne = dimension.colonne; FileImage->ligne = dimension.ligne; // D‚placement … la zone des donn‚es pixels memcpy (&posdep, bufferfile + 10,2); free (bufferfile); // Nombre d'octets par ligne nbOctetParLigne = (filesize - posdep) / hauteur; if ((bufferfile = malloc (nbOctetParLigne)) == NULL) { printf("Erreur : allocation m‚moire insuffisante\n"); exit(-3); } // Lecture des pixels dans le fichier BMP ImageInit = (int huge*) farcalloc (dimension.ligne * dimension.colonne,(UL) sizeof(int)); if (ImageInit == NULL) exit(-4); for (i = 0; i < hauteur; i++) { filesize = filesize - nbOctetParLigne; if (fseek (streamIn,filesize,SEEK_SET)) break; if ( !fread (bufferfile,nbOctetParLigne,1,streamIn)) break; pos2 = (UL)i * dimension.colonne; for (j = 0; j < largeur; j++) { if (j % 2) { couleur = bufferfile[j / 2] & 0x0F; } else { couleur = (bufferfile[j / 2] & 0xF0) >> 4; } pos1 = pos2 + (UL) j; if (!couleur) { *(ImageInit + pos1) = WHITE; } else *(ImageInit + pos1) = BLACK; } } // Lib‚ration de la m‚moire et fermeture de fichier free(bufferfile); fclose (streamIn); return(0); }