- merge the latest code from my minibranch:
authorGed Murphy <gedmurphy@reactos.org>
Sun, 19 Nov 2006 19:49:45 +0000 (19:49 +0000)
committerGed Murphy <gedmurphy@reactos.org>
Sun, 19 Nov 2006 19:49:45 +0000 (19:49 +0000)
- use a static image to refer to when choosing your image brightness so returning to normal (100) displays the original colours
- allow  individual colours (RGB) to be adjusted as well as adjusting them all simultaneously
- apply the chosen brightness from the dialog to the main image
- implement greyscale, so an image can be displayed in black and white
- implement inverting of colours so an image can be displayed as a negative.

svn path=/trunk/; revision=24784

reactos/base/applications/imagesoft/adjust.c
reactos/base/applications/imagesoft/brightness.c [new file with mode: 0644]
reactos/base/applications/imagesoft/imageprop.c [deleted file]
reactos/base/applications/imagesoft/imageprop.h
reactos/base/applications/imagesoft/imagesoft.rbuild
reactos/base/applications/imagesoft/imgedwnd.c
reactos/base/applications/imagesoft/lang/En.rc
reactos/base/applications/imagesoft/mainwnd.c
reactos/base/applications/imagesoft/resource.h

index 42b4ea9..ba414f1 100644 (file)
@@ -1,9 +1,10 @@
-#include "precomp.h"\r
+#include <precomp.h>\r
 \r
 \r
-VOID\r
-AdjustBrightness(PIMAGEADJUST pImgAdj,\r
-                 HDC hdcMem)\r
+BOOL\r
+DisplayBlackAndWhite(HWND hwnd,\r
+                     HDC hdcMem,\r
+                     HBITMAP hBitmap)\r
 {\r
     BITMAPINFO bi;\r
     BITMAP bitmap;\r
@@ -11,35 +12,39 @@ AdjustBrightness(PIMAGEADJUST pImgAdj,
     DWORD Count = 0;\r
     INT i, j;\r
     PBYTE pBits;\r
+    RECT rc;\r
+\r
+    GetObject(hBitmap,\r
+              sizeof(BITMAP),\r
+              &bitmap);\r
 \r
     /* Bitmap header */\r
     bi.bmiHeader.biSize = sizeof(bi.bmiHeader);\r
-    bi.bmiHeader.biWidth = pImgAdj->ImageRect.right;\r
-    bi.bmiHeader.biHeight = pImgAdj->ImageRect.bottom;\r
+    bi.bmiHeader.biWidth = bitmap.bmWidth;\r
+    bi.bmiHeader.biHeight = bitmap.bmHeight;\r
     bi.bmiHeader.biPlanes = 1;\r
     bi.bmiHeader.biBitCount = 32;\r
     bi.bmiHeader.biCompression = BI_RGB;\r
-    bi.bmiHeader.biSizeImage = pImgAdj->ImageRect.right * 4 * pImgAdj->ImageRect.bottom;\r
+    bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;\r
     bi.bmiHeader.biClrUsed = 0;\r
     bi.bmiHeader.biClrImportant = 0;\r
 \r
     /* Buffer */\r
     pBits = (PBYTE)HeapAlloc(ProcessHeap,\r
                              0,\r
-                             pImgAdj->ImageRect.right * 4 * pImgAdj->ImageRect.bottom);\r
+                             bitmap.bmWidth * bitmap.bmHeight * 4);\r
+    if (!pBits)\r
+        return FALSE;\r
 \r
+    /* get the bits from the original bitmap */\r
     bRes = GetDIBits(hdcMem,\r
-                     pImgAdj->hBitmap,\r
+                     hBitmap,\r
                      0,\r
-                     pImgAdj->ImageRect.bottom,\r
+                     bitmap.bmHeight,\r
                      pBits,\r
                      &bi,\r
                      DIB_RGB_COLORS);\r
 \r
-    GetObject(pImgAdj->hBitmap,\r
-              sizeof(BITMAP),\r
-              &bitmap);\r
-\r
     for (i = 0; i < bitmap.bmHeight; i++)\r
     {\r
         for (j = 0; j < bitmap.bmWidth; j++)\r
@@ -56,35 +61,22 @@ AdjustBrightness(PIMAGEADJUST pImgAdj,
             g = GetGValue(Val);\r
             r = GetBValue(Val);\r
 \r
-            /* Red */\r
-            r += pImgAdj->RedVal;\r
-            if (r > 255) r = 255;\r
-            else if (r < 0) r = 0;\r
-\r
-            /* Green */\r
-            g += pImgAdj->GreenVal;\r
-            if (g > 255) g = 255;\r
-            else if (g < 0) g = 0;\r
-\r
-            /* Blue */\r
-            b += pImgAdj->BlueVal;\r
-            if (b > 255) b = 255;\r
-            else if (b < 0) b = 0;\r
-\r
-            /* Store in reverse order */\r
-            Val = RGB(b, g, r);\r
-            CopyMemory(&pBits[Count],\r
-                       &Val,\r
+                       // get the average color value\r
+                       Val = (r+g+b)/3;\r
+\r
+                       // assign to RGB color                  \r
+                       Val = RGB(Val, Val, Val);\r
+                       CopyMemory(&pBits[Count], \r
+                       &Val, \r
                        4);\r
 \r
-            /* RGB color take 4 bytes.The high-order byte must be zero */\r
-            Count += 4;\r
+                       Count+=4;\r
         }\r
     }\r
 \r
     /* Set the new pixel bits */\r
     SetDIBits(hdcMem,\r
-              pImgAdj->hBitmap,\r
+              hBitmap,\r
               0,\r
               bRes,\r
               pBits,\r
@@ -95,7 +87,105 @@ AdjustBrightness(PIMAGEADJUST pImgAdj,
              0,\r
              pBits);\r
 \r
-    InvalidateRect(pImgAdj->hPicPrev,\r
-                   &pImgAdj->ImageRect,\r
+    GetClientRect(hwnd,\r
+                  &rc);\r
+\r
+    InvalidateRect(hwnd,\r
+                   &rc,\r
                    FALSE);\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+BOOL\r
+DisplayInvertedColors(HWND hwnd,\r
+                      HDC hdcMem,\r
+                      HBITMAP hBitmap)\r
+{\r
+    BITMAPINFO bi;\r
+    BITMAP bitmap;\r
+    BOOL bRes;\r
+    DWORD Count = 0;\r
+    INT i, j;\r
+    PBYTE pBits;\r
+    RECT rc;\r
+\r
+    GetObject(hBitmap,\r
+              sizeof(BITMAP),\r
+              &bitmap);\r
+\r
+    /* Bitmap header */\r
+    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);\r
+    bi.bmiHeader.biWidth = bitmap.bmWidth;\r
+    bi.bmiHeader.biHeight = bitmap.bmHeight;\r
+    bi.bmiHeader.biPlanes = 1;\r
+    bi.bmiHeader.biBitCount = 32;\r
+    bi.bmiHeader.biCompression = BI_RGB;\r
+    bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;\r
+    bi.bmiHeader.biClrUsed = 0;\r
+    bi.bmiHeader.biClrImportant = 0;\r
+\r
+    /* Buffer */\r
+    pBits = (PBYTE)HeapAlloc(ProcessHeap,\r
+                             0,\r
+                             bitmap.bmWidth * bitmap.bmHeight * 4);\r
+    if (!pBits)\r
+        return FALSE;\r
+\r
+    /* get the bits from the original bitmap */\r
+    bRes = GetDIBits(hdcMem,\r
+                     hBitmap,\r
+                     0,\r
+                     bitmap.bmHeight,\r
+                     pBits,\r
+                     &bi,\r
+                     DIB_RGB_COLORS);\r
+\r
+    for (i = 0; i < bitmap.bmHeight; i++)\r
+    {\r
+        for (j = 0; j < bitmap.bmWidth; j++)\r
+        {\r
+            DWORD Val = 0;\r
+            INT b, g, r;\r
+\r
+            CopyMemory(&Val,\r
+                       &pBits[Count],\r
+                       4);\r
+\r
+                       b = 255 - GetRValue(Val);\r
+                       g = 255 - GetGValue(Val);\r
+                       r = 255 - GetBValue(Val);\r
+                       \r
+                       Val = RGB(b, g, r);\r
+\r
+                       CopyMemory(&pBits[Count], \r
+                       &Val, \r
+                       4);\r
+\r
+                       Count+=4;\r
+        }\r
+    }\r
+\r
+    /* Set the new pixel bits */\r
+    SetDIBits(hdcMem,\r
+              hBitmap,\r
+              0,\r
+              bRes,\r
+              pBits,\r
+              &bi,\r
+              DIB_RGB_COLORS);\r
+\r
+    HeapFree(ProcessHeap,\r
+             0,\r
+             pBits);\r
+\r
+    GetClientRect(hwnd,\r
+                  &rc);\r
+\r
+    InvalidateRect(hwnd,\r
+                   &rc,\r
+                   FALSE);\r
+\r
+    return TRUE;\r
 }\r
diff --git a/reactos/base/applications/imagesoft/brightness.c b/reactos/base/applications/imagesoft/brightness.c
new file mode 100644 (file)
index 0000000..6403d70
--- /dev/null
@@ -0,0 +1,379 @@
+#include "precomp.h"\r
+\r
+#define BASECOLOUR 100\r
+\r
+\r
+VOID\r
+AdjustBrightness(HBITMAP hOrigBitmap,\r
+                 HBITMAP hNewBitmap,\r
+                 HWND hwnd,\r
+                 HDC hdcMem,\r
+                 INT RedVal,\r
+                 INT GreenVal,\r
+                 INT BlueVal)\r
+{\r
+    BITMAPINFO bi;\r
+    BITMAP bitmap;\r
+    BOOL bRes;\r
+    DWORD Count = 0;\r
+    INT i, j;\r
+    PBYTE pBits;\r
+    RECT rc;\r
+\r
+    GetObject(hNewBitmap,\r
+              sizeof(BITMAP),\r
+              &bitmap);\r
+\r
+    /* Bitmap header */\r
+    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);\r
+    bi.bmiHeader.biWidth = bitmap.bmWidth;\r
+    bi.bmiHeader.biHeight = bitmap.bmHeight;\r
+    bi.bmiHeader.biPlanes = 1;\r
+    bi.bmiHeader.biBitCount = 32;\r
+    bi.bmiHeader.biCompression = BI_RGB;\r
+    bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4;\r
+    bi.bmiHeader.biClrUsed = 0;\r
+    bi.bmiHeader.biClrImportant = 0;\r
+\r
+    /* Buffer */\r
+    pBits = (PBYTE)HeapAlloc(ProcessHeap,\r
+                             0,\r
+                             bitmap.bmWidth * bitmap.bmHeight * 4);\r
+    if (!pBits)\r
+        return;\r
+\r
+    /* get the bits from the original bitmap */\r
+    bRes = GetDIBits(hdcMem,\r
+                     hOrigBitmap,\r
+                     0,\r
+                     bitmap.bmHeight,\r
+                     pBits,\r
+                     &bi,\r
+                     DIB_RGB_COLORS);\r
+\r
+    for (i = 0; i < bitmap.bmHeight; i++)\r
+    {\r
+        for (j = 0; j < bitmap.bmWidth; j++)\r
+        {\r
+            DWORD Val = 0;\r
+            INT b, g, r;\r
+\r
+            CopyMemory(&Val,\r
+                       &pBits[Count],\r
+                       4);\r
+\r
+            /* Get pixels in reverse order */\r
+            b = GetRValue(Val);\r
+            g = GetGValue(Val);\r
+            r = GetBValue(Val);\r
+\r
+            /* Red */\r
+            r += RedVal;\r
+            if (r > 255) r = 255;\r
+            else if (r < 0) r = 0;\r
+\r
+            /* Green */\r
+            g += GreenVal;\r
+            if (g > 255) g = 255;\r
+            else if (g < 0) g = 0;\r
+\r
+            /* Blue */\r
+            b += BlueVal;\r
+            if (b > 255) b = 255;\r
+            else if (b < 0) b = 0;\r
+\r
+            /* Store in reverse order */\r
+            Val = RGB(b, g, r);\r
+            CopyMemory(&pBits[Count],\r
+                       &Val,\r
+                       4);\r
+\r
+            /* RGB color take 4 bytes.The high-order byte must be zero */\r
+            Count += 4;\r
+        }\r
+    }\r
+\r
+    /* Set the new pixel bits */\r
+    SetDIBits(hdcMem,\r
+              hNewBitmap,\r
+              0,\r
+              bRes,\r
+              pBits,\r
+              &bi,\r
+              DIB_RGB_COLORS);\r
+\r
+    HeapFree(ProcessHeap,\r
+             0,\r
+             pBits);\r
+\r
+    GetClientRect(hwnd,\r
+                  &rc);\r
+\r
+    InvalidateRect(hwnd,\r
+                   &rc,\r
+                   FALSE);\r
+}\r
+\r
+\r
+static PIMAGEADJUST\r
+OnInitDialog(PIMAGEADJUST pImgAdj,\r
+             HWND hDlg,\r
+             LPARAM lParam)\r
+{\r
+    pImgAdj = HeapAlloc(ProcessHeap,\r
+                        0,\r
+                        sizeof(IMAGEADJUST));\r
+    if (!pImgAdj)\r
+        return NULL;\r
+\r
+\r
+    pImgAdj->Info = (PMAIN_WND_INFO)lParam;\r
+    if (!pImgAdj->Info->ImageEditors)\r
+        goto fail;\r
+\r
+\r
+    pImgAdj->hPicPrev = GetDlgItem(hDlg, IDC_PICPREVIEW);\r
+    GetClientRect(pImgAdj->hPicPrev,\r
+                  &pImgAdj->ImageRect);\r
+\r
+    /* Make a static copy of the main image */\r
+    pImgAdj->hBitmap = CopyImage(pImgAdj->Info->ImageEditors->hBitmap,\r
+                                 IMAGE_BITMAP,\r
+                                 pImgAdj->ImageRect.right,\r
+                                 pImgAdj->ImageRect.bottom,\r
+                                 LR_CREATEDIBSECTION);\r
+    if (!pImgAdj->hBitmap)\r
+        goto fail;\r
+\r
+    /* Make a copy which will be updated */\r
+    pImgAdj->hPreviewBitmap = CopyImage(pImgAdj->Info->ImageEditors->hBitmap,\r
+                                        IMAGE_BITMAP,\r
+                                        pImgAdj->ImageRect.right,\r
+                                        pImgAdj->ImageRect.bottom,\r
+                                        LR_CREATEDIBSECTION);\r
+    if (!pImgAdj->hPreviewBitmap)\r
+        goto fail;\r
+\r
+\r
+    pImgAdj->RedVal = pImgAdj->BlueVal = pImgAdj->GreenVal = 0;\r
+\r
+    /* setup dialog */\r
+    SendDlgItemMessage(hDlg,\r
+                       IDC_BRI_FULL,\r
+                       BM_SETCHECK,\r
+                       BST_CHECKED,\r
+                       0);\r
+    SendDlgItemMessage(hDlg,\r
+                       IDC_BRI_TRACKBAR,\r
+                       TBM_SETRANGE,\r
+                       TRUE,\r
+                       (LPARAM)MAKELONG(0, 200));\r
+    SendDlgItemMessage(hDlg,\r
+                       IDC_BRI_TRACKBAR,\r
+                       TBM_SETPOS,\r
+                       TRUE,\r
+                       (LPARAM)BASECOLOUR);\r
+    SetDlgItemText(hDlg,\r
+                   IDC_BRI_EDIT,\r
+                   _T("100"));\r
+\r
+    return pImgAdj;\r
+\r
+fail:\r
+    HeapFree(ProcessHeap,\r
+             0,\r
+             pImgAdj);\r
+    return NULL;\r
+}\r
+\r
+\r
+static VOID\r
+OnDrawItem(PIMAGEADJUST pImgAdj,\r
+           LPARAM lParam)\r
+{\r
+    LPDRAWITEMSTRUCT lpDrawItem;\r
+    HDC hdcMem;\r
+\r
+    lpDrawItem = (LPDRAWITEMSTRUCT)lParam;\r
+\r
+    hdcMem = CreateCompatibleDC(lpDrawItem->hDC);\r
+\r
+    if(lpDrawItem->CtlID == IDC_PICPREVIEW)\r
+    {\r
+        SelectObject(hdcMem,\r
+                     pImgAdj->hPreviewBitmap);\r
+\r
+        BitBlt(lpDrawItem->hDC,\r
+               pImgAdj->ImageRect.left,\r
+               pImgAdj->ImageRect.top,\r
+               pImgAdj->ImageRect.right,\r
+               pImgAdj->ImageRect.bottom,\r
+               hdcMem,\r
+               0,\r
+               0,\r
+               SRCCOPY);\r
+\r
+        DeleteDC(hdcMem);\r
+    }\r
+}\r
+\r
+\r
+static VOID\r
+OnTrackBar(PIMAGEADJUST pImgAdj,\r
+           HWND hDlg)\r
+{\r
+    HDC hdcMem;\r
+    DWORD TrackPos;\r
+\r
+    TrackPos = (DWORD)SendDlgItemMessage(hDlg,\r
+                                         IDC_BRI_TRACKBAR,\r
+                                         TBM_GETPOS,\r
+                                         0,\r
+                                         0);\r
+\r
+    SetDlgItemInt(hDlg,\r
+                  IDC_BRI_EDIT,\r
+                  TrackPos,\r
+                  FALSE);\r
+\r
+    if (IsDlgButtonChecked(hDlg, IDC_BRI_FULL) == BST_CHECKED)\r
+    {\r
+        pImgAdj->RedVal = pImgAdj->GreenVal = pImgAdj->BlueVal = TrackPos - BASECOLOUR;\r
+    }\r
+    else if (IsDlgButtonChecked(hDlg, IDC_BRI_RED) == BST_CHECKED)\r
+    {\r
+        pImgAdj->RedVal = TrackPos - BASECOLOUR;\r
+    }\r
+    else if (IsDlgButtonChecked(hDlg, IDC_BRI_GREEN) == BST_CHECKED)\r
+    {\r
+        pImgAdj->GreenVal = TrackPos - BASECOLOUR;\r
+    }\r
+    else if (IsDlgButtonChecked(hDlg, IDC_BRI_BLUE) == BST_CHECKED)\r
+    {\r
+        pImgAdj->BlueVal = TrackPos - BASECOLOUR;\r
+    }\r
+\r
+    hdcMem = GetDC(pImgAdj->hPicPrev);\r
+\r
+    AdjustBrightness(pImgAdj->hBitmap,\r
+                     pImgAdj->hPreviewBitmap,\r
+                     pImgAdj->hPicPrev,\r
+                     hdcMem,\r
+                     pImgAdj->RedVal,\r
+                     pImgAdj->GreenVal,\r
+                     pImgAdj->BlueVal);\r
+\r
+    ReleaseDC(pImgAdj->hPicPrev, hdcMem);\r
+}\r
+\r
+\r
+static BOOL\r
+OnCommand(PIMAGEADJUST pImgAdj,\r
+          HWND hDlg,\r
+          UINT uID)\r
+{\r
+    switch (uID)\r
+    {\r
+        case IDOK:\r
+        {\r
+            HDC hdcMem;\r
+\r
+            hdcMem = GetDC(pImgAdj->Info->ImageEditors->hSelf);\r
+\r
+            AdjustBrightness(pImgAdj->Info->ImageEditors->hBitmap,\r
+                             pImgAdj->Info->ImageEditors->hBitmap,\r
+                             pImgAdj->Info->ImageEditors->hSelf,\r
+                             hdcMem,\r
+                             pImgAdj->RedVal,\r
+                             pImgAdj->GreenVal,\r
+                             pImgAdj->BlueVal);\r
+\r
+            ReleaseDC(pImgAdj->Info->ImageEditors->hSelf,\r
+                      hdcMem);\r
+\r
+            EndDialog(hDlg,\r
+                      uID);\r
+\r
+            return TRUE;\r
+        }\r
+\r
+        case IDCANCEL:\r
+        {\r
+            EndDialog(hDlg,\r
+                      uID);\r
+            return TRUE;\r
+        }\r
+    }\r
+\r
+    return FALSE;\r
+}\r
+\r
+\r
+INT_PTR CALLBACK\r
+BrightnessProc(HWND hDlg,\r
+               UINT message,\r
+               WPARAM wParam,\r
+               LPARAM lParam)\r
+{\r
+    static PIMAGEADJUST pImgAdj = NULL;\r
+\r
+    switch (message)\r
+    {\r
+        case WM_INITDIALOG:\r
+        {\r
+            pImgAdj = OnInitDialog(pImgAdj,\r
+                                   hDlg,\r
+                                   lParam);\r
+            if (!pImgAdj)\r
+            {\r
+                EndDialog(hDlg, -1);\r
+                return FALSE;\r
+            }\r
+\r
+            return TRUE;\r
+        }\r
+\r
+        case WM_DRAWITEM:\r
+        {\r
+            OnDrawItem(pImgAdj,\r
+                       lParam);\r
+            return TRUE;\r
+        }\r
+\r
+        case WM_HSCROLL:\r
+        {\r
+            if (LOWORD(wParam) == TB_THUMBTRACK ||\r
+                LOWORD(wParam) == TB_ENDTRACK)\r
+            {\r
+                OnTrackBar(pImgAdj,\r
+                           hDlg);\r
+            }\r
+\r
+            return TRUE;\r
+        }\r
+\r
+        case WM_COMMAND:\r
+        {\r
+            return OnCommand(pImgAdj,\r
+                             hDlg,\r
+                             LOWORD(wParam));\r
+        }\r
+\r
+        case WM_DESTROY:\r
+        {\r
+            if (pImgAdj)\r
+            {\r
+                if (pImgAdj->hBitmap)\r
+                    DeleteObject(pImgAdj->hBitmap);\r
+                if (pImgAdj->hPreviewBitmap)\r
+                    DeleteObject(pImgAdj->hPreviewBitmap);\r
+\r
+                HeapFree(ProcessHeap,\r
+                         0,\r
+                         pImgAdj);\r
+            }\r
+        }\r
+    }\r
+\r
+    return FALSE;\r
+}\r
diff --git a/reactos/base/applications/imagesoft/imageprop.c b/reactos/base/applications/imagesoft/imageprop.c
deleted file mode 100644 (file)
index d3e0391..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <precomp.h>
-
-INT_PTR CALLBACK
-BrightnessProc(HWND hDlg,
-               UINT message,
-               WPARAM wParam,
-               LPARAM lParam)
-{
-    static PIMAGEADJUST pImgAdj = NULL;
-
-    switch (message)
-    {
-        case WM_INITDIALOG:
-        {
-            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;
-            HDC hdcMem;
-
-            lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
-
-            hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
-
-            if(lpDrawItem->CtlID == IDC_PICPREVIEW)
-            {
-                SelectObject(hdcMem,
-                             pImgAdj->hBitmap);
-
-                BitBlt(lpDrawItem->hDC,
-                       pImgAdj->ImageRect.left,
-                       pImgAdj->ImageRect.top,
-                       pImgAdj->ImageRect.right,
-                       pImgAdj->ImageRect.bottom,
-                       hdcMem,
-                       0,
-                       0,
-                       SRCCOPY);
-
-                DeleteDC(hdcMem);
-            }
-            return TRUE;
-        }
-
-        case WM_HSCROLL:
-        {
-            if (LOWORD(wParam) == TB_THUMBTRACK ||
-                LOWORD(wParam) == TB_ENDTRACK)
-            {
-                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,
-                              TrackPos,
-                              FALSE);
-
-                hdcMem = GetDC(pImgAdj->hPicPrev);
-
-                AdjustBrightness(pImgAdj,
-                                 hdcMem);
-
-                ReleaseDC(pImgAdj->hPicPrev, hdcMem);
-
-            }
-
-            return TRUE;
-        }
-
-        case WM_COMMAND:
-        {
-            if (LOWORD(wParam) == IDOK ||
-                LOWORD(wParam) == IDCANCEL)
-            {
-                EndDialog(hDlg,
-                          LOWORD(wParam));
-                return TRUE;
-            }
-        }
-        break;
-
-        case WM_DESTROY:
-        {
-            DeleteObject(pImgAdj->hBitmap);
-
-            HeapFree(ProcessHeap,
-                     0,
-                     pImgAdj);
-        }
-
-    }
-
-    return FALSE;
-}
index bee3695..5114ae9 100644 (file)
@@ -4,8 +4,8 @@ typedef struct _IMAGEADJUST
     PMAIN_WND_INFO Info;\r
     HWND hPicPrev;\r
     HBITMAP hBitmap;\r
+    HBITMAP hPreviewBitmap;\r
     RECT ImageRect;\r
-    DWORD OldTrackPos;\r
     INT RedVal;\r
     INT GreenVal;\r
     INT BlueVal;\r
@@ -16,10 +16,19 @@ INT_PTR CALLBACK ImagePropDialogProc(HWND hDlg,
                                      UINT message,\r
                                      WPARAM wParam,\r
                                      LPARAM lParam);\r
+\r
 INT_PTR CALLBACK BrightnessProc(HWND hDlg,\r
                                 UINT message,\r
                                 WPARAM wParam,\r
                                 LPARAM lParam);\r
 \r
-VOID AdjustBrightness(PIMAGEADJUST pImgAdj,\r
-                      HDC hdcMem);\r
+VOID AdjustBrightness(HBITMAP hOrigBitmap,\r
+                      HBITMAP hNewBitmap,\r
+                      HWND hwnd,\r
+                      HDC hdcMem,\r
+                      INT RedVal,\r
+                      INT GreenVal,\r
+                      INT BlueVal);\r
+\r
+BOOL DisplayBlackAndWhite(HWND hwnd, HDC hdcMem, HBITMAP hBitmap);\r
+BOOL DisplayInvertedColors(HWND hwnd, HDC hdcMem, HBITMAP hBitmap);\r
index af0c1d3..4c561ee 100644 (file)
                <compilationunit name="unit.c">
                        <file>about.c</file>
                        <file>adjust.c</file>
+                       <file>brightness.c</file>
                        <file>custcombo.c</file>
                        <file>floatwindow.c</file>
                        <file>font.c</file>
-                       <file>imageprop.c</file>
                        <file>imagesoft.c</file>
                        <file>imgedwnd.c</file>
                        <file>mainwnd.c</file>
index e25bacf..3a7feed 100644 (file)
@@ -1,4 +1,4 @@
-#include <precomp.h>
+#include "precomp.h"
 
 static const TCHAR szImageEditWndClass[] = TEXT("ImageSoftEditWndClass");
 
@@ -33,13 +33,15 @@ EditWndUpdateScrollInfo(PEDIT_WND_INFO Info)
 }
 
 
-static VOID
+static BOOL
 LoadBlankCanvas(PEDIT_WND_INFO Info)
 {
     /* FIXME: convert this to a DIB Section */
     /* set bitmap dimensions */
     Info->Width = Info->OpenInfo->New.Width;
     Info->Height = Info->OpenInfo->New.Height;
+
+    return TRUE;
 }
 
 static BOOL
@@ -125,6 +127,8 @@ LoadDIBImage(PEDIT_WND_INFO Info)
 static BOOL
 InitEditWnd(PEDIT_WND_INFO Info)
 {
+    //BOOL bRet = FALSE;
+
     Info->Zoom = 100;
 
     if (Info->OpenInfo != NULL)
index a49f137..3f29f7a 100644 (file)
@@ -50,6 +50,11 @@ BEGIN
     MENUITEM "Brightness...",       ID_BRIGHTNESS
     MENUITEM "Contrast...",         -1, GRAYED
     MENUITEM "Hue/Saturation...",   -1, GRAYED
+    POPUP "Colour"
+    BEGIN
+      MENUITEM "Black and White"    ID_BLACKANDWHITE
+      MENUITEM "Invert Colours"     ID_INVERTCOLORS
+    END
     MENUITEM SEPARATOR
     MENUITEM "Blur",                -1, GRAYED
     MENUITEM "Sharpen",             -1, GRAYED
index 8e1c0db..1d6744b 100644 (file)
@@ -906,6 +906,28 @@ MainWndCommand(PMAIN_WND_INFO Info,
                            (LPARAM)Info);
             break;
 
+        case ID_BLACKANDWHITE:
+        {
+            if (Info->ImageEditors)
+            {
+                DisplayBlackAndWhite(Info->ImageEditors->hSelf,
+                                     Info->ImageEditors->hDCMem,
+                                     Info->ImageEditors->hBitmap);
+            }
+        }
+        break;
+
+        case ID_INVERTCOLORS:
+        {
+            if (Info->ImageEditors)
+            {
+                DisplayInvertedColors(Info->ImageEditors->hSelf,
+                                      Info->ImageEditors->hDCMem,
+                                      Info->ImageEditors->hBitmap);
+            }
+        }        
+        break;
+
         case ID_EXIT:
             SendMessage(Info->hSelf,
                         WM_CLOSE,
index 2fc7436..6853130 100644 (file)
@@ -80,6 +80,8 @@
 
 /* Adjust */
 #define ID_BRIGHTNESS           2100
+#define ID_BLACKANDWHITE        2101
+#define ID_INVERTCOLORS         2102
 
 #define ID_ABOUT                2400