mcpima_no_pal.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 */
00019 
00036 #include "image.h"    /* types des donnees manipulees dans ima2D */
00037 #include "proto2D.h"  /* descripteurs et prototypes des fonctions de ima2D */
00038 #include <stdlib.h>
00039 #include <limits.h> /* pour  USHRT_MAX ... */
00040 
00041 int main(int argc, char *argv[]){
00042 
00043 /* DECLARATIONS */
00044 
00045   /* images */ 
00046   imau1 im0u1, imresu1;
00047   imau2 im0u2;
00048   imafl im0fl;
00049 
00050   /* operateurs */
00051   read_ima_t rea;
00052   write_ima_t wri;   
00053 
00054   /* main : variables et parametres propres au main*/
00055   param par0, *ptp;      /* tete et pointeur pour la chaine de parametres */
00056   int i, j, t0, tres, nr, nc;      
00057   pixu2 tmpu2;
00058   pixfl tmpfl;
00059 
00060   
00061 /* LECTURE PARAMETRES */
00062 
00063   /* debut: OBLIGATOIRE pour compatibilite avec les 3 modes de lecture de param */
00064   param_debut(argc, argv, &par0); 
00065   ptp = &par0;      /* regle : ptp pointe sur la structure du parametre suivant */
00066 
00067   /* operateurs: ptp est passe en argument, return fournit la nouvelle position */
00068   ptp = read_ima_lect(&rea, ptp, ">> entree format .ima | .ras (8b) | .imw | .imf :");
00069   ptp = write_ima_lect(&wri, ptp, ">> sortie format .ras (8b) :");
00070 
00071   /* fin: sauvegarde des parametres utilises en mode MANUEL ou FICHIER */ 
00072   param_fin(argc, argv, &par0);
00073 
00074 
00075 /* INITIALISATION  */
00076 
00077   /* operateur */
00078   if( !strcmp(rea.ext, "ima") || !strcmp(rea.ext, "ras")){
00079       read_imau1_init(&rea, &im0u1);   
00080       nc = im0u1.nc;    
00081       nr = im0u1.nr;    
00082       t0 = 1;
00083   }
00084   else if(!strcmp(rea.ext, "imw")){
00085       read_imau2_init(&rea, &im0u2);
00086       nc = im0u2.nc;    
00087       nr = im0u2.nr;    
00088       t0 = 2;
00089   }
00090   else if(!strcmp(rea.ext, "imf")){
00091       read_imafl_init(&rea, &im0fl);
00092       nc = im0fl.nc;    
00093       nr = im0fl.nr;    
00094       t0 = 4;
00095   }
00096   else{
00097       printf("\nextension d'entree %s inconnue\n", rea.ext);
00098       exit(0);
00099   }      
00100   write_ima_init(&wri);
00101 
00102   /* main : en cas de variable a allouer/initialiser dans le main  */  
00103   if( strcmp(wri.ext, "ras")!=0 ) {
00104     printf("mauvais format de sortie!!\n" );
00105     exit(0);
00106   }
00107   imresu1.nc = nc;
00108   imresu1.nr = nr;
00109   alloc_imau1(&imresu1);
00110   tres = 1;
00111   
00112      
00113   
00114    
00115 /* CALCUL */   
00116   switch(t0){  
00117   case 1 :
00118       imresu1 = im0u1; 
00119       /*suppression purement et simplement de la palette*/
00120       imresu1.lutr = NULL; 
00121       imresu1.lutv = NULL; 
00122       imresu1.lutb = NULL; 
00123       break;  
00124   case 2 : 
00125     for(j=0; j<nr; j++)
00126       for(i=0; i<nc; i++)
00127         if( (tmpu2 = im0u2.p[j][i]) > 255)
00128           imresu1.p[j][i] = 255;
00129         else
00130           imresu1.p[j][i] = (pixu1)tmpu2;
00131     
00132     break;
00133   case 4 :
00134     for(j=0; j<nr; j++)
00135       for(i=0; i<nc; i++)
00136         if( (tmpfl = im0fl.p[j][i]+0.5) >= 256.)
00137           imresu1.p[j][i] = 255;
00138         else if(tmpfl < 0.)
00139           imresu1.p[j][i] = 0;
00140         else
00141           imresu1.p[j][i] = (pixu1)tmpfl;      
00142     
00143     break;
00144   }  
00145   
00146   /* FREMETURE */
00147   write_imau1_ferm(&wri, imresu1);
00148   
00149   
00150 }

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