PasseHautv4_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::PasseHautv4(int Type,CImage *ImgDest) 
27  { 
28    if(hBmp==0){ 
29      MessageBox(NULL,"PasseHautv4 : 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    if(ImgDest==0) 
37      ImgDest=this; 
38   
39    int i,j; 
40    double *PHAUT=new double[Width*Height]; 
41   
42   
43    double *PHAUT_Red,*PHAUT_Green; 
44    if(Type==RGBi) 
45    { 
46      PHAUT_Red=new double[Width*Height]; 
47      PHAUT_Green=new double[Width*Height]; 
48    } 
49   
50    //recupération des pixels 
51    GetBitmapBits(hBmp,Width*Height*4,ucBits); 
52   
53    for(i=1;i<Width-1;i++) 
54      for(j=1;j<Height-1;j++) 
55      { 
56        switch(Type) 
57        { 
58        case RGBi: 
59          PHAUT_Red[(i+j*Width)]=         -GetPixel(i,j-1,RED) 
60                      -GetPixel(i-1,j,RED)  +5*GetPixel(i,j,RED)  -GetPixel(i+1,j,RED) 
61                             -GetPixel(i,j+1,RED); 
62   
63   
64          PHAUT_Green[(i+j*Width)]=        -GetPixel(i,j-1,GREEN) 
65                      -GetPixel(i-1,j,GREEN)  +5*GetPixel(i,j,GREEN)  -GetPixel(i+1,j,GREEN) 
66                               -GetPixel(i,j+1,GREEN); 
67   
68          PHAUT[(i+j*Width)]=             -GetPixel(i,j-1,BLUE) 
69                      -GetPixel(i-1,j,BLUE)  +5*GetPixel(i,j,BLUE)  -GetPixel(i+1,j,BLUE) 
70                             -GetPixel(i,j+1,BLUE); 
71   
72        break; 
73        default: 
74          PHAUT[(i+j*Width)]=             -GetPixel(i,j-1,Type) 
75                      -GetPixel(i-1,j,Type)  +5*GetPixel(i,j,Type)  -GetPixel(i+1,j,Type) 
76                             -GetPixel(i,j+1,Type); 
77          break; 
78        } 
79      } 
80   
81    switch(Type) 
82    { 
83    case RGBi: 
84      ImgDest->ImgType=RGBi; 
85      for(i=0,j=0;i<Width*Height*4;i+=4,j++) 
86      { 
87        ImgDest->ucBits[i]=Limit((int)PHAUT[j]); 
88        ImgDest->ucBits[i+1]=Limit((int)PHAUT_Green[j]); 
89        ImgDest->ucBits[i+2]=Limit((int)PHAUT_Red[j]); 
90   
91      } 
92      delete []PHAUT_Red; 
93      delete []PHAUT_Green; 
94   
95      break; 
96   
97    default: 
98      ImgDest->ImgType=GRAY; 
99      for(i=0,j=0;i<Width*Height*4;i+=4,j++) 
100      { 
101        ImgDest->ucBits[i]=LimitABS((int)PHAUT[j]); 
102        ImgDest->ucBits[i+1]=LimitABS((int)PHAUT[j]); 
103        ImgDest->ucBits[i+2]=LimitABS((int)PHAUT[j]); 
104      } 
105      break; 
106    } 
107   
108    delete []PHAUT; 
109   
110   
111    SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); 
112   
113    return 1; 
114  } 

lien1 lien2 lien3