lconv_img.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 /* ************************* lconv_img.c ******************************/
00020 /*                                                                    */
00021 /* ********************************************************************/
00022 
00071   /* doc suivantes en sous-partie */  
00072 
00073 #include "image.h"
00074 #include "proto2D.h"
00075 #include "conv_img.h"
00076 #include <stdlib.h>
00077 
00078 
00079 void conv_TLS_RVB2(space_struct *des, imarvb *ima_tls, imarvb *ima_rvb)
00080 {
00081         unsigned char *ima_L,*ima_T,*ima_S;
00082         int Y,X;
00083         unsigned char *ima_R,*ima_V,*ima_B;
00084 
00085         unsigned char *R,*V,*B;
00086         unsigned char *L,*T,*S;
00087         double          L_f,T_f,S_f,R_f, V_f, B_f;      
00088         double          DEUX_PI;
00089         double          C1,C2,angle;
00090         double          Fact,F_1_3,F_2_3;
00091         register        i,j;
00092         
00093         ima_T = ima_tls->r[0];
00094         ima_L = ima_tls->v[0];
00095         ima_S = ima_tls->b[0];
00096         Y = ima_tls->nr;
00097         X = ima_tls->nc;
00098         ima_R = ima_rvb->r[0];
00099         ima_V = ima_rvb->v[0];
00100         ima_B = ima_rvb->b[0];
00101 
00102         R=ima_R;
00103         V=ima_V;
00104         B=ima_B;
00105         L=ima_L;
00106         T=ima_T;
00107         S=ima_S;
00108 
00109         DEUX_PI = 2*M_PI;
00110         F_1_3  = 1.0/3.0;
00111         F_2_3  = 2.0/3.0;
00112         Fact   = sqrt(3.0)/3.0;
00113 
00114         for(i=Y;i--;)
00115                 for(j=X;j--;)
00116                         {
00117 
00118                           /* ************************************* */
00119                           *T += (unsigned char) des->comp_a;
00120                           *L += (unsigned char) des->comp_b;
00121                           *S += (unsigned char) des->comp_c;
00122                           /* ************************************* */
00123 
00124                                                 /* Modif teinte */
00125                                 if( *T > 192)
00126                                     T_f = (double)((int)*T-255);
00127                                 else
00128                                         T_f = (double)*T;
00129                         
00130                                 L_f = (double)*L;
00131                                 S_f = (double)*S;
00132 
00133                                                 /* calcul de C1 et C2 */
00134                                 angle = T_f*DEUX_PI/255.0;
00135                                 C1 = S_f*cos(angle);
00136                                 C2 = S_f*sin(angle);
00137 
00138                                                 /* calcul de R,V,B      flotant*/
00139                                 R_f = (L_f + (F_2_3)*C1);
00140                                 V_f = (L_f - (F_1_3)*C1 + Fact*C2);
00141                                 B_f = (L_f - (F_1_3)*C1 - Fact*C2);
00142                                                 /* test si valeur non negative ou > 255 */
00143                                 if (R_f <0 )
00144                                         R_f = 0;
00145                                 if (R_f > 255)
00146                                         R_f = 255;
00147                                 if (V_f <0 )
00148                                         V_f = 0;
00149                                 if (V_f > 255)
00150                                         V_f = 255;
00151                                 if (B_f <0 )
00152                                         B_f = 0;
00153                                 if (B_f > 255)
00154                                         B_f = 255;
00155                                 /*
00156                                 *R = (unsigned char)irint(R_f);
00157                                 *V = (unsigned char)irint(V_f);
00158                                 *B = (unsigned char)irint(B_f);
00159                                 */
00160                                 *R = (unsigned char)rint(R_f);
00161                                 *V = (unsigned char)rint(V_f);
00162                                 *B = (unsigned char)rint(B_f);
00163 
00164                                                 /* Passage pixel suivant */
00165                                 R++,V++,B++;
00166                                 L++,T++,S++;
00167                         }
00168 }
00169 
00170 
00171 
00172 void  conv_RVB_TLS2(space_struct *des, imarvb *ima_rvb, imarvb *ima_tls)
00173 {
00174         unsigned char *ima_R,*ima_V,*ima_B;
00175         int Y,X;
00176         unsigned char *ima_L,*ima_T,*ima_S;
00177 
00178         unsigned char *R,*V,*B;
00179         unsigned char *L,*T,*S;
00180         double          DEUX_PI;
00181         double          C1,C2,calc_inter,double_T;
00182         double          Fact_T,Fact_C2;
00183         register        i,j;
00184 
00185 
00186         ima_R = ima_rvb->r[0];
00187         ima_V = ima_rvb->v[0];
00188         ima_B = ima_rvb->b[0];
00189         Y = ima_rvb->nr;
00190         X = ima_rvb->nc;
00191         ima_T = ima_tls->r[0];
00192         ima_L = ima_tls->v[0];
00193         ima_S = ima_tls->b[0];
00194 
00195         R=ima_R;
00196         V=ima_V;
00197         B=ima_B;
00198         L=ima_L;
00199         T=ima_T;
00200         S=ima_S;
00201 
00202         DEUX_PI = 2*M_PI;
00203         Fact_C2 = sqrt(3.0)/2.0;
00204         Fact_T = (double)(255.0 / DEUX_PI);     /* Norm Couleur entre 0..255 */
00205 
00206         for(i=Y;i--;)
00207                 for(j=X;j--;)
00208                         {
00209                                                 /* calcul de la luminance */
00210                                 ;
00211                                 /* *L=(unsigned char)irint(((double)*R + (double)*V  + (double)*B)/3.0 ); */
00212                                 *L=(unsigned char)rint(((double)*R + (double)*V  + (double)*B)/3.0 );
00213                                                 /* calcul facteur C1 et C2 */
00214                                 C1 = (double)(*R) - ((double)(*V) + (double)(*B)) / 2.0;
00215                                 C2 = ((double)(*V) - (double)(*B)) * Fact_C2;
00216 
00217                                                 /* Calcul de la teinte */
00218                                 if (C1 == 0.0)
00219                                 {
00220                                    if (C2 > 0)
00221                                       *T = 64;
00222                                    else
00223                                       *T = 192;
00224                                 }
00225                                 else
00226                                 {
00227                                    calc_inter = (double)C2 / (double)C1;
00228                                    if (C1 > 0.0) 
00229                                       double_T = atan(calc_inter) * Fact_T;
00230                                    else
00231                                   double_T = (M_PI + atan(calc_inter)) * Fact_T;
00232 
00233                                         if (double_T >= 0)
00234                                         {
00235                                                 if (double_T - (int)double_T < 0.4999)
00236                                                 {
00237                                                         *T = (unsigned char)((int)double_T );
00238                                                 }
00239                                                 else
00240                                                 {
00241                                                         *T = (unsigned char)((int)double_T + 1);
00242                                                 }
00243                                         }
00244                                         else
00245                                         {
00246                                                 if (double_T - (int)double_T  > 0.5)
00247                                                 {
00248                                                         *T = (unsigned char)(255 + (int)double_T + 1);
00249                                                 }
00250                                                 else
00251                                                 {
00252                                                         *T = (unsigned char)(255 + (int)double_T);
00253                                                 }
00254                         
00255                                         }
00256  
00257                                 }
00258 
00259                                                 /* Calcul de la saturation */
00260                                 calc_inter = (double)(C1) * (double)C1  + (double)(C2) * (double)C2;
00261                                 /* *S = (unsigned char)irint(sqrt(calc_inter)); */
00262                                 *S = (unsigned char)rint(sqrt(calc_inter));
00263 
00264                                  /* ************************************* */
00265                                 *T += (unsigned char) des->comp_a;
00266                                 *L += (unsigned char) des->comp_b;
00267                                 *S += (unsigned char) des->comp_c;
00268                                 /* ************************************* */
00269 
00270                                 des->comp0[i][j] = (double) *T;
00271                                 des->comp1[i][j] = (double) *L;
00272                                 des->comp2[i][j] = (double) *S;
00273 
00274                                 /* Passage pixel suivant */
00275                                 R++,V++,B++;
00276                                 L++,T++,S++;
00277                              
00278                         }
00279 }
00280 
00282 /*L'espace HSV*/
00283 
00284 
00285 double maxim(double i, double j)
00286 {
00287   if(i > j)
00288     return(i);
00289   else
00290     return(j);
00291 }
00292 
00293 double minim(double i, double j)
00294 {
00295   if(i < j)
00296     return(i);
00297   else
00298     return(j);
00299 }
00300 
00301 
00302 
00303 void  conv_RVB_HSV(space_struct *des, imarvb *ima_rvb)
00304 {
00305 
00306 unsigned char *ima_R, *ima_V, *ima_B;
00307 int Y, X;
00308 pixdb *ima_H, *ima_S, *ima_Val;
00309 
00310 unsigned char *R, *V, *B;
00311 pixdb *H, *S, *Val;
00312 
00313 double *RD, *VD, *BD, *HD, *SD, *ValD;
00314 
00315 register i, j;
00316 
00317 double imax, imin, rc, vc, bc;
00318 
00319 
00320         ima_R = ima_rvb->r[0];
00321         ima_V = ima_rvb->v[0];
00322         ima_B = ima_rvb->b[0];
00323         Y = ima_rvb->nr;
00324         X = ima_rvb->nc;
00325         ima_H = des->comp0[0];
00326         ima_S = des->comp1[0];
00327         ima_Val = des->comp2[0];
00328 
00329         R=ima_R;
00330         V=ima_V;
00331         B=ima_B;
00332         H=ima_H;
00333         S=ima_S;
00334         Val=ima_Val;
00335 
00336         RD = (double *)ima_R; VD = (double *) ima_V; BD = (double *) ima_B; 
00337         HD = (double *)ima_H; SD = (double *) ima_S; ValD = (double *) ima_Val; 
00338 
00339         for(i=Y;i--;)             
00340             for(j=X;j--;)
00341                 {
00342           
00343       *RD = (double)(*R);  *VD = (double)(*V);  *BD = (double)(*B);
00344       *RD = (*RD)/ 255.0;  *VD = (*VD)/ 255.0;  *BD = (*BD)/ 255.0;
00345 
00346            imax = maxim(*RD, maxim(*VD, *BD));
00347            imin = minim(*RD, minim(*VD, *BD));
00348            
00349  if (*RD<0.0 || *RD>1.0 || *VD<0.0 || *VD>1.0 || *BD<0.0 || *BD>1.0 ){
00350    printf("\nERROR: Les valeurs de *R, *V et *B sont dehors l'interval [0,1].");
00351    printf("\nOperateur:  conv_RVB_HSV() \n"); 
00352    exit(1);}
00353    
00354 
00355     *ValD = imax;
00356     if (imax != 0) {
00357         *SD = (imax - imin) / imax;
00358     } else {
00359         *SD = 0;
00360     }
00361 
00362     if (*SD == 0) {
00363         *HD = -1;
00364     } else {
00365         rc = (imax - *RD) / (imax - imin);
00366         vc = (imax - *VD) / (imax - imin);
00367         bc = (imax - *BD) / (imax - imin);
00368         if (*RD == imax) {
00369             *HD = bc - vc;
00370         } else if (*VD == imax) {
00371             *HD = 2.0 + rc - bc;
00372         } else {
00373             *HD = 4.0 + vc - rc;
00374         }
00375         *HD *= 60.0;
00376         if (*HD < 0.0) {
00377             *HD += 360.0;
00378         }
00379     }    
00380 
00381       *HD += des->comp_a;   *SD += des->comp_b;   *ValD += des->comp_c;
00382 
00383       des->comp0[i][j] = *HD; des->comp1[i][j] = *SD; des->comp2[i][j] = *ValD;
00384 
00385       R++, V++, B++;
00386       H++, S++, Val++;
00387      }
00388 }
00389 
00390 
00391 
00392 
00393 void conv_HSV_RVB(space_struct *des, imarvb *ima_rvb)
00394 {
00395   
00396 pixdb *ima_H, *ima_S, *ima_Val;
00397 unsigned char *ima_R, *ima_V, *ima_B;
00398 
00399 int Y, X;
00400 
00401 unsigned char *R, *V, *B;
00402 pixdb *H, *S, *Val;
00403 
00404 register i, j;
00405 int z;
00406 double f, p, q, t;
00407 
00408 double *RD, *VD, *BD, *HD, *SD, *ValD;
00409 
00410         ima_H = des->comp0[0];
00411         ima_S = des->comp1[0];
00412         ima_Val = des->comp2[0];
00413         Y = des->nr;
00414         X = des->nc;
00415         ima_R = ima_rvb->r[0];
00416         ima_V = ima_rvb->v[0];
00417         ima_B = ima_rvb->b[0];
00418         
00419         R=ima_R;
00420         V=ima_V;
00421         B=ima_B;
00422         H=ima_H;
00423         S=ima_S;
00424         Val=ima_Val;
00425 
00426         HD = (double *)ima_H; SD = (double *) ima_S; ValD = (double *) ima_Val; 
00427         RD = (double *)ima_R; VD = (double *) ima_V; BD = (double *) ima_B; 
00428 
00429    for(i=Y;i--;)
00430       for(j=X;j--;)
00431          {
00432       *HD = des->comp0[i][j];  *SD = des->comp1[i][j];  *ValD =  des->comp2[i][j];
00433       *HD += des->comp_a;      *SD += des->comp_b;      *ValD += des->comp_c;
00434 
00435     if (*SD == 0) {
00436         *RD = *VD = *BD = *ValD;
00437     } else {
00438         if (*HD == 360.0) {*HD = 0;}
00439 
00440         *HD /= 60.0;
00441 
00442         z = (int)floor(*HD);
00443         f = *HD - z;
00444         p = *ValD * (1.0 - *SD);
00445         q = *ValD * (1.0 - (*SD * f));
00446         t = *ValD * (1.0 - (*SD * (1.0 - f)));
00447 
00448         switch (z) {
00449             case 0:
00450                 *RD = *ValD;
00451                 *VD = t;
00452                 *BD = p;
00453                 break;
00454 
00455             case 1:
00456                 *RD = q;
00457                 *VD = *ValD;
00458                 *BD = p;
00459                 break;
00460 
00461             case 2:
00462                 *RD = p;
00463                 *VD = *ValD;
00464                 *BD = t;
00465                 break;
00466 
00467             case 3:
00468                 *RD = p;
00469                 *VD = q;
00470                 *BD = *ValD;
00471                 break;
00472 
00473             case 4:
00474                 *RD = t;
00475                 *VD = p;
00476                 *BD = *ValD;
00477                 break;
00478 
00479             case 5:
00480                 *RD = *ValD;
00481                 *VD = p;
00482                 *BD = q;
00483                 break;
00484          }
00485     }
00486 
00487      *RD = (*RD) * 255.0;     *VD = (*VD) * 255.0;     *BD = (*BD) * 255.0;
00488      *R = (unsigned char)(*RD); *V = (unsigned char)(*VD); *B = (unsigned char)(*BD);
00489  
00490       R++, V++, B++;
00491       H++, S++, Val++;
00492 
00493       }
00494 }
00495 
00496 /* ********************************************************* */
00497 
00498 /* Transforme la carte d'intensite RGB to XYZ */
00499 
00500 void toetRGB_to_XYZ(RD, VD, BD, X, Y, Z)
00501 double RD, VD, BD, *X, *Y, *Z;
00502 {
00503    if (RD<0.0 || RD>1.0 || VD<0.0 || VD>1.0 || BD<0.0 || BD>1.0 ){
00504         printf("\nEREURE: Les valeurs de *R, *V et *B sont dehors l'interval [0,1].");
00505         printf("\nOperateur:   toetRGB_to_XYZ() \n"); 
00506         exit(1);}
00507 
00508    *X= 0.040*RD + 0.084*VD - 0.041*BD;
00509    *Y= 0.021*RD + 0.107*VD - 0.038*BD;
00510    *Z=-0.005*RD + 0.011*VD + 0.024*BD;
00511 
00512 }
00513 
00514 /* Transforme la carte d'intensite XYZ to RGB */
00515 
00516 void ceiRGB_to_XYZ(RD, VD, BD, X, Y, Z)
00517 double RD, VD, BD, *X, *Y, *Z; 
00518 {
00519    if (RD<0.0 || RD>1.0 || VD<0.0 || VD>1.0 || BD<0.0 || BD>1.0 ){
00520         printf("\nEREURE: Les valeurs de *R, *V et *B sont dehors l'interval [0,1].");
00521         printf("\nOperateur:  ceiRGB_to_XYZ() \n"); 
00522         exit(1);}
00523    
00524    *X = 0.490*RD + 0.310*VD + 0.200*BD;
00525    *Y = 0.177*RD + 0.813*VD + 0.011*BD;
00526    *Z = 0.000*RD + 0.010*VD + 0.990*BD;
00527 
00528 }
00529 
00530 void XYZ_to_ceiuvY(X,Y,Z,u,v,Y1)
00531 double X,Y,Z;
00532 double *u, *v, *Y1;
00533 {
00534   double w;
00535 
00536   /*  
00537 if (X<0.0 || X>1.0 || Y<0.0 || Y>1.0 || Z<0.0 || Z>1.0 ){
00538    printf("\nEREURE: Les valeurs de X, Y et Z sont dehors l'interval [0,1].");
00539    printf("\nOperateur: XYZ_to_ceiuvY() \n"); 
00540    exit(1);}
00541    */
00542 
00543   w=X+15.0*Y+3.0*Z;
00544   if(w!=0.0)
00545     {
00546       *Y1=Y;
00547       *u=(4.0*X)/w;
00548       *v=(6.0*Y)/w;
00549     }
00550   else{
00551     *Y1=0.0;
00552     *u=0.0;
00553     *v=0.0;
00554   }
00555 }
00556 
00557 
00558 double f(double t)
00559 {
00560   if( t> 0.008856)
00561   return(pow(t,(1.0/3.0)));
00562 else 
00563   return(0.787*t+16.0/116.0);
00564 }
00565 
00566 
00567 
00568 void conv_RVB_Lab(space_struct *des, imarvb *ima_rvb)
00569 {
00570   
00571 unsigned char *ima_R, *ima_V, *ima_B;
00572 int N, M;
00573 pixdb *ima_L, *ima_a, *ima_b;
00574 
00575 unsigned char *R, *V, *B;
00576 pixdb *L, *a, *b;
00577 
00578 double *RD, *VD, *BD, *LD, *aD, *bD;
00579 
00580 register i, j;
00581 
00582 double X, Y, Z, u, v, Y_Yo, Xo, Yo, Zo;
00583 
00584         ima_R = ima_rvb->r[0];
00585         ima_V = ima_rvb->v[0];
00586         ima_B = ima_rvb->b[0];
00587         N = ima_rvb->nr;
00588         M = ima_rvb->nc;
00589         ima_L = des->comp0[0];
00590         ima_a = des->comp1[0];
00591         ima_b = des->comp2[0];
00592 
00593         R=ima_R;
00594         V=ima_V;
00595         B=ima_B;
00596         L=ima_L;
00597         a=ima_a;
00598         b=ima_b;
00599 
00600          RD = (double *)ima_R; VD = (double *) ima_V; BD = (double *) ima_B; 
00601          LD = (double *)ima_L; aD = (double *) ima_a; bD = (double *) ima_b;
00602 
00603         for(i=N;i--;)             
00604             for(j=M;j--;)
00605                 {
00606                   
00607       *RD = (double)(*R);   *VD = (double)(*V);    *BD = (double)(*B);      
00608       *RD = (*RD)/ 255.0;   *VD = (*VD)/ 255.0;    *BD = (*BD)/ 255.0;      
00609       
00610       if (*RD<0.0 || *RD>1.0 || *VD<0.0 || *VD>1.0 || *BD<0.0 || *BD>1.0 ){
00611         printf("\nERROR: Les valeurs de *R, *V et *B sont dehors l'interval [0,1].");
00612         printf("\nOperateur:  conv_RVB_HSV() \n"); 
00613         exit(1);}
00614       
00615       /*Les coordonees de reference pour blanc  toetRGB */
00616       if(des->transf_interm == 0)
00617         toetRGB_to_XYZ(1.0,1.0,1.0, &Xo, &Yo, &Zo);
00618       else if(des->transf_interm == 1)
00619         ceiRGB_to_XYZ(1.0,1.0,1.0, &Xo, &Yo, &Zo);
00620 
00621       /* Conversion de toetRGB a XYZ de CEI*/
00622       if(des->transf_interm == 0)
00623         toetRGB_to_XYZ(*RD, *VD, *BD, &X, &Y, &Z);
00624       else if(des->transf_interm == 1)
00625         ceiRGB_to_XYZ(*RD, *VD, *BD, &X, &Y, &Z);
00626              /* printf("\nOJO: Conversion RGB-XYZ Standar\n"); */
00627 
00628       /* Les coordonees Lab  CEI */
00629       Y_Yo=Y/Yo;
00630       if( Y_Yo> 0.008856)
00631          *LD=116.0*pow(Y_Yo,(1.0/3.0))-16.0;
00632       else if( Y_Yo <= 0.008856)
00633          *LD=903.3*Y_Yo;
00634 
00635       *aD=500.0*(f(X/Xo)-f(Y/Yo));
00636       *bD=200.0*(f(Y/Yo)-f(Z/Zo));
00637      
00638       *LD += des->comp_a;      *aD += des->comp_b;      *bD += des->comp_c;
00639 
00640       des->comp0[i][j] = *LD; des->comp1[i][j] = *aD; des->comp2[i][j] = *bD;
00641      
00642       R++, V++, B++;
00643       L++, a++, b++;      
00644         }  
00645 }
00646 
00647 
00648 
00649 void conv_RVB_Luv(space_struct *des, imarvb *ima_rvb)
00650 {
00651      
00652 unsigned char *ima_R, *ima_V, *ima_B;
00653 int N, M;
00654 pixdb *ima_L, *ima_u, *ima_v;
00655 
00656 unsigned char *R, *V, *B;
00657 pixdb *L, *U, *Va;
00658 
00659 double *RD, *VD, *BD, *LD, *uD, *vD;
00660 
00661 register i, j;
00662 
00663 double X, Y, Z, u, v, Y_Yo, uo, vo, Yo;
00664 
00665         ima_R = ima_rvb->r[0];
00666         ima_V = ima_rvb->v[0];
00667         ima_B = ima_rvb->b[0];
00668         N = ima_rvb->nr;
00669         M = ima_rvb->nc;
00670         ima_L = des->comp0[0];
00671         ima_u = des->comp1[0];
00672         ima_v = des->comp2[0];
00673 
00674         R=ima_R;
00675         V=ima_V;
00676         B=ima_B;
00677         L=ima_L;
00678         U=ima_u;
00679         Va=ima_v;
00680 
00681          RD = (double *)ima_R; VD = (double *) ima_V; BD = (double *) ima_B; 
00682          LD = (double *)ima_L; uD = (double *) ima_u; vD = (double *) ima_v; 
00683 
00684         for(i=N;i--;)             
00685             for(j=M;j--;)
00686                 {                 
00687 
00688       *RD = (double)(*R);   *VD = (double)(*V);    *BD = (double)(*B);      
00689       *RD = (*RD)/ 255.0;   *VD = (*VD)/ 255.0;    *BD = (*BD)/ 255.0;      
00690       
00691       if (*RD<0.0 || *RD>1.0 || *VD<0.0 || *VD>1.0 || *BD<0.0 || *BD>1.0 ){
00692         printf("\nERROR: Les valeurs de *R, *V et *B sont dehors l'interval [0,1].");
00693         printf("\nOperateur:  conv_RVB_HSV() \n"); 
00694         exit(1);}
00695       
00696         /*Les coordonees de reference pour blanc  toetRGB */
00697       if(des->transf_interm == 0)
00698          toetRGB_to_XYZ(1.0,1.0,1.0, &X, &Y, &Z);
00699       else if(des->transf_interm == 1)
00700         ceiRGB_to_XYZ(1.0,1.0,1.0, &X, &Y, &Z);
00701       
00702       XYZ_to_ceiuvY(X,Y,Z,&uo,&vo,&Yo);
00703 
00704       /* Conversion de toetRGB a XYZ de CEI*/
00705       if(des->transf_interm == 0)
00706         toetRGB_to_XYZ(*RD, *VD, *BD, &X, &Y, &Z);
00707       else  if(des->transf_interm == 1) 
00708         ceiRGB_to_XYZ(*RD, *VD, *BD, &X, &Y, &Z);
00709         
00710       XYZ_to_ceiuvY(X,Y,Z,&u,&v,&Y_Yo);
00711 
00712       /* Les coordonees Luv  CEI */
00713 
00714       Y_Yo/=Yo;
00715       if( Y_Yo > 0.008856)
00716         *LD = 116.0 * pow(Y_Yo,(1.0/3.0)) - 16.0;
00717       else if( Y_Yo <= 0.008856)
00718         *LD = 903.3 * Y_Yo;
00719 
00720       *uD=13.0*(*LD)*(u-uo);
00721       *vD=13.0*(*LD)*(v-vo);    
00722 
00723       *LD += des->comp_a;      *uD += des->comp_b;      *vD += des->comp_c;
00724 
00725        des->comp0[i][j] = *LD; des->comp1[i][j] = *uD; des->comp2[i][j] = *vD;
00726     
00727       R++, V++, B++;
00728       L++, U++, Va++;
00729      }      
00730 }
00731 
00732 
00733 
00734 
00735 /* *************************  LECTURE  ****************************** */
00746 param *conv_img_lect(space_struct *des, param *ptp, char *debq)
00747 {
00748   char question[500];
00749 
00750   sprintf(question, "%s Tipe de conversion (entier)", debq); 
00751   lec_param(question, ptp);
00752   des->type_conv = atoi(ptp->rep);
00753   ptp = ptp->next;
00754    
00755   switch(des->type_conv)
00756     {
00757     case 1:
00758     case 2: { sprintf(question, "%s Teinte (TLS) (entier)", debq); 
00759               lec_param(question, ptp);
00760               des->comp_a = atof(ptp->rep);
00761               ptp = ptp->next; 
00762    
00763               sprintf(question, "%s Luminance (TLS) (entier)", debq); 
00764               lec_param(question, ptp);
00765               des->comp_b = atof(ptp->rep);
00766               ptp = ptp->next;  
00767 
00768               sprintf(question, "%s Saturation (TLS) (entier)", debq); 
00769               lec_param(question, ptp);
00770               des->comp_c = atof(ptp->rep);
00771               ptp = ptp->next;
00772 
00773               break;}
00774 
00775     case 3: 
00776     case 4: { sprintf(question, "%s Hue - Teinte (HSV) (real) 0 - 360 ", debq); 
00777               lec_param(question, ptp);
00778               des->comp_a = atof(ptp->rep);
00779               ptp = ptp->next; 
00780    
00781               sprintf(question, "%s Saturation (HSV) (real) 0 - 1 ", debq); 
00782               lec_param(question, ptp);
00783               des->comp_b = atof(ptp->rep);
00784               ptp = ptp->next;  
00785 
00786               sprintf(question, "%s Value (HSV) (real) 0 - 1 ", debq); 
00787               lec_param(question, ptp);
00788               des->comp_c = atof(ptp->rep);
00789               ptp = ptp->next;
00790 
00791               break;}
00792 
00793     case 5: { sprintf(question, "%s L (Lab) (real) ", debq); 
00794               lec_param(question, ptp);
00795               des->comp_a = atof(ptp->rep);
00796               ptp = ptp->next; 
00797    
00798               sprintf(question, "%s a (Lab) (real) ", debq); 
00799               lec_param(question, ptp);
00800               des->comp_b = atof(ptp->rep);
00801               ptp = ptp->next;  
00802 
00803               sprintf(question, "%s b (Lab) (real) ", debq); 
00804               lec_param(question, ptp);
00805               des->comp_c = atof(ptp->rep);
00806               ptp = ptp->next;
00807               
00808               sprintf(question, "%s (Transformation intermediaire) (0 - Transforme les intensite toetRGB en XYZ apres en Lab) (1 - Transforme les intensite ceiRGB en XYZ apres en Lab)", debq); 
00809               lec_param(question, ptp);
00810               des->transf_interm  = atoi(ptp->rep);
00811               ptp = ptp->next;
00812 
00813               break;}
00814 
00815     case 6:  { sprintf(question, "%s L (Luv) (real) ", debq); 
00816               lec_param(question, ptp);
00817               des->comp_a = atof(ptp->rep);
00818               ptp = ptp->next; 
00819    
00820               sprintf(question, "%s u (Luv) (real) ", debq); 
00821               lec_param(question, ptp);
00822               des->comp_b = atof(ptp->rep);
00823               ptp = ptp->next;  
00824 
00825               sprintf(question, "%s v (Luv) (real) ", debq); 
00826               lec_param(question, ptp);
00827               des->comp_c = atof(ptp->rep);
00828               ptp = ptp->next;
00829                 
00830               sprintf(question, "%s (Transformation intermediaire) (0 - Transforme les intensite toetRGB en XYZ apres en Lab) (1 - Transforme les intensite ceiRGB en XYZ apres en Lab)", debq); 
00831               lec_param(question, ptp);
00832               des->transf_interm = atoi(ptp->rep);
00833               ptp = ptp->next;
00834         
00835               break;}
00836 
00837     default: printf("Nombre incorect");
00838     }
00839 
00840   return(ptp);
00841 }
00842 
00843 
00844 /* *************************  INITIALISATION  ************************** */
00855 int conv_img_init(space_struct *des, imarvb im0, imarvb *imres0)
00856 {   
00857   imres0->nr = im0.nr;
00858   imres0->nc = im0.nc;
00859   alloc_imarvb(imres0);
00860 
00861   des->nr = im0.nr;
00862   des->nc = im0.nc;
00863   alloc_space_struct(des, &im0);  
00864 }
00865 
00866 
00867 /* *************************  CALCUL  ************************** */
00877 int  conv_img_calc(space_struct *des, imarvb im0, imarvb *imres0)
00878 {
00879     
00880 switch(des->type_conv)
00881     {
00882     case 1: {conv_RVB_TLS2(des, &im0, imres0); break;}
00883     case 2: {conv_TLS_RVB2(des, &im0, imres0); break;}
00884     case 3: {conv_RVB_HSV(des, &im0); break;}
00885     case 4: {conv_HSV_RVB(des, imres0); break;}
00886     case 5: {conv_RVB_Lab(des, &im0); break;}
00887     case 6: {conv_RVB_Luv(des, &im0); break;}
00888     default: printf("Nombre incorect");
00889     }
00890 
00891 }
00892 
00893 
00894 
00895 
00896 /* ************************* alloc_space_struct ************************* */
00897 /* TYPES space_struct
00898     allocation de memoire pour la structure de donnes space_struct.\\
00899     allocation en une fois permettant l'adressage 1D : im->p[0] + j*im->nc + i
00900     ou l'adressage 2D : im->p[j][i]
00901     @param space  pointeur space_structure a allouer pour les 3 vecteurs contenant les composantes de l'image convertie
00902     @param im  pointeur image a convertir, nombre de colonnes (im->nc) et 
00903     nombre de lignes (im->nr) connus
00904     @author B. Ionescu
00905     @version 1.0 (10/12/00); Include : proto2D.h   lconv.h
00906 */
00907 
00908 int alloc_space_struct(space_struct *space, imarvb *im)
00909 {
00910    int j;
00911  
00912   /* tableau d'adresses des debuts de ligne                             */
00913   if( (space->comp0 = (pixdb **)malloc(im->nr*sizeof(pixdb *))) == NULL )
00914         {printf ("\n allocation image impossible\n");  exit(1);}
00915   if( (space->comp1 = (pixdb **)malloc(im->nr*sizeof(pixdb *))) == NULL )
00916         {printf ("\n allocation image impossible\n");  exit(1);}
00917   if( (space->comp2 = (pixdb **)malloc(im->nr*sizeof(pixdb *))) == NULL )
00918         {printf ("\n allocation image impossible\n");  exit(1);}
00919  
00920   /* tableau 1D donnant l'image en 1 seul bloc, ligne apres ligne       */
00921   if( (space->comp0[0] = (pixdb *)malloc(im->nc*im->nr*sizeof(pixdb))) == NULL)
00922         {printf ("\n allocation image impossible\n");  exit(1); }
00923   if( (space->comp1[0] = (pixdb *)malloc(im->nc*im->nr*sizeof(pixdb))) == NULL)
00924         {printf ("\n allocation image impossible\n");  exit(1); }
00925   if( (space->comp2[0] = (pixdb *)malloc(im->nc*im->nr*sizeof(pixdb))) == NULL)
00926         {printf ("\n allocation image impossible\n");  exit(1); }
00927  
00928   /* positionnement des pointeurs de debut de ligne                     */
00929   for(j = 1; j < im->nr; j++){
00930         space->comp0[j] =  space->comp0[0] + j*(im->nc);
00931         space->comp1[j] =  space->comp1[0] + j*(im->nc);
00932         space->comp2[j] =  space->comp2[0] + j*(im->nc);
00933   }
00934 }
00935 
00936 /* ********************* liberation memeoire image  ********************** */
00937 /* TYPES space_struct
00938     desallocation d'une structure.
00939     \\
00940     @param space  pointeur space_struct  a desallouer, 
00941     @author Benone Ionescu
00942     @version 1.0 (10/12/00); Include : proto2D.h  conv_img.h
00943 */
00944 
00945 int free_space_struct(space_struct *space)
00946 {
00947   free(space->comp0[0]);  free(space->comp1[0]); free(space->comp2[0]);
00948   free(space->comp0);  free(space->comp1);  free(space->comp2);
00949 }
00950 
00951 
00952   /* fin doc en sous partie */   

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