ReactOS  0.4.14-dev-49-gfb4591c
contrast.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 #define BASECOLOUR 100
4 
5 
6 VOID
7 AdjustContrast(HBITMAP hOrigBitmap,
8  HBITMAP hNewBitmap,
9  HWND hwnd,
10  HDC hdcMem,
11  INT RedVal,
12  INT GreenVal,
13  INT BlueVal)
14 {
15  BITMAPINFO bi;
16  BITMAP bitmap;
17  BOOL bRes;
18  DWORD Count = 0;
19  INT i, j;
20  PBYTE pBits;
21  RECT rc;
22 
23  GetObject(hNewBitmap,
24  sizeof(BITMAP),
25  &bitmap);
26 
27  /* Bitmap header */
28  bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
29  bi.bmiHeader.biWidth = bitmap.bmWidth;
30  bi.bmiHeader.biHeight = bitmap.bmHeight;
31  bi.bmiHeader.biPlanes = 1;
32  bi.bmiHeader.biBitCount = 32;
34  bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;
35  bi.bmiHeader.biClrUsed = 0;
37 
38  /* Buffer */
39  pBits = (PBYTE)HeapAlloc(ProcessHeap,
40  0,
41  bitmap.bmWidth * bitmap.bmHeight * 4);
42  if (!pBits)
43  return;
44 
45  /* get the bits from the original bitmap */
46  bRes = GetDIBits(hdcMem,
47  hOrigBitmap,
48  0,
49  bitmap.bmHeight,
50  pBits,
51  &bi,
53 
54  for (i = 0; i < bitmap.bmHeight; i++)
55  {
56  for (j = 0; j < bitmap.bmWidth; j++)
57  {
58  DWORD Val = 0;
59  INT b, g, r;
60 
61  CopyMemory(&Val,
62  &pBits[Count],
63  4);
64 
65  /* Get pixels in reverse order */
66  b = GetRValue(Val);
67  g = GetGValue(Val);
68  r = GetBValue(Val);
69 
70  r = ((r - 128) * RedVal) / 100 + 128;
71  g = ((g - 128) * GreenVal) / 100 + 128;
72  b = ((b - 128) * BlueVal) / 100 + 128;
73 
74  /* Red */
75  if (r > 255) r = 255;
76  else if (r < 0) r = 0;
77 
78  /* Green */
79  if (g > 255) g = 255;
80  else if (g < 0) g = 0;
81 
82  /* Blue */
83  if (b > 255) b = 255;
84  else if (b < 0) b = 0;
85 
86  /* Store in reverse order */
87  Val = RGB(b, g, r);
88  CopyMemory(&pBits[Count],
89  &Val,
90  4);
91 
92  /* RGB color take 4 bytes.The high-order byte must be zero */
93  Count += 4;
94  }
95  }
96 
97  /* Set the new pixel bits */
99  hNewBitmap,
100  0,
101  bRes,
102  pBits,
103  &bi,
105 
107  0,
108  pBits);
109 
111  &rc);
112 
114  &rc,
115  FALSE);
116 }
117 
118 
119 static PIMAGEADJUST
121  HWND hDlg,
122  LPARAM lParam)
123 {
124  pImgAdj = (IMAGEADJUST*) HeapAlloc(ProcessHeap,
125  0,
126  sizeof(IMAGEADJUST));
127  if (!pImgAdj)
128  return NULL;
129 
130 
131  pImgAdj->Info = (PMAIN_WND_INFO)lParam;
132  if (!pImgAdj->Info->ImageEditors)
133  goto fail;
134 
135 
136  pImgAdj->hPicPrev = GetDlgItem(hDlg, IDC_PICPREVIEW);
137  GetClientRect(pImgAdj->hPicPrev,
138  &pImgAdj->ImageRect);
139 
140  /* Make a static copy of the main image */
141  pImgAdj->hBitmap = (HBITMAP) CopyImage(pImgAdj->Info->ImageEditors->hBitmap,
142  IMAGE_BITMAP,
143  pImgAdj->ImageRect.right,
144  pImgAdj->ImageRect.bottom,
146  if (!pImgAdj->hBitmap)
147  goto fail;
148 
149  /* Make a copy which will be updated */
150  pImgAdj->hPreviewBitmap = (HBITMAP) CopyImage(pImgAdj->Info->ImageEditors->hBitmap,
151  IMAGE_BITMAP,
152  pImgAdj->ImageRect.right,
153  pImgAdj->ImageRect.bottom,
155  if (!pImgAdj->hPreviewBitmap)
156  goto fail;
157 
158 
159  pImgAdj->RedVal = pImgAdj->BlueVal = pImgAdj->GreenVal = 100;
160 
161  /* setup dialog */
162  SendDlgItemMessage(hDlg,
163  IDC_BRI_FULL,
164  BM_SETCHECK,
165  BST_CHECKED,
166  0);
167  SendDlgItemMessage(hDlg,
169  TBM_SETRANGE,
170  TRUE,
171  (LPARAM)MAKELONG(0, 200));
172  SendDlgItemMessage(hDlg,
174  TBM_SETPOS,
175  TRUE,
176  (LPARAM)BASECOLOUR);
177  SetDlgItemText(hDlg,
178  IDC_BRI_EDIT,
179  _T("100"));
180 
181  return pImgAdj;
182 
183 fail:
185  0,
186  pImgAdj);
187  return NULL;
188 }
189 
190 
191 static VOID
193  LPARAM lParam)
194 {
195  LPDRAWITEMSTRUCT lpDrawItem;
196  HDC hdcMem;
197 
198  lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
199 
200  hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
201 
202  if(lpDrawItem->CtlID == IDC_PICPREVIEW)
203  {
205  pImgAdj->hPreviewBitmap);
206 
207  BitBlt(lpDrawItem->hDC,
208  pImgAdj->ImageRect.left,
209  pImgAdj->ImageRect.top,
210  pImgAdj->ImageRect.right,
211  pImgAdj->ImageRect.bottom,
212  hdcMem,
213  0,
214  0,
215  SRCCOPY);
216 
217  DeleteDC(hdcMem);
218  }
219 }
220 
221 
222 static VOID
224  HWND hDlg)
225 {
226  HDC hdcMem;
227  DWORD TrackPos;
228 
229  TrackPos = (DWORD)SendDlgItemMessage(hDlg,
231  TBM_GETPOS,
232  0,
233  0);
234 
235  SetDlgItemInt(hDlg,
236  IDC_BRI_EDIT,
237  TrackPos,
238  FALSE);
239 
241  {
242  pImgAdj->RedVal = pImgAdj->GreenVal = pImgAdj->BlueVal = TrackPos - BASECOLOUR + 100;
243  }
244  else if (IsDlgButtonChecked(hDlg, IDC_BRI_RED) == BST_CHECKED)
245  {
246  pImgAdj->RedVal = TrackPos - BASECOLOUR + 100;
247  }
248  else if (IsDlgButtonChecked(hDlg, IDC_BRI_GREEN) == BST_CHECKED)
249  {
250  pImgAdj->GreenVal = TrackPos - BASECOLOUR + 100;
251  }
252  else if (IsDlgButtonChecked(hDlg, IDC_BRI_BLUE) == BST_CHECKED)
253  {
254  pImgAdj->BlueVal = TrackPos - BASECOLOUR + 100;
255  }
256 
257  hdcMem = GetDC(pImgAdj->hPicPrev);
258 
259  AdjustContrast(pImgAdj->hBitmap,
260  pImgAdj->hPreviewBitmap,
261  pImgAdj->hPicPrev,
262  hdcMem,
263  pImgAdj->RedVal,
264  pImgAdj->GreenVal,
265  pImgAdj->BlueVal);
266 
267  ReleaseDC(pImgAdj->hPicPrev, hdcMem);
268 }
269 
270 
271 static BOOL
273  HWND hDlg,
274  UINT uID)
275 {
276  switch (uID)
277  {
278  case IDOK:
279  {
280  HDC hdcMem;
281 
282  hdcMem = GetDC(pImgAdj->Info->ImageEditors->hSelf);
283 
285  pImgAdj->Info->ImageEditors->hBitmap,
286  pImgAdj->Info->ImageEditors->hSelf,
287  hdcMem,
288  pImgAdj->RedVal,
289  pImgAdj->GreenVal,
290  pImgAdj->BlueVal);
291 
292  ReleaseDC(pImgAdj->Info->ImageEditors->hSelf,
293  hdcMem);
294 
295  EndDialog(hDlg,
296  uID);
297 
298  return TRUE;
299  }
300 
301  case IDCANCEL:
302  {
303  EndDialog(hDlg,
304  uID);
305  return TRUE;
306  }
307  }
308 
309  return FALSE;
310 }
311 
312 
315  UINT message,
316  WPARAM wParam,
317  LPARAM lParam)
318 {
319  static PIMAGEADJUST pImgAdj = NULL;
320 
321  switch (message)
322  {
323  case WM_INITDIALOG:
324  {
325  pImgAdj = Cont_OnInitDialog(pImgAdj,
326  hDlg,
327  lParam);
328  if (!pImgAdj)
329  {
330  EndDialog(hDlg, -1);
331  return FALSE;
332  }
333 
334  return TRUE;
335  }
336 
337  case WM_DRAWITEM:
338  {
339  Cont_OnDrawItem(pImgAdj,
340  lParam);
341  return TRUE;
342  }
343 
344  case WM_HSCROLL:
345  {
346  if (LOWORD(wParam) == TB_THUMBTRACK ||
348  {
349  Cont_OnTrackBar(pImgAdj,
350  hDlg);
351  }
352 
353  return TRUE;
354  }
355 
356  case WM_COMMAND:
357  {
358  return Cont_OnCommand(pImgAdj,
359  hDlg,
360  LOWORD(wParam));
361  }
362 
363  case WM_DESTROY:
364  {
365  if (pImgAdj)
366  {
367  if (pImgAdj->hBitmap)
368  DeleteObject(pImgAdj->hBitmap);
369  if (pImgAdj->hPreviewBitmap)
370  DeleteObject(pImgAdj->hPreviewBitmap);
371 
373  0,
374  pImgAdj);
375  }
376  }
377  }
378 
379  return FALSE;
380 }
#define TB_THUMBTRACK
Definition: commctrl.h:2050
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IDC_BRI_GREEN
Definition: resource.h:258
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
DWORD biClrImportant
Definition: amvideo.idl:40
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
HDC WINAPI GetDC(_In_opt_ HWND)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define IDC_BRI_RED
Definition: resource.h:257
static HDC
Definition: imagelist.c:92
static BOOL Cont_OnCommand(PIMAGEADJUST pImgAdj, HWND hDlg, UINT uID)
Definition: contrast.c:272
#define CALLBACK
Definition: compat.h:27
#define GetRValue(rgb)
Definition: wingdi.h:2930
#define TBM_SETRANGE
Definition: commctrl.h:2009
LONG top
Definition: windef.h:292
#define IDC_BRI_FULL
Definition: resource.h:256
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define TBM_SETPOS
Definition: commctrl.h:2008
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5743
LONG left
Definition: windef.h:291
int32_t INT_PTR
Definition: typedefs.h:62
LONG right
Definition: windef.h:293
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
HWND hPicPrev
Definition: imageprop.h:5
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define GetGValue(rgb)
Definition: wingdi.h:2931
RECT ImageRect
Definition: imageprop.h:8
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PMAIN_WND_INFO Info
Definition: imageprop.h:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TBM_GETPOS
Definition: commctrl.h:2003
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
INT_PTR CALLBACK ContrastProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: contrast.c:314
DWORD biCompression
Definition: amvideo.idl:35
#define MAKELONG(a, b)
Definition: typedefs.h:248
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define b
Definition: ke_i.h:79
#define IDC_BRI_BLUE
Definition: resource.h:259
#define WM_DESTROY
Definition: winuser.h:1591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
Definition: uimain.c:88
GLboolean GLboolean g
Definition: glext.h:6204
#define BM_SETCHECK
Definition: winuser.h:1903
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define _T(x)
Definition: vfdio.h:22
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BASECOLOUR
Definition: contrast.c:3
#define RGB(r, g, b)
Definition: wingdi.h:2935
struct _MAIN_WND_INFO * PMAIN_WND_INFO
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD biSizeImage
Definition: amvideo.idl:36
#define GetObject
Definition: wingdi.h:4463
#define SetDlgItemText
Definition: winuser.h:5750
VOID AdjustContrast(HBITMAP hOrigBitmap, HBITMAP hNewBitmap, HWND hwnd, HDC hdcMem, INT RedVal, INT GreenVal, INT BlueVal)
Definition: contrast.c:7
#define TB_ENDTRACK
Definition: commctrl.h:2053
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
static PIMAGEADJUST Cont_OnInitDialog(PIMAGEADJUST pImgAdj, HWND hDlg, LPARAM lParam)
Definition: contrast.c:120
#define IDC_PICPREVIEW
Definition: resource.h:251
#define WM_COMMAND
Definition: winuser.h:1722
HBITMAP hBitmap
Definition: imgedwnd.h:67
HANDLE ProcessHeap
Definition: servman.c:15
#define IDC_BRI_TRACKBAR
Definition: resource.h:261
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
static VOID Cont_OnDrawItem(PIMAGEADJUST pImgAdj, LPARAM lParam)
Definition: contrast.c:192
#define IDC_BRI_EDIT
Definition: resource.h:260
BOOL WINAPI DeleteDC(_In_ HDC)
Definition: bl.h:1331
#define LR_CREATEDIBSECTION
Definition: winuser.h:1088
HBITMAP hPreviewBitmap
Definition: imageprop.h:7
INT GreenVal
Definition: imageprop.h:10
unsigned int UINT
Definition: ndis.h:50
#define WM_HSCROLL
Definition: winuser.h:1725
#define IMAGE_BITMAP
Definition: winuser.h:211
INT RedVal
Definition: imageprop.h:9
#define BST_CHECKED
Definition: winuser.h:197
#define WM_DRAWITEM
Definition: winuser.h:1627
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
static VOID Cont_OnTrackBar(PIMAGEADJUST pImgAdj, HWND hDlg)
Definition: contrast.c:223
LONG bottom
Definition: windef.h:294
#define GetBValue(rgb)
Definition: wingdi.h:2932
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
#define IDCANCEL
Definition: winuser.h:825
#define DIB_RGB_COLORS
Definition: wingdi.h:366
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
BYTE * PBYTE
Definition: pedump.c:66
#define WM_INITDIALOG
Definition: winuser.h:1721
#define BI_RGB
Definition: precomp.h:34
LPARAM lParam
Definition: combotst.c:139
PEDIT_WND_INFO ImageEditors
Definition: mainwnd.h:22
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SRCCOPY
Definition: wingdi.h:332
HBITMAP hBitmap
Definition: imageprop.h:6
HDC hdcMem
Definition: welcome.c:104