[LT2013]
[reactos.git] / modules / rosapps / applications / imagesoft / adjust.c
1 #include <precomp.h>
2
3
4 BOOL
5 DisplayBlackAndWhite(HWND hwnd,
6 HDC hdcMem,
7 HBITMAP hBitmap)
8 {
9 BITMAPINFO bi;
10 BITMAP bitmap;
11 BOOL bRes;
12 DWORD Count = 0;
13 INT i, j;
14 PBYTE pBits;
15 RECT rc;
16
17 GetObject(hBitmap,
18 sizeof(BITMAP),
19 &bitmap);
20
21 /* Bitmap header */
22 bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
23 bi.bmiHeader.biWidth = bitmap.bmWidth;
24 bi.bmiHeader.biHeight = bitmap.bmHeight;
25 bi.bmiHeader.biPlanes = 1;
26 bi.bmiHeader.biBitCount = 32;
27 bi.bmiHeader.biCompression = BI_RGB;
28 bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;
29 bi.bmiHeader.biClrUsed = 0;
30 bi.bmiHeader.biClrImportant = 0;
31
32 /* Buffer */
33 pBits = (PBYTE)HeapAlloc(ProcessHeap,
34 0,
35 bitmap.bmWidth * bitmap.bmHeight * 4);
36 if (!pBits)
37 return FALSE;
38
39 /* get the bits from the original bitmap */
40 bRes = GetDIBits(hdcMem,
41 hBitmap,
42 0,
43 bitmap.bmHeight,
44 pBits,
45 &bi,
46 DIB_RGB_COLORS);
47
48 for (i = 0; i < bitmap.bmHeight; i++)
49 {
50 for (j = 0; j < bitmap.bmWidth; j++)
51 {
52 DWORD Val = 0;
53 INT b, g, r;
54
55 CopyMemory(&Val,
56 &pBits[Count],
57 4);
58
59 /* Get pixels in reverse order */
60 b = GetRValue(Val);
61 g = GetGValue(Val);
62 r = GetBValue(Val);
63
64 /* get the average color value */
65 Val = (r + g + b) / 3;
66
67 /* assign to RGB color */
68 Val = RGB(Val, Val, Val);
69 CopyMemory(&pBits[Count],
70 &Val,
71 4);
72
73 Count+=4;
74 }
75 }
76
77 /* Set the new pixel bits */
78 SetDIBits(hdcMem,
79 hBitmap,
80 0,
81 bRes,
82 pBits,
83 &bi,
84 DIB_RGB_COLORS);
85
86 HeapFree(ProcessHeap,
87 0,
88 pBits);
89
90 GetClientRect(hwnd,
91 &rc);
92
93 InvalidateRect(hwnd,
94 &rc,
95 FALSE);
96
97 return TRUE;
98 }
99
100
101 BOOL
102 DisplayInvertedColors(HWND hwnd,
103 HDC hdcMem,
104 HBITMAP hBitmap)
105 {
106 BITMAPINFO bi;
107 BITMAP bitmap;
108 BOOL bRes;
109 DWORD Count = 0;
110 INT i, j;
111 PBYTE pBits;
112 RECT rc;
113
114 GetObject(hBitmap,
115 sizeof(BITMAP),
116 &bitmap);
117
118 /* Bitmap header */
119 bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
120 bi.bmiHeader.biWidth = bitmap.bmWidth;
121 bi.bmiHeader.biHeight = bitmap.bmHeight;
122 bi.bmiHeader.biPlanes = 1;
123 bi.bmiHeader.biBitCount = 32;
124 bi.bmiHeader.biCompression = BI_RGB;
125 bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;
126 bi.bmiHeader.biClrUsed = 0;
127 bi.bmiHeader.biClrImportant = 0;
128
129 /* Buffer */
130 pBits = (PBYTE)HeapAlloc(ProcessHeap,
131 0,
132 bitmap.bmWidth * bitmap.bmHeight * 4);
133 if (!pBits)
134 return FALSE;
135
136 /* get the bits from the original bitmap */
137 bRes = GetDIBits(hdcMem,
138 hBitmap,
139 0,
140 bitmap.bmHeight,
141 pBits,
142 &bi,
143 DIB_RGB_COLORS);
144
145 for (i = 0; i < bitmap.bmHeight; i++)
146 {
147 for (j = 0; j < bitmap.bmWidth; j++)
148 {
149 DWORD Val = 0;
150 INT b, g, r;
151
152 CopyMemory(&Val,
153 &pBits[Count],
154 4);
155
156 b = 255 - GetRValue(Val);
157 g = 255 - GetGValue(Val);
158 r = 255 - GetBValue(Val);
159
160 Val = RGB(b, g, r);
161
162 CopyMemory(&pBits[Count],
163 &Val,
164 4);
165
166 Count+=4;
167 }
168 }
169
170 /* Set the new pixel bits */
171 SetDIBits(hdcMem,
172 hBitmap,
173 0,
174 bRes,
175 pBits,
176 &bi,
177 DIB_RGB_COLORS);
178
179 HeapFree(ProcessHeap,
180 0,
181 pBits);
182
183 GetClientRect(hwnd,
184 &rc);
185
186 InvalidateRect(hwnd,
187 &rc,
188 FALSE);
189
190 return TRUE;
191 }
192
193
194
195 BOOL
196 DisplayBlur(HWND hwnd,
197 HDC hdcMem,
198 HBITMAP hBitmap)
199 {
200 BITMAPINFO bi;
201 BITMAP bitmap;
202 BOOL bRes;
203 DWORD Count = 0;
204 INT i, j;
205 PBYTE pBits, pBitsTemp;
206 RECT rc;
207
208 GetObject(hBitmap,
209 sizeof(BITMAP),
210 &bitmap);
211
212 /* Bitmap header */
213 bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
214 bi.bmiHeader.biWidth = bitmap.bmWidth;
215 bi.bmiHeader.biHeight = bitmap.bmHeight;
216 bi.bmiHeader.biPlanes = 1;
217 bi.bmiHeader.biBitCount = 32;
218 bi.bmiHeader.biCompression = BI_RGB;
219 bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;
220 bi.bmiHeader.biClrUsed = 0;
221 bi.bmiHeader.biClrImportant = 0;
222
223 /* Buffer */
224 pBits = (PBYTE)HeapAlloc(ProcessHeap,
225 0,
226 bitmap.bmWidth * bitmap.bmHeight * 4);
227 pBitsTemp = (PBYTE)HeapAlloc(ProcessHeap,
228 0,
229 bitmap.bmWidth * bitmap.bmHeight * 4);
230 if (!pBits || !pBitsTemp)
231 return FALSE;
232
233 /* get the bits from the original bitmap */
234 bRes = GetDIBits(hdcMem,
235 hBitmap,
236 0,
237 bitmap.bmHeight,
238 pBits,
239 &bi,
240 DIB_RGB_COLORS);
241
242 for (i = 0; i < bitmap.bmHeight; i++)
243 {
244 for (j = 0; j < bitmap.bmWidth; j++)
245 {
246 LONG Val = 0;
247 INT b, g, r;
248 INT c1, c2, c3, c4, c5;
249
250 CopyMemory(&Val,
251 &pBits[Count],
252 4);
253
254 b = GetRValue(Val);
255 g = GetGValue(Val);
256 r = GetBValue(Val);
257
258 c1 = r;
259 /* Red */
260 if ((Count < ((bitmap.bmHeight - 1) * bitmap.bmWidth * 4lu)) &&
261 (Count > (bitmap.bmWidth * 4lu)))
262 {
263 CopyMemory(&Val, &pBits[Count - (bitmap.bmWidth * 4)], 4);
264 c2 = GetBValue(Val);
265
266 CopyMemory(&Val, &pBits[Count + 4], 4);
267 c3 = GetBValue(Val);
268
269 CopyMemory(&Val, &pBits[(Count + (bitmap.bmWidth * 4))], 4);
270 c4 = GetBValue(Val);
271
272 CopyMemory(&Val, &pBits[Count - 4], 4);
273 c5 = GetBValue(Val);
274
275 r = (c1 + c2 + c3 + c4 + c5) / 5;
276 }
277
278 /* Green */
279 c1 = g;
280 if ((Count < ((bitmap.bmHeight - 1) * bitmap.bmWidth * 4lu)) &&
281 (Count > (bitmap.bmWidth * 4lu)))
282 {
283 CopyMemory(&Val, &pBits[(Count - (bitmap.bmWidth * 4lu))], 4);
284 c2 = GetGValue(Val);
285
286 CopyMemory(&Val, &pBits[Count + 4], 4);
287 c3 = GetGValue(Val);
288
289 CopyMemory(&Val, &pBits[(Count + (bitmap.bmWidth * 4lu))], 4);
290 c4 = GetGValue(Val);
291
292 CopyMemory(&Val, &pBits[Count-4], 4);
293 c5 = GetGValue(Val);
294
295 g = (c1 + c2 + c3 + c4 + c5) / 5;
296 }
297
298 /* Blue */
299 c1 = b;
300 if ((Count < ((bitmap.bmHeight - 1) * bitmap.bmWidth * 4lu)) &&
301 (Count > (bitmap.bmWidth * 4lu)))
302 {
303 CopyMemory(&Val, &pBits[(Count - (bitmap.bmWidth * 4l))], 4);
304 c2 = GetRValue(Val);
305
306 CopyMemory(&Val, &pBits[Count + 4], 4);
307 c3 = GetRValue(Val);
308
309 CopyMemory(&Val, &pBits[(Count + (bitmap.bmWidth * 4l))], 4);
310 c4 = GetRValue(Val);
311
312 CopyMemory(&Val, &pBits[Count-4], 4);
313 c5 = GetRValue(Val);
314
315 b = (c1 + c2 + c3 + c4 + c5) / 5;
316 }
317
318 Val = RGB(b, g, r);
319
320 CopyMemory(&pBitsTemp[Count],
321 &Val,
322 4);
323
324 Count+=4;
325 }
326 }
327
328 /* Set the new pixel bits */
329 SetDIBits(hdcMem,
330 hBitmap,
331 0,
332 bRes,
333 pBitsTemp,
334 &bi,
335 DIB_RGB_COLORS);
336
337 HeapFree(ProcessHeap,
338 0,
339 pBits);
340 HeapFree(ProcessHeap,
341 0,
342 pBitsTemp);
343
344 GetClientRect(hwnd,
345 &rc);
346
347 InvalidateRect(hwnd,
348 &rc,
349 FALSE);
350
351 return TRUE;
352 }
353
354
355
356 BOOL
357 DisplaySharpness(HWND hwnd,
358 HDC hdcMem,
359 HBITMAP hBitmap)
360 {
361 BITMAPINFO bi;
362 BITMAP bitmap;
363 BOOL bRes;
364 DWORD Count = 0;
365 INT i, j;
366 PBYTE pBits, pBitsTemp;
367 RECT rc;
368
369 GetObject(hBitmap,
370 sizeof(BITMAP),
371 &bitmap);
372
373 /* Bitmap header */
374 bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
375 bi.bmiHeader.biWidth = bitmap.bmWidth;
376 bi.bmiHeader.biHeight = bitmap.bmHeight;
377 bi.bmiHeader.biPlanes = 1;
378 bi.bmiHeader.biBitCount = 32;
379 bi.bmiHeader.biCompression = BI_RGB;
380 bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;
381 bi.bmiHeader.biClrUsed = 0;
382 bi.bmiHeader.biClrImportant = 0;
383
384 /* Buffer */
385 pBits = (PBYTE)HeapAlloc(ProcessHeap,
386 0,
387 bitmap.bmWidth * bitmap.bmHeight * 4);
388 pBitsTemp = (PBYTE)HeapAlloc(ProcessHeap,
389 0,
390 bitmap.bmWidth * bitmap.bmHeight * 4);
391 if (!pBits || !pBitsTemp)
392 return FALSE;
393
394 /* get the bits from the original bitmap */
395 bRes = GetDIBits(hdcMem,
396 hBitmap,
397 0,
398 bitmap.bmHeight,
399 pBits,
400 &bi,
401 DIB_RGB_COLORS);
402
403 for (i = 0; i < bitmap.bmHeight; i++)
404 {
405 for (j = 0; j < bitmap.bmWidth; j++)
406 {
407 LONG Val = 0;
408 INT b, g, r;
409 INT c1, c2, c3, c4, c5;
410
411 CopyMemory(&Val,
412 &pBits[Count],
413 4);
414
415 b = GetRValue(Val);
416 g = GetGValue(Val);
417 r = GetBValue(Val);
418
419 c1 = r;
420 /* Red */
421 if ((Count < ((bitmap.bmHeight - 1) * bitmap.bmWidth * 4lu)) &&
422 (Count > (bitmap.bmWidth * 4lu)))
423 {
424 CopyMemory(&Val, &pBits[Count - (bitmap.bmWidth * 4l)], 4);
425 c2 = GetBValue(Val);
426
427 CopyMemory(&Val, &pBits[Count + 4], 4);
428 c3 = GetBValue(Val);
429
430 CopyMemory(&Val, &pBits[(Count + (bitmap.bmWidth * 4l))], 4);
431 c4 = GetBValue(Val);
432
433 CopyMemory(&Val, &pBits[Count - 4], 4);
434 c5 = GetBValue(Val);
435
436 r = (c1 * 5) - (c2 + c3 + c4 + c5);
437 }
438
439 /* Green */
440 c1 = g;
441 if ((Count < ((bitmap.bmHeight - 1)* bitmap.bmWidth * 4lu)) &&
442 (Count > (bitmap.bmWidth * 4lu)))
443 {
444 CopyMemory(&Val, &pBits[(Count - (bitmap.bmWidth * 4l))], 4);
445 c2 = GetGValue(Val);
446
447 CopyMemory(&Val, &pBits[Count + 4], 4);
448 c3 = GetGValue(Val);
449
450 CopyMemory(&Val, &pBits[(Count + (bitmap.bmWidth * 4l))], 4);
451 c4 = GetGValue(Val);
452
453 CopyMemory(&Val, &pBits[Count - 4], 4);
454 c5 = GetGValue(Val);
455
456 g = (c1 * 5) - (c2 + c3 + c4 + c5);
457 }
458
459 /* Blue */
460 c1 = b;
461 if ((Count < ((bitmap.bmHeight - 1) * bitmap.bmWidth * 4lu)) &&
462 (Count > (bitmap.bmWidth * 4lu)))
463 {
464 CopyMemory(&Val, &pBits[(Count - (bitmap.bmWidth * 4l))], 4);
465 c2 = GetRValue(Val);
466
467 CopyMemory(&Val, &pBits[Count + 4], 4);
468 c3 = GetRValue(Val);
469
470 CopyMemory(&Val, &pBits[(Count+(bitmap.bmWidth * 4l))], 4);
471 c4 = GetRValue(Val);
472
473 CopyMemory(&Val, &pBits[Count - 4], 4);
474 c5 = GetRValue(Val);
475
476 b = (c1 * 5) - (c2 + c3 + c4 + c5);
477 }
478
479 /* Red */
480 if (r > 255) r = 255;
481 if (r < 0) r = 0;
482
483 /* Green */
484 if (g > 255) g = 255;
485 if (g < 0)g = 0;
486
487 /* Blue */
488 if (b > 255) b = 255;
489 if (b < 0) b = 0;
490
491 Val = RGB(b, g, r);
492
493 CopyMemory(&pBitsTemp[Count],
494 &Val,
495 4);
496
497 Count+=4;
498 }
499 }
500
501 /* Set the new pixel bits */
502 SetDIBits(hdcMem,
503 hBitmap,
504 0,
505 bRes,
506 pBitsTemp,
507 &bi,
508 DIB_RGB_COLORS);
509
510 HeapFree(ProcessHeap,
511 0,
512 pBits);
513 HeapFree(ProcessHeap,
514 0,
515 pBitsTemp);
516
517 GetClientRect(hwnd,
518 &rc);
519
520 InvalidateRect(hwnd,
521 &rc,
522 FALSE);
523
524 return TRUE;
525 }