Author: gedmurphy
Date: Thu Nov 16 21:49:58 2006
New Revision: 24771
URL:
http://svn.reactos.org/svn/reactos?rev=24771&view=rev
Log:
- Add test code for adjusting the brightness of an image. It's a bit of a hack at the
moment, but adjusting the trackbar in the brightness dialog will alter the brightness of
the small image.
- save pointer to the bitmap header and bitmap bits in the image struct.
Added:
trunk/reactos/base/applications/imagesoft/adjust.c
trunk/reactos/base/applications/imagesoft/imageprop.h
Modified:
trunk/reactos/base/applications/imagesoft/imageprop.c
trunk/reactos/base/applications/imagesoft/imagesoft.rbuild
trunk/reactos/base/applications/imagesoft/imgedwnd.c
trunk/reactos/base/applications/imagesoft/imgedwnd.h
trunk/reactos/base/applications/imagesoft/precomp.h
trunk/reactos/base/applications/imagesoft/res/imagesoft.ico (props changed)
Added: trunk/reactos/base/applications/imagesoft/adjust.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/adjust.c (added)
+++ trunk/reactos/base/applications/imagesoft/adjust.c Thu Nov 16 21:49:58 2006
@@ -1,0 +1,101 @@
+#include "precomp.h"
+
+
+VOID
+AdjustBrightness(PIMAGEADJUST pImgAdj,
+ HDC hdcMem)
+{
+ BITMAPINFO bi;
+ BITMAP bitmap;
+ BOOL bRes;
+ DWORD Count = 0;
+ INT i, j;
+ PBYTE pBits;
+
+ /* Bitmap header */
+ bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
+ bi.bmiHeader.biWidth = pImgAdj->ImageRect.right;
+ bi.bmiHeader.biHeight = pImgAdj->ImageRect.bottom;
+ bi.bmiHeader.biPlanes = 1;
+ bi.bmiHeader.biBitCount = 32;
+ bi.bmiHeader.biCompression = BI_RGB;
+ bi.bmiHeader.biSizeImage = pImgAdj->ImageRect.right * 4 *
pImgAdj->ImageRect.bottom;
+ bi.bmiHeader.biClrUsed = 0;
+ bi.bmiHeader.biClrImportant = 0;
+
+ /* Buffer */
+ pBits = (PBYTE)HeapAlloc(ProcessHeap,
+ 0,
+ pImgAdj->ImageRect.right * 4 *
pImgAdj->ImageRect.bottom);
+
+ bRes = GetDIBits(hdcMem,
+ pImgAdj->hBitmap,
+ 0,
+ pImgAdj->ImageRect.bottom,
+ pBits,
+ &bi,
+ DIB_RGB_COLORS);
+
+ GetObject(pImgAdj->hBitmap,
+ sizeof(BITMAP),
+ &bitmap);
+
+ for (i = 0; i < bitmap.bmHeight; i++)
+ {
+ for (j = 0; j < bitmap.bmWidth; j++)
+ {
+ DWORD Val = 0;
+ INT b, g, r;
+
+ CopyMemory(&Val,
+ &pBits[Count],
+ 4);
+
+ /* Get pixels in reverse order */
+ b = GetRValue(Val);
+ g = GetGValue(Val);
+ r = GetBValue(Val);
+
+ /* Red */
+ r += pImgAdj->RedVal;
+ if (r > 255) r = 255;
+ else if (r < 0) r = 0;
+
+ /* Green */
+ g += pImgAdj->GreenVal;
+ if (g > 255) g = 255;
+ else if (g < 0) g = 0;
+
+ /* Blue */
+ b += pImgAdj->BlueVal;
+ if (b > 255) b = 255;
+ else if (b < 0) b = 0;
+
+ /* Store in reverse order */
+ Val = RGB(b, g, r);
+ CopyMemory(&pBits[Count],
+ &Val,
+ 4);
+
+ /* RGB color take 4 bytes.The high-order byte must be zero */
+ Count += 4;
+ }
+ }
+
+ /* Set the new pixel bits */
+ SetDIBits(hdcMem,
+ pImgAdj->hBitmap,
+ 0,
+ bRes,
+ pBits,
+ &bi,
+ DIB_RGB_COLORS);
+
+ HeapFree(ProcessHeap,
+ 0,
+ pBits);
+
+ InvalidateRect(pImgAdj->hPicPrev,
+ &pImgAdj->ImageRect,
+ FALSE);
+}
Modified: trunk/reactos/base/applications/imagesoft/imageprop.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/imageprop.c (original)
+++ trunk/reactos/base/applications/imagesoft/imageprop.c Thu Nov 16 21:49:58 2006
@@ -6,36 +6,52 @@
WPARAM wParam,
LPARAM lParam)
{
- static PMAIN_WND_INFO Info = NULL;
+ static PIMAGEADJUST pImgAdj = NULL;
switch (message)
{
case WM_INITDIALOG:
{
- Info = (PMAIN_WND_INFO)lParam;
+ pImgAdj = HeapAlloc(ProcessHeap,
+ 0,
+ sizeof(IMAGEADJUST));
+ if (!pImgAdj)
+ return -1;
+ /* setup values */
+ pImgAdj->Info = (PMAIN_WND_INFO)lParam;
+ pImgAdj->hPicPrev = GetDlgItem(hDlg, IDC_PICPREVIEW);
+ GetClientRect(pImgAdj->hPicPrev,
+ &pImgAdj->ImageRect);
+
+ pImgAdj->hBitmap =
CopyImage(pImgAdj->Info->ImageEditors->hBitmap,
+ IMAGE_BITMAP,
+ pImgAdj->ImageRect.right,
+ pImgAdj->ImageRect.bottom,
+ LR_CREATEDIBSECTION);
+
+ pImgAdj->OldTrackPos = 100;
+ pImgAdj->RedVal = pImgAdj->BlueVal = pImgAdj->GreenVal = 0;
+
+ /* setup dialog */
SendDlgItemMessage(hDlg,
IDC_BRI_FULL,
BM_SETCHECK,
BST_CHECKED,
0);
-
SendDlgItemMessage(hDlg,
IDC_BRI_TRACKBAR,
TBM_SETRANGE,
TRUE,
(LPARAM)MAKELONG(0, 200));
-
SendDlgItemMessage(hDlg,
IDC_BRI_TRACKBAR,
TBM_SETPOS,
TRUE,
(LPARAM)100);
-
SetDlgItemText(hDlg,
IDC_BRI_EDIT,
_T("100"));
-
return TRUE;
}
@@ -43,33 +59,26 @@
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpDrawItem;
- HWND hPicPrev = GetDlgItem(hDlg, IDC_PICPREVIEW);
- RECT ImageRect = {0};
HDC hdcMem;
lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
-
- GetClientRect(hPicPrev,
- &ImageRect);
hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
if(lpDrawItem->CtlID == IDC_PICPREVIEW)
{
- SelectObject(hdcMem,
- Info->ImageEditors->hBitmap);
+ SelectObject(hdcMem,
+ pImgAdj->hBitmap);
- StretchBlt(lpDrawItem->hDC,
- ImageRect.left,
- ImageRect.top,
- ImageRect.right,
- ImageRect.bottom,
- hdcMem,
- 0,
- 0,
- Info->ImageEditors->Width,
- Info->ImageEditors->Height,
- SRCCOPY);
+ BitBlt(lpDrawItem->hDC,
+ pImgAdj->ImageRect.left,
+ pImgAdj->ImageRect.top,
+ pImgAdj->ImageRect.right,
+ pImgAdj->ImageRect.bottom,
+ hdcMem,
+ 0,
+ 0,
+ SRCCOPY);
DeleteDC(hdcMem);
}
@@ -81,15 +90,29 @@
if (LOWORD(wParam) == TB_THUMBTRACK ||
LOWORD(wParam) == TB_ENDTRACK)
{
- DWORD Pos = (DWORD)SendDlgItemMessage(hDlg,
- IDC_BRI_TRACKBAR,
- TBM_GETPOS,
- 0,
- 0);
+ HDC hdcMem;
+ DWORD TrackPos = (DWORD)SendDlgItemMessage(hDlg,
+ IDC_BRI_TRACKBAR,
+ TBM_GETPOS,
+ 0,
+ 0);
+
+ /* quick hack, change all the colours regardless */
+ pImgAdj->RedVal = pImgAdj->BlueVal = pImgAdj->GreenVal =
TrackPos - pImgAdj->OldTrackPos;
+ pImgAdj->OldTrackPos = TrackPos;
+
SetDlgItemInt(hDlg,
IDC_BRI_EDIT,
- Pos,
+ TrackPos,
FALSE);
+
+ hdcMem = GetDC(pImgAdj->hPicPrev);
+
+ AdjustBrightness(pImgAdj,
+ hdcMem);
+
+ ReleaseDC(pImgAdj->hPicPrev, hdcMem);
+
}
return TRUE;
@@ -106,6 +129,16 @@
}
}
break;
+
+ case WM_DESTROY:
+ {
+ DeleteObject(pImgAdj->hBitmap);
+
+ HeapFree(ProcessHeap,
+ 0,
+ pImgAdj);
+ }
+
}
return FALSE;
Added: trunk/reactos/base/applications/imagesoft/imageprop.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/imageprop.h (added)
+++ trunk/reactos/base/applications/imagesoft/imageprop.h Thu Nov 16 21:49:58 2006
@@ -1,0 +1,25 @@
+
+typedef struct _IMAGEADJUST
+{
+ PMAIN_WND_INFO Info;
+ HWND hPicPrev;
+ HBITMAP hBitmap;
+ RECT ImageRect;
+ DWORD OldTrackPos;
+ INT RedVal;
+ INT GreenVal;
+ INT BlueVal;
+} IMAGEADJUST, *PIMAGEADJUST;
+
+
+INT_PTR CALLBACK ImagePropDialogProc(HWND hDlg,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam);
+INT_PTR CALLBACK BrightnessProc(HWND hDlg,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam);
+
+VOID AdjustBrightness(PIMAGEADJUST pImgAdj,
+ HDC hdcMem);
Modified: trunk/reactos/base/applications/imagesoft/imagesoft.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/imagesoft.rbuild (original)
+++ trunk/reactos/base/applications/imagesoft/imagesoft.rbuild Thu Nov 16 21:49:58 2006
@@ -17,6 +17,7 @@
<library>comdlg32</library>
<compilationunit name="unit.c">
<file>about.c</file>
+ <file>adjust.c</file>
<file>custcombo.c</file>
<file>floatwindow.c</file>
<file>font.c</file>
Modified: trunk/reactos/base/applications/imagesoft/imgedwnd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/imgedwnd.c (original)
+++ trunk/reactos/base/applications/imagesoft/imgedwnd.c Thu Nov 16 21:49:58 2006
@@ -70,41 +70,35 @@
if (bSuccess && (BytesRead == sizeof(BITMAPFILEHEADER))
&& (bmfh.bfType == *(WORD *)"BM"))
{
- PBITMAPINFO pbmi;
- DWORD InfoSize;
-
- InfoSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
-
- pbmi = HeapAlloc(ProcessHeap,
- 0,
- InfoSize);
- if (pbmi)
+ DWORD InfoSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
+
+ Info->pbmi = HeapAlloc(ProcessHeap,
+ 0,
+ InfoSize);
+ if (Info->pbmi)
{
bSuccess = ReadFile(hFile,
- pbmi,
+ Info->pbmi,
InfoSize,
&BytesRead,
NULL);
if (bSuccess && (BytesRead == InfoSize))
{
- PBYTE pBits;
-
Info->hBitmap = CreateDIBSection(NULL,
- pbmi,
+ Info->pbmi,
DIB_RGB_COLORS,
- (VOID *)&pBits,
+ (VOID *)&Info->pBits,
NULL,
0);
if (Info->hBitmap != NULL)
{
ReadFile(hFile,
- pBits,
+ Info->pBits,
bmfh.bfSize - bmfh.bfOffBits,
&BytesRead,
NULL);
- /* get bitmap dimensions */
GetObject(Info->hBitmap,
sizeof(BITMAP),
&bitmap);
@@ -115,10 +109,6 @@
bRet = TRUE;
}
}
-
- HeapFree(ProcessHeap,
- 0,
- pbmi);
}
}
else if (!bSuccess)
@@ -186,6 +176,12 @@
DeleteDC(Info->hDCMem);
/* FIXME - free resources and run down editor */
+ HeapFree(ProcessHeap,
+ 0,
+ Info->pbmi);
+ HeapFree(ProcessHeap,
+ 0,
+ Info->pBits);
/* Remove the image editor from the list */
PrevEditor = &Info->MainWnd->ImageEditors;
Modified: trunk/reactos/base/applications/imagesoft/imgedwnd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/imgedwnd.h (original)
+++ trunk/reactos/base/applications/imagesoft/imgedwnd.h Thu Nov 16 21:49:58 2006
@@ -66,6 +66,8 @@
HWND hSelf;
HBITMAP hBitmap;
HDC hDCMem;
+ PBITMAPINFO pbmi;
+ PBYTE pBits;
struct _MAIN_WND_INFO *MainWnd;
struct _EDIT_WND_INFO *Next;
POINT ScrollPos;
Modified: trunk/reactos/base/applications/imagesoft/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/imagesof…
==============================================================================
--- trunk/reactos/base/applications/imagesoft/precomp.h (original)
+++ trunk/reactos/base/applications/imagesoft/precomp.h Thu Nov 16 21:49:58 2006
@@ -12,6 +12,7 @@
#include "tooldock.h"
#include "imgedwnd.h"
#include "mainwnd.h"
+#include "imageprop.h"
#include "misc.h"
#define MAX_KEY_LENGTH 256
@@ -31,16 +32,6 @@
UINT message,
WPARAM wParam,
LPARAM lParam);
-
-/* imageprop.c */
-INT_PTR CALLBACK ImagePropDialogProc(HWND hDlg,
- UINT message,
- WPARAM wParam,
- LPARAM lParam);
-INT_PTR CALLBACK BrightnessProc(HWND hDlg,
- UINT message,
- WPARAM wParam,
- LPARAM lParam);
/* opensave.c */
VOID FileInitialize(HWND hwnd);
Propchange: trunk/reactos/base/applications/imagesoft/res/imagesoft.ico
------------------------------------------------------------------------------
--- svn:needs-lock (original)
+++ svn:needs-lock (removed)
@@ -1,1 +1,0 @@
-*