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