00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "image.h"
00032 #include "proto2D.h"
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <ctype.h>
00036 #include <string.h>
00037
00038
00039
00069 int param_debut(int argc, char **argv, param *ptp){
00070 FILE *fp;
00071 char nom[200], l;
00072 param *ptpar, tmp_par;
00073
00074
00075 ptp->qst[0] = '\0';
00076 ptp->rep[0] = '\0';
00077 ptp->next = NULL;
00078 printf("\n\n\t\t >>> programme %s <<< \n\n", argv[0]);
00079
00080
00081 if(argc == 1){
00082 printf("\n>> param_debut, mode MANUEL\n");
00083 return(0);
00084 }
00085
00086 l = strlen(argv[1]);
00087 do
00088 l--;
00089 while(argv[1][l] != '.' && l>0);
00090
00091
00092 if( (argc == 2) && (strcmp(argv[1]+l, ".ctrl") == 0) ){
00093 if( (fp=fopen(argv[1], "r")) == NULL ){
00094 printf("\n>> ERREUR param_debut : fichier %s introuvable\n", argv[1]);
00095 exit(1);
00096 }
00097 l = 0;
00098 while( flec_param(fp, ptp) ){
00099 ptp = ptp->next;
00100 l++;
00101 }
00102 printf("\n>> param_debut, mode FICHIER : %d parametres lus dans %s\n", l, argv[1]);
00103 fclose(fp);
00104 return(0);
00105 }
00106
00107
00108 for(l=1; l<argc; l++){
00109 ptp->qst[0] = '\0';
00110 strcpy(ptp->rep, argv[l]);
00111 alloc_param(ptp);
00112 ptp = ptp->next;
00113 }
00114 printf("\n>> param_debut, mode AUTO : %d parametres passes en ligne\n", argc-1, argv[1]);
00115 return(0);
00116 }
00117
00118
00130 int param_fin(int argc, char **argv, param *ptp){
00131 FILE *fp;
00132 char nom[200];
00133 int l;
00134
00135 if( argc == 1 )
00136 sprintf(nom, "%s.ctrl", argv[0]);
00137 else if ( argc == 2 ){
00138 l = strlen(argv[1]);
00139 do
00140 l--;
00141 while(argv[1][l] != '.' && l>0);
00142 if(strcmp(argv[1]+l, ".ctrl") == 0)
00143 strcpy(nom, argv[1]);
00144 else
00145 return(0);
00146 }
00147 else
00148 return(0);
00149
00150 lec_nom(nom, ">> param_fin : fichier de sauvegarde des nouveaux parametres");
00151 l = strlen(nom);
00152 do
00153 l--;
00154 while(nom[l] != '.' && l>0);
00155 if( l == 0 )
00156 strcat(nom, ".ctrl");
00157 else if (strcmp(nom+l, ".ctrl") != 0){
00158 strcat(nom, ".ctrl");
00159 printf("\n>> ATT param_fin : extension erronee, .ctrl ajoutee => %s\n",
00160 nom);
00161 }
00162 if( (fp=fopen(nom, "w")) == NULL ){
00163 printf("\n>> ERREUR param_fin : fichier %s inouvable\n", nom);
00164 exit(1);
00165 }
00166 while(ptp->qst[0] != '\0' && ptp->rep[0] != '\0'){
00167 fprintf(fp, "%s\t\t#%s\n", ptp->rep, ptp->qst);
00168 ptp = ptp->next;
00169 }
00170 fclose(fp);
00171 return(0);
00172 }
00173
00174
00175
00189 void lec_param(char *chaine, param *ptp){
00190 char replue[200];
00191
00192
00193 if( (ptp->qst[0] == '\0') && (ptp->rep[0] == '\0') ){
00194 strcpy(ptp->qst, chaine);
00195 do{
00196 printf("\n%s? : ", ptp->qst);
00197 fgets(ptp->rep, 199, stdin);
00198
00199 if(ptp->rep[strlen(ptp->rep)-1] == '\n')
00200 ptp->rep[strlen(ptp->rep)-1] = '\0';
00201
00202 }while( ptp->rep == '\0' );
00203 }
00204
00205 else if ( (ptp->qst[0] != '\0') && (ptp->rep[0] != '\0') ){
00206 if( strcmp(ptp->qst, chaine) ){
00207 printf("\nATT lec_param : questions differentes : \n\t- fichier .ctrl => %s\n\t- source C => %s\n",
00208 ptp->qst, chaine);
00209
00210 strcpy(ptp->qst, chaine);
00211 }
00212 printf("\n%s? [%s] : ", ptp->qst, ptp->rep);
00213 fgets(replue, 199, stdin);
00214
00215 if(replue[strlen(replue)-1] == '\n')
00216 replue[strlen(replue)-1] = '\0';
00217
00218 if( replue[0] != '\0')
00219 strcpy(ptp->rep, replue);
00220 }
00221
00222 else if ( (ptp->qst[0] == '\0') && (ptp->rep[0] != '\0') ){
00223 printf("\n%s = %s\n", chaine, ptp->rep);
00224 }
00225
00226 else{
00227 printf("\nERREUR lec_param : qst=%s, rep=%s\n", ptp->qst, ptp->rep);
00228 }
00229 if( ptp->next == NULL )
00230 alloc_param(ptp);
00231 }
00232
00233
00246 int flec_param(FILE *fp, param *ptp){
00247 char tmpc;
00248 int i=-1;
00249
00250 if( fscanf(fp, "%s", ptp->rep) == 0 )
00251 return(0);
00252
00253 do
00254 tmpc = (char)fgetc(fp);
00255 while( tmpc != '#' && tmpc != EOF );
00256 if(tmpc == EOF)
00257 return(0);
00258
00259 do{
00260 i++;
00261 ptp->qst[i] = (pixu1)fgetc(fp);
00262 }while( ptp->qst[i]!='\n' && ptp->qst[i]!=EOF && i<199 );
00263 if(ptp->qst[i] == EOF)
00264 return(0);
00265
00266 if( i == 199 ){
00267 printf("\n ATT flec_param : question trop longue (>199 caracteres)\n");
00268 do
00269 tmpc = (pixu1)fgetc(fp);
00270 while( tmpc != '\n' && tmpc != EOF);
00271 }
00272 ptp->qst[i] = '\0';
00273
00274 if( ptp->next == NULL )
00275 alloc_param(ptp);
00276 return(1);
00277 }
00278
00279
00291 void alloc_param(param *ptp){
00292
00293 if( (ptp->next = (param*)malloc(sizeof(param))) == NULL ){
00294 printf ("\nERREUR alloc_param : allocation impossible\n");
00295 exit(1);
00296 }
00297 ptp->next->qst[0] = '\0';
00298 ptp->next->rep[0] = '\0';
00299 ptp->next->next = NULL;
00300 }
00301
00302
00303
00304
00313 void lec_int(int *pt_i, char *chaine){
00314 char rep[200];
00315
00316 printf("\n%s? [%d] : ", chaine, *pt_i);
00317 fgets(rep, 199, stdin);
00318
00319 if(rep[strlen(rep)-1] == '\n')
00320 rep[strlen(rep)-1] = '\0';
00321
00322 if (rep[0] != '\0')
00323 *pt_i = atoi(rep);
00324 }
00325
00334 void lec_float(float *pt_f, char *chaine){
00335 char rep[200];
00336
00337 printf("\n%s? [%.3f] : ", chaine, *pt_f);
00338 fgets(rep, 199, stdin);
00339
00340 if(rep[strlen(rep)-1] == '\n')
00341 rep[strlen(rep)-1] = '\0';
00342 if (rep[0] != '\0')
00343 *pt_f = (float)atof(rep);
00344 }
00345
00354 void lec_double(double *pt_d, char *chaine){
00355 char rep[200];
00356
00357 printf("\n%s? [%.3f] : ", chaine, *pt_d);
00358 fgets(rep, 199, stdin);
00359
00360 if(rep[strlen(rep)-1] == '\n')
00361 rep[strlen(rep)-1] = '\0';
00362 if (rep[0] != '\0')
00363 *pt_d = atof(rep);
00364 }
00365
00374 void lec_nom(char *pt_nom, char *chaine){
00375 char rep[200];
00376
00377 printf("\n%s? [%s] : ", chaine, pt_nom);
00378 fgets(rep, 199, stdin);
00379
00380 if(rep[strlen(rep)-1] == '\n')
00381 rep[strlen(rep)-1] = '\0';
00382 if (rep[0] != '\0')
00383 strcpy(pt_nom, rep);
00384 }
00385
00386
00407 int nom_image_suivante( char *nom0, char *nomres){
00408
00409 int l, n;
00410 char *ptnum;
00411
00412 strcpy(nomres, nom0);
00413 l = strlen(nom0);
00414 if( isdigit( nom0[l-2] ) ) {
00415 ptnum = nom0 + l - 2;
00416 n = atoi(ptnum) + 1;
00417 ptnum = nomres + l - 2;
00418 sprintf(ptnum, "%02d", n);
00419 return(2);
00420 }
00421 else if( isdigit( nom0[l-1] ) ) {
00422 ptnum = nom0 + l - 1;
00423 n = atoi(ptnum) + 1;
00424 ptnum = nomres + l - 1;
00425 sprintf(ptnum, "%d", n);
00426 if(n>9){
00427 printf("\n>>nom_image_suivante : ATT, la numerotation passe de 1 a 2 chiffres:\n");
00428 printf("\t nom initial : %s\n", nom0);
00429 printf("\t nom suivant : %s\n", nomres);
00430 }
00431 return(1);
00432 }
00433 else{
00434 strcat(nomres, "_01");
00435 printf("\n>>nom_image_suivante : ATT, chaine %s incorrecte; nouveau nom : %s\n",
00436 nom0, nomres);
00437 return(0);
00438 }
00439
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00471 int alloc_imau1(imau1 *im){
00472 int j;
00473
00474
00475 if( (im->p = (pixu1 **)malloc(im->nr*sizeof(pixu1 *))) == NULL )
00476 {printf ("\n allocation image impossible\n"); exit(1);}
00477
00478
00479 if( (im->p[0] = (pixu1 *)malloc(im->nc*im->nr*sizeof(pixu1))) == NULL)
00480 {printf ("\n allocation image impossible\n"); exit(1); }
00481
00482
00483 for(j = 1; j < im->nr; j++)
00484 im->p[j] = im->p[0] + j*(im->nc);
00485
00486
00487 im->lutr = NULL;
00488 im->lutv = NULL;
00489 im->lutb = NULL;
00490
00491
00492 strcpy(im->nom, "");
00493 }
00494
00495
00496 int alloc_imarvb(imarvb *im){
00497 int j;
00498
00499
00500 if( (im->r = (pixu1 **)malloc(im->nr*sizeof(pixu1 *))) == NULL )
00501 {printf ("\n allocation image impossible\n"); exit(1);}
00502 if( (im->v = (pixu1 **)malloc(im->nr*sizeof(pixu1 *))) == NULL )
00503 {printf ("\n allocation image impossible\n"); exit(1);}
00504 if( (im->b = (pixu1 **)malloc(im->nr*sizeof(pixu1 *))) == NULL )
00505 {printf ("\n allocation image impossible\n"); exit(1);}
00506
00507
00508 if( (im->r[0] = (pixu1 *)malloc(im->nc*im->nr*sizeof(pixu1))) == NULL)
00509 {printf ("\n allocation image impossible\n"); exit(1); }
00510 if( (im->v[0] = (pixu1 *)malloc(im->nc*im->nr*sizeof(pixu1))) == NULL)
00511 {printf ("\n allocation image impossible\n"); exit(1); }
00512 if( (im->b[0] = (pixu1 *)malloc(im->nc*im->nr*sizeof(pixu1))) == NULL)
00513 {printf ("\n allocation image impossible\n"); exit(1); }
00514
00515
00516 for(j = 1; j < im->nr; j++){
00517 im->r[j] = im->r[0] + j*(im->nc);
00518 im->v[j] = im->v[0] + j*(im->nc);
00519 im->b[j] = im->b[0] + j*(im->nc);
00520 }
00521
00522
00523 strcpy(im->nom, "");
00524 }
00525
00526
00527 int alloc_imau2(imau2 *im){
00528 int j;
00529
00530
00531 if( (im->p = (pixu2 **)malloc(im->nr*sizeof(pixu2 *))) == NULL )
00532 {printf ("\n allocation image impossible\n"); exit(1);}
00533
00534
00535 if( (im->p[0] = (pixu2 *)malloc(im->nc*im->nr*sizeof(pixu2))) == NULL)
00536 {printf ("\n allocation image impossible\n"); exit(1); }
00537
00538
00539 for(j = 1; j < im->nr; j++)
00540 im->p[j] = im->p[0] + j*(im->nc);
00541
00542
00543 strcpy(im->nom, "");
00544 }
00545
00546
00547 int alloc_imas2(imas2 *im){
00548 int j;
00549
00550
00551 if( (im->p = (pixs2 **)malloc(im->nr*sizeof(pixs2 *))) == NULL )
00552 {printf ("\n allocation image impossible\n"); exit(1);}
00553
00554
00555 if( (im->p[0] = (pixs2 *)malloc(im->nc*im->nr*sizeof(pixs2))) == NULL)
00556 {printf ("\n allocation image impossible\n"); exit(1); }
00557
00558
00559 for(j = 1; j < im->nr; j++)
00560 im->p[j] = im->p[0] + j*(im->nc);
00561
00562
00563 strcpy(im->nom, "");
00564 }
00565
00566
00567
00568 int alloc_imau4(imau4 *im){
00569 int j;
00570
00571
00572 if( (im->p = (pixu4 **)malloc(im->nr*sizeof(pixu4 *))) == NULL )
00573 {printf ("\n allocation image impossible\n"); exit(1);}
00574
00575
00576 if( (im->p[0] = (pixu4 *)malloc(im->nc*im->nr*sizeof(pixu4))) == NULL)
00577 {printf ("\n allocation image impossible\n"); exit(1); }
00578
00579
00580 for(j = 1; j < im->nr; j++)
00581 im->p[j] = im->p[0] + j*(im->nc);
00582
00583
00584 strcpy(im->nom, "");
00585 }
00586
00587
00588
00589 int alloc_imas4(imas4 *im){
00590 int j;
00591
00592
00593 if( (im->p = (pixs4 **)malloc(im->nr*sizeof(pixs4 *))) == NULL )
00594 {printf ("\n allocation image impossible\n"); exit(1);}
00595
00596
00597 if( (im->p[0] = (pixs4 *)malloc(im->nc*im->nr*sizeof(pixs4))) == NULL)
00598 {printf ("\n allocation image impossible\n"); exit(1); }
00599
00600
00601 for(j = 1; j < im->nr; j++)
00602 im->p[j] = im->p[0] + j*(im->nc);
00603
00604
00605 strcpy(im->nom, "");
00606 }
00607
00608
00609 int alloc_imafl(imafl *im){
00610 int j;
00611
00612
00613 if( (im->p = (pixfl **)malloc(im->nr*sizeof(pixfl *))) == NULL )
00614 {printf ("\n allocation image impossible\n"); exit(1);}
00615
00616
00617 if( (im->p[0] = (pixfl *)malloc(im->nc*im->nr*sizeof(pixfl))) == NULL)
00618 {printf ("\n allocation image impossible\n"); exit(1); }
00619
00620
00621 for(j = 1; j < im->nr; j++)
00622 im->p[j] = im->p[0] + j*(im->nc);
00623
00624
00625 strcpy(im->nom, "");
00626 }
00627
00628
00629 int alloc_imadb(imadb *im){
00630 int j;
00631
00632
00633 if( (im->p = (pixdb **)malloc(im->nr*sizeof(pixdb *))) == NULL )
00634 {printf ("\n allocation image impossible\n"); exit(1);}
00635
00636
00637 if( (im->p[0] = (pixdb *)malloc(im->nc*im->nr*sizeof(pixdb))) == NULL)
00638 {printf ("\n allocation image impossible\n"); exit(1); }
00639
00640
00641 for(j = 1; j < im->nr; j++)
00642 im->p[j] = im->p[0] + j*(im->nc);
00643
00644
00645 strcpy(im->nom, "");
00646 }
00647
00648
00649 int alloc_imacx4(imacx4 *im){
00650 int j;
00651
00652
00653 if( (im->p = (pixcx4 **)malloc(im->nr*sizeof(pixcx4 *))) == NULL )
00654 {printf ("\n allocation image impossible\n"); exit(1);}
00655
00656
00657 if( (im->p[0] = (pixcx4 *)malloc(im->nc*im->nr*sizeof(pixcx4))) == NULL)
00658 {printf ("\n allocation image impossible\n"); exit(1); }
00659
00660
00661 for(j = 1; j < im->nr; j++)
00662 im->p[j] = im->p[0] + j*(im->nc);
00663
00664
00665 strcpy(im->nom, "");
00666 }
00667
00668
00669 int alloc_imacx8(imacx8 *im){
00670 int j;
00671
00672
00673 if( (im->p = (pixcx8 **)malloc(im->nr*sizeof(pixcx8 *))) == NULL )
00674 {printf ("\n allocation image impossible\n"); exit(1);}
00675
00676
00677 if( (im->p[0] = (pixcx8 *)malloc(im->nc*im->nr*sizeof(pixcx8))) == NULL)
00678 {printf ("\n allocation image impossible\n"); exit(1); }
00679
00680
00681 for(j = 1; j < im->nr; j++)
00682 im->p[j] = im->p[0] + j*(im->nc);
00683
00684
00685 strcpy(im->nom, "");
00686 }
00687
00688
00689 int alloc_imacx16(imacx16 *im){
00690 int j;
00691
00692
00693 if( (im->p = (pixcx16 **)malloc(im->nr*sizeof(pixcx16 *))) == NULL )
00694 {printf ("\n allocation image impossible\n"); exit(1);}
00695
00696
00697 if( (im->p[0] = (pixcx16 *)malloc(im->nc*im->nr*sizeof(pixcx16))) == NULL)
00698 {printf ("\n allocation image impossible\n"); exit(1); }
00699
00700
00701 for(j = 1; j < im->nr; j++)
00702 im->p[j] = im->p[0] + j*(im->nc);
00703
00704
00705 strcpy(im->nom, "");
00706 }
00707
00716 int alloc_imau1_as(imau1 *modele, imau1 *out){
00717 int j;
00718
00719 out->nr = modele->nr;
00720 out->nc = modele->nc;
00721
00722 out->lutr = modele->lutr;
00723 out->lutv = modele->lutv;
00724 out->lutb = modele->lutb;
00725
00726
00727 if( (out->p = (pixu1 **)calloc(out->nr, sizeof(pixu1 *))) == NULL )
00728 {printf ("\n allocation image impossible\n"); exit(1);}
00729
00730
00731 if( (out->p[0] = (pixu1 *)calloc(out->nc, out->nr*sizeof(pixu1))) == NULL)
00732 {printf ("\n allocation image impossible\n"); exit(1); }
00733
00734
00735 for(j = 1; j < out->nr; j++)
00736 out->p[j] = out->p[0] + j*(out->nc);
00737
00738
00739 strcpy(out->nom, modele->nom);
00740 }
00741
00742
00743
00744
00753 int free_imau1(imau1 *im){
00754 free(im->p[0]);
00755 free(im->p);
00756 }
00757 int free_imarvb(imarvb *im){
00758 free(im->r[0]); free(im->v[0]); free(im->b[0]);
00759 free(im->r); free(im->v); free(im->b);
00760 }
00761 int free_imau2(imau2 *im){
00762 free(im->p[0]);
00763 free(im->p);
00764 }
00765 int free_imas2(imas2 *im){
00766 free(im->p[0]);
00767 free(im->p);
00768 }
00769 int free_imau4(imau4 *im){
00770 free(im->p[0]);
00771 free(im->p);
00772 }
00773 int free_imas4(imas4 *im){
00774 free(im->p[0]);
00775 free(im->p);
00776 }
00777 int free_imafl(imafl *im){
00778 free(im->p[0]);
00779 free(im->p);
00780 }
00781 int free_imadb(imadb *im){
00782 free(im->p[0]);
00783 free(im->p);
00784 }
00785 int free_imacx4(imacx4 *im){
00786 free(im->p[0]);
00787 free(im->p);
00788 }
00789 int free_imacx8(imacx8 *im){
00790 free(im->p[0]);
00791 free(im->p);
00792 }
00793 int free_imacx16(imacx16 *im){
00794 free(im->p[0]);
00795 free(im->p);
00796 }