Sepia.cpp

1  /***********************************************************************************  
2      ImAnalyse : software in image processing and image analysis 
3     
4      Copyright (C) 27 avril 2008  <Vincent MORARD> 
5    Version: 2.0 
6      Contact: vincent<POINT>morard<AROBAS>cpe<POINT>fr 
7    Website: http://pistol.petesampras.free.fr 
8   
9      This program is free software: you can redistribute it and/or modify 
10      it under the terms of the GNU General Public License as published by 
11      the Free Software Foundation, either version 3 of the License, or 
12      (at your option) any later version. 
13   
14      This program is distributed in the hope that it will be useful, 
15      but WITHOUT ANY WARRANTY; without even the implied warranty of 
16      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
17      GNU General Public License for more details. 
18   
19      You should have received a copy of the GNU General Public License 
20      along with this program.  If not, see <http://www.gnu.org/licenses/ 
21  **********************************************************************************/ 
22  #include "CImage.h" 
23   
24   
25   
26  bool CImage::Sepia(int Sat,int Hue,CImage *ImgDest) 
27  { 
28    if(hBmp==0){ 
29      MessageBox(NULL,"Sepia : L'image source est vide", 
30            NULL,MB_OK|MB_ICONWARNING); 
31      return 0; 
32    } 
33   
34    if(ImgDest!=0 && ImgDest!=this) 
35      ImgDest->Copy(this); 
36   
37    if(ImgDest==0) 
38      ImgDest=this; 
39   
40    //recupération des pixels 
41    GetBitmapBits(hBmp,Width*Height*4,ucBits); 
42    //PostThreadMessage(idThread,WM_COMMAND,WM_COMMAND,0); 
43    int i; 
44    double H,S,L,R,G,B; 
45    for(i=0;i<4*Width*Height;i+=4) 
46    { 
47      RGB_to_HSL2(ucBits[i+2],ucBits[i+1],ucBits[i],&H,&S,&L); 
48      H=Hue; 
49      S=Sat; 
50      HSL_to_RGB2(H,S,L,&R,&G,&B); 
51      L/=240.0; 
52      R=ucBits[i+2]+L*(R-ucBits[i+2]); 
53      G=ucBits[i+1]+L*(G-ucBits[i+1]); 
54      B=ucBits[i]  +L*(B-ucBits[i]); 
55   
56      ImgDest->ucBits[i]=(int)Limit(B); 
57      ImgDest->ucBits[i+1]=(int)Limit(G); 
58      ImgDest->ucBits[i+2]=(int)Limit(R); 
59      //(int)((B>255) ? (255):((B>=0)?(B):(0))); 
60      //ImgDest[i+1]=Limit(B);(int)((G>255) ? (255):((G>=0)?(G):(0))); 
61      //ImgDest[i+2]=Limit(B);(int)((R>255) ? (255):((R>=0)?(R):(0))); 
62    } 
63   
64   
65    //recupération des pixels 
66    SetBitmapBits(ImgDest->hBmp,Width*Height*4,ImgDest->ucBits); 
67    return 1; 
68   
69  } 

lien1 lien2 lien3