mcpima.c

00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library is free software: you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation, either version 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00037 #include "image.h"    /* types des donnees manipulees dans ima2D */
00038 #include "proto2D.h"  /* descripteurs et prototypes des fonctions de ima2D */
00039 #include <stdlib.h>
00040 #include <limits.h> /* pour  USHRT_MAX ... */
00041 
00042 int main(int argc, char *argv[]){
00043 
00044 /* DECLARATIONS */
00045 
00046   /* images */ 
00047   imau1 im0u1, imresu1;
00048   imau2 im0u2, imresu2;
00049   imau4 im0u4, imresu4;
00050   imafl im0fl, imresfl;
00051 
00052   /* operateurs */
00053   read_ima_t rea;
00054   write_ima_t wri;   
00055 
00056   /* main : variables et parametres propres au main*/
00057   param par0, *ptp;      /* tete et pointeur pour la chaine de parametres */
00058   int i, j, t0, tres, nr, nc;      
00059   float v0, gain, offset;
00060   
00061 
00062   
00063 /* LECTURE PARAMETRES */
00064 
00065   /* debut: OBLIGATOIRE pour compatibilite avec les 3 modes de lecture de param */
00066   param_debut(argc, argv, &par0); 
00067   ptp = &par0;      /* regle : ptp pointe sur la structure du parametre suivant */
00068 
00069   /* operateurs: ptp est passe en argument, return fournit la nouvelle position */
00070   ptp = read_ima_lect(&rea, ptp, ">> entree format .ima | .ras (8b) | .imw|IMW | .iml|IML | .imf|IMF :");
00071   ptp = write_ima_lect(&wri, ptp, ">> sortie format .ima | .ras (8b) | .imw | .iml | .imf :");
00072 
00073   /* param du main */
00074   lec_param(">>mcpima, cefficient multiplicatif = gain (float)", ptp);
00075   gain = (float)atof(ptp->rep);
00076   ptp = ptp->next;
00077   lec_param(">>mcpima, cefficient aditif = offset (float)", ptp);
00078   offset = (float)atof(ptp->rep);
00079   ptp = ptp->next;
00080 
00081   /* fin: sauvegarde des parametres utilises en mode MANUEL ou FICHIER */
00082   param_fin(argc, argv, &par0);
00083 
00084 
00085 /* INITIALISATION  */
00086 
00087   /* image d'entree */
00088   if( !strcmp(rea.ext, "ima") || !strcmp(rea.ext, "ras") ){
00089       read_imau1_init(&rea, &im0u1);  
00090       nc = im0u1.nc;    
00091       nr = im0u1.nr;    
00092       t0 = 1;
00093   }
00094   else if( !strcmp(rea.ext, "imw") || !strcmp(rea.ext, "IMW") ){
00095       read_imau2_init(&rea, &im0u2);
00096       nc = im0u2.nc;    
00097       nr = im0u2.nr;    
00098       t0 = 2;
00099   }
00100   else if( !strcmp(rea.ext, "iml") || !strcmp(rea.ext, "IML") ){
00101       read_imau4_init(&rea, &im0u4);
00102       nc = im0u4.nc;    
00103       nr = im0u4.nr;    
00104       t0 = 3;
00105   }
00106   else if (!strcmp(rea.ext, "imf") || !strcmp(rea.ext, "IMF") ){
00107       read_imafl_init(&rea, &im0fl);
00108       nc = im0fl.nc;    
00109       nr = im0fl.nr;    
00110       t0 = 4;
00111   }
00112   else{
00113       printf("\nextension %s inconnue\n", rea.ext);
00114       exit(0);
00115   }      
00116   write_ima_init(&wri);
00117 
00118   /* image de sortie  */ 
00119   if( !strcmp(wri.ext, "ima") || !strcmp(wri.ext, "ras")){
00120       imresu1.nc = nc;
00121       imresu1.nr = nr;
00122       alloc_imau1(&imresu1);
00123       tres = 1;
00124   }
00125   else if(!strcmp(wri.ext, "imw")){
00126       imresu2.nc = nc;
00127       imresu2.nr = nr;
00128       alloc_imau2(&imresu2);
00129       tres = 2;
00130   }
00131   else if(!strcmp(wri.ext, "iml")){
00132       imresu4.nc = nc;
00133       imresu4.nr = nr;
00134       alloc_imau4(&imresu4);
00135       tres = 3;
00136   }
00137   else if(!strcmp(wri.ext, "imf")){
00138       imresfl.nc = nc;
00139       imresfl.nr = nr;
00140       alloc_imafl(&imresfl);
00141       tres = 4;
00142   }
00143   else{
00144       printf("\nextension %s inconnue\n", wri.ext);
00145       exit(0);
00146   }      
00147   
00148    
00149 /* CALCUL */
00150   /* prise en compte de la LUT en cas de 2 images 8 bits */
00151   if ( t0==1 && tres==1 ){
00152       imresu1.lutr = im0u1.lutr;
00153       imresu1.lutv = im0u1.lutv;
00154       imresu1.lutb = im0u1.lutb;
00155   }
00156 
00157   for(j=0; j<nr; j++)
00158       for(i=0; i<nc; i++){
00159           /* valeur initiale */
00160           switch(t0){
00161           case 1 :      
00162               v0 = (float)im0u1.p[j][i];
00163               break;
00164           case 2 :
00165               v0 = (float)im0u2.p[j][i];
00166               break;
00167           case 3 :
00168               v0 = (float)im0u4.p[j][i];
00169               break;
00170           case 4 :
00171               v0 = im0fl.p[j][i];
00172               break;
00173           }
00174           /* valeur resultat */
00175           v0 = v0*gain + offset;
00176           switch(tres){
00177           case 1 :
00178               v0 = v0 +0.5;
00179               if( v0 <= 0.)
00180                   imresu1.p[j][i] = 0;
00181               else if( v0 >= 256. )
00182                   imresu1.p[j][i] = 255;
00183               else
00184                   imresu1.p[j][i] = (pixu1)v0;
00185               break;
00186           case 2 :
00187               v0 = v0 +0.5;
00188               if( v0 <= 0.)
00189                   imresu2.p[j][i] = 0;
00190               else if( v0 >= USHRT_MAX+1 )
00191                   imresu2.p[j][i] = USHRT_MAX;
00192               else
00193                   imresu2.p[j][i] = (pixu2)v0;
00194               break;
00195           case 3 :
00196               v0 = v0 +0.5;
00197               if( v0 <= 0.)
00198                   imresu4.p[j][i] = 0;
00199               else if( v0 >= (float)UINT_MAX + 1.)
00200                   imresu4.p[j][i] = UINT_MAX;
00201               else
00202                   imresu4.p[j][i] = (pixu4)v0;
00203               break;
00204           case 4 :
00205               imresfl.p[j][i] = v0;
00206               break;
00207           }               
00208       }
00209 
00210 
00211 /* FREMETURE */
00212   switch(tres){
00213   case 1 :
00214       write_imau1_ferm(&wri, imresu1);
00215       break;
00216   case 2 :
00217       write_imau2_ferm(&wri, imresu2);
00218       break;
00219   case 3 :
00220       write_imau4_ferm(&wri, imresu4);
00221       break;
00222   case 4 :
00223       write_imafl_ferm(&wri, imresfl);
00224       break;
00225   }
00226 }
00227 

Generated on Tue Apr 22 13:31:04 2008 for ima2D by  doxygen 1.5.3