Binaire.cpp
1 |
/*********************************************************************************** |
2 |
ImAnalyse : software in image processing and image analysis |
3 |
|
4 |
Copyright (C) 10 juillet 2008 <Vincent MORARD> |
5 |
Version: 2.1 |
6 |
Contact: vincent<POINT>morard<AROBAS>cpe<POINT>fr |
7 |
Website: http://ImAnalyse.free.fr |
8 |
Website: http://pistol.petesampras.free.fr |
9 |
|
10 |
This program is free software: you can redistribute it and/or modify |
11 |
it under the terms of the GNU General Public License as published by |
12 |
the Free Software Foundation, either version 3 of the License, or |
13 |
(at your option) any later version. |
14 |
|
15 |
This program is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
GNU General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU General Public License |
21 |
along with this program. If not, see <http://www.gnu.org/licenses/ |
22 |
**********************************************************************************/ |
23 |
#include "../CImage.h" |
24 |
|
25 |
//Opérations binaire :AND on fait un ET logique entre l'image this et Other. Le |
26 |
//résultat est placéer dans ImgDest |
27 |
//Si les dimensions ne sont pas les memes, on prend les dim minimum commune au deux |
28 |
//images |
29 |
void CImage::AND(CImage *Other,CImage *ImgDest) |
30 |
{ |
31 |
if(hBmp==0 || Other->hBmp==0){ |
32 |
MessageBox(NULL,"AND : L'image source est vide", |
33 |
NULL,MB_OK|MB_ICONWARNING); |
34 |
return ; |
35 |
} |
36 |
|
37 |
if(ImgType!=BIN || Other->ImgType!=BIN){ |
38 |
MessageBox(NULL,"AND : Les images doivent être binaire", |
39 |
NULL,MB_OK|MB_ICONWARNING); |
40 |
return ; |
41 |
} |
42 |
if(Width!=Other->Width || Height!=Other->Height) |
43 |
if(MessageBox(NULL,"AND : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
44 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
45 |
return ; |
46 |
|
47 |
if(ImgDest!=0 && ImgDest!=this) |
48 |
ImgDest->Copy(this); |
49 |
|
50 |
if(ImgDest==0) |
51 |
ImgDest=this; |
52 |
|
53 |
int cx,cy,posImg1,posImg2;; |
54 |
cx=min(Width,Other->Width); |
55 |
cy=min(Height,Other->Height); |
56 |
|
57 |
//recupération des pixels |
58 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
59 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
60 |
|
61 |
for(int j=0;j<cy;j++) |
62 |
for(int i=0;i<cx*4;i+=4) |
63 |
{ |
64 |
posImg1=i+Width*j*4; |
65 |
posImg2=i+Other->Width*j*4; |
66 |
if(ucBits[posImg1]==255 && Other->ucBits[posImg2]==255) |
67 |
{ |
68 |
ImgDest->ucBits[posImg1]=255; |
69 |
ImgDest->ucBits[posImg1+1]=255; |
70 |
ImgDest->ucBits[posImg1+2]=255; |
71 |
} |
72 |
else |
73 |
{ |
74 |
ImgDest->ucBits[posImg1]=0; |
75 |
ImgDest->ucBits[posImg1+1]=0; |
76 |
ImgDest->ucBits[posImg1+2]=0; |
77 |
} |
78 |
} |
79 |
|
80 |
|
81 |
SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); |
82 |
|
83 |
|
84 |
} |
85 |
|
86 |
//Opérations binaire :NAND on fait un NON ET logique entre l'image this et Other. Le |
87 |
//résultat est placéer dans ImgDest |
88 |
//Si les dimensions ne sont pas les memes, on prend les dim minimum commune au deux |
89 |
//images |
90 |
void CImage::NAND(CImage *Other,CImage *ImgDest) |
91 |
{ |
92 |
if(hBmp==0 || Other->hBmp==0){ |
93 |
MessageBox(NULL,"NAND : L'image source est vide", |
94 |
NULL,MB_OK|MB_ICONWARNING); |
95 |
return ; |
96 |
} |
97 |
|
98 |
if(ImgType!=BIN || Other->ImgType!=BIN){ |
99 |
MessageBox(NULL,"NAND : Les images doivent être binaire", |
100 |
NULL,MB_OK|MB_ICONWARNING); |
101 |
return ; |
102 |
} |
103 |
if(Width!=Other->Width || Height!=Other->Height) |
104 |
if(MessageBox(NULL," NAND : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
105 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
106 |
return ; |
107 |
|
108 |
if(ImgDest!=0 && ImgDest!=this) |
109 |
ImgDest->Copy(this); |
110 |
|
111 |
int cx,cy,posImg1,posImg2;; |
112 |
cx=min(Width,Other->Width); |
113 |
cy=min(Height,Other->Height); |
114 |
|
115 |
//recupération des pixels |
116 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
117 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
118 |
|
119 |
for(int j=0;j<cy;j++) |
120 |
for(int i=0;i<cx*4;i+=4) |
121 |
{ |
122 |
posImg1=i+Width*j*4; |
123 |
posImg2=i+Other->Width*j*4; |
124 |
if(!(ucBits[posImg1]==255 && Other->ucBits[posImg2]==255)) |
125 |
{ |
126 |
ImgDest->ucBits[posImg1]=255; |
127 |
ImgDest->ucBits[posImg1+1]=255; |
128 |
ImgDest->ucBits[posImg1+2]=255; |
129 |
} |
130 |
else |
131 |
{ |
132 |
ImgDest->ucBits[posImg1]=0; |
133 |
ImgDest->ucBits[posImg1+1]=0; |
134 |
ImgDest->ucBits[posImg1+2]=0; |
135 |
} |
136 |
} |
137 |
|
138 |
SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); |
139 |
} |
140 |
|
141 |
|
142 |
//Opérations binaire :OR on fait un OU logique entre l'image this et Other. Le |
143 |
//résultat est placéer dans ImgDest |
144 |
//Si les dimensions ne sont pas les memes, on prend les dim minimum commune au deux |
145 |
//images |
146 |
void CImage::OR(CImage *Other,CImage *ImgDest) |
147 |
{ |
148 |
if(hBmp==0 || Other->hBmp==0){ |
149 |
MessageBox(NULL,"OR : L'image source est vide", |
150 |
NULL,MB_OK|MB_ICONWARNING); |
151 |
return ; |
152 |
} |
153 |
|
154 |
if(ImgType!=BIN || Other->ImgType!=BIN){ |
155 |
MessageBox(NULL,"OR : Les images doivent être binaire", |
156 |
NULL,MB_OK|MB_ICONWARNING); |
157 |
return ; |
158 |
} |
159 |
if(Width!=Other->Width || Height!=Other->Height) |
160 |
if(MessageBox(NULL,"OR : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
161 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
162 |
return ; |
163 |
|
164 |
if(ImgDest!=0 && ImgDest!=this) |
165 |
ImgDest->Copy(this); |
166 |
|
167 |
int cx,cy,posImg1,posImg2;; |
168 |
cx=min(Width,Other->Width); |
169 |
cy=min(Height,Other->Height); |
170 |
|
171 |
//recupération des pixels |
172 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
173 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
174 |
|
175 |
for(int j=0;j<cy;j++) |
176 |
for(int i=0;i<cx*4;i+=4) |
177 |
{ |
178 |
posImg1=i+Width*j*4; |
179 |
posImg2=i+Other->Width*j*4; |
180 |
if(ucBits[posImg1]==255 || Other->ucBits[posImg2]==255) |
181 |
{ |
182 |
ImgDest->ucBits[posImg1]=255; |
183 |
ImgDest->ucBits[posImg1+1]=255; |
184 |
ImgDest->ucBits[posImg1+2]=255; |
185 |
} |
186 |
else |
187 |
{ |
188 |
ImgDest->ucBits[posImg1]=0; |
189 |
ImgDest->ucBits[posImg1+1]=0; |
190 |
ImgDest->ucBits[posImg1+2]=0; |
191 |
} |
192 |
} |
193 |
|
194 |
|
195 |
SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); |
196 |
} |
197 |
|
198 |
//Opérations binaire :NOR on fait un NON OU logique entre l'image this et Other. Le |
199 |
//résultat est placéer dans ImgDest |
200 |
//Si les dimensions ne sont pas les memes, on prend les dim minimum commune au deux |
201 |
//images |
202 |
void CImage::NOR(CImage *Other,CImage *ImgDest) |
203 |
{ |
204 |
if(hBmp==0 || Other->hBmp==0){ |
205 |
MessageBox(NULL,"XOR : L'image source est vide", |
206 |
NULL,MB_OK|MB_ICONWARNING); |
207 |
return ; |
208 |
} |
209 |
|
210 |
if(ImgType!=BIN || Other->ImgType!=BIN){ |
211 |
MessageBox(NULL,"XOR : Les images doivent être binaire", |
212 |
NULL,MB_OK|MB_ICONWARNING); |
213 |
return ; |
214 |
} |
215 |
if(Width!=Other->Width || Height!=Other->Height) |
216 |
if(MessageBox(NULL,"XOR : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
217 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
218 |
return ; |
219 |
|
220 |
if(ImgDest!=0 && ImgDest!=this) |
221 |
ImgDest->Copy(this); |
222 |
|
223 |
int cx,cy,posImg1,posImg2;; |
224 |
cx=min(Width,Other->Width); |
225 |
cy=min(Height,Other->Height); |
226 |
|
227 |
//recupération des pixels |
228 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
229 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
230 |
|
231 |
for(int j=0;j<cy;j++) |
232 |
for(int i=0;i<cx*4;i+=4) |
233 |
{ |
234 |
posImg1=i+Width*j*4; |
235 |
posImg2=i+Other->Width*j*4; |
236 |
if(!(ucBits[posImg1]==255 || Other->ucBits[posImg2]==255)) |
237 |
{ |
238 |
ImgDest->ucBits[posImg1]=255; |
239 |
ImgDest->ucBits[posImg1+1]=255; |
240 |
ImgDest->ucBits[posImg1+2]=255; |
241 |
} |
242 |
else |
243 |
{ |
244 |
ImgDest->ucBits[posImg1]=0; |
245 |
ImgDest->ucBits[posImg1+1]=0; |
246 |
ImgDest->ucBits[posImg1+2]=0; |
247 |
} |
248 |
} |
249 |
|
250 |
|
251 |
SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); |
252 |
} |
253 |
|
254 |
|
255 |
//Opérations binaire :NOT on fait un NON logique de l'image this. Le |
256 |
//résultat est placéer dans ImgDest |
257 |
bool CImage::NOT(CImage *ImgDest) |
258 |
{ |
259 |
if(hBmp==0 ){ |
260 |
MessageBox(NULL,"NOT : L'image source est vide", |
261 |
NULL,MB_OK|MB_ICONWARNING); |
262 |
return 0; |
263 |
} |
264 |
|
265 |
if(ImgType!=BIN){ |
266 |
MessageBox(NULL,"NOT : Les images doivent être binaire", |
267 |
NULL,MB_OK|MB_ICONWARNING); |
268 |
return 0; |
269 |
} |
270 |
|
271 |
|
272 |
if(ImgDest!=0 && ImgDest!=this) |
273 |
ImgDest->Copy(this); |
274 |
if(ImgDest==0) |
275 |
ImgDest=this; |
276 |
//recupération des pixels |
277 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
278 |
|
279 |
for(int i=0;i<Width*Height*4;i+=4){ |
280 |
ImgDest->ucBits[i]=(ucBits[i]==255 ? 0 : 255); |
281 |
ImgDest->ucBits[i+1]=ImgDest->ucBits[i]; |
282 |
ImgDest->ucBits[i+2]=ImgDest->ucBits[i]; |
283 |
} |
284 |
|
285 |
SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); |
286 |
return 1; |
287 |
} |
lien1 lien2 lien3