- 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.

svn path=/trunk/; revision=24771
This commit is contained in:
Ged Murphy
2006-11-16 18:49:58 +00:00
parent 596c3bee62
commit 265fc33b63
7 changed files with 208 additions and 59 deletions
@@ -0,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);
}
+63 -30
View File
@@ -6,70 +6,79 @@ BrightnessProc(HWND hDlg,
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;
}
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 @@ BrightnessProc(HWND hDlg,
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 @@ BrightnessProc(HWND hDlg,
}
}
break;
case WM_DESTROY:
{
DeleteObject(pImgAdj->hBitmap);
HeapFree(ProcessHeap,
0,
pImgAdj);
}
}
return FALSE;
@@ -0,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);
@@ -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>
+15 -19
View File
@@ -70,41 +70,35 @@ LoadDIBImage(PEDIT_WND_INFO Info)
if (bSuccess && (BytesRead == sizeof(BITMAPFILEHEADER))
&& (bmfh.bfType == *(WORD *)"BM"))
{
PBITMAPINFO pbmi;
DWORD InfoSize;
DWORD InfoSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
InfoSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
pbmi = HeapAlloc(ProcessHeap,
0,
InfoSize);
if (pbmi)
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 @@ LoadDIBImage(PEDIT_WND_INFO Info)
bRet = TRUE;
}
}
HeapFree(ProcessHeap,
0,
pbmi);
}
}
else if (!bSuccess)
@@ -186,6 +176,12 @@ DestroyEditWnd(PEDIT_WND_INFO Info)
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;
@@ -66,6 +66,8 @@ typedef struct _EDIT_WND_INFO
HWND hSelf;
HBITMAP hBitmap;
HDC hDCMem;
PBITMAPINFO pbmi;
PBYTE pBits;
struct _MAIN_WND_INFO *MainWnd;
struct _EDIT_WND_INFO *Next;
POINT ScrollPos;
+1 -10
View File
@@ -12,6 +12,7 @@
#include "tooldock.h"
#include "imgedwnd.h"
#include "mainwnd.h"
#include "imageprop.h"
#include "misc.h"
#define MAX_KEY_LENGTH 256
@@ -32,16 +33,6 @@ INT_PTR CALLBACK AboutDialogProc(HWND hDlg,
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);
BOOL DoOpenFile(HWND hwnd,