home *** CD-ROM | disk | FTP | other *** search
- /*
-
- GBMV2.C Display a bitmap
-
- */
-
- /*...sincludes:0:*/
- #define INCL_DOS
- #define INCL_WIN
- #define INCL_GPI
- #define INCL_DEV
- #define INCL_SPL
- #define INCL_SPLDOSPRINT
- #define INCL_BITMAPFILEFORMAT
- #include <os2.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- #include <malloc.h>
- #include <memory.h>
- #include <process.h>
- #include <math.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <io.h>
- #include <fcntl.h>
- #include "standard.h"
- #include "scroll.h"
- #include "gbm.h"
- #include "gbmtrunc.h"
- #include "gbmerr.h"
- #include "gbmht.h"
- #include "gbmhist.h"
- #include "gbmmir.h"
- #include "gbmrect.h"
- #include "gbmdlg.h"
- #include "gbmdlgrc.h"
- #include "gbmv2.h"
- #include "gbmv2hlp.h"
-
- /*...vscroll\46\h:0:*/
- /*...vgbm\46\h:0:*/
- /*...vgbmtrunc\46\h:0:*/
- /*...vgbmerr\46\h:0:*/
- /*...vgbmht\46\h:0:*/
- /*...vgbmhist\46\h:0:*/
- /*...vgbmmir\46\h:0:*/
- /*...vgbmrect\46\h:0:*/
- /*...vgbmdlg\46\h:0:*/
- /*...vgbmdlgrc\46\h:0:*/
- /*...vgbmv2\46\h:0:*/
- /*...vgbmv2hlp\46\h:0:*/
- /*...e*/
- /*...suseful:0:*/
- /* Windows has these 2 */
-
- /*...sEnableMenuItem:0:*/
- static VOID EnableMenuItem(HWND hWndMenu, SHORT idMenuItem, BOOL fEnabled)
- {
- WinSendMsg(hWndMenu, MM_SETITEMATTR,
- MPFROM2SHORT(idMenuItem, TRUE),
- MPFROM2SHORT(MIA_DISABLED, ( fEnabled ) ? 0 : MIA_DISABLED));
- }
- /*...e*/
- /*...sCheckMenuItem:0:*/
- static VOID CheckMenuItem(HWND hWndMenu, SHORT idMenuItem, BOOL fChecked)
- {
- WinSendMsg(hWndMenu, MM_SETITEMATTR,
- MPFROM2SHORT(idMenuItem, TRUE),
- MPFROM2SHORT(MIA_CHECKED, ( fChecked ) ? MIA_CHECKED : 0));
- }
- /*...e*/
-
- /* These are generally useful */
-
- /*...sWarning:0:*/
- static VOID Warning(HWND hwnd, const CHAR *szFmt, ...)
- {
- va_list vars;
- CHAR sz [256+1];
-
- va_start(vars, szFmt);
- vsprintf(sz, szFmt, vars);
- va_end(vars);
- WinMessageBox(HWND_DESKTOP, hwnd, sz, NULL, 0, MB_OK | MB_WARNING | MB_MOVEABLE);
- }
- /*...e*/
-
- /*...sTidySysMenu:0:*/
- static VOID TidySysMenu(HWND hwndFrame)
- {
- HWND hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
- USHORT id = SHORT1FROMMR(WinSendMsg(hwndSysMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(0), NULL));
- MENUITEM mi;
- HWND hwndSysSubMenu;
- SHORT sInx, cItems;
-
- WinSendMsg(hwndSysMenu, MM_QUERYITEM, MPFROM2SHORT(id, FALSE), MPFROMP(&mi));
- hwndSysSubMenu = mi.hwndSubMenu;
-
- cItems = SHORT1FROMMR(WinSendMsg(hwndSysSubMenu, MM_QUERYITEMCOUNT, NULL, NULL));
-
- for ( sInx = cItems - 1; sInx >= 0; sInx-- )
- {
- id = SHORT1FROMMR(WinSendMsg(hwndSysSubMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(sInx), NULL));
-
- WinSendMsg(hwndSysSubMenu, MM_QUERYITEM,
- MPFROM2SHORT(id, FALSE), MPFROMP(&mi));
- if ( (mi.afStyle & MIS_SEPARATOR) != 0 ||
- (mi.afAttribute & MIA_DISABLED ) != 0 ||
- id == (USHORT) SC_TASKMANAGER )
- WinSendMsg(hwndSysSubMenu, MM_DELETEITEM,
- MPFROM2SHORT(id, FALSE), NULL);
- }
- }
- /*...e*/
- /*...sRestrictEntryfield:0:*/
- /*
- This is a function you call on an WC_ENTRYFIELD window that causes the window
- to only allow strings in one set to be used and also not allow strings in
- another set.
- */
-
- typedef struct /* restr */
- {
- CHAR *szIfIn;
- CHAR *szMapTo;
- CHAR *szAllowed;
- CHAR *szNotAllowed;
- PFNWP pfnwpOld;
- } RESTR;
-
- /*...sRestrictSubProc:0:*/
- #define L_ENTRYMAX 500
-
- /*...sMapChar:0:*/
- static CHAR MapChar(RESTR *prestr, CHAR ch)
- {
- CHAR *sz;
-
- if ( prestr -> szIfIn == NULL || prestr -> szMapTo == NULL )
- return ( ch );
-
- if ( (sz = strchr(prestr -> szIfIn, ch)) == NULL )
- return ( ch );
-
- return ( prestr -> szMapTo [sz - prestr -> szIfIn] );
- }
- /*...e*/
- /*...sProblemAllowed:0:*/
- static BOOL ProblemAllowed(RESTR *prestr, CHAR ch)
- {
- return ( prestr -> szAllowed != NULL && strchr(prestr -> szAllowed, ch) == NULL );
- } /* More >>> */
- /*...e*/
- /*...sProblemNotAllowed:0:*/
- static BOOL ProblemNotAllowed(RESTR *prestr, CHAR ch)
- {
- return ( prestr -> szNotAllowed != NULL && strchr(prestr -> szNotAllowed, ch) != NULL );
- } /* More >>> */
- /*...e*/
-
- MRESULT _System RestrictSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- RESTR *prestr = (RESTR *) WinQueryWindowULong(hwnd, QWL_USER);
- PFNWP pfnwpOld = prestr -> pfnwpOld;
-
- switch ( (int) msg )
- {
- /*...sWM_DESTROY \45\ clean up:16:*/
- case WM_DESTROY:
- free(prestr);
- break;
- /*...e*/
- /*...sWM_CHAR \45\ map incoming chars:16:*/
- case WM_CHAR:
- {
- USHORT fs = SHORT1FROMMP(mp1);
- CHAR ch = (CHAR) SHORT1FROMMP(mp2);
- USHORT vkey = SHORT2FROMMP(mp2);
-
- if ( (fs & KC_VIRTUALKEY) != 0 && (fs & KC_ALT) != 0 &&
- (vkey == VK_LEFT || vkey == VK_RIGHT || vkey == VK_UP || vkey == VK_DOWN) )
- /* If we let the entryfield get these, it won't process them */
- /* It will pass them to its owner, the dialog. */
- /* The dialog will use them to change the focus! */
- /* This is not desired, as Alt+NNN is being used */
- return ( (MRESULT) 0 );
-
- if ( (fs & KC_CHAR) != 0 && ch != '\b' && ch != '\t' )
- {
- ch = MapChar(prestr, ch);
-
- if ( ProblemAllowed(prestr, ch) ||
- ProblemNotAllowed(prestr, ch) )
- {
- WinAlarm(HWND_DESKTOP, WA_WARNING);
- return ( (MRESULT) 0 );
- }
-
- mp2 = MPFROM2SHORT(ch, vkey);
- }
- }
- break;
- /*...e*/
- /*...sEM_PASTE \45\ paste then alter chars:16:*/
- case EM_PASTE:
- {
- MRESULT mr = (*pfnwpOld)(hwnd, msg, mp1, mp2);
- MRESULT mrSel = WinSendMsg(hwnd, EM_QUERYSEL, NULL, NULL);
- CHAR sz [L_ENTRYMAX+1], *szTmp;
-
- WinQueryWindowText(hwnd, L_ENTRYMAX, sz);
- for ( szTmp = sz; *szTmp; szTmp++ )
- {
- *szTmp = MapChar(prestr, *szTmp);
- if ( ProblemAllowed(prestr, *szTmp) ||
- ProblemNotAllowed(prestr, *szTmp) )
- {
- strcpy(szTmp, szTmp + 1);
- szTmp--;
- }
- }
- WinSetWindowText(hwnd, sz);
- WinSendMsg(hwnd, EM_SETSEL, mrSel, NULL);
-
- return ( mr );
- }
- /*...e*/
- }
- return ( (*pfnwpOld)(hwnd, msg, mp1, mp2) );
- }
- /*...e*/
-
- static BOOL RestrictEntryfield(
- HWND hwnd,
- CHAR *szIfIn,
- CHAR *szMapTo,
- CHAR *szAllowed,
- CHAR *szNotAllowed
- )
- {
- RESTR *prestr;
-
- if ( (prestr = malloc(sizeof(RESTR))) == NULL )
- return ( FALSE );
-
- prestr -> szIfIn = szIfIn ;
- prestr -> szMapTo = szMapTo ;
- prestr -> szAllowed = szAllowed ;
- prestr -> szNotAllowed = szNotAllowed;
- prestr -> pfnwpOld = WinSubclassWindow(hwnd, RestrictSubProc);
-
- WinSetWindowULong(hwnd, QWL_USER, (LONG) prestr);
-
- return ( TRUE );
- }
- /*...e*/
- /*...e*/
- /*...spriority:0:*/
- static VOID LowPri(VOID)
- {
- #ifdef NEVER
- DosSetPrty(PRTYS_THREAD, PRTYC_IDLETIME, 0, 0);
- #endif
- DosSetPrty(PRTYS_THREAD, PRTYC_REGULAR, PRTYD_MINIMUM, 0);
- }
-
- static VOID RegPri(VOID)
- {
- DosSetPrty(PRTYS_THREAD, PRTYC_REGULAR, 0, 0);
- }
- /*...e*/
- /*...sbmputils:0:*/
- /*
-
- All bitmaps referred to below should not be selected into a hps at time of
- call. They will be selected into screen or printer compatible hps's during the
- call and be unselected afterwards. Because of this, you will find that the
- colours change in the bitmap when using the BmpPrint call. The solution is
- to copy the desired bitmap, call BmpPrint on it, then to discard it.
-
- */
-
- typedef USHORT BMP_ERR;
- #define BMP_ERR_OK 0 /* All went ok */
- #define BMP_ERR_MEM 1 /* Out of memory */
- #define BMP_ERR_RES 2 /* Out of PM resources (DC, PS etc.) */
- #define BMP_ERR_QUERY 3 /* Can't query queue info */
- #define BMP_ERR_PRINTER 4 /* Can't find the printer */
- #define BMP_ERR_PRINT 5 /* Error in the printing itself */
-
- /*...sBmpBlitter \45\ blit one part of one bitmap to part of another:0:*/
- BMP_ERR BmpBlitter(
- HAB hab,
- HBITMAP hbmSrc, RECTL rclSrc,
- HBITMAP hbmDst, RECTL rclDst
- )
- {
- HDC hdcSrc, hdcDst;
- HPS hpsSrc, hpsDst;
- BITMAPINFOHEADER2 bmp;
- SIZEL sizl;
- POINTL aptl [4];
-
- if ( (hdcSrc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, (HDC) NULL)) == (HDC) NULL )
- return ( BMP_ERR_RES );
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbmSrc, &bmp);
- sizl.cx = bmp.cx; sizl.cy = bmp.cy;
- if ( (hpsSrc = GpiCreatePS(hab, hdcSrc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == (HPS) NULL )
- {
- DevCloseDC(hdcSrc);
- return ( BMP_ERR_RES );
- }
-
- if ( (hdcDst = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, (HDC) NULL)) == (HDC) NULL )
- {
- GpiDestroyPS(hpsSrc); DevCloseDC(hdcSrc);
- return ( BMP_ERR_RES );
- }
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbmDst, &bmp);
- sizl.cx = bmp.cx; sizl.cy = bmp.cy;
- if ( (hpsDst = GpiCreatePS(hab, hdcDst, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == (HPS) NULL )
- {
- DevCloseDC(hdcDst);
- GpiDestroyPS(hpsSrc); DevCloseDC(hdcSrc);
- return ( BMP_ERR_RES );
- }
-
- GpiSetBitmap(hpsSrc, hbmSrc);
- GpiSetBitmap(hpsDst, hbmDst);
-
- aptl [0].x = rclDst.xLeft;
- aptl [0].y = rclDst.yBottom;
- aptl [1].x = rclDst.xRight;
- aptl [1].y = rclDst.yTop;
- aptl [2].x = rclSrc.xLeft;
- aptl [2].y = rclSrc.yBottom;
- aptl [3].x = rclSrc.xRight;
- aptl [3].y = rclSrc.yTop;
-
- if ( aptl [1].x - aptl [0].x == aptl [3].x - aptl [2].x &&
- aptl [1].y - aptl [0].y == aptl [3].y - aptl [2].y )
- GpiBitBlt(hpsDst, hpsSrc, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE);
- else
- GpiBitBlt(hpsDst, hpsSrc, 4L, aptl, ROP_SRCCOPY, BBO_IGNORE);
-
- GpiSetBitmap(hpsDst, (HBITMAP) NULL); GpiDestroyPS(hpsDst); DevCloseDC(hdcDst);
- GpiSetBitmap(hpsSrc, (HBITMAP) NULL); GpiDestroyPS(hpsSrc); DevCloseDC(hdcSrc);
-
- return ( BMP_ERR_OK );
- }
- /*...e*/
- /*...sBmpCopySubrectangle \45\ make a new bitmap from a bit of the first:0:*/
- BMP_ERR BmpCopySubrectangle(HAB hab, HBITMAP hbmSrc, RECTL rclSrc, HBITMAP *phbmDst)
- {
- BITMAPINFOHEADER2 bmp;
- HBITMAP hbmDst;
- RECTL rclDst;
- SIZEL sizl;
- USHORT rc;
- HDC hdc;
- HPS hps;
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbmSrc, &bmp);
-
- bmp.cx = (USHORT) (rclSrc.xRight - rclSrc.xLeft);
- bmp.cy = (USHORT) (rclSrc.yTop - rclSrc.yBottom);
-
- if ( (hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, (HDC) NULL)) == (HDC) NULL )
- return ( BMP_ERR_RES );
-
- sizl.cx = bmp.cx; sizl.cy = bmp.cy;
- if ( (hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == (HPS) NULL )
- {
- DevCloseDC(hdc);
- return ( BMP_ERR_RES );
- }
-
- if ( (hbmDst = GpiCreateBitmap(hps, &bmp, 0L, NULL, NULL)) == (HBITMAP) NULL )
- {
- GpiDestroyPS(hps);
- DevCloseDC(hdc);
- return ( BMP_ERR_MEM );
- }
-
- GpiDestroyPS(hps);
- DevCloseDC(hdc);
-
- rclDst.xLeft = 0; rclDst.xRight = bmp.cx;
- rclDst.yBottom = 0; rclDst.yTop = bmp.cy;
-
- if ( (rc = BmpBlitter(hab, hbmSrc, rclSrc, hbmDst, rclDst)) != BMP_ERR_OK )
- {
- GpiDeleteBitmap(hbmDst);
- return ( rc );
- }
-
- *phbmDst = hbmDst;
-
- return ( BMP_ERR_OK );
- }
- /*...e*/
- /*...sBmpCopy \45\ make a new bitmap from all of the first:0:*/
- BMP_ERR BmpCopy(HAB hab, HBITMAP hbmSrc, HBITMAP *phbmDst)
- {
- BITMAPINFOHEADER2 bmp;
- RECTL rclSrc;
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbmSrc, &bmp);
-
- rclSrc.xLeft = 0; rclSrc.xRight = bmp.cx;
- rclSrc.yBottom = 0; rclSrc.yTop = bmp.cy;
-
- return ( BmpCopySubrectangle(hab, hbmSrc, rclSrc, phbmDst) );
- }
- /*...e*/
- /*...sBmpPrint \45\ print a bitmap:0:*/
- /*...sEnquireQueueDetails:0:*/
- static BOOL EnquireQueueDetails(
- CHAR *szQueue,
- CHAR *szLogAddress,
- CHAR *szDriverName,
- CHAR *szNameWPS,
- DRIVDATA **ppdriv
- )
- {
- ULONG cb; PRQINFO3 *ppq3;
-
- SplQueryQueue(NULL, szQueue, 3, NULL, 0, &cb);
- if ( cb < sizeof(PRQINFO3) )
- return ( FALSE );
- if ( (ppq3 = (PRQINFO3 *) malloc(cb)) == (PRQINFO3 *) NULL )
- return ( FALSE );
- SplQueryQueue(NULL, szQueue, 3, ppq3, cb, &cb);
- strcpy(szNameWPS, ppq3 -> pszComment);
- strcpy(szLogAddress, szQueue);
- sscanf(ppq3 -> pszDriverName, "%[^.,;]", szDriverName);
- *ppdriv = ppq3 -> pDriverData;
- free(ppq3);
- return ( TRUE );
- }
- /*...e*/
- /*...sPrinterInfo:0:*/
- static BOOL PrinterInfo(HPS hpsPrinter, CHAR *szNameWPS)
- {
- HDC hdcPrinter = GpiQueryDevice(hpsPrinter);
- LONG lBitCount, lPlanes, lColors, lPhysColors;
- SIZEL sizlPrinter;
- CHAR sz [100+1];
-
- GpiQueryPS(hpsPrinter, &sizlPrinter);
-
- DevQueryCaps(hdcPrinter, CAPS_COLOR_BITCOUNT, 1L, &lBitCount );
- DevQueryCaps(hdcPrinter, CAPS_COLOR_PLANES , 1L, &lPlanes );
- DevQueryCaps(hdcPrinter, CAPS_COLORS , 1L, &lColors );
- DevQueryCaps(hdcPrinter, CAPS_PHYS_COLORS , 1L, &lPhysColors);
-
- sprintf(sz, "%s: %ldx%ld, %ld bits, %ld planes, %ld colors, %ld physical colors?",
- szNameWPS, sizlPrinter.cx, sizlPrinter.cy, lBitCount, lPlanes, lColors, lPhysColors);
-
- return ( WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, sz, "GbmV2 - Confirm Printer", 0, MB_OKCANCEL | MB_QUERY | MB_MOVEABLE) == MBID_OK );
- }
- /*...e*/
- /*...sTransferBitmapData:0:*/
- /*
- Put the largest possible copy of the bitmap onto the printer presentation
- space. Preserve aspect ratio and correct for printer aspect ratio.
- */
-
- /*...sMonoPrint:0:*/
- static BOOL MonoPrint(HPS hpsPrinter)
- {
- HDC hdcPrinter = GpiQueryDevice(hpsPrinter);
- LONG lBitCount, lPlanes;
-
- DevQueryCaps(hdcPrinter, CAPS_COLOR_BITCOUNT, 1L, &lBitCount);
- DevQueryCaps(hdcPrinter, CAPS_COLOR_PLANES , 1L, &lPlanes );
-
- return ( lBitCount == 1 && lPlanes == 1 );
- }
- /*...e*/
-
- static BMP_ERR TransferBitmapData(HAB hab, HBITMAP hbm, HDC hdcPrinter, HPS hpsPrinter)
- {
- SIZEL sizlMemory, sizlPrinter, sizlImage;
- SIZEL sizlMmPrinter, sizlMmImage; /* Sizes in mm */
- HDC hdcMemory;
- HPS hpsMemory;
- POINTL aptl [4];
- BITMAPINFOHEADER2 bmp;
- LONG xRes, yRes, xCentre, yCentre;
-
- /* Query printer size */
-
- GpiQueryPS(hpsPrinter, &sizlPrinter);
-
- /* Query bitmap size */
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbm, &bmp);
- sizlMemory.cx = (LONG) bmp.cx;
- sizlMemory.cy = (LONG) bmp.cy;
-
- /* Make a memory device context for the bitmap */
-
- if ( (hdcMemory = DevOpenDC(hab, OD_MEMORY, "*", 0L, NULL, hdcPrinter)) == (HPS) NULL )
- return ( BMP_ERR_RES );
-
- if ( (hpsMemory = GpiCreatePS(hab, hdcMemory, &sizlMemory, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == (HPS) NULL )
- {
- DevCloseDC(hdcMemory);
- return ( BMP_ERR_RES );
- }
-
- GpiSetBitmap(hpsMemory, hbm);
-
- /* Set colours ready for blitting into printer ps */
-
- GpiSetColor(hpsMemory, CLR_WHITE);
- GpiSetBackColor(hpsMemory, CLR_BLACK);
- GpiSetColor(hpsPrinter, CLR_WHITE);
- GpiSetBackColor(hpsPrinter, CLR_BLACK);
-
- /*...sscale to fit page:8:*/
- /* Query printer aspect ratio */
-
- DevQueryCaps(hdcPrinter, CAPS_HORIZONTAL_RESOLUTION, 1L, &xRes);
- DevQueryCaps(hdcPrinter, CAPS_VERTICAL_RESOLUTION , 1L, &yRes);
-
- /* Get size of page in mm */
-
- sizlMmPrinter.cx = (1000L * sizlPrinter.cx) / xRes;
- sizlMmPrinter.cy = (1000L * sizlPrinter.cy) / yRes;
-
- /* Get largest image size in mm */
-
- if ( sizlMemory.cx * sizlMmPrinter.cy > sizlMemory.cy * sizlMmPrinter.cx )
- /* Stretch to fill width */
- {
- sizlMmImage.cx = sizlMmPrinter.cx;
- sizlMmImage.cy = (sizlMmImage.cx * sizlMemory.cy) / sizlMemory.cx;
- }
- else
- /* Stretch to fill height */
- {
- sizlMmImage.cy = sizlMmPrinter.cy;
- sizlMmImage.cx = (sizlMmImage.cy * sizlMemory.cx) / sizlMemory.cy;
- }
-
- sizlImage.cx = (xRes * sizlMmImage.cx) / 1000L;
- sizlImage.cy = (yRes * sizlMmImage.cy) / 1000L;
-
- xCentre = ((sizlPrinter.cx - sizlImage.cx) >> 1);
- yCentre = ((sizlPrinter.cy - sizlImage.cy) >> 1);
-
- aptl [0].x = xCentre;
- aptl [0].y = yCentre;
- aptl [1].x = xCentre + sizlImage.cx;
- aptl [1].y = yCentre + sizlImage.cy;
- aptl [2].x = 0;
- aptl [2].y = 0;
- aptl [3].x = sizlMemory.cx;
- aptl [3].y = sizlMemory.cy;
-
- GpiBitBlt(hpsPrinter, hpsMemory, 4L, aptl, ROP_SRCCOPY,
- MonoPrint(hpsPrinter) ? BBO_AND : BBO_IGNORE);
- /*...e*/
- #ifdef NEVER
- /*...sposition in the middle if room:8:*/
- if ( sizlMemory.cx < sizlPrinter.cx &&
- sizlMemory.cy < sizlPrinter.cy )
- {
- xCentre = ((sizlPrinter.cx - sizlMemory.cx) >> 1);
- yCentre = ((sizlPrinter.cy - sizlMemory.cy) >> 1);
-
- aptl [0].x = xCentre;
- aptl [0].y = yCentre;
- aptl [1].x = xCentre + sizlMemory.cx;
- aptl [1].y = yCentre + sizlMemory.cy;
- aptl [2].x = 0;
- aptl [2].y = 0;
-
- GpiBitBlt(hpsPrinter, hpsMemory, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE);
- }
- /*...e*/
- #endif
-
- GpiSetBitmap(hpsMemory, (HBITMAP) NULL);
- GpiDestroyPS(hpsMemory);
- DevCloseDC(hdcMemory);
-
- return ( BMP_ERR_OK );
- }
- /*...e*/
-
- BMP_ERR BmpPrint(
- HAB hab,
- HBITMAP hbm,
- CHAR *szDocName,
- CHAR *szComment,
- CHAR *szQueueToUse
- )
- {
- static SIZEL sizl = { 0, 0 };
- HDC hdcPrinter;
- HPS hpsPrinter;
- CHAR szLogAddress [256];
- CHAR szDriverName [256];
- CHAR szNameWPS [256];
- DEVOPENSTRUC dop;
- USHORT cb, usJobId;
- CHAR szQueue [256];
- BMP_ERR rc;
- LONG lOutCount;
- BOOL fQueried = FALSE;
-
- /* Set defaults, in case can't query information about printer */
-
- dop.pszLogAddress = szLogAddress;
- dop.pszDriverName = szDriverName;
- dop.pdriv = NULL;
- dop.pszDataType = "PM_Q_STD";
- dop.pszComment = szComment;
- dop.pszQueueProcName = NULL;
- dop.pszQueueProcParams = NULL;
- dop.pszSpoolerParams = NULL;
- dop.pszNetworkParams = NULL;
-
- if ( szQueueToUse != NULL )
- /* Use the queue we have been told to use */
- fQueried = EnquireQueueDetails(szQueueToUse, szLogAddress, szDriverName, szNameWPS, &dop.pdriv);
- else if ( (cb = (USHORT) PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER",
- "QUEUE", NULL, szQueue, (LONG) sizeof(szQueue))) > 0 )
- /* Use application default queue */
- {
- szQueue [cb - 2] = '\0'; /* Remove semicolon at end */
- fQueried = EnquireQueueDetails(szQueue, szLogAddress, szDriverName, szNameWPS, &dop.pdriv);
- }
-
- if ( !fQueried )
- return ( BMP_ERR_QUERY );
-
- /* Try to create printer device context */
-
- if ( (hdcPrinter = DevOpenDC(hab, OD_QUEUED, "*", 5L, (PDEVOPENDATA) &dop, (HDC) NULL)) == (HDC) NULL )
- /* Failed to open printer device context */
- return ( BMP_ERR_PRINTER );
-
- /* Create a presentation space of default size (size of page) */
-
- if ( (hpsPrinter = GpiCreatePS(hab, hdcPrinter, &sizl, PU_PELS | GPIF_DEFAULT | GPIA_ASSOC)) == (HPS) NULL )
- /* Could not make presentation space */
- {
- DevCloseDC(hdcPrinter);
- return ( BMP_ERR_PRINTER );
- }
-
- /* Tell user about printer, and give chance to abort job */
-
- if ( !PrinterInfo(hpsPrinter, szNameWPS) )
- {
- GpiAssociate(hpsPrinter, (HDC) NULL);
- GpiDestroyPS(hpsPrinter);
- DevCloseDC(hdcPrinter);
- return ( BMP_ERR_OK );
- }
-
- /* Indicate a new print job is starting */
-
- if ( !DevEscape(hdcPrinter, DEVESC_STARTDOC, (LONG) strlen(szDocName),
- (BYTE *) szDocName, &lOutCount, (BYTE *) NULL) )
- {
- GpiAssociate(hpsPrinter, (HDC) NULL);
- GpiDestroyPS(hpsPrinter);
- DevCloseDC(hdcPrinter);
- return ( BMP_ERR_PRINT );
- }
-
- GpiErase(hpsPrinter); /* Blank the page to CLR_BACKGROUND */
-
- if ( (rc = TransferBitmapData(hab, hbm, hdcPrinter, hpsPrinter)) != BMP_ERR_OK )
- {
- DevEscape(hdcPrinter, DEVESC_ABORTDOC, 0L, NULL, 0L, NULL);
- GpiAssociate(hpsPrinter, (HDC) NULL);
- GpiDestroyPS(hpsPrinter);
- DevCloseDC(hdcPrinter);
- return ( rc );
- }
-
- /* Indicate the job is done */
-
- if ( !DevEscape(hdcPrinter, DEVESC_ENDDOC, 0L, (BYTE *) NULL, &lOutCount, (BYTE *) &usJobId) )
- {
- GpiAssociate(hpsPrinter, (HDC) NULL);
- GpiDestroyPS(hpsPrinter);
- DevCloseDC(hdcPrinter);
- return ( BMP_ERR_PRINT );
- }
-
- GpiAssociate(hpsPrinter, (HDC) NULL);
- GpiDestroyPS(hpsPrinter);
- DevCloseDC(hdcPrinter);
-
- return ( BMP_ERR_OK );
- }
- /*...e*/
- /*...sBmpErrorMessage \45\ get error message from error return code:0:*/
- CHAR *BmpErrorMessage(BMP_ERR rc, CHAR *sz)
- {
- static CHAR *aszBitmapErrors [] =
- {
- "",
- "out of memory",
- "out of resources",
- "can't query printer/queue details",
- "can't locate printer/queue",
- "error sending data to printer/queue",
- };
-
- return ( strcpy(sz, aszBitmapErrors [rc]) );
- }
- /*...e*/
- /*...e*/
- /*...shelp:0:*/
- static HELPINIT hinit;
-
- /*...sHlpWarning:0:*/
- static VOID HlpWarning(HWND hwnd, CHAR *szFmt, ...)
- {
- va_list vars;
- CHAR sz [256+1];
-
- va_start(vars, szFmt);
- vsprintf(sz, szFmt, vars);
- va_end(vars);
- WinMessageBox(HWND_DESKTOP, hwnd, sz, "Help system", 0, MB_OK | MB_WARNING | MB_MOVEABLE);
- }
- /*...e*/
- /*...sHlpInit:0:*/
- static HWND HlpInit(
- HWND hwnd,
- HMODULE hmod, USHORT idHelpTable,
- CHAR *szHelpFile,
- CHAR *szTitle
- )
- {
- HAB hab = WinQueryAnchorBlock(hwnd);
- HWND hwndHelp;
- CHAR sz [256+1];
-
- hinit.cb = sizeof(HELPINIT);
- hinit.ulReturnCode = 0L;
-
- /* HELPTABLE resource handle */
- hinit.hmodHelpTableModule = hmod;
- hinit.phtHelpTable = (HELPTABLE *) (0xffff0000L | idHelpTable);
-
- /* Help window title bar */
- strcpy(sz, szTitle);
- strcat(sz, " Help");
- hinit.pszHelpWindowTitle = sz;
-
- /* Not showing panel IDs */
- hinit.fShowPanelId = CMIC_HIDE_PANEL_ID;
-
- /* No tutorial program */
- hinit.pszTutorialName = NULL;
-
- /* Action bar is not tailored */
- hinit.hmodAccelActionBarModule = (HMODULE) NULL;
- hinit.idAccelTable = (USHORT) NULL;
- hinit.idActionBar = (USHORT) NULL;
-
- /* No default librarys */
- hinit.pszHelpLibraryName = "";
-
- if ( (hwndHelp = WinCreateHelpInstance(hab, &hinit)) == (HWND) NULL )
- {
- HlpWarning(hwnd, "Unable to create help instance");
- return ( (HWND) NULL );
- }
-
- if ( WinSendMsg(hwndHelp, HM_SET_HELP_LIBRARY_NAME, MPFROMP(szHelpFile), NULL) )
- {
- WinDestroyHelpInstance(hwndHelp);
- HlpWarning(hwnd, "Unable to find help libraries");
- return ( (HWND) NULL );
- }
-
- return ( hwndHelp );
- }
- /*...e*/
- /*...sHlpDeinit:0:*/
- static VOID HlpDeinit(HWND hwndHelp)
- {
- WinDestroyHelpInstance(hwndHelp);
- }
- /*...e*/
- /*...sHlpActivate:0:*/
- static VOID HlpActivate(HWND hwndHelp, HWND hwndFrame)
- {
- if ( !WinAssociateHelpInstance(hwndHelp, hwndFrame))
- HlpWarning(hwndFrame, "Unable to associate help instance");
- }
- /*...e*/
- /*...sHlpWndProc:0:*/
- MRESULT _System HlpWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- CHAR sz [256+1];
-
- switch ( (int) msg )
- {
- /*...sHM_ERROR:16:*/
- case HM_ERROR:
- switch( SHORT1FROMMP(mp1) )
- {
- case HMERR_HELPITEM_NOT_FOUND:
- sprintf(sz, "Item 0x%08lx not found", LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- case HMERR_HELPSUBITEM_NOT_FOUND:
- sprintf(sz, "Sub-Item 0x%08lx not found", LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- case HMERR_INDEX_NOT_FOUND:
- HlpWarning(hwnd, "No index in library file" );
- break;
- case HMERR_CONTENT_NOT_FOUND:
- HlpWarning(hwnd, "Library file does not have any contents");
- break;
- case HMERR_OPEN_LIB_FILE:
- HlpWarning(hwnd, "Cannot open library file");
- break;
- case HMERR_READ_LIB_FILE:
- HlpWarning(hwnd, "Cannot read library file");
- break;
- case HMERR_CLOSE_LIB_FILE:
- HlpWarning(hwnd, "Cannot close library file");
- break;
- case HMERR_INVALID_LIB_FILE:
- HlpWarning(hwnd, "Improper library file provided");
- break;
- case HMERR_NO_MEMORY:
- HlpWarning(hwnd, "Unable to allocate the requested amount of memory");
- break;
- case HMERR_ALLOCATE_SEGMENT:
- HlpWarning(hwnd, "Unable to allocate memory for IPF");
- break;
- case HMERR_FREE_MEMORY:
- HlpWarning(hwnd, "Unable to free allocated memory");
- break;
- case HMERR_PANEL_NOT_FOUND:
- HlpWarning(hwnd, "Unable to find help panel requested");
- break;
- case HMERR_DATABASE_NOT_OPEN:
- HlpWarning(hwnd, "Unable to read the unopened database");
- break;
- default:
- sprintf(sz, "Error mp1=0x%08lx mp2=0x%08lx",LONGFROMMP(mp1), LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- }
- break;
- /*...e*/
- /*...sHM_INFORM:16:*/
- case HM_INFORM:
- sprintf(sz, "Inform 0x%08lx 0x%08lx",
- LONGFROMMP(mp1), LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- /*...e*/
- /*...sHM_QUERY_KEYS_HELP:16:*/
- case HM_QUERY_KEYS_HELP:
- return ( (MRESULT) HID_HELPKEYS );
- /*...e*/
- /*...sHM_EXT_HELP_UNDEFINED:16:*/
- case HM_EXT_HELP_UNDEFINED:
- sprintf(sz, "Extended help undefined mp1=0x%08lx mp2=0x%l08x",
- LONGFROMMP(mp1), LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- /*...e*/
- /*...sHM_HELPSUBITEM_NOT_FOUND:16:*/
- case HM_HELPSUBITEM_NOT_FOUND:
- sprintf(sz, "Sub-Item 0x%08lx 0x%08lx not found",
- LONGFROMMP(mp1), LONGFROMMP(mp2));
- HlpWarning(hwnd, sz);
- break;
- /*...e*/
- }
- return ( WinDefWindowProc(hwnd, msg, mp1, mp2) );
- }
- /*...e*/
- /*...sHlpHelpForHelp:0:*/
- static VOID HlpHelpForHelp(HWND hwndHelp)
- {
- WinPostMsg(hwndHelp, HM_DISPLAY_HELP, NULL, NULL);
- }
- /*...e*/
-
- static HWND hwndHelp;
- /*...e*/
- /*...svars:0:*/
- #define MAX_FILE_NAME 256
-
- static CHAR szAppName [] = "GbmV2";
- static CHAR szFileName [MAX_FILE_NAME+1] = "";
-
- static BOOL fGotBitmap = FALSE;
- static BOOL fUnsavedChanges = FALSE;
- static GBM gbm;
- static GBMRGB gbmrgb [0x100];
- static BYTE *pbData;
-
- #define VIEW_NULL 0
- #define VIEW_HALFTONE 1
- #define VIEW_ERRDIFF 2
- static BYTE bView = VIEW_NULL;
- static LONG lBitCountScreen;
-
- static BOOL fBusy = FALSE;
- static HWND hwndObject;
- static HWND hwndBitmap;
- static HWND hwndScroller;
- static BOOL fSelectionDefined = FALSE;
- static RECTL rclSelection;
- /*...e*/
- /*...sundo:0:*/
- static BOOLEAN fCanUndo = FALSE;
- static GBM gbmUndo;
- static GBMRGB gbmrgbUndo [0x100];
- static BYTE *pbDataUndo;
- static CHAR *szWhatUndo;
-
- /*...sDiscardUndo:0:*/
- static VOID DiscardUndo(VOID)
- {
- if ( fCanUndo )
- {
- if ( pbDataUndo != NULL )
- free(pbDataUndo);
- fCanUndo = FALSE;
- }
- }
- /*...e*/
- /*...sKeepForUndo:0:*/
- static VOID KeepForUndo(GBM *gbm, GBMRGB *gbmrgb, BYTE *pbData, CHAR *szWhat)
- {
- int stride = ((gbm -> w * gbm -> bpp + 31) / 32) * 4;
- DiscardUndo();
- szWhatUndo = szWhat;
- gbmUndo = *gbm;
- memcpy(gbmrgbUndo, gbmrgb, 0x100 * sizeof(GBMRGB));
- if ( pbData != NULL )
- {
- if ( (pbDataUndo = malloc(stride * gbm -> h)) == NULL )
- return; /* Can't keep data for undo purposes */
- memcpy(pbDataUndo, pbData, stride * gbm -> h);
- }
- else
- pbDataUndo = NULL;
- fCanUndo = TRUE;
- }
- /*...e*/
- /*...sUseUndoBuffer:0:*/
- static VOID UseUndoBuffer(GBM *gbm, GBMRGB *gbmrgb, BYTE **ppbData, CHAR **pszWhat)
- {
- *gbm = gbmUndo;
- memcpy(gbmrgb, gbmrgbUndo, 0x100 * sizeof(GBMRGB));
- *ppbData = pbDataUndo;
- *pszWhat = szWhatUndo;
- fCanUndo = FALSE;
- }
- /*...e*/
- /*...e*/
- /*...sLoadBitmap:0:*/
- static BOOL LoadBitmap(
- HWND hwnd,
- CHAR *szFn, CHAR *szOpt,
- GBM *gbm, GBMRGB *gbmrgb, BYTE **ppbData
- )
- {
- GBM_ERR rc;
- int fd, ft;
- ULONG cb, cbLine;
-
- if ( gbm_guess_filetype(szFn, &ft) != GBM_ERR_OK )
- {
- Warning(hwnd, "Can't deduce bitmap format from file extension: %s", szFn);
- return ( FALSE );
- }
-
- if ( (fd = open(szFn, O_RDONLY|O_BINARY)) == -1 )
- {
- Warning(hwnd, "Can't open file: %s", szFn);
- return ( FALSE );
- }
-
- if ( (rc = gbm_read_header(szFn, fd, ft, gbm, szOpt)) != GBM_ERR_OK )
- {
- close(fd);
- Warning(hwnd, "Can't read file header of %s: %s", szFn, gbm_err(rc));
- return ( FALSE );
- }
-
- if ( (rc = gbm_read_palette(fd, ft, gbm, gbmrgb)) != GBM_ERR_OK )
- {
- close(fd);
- Warning(hwnd, "Can't read file palette of %s: %s", szFn, gbm_err(rc));
- return ( FALSE );
- }
-
- cbLine = ((gbm -> w * gbm -> bpp + 31)/32) * 4;
- cb = gbm -> h * cbLine;
- if ( (*ppbData = malloc((int) cb)) == NULL )
- {
- close(fd);
- Warning(hwnd, "Out of memory requesting %ld bytes", cb);
- return ( FALSE );
- }
-
- if ( (rc = gbm_read_data(fd, ft, gbm, *ppbData)) != GBM_ERR_OK )
- {
- free(*ppbData);
- close(fd);
- Warning(hwnd, "Can't read file data of %s: %s", szFn, gbm_err(rc));
- return ( FALSE );
- }
-
- close(fd);
-
- return ( TRUE );
- }
- /*...e*/
- /*...sCopyTo24:0:*/
- static VOID CopyTo24(GBM *gbm, GBMRGB *gbmrgb, BYTE *pbDataSrc, BYTE *pbDataDest)
- {
- int cbLineSrc = ((gbm -> w * gbm -> bpp + 31)/32) * 4;
- int cbLineDest = ((gbm -> w * 3 + 3) & ~3);
- int y;
-
- for ( y = 0; y < gbm -> h; y++ )
- {
- BYTE *pbSrc = pbDataSrc + y * cbLineSrc ;
- BYTE *pbDest = pbDataDest + y * cbLineDest;
- int x;
-
- switch ( gbm -> bpp )
- {
- /*...s1:24:*/
- case 1:
- {
- BYTE c;
-
- for ( x = 0; x < gbm -> w; x++ )
- {
- if ( (x & 7) == 0 )
- c = *pbSrc++;
- else
- c <<= 1;
-
- *pbDest++ = gbmrgb [c >> 7].b;
- *pbDest++ = gbmrgb [c >> 7].g;
- *pbDest++ = gbmrgb [c >> 7].r;
- }
- }
- break;
- /*...e*/
- /*...s4:24:*/
- case 4:
- for ( x = 0; x + 1 < gbm -> w; x += 2 )
- {
- BYTE c = *pbSrc++;
-
- *pbDest++ = gbmrgb [c >> 4].b;
- *pbDest++ = gbmrgb [c >> 4].g;
- *pbDest++ = gbmrgb [c >> 4].r;
- *pbDest++ = gbmrgb [c & 15].b;
- *pbDest++ = gbmrgb [c & 15].g;
- *pbDest++ = gbmrgb [c & 15].r;
- }
-
- if ( x < gbm -> w )
- {
- BYTE c = *pbSrc;
-
- *pbDest++ = gbmrgb [c >> 4].b;
- *pbDest++ = gbmrgb [c >> 4].g;
- *pbDest++ = gbmrgb [c >> 4].r;
- }
- break;
- /*...e*/
- /*...s8:24:*/
- case 8:
- for ( x = 0; x < gbm -> w; x++ )
- {
- BYTE c = *pbSrc++;
-
- *pbDest++ = gbmrgb [c].b;
- *pbDest++ = gbmrgb [c].g;
- *pbDest++ = gbmrgb [c].r;
- }
- break;
- /*...e*/
- /*...s24:24:*/
- case 24:
- memcpy(pbDataDest, pbDataSrc, cbLineSrc * gbm -> h);
- break;
- /*...e*/
- }
- }
- }
- /*...e*/
- /*...sTo24Bit:0:*/
- static BOOL To24Bit(GBM *gbm, GBMRGB *gbmrgb, BYTE *pbData, BYTE **ppbDataNew)
- {
- int cbLineDest = ((gbm -> w * 3 + 3) & ~3);
- if ( (*ppbDataNew = malloc(cbLineDest * gbm -> h)) == NULL )
- return ( FALSE );
-
- CopyTo24(gbm, gbmrgb, pbData, *ppbDataNew);
-
- return ( TRUE );
- }
- /*...e*/
- /*...sMakeBitmap:0:*/
- static BOOL MakeBitmap(
- HWND hwnd,
- GBM *gbm, GBMRGB *gbmrgb, BYTE *pbData,
- HBITMAP *phbm
- )
- {
- HAB hab = WinQueryAnchorBlock(hwnd);
- USHORT cRGB, usCol;
- SIZEL sizl;
- HDC hdc;
- HPS hps;
- struct
- {
- BITMAPINFOHEADER2 bmp2;
- RGB2 argb2Color [0x100];
- } bm;
-
- /* Got the data in memory, now make bitmap */
-
- memset(&bm, 0, sizeof(bm));
-
- bm.bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
- bm.bmp2.cx = gbm -> w;
- bm.bmp2.cy = gbm -> h;
- bm.bmp2.cBitCount = gbm -> bpp;
- bm.bmp2.cPlanes = 1;
-
- cRGB = ( (1 << gbm -> bpp) & 0x1ff );
- /* 1 -> 2, 4 -> 16, 8 -> 256, 24 -> 0 */
-
- for ( usCol = 0; usCol < cRGB; usCol++ )
- {
- bm.argb2Color [usCol].bRed = gbmrgb [usCol].r;
- bm.argb2Color [usCol].bGreen = gbmrgb [usCol].g;
- bm.argb2Color [usCol].bBlue = gbmrgb [usCol].b;
- }
-
- if ( (hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, (HDC) NULL)) == (HDC) NULL )
- {
- Warning(hwnd, "DevOpenDC failure");
- return ( FALSE );
- }
-
- sizl.cx = bm.bmp2.cx;
- sizl.cy = bm.bmp2.cy;
- if ( (hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == (HPS) NULL )
- {
- Warning(hwnd, "GpiCreatePS failure");
- DevCloseDC(hdc);
- return ( FALSE );
- }
-
-
- if ( cRGB == 2 )
- /*...shandle 1bpp case:16:*/
- /*
- 1bpp presentation spaces have a reset or background colour.
- They also have a contrast or foreground colour.
- When data is mapped into a 1bpp presentation space :-
- Data which is the reset colour, remains reset, and is stored as 0's.
- All other data becomes contrast, and is stored as 1's.
- The reset colour for 1bpp screen HPSs is white.
- I want 1's in the source data to become 1's in the HPS.
- We seem to have to reverse the ordering here to get the desired effect.
- */
-
- {
- static RGB2 argb2Black = { 0x00, 0x00, 0x00 };
- static RGB2 argb2White = { 0xff, 0xff, 0xff };
- bm.argb2Color [0] = argb2Black; /* Contrast */
- bm.argb2Color [1] = argb2White; /* Reset */
- }
- /*...e*/
-
- if ( (*phbm = GpiCreateBitmap(hps, &(bm.bmp2), CBM_INIT, pbData, (BITMAPINFO2 *) &(bm.bmp2))) == (HBITMAP) NULL )
- {
- Warning(hwnd, "GpiCreateBitmap failure");
- GpiDestroyPS(hps);
- DevCloseDC(hdc);
- return ( FALSE );
- }
-
- GpiSetBitmap(hps, (HBITMAP) NULL);
- GpiDestroyPS(hps);
- DevCloseDC(hdc);
-
- return ( TRUE );
- }
- /*...e*/
- /*...sMakeVisual:0:*/
- static BOOL MakeVisual(
- HWND hwnd,
- GBM *gbm, GBMRGB *gbmrgb, BYTE *pbData,
- BYTE bView,
- HBITMAP *phbm, LONG *plColorBg, LONG *plColorFg
- )
- {
- HPS hps = WinGetPS(HWND_DESKTOP);
- HDC hdc = GpiQueryDevice(hps);
- LONG lPlanes, lBitCount;
- GBM gbmVisual;
- GBMRGB gbmrgbVisual [0x100];
- BYTE *pbDataVisual;
-
- DevQueryCaps(hdc, CAPS_COLOR_PLANES , 1L, &lPlanes );
- DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1L, &lBitCount);
- WinReleasePS(hps);
-
- gbmVisual = *gbm;
- memcpy(gbmrgbVisual, gbmrgb, 0x100 * sizeof(GBMRGB));
- pbDataVisual = pbData;
-
- switch ( bView )
- {
- /*...sVIEW_HALFTONE:16:*/
- case VIEW_HALFTONE:
- if ( !To24Bit(gbm, gbmrgb, pbData, &pbDataVisual) )
- {
- Warning(hwnd, "Out of memory making halftoned view");
- break;
- }
- gbmVisual.bpp = 24;
- switch ( (int) lBitCount )
- {
- case 4:
- gbm_ht_pal_VGA(gbmrgbVisual);
- gbm_ht_VGA_3x3(&gbmVisual, pbDataVisual, pbDataVisual);
- gbmVisual.bpp = 4;
- break;
- case 8:
- gbm_ht_pal_7R8G4B(gbmrgbVisual);
- gbm_ht_7R8G4B_2x2(&gbmVisual, pbDataVisual, pbDataVisual);
- gbmVisual.bpp = 8;
- break;
- case 16:
- gbm_ht_24_2x2(&gbmVisual, pbDataVisual, pbDataVisual, 0xf8, 0xfc, 0xf8);
- gbmVisual.bpp = 24;
- break;
- }
- break;
- /*...e*/
- /*...sVIEW_ERRDIFF:16:*/
- case VIEW_ERRDIFF:
- if ( !To24Bit(gbm, gbmrgb, pbData, &pbDataVisual) )
- {
- Warning(hwnd, "Out of memory making error-diffused view");
- break;
- }
- gbmVisual.bpp = 24;
- switch ( (int) lBitCount )
- {
- case 4:
- /* VGA */
- gbm_errdiff_pal_VGA(gbmrgbVisual);
- gbm_errdiff_VGA(&gbmVisual, pbDataVisual, pbDataVisual);
- gbmVisual.bpp = 4;
- break;
- case 8:
- /* 8514/A, XGA, IA/A */
- gbm_errdiff_pal_7R8G4B(gbmrgbVisual);
- gbm_errdiff_7R8G4B(&gbmVisual, pbDataVisual, pbDataVisual);
- gbmVisual.bpp = 8;
- break;
- case 16:
- /* XGA-2 5:6:5 mode */
- if ( !gbm_errdiff_24(&gbmVisual, pbDataVisual, pbDataVisual, 0xf8, 0xfc, 0xf8) )
- break;
- gbmVisual.bpp = 24;
- break;
- }
- break;
- /*...e*/
- }
-
- if ( !MakeBitmap(hwnd, &gbmVisual, gbmrgbVisual, pbDataVisual, phbm) )
- {
- if ( pbDataVisual != pbData )
- free(pbDataVisual);
- /* Note MakeBitmap displays its own message */
- return ( FALSE );
- }
-
- if ( gbmVisual.bpp == 1 )
- /*...sremember Bg and Fg colours:16:*/
- {
- *plColorBg = (gbmrgbVisual [0].r << 16) + (gbmrgbVisual [0].g << 8) + gbmrgbVisual [0].b;
- *plColorFg = (gbmrgbVisual [1].r << 16) + (gbmrgbVisual [1].g << 8) + gbmrgbVisual [1].b;
- }
- /*...e*/
-
- if ( pbDataVisual != pbData )
- free(pbDataVisual);
-
- return ( TRUE );
- }
- /*...e*/
- /*...sSaveBitmap:0:*/
- static BOOL SaveBitmap(
- HWND hwnd,
- CHAR *szFn, CHAR *szOpt,
- GBM *gbm, GBMRGB *gbmrgb, BYTE *pbData
- )
- {
- GBM_ERR rc;
- int fd, ft, flag;
- GBMFT gbmft;
-
- if ( gbm_guess_filetype(szFn, &ft) != GBM_ERR_OK )
- {
- Warning(hwnd, "Can't deduce bitmap format from file extension: %s", szFn);
- return ( FALSE );
- }
-
- gbm_query_filetype(ft, &gbmft);
- switch ( gbm -> bpp )
- {
- case 1: flag = GBM_FT_W1; break;
- case 4: flag = GBM_FT_W4; break;
- case 8: flag = GBM_FT_W8; break;
- case 24: flag = GBM_FT_W24; break;
- }
-
- if ( (gbmft.flags & flag) == 0 )
- {
- Warning(hwnd, "Bitmap file format %s does not support writing %d bpp files",
- gbmft.short_name, gbm -> bpp);
- return ( FALSE );
- }
-
- if ( (fd = open(szFn, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1 )
- {
- Warning(hwnd, "Can't create file: %s", szFn);
- return ( FALSE );
- }
-
- if ( (rc = gbm_write(szFn, fd, ft, gbm, gbmrgb, pbData, szOpt)) != GBM_ERR_OK )
- {
- close(fd);
- unlink(szFn);
- Warning(hwnd, "Can't write bitmap to file %s: %s", szFn, gbm_err(rc));
- return ( FALSE );
- }
-
- close(fd);
-
- return ( TRUE );
- }
- /*...e*/
- /*...sSaveChanges:0:*/
- /*
- Returns TRUE if changes saved ok.
- Returns FALSE if cancel selected.
- */
-
- static BOOL SaveChanges(HWND hwnd)
- {
- CHAR sz [255];
-
- if ( !fGotBitmap )
- return ( TRUE );
-
- if ( !fUnsavedChanges )
- return ( TRUE );
-
- sprintf(sz, "Save current changes: %s", szFileName);
- switch ( WinMessageBox(HWND_DESKTOP, hwnd, sz, szAppName, 0, MB_YESNOCANCEL | MB_WARNING | MB_MOVEABLE) )
- {
- case MBID_YES:
- {
- GBMFILEDLG gbmfild;
-
- memset(&gbmfild.fild, 0, sizeof(FILEDLG));
- gbmfild.fild.cbSize = sizeof(FILEDLG);
- gbmfild.fild.fl = (FDS_CENTER|FDS_SAVEAS_DIALOG|FDS_HELPBUTTON);
- strcpy(gbmfild.fild.szFullFile, szFileName);
- strcpy(gbmfild.szOptions, "");
- while ( gbmfild.fild.szFullFile [0] == '\0' )
- /* Try to correct filename */
- {
- GbmFileDlg(HWND_DESKTOP, hwnd, &gbmfild);
- if ( gbmfild.fild.lReturn != DID_OK )
- return ( FALSE );
- }
- if ( !SaveBitmap(hwnd, gbmfild.fild.szFullFile, gbmfild.szOptions, &gbm, gbmrgb, pbData) )
- return ( FALSE );
-
- strcpy(szFileName, gbmfild.fild.szFullFile);
- fUnsavedChanges = FALSE;
- return ( TRUE );
- }
- case MBID_NO:
- return ( TRUE );
- case MBID_CANCEL:
- return ( FALSE );
- }
- /* NOT REACHED */
- return ( FALSE ); /* Keep fussy compiler happy */
- }
- /*...e*/
- /*...sBitmapWndProc:0:*/
- #define WC_BITMAP "GbmV2BitmapViewerClass"
-
- static BOOL fTracking = FALSE;
-
- /*
- This is a pretty simple window class. Its aim in life is to display the bitmap
- held by the global variable 'hbm'.
- */
-
- static HBITMAP hbm = NULLHANDLE;
- static LONG lColorBg, lColorFg;
- static HMTX hmtxHbm;
-
- static VOID RequestHbm(VOID)
- {
- DosRequestMutexSem(hmtxHbm, SEM_INDEFINITE_WAIT);
- }
-
- static VOID ReleaseHbm(VOID)
- {
- DosReleaseMutexSem(hmtxHbm);
- }
-
- MRESULT _System BitmapWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- switch ( (int) msg )
- {
- /*...sWM_PAINT \45\ repaint client area:16:*/
- case WM_PAINT:
- {
- RECTL rclUpdate;
- HPS hps = WinBeginPaint(hwnd, (HPS) NULL, &rclUpdate);
-
- RequestHbm();
-
- if ( hbm != (HBITMAP) NULL )
- {
- static SIZEL sizl = { 0, 0 };
- HAB hab = WinQueryAnchorBlock(hwnd);
- HDC hdcBmp = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, (HDC) NULL);
- HPS hpsBmp = GpiCreatePS(hab, hdcBmp, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
- POINTL aptl [3];
- BITMAPINFOHEADER bmp;
-
- GpiQueryBitmapParameters(hbm, &bmp);
-
- GpiSetBitmap(hpsBmp, hbm);
-
- GpiSetBackColor(hps, GpiQueryColorIndex(hps, 0, lColorBg));
- GpiSetColor (hps, GpiQueryColorIndex(hps, 0, lColorFg));
-
- aptl [0].x = 0;
- aptl [0].y = 0;
- aptl [1].x = bmp.cx;
- aptl [1].y = bmp.cy;
- aptl [2].x = 0;
- aptl [2].y = 0;
- GpiBitBlt(hps, hpsBmp, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE);
-
- GpiSetBitmap(hpsBmp, (HBITMAP) NULL);
- GpiDestroyPS(hpsBmp);
- DevCloseDC(hdcBmp);
-
- if ( fSelectionDefined )
- {
- POINTL ptl;
-
- GpiSetMix(hps, FM_INVERT);
- ptl.x = rclSelection.xLeft;
- ptl.y = rclSelection.yBottom;
- GpiMove(hps, &ptl);
- ptl.x = rclSelection.xRight - 1L;
- ptl.y = rclSelection.yTop - 1L;
- GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
- }
- }
-
- ReleaseHbm();
-
- WinEndPaint(hps);
- }
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_CHAR \45\ got a character from the user:16:*/
- #define KS(vkey,kc) ((vkey)+((kc&(KC_ALT|KC_SHIFT|KC_CTRL))<<16))
-
- case WM_CHAR:
- {
- USHORT fs = SHORT1FROMMP(mp1);
- CHAR ch = (CHAR) SHORT1FROMMP(mp2);
- USHORT vkey = SHORT2FROMMP(mp2);
- HWND hwndHscroll = WinWindowFromID(hwndScroller, SCID_HSCROLL);
- HWND hwndVscroll = WinWindowFromID(hwndScroller, SCID_VSCROLL);
-
- if ( fTracking )
- /* Swallow the key */
- return ( (MRESULT) 0 );
-
- if ( fs & KC_VIRTUALKEY )
- {
- switch ( KS(vkey,fs) )
- {
- case KS(VK_LEFT,0):
- case KS(VK_RIGHT,0):
- return ( WinSendMsg(hwndHscroll, msg, mp1, mp2) );
- case KS(VK_LEFT,KC_SHIFT):
- fs &= ~KC_SHIFT;
- vkey = VK_PAGEUP;
- mp1 = MPFROMSHORT(fs);
- mp2 = MPFROM2SHORT(ch, vkey);
- return ( WinSendMsg(hwndHscroll, msg, mp1, mp2) );
- case KS(VK_RIGHT,KC_SHIFT):
- fs &= ~KC_SHIFT;
- vkey = VK_PAGEDOWN;
- mp1 = MPFROMSHORT(fs);
- mp2 = MPFROM2SHORT(ch, vkey);
- return ( WinSendMsg(hwndHscroll, msg, mp1, mp2) );
- case KS(VK_UP,0):
- case KS(VK_DOWN,0):
- case KS(VK_PAGEUP,0):
- case KS(VK_PAGEDOWN,0):
- return ( WinSendMsg(hwndVscroll, msg, mp1, mp2) );
- case KS(VK_UP,KC_SHIFT):
- fs &= ~KC_SHIFT;
- vkey = VK_PAGEUP;
- mp1 = MPFROMSHORT(fs);
- mp2 = MPFROM2SHORT(ch, vkey);
- return ( WinSendMsg(hwndVscroll, msg, mp1, mp2) );
- case KS(VK_DOWN,KC_SHIFT):
- fs &= ~KC_SHIFT;
- vkey = VK_PAGEDOWN;
- mp1 = MPFROMSHORT(fs);
- mp2 = MPFROM2SHORT(ch, vkey);
- return ( WinSendMsg(hwndVscroll, msg, mp1, mp2) );
- }
- }
- }
- break;
- /*...e*/
- /*...sWM_BUTTON2DOWN \45\ cancel current selection:16:*/
- case WM_BUTTON2DOWN:
- fSelectionDefined = FALSE;
- WinInvalidateRect(hwnd, NULL, TRUE);
- WinUpdateWindow(hwnd);
- break;
- /*...e*/
- /*...sWM_MOUSEMOVE \45\ hourglass:16:*/
- case WM_MOUSEMOVE:
- if ( fTracking )
- return ( (MRESULT) 0 );
-
- if ( fBusy )
- {
- WinSetPointer(HWND_DESKTOP,
- WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
- return ( (MRESULT) 0 );
- }
- break;
- /*...e*/
- }
- return ( WinDefWindowProc(hwnd, msg, mp1, mp2) );
- }
- /*...e*/
- /*...sSetBitmap:0:*/
- static VOID SetBitmap(HBITMAP hbmNew)
- {
- HBITMAP hbmOld = hbm;
- BOOL fOld = ( hbmOld != (HBITMAP) NULL );
- BOOL fNew = ( hbmNew != (HBITMAP) NULL );
-
- RequestHbm();
-
- if ( hbmNew == hbmOld )
- {
- ReleaseHbm();
- return;
- }
-
- hbm = hbmNew;
-
- if ( fOld )
- GpiDeleteBitmap(hbmOld);
-
- if ( fNew )
- {
- BITMAPINFOHEADER2 bmp;
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbm, &bmp);
- ReleaseHbm();
- WinShowWindow(hwndBitmap, FALSE);
- WinSetWindowPos(hwndBitmap, (HWND) NULL, 0,0,bmp.cx,bmp.cy, SWP_SIZE);
- }
- else
- {
- ReleaseHbm();
- WinSetWindowPos(hwndBitmap, (HWND) NULL, 0,0,0,0, SWP_SIZE);
- }
-
- if ( !fOld && fNew )
- {
- WinSendMsg(hwndScroller, SCM_CHILD, MPFROMHWND(hwndBitmap), NULL);
- WinShowWindow(hwndBitmap, TRUE);
- }
-
- if ( fOld && fNew )
- {
- WinSendMsg(hwndScroller, SCM_SIZE, MPFROMHWND(hwndBitmap), NULL);
- WinShowWindow(hwndBitmap, TRUE);
- }
-
- if ( fOld && !fNew )
- WinSendMsg(hwndScroller, SCM_CHILD, MPFROMHWND((HWND) NULL), NULL);
- }
- /*...e*/
- /*...sSelect:0:*/
- /*...sTracking:0:*/
- /*
- Credit for this to Petzold.
- */
-
- static BOOL Tracking(
- HWND hwnd,
- RECTL *prclTrack,
- int x, int y, int cx, int cy,
- HPOINTER hptr1, HPOINTER hptr2
- )
- {
- TRACKINFO ti;
-
- ti.cxBorder = 1;
- ti.cyBorder = 1;
- ti.cxGrid = 0;
- ti.cyGrid = 0;
- ti.cxKeyboard = 4;
- ti.cyKeyboard = 4;
-
- ti.rclBoundary.xLeft = x;
- ti.rclBoundary.xRight = x + cx;
- ti.rclBoundary.yBottom = y;
- ti.rclBoundary.yTop = y + cy;
-
- ti.ptlMinTrackSize.x = 1;
- ti.ptlMinTrackSize.y = 1;
-
- ti.ptlMaxTrackSize.x = cx;
- ti.ptlMaxTrackSize.y = cy;
-
- ti.rclTrack.xLeft = x + cx/4;
- ti.rclTrack.xRight = x + cx/4;
- ti.rclTrack.yBottom = y + cy/4;
- ti.rclTrack.yTop = y + cy/4;
-
- /*...smove pointer:8:*/
- {
- POINTL ptl;
-
- ptl.x = ti.rclTrack.xLeft;
- ptl.y = ti.rclTrack.yBottom;
- WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1);
- WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y);
- }
- /*...e*/
-
- ti.fs = TF_MOVE | TF_STANDARD | TF_SETPOINTERPOS | TF_ALLINBOUNDARY;
-
- WinSetPointer(HWND_DESKTOP, hptr1);
-
- if ( !WinTrackRect(hwnd, (HPS) NULL, &ti) )
- return ( FALSE );
-
- ti.fs = TF_RIGHT | TF_TOP | TF_STANDARD | TF_SETPOINTERPOS | TF_ALLINBOUNDARY;
-
- WinSetPointer(HWND_DESKTOP, hptr2);
-
- if ( !WinTrackRect(hwnd, (HPS) NULL, &ti) )
- return ( FALSE );
-
- *prclTrack = ti.rclTrack;
-
- return ( TRUE );
- }
- /*...e*/
-
- static BOOL Select(
- HWND hwnd,
- RECTL *prclTrack,
- int x, int y, int cx, int cy
- )
- {
- HPOINTER hptr1 = WinLoadPointer(HWND_DESKTOP, (HMODULE) NULL, RID_SELECT1);
- HPOINTER hptr2 = WinLoadPointer(HWND_DESKTOP, (HMODULE) NULL, RID_SELECT2);
- BOOL f;
-
- fTracking = TRUE;
- f = Tracking(hwnd, prclTrack, x, y, cx, cy, hptr1, hptr2);
- fTracking = FALSE;
-
- WinDestroyPointer(hptr1);
- WinDestroyPointer(hptr2);
-
- return ( f );
- }
- /*...e*/
- /*...sDeleteBitmap:0:*/
- static VOID DeleteBitmap(VOID)
- {
- if ( fGotBitmap )
- {
- free(pbData);
- fGotBitmap = FALSE;
- }
- }
- /*...e*/
- /*...sCaption:0:*/
- static VOID Caption(HWND hwndClient, CHAR *szFmt, CHAR *szFileName)
- {
- HWND hwndFrame = WinQueryWindow(hwndClient, QW_PARENT);
- CHAR sz [20+MAX_FILE_NAME+50+1], *szAppend;
-
- strcpy(sz, szAppName);
-
- szAppend = sz + strlen(sz);
-
- sprintf(szAppend, szFmt,
- ( szFileName [0] != '\0' ) ? szFileName : "(untitled)" );
-
- WinSetWindowText(hwndFrame, sz);
- }
- /*...e*/
- /*...sObjectWndProc:0:*/
- #define WC_GBMV2_OBJECT "GbmV2ObjectWindowClass"
-
- /*...sUM_ user window messages:0:*/
- #define UM_NEW WM_USER
- #define UM_OPEN (WM_USER+ 1)
- #define UM_SAVE (WM_USER+ 2)
- #define UM_SAVE_AS (WM_USER+ 3)
- #define UM_PRINT (WM_USER+ 4)
- #define UM_UNDO (WM_USER+ 5)
- #define UM_SELECT (WM_USER+ 6)
- #define UM_SELECT_ALL (WM_USER+ 7)
- #define UM_DESELECT (WM_USER+ 8)
- #define UM_COPY (WM_USER+ 9)
- #define UM_REF_HORZ (WM_USER+10)
- #define UM_REF_VERT (WM_USER+11)
- #define UM_ROT_90 (WM_USER+12)
- #define UM_ROT_180 (WM_USER+13)
- #define UM_ROT_270 (WM_USER+14)
- #define UM_TRANSPOSE (WM_USER+15)
- #define UM_CROP (WM_USER+16)
- #define UM_COLOUR (WM_USER+17)
- #define UM_MAP (WM_USER+18)
- #define UM_VIEW_NULL (WM_USER+19)
- #define UM_VIEW_HALFTONE (WM_USER+20)
- #define UM_VIEW_ERRDIFF (WM_USER+21)
-
- #define UM_DONE (WM_USER+22)
- /*...e*/
-
- /*...sReflect:0:*/
- static VOID Reflect(HWND hwndClient, BOOL fHorz, BOOL fVert, BOOL fTranspose, CHAR *szWhat)
- {
- HBITMAP hbmNew;
- int stride, stride_t;
- GBM gbmNew;
- BYTE *pbDataNew;
- RECTL rclNew;
- LONG lColorBgNew, lColorFgNew;
-
- Caption(hwndClient, " - reflecting %s", szFileName);
-
- stride = (((gbm.w * gbm.bpp + 31) / 32) * 4);
- if ( (pbDataNew = malloc(stride * gbm.h)) == NULL )
- {
- Warning(hwndClient, "Out of memory");
- return;
- }
-
- gbmNew = gbm;
- memcpy(pbDataNew, pbData, stride * gbm.h);
- if ( fSelectionDefined )
- rclNew = rclSelection;
- LowPri();
- if ( fHorz )
- {
- if ( !gbm_ref_horz(&gbm, pbDataNew) )
- {
- free(pbDataNew);
- RegPri();
- Warning(hwndClient, "Out of memory");
- return;
- }
- if ( fSelectionDefined )
- {
- LONG xLeft = rclNew.xLeft;
- LONG xRight = rclNew.xRight;
- rclNew.xLeft = gbm.w - xRight;
- rclNew.xRight = gbm.w - xLeft;
- }
- }
-
- if ( fVert )
- {
- if ( !gbm_ref_vert(&gbm, pbDataNew) )
- {
- free(pbDataNew);
- RegPri();
- Warning(hwndClient, "Out of memory");
- return;
- }
- if ( fSelectionDefined )
- {
- LONG yBottom = rclNew.yBottom;
- LONG yTop = rclNew.yTop;
- rclNew.yTop = gbm.h - yBottom;
- rclNew.yBottom = gbm.h - yTop;
- }
- }
-
- if ( fTranspose )
- {
- BYTE *pbDataTrans;
- int t;
-
- stride_t = (((gbm.h * gbm.bpp + 31) / 32) * 4);
-
- if ( (pbDataTrans = malloc(stride_t * gbm.w)) == NULL )
- {
- free(pbDataNew);
- RegPri();
- Warning(hwndClient, "Out of memory");
- return;
- }
-
- gbm_transpose(&gbm, pbDataNew, pbDataTrans);
- free(pbDataNew);
- pbDataNew = pbDataTrans;
- t = gbmNew.w; gbmNew.w = gbmNew.h; gbmNew.h = t;
-
- if ( fSelectionDefined )
- {
- LONG tt;
-
- tt = rclNew.xLeft; rclNew.xLeft = rclNew.yBottom; rclNew.yBottom = tt;
- tt = rclNew.xRight; rclNew.xRight = rclNew.yTop; rclNew.yTop = tt;
- }
- }
-
- Caption(hwndClient, " - rendering %s", szFileName);
- if ( !MakeVisual(hwndClient, &gbmNew, gbmrgb, pbDataNew, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- free(pbDataNew);
- RegPri();
- return;
- }
-
- KeepForUndo(&gbm, gbmrgb, pbData, szWhat);
-
- gbm = gbmNew;
- free(pbData);
- pbData = pbDataNew;
- if ( fSelectionDefined )
- rclSelection = rclNew;
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- fUnsavedChanges = TRUE;
- RegPri();
- }
- /*...e*/
- /*...sColourAdjust:0:*/
- /*...smapinfos:0:*/
- #define CVT_I_TO_L 0
- #define CVT_I_TO_P 1
- #define CVT_L_TO_I 2
- #define CVT_L_TO_P 3
- #define CVT_P_TO_I 4
- #define CVT_P_TO_L 5
- /*...e*/
-
- static int map = CVT_I_TO_L;
- static double gama = 2.1, shelf = 0.0;
-
- MRESULT _System ColourDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- switch ( msg )
- {
- /*...sWM_INITDLG:16:*/
- case WM_INITDLG:
- {
- CHAR sz [50+1];
- SHORT id;
-
- switch ( map )
- {
- case CVT_I_TO_L: id = DID_I_TO_L; break;
- case CVT_I_TO_P: id = DID_I_TO_P; break;
- case CVT_L_TO_I: id = DID_L_TO_I; break;
- case CVT_L_TO_P: id = DID_L_TO_P; break;
- case CVT_P_TO_I: id = DID_P_TO_I; break;
- case CVT_P_TO_L: id = DID_P_TO_L; break;
- }
-
- WinSendDlgItemMsg(hwnd, id, BM_CLICK, MPFROMSHORT(TRUE), NULL);
- WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, id));
-
- sprintf(sz, "%1.1lf", gama);
- WinSetDlgItemText(hwnd, DID_GAMMA, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_GAMMA), NULL, NULL, "0123456789.", NULL);
-
- sprintf(sz, "%1.1lf", shelf);
- WinSetDlgItemText(hwnd, DID_SHELF, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_SHELF), NULL, NULL, "0123456789.", NULL);
-
- TidySysMenu(hwnd);
- return ( (MRESULT) TRUE ); /* We have set the focus */
- }
- /*...e*/
- /*...sWM_COMMAND:16:*/
- case WM_COMMAND:
- switch ( COMMANDMSG(&msg) -> cmd )
- {
- /*...sDID_OK:32:*/
- case DID_OK:
- {
- SHORT sInx = SHORT1FROMMR(WinSendDlgItemMsg(hwnd, DID_I_TO_L, BM_QUERYCHECKINDEX, NULL, NULL)) - 1;
- CHAR sz [50+1];
- int mapNew;
- double gamaNew, shelfNew;
-
- switch ( sInx )
- {
- case DID_I_TO_L - DID_I_TO_L: mapNew = CVT_I_TO_L; break;
- case DID_I_TO_P - DID_I_TO_L: mapNew = CVT_I_TO_P; break;
- case DID_L_TO_I - DID_I_TO_L: mapNew = CVT_L_TO_I; break;
- case DID_L_TO_P - DID_I_TO_L: mapNew = CVT_L_TO_P; break;
- case DID_P_TO_I - DID_I_TO_L: mapNew = CVT_P_TO_I; break;
- case DID_P_TO_L - DID_I_TO_L: mapNew = CVT_P_TO_L; break;
- }
- WinQueryDlgItemText(hwnd, DID_GAMMA, sizeof(sz), sz);
- sscanf(sz, "%lf", &gamaNew);
- WinQueryDlgItemText(hwnd, DID_SHELF, sizeof(sz), sz);
- sscanf(sz, "%lf", &shelfNew);
-
- if ( gamaNew < 0.1 || gamaNew > 10.0 )
- Warning(hwnd, "Gamma must be between 0.1 and 10.0");
- else if ( shelfNew < 0.0 || shelfNew > 1.0 )
- Warning(hwnd, "Shelf must be between 0.0 and 1.0");
- else
- {
- map = mapNew;
- gama = gamaNew;
- shelf = shelfNew;
- WinDismissDlg(hwnd, TRUE);
- return ( (MRESULT) 0 );
- }
- }
- break;
- /*...e*/
- /*...sDID_CANCEL:32:*/
- case DID_CANCEL:
- WinDismissDlg(hwnd, FALSE);
- return ( (MRESULT) 0 );
- /*...e*/
- }
- break;
- /*...e*/
- /*...sWM_CONTROL:16:*/
- case WM_CONTROL:
- {
- SHORT id = SHORT1FROMMP(mp1);
- SHORT note = SHORT2FROMMP(mp1);
- HWND hwndG = WinWindowFromID(hwnd, DID_GAMMA_TEXT);
- HWND hwndS = WinWindowFromID(hwnd, DID_SHELF_TEXT);
-
- switch ( id )
- {
- case DID_I_TO_L:
- case DID_L_TO_I:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndG, FALSE);
- WinEnableWindow(hwndS, FALSE);
- }
- break;
- case DID_I_TO_P:
- case DID_P_TO_I:
- case DID_P_TO_L:
- case DID_L_TO_P:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndG, TRUE);
- WinEnableWindow(hwndS, TRUE);
- }
- break;
- }
- }
- break;
- /*...e*/
- /*...sWM_CLOSE:16:*/
- case WM_CLOSE:
- WinDismissDlg(hwnd, FALSE);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_HELP:16:*/
- case WM_HELP:
- /* Parent is HWND_DESKTOP */
- /* WinDefDlgProc() will pass this up to the parent */
- /* So redirect to the owner */
- return ( WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), msg, mp1, mp2) );
- /*...e*/
- }
- return ( WinDefDlgProc(hwnd, msg, mp1, mp2) );
- }
-
- /*...smap_compute:0:*/
- /*...slstar_from_i:0:*/
- static double lstar_from_i(double y)
- {
- y = pow(1.16 * y, 1.0/3.0) - 0.16;
-
- if ( y < 0.0 ) y = 0.0; else if ( y > 1.0 ) y = 1.0;
-
- return ( y );
- }
- /*...e*/
- /*...si_from_lstar:0:*/
- static double i_from_lstar(double y)
- {
- y = pow(y + 0.16, 3.0) / 1.16;
-
- if ( y < 0.0 ) y = 0.0; else if ( y > 1.0 ) y = 1.0;
-
- return ( y );
- }
- /*...e*/
- /*...spal_from_i:0:*/
- static double pal_from_i(double y, double gam, double shelf)
- {
- y = pow(y,1.0 / gam) * (1.0 - shelf) + shelf;
-
- if ( y < 0.0 ) y = 0.0; else if ( y > 1.0 ) y = 1.0;
-
- return ( y );
- }
- /*...e*/
- /*...si_from_pal:0:*/
- static double i_from_pal(double y, double gam, double shelf)
- {
- if ( y >= shelf )
- y = pow((y - shelf) / (1.0 - shelf), gam);
- else
- y = 0.0;
-
- if ( y < 0.0 ) y = 0.0; else if ( y > 1.0 ) y = 1.0;
-
- return ( y );
- }
- /*...e*/
-
- static void map_compute(int m, byte remap [], double gam, double shelf)
- {
- int i;
-
- for ( i = 0; i < 0x100; i++ )
- {
- double y = (double) i / 255.0;
-
- switch ( m )
- {
- case CVT_I_TO_P: y = pal_from_i(y, gam, shelf); break;
- case CVT_P_TO_I: y = i_from_pal(y, gam, shelf); break;
- case CVT_I_TO_L: y = lstar_from_i(y); break;
- case CVT_L_TO_I: y = i_from_lstar(y); break;
- case CVT_P_TO_L: y = lstar_from_i(i_from_pal(y, gam, shelf)); break;
- case CVT_L_TO_P: y = pal_from_i(i_from_lstar(y), gam, shelf); break;
- }
-
- remap [i] = (byte) (y * 255.0);
- }
- }
- /*...e*/
- /*...smap_data:0:*/
- static void map_data(byte *data, int w, int h, byte remap [])
- {
- int stride = ((w * 3 + 3) & ~3);
- int x, y;
-
- for ( y = 0; y < h; y++, data += stride )
- for ( x = 0; x < w * 3; x++ )
- data [x] = remap [data [x]];
- }
- /*...e*/
- /*...smap_palette:0:*/
- static void map_palette(GBMRGB *gbmrgb, int npals, byte remap [])
- {
- for ( ; npals--; gbmrgb++ )
- {
- gbmrgb -> b = remap [gbmrgb -> b];
- gbmrgb -> g = remap [gbmrgb -> g];
- gbmrgb -> r = remap [gbmrgb -> r];
- }
- }
- /*...e*/
-
- static VOID ColourAdjust(HWND hwndClient)
- {
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
- BYTE abRemap [0x100];
-
- Caption(hwndClient, " - colour adjusting %s", szFileName);
-
- map_compute(map, abRemap, gama, shelf);
-
- LowPri();
- if ( gbm.bpp == 24 )
- /*...smap the data:16:*/
- {
- int stride;
- BYTE *pbDataNew;
-
- stride = (((gbm.w * gbm.bpp + 31) / 32) * 4);
- if ( (pbDataNew = malloc(stride * gbm.h)) == NULL )
- {
- Warning(hwndClient, "Out of memory");
- return;
- }
-
- memcpy(pbDataNew, pbData, stride * gbm.h);
- map_data(pbDataNew, gbm.w, gbm.h, abRemap);
-
- Caption(hwndClient, " - rendering %s", szFileName);
- if ( !MakeVisual(hwndClient, &gbm, gbmrgb, pbDataNew, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- free(pbDataNew);
- RegPri();
- return;
- }
-
- KeepForUndo(&gbm, gbmrgb, pbData, "colour space mapping");
-
- free(pbData);
- pbData = pbDataNew;
- }
- /*...e*/
- else
- /*...smap the palette:16:*/
- {
- GBMRGB gbmrgbNew [0x100];
-
- memcpy(gbmrgbNew, gbmrgb, (sizeof(GBMRGB) << gbm.bpp) );
- map_palette(gbmrgbNew, 1 << gbm.bpp, abRemap);
-
- Caption(hwndClient, " - rendering %s", szFileName);
- if ( !MakeVisual(hwndClient, &gbm, gbmrgbNew, pbData, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- RegPri();
- return;
- }
-
- KeepForUndo(&gbm, gbmrgb, NULL, "colour space mapping");
-
- memcpy(gbmrgb, gbmrgbNew, (sizeof(GBMRGB) << gbm.bpp) );
- }
- /*...e*/
-
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- fUnsavedChanges = TRUE;
- RegPri();
- }
- /*...e*/
- /*...sMap:0:*/
- /*...smapinfos:0:*/
- #define CVT_BW 0
- #define CVT_VGA 1
- #define CVT_8 2
- #define CVT_4G 3
- #define CVT_784 4
- #define CVT_666 5
- #define CVT_8G 6
- #define CVT_TRIPEL 7
- #define CVT_RGB 8
- #define CVT_FREQ 9
-
- #define CVT_NEAREST 0
- #define CVT_ERRDIFF 1
- #define CVT_HALFTONE 2
- /*...e*/
-
- static int iKeepRed = 8, iKeepGreen = 8, iKeepBlue = 8, nCols = 256;
- static int iPal = CVT_784, iAlg = CVT_ERRDIFF;
-
- MRESULT _System MapDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- switch ( msg )
- {
- /*...sWM_INITDLG:16:*/
- case WM_INITDLG:
- {
- CHAR sz [50+1];
- SHORT id;
-
- switch ( iPal )
- {
- case CVT_BW: id = DID_MAP_BW; break;
- case CVT_VGA: id = DID_MAP_VGA; break;
- case CVT_8: id = DID_MAP_8; break;
- case CVT_4G: id = DID_MAP_4G; break;
- case CVT_784: id = DID_MAP_784; break;
- case CVT_666: id = DID_MAP_666; break;
- case CVT_8G: id = DID_MAP_8G; break;
- case CVT_TRIPEL: id = DID_MAP_TRIPEL; break;
- case CVT_RGB: id = DID_MAP_RGB; break;
- case CVT_FREQ: id = DID_MAP_FREQ; break;
- }
-
- WinSendDlgItemMsg(hwnd, id, BM_CLICK, MPFROMSHORT(TRUE), NULL);
- WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, id));
-
- switch ( iAlg )
- {
- case CVT_NEAREST: id = DID_NEAREST; break;
- case CVT_HALFTONE: id = DID_HALFTONE; break;
- case CVT_ERRDIFF: id = DID_ERRDIFF; break;
- }
-
- WinSendDlgItemMsg(hwnd, id, BM_CLICK, MPFROMSHORT(TRUE), NULL);
-
- sprintf(sz, "%d", iKeepRed);
- WinSetDlgItemText(hwnd, DID_R, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_R), NULL, NULL, "0123456789", NULL);
-
- sprintf(sz, "%d", iKeepGreen);
- WinSetDlgItemText(hwnd, DID_G, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_G), NULL, NULL, "0123456789", NULL);
-
- sprintf(sz, "%d", iKeepBlue);
- WinSetDlgItemText(hwnd, DID_B, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_B), NULL, NULL, "0123456789", NULL);
-
- sprintf(sz, "%d", nCols);
- WinSetDlgItemText(hwnd, DID_N, sz);
- RestrictEntryfield(WinWindowFromID(hwnd, DID_N), NULL, NULL, "0123456789", NULL);
-
- TidySysMenu(hwnd);
- return ( (MRESULT) TRUE ); /* We have set the focus */
- }
- /*...e*/
- /*...sWM_CONTROL:16:*/
- case WM_CONTROL:
- {
- SHORT id = SHORT1FROMMP(mp1);
- SHORT note = SHORT2FROMMP(mp1);
- HWND hwndR = WinWindowFromID(hwnd, DID_R_TEXT);
- HWND hwndG = WinWindowFromID(hwnd, DID_G_TEXT);
- HWND hwndB = WinWindowFromID(hwnd, DID_B_TEXT);
- HWND hwndN = WinWindowFromID(hwnd, DID_N_TEXT);
- HWND hwndH = WinWindowFromID(hwnd, DID_HALFTONE);
- HWND hwndE = WinWindowFromID(hwnd, DID_ERRDIFF);
-
- switch ( id )
- {
- case DID_MAP_BW:
- case DID_MAP_8:
- case DID_MAP_VGA:
- case DID_MAP_4G:
- case DID_MAP_784:
- case DID_MAP_666:
- case DID_MAP_8G:
- case DID_MAP_TRIPEL:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndR, FALSE);
- WinEnableWindow(hwndG, FALSE);
- WinEnableWindow(hwndB, FALSE);
- WinEnableWindow(hwndN, FALSE);
- }
- break;
- case DID_MAP_RGB:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndR, TRUE);
- WinEnableWindow(hwndG, TRUE);
- WinEnableWindow(hwndB, TRUE);
- WinEnableWindow(hwndN, FALSE);
- }
- break;
- case DID_MAP_FREQ:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndR, TRUE);
- WinEnableWindow(hwndG, TRUE);
- WinEnableWindow(hwndB, TRUE);
- WinEnableWindow(hwndN, TRUE);
- }
- break;
- }
-
- switch ( id )
- {
- case DID_MAP_8G:
- case DID_MAP_TRIPEL:
- case DID_MAP_FREQ:
- if ( note == BN_CLICKED )
- {
- WinSendDlgItemMsg(hwnd, DID_NEAREST, BM_CLICK, MPFROMSHORT(TRUE), NULL);
- WinEnableWindow(hwndH, FALSE);
- WinEnableWindow(hwndE, FALSE);
- }
- break;
- case DID_MAP_BW:
- case DID_MAP_4G:
- if ( note == BN_CLICKED )
- {
- WinSendDlgItemMsg(hwnd, DID_NEAREST, BM_CLICK, MPFROMSHORT(TRUE), NULL);
- WinEnableWindow(hwndH, FALSE);
- WinEnableWindow(hwndE, TRUE);
- }
- break;
- case DID_MAP_8:
- case DID_MAP_VGA:
- case DID_MAP_784:
- case DID_MAP_666:
- case DID_MAP_RGB:
- if ( note == BN_CLICKED )
- {
- WinEnableWindow(hwndH, TRUE);
- WinEnableWindow(hwndE, TRUE);
- }
- break;
- }
- }
- break;
- /*...e*/
- /*...sWM_COMMAND:16:*/
- case WM_COMMAND:
- switch ( COMMANDMSG(&msg) -> cmd )
- {
- /*...sDID_OK:32:*/
- case DID_OK:
- {
- SHORT sInx;
- CHAR sz [50+1];
- int iPalNew, iAlgNew;
- int iKeepRedNew, iKeepGreenNew, iKeepBlueNew, nColsNew;
-
- sInx = SHORT1FROMMR(WinSendDlgItemMsg(hwnd, DID_MAP_BW, BM_QUERYCHECKINDEX, NULL, NULL)) - 1;
- switch ( sInx )
- {
- case DID_MAP_BW - DID_MAP_BW: iPalNew = CVT_BW; break;
- case DID_MAP_VGA - DID_MAP_BW: iPalNew = CVT_VGA; break;
- case DID_MAP_8 - DID_MAP_BW: iPalNew = CVT_8; break;
- case DID_MAP_4G - DID_MAP_BW: iPalNew = CVT_4G; break;
- case DID_MAP_784 - DID_MAP_BW: iPalNew = CVT_784; break;
- case DID_MAP_666 - DID_MAP_BW: iPalNew = CVT_666; break;
- case DID_MAP_8G - DID_MAP_BW: iPalNew = CVT_8G; break;
- case DID_MAP_TRIPEL - DID_MAP_BW: iPalNew = CVT_TRIPEL; break;
- case DID_MAP_RGB - DID_MAP_BW: iPalNew = CVT_RGB; break;
- case DID_MAP_FREQ - DID_MAP_BW: iPalNew = CVT_FREQ; break;
- }
-
- WinEnableWindow(WinWindowFromID(hwnd, DID_NEAREST ), TRUE);
- WinEnableWindow(WinWindowFromID(hwnd, DID_HALFTONE), TRUE);
- WinEnableWindow(WinWindowFromID(hwnd, DID_ERRDIFF ), TRUE);
-
- sInx = SHORT1FROMMR(WinSendDlgItemMsg(hwnd, DID_NEAREST, BM_QUERYCHECKINDEX, NULL, NULL)) - 1;
- switch ( sInx )
- {
- case DID_NEAREST - DID_NEAREST: iAlgNew = CVT_NEAREST; break;
- case DID_HALFTONE - DID_NEAREST: iAlgNew = CVT_HALFTONE; break;
- case DID_ERRDIFF - DID_NEAREST: iAlgNew = CVT_ERRDIFF; break;
- }
-
- WinQueryDlgItemText(hwnd, DID_R, sizeof(sz), sz);
- sscanf(sz, "%d", &iKeepRedNew);
- WinQueryDlgItemText(hwnd, DID_G, sizeof(sz), sz);
- sscanf(sz, "%d", &iKeepGreenNew);
- WinQueryDlgItemText(hwnd, DID_B, sizeof(sz), sz);
- sscanf(sz, "%d", &iKeepBlueNew);
- WinQueryDlgItemText(hwnd, DID_N, sizeof(sz), sz);
- sscanf(sz, "%d", &nColsNew);
-
- if ( iKeepRedNew < 0 || iKeepRedNew > 8 )
- Warning(hwnd, "No. bits R must be between 0 and 8");
- else if ( iKeepGreenNew < 0 || iKeepGreenNew > 8 )
- Warning(hwnd, "No. bits G must be between 0 and 8");
- else if ( iKeepBlueNew < 0 || iKeepBlueNew > 8 )
- Warning(hwnd, "No. bits B must be between 0 and 8");
- else if ( nColsNew < 1 || nColsNew > 256 )
- Warning(hwnd, "No. bits B must be between 1 and 256");
- else
- {
- iPal = iPalNew;
- iAlg = iAlgNew;
- iKeepRed = iKeepRedNew;
- iKeepGreen = iKeepGreenNew;
- iKeepBlue = iKeepBlueNew;
- nCols = nColsNew;
- WinDismissDlg(hwnd, TRUE);
- return ( (MRESULT) 0 );
- }
- }
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sDID_CANCEL:32:*/
- case DID_CANCEL:
- WinDismissDlg(hwnd, FALSE);
- return ( (MRESULT) 0 );
- /*...e*/
- }
- break;
- /*...e*/
- /*...sWM_CLOSE:16:*/
- case WM_CLOSE:
- WinDismissDlg(hwnd, FALSE);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_HELP:16:*/
- case WM_HELP:
- /* Parent is HWND_DESKTOP */
- /* WinDefDlgProc() will pass this up to the parent */
- /* So redirect to the owner */
- return ( WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), msg, mp1, mp2) );
- /*...e*/
- }
- return ( WinDefDlgProc(hwnd, msg, mp1, mp2) );
- }
-
- /*...sToGreyPal:0:*/
- static VOID ToGreyPal(GBMRGB *gbmrgb)
- {
- int i;
-
- for ( i = 0; i < 0x100; i++ )
- gbmrgb [i].r =
- gbmrgb [i].g =
- gbmrgb [i].b = (byte) i;
- }
- /*...e*/
- /*...sToGrey:0:*/
- static VOID ToGrey(GBM *gbm, byte *src_data, byte *dest_data)
- {
- int src_stride = ((gbm -> w * 3 + 3) & ~3);
- int dest_stride = ((gbm -> w + 3) & ~3);
- int y;
-
- for ( y = 0; y < gbm -> h; y++ )
- {
- byte *src = src_data;
- byte *dest = dest_data;
- int x;
-
- for ( x = 0; x < gbm -> w; x++ )
- {
- byte b = *src++;
- byte g = *src++;
- byte r = *src++;
-
- *dest++ = (byte) (((word) r * 77 + (word) g * 151 + (word) b * 28) >> 8);
- }
-
- src_data += src_stride;
- dest_data += dest_stride;
- }
- gbm -> bpp = 8;
- }
- /*...e*/
- /*...sTripelPal:0:*/
- static VOID TripelPal(GBMRGB *gbmrgb)
- {
- int i;
-
- memset(gbmrgb, 0, 0x100 * sizeof(GBMRGB));
-
- for ( i = 0; i < 0x40; i++ )
- {
- gbmrgb [i ].r = (byte) (i << 2);
- gbmrgb [i + 0x40].g = (byte) (i << 2);
- gbmrgb [i + 0x80].b = (byte) (i << 2);
- }
- }
- /*...e*/
- /*...sTripel:0:*/
- static VOID Tripel(GBM *gbm, byte *src_data, byte *dest_data)
- {
- int src_stride = ((gbm -> w * 3 + 3) & ~3);
- int dest_stride = ((gbm -> w + 3) & ~3);
- int y;
-
- for ( y = 0; y < gbm -> h; y++ )
- {
- byte *src = src_data;
- byte *dest = dest_data;
- int x;
-
- for ( x = 0; x < gbm -> w; x++ )
- {
- byte b = *src++;
- byte g = *src++;
- byte r = *src++;
-
- switch ( (x+y)%3 )
- {
- case 0: *dest++ = (byte) (r >> 2) ; break;
- case 1: *dest++ = (byte) (0x40 + (g >> 2)); break;
- case 2: *dest++ = (byte) (0x80 + (b >> 2)); break;
- }
- }
-
- src_data += src_stride;
- dest_data += dest_stride;
- }
- gbm -> bpp = 8;
- }
- /*...e*/
-
- static VOID Map(HWND hwndClient)
- {
- HBITMAP hbmNew;
- GBM gbmNew;
- LONG lColorBgNew, lColorFgNew;
- GBMRGB gbmrgbNew [0x100];
- BYTE *pbDataNew;
- BOOL ok = TRUE;
- int stride;
- BYTE bViewFast;
-
- Caption(hwndClient, " - mapping %s", szFileName);
-
- /*...sspeedup rendering later:8:*/
- {
- CHAR *szFast = "You have just selected a mapping to a palette which has all "
- "of its colours in the screen palette. Therefore halftoning "
- "or error diffusion will cause no improvement - change View "
- "setting to Raw PM mapping?";
- bViewFast = bView;
-
- switch ( iPal )
- {
- case CVT_BW:
- bViewFast = VIEW_NULL;
- break;
- case CVT_8:
- case CVT_VGA:
- if ( lBitCountScreen == 4 )
- bViewFast = VIEW_NULL;
- break;
- case CVT_784:
- if ( lBitCountScreen == 8 )
- bViewFast = VIEW_NULL;
- break;
- case CVT_FREQ:
- case CVT_RGB:
- if ( lBitCountScreen == 16 &&
- iKeepRed <= 5 &&
- iKeepGreen <= 6 &&
- iKeepBlue <= 5 )
- bViewFast = VIEW_NULL;
- break;
- }
-
- if ( bViewFast != bView )
- switch ( WinMessageBox(HWND_DESKTOP, hwndClient, szFast, szAppName, 0, MB_YESNOCANCEL | MB_WARNING | MB_MOVEABLE) )
- {
- case MBID_YES:
- bView = bViewFast;
- break;
- case MBID_NO:
- break;
- case MBID_CANCEL:
- return;
- }
- }
- /*...e*/
-
- gbmNew = gbm;
- gbmNew.bpp = 24;
-
- stride = ((gbm.w * 3 + 3) & ~3);
- if ( (pbDataNew = malloc(stride * gbm.h)) == NULL )
- {
- Warning(hwndClient, "Out of memory");
- return;
- }
-
- CopyTo24(&gbm, gbmrgb, pbData, pbDataNew);
-
- LowPri();
- /*...sdo mapping:8:*/
- {
- BYTE rm = (BYTE) (0xff00 >> iKeepRed );
- BYTE gm = (BYTE) (0xff00 >> iKeepGreen);
- BYTE bm = (BYTE) (0xff00 >> iKeepBlue );
-
- #define SW2(a,b) (((a)<<8)|(b))
-
- switch ( SW2(iPal,iAlg) )
- {
- case SW2(CVT_BW,CVT_NEAREST):
- gbm_trunc_pal_BW(gbmrgbNew);
- gbm_trunc_BW(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_4G,CVT_NEAREST):
- gbm_trunc_pal_4G(gbmrgbNew);
- gbm_trunc_4G(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_8,CVT_NEAREST):
- gbm_trunc_pal_8(gbmrgbNew);
- gbm_trunc_8(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_VGA,CVT_NEAREST):
- gbm_trunc_pal_VGA(gbmrgbNew);
- gbm_trunc_VGA(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_784,CVT_NEAREST):
- gbm_trunc_pal_7R8G4B(gbmrgbNew);
- gbm_trunc_7R8G4B(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_666,CVT_NEAREST):
- gbm_trunc_pal_6R6G6B(gbmrgbNew);
- gbm_trunc_6R6G6B(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_8G,CVT_NEAREST):
- ToGreyPal(gbmrgbNew);
- ToGrey(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_TRIPEL,CVT_NEAREST):
- TripelPal(gbmrgbNew);
- Tripel(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_FREQ,CVT_NEAREST):
- memset(gbmrgbNew, 0, sizeof(gbmrgbNew));
- gbm_hist(&gbmNew, pbDataNew, gbmrgbNew, pbDataNew, nCols, rm, gm, bm);
- break;
- case SW2(CVT_RGB,CVT_NEAREST):
- gbm_trunc_24(&gbmNew, pbDataNew, pbDataNew, rm, gm, bm);
- break;
- case SW2(CVT_BW,CVT_ERRDIFF):
- gbm_errdiff_pal_BW(gbmrgbNew);
- ok = gbm_errdiff_BW(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_4G,CVT_ERRDIFF):
- gbm_errdiff_pal_4G(gbmrgbNew);
- ok = gbm_errdiff_4G(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_8,CVT_ERRDIFF):
- gbm_errdiff_pal_8(gbmrgbNew);
- ok = gbm_errdiff_8(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_VGA,CVT_ERRDIFF):
- gbm_errdiff_pal_VGA(gbmrgbNew);
- ok = gbm_errdiff_VGA(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_784,CVT_ERRDIFF):
- gbm_errdiff_pal_7R8G4B(gbmrgbNew);
- ok = gbm_errdiff_7R8G4B(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_666,CVT_ERRDIFF):
- gbm_errdiff_pal_6R6G6B(gbmrgbNew);
- ok = gbm_errdiff_6R6G6B(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_RGB,CVT_ERRDIFF):
- ok = gbm_errdiff_24(&gbmNew, pbDataNew, pbDataNew, rm, gm, bm);
- break;
- case SW2(CVT_784,CVT_HALFTONE):
- gbm_ht_pal_7R8G4B(gbmrgbNew);
- gbm_ht_7R8G4B_2x2(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_666,CVT_HALFTONE):
- gbm_ht_pal_6R6G6B(gbmrgbNew);
- gbm_ht_6R6G6B_2x2(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_8,CVT_HALFTONE):
- gbm_ht_pal_8(gbmrgbNew);
- gbm_ht_8_3x3(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_VGA,CVT_HALFTONE):
- gbm_ht_pal_VGA(gbmrgbNew);
- gbm_ht_VGA_3x3(&gbmNew, pbDataNew, pbDataNew);
- break;
- case SW2(CVT_RGB,CVT_HALFTONE):
- gbm_ht_24_2x2(&gbmNew, pbDataNew, pbDataNew, rm, gm, bm);
- break;
- }
-
- switch ( iPal )
- {
- case CVT_BW:
- gbmNew.bpp = 1;
- break;
- case CVT_4G:
- case CVT_8:
- case CVT_VGA:
- gbmNew.bpp = 4;
- break;
- case CVT_784:
- case CVT_666:
- case CVT_8G:
- case CVT_TRIPEL:
- case CVT_FREQ:
- gbmNew.bpp = 8;
- break;
- case CVT_RGB:
- gbmNew.bpp = 24;
- break;
- }
- }
- /*...e*/
-
- if ( !ok )
- {
- free(pbDataNew);
- RegPri();
- Warning(hwndClient, "Unable to perform mapping");
- return;
- }
-
- Caption(hwndClient, " - rendering %s", szFileName);
- if ( !MakeVisual(hwndClient, &gbmNew, gbmrgbNew, pbDataNew, bViewFast, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- free(pbDataNew);
- RegPri();
- return;
- }
-
- KeepForUndo(&gbm, gbmrgb, pbData, "mapping");
-
- gbm = gbmNew;
- if ( gbm.bpp != 24 )
- memcpy(gbmrgb, gbmrgbNew, (sizeof(GBMRGB) << gbm.bpp) );
- free(pbData);
- pbData = pbDataNew;
-
- stride = (((gbm.w * gbm.bpp + 31) / 32) * 4);
- if ( (pbDataNew = realloc(pbData, stride * gbm.h)) != NULL )
- pbData = pbDataNew;
-
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- fUnsavedChanges = TRUE;
- RegPri();
- }
- /*...e*/
-
- MRESULT _System ObjectWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- switch ( (int) msg )
- {
- /*...sUM_NEW \45\ clear out bitmap:16:*/
- case UM_NEW:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- DiscardUndo();
-
- if ( fGotBitmap )
- if ( SaveChanges(hwndClient) )
- {
- SetBitmap((HBITMAP) NULL);
- WinInvalidateRect(hwndScroller, NULL, TRUE);
- WinUpdateWindow(hwndScroller);
- DeleteBitmap();
- strcpy(szFileName, "");
- fSelectionDefined = FALSE;
- fUnsavedChanges = FALSE;
- Caption(hwndClient, "", "");
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_OPEN \45\ read in a new bitmap:16:*/
- case UM_OPEN:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- if ( SaveChanges(hwndClient) )
- {
- GBMFILEDLG gbmfild;
-
- memset(&gbmfild.fild, 0, sizeof(FILEDLG));
- gbmfild.fild.cbSize = sizeof(FILEDLG);
- gbmfild.fild.fl = (FDS_CENTER|FDS_OPEN_DIALOG|FDS_HELPBUTTON);
- strcpy(gbmfild.fild.szFullFile, szFileName);
- strcpy(gbmfild.szOptions, "");
- GbmFileDlg(HWND_DESKTOP, hwndClient, &gbmfild);
- if ( gbmfild.fild.lReturn == DID_OK )
- {
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- SetBitmap((HBITMAP) NULL);
- WinInvalidateRect(hwndScroller, NULL, TRUE);
- WinUpdateWindow(hwndScroller);
- DeleteBitmap();
- DiscardUndo();
- Caption(hwndClient, " - reading %s", gbmfild.fild.szFullFile);
- LowPri();
- if ( LoadBitmap(hwndClient, gbmfild.fild.szFullFile, gbmfild.szOptions, &gbm, gbmrgb, &pbData) )
- {
- Caption(hwndClient, " - rendering %s", gbmfild.fild.szFullFile);
- LowPri();
- if ( MakeVisual(hwndClient, &gbm, gbmrgb, pbData, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- strcpy(szFileName, gbmfild.fild.szFullFile);
- fGotBitmap = TRUE;
- fSelectionDefined = FALSE;
- fUnsavedChanges = FALSE;
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- Caption(hwndClient, " - %s", szFileName);
- }
- else
- {
- free(pbData);
- Caption(hwndClient, "", "");
- }
- }
- else
- Caption(hwndClient, "", "");
- RegPri();
- }
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_SAVE \45\ save with old name:16:*/
- case UM_SAVE:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - saving %s", szFileName);
- LowPri();
- if ( SaveBitmap(hwndClient, szFileName, "", &gbm, gbmrgb, pbData) )
- fUnsavedChanges = FALSE;
- RegPri();
- Caption(hwndClient, "- %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_SAVE_AS \45\ save with new name:16:*/
- case UM_SAVE_AS:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- GBMFILEDLG gbmfild;
-
- memset(&gbmfild.fild, 0, sizeof(FILEDLG));
- gbmfild.fild.cbSize = sizeof(FILEDLG);
- gbmfild.fild.fl = (FDS_CENTER|FDS_SAVEAS_DIALOG|FDS_HELPBUTTON);
- strcpy(gbmfild.fild.szFullFile, szFileName);
- strcpy(gbmfild.szOptions, "");
- GbmFileDlg(HWND_DESKTOP, hwndClient, &gbmfild);
- if ( gbmfild.fild.lReturn == DID_OK )
- {
- Caption(hwndClient, " - saving as %s", gbmfild.fild.szFullFile);
- LowPri();
- if ( SaveBitmap(hwndClient, gbmfild.fild.szFullFile, "", &gbm, gbmrgb, pbData) )
- {
- strcpy(szFileName, gbmfild.fild.szFullFile);
- fUnsavedChanges = FALSE;
- }
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_PRINT \45\ print image:16:*/
- case UM_PRINT:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- HAB hab = WinQueryAnchorBlock(hwndClient);
- HBITMAP hbmCopy;
- BMP_ERR rc;
- CHAR sz [255+1];
-
- Caption(hwndClient, " - printing %s", szFileName);
- LowPri();
- if ( (rc = BmpCopy(hab, hbm, &hbmCopy)) != BMP_ERR_OK )
- {
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- Warning(hwndClient, "Can't make a copy of bitmap to send to printer: %s", BmpErrorMessage(rc, sz));
- }
- else if ( (rc = BmpPrint(hab, hbmCopy, szFileName, szAppName, NULL)) != BMP_ERR_OK )
- {
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- GpiDeleteBitmap(hbmCopy);
- Warning(hwndClient, "Unable to print bitmap: %s", BmpErrorMessage(rc, sz));
- }
- else
- {
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- GpiDeleteBitmap(hbmCopy);
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
-
- /*...e*/
- /*...sUM_UNDO \45\ undo previous operation:16:*/
- case UM_UNDO:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- GBM gbmNew;
- GBMRGB gbmrgbNew [0x100];
- BYTE *pbDataNew;
- CHAR *szWhat;
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- UseUndoBuffer(&gbmNew, gbmrgbNew, &pbDataNew, &szWhat);
- if ( pbDataNew == NULL )
- pbDataNew = pbData;
-
- Caption(hwndClient, " - rendering %s", szFileName);
- if ( !MakeVisual(hwndClient, &gbmNew, gbmrgbNew, pbDataNew, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- if ( pbDataNew != pbData )
- free(pbDataNew);
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
-
- gbm = gbmNew;
- memcpy(gbmrgb, gbmrgbNew, 0x100 * sizeof(GBMRGB));
- if ( pbDataNew != pbData )
- {
- free(pbData);
- pbData = pbDataNew;
- }
- fSelectionDefined = FALSE;
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- fUnsavedChanges = TRUE;
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_SELECT \45\ select region of bitmap:16:*/
- case UM_SELECT:
- {
- BITMAPINFOHEADER2 bmp;
- SWP swpBitmap, swpScroller;
- int cxScrollbar, cyScrollbar, x, y, cx, cy;
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbm, &bmp);
- fSelectionDefined = FALSE;
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- WinQueryWindowPos(hwndBitmap , &swpBitmap );
- WinQueryWindowPos(hwndScroller, &swpScroller);
- cxScrollbar = (int) WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
- cyScrollbar = (int) WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
- x = - (int) swpBitmap.x ; if ( x < 0 ) x = 0;
- y = - (int) swpBitmap.y + cyScrollbar; if ( y < 0 ) y = 0;
- cx = (int) swpScroller.cx - cxScrollbar; if ( cx > (int) bmp.cx ) cx = (int) bmp.cx;
- cy = (int) swpScroller.cy - cyScrollbar; if ( cy > (int) bmp.cy ) cy = (int) bmp.cy;
- fSelectionDefined = Select(hwndBitmap, &rclSelection, x, y, cx, cy);
- if ( fSelectionDefined )
- {
- if ( rclSelection.xLeft != rclSelection.xRight &&
- rclSelection.yBottom != rclSelection.yTop )
- {
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- }
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_SELECT_ALL \45\ select region of bitmap:16:*/
- case UM_SELECT_ALL:
- {
- BITMAPINFOHEADER2 bmp;
-
- fSelectionDefined = FALSE;
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
-
- bmp.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbm, &bmp);
- fSelectionDefined = TRUE;
- rclSelection.xLeft = 0;
- rclSelection.xRight = bmp.cx;
- rclSelection.yTop = bmp.cy;
- rclSelection.yBottom = 0;
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_DESELECT \45\ de\45\select any selcted area:16:*/
- case UM_DESELECT:
- if ( fSelectionDefined )
- {
- fSelectionDefined = FALSE;
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- }
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sUM_COPY \45\ copy bitmap to clipboard:16:*/
- case UM_COPY:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- HAB hab = WinQueryAnchorBlock(hwndClient);
- HBITMAP hbmClipbrd;
- BITMAPINFOHEADER2 bmpClipbrd;
- RECTL rclClipbrd;
- HPS hps;
-
- hps = WinGetPS(hwndClient);
- bmpClipbrd.cbFix = sizeof(BITMAPINFOHEADER2);
- GpiQueryBitmapInfoHeader(hbm, &bmpClipbrd);
- bmpClipbrd.cx = (USHORT) (rclSelection.xRight - rclSelection.xLeft);
- bmpClipbrd.cy = (USHORT) (rclSelection.yTop - rclSelection.yBottom);
- if ( (hbmClipbrd = GpiCreateBitmap(hps, &bmpClipbrd, 0L, NULL, NULL)) == (HBITMAP) NULL )
- Warning(hwndClient, "Can't create bitmap to place on the clipboard");
- else
- {
- rclClipbrd.xLeft = 0; rclClipbrd.xRight = bmpClipbrd.cx;
- rclClipbrd.yBottom = 0; rclClipbrd.yTop = bmpClipbrd.cy;
- BmpBlitter(hab, hbm, rclSelection, hbmClipbrd, rclClipbrd);
- WinOpenClipbrd(hab);
- WinEmptyClipbrd(hab);
- WinSetClipbrdData(hab, (ULONG) hbmClipbrd, CF_BITMAP, CFI_HANDLE);
- WinCloseClipbrd(hab);
- }
- WinReleasePS(hps);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_REF_HORZ \45\ reflect horizontally:16:*/
- case UM_REF_HORZ:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - reflecting horizontally %s", szFileName);
- Reflect(hwndClient, TRUE, FALSE, FALSE, "horizontal reflection");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_REF_VERT \45\ reflect vertically:16:*/
- case UM_REF_VERT:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - reflecting vertically %s", szFileName);
- Reflect(hwndClient, FALSE, TRUE, FALSE, "vertical reflection");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_ROT_90 \45\ rotate 90 degrees:16:*/
- case UM_ROT_90:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - rotating 90 %s", szFileName);
- Reflect(hwndClient, FALSE, TRUE, TRUE, "90 degree rotation");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_ROT_180 \45\ rotate 180 degrees:16:*/
- case UM_ROT_180:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - rotating 180 %s", szFileName);
- Reflect(hwndClient, TRUE, TRUE, FALSE, "180 degree rotation");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_ROT_270 \45\ rotate 270 degrees:16:*/
- case UM_ROT_270:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - rotating 270 %s", szFileName);
- Reflect(hwndClient, TRUE, FALSE, TRUE, "270 degree rotation");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_TRANSPOSE \45\ transpose x for y:16:*/
- case UM_TRANSPOSE:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
-
- Caption(hwndClient, " - transposing %s", szFileName);
- Reflect(hwndClient, FALSE, FALSE, TRUE, "transpose");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_CROP \45\ crop to selection:16:*/
- case UM_CROP:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- GBM gbmNew;
- LONG lColorBgNew, lColorFgNew;
- BYTE *pbDataNew;
- HBITMAP hbmNew;
- int stride;
-
- Caption(hwndClient, " - cropping %s", szFileName);
- LowPri();
-
- gbmNew.w = rclSelection.xRight - rclSelection.xLeft;
- gbmNew.h = rclSelection.yTop - rclSelection.yBottom;
- gbmNew.bpp = gbm.bpp;
-
- stride = (((gbm.w * gbm.bpp + 31) / 32) * 4);
-
- if ( (pbDataNew = malloc(stride * gbmNew.h)) == NULL )
- {
- RegPri();
- Warning(hwndClient, "Out of memory");
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
-
- gbm_subrectangle(&gbm, rclSelection.xLeft, rclSelection.yBottom,
- gbmNew.w, gbmNew.h, pbData, pbDataNew);
-
- if ( !MakeVisual(hwndClient, &gbmNew, gbmrgb, pbDataNew, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- free(pbDataNew);
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
-
- KeepForUndo(&gbm, gbmrgb, pbData, "cropping");
-
- gbm = gbmNew;
- free(pbData);
- pbData = pbDataNew;
- fSelectionDefined = FALSE;
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- fUnsavedChanges = TRUE;
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_COLOUR \45\ colour space:16:*/
- case UM_COLOUR:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- if ( WinDlgBox(HWND_DESKTOP, hwndClient, ColourDlgProc, (HMODULE) NULL, RID_DLG_COLOUR, NULL) )
- {
- ColourAdjust(hwndClient);
- Caption(hwndClient, " - %s", szFileName);
- }
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_MAP \45\ map:16:*/
- case UM_MAP:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- if ( WinDlgBox(HWND_DESKTOP, hwndClient, MapDlgProc, (HMODULE) NULL, RID_DLG_MAP, NULL) )
- {
- Map(hwndClient);
- Caption(hwndClient, " - %s", szFileName);
- }
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_VIEW_NULL \45\ view with no transform:16:*/
- case UM_VIEW_NULL:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- Caption(hwndClient, " - rendering %s", szFileName);
- LowPri();
- if ( MakeVisual(hwndClient, &gbm, gbmrgb, pbData, VIEW_NULL, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- bView = VIEW_NULL;
- }
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_VIEW_HALFTONE \45\ view with error diffusion:16:*/
- case UM_VIEW_HALFTONE:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- Caption(hwndClient, " - rendering %s", szFileName);
- LowPri();
- if ( MakeVisual(hwndClient, &gbm, gbmrgb, pbData, VIEW_HALFTONE, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- bView = VIEW_HALFTONE;
- }
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_VIEW_ERRDIFF \45\ view with halftoning:16:*/
- case UM_VIEW_ERRDIFF:
- {
- HWND hwndClient = HWNDFROMMP(mp1);
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- Caption(hwndClient, " - rendering %s", szFileName);
- LowPri();
- if ( MakeVisual(hwndClient, &gbm, gbmrgb, pbData, VIEW_ERRDIFF, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndBitmap, NULL, TRUE);
- WinUpdateWindow(hwndBitmap);
- bView = VIEW_ERRDIFF;
- }
- RegPri();
- Caption(hwndClient, " - %s", szFileName);
-
- WinSendMsg(hwnd, UM_DONE, NULL, NULL);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sUM_DONE \45\ done\44\ and set pointer back:16:*/
- case UM_DONE:
- {
- POINTL ptl;
- fBusy = FALSE;
- WinQueryPointerPos(HWND_DESKTOP, &ptl);
- WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- }
- return ( WinDefWindowProc(hwnd, msg, mp1, mp2) );
- }
- /*...e*/
- /*...sObjectThread:0:*/
- #define CB_STACK_OBJECT 0x8000
-
- static VOID _Optlink ObjectThread(VOID *pvParams)
- {
- HAB hab = WinInitialize(0);
- HMQ hmq = WinCreateMsgQueue(hab, 0);
- QMSG qmsg;
-
- pvParams=pvParams; /* Suppress 'unref' compiler warning */
-
- WinRegisterClass(hab, WC_GBMV2_OBJECT, ObjectWndProc, 0L, 0);
-
- hwndObject = WinCreateWindow(HWND_OBJECT, WC_GBMV2_OBJECT, NULL, 0L, 0,0,0,0,
- HWND_DESKTOP, HWND_BOTTOM, 0, NULL, NULL);
-
- while ( WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0) )
- WinDispatchMsg(hab, &qmsg);
-
- WinDestroyWindow(hwndObject);
-
- WinDestroyMsgQueue(hmq);
- WinTerminate(hab);
- }
- /*...e*/
- /*...sGbmV2WndProc:0:*/
- #define WC_GBMV2 "GbmV2Class"
-
- MRESULT _System GbmV2WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- switch ( (int) msg )
- {
- /*...sWM_PAINT \45\ repaint client area:16:*/
- /*
- Dead simple, as this window is usually completely covered by the scroller
- window.
- */
-
- case WM_PAINT:
- {
- HPS hps = WinBeginPaint(hwnd, (HPS) NULL, (RECTL *) NULL);
-
- GpiSetBackColor(hps, CLR_RED);
-
- GpiErase(hps);
-
- WinEndPaint(hps);
- }
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_SIZE \45\ user has resized window:16:*/
- case WM_SIZE:
- {
- SWP swp;
-
- WinQueryWindowPos(hwnd, &swp);
- WinSetWindowPos(hwndScroller, (HWND) NULL, 0, 0, swp.cx, swp.cy, SWP_SIZE);
- }
- break;
- /*...e*/
- /*...sWM_INITMENU \45\ enable right menuitems:16:*/
- case WM_INITMENU:
- {
- HWND hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
- HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
-
- switch ( SHORT1FROMMP(mp1) )
- {
- /*...sMID_FILE:32:*/
- case MID_FILE:
- EnableMenuItem(hwndMenu, MID_NEW , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_OPEN , !fBusy );
- EnableMenuItem(hwndMenu, MID_SAVE , !fBusy && fGotBitmap && (szFileName [0] != '\0') );
- EnableMenuItem(hwndMenu, MID_SAVE_AS, !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_PRINT , !fBusy && fGotBitmap);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sMID_EDIT:32:*/
- case MID_EDIT:
- {
- CHAR szUndo [100+1];
- EnableMenuItem(hwndMenu, MID_UNDO , !fBusy && fCanUndo);
- if ( fCanUndo )
- sprintf(szUndo, "~Undo %s", szWhatUndo);
- else
- sprintf(szUndo, "~Undo");
- WinSendMsg(hwndMenu, MM_SETITEMTEXT, MPFROMSHORT(MID_UNDO), MPFROMP(szUndo));
- EnableMenuItem(hwndMenu, MID_SELECT , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_SELECT_ALL, !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_DESELECT , !fBusy && fSelectionDefined);
- EnableMenuItem(hwndMenu, MID_COPY , !fBusy && fGotBitmap && fSelectionDefined);
- return ( (MRESULT) 0 );
- }
- /*...e*/
- /*...sMID_BITMAP:32:*/
- case MID_BITMAP:
- EnableMenuItem(hwndMenu, MID_REF_HORZ , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_REF_VERT , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_ROT_90 , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_ROT_180 , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_ROT_270 , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_TRANSPOSE, !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_CROP , !fBusy && fGotBitmap && fSelectionDefined);
- EnableMenuItem(hwndMenu, MID_COLOUR , !fBusy && fGotBitmap);
- EnableMenuItem(hwndMenu, MID_MAP , !fBusy && fGotBitmap);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sMID_VIEW:32:*/
- case MID_VIEW:
- {
- BOOL fHalftone = ( lBitCountScreen == 4 || lBitCountScreen == 8 || lBitCountScreen == 16 );
- BOOL fErrDiff = ( lBitCountScreen == 4 || lBitCountScreen == 8 || lBitCountScreen == 16 );
-
- EnableMenuItem(hwndMenu, MID_VIEW_NULL , !fBusy && fGotBitmap && bView != VIEW_NULL );
- EnableMenuItem(hwndMenu, MID_VIEW_HALFTONE, !fBusy && fGotBitmap && bView != VIEW_HALFTONE && fHalftone);
- EnableMenuItem(hwndMenu, MID_VIEW_ERRDIFF , !fBusy && fGotBitmap && bView != VIEW_ERRDIFF && fErrDiff );
- CheckMenuItem(hwndMenu, MID_VIEW_NULL , bView == VIEW_NULL );
- CheckMenuItem(hwndMenu, MID_VIEW_HALFTONE, bView == VIEW_HALFTONE);
- CheckMenuItem(hwndMenu, MID_VIEW_ERRDIFF , bView == VIEW_ERRDIFF );
- return ( (MRESULT) 0 );
- }
- /*...e*/
- }
- }
- break;
- /*...e*/
- /*...sWM_COMMAND \45\ menu command:16:*/
- case WM_COMMAND:
- switch ( COMMANDMSG(&msg) -> cmd )
- {
- /*...sMID_NEW \45\ clear out bitmap:32:*/
- case MID_NEW:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_NEW, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_OPEN \45\ read in a new bitmap:32:*/
- case MID_OPEN:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_OPEN, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_SAVE \45\ save with old name:32:*/
- case MID_SAVE:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_SAVE, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_SAVE_AS \45\ save with new name:32:*/
- case MID_SAVE_AS:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_SAVE_AS, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_PRINT \45\ print image:32:*/
- case MID_PRINT:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_PRINT, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_UNDO \45\ undo previous operation:32:*/
- case MID_UNDO:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_UNDO, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_SELECT \45\ select region of bitmap:32:*/
- case MID_SELECT:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_SELECT, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_SELECT_ALL \45\ select region of bitmap:32:*/
- case MID_SELECT_ALL:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_SELECT_ALL, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_DESELECT \45\ de\45\select any selcted area:32:*/
- case MID_DESELECT:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_DESELECT, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_COPY \45\ copy bitmap to clipboard:32:*/
- case MID_COPY:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_COPY, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_REF_HORZ \45\ reflect horizontally:32:*/
- case MID_REF_HORZ:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_REF_HORZ, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_REF_VERT \45\ reflect vertically:32:*/
- case MID_REF_VERT:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_REF_VERT, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_ROT_90 \45\ rotate by 90 degrees:32:*/
- case MID_ROT_90:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_ROT_90, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_ROT_180 \45\ rotate by 180 degrees:32:*/
- case MID_ROT_180:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_ROT_180, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_ROT_270 \45\ rotate by 270 degrees:32:*/
- case MID_ROT_270:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_ROT_270, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_TRANSPOSE \45\ transpose x for y:32:*/
- case MID_TRANSPOSE:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_TRANSPOSE, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_CROP \45\ crop to selection:32:*/
- case MID_CROP:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_CROP, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_COLOUR \45\ change colour space:32:*/
- case MID_COLOUR:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_COLOUR, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_MAP \45\ map:32:*/
- case MID_MAP:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_MAP, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_VIEW_NULL \45\ view with no transform:32:*/
- case MID_VIEW_NULL:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_VIEW_NULL, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_VIEW_HALFTONE \45\ view with errordiffusion:32:*/
- case MID_VIEW_HALFTONE:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_VIEW_HALFTONE, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_VIEW_ERRDIFF \45\ view with halftoning:32:*/
- case MID_VIEW_ERRDIFF:
- fBusy = TRUE;
- WinPostMsg(hwndObject, UM_VIEW_ERRDIFF, MPFROMHWND(hwnd), NULL);
- break;
- /*...e*/
- /*...sMID_HELP_FOR_HELP \45\ bring up help for help:32:*/
- case MID_HELP_FOR_HELP:
- HlpHelpForHelp(hwndHelp);
- break;
- /*...e*/
- /*...sMID_EXIT \45\ initiate shutdown of this app:32:*/
- case MID_EXIT:
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
- break;
- /*...e*/
- }
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_CLOSE \45\ close window:16:*/
- case WM_CLOSE:
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
- return ( (MRESULT) 0 );
- /*...e*/
- /*...sWM_CONTROL \45\ override scrolling amount:16:*/
- case WM_CONTROL:
- if ( SHORT1FROMMP(mp1) == WID_SCROLL )
- switch ( SHORT2FROMMP(mp1) )
- {
- case SCN_HPAGE:
- case SCN_VPAGE:
- return ( (MRESULT) SHORT2FROMMP(mp2) );
- }
- break;
- /*...e*/
- /*...sWM_ACTIVATE \45\ ensure help instance is ours:16:*/
- case WM_ACTIVATE:
- {
- HWND hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
-
- if ( mp1 && hwndHelp != (HWND) NULL )
- HlpActivate(hwndHelp, hwndFrame);
- }
- break;
- /*...e*/
- /*...sHM_\42\ \45\ redirect help support:16:*/
- case HM_ERROR:
- case HM_INFORM:
- case HM_QUERY_KEYS_HELP:
- case HM_EXT_HELP_UNDEFINED:
- case HM_HELPSUBITEM_NOT_FOUND:
- return ( HlpWndProc(hwnd, msg, mp1, mp2) );
- /*...e*/
- }
- return ( WinDefWindowProc(hwnd, msg, mp1, mp2) );
- }
- /*...e*/
- /*...smain:0:*/
- int main(int argc, CHAR *argv [])
- {
- HAB hab = WinInitialize(0);
- HMQ hmq = WinCreateMsgQueue(hab, 0);
- QMSG qmsg;
- HWND hwndFrame, hwndClient;
- HPS hps;
- HDC hdc;
- SWP swp;
- static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
- FCF_SIZEBORDER | FCF_MINMAX |
- FCF_MENU | FCF_ICON |
- FCF_SHELLPOSITION | FCF_TASKLIST |
- FCF_ACCELTABLE ;
-
- gbm_init();
-
- hps = WinGetPS(HWND_DESKTOP);
- hdc = GpiQueryDevice(hps);
- DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1L, &lBitCountScreen);
- WinReleasePS(hps);
-
- DosCreateMutexSem(NULL, &hmtxHbm, 0 /*=Private*/, FALSE /*=unowned*/ );
-
- RegisterScrollClass(hab);
- WinRegisterClass(hab, WC_GBMV2, GbmV2WndProc, CS_CLIPCHILDREN|CS_SIZEREDRAW, 0);
- WinRegisterClass(hab, WC_BITMAP, BitmapWndProc, 0L, 0);
-
- hwndFrame = WinCreateStdWindow(
- HWND_DESKTOP, /* Parent window handle */
- WS_VISIBLE, /* Style of frame window */
- &flFrameFlags, /* Pointer to control data */
- WC_GBMV2, /* Client window class name */
- NULL, /* Title bar text */
- 0L, /* Style of client window */
- (HMODULE) NULL, /* Module handle for resources */
- RID_GBMV2, /* ID of resources */
- &hwndClient); /* Pointer to client window handle */
-
- WinSetWindowText(hwndFrame, szAppName);
-
- WinQueryWindowPos(hwndClient, &swp);
-
- hwndScroller = WinCreateWindow(hwndClient, WC_SCROLL, "", WS_VISIBLE|SCS_HSCROLL|SCS_VSCROLL|SCS_HCENTRE|SCS_VCENTRE|SCS_HPAGE|SCS_VPAGE,
- 0,0,swp.cx,swp.cy, hwndClient, HWND_BOTTOM, WID_SCROLL, NULL, NULL);
- hwndBitmap = WinCreateWindow(hwndScroller, WC_BITMAP, "", WS_VISIBLE|WS_CLIPSIBLINGS,
- 0,0,0,0, hwndScroller, HWND_BOTTOM, WID_BITMAP, NULL, NULL);
- WinSetFocus(HWND_DESKTOP, hwndBitmap);
-
- _beginthread(ObjectThread, NULL, CB_STACK_OBJECT, NULL);
-
- if ( argc >= 2 )
- {
- CHAR *szOpt;
-
- if ( (szOpt = strchr(argv [1], ',')) != NULL )
- *szOpt++ = '\0';
- else
- szOpt = "";
-
- if ( LoadBitmap(HWND_DESKTOP, argv [1], szOpt, &gbm, gbmrgb, &pbData) )
- {
- HBITMAP hbmNew;
- LONG lColorBgNew, lColorFgNew;
-
- if ( MakeVisual(HWND_DESKTOP, &gbm, gbmrgb, pbData, bView, &hbmNew, &lColorBgNew, &lColorFgNew) )
- {
- strcpy(szFileName, argv [1]);
- Caption(hwndClient, " - %s", szFileName);
- lColorBg = lColorBgNew;
- lColorFg = lColorFgNew;
- SetBitmap(hbmNew);
- WinInvalidateRect(hwndScroller, NULL, TRUE);
- WinUpdateWindow(hwndScroller);
- fGotBitmap = TRUE;
- }
- else
- free(pbData);
- }
- }
-
- if ( (hwndHelp = HlpInit(hwndClient,
- (HMODULE) NULL, RID_HELP_TABLE,
- "GBMV2.HLP GBMDLG.HLP", szAppName)) != (HWND) NULL )
- HlpActivate(hwndHelp, hwndFrame);
-
- for ( ;; )
- {
- while ( WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0) )
- WinDispatchMsg(hab, &qmsg);
-
- if ( SaveChanges(hwndFrame) )
- /* User has not cancelled Close */
- {
- if ( !fBusy )
- break;
-
- Warning(hwndFrame, "Cannot Close yet, %s is busy, please wait and retry", szAppName);
- }
- }
-
- if ( hwndHelp != (HWND) NULL )
- HlpDeinit(hwndHelp);
-
- WinPostMsg(hwndObject, WM_QUIT, NULL, NULL);
-
- WinDestroyWindow(hwndBitmap);
- WinDestroyWindow(hwndScroller);
- WinDestroyWindow(hwndFrame);
-
- DosCloseMutexSem(hmtxHbm);
-
- gbm_deinit();
-
- WinDestroyMsgQueue(hmq);
- WinTerminate(hab);
-
- return ( 0 );
- }
- /*...e*/
-