/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1990-2004 by LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include #include #include "math.h" #include "Segdem.h" #include "prsht.h" #include "commctrl.h" #define RCWIDTH(lpRect) (((LPRECT) lpRect)->right - ((LPRECT) lpRect)->left) #define RCHEIGHT(lpRect) (((LPRECT) lpRect)->bottom - ((LPRECT) lpRect)->top) #define IMGPROF_AUTO 0 #define IMGPROF_NOISY 1 #define IMGPROF_SCANNED 2 #define IMGPROF_PRINTED 3 #define IMGPROF_COMPUTERGEN 4 #define IMGPROF_PHOTOS 5 #define IMGPROF_USERDEFINED 6 #define OPIMGQ_AUTO 0 #define OPIMGQ_POOR 1 #define OPIMGQ_AVG 2 #define OPIMGQ_GOOD 3 #define OPIMGQ_EXCELLENT 4 #define OPIMGQ_USERDEFINED 5 #define RESIZE_TOP 0 #define RESIZE_BOTTOM 1 #define RESIZE_LEFT 2 #define RESIZE_RIGHT 3 #define RESIZE_LEFT_TOP 4 #define RESIZE_RIGHT_TOP 5 #define RESIZE_LEFT_BOTTOM 6 #define RESIZE_RIGHT_BOTTOM 7 #define RESIZE_SEGMENT 8 #define RESIZE_CONTEXTMNEU 9 #define RESIZE_NOTHING -1 L_TCHAR TEXT_1BIT_BW[] = TEXT("T1BW"); L_TCHAR TEXT_1BIT_COLOR[] = TEXT("T1C"); L_TCHAR TEXT_2BIT_COLOR[] = TEXT("T2C"); L_TCHAR TEXT_2BIT_GRAYSCALE[] = TEXT("G2"); L_TCHAR TEXT_8BIT_GRAYSCALE[] = TEXT("G8"); L_TCHAR TEXT_PICTURE[] = TEXT("P"); L_TCHAR TEXT_BACKGRND[] = TEXT("BG"); L_TCHAR TEXT_ONECOLOR[] = TEXT("1C"); L_TCHAR TEXT_2BIT_BW[] = TEXT("T2BW"); #define SIZE_TEXT_BACKGRND (sizeof(TEXT_BACKGRND) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_ONECOLOR (sizeof(TEXT_ONECOLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_BW (sizeof(TEXT_2BIT_BW) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_1BIT_BW (sizeof(TEXT_1BIT_BW) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_1BIT_COLOR (sizeof(TEXT_1BIT_COLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_COLOR (sizeof(TEXT_2BIT_COLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_GRAYSCALE (sizeof(TEXT_2BIT_GRAYSCALE) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_8BIT_GRAYSCALE (sizeof(TEXT_8BIT_GRAYSCALE) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_PICTURE (sizeof(TEXT_PICTURE) / sizeof(L_TCHAR)) - 1 LRESULT CALLBACK CompressionDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK PdfCompressionDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK AutoSegmentationDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK SegmentationExtDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK ColorsDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK SaveMultiDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); L_VOID OnInitOptionDialog(HWND hWnd); L_VOID InitValues(HWND hDlg); L_VOID AutoSegmentationDialogCommand(HWND hWnd, UINT uID, UINT uMsg); L_VOID SegmentationExtDialogCommand(HWND hWnd, UINT uID, UINT uMsg); L_VOID HandleSlider(HWND hParent, HWND hWnd, int nCode); L_VOID HandleSlider2(HWND hParent, HWND hWnd, int nCode); L_VOID UpdateCompressionPage(HWND hWnd); L_VOID UpdateAutoSegmentationPage(HWND hWnd); L_VOID UpdateCombineFactorStatus(HWND hWnd, L_BOOL bEnable); L_VOID CompressionDialogCommand(HWND hWnd, UINT uID, UINT uMsg); L_VOID UpdateSegmentationExtPage(HWND hWnd); L_VOID LockOutputOptions(HWND hWnd, L_BOOL bLock); L_VOID LockInputOptions(HWND hWnd, L_BOOL bLock); L_BOOL ShowHorizontal ( HWND hList ); L_INT EXT_CALLBACK EnumAutoSegments(HSEGMENTATION hSegment, const pSEGMENTDATA pSegment, L_INT nSegId, L_VOID L_FAR* pUserData); static L_VOID Child_OnLButtonUp (HWND hWnd, L_INT x, L_INT y, UINT keyFlags); static L_VOID Child_OnLButtonDown (HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, UINT keyFlags); static L_VOID Child_OnRButtonDown (HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, UINT keyFlags); static L_BOOL Child_OnSetCursor (HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg); static L_VOID Child_OnMouseMove (HWND hWnd, L_INT x, L_INT y, UINT keyFlags); static L_BOOL Child_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct); static L_VOID Child_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify); static L_VOID Child_OnSize (HWND hWnd, UINT nState, L_INT nCx, L_INT nCy); static L_VOID Child_OnPaint (HWND hWnd); static L_VOID Child_OnMDIActivate (HWND hWnd, L_BOOL fActive, HWND hWndActivate,HWND hWndDeactivate); static L_VOID Child_OnDestroy (HWND hWnd); static L_VOID Child_OnVScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos); static L_VOID Child_OnHScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos); static L_VOID Child_OnKeyDown (HWND hWnd, UINT vk, L_BOOL fDown, L_INT cRepeat, UINT flags); static L_VOID Child_OnSetFocus (HWND hWnd, HWND hwndNewFocus); static L_BOOL Child_OnEraseBkgnd (HWND hWnd, HDC hDC); static L_VOID Child_OnClose (HWND hWnd); static L_VOID Child_OnContextMenu (HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos); static L_VOID Child_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange); static L_BOOL Child_OnQueryNewPalette (HWND hWnd); L_VOID DisplayCurrentTabPage (HWND hDlg); L_VOID UnSelectSegments (HWND hWnd, LPCHILDDATA pData); L_VOID RemoveSelectedSegments (LPCHILDDATA pData); L_VOID UnSelectCurrentSegment(HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y); L_BOOL IsSegmentSelected (LPCHILDDATA pData, L_INT nSegment); L_VOID RefreshSegments (HWND hWnd, LPCHILDDATA pData, LPRECT pRect); L_VOID StopSegmentation (pHSEGMENTATION phSegment); L_VOID ShowColorDialog (HWND hwnd, COLORREF* pClr); L_INT DrawManualSegment (HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y); L_VOID UpdateSegments (HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y); L_INT FindNextSelectionIndex(LPCHILDDATA pData); L_VOID SelectSegments (HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y); L_VOID CombineSegments (HWND hWnd, LPCHILDDATA pData); L_VOID ExportSegments (HWND hWnd); L_VOID ImportSegments (HWND hWnd); L_VOID ShowUniqueColors (HWND hWnd, pBITMAPHANDLE pBitmap); L_VOID ShowSegmentUniqueColors(HWND hWnd); L_VOID ShowSegmentInNewWindow(HWND hWnd); L_BOOL CanEnlargeFromLeft (LPRECT pLeftRc, LPRECT pSelRect); L_BOOL CanEnlargeFromTop (LPRECT pTopRc, LPRECT pSelRect); L_BOOL CanEnlargeFromRight (LPRECT pRightRc, LPRECT pSelRect); L_BOOL CanEnlargeFromBottom (LPRECT pBottomRc, LPRECT pSelRect); L_VOID EnlargeSegment (HWND hWnd); L_VOID ShowHistogram (HWND hWnd, pBITMAPHANDLE pBitmap); L_VOID ShowSegmentHistogram (HWND hWnd); L_VOID ShowSegmentType (HWND hWnd); L_VOID ClearSegments (HWND hWnd); L_VOID NormalizeRect (RECT* pRect); L_VOID CheckRectCoordinates (L_INT nLineSel, RECT* pRect, L_BOOL bManual, RECT* pManualSeg, L_INT nStartRow, L_INT nEndRow, RECT* pOldManualRect); L_INT SaveBitmap (HWND hWnd); L_VOID UpdateSaveFileOption (SAVEDLGPARAMS* pFSParm, pSAVEFILEOPTION pSaveOpt); L_INT SaveMRC (HWND hWnd); L_INT SaveLeadMRC (HWND hWnd); L_INT SavePDF (HWND hWnd); L_BOOL ManualSegmentation (HWND hWnd); L_VOID AutoManualSegmentation(HWND hWnd); L_VOID AutoSegmentation (HWND hWnd); L_VOID OpenDilaogColorRes (HWND hWnd); L_VOID DrawSelectedLines (HWND hWnd, RECT* pRect); L_VOID ChangeToZoom (HWND hWnd, RECT* pRect); L_VOID ChangeToImage (HWND hWnd, RECT* pRect); L_VOID ZoomBitmap (HWND hWnd, RECT* pRect, L_FLOAT fZoomVal, L_INT nWidth, L_INT nHeight); L_VOID DrawManualSegmentRect(HWND hWnd, POINT ptStart, POINT ptEnd, L_INT nMode); L_VOID DeleteSegment (HWND hWnd); L_VOID SelectAllSegments (HWND hWnd); L_VOID UndoSegmentation (HWND hWnd, LPCHILDDATA pData); L_VOID LButtonUp (HWND hWnd, L_INT x, L_INT y); L_VOID SetFileNameExt (L_TCHAR L_FAR* pszFileName, L_TCHAR L_FAR* pszExt); L_VOID FindSelectionLine (HWND hWnd, RECT* pRect, POINT pt); L_VOID ShiftSegmentID (LPCHILDDATA pData, L_INT nIndex, L_INT nCount); L_VOID ChangeQFactorStatus (HWND hWnd); static HWND hwndClient, hwndFrame; L_BOOL bInScroll; extern L_UINT uInputImageType; extern L_UINT uOutputImageType; extern SEGMENTATIONOPTIONS gSegOpt; extern SEGMENTEXTOPTIONS gSegExt; extern SEGMENTEXTOPTIONS gInputImgUserDef; extern SEGMENTEXTOPTIONS gOutputImgUserDef; extern L_BOOL gbShowSegmentType; extern L_INT gnQFactor; extern L_INT gnGSQFactor; extern L_INT gnMaskCoder; extern L_INT gnPictureCoder; extern L_INT gnTextCoder2Bit; extern L_INT gnGrayscale8BitCoder; extern L_INT gnGrayscale2BitCoder; extern COLORREF gcrBground; extern COLORREF gcrFground; extern L_INT gnPdfPictureCoder; extern L_INT gnPdfTextCoder2Bit; extern L_INT gnPdfMaskCoder; extern L_INT gnPdfQFactor; extern PDFDPIOPTIONS DPIOptions; HWND hPage[5]; SEGMENTATIONOPTIONS gTempSegOpt; SEGMENTEXTOPTIONS gTempSegExt; L_INT gnTempQFactor; L_INT gnTempGSQFactor; L_INT gnTempMaskCoder; L_INT gnTempTextCoder2Bit; L_INT gnTempPictureCoder; L_INT gnTempGrayscaleCoder8Bit; L_INT gnTempGrayscaleCoder2Bit; COLORREF gcrTempBground; COLORREF gcrTempFground; L_INT gnTempPdfQFactor; L_INT gnTempPdfMaskCoder; L_INT gnTempPdfTextCoder2Bit; L_INT gnTempPdfPictureCoder; L_BOOL gbChange; LRESULT CALLBACK ChildWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { HANDLE_MSG (hWnd, WM_CREATE, Child_OnCreate); HANDLE_MSG (hWnd, WM_COMMAND, Child_OnCommand); HANDLE_MSG (hWnd, WM_SIZE, Child_OnSize); HANDLE_MSG (hWnd, WM_MDIACTIVATE, Child_OnMDIActivate); HANDLE_MSG (hWnd, WM_PAINT, Child_OnPaint); HANDLE_MSG (hWnd, WM_DESTROY, Child_OnDestroy); HANDLE_MSG (hWnd, WM_VSCROLL, Child_OnVScroll); HANDLE_MSG (hWnd, WM_HSCROLL, Child_OnHScroll); HANDLE_MSG (hWnd, WM_ERASEBKGND, Child_OnEraseBkgnd); HANDLE_MSG (hWnd, WM_CLOSE, Child_OnClose); HANDLE_MSG (hWnd, WM_LBUTTONUP, Child_OnLButtonUp); HANDLE_MSG (hWnd, WM_LBUTTONDOWN, Child_OnLButtonDown); HANDLE_MSG (hWnd, WM_RBUTTONDOWN, Child_OnRButtonDown); HANDLE_MSG (hWnd, WM_MOUSEMOVE, Child_OnMouseMove); HANDLE_MSG (hWnd, WM_SETCURSOR, Child_OnSetCursor); HANDLE_MSG (hWnd, WM_KEYDOWN, Child_OnKeyDown); HANDLE_MSG (hWnd, WM_SETFOCUS, Child_OnSetFocus); HANDLE_MSG (hWnd, WM_CONTEXTMENU, Child_OnContextMenu); HANDLE_MSG (hWnd, WM_PALETTECHANGED, Child_OnPaletteChanged); HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Child_OnQueryNewPalette); } return DefMDIChildProc (hWnd, message, wParam, lParam); } static L_VOID Child_OnContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos) { HMENU hMenu; LPCHILDDATA pData; RECT rcSelected; POINT pt; L_FLOAT fFactor; L_INT i; HWND hActiveWnd; hActiveWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); if (hActiveWnd != hWnd) return; SendMessage(hwndFrame, WM_INITMENUPOPUP, 0, 0); pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (pData->bLBDown) return; /* Display the context menu when there is 1 selection or 2 selection */ if (FindSelectionCount(pData) == 0) return; pData->nLineSel = RESIZE_CONTEXTMNEU; SetCursor(LoadCursor(NULL, IDC_ARROW)); fFactor = (L_FLOAT)(pData->fZoomVal / 100.0); GetCursorPos(&pt); ScreenToClient(hWnd, &pt); pt.x += pData->nHscrollPos; pt.y += pData->nVscrollPos; if (FindSelectionCount(pData) > 1) { for (i = 0; i < FindSelectionCount(pData); i++) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); if (PtInRect(&rcSelected, pt)) { hMenu = GetSubMenu(hContextCombineMenu, 0); break; } } } else { /* If we have a selected segment , then display context menu .*/ CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); if (!PtInRect(&rcSelected, pt)) return; hMenu = GetSubMenu(hContextMenu, 0); } // Check if the xPos and yPos not 0xFFFF (coming from Shift + F10) if ((xPos == 0xFFFF) && (yPos == 0xFFFF)) { GetCursorPos(&pt); xPos = pt.x; yPos = pt.y; } TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, hWnd, NULL); } static L_VOID Child_OnSetFocus(HWND hWnd, HWND hwndOldFocus) { LPCHILDDATA pData; POINT pt; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; // Release mouse capture if (pData->bLBDown) { ReleaseCapture(); pData->bLBDown = FALSE; GetCursorPos(&pt); LButtonUp(hWnd, pt.x, pt.y); } } L_INT AllocateSegment(LPCHILDDATA pData, L_INT *pnSegment) { L_VOID *pTemp = NULL; if(NULL == pData) { return ERROR_INV_PARAMETER ; } *pnSegment = pData->nSegments++; if (*pnSegment < 1) { FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); pData->pSegments = (pSEGMENTS) GlobalAllocPtr(GHND,sizeof(SEGMENTS)); pData->pSelSegmentId = (L_INT*) GlobalAllocPtr(GHND,sizeof(L_INT)); RemoveSelectedSegments(pData); } else { pData->pSegments = (pSEGMENTS) GlobalReAllocPtr(pData->pSegments, sizeof(SEGMENTS) * (*pnSegment + 1), GHND); pData->pSelSegmentId = (L_INT*) GlobalReAllocPtr(pData->pSelSegmentId, sizeof(L_INT) * (*pnSegment + 1), GHND); pData->pSelSegmentId[*pnSegment] = -1; } if (!pData->pSegments || !pData->pSelSegmentId) { FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); return ERROR_NO_MEMORY; } return SUCCESS; } L_INT RemoveSegment(LPCHILDDATA pData, HWND hWnd) { L_VOID *pTemp = NULL; if(NULL == pData) { return ERROR_INV_PARAMETER ; } pData->nSegments--; if (pData->nSegments > 0) { pData->pSegments = (pSEGMENTS)GlobalReAllocPtr(pData->pSegments, sizeof(SEGMENTS) * pData->nSegments, GHND); pData->pSelSegmentId = (L_INT*)GlobalReAllocPtr(pData->pSelSegmentId, sizeof(L_INT) * pData->nSegments, GHND); if (!pData->pSegments || !pData->pSelSegmentId) { FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); return ERROR_NO_MEMORY; } } else { FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); } InvalidateRect(hWnd, NULL, TRUE); return SUCCESS; } static L_VOID Child_OnKeyDown(HWND hWnd, UINT vk, L_BOOL fDown, L_INT cRepeat, UINT flags) { L_INT i, nRet = SUCCESS; LPCHILDDATA pData; RECT rcSelected; short uShiftPressed; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if ((cRepeat == 1)) { switch(vk) { case VK_ESCAPE: // Cancel SetCursor(LoadCursor(NULL, IDC_WAIT)); if (pData->bLBDown && pData->bDrawSegment) // Escape while drawing pData->bManual = FALSE; else if (pData->bLBDown && pData->bMouseMove && !pData->bDrawSegment) // draging segment { ClearSegments(hWnd); L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); break; } else pData->bDrawSegment = FALSE; // remove selection for (i = 0; i < FindSelectionCount(pData); i++) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); InvalidateRect(hWnd, &rcSelected, TRUE); } RemoveSelectedSegments(pData); InvalidateRect(hWnd, NULL, TRUE); SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case VK_TAB: SetCursor(LoadCursor(NULL, IDC_WAIT)); uShiftPressed = GetAsyncKeyState(VK_SHIFT); if (pData->pSelSegmentId && FindSelectionCount(pData) == 0) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSelected, 50, 50); InvalidateRect(hWnd, &rcSelected, FALSE); // Select the first item if (uShiftPressed & 0x8000) pData->pSelSegmentId[0] = pData->nSegments - 1; else pData->pSelSegmentId[0] = 0; CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSelected, 50, 50); InvalidateRect(hWnd, &rcSelected, TRUE); UpdateWindow(hWnd); } else if (FindSelectionCount(pData) == 1) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSelected, 50, 50); InvalidateRect(hWnd, &rcSelected, FALSE); if (uShiftPressed & 0x8000) pData->pSelSegmentId[0]--; else pData->pSelSegmentId[0]++; if (pData->pSelSegmentId[0] >= pData->nSegments) pData->pSelSegmentId[0] = 0; else if (pData->pSelSegmentId[0] < 0) pData->pSelSegmentId[0] = pData->nSegments - 1; CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSelected, 50, 50); InvalidateRect(hWnd, &rcSelected, TRUE); UpdateWindow(hWnd); } SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case VK_SUBTRACT: // Zoom out SetCursor(LoadCursor(NULL, IDC_WAIT)); pData->bFitToWindow = FALSE; pData->fZoomVal -= 10; if (pData->fZoomVal < 10) { pData->fZoomVal = 10; } ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case VK_ADD: // Zoom in SetCursor(LoadCursor(NULL, IDC_WAIT)); pData->bFitToWindow = FALSE; pData->fZoomVal += 10; if (pData->fZoomVal > 500) { pData->fZoomVal = 500; } ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case VK_DELETE: // Delete a segment SetCursor(LoadCursor(NULL, IDC_WAIT)); DeleteSegment(hWnd); SetCursor(LoadCursor(NULL, IDC_ARROW)); break; default: break; } } } L_VOID UndoSegmentation(HWND hWnd, LPCHILDDATA pData) { if (pData->hPrevSegment) { StopSegmentation(&pData->hSegment); L_MrcCopySegmentationHandle(&pData->hSegment, pData->hPrevSegment); StopSegmentation(&pData->hPrevSegment); RefreshSegments(hWnd, pData, NULL); InvalidateRect(hWnd, NULL, TRUE); } } L_VOID SelectAllSegments(HWND hWnd) { L_INT i; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (!pData->pSelSegmentId) return; for (i = 0; i < pData->nSegments; i++) { pData->pSelSegmentId[i] = i; } InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } L_VOID DeleteSegment(HWND hWnd) { L_INT i, nCount, nRet = SUCCESS; LPCHILDDATA pData; RECT rcDeleted; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; nCount = FindSelectionCount(pData); if (nCount < 1) return; // Before update the segment, take a copy for undo //if (pData->hSegment) { if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); } for (i = 0; i < nCount; i++) { nRet = L_MrcDeleteSegment(pData->hSegment, pData->pSegments[pData->pSelSegmentId[i]].nSegId); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Error deleting segment."), TEXT("Error"), MB_OK); } CopyRect(&rcDeleted, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcDeleted); OffsetRect(&rcDeleted, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcDeleted, 50, 50); InvalidateRect(hWnd, &rcDeleted, TRUE); pData->pSelSegmentId[0] = -1; } RefreshSegments(hWnd, pData, NULL); /*if (pData->nSegments == 0) StopSegmentation(&pData->hSegment);*/ } static L_BOOL Child_OnSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg) { LPCHILDDATA pData; HWND hActiveWnd; HCURSOR hCursor; RECT Rect, rcClient; RECT rcSelectedLeft, rcSelectedRight; RECT rcSelectedUp, rcSelectedDown; RECT rcSelectedLT, rcSelectedRT; RECT rcSelectedLB, rcSelectedRB; L_INT i, x1, y1, x2, y2; POINT pt; hActiveWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); if (hActiveWnd != hWnd) return (FORWARD_WM_SETCURSOR(hWnd, hwndCursor, codeHitTest, msg, DefWindowProc)); pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return TRUE; // If right mouse is clicked then , change cursor into arrow if (pData->nLineSel == RESIZE_CONTEXTMNEU) { pData->nLineSel = RESIZE_NOTHING; return (FORWARD_WM_SETCURSOR(hWnd, hwndCursor, codeHitTest, msg, DefWindowProc)); } // Find the client area GetClientRect(hWnd, &rcClient); GetCursorPos(&pt); // Find the cursor position ScreenToClient(hWnd, &pt); // Check if the cursor position is out of window if ((rcClient.left > pt.x) || (rcClient.top > pt.y) || (rcClient.right < pt.x) || (rcClient.bottom < pt.y)) return (FORWARD_WM_SETCURSOR(hWnd, hwndCursor, codeHitTest, msg, DefWindowProc)); // Are we drawing ? pData->bMouseMove = FALSE; if (pData->bDrawSegment) { SetCursor(LoadCursor(NULL, IDC_CROSS)); return TRUE; } // Check if the there is a segment selected or the manual process is active if (FindSelectionCount(pData) == 0) { // Set the defualt cursor hCursor = LoadCursor(NULL, IDC_ARROW); if (hCursor) SetCursor(hCursor); return (FORWARD_WM_SETCURSOR(hWnd, hwndCursor, codeHitTest, msg, DefWindowProc)); } if (!pData->bDrawSegment) { for (i = 0; i < FindSelectionCount(pData); i++) { // Save the selected info segment CopyRect(&Rect, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &Rect); // Get the selection rectangles position // Find the Top selection rect x1 = (Rect.right + Rect.left) / 2 - 3 - pData->nHscrollPos; y1 = Rect.top - 3 - pData->nVscrollPos; x2 = (Rect.right + Rect.left) / 2 + 3 - pData->nHscrollPos; y2 = Rect.top + 3 - pData->nVscrollPos; SetRect(&rcSelectedUp, x1, y1, x2, y2); // Find the Bottom selection rect x1 = (Rect.right + Rect.left) / 2 - 3 - pData->nHscrollPos; y1 = Rect.bottom - 3 - pData->nVscrollPos; x2 = (Rect.right + Rect.left) / 2 + 3 - pData->nHscrollPos; y2 = Rect.bottom + 3 - pData->nVscrollPos; SetRect(&rcSelectedDown, x1, y1, x2, y2); // Find the Left selection rect x1 = Rect.left - 3 - pData->nHscrollPos; y1 = (Rect.top + Rect.bottom) / 2 - 3 - pData->nVscrollPos; x2 = Rect.left + 3 - pData->nHscrollPos; y2 = (Rect.top + Rect.bottom) / 2 + 3 - pData->nVscrollPos; SetRect(&rcSelectedLeft, x1, y1, x2, y2); // Find the Right selection rect x1 = Rect.right - 3 - pData->nHscrollPos; y1 = (Rect.top + Rect.bottom) / 2 - 3 - pData->nVscrollPos; x2 = Rect.right + 3 - pData->nHscrollPos; y2 = (Rect.top + Rect.bottom) / 2 + 3 - pData->nVscrollPos; SetRect(&rcSelectedRight, x1, y1, x2, y2); // Find the Left-Top selection rect x1 = Rect.left - 3 - pData->nHscrollPos; y1 = Rect.top - 3 - pData->nVscrollPos; x2 = Rect.left + 3 - pData->nHscrollPos; y2 = Rect.top + 3 - pData->nVscrollPos; SetRect(&rcSelectedLT, x1, y1, x2, y2); // Find the Right-Top selection rect x1 = Rect.right - 3 - pData->nHscrollPos; y1 = Rect.top - 3 - pData->nVscrollPos; x2 = Rect.right + 3 - pData->nHscrollPos; y2 = Rect.top + 3 - pData->nVscrollPos; SetRect(&rcSelectedRT, x1, y1, x2, y2); // Find the Left-Bottom selection rect x1 = Rect.left - 3 - pData->nHscrollPos; y1 = Rect.bottom - 3 - pData->nVscrollPos; x2 = Rect.left + 3 - pData->nHscrollPos; y2 = Rect.bottom + 3 - pData->nVscrollPos; SetRect(&rcSelectedLB, x1, y1, x2, y2); // Find the Right-Bottom selection rect x1 = Rect.right - 3 - pData->nHscrollPos; y1 = Rect.bottom - 3 - pData->nVscrollPos; x2 = Rect.right + 3 - pData->nHscrollPos; y2 = Rect.bottom + 3 - pData->nVscrollPos; SetRect(&rcSelectedRB, x1, y1, x2, y2); // Over which selected rect is the cursor ? if (PtInRect(&rcSelectedUp, pt) || PtInRect(&rcSelectedDown, pt)) { hCursor = LoadCursor(NULL, IDC_SIZENS); if (hCursor) SetCursor(hCursor); pData->bMouseMove = TRUE; return TRUE; } else if (PtInRect(&rcSelectedLeft, pt) || PtInRect(&rcSelectedRight, pt)) { hCursor = LoadCursor(NULL, IDC_SIZEWE); if (hCursor) SetCursor(hCursor); pData->bMouseMove = TRUE; return TRUE; } else if (PtInRect(&rcSelectedLT, pt) || PtInRect(&rcSelectedRB, pt)) { hCursor = LoadCursor(NULL, IDC_SIZENWSE); if (hCursor) SetCursor(hCursor); pData->bMouseMove = TRUE; return TRUE; } else if (PtInRect(&rcSelectedRT, pt) || PtInRect(&rcSelectedLB, pt)) { hCursor = LoadCursor(NULL, IDC_SIZENESW); if (hCursor) SetCursor(hCursor); pData->bMouseMove = TRUE; return TRUE; } else { OffsetRect(&Rect, -pData->nHscrollPos, -pData->nVscrollPos); if (PtInRect(&Rect, pt)) { hCursor = LoadCursor(NULL, IDC_SIZEALL); if (hCursor) SetCursor(hCursor); pData->bMouseMove = TRUE; return TRUE; } else { // Set the default cursor hCursor = LoadCursor(NULL, IDC_ARROW); if (hCursor) SetCursor(hCursor); } } } } return (FORWARD_WM_SETCURSOR(hWnd, hwndCursor, codeHitTest, msg, DefWindowProc)); } L_VOID DrawSelectedLines(HWND hWnd, RECT* pRect) { HDC hDC = GetDC(hWnd); L_INT x1, y1, x2, y2; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData || !hDC) return; // Draw the selection rectangles x1 = (pRect->right + pRect->left) / 2 - 3 -pData->nHscrollPos; y1 = pRect->top - 3 -pData->nVscrollPos; x2 = (pRect->right + pRect->left) / 2 + 3 -pData->nHscrollPos; y2 = pRect->top + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = (pRect->right + pRect->left) / 2 - 3 -pData->nHscrollPos; y1 = pRect->bottom - 3 -pData->nVscrollPos; x2 = (pRect->right + pRect->left) / 2 + 3 -pData->nHscrollPos; y2 = pRect->bottom + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->left - 3 -pData->nHscrollPos; y1 = (pRect->top + pRect->bottom) / 2 - 3 -pData->nVscrollPos; x2 = pRect->left + 3 -pData->nHscrollPos; y2 = (pRect->top + pRect->bottom) / 2 + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->right - 3 -pData->nHscrollPos; y1 = (pRect->top + pRect->bottom) / 2 - 3 -pData->nVscrollPos; x2 = pRect->right + 3 -pData->nHscrollPos; y2 = (pRect->top + pRect->bottom) / 2 + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->left - 3 -pData->nHscrollPos; y1 = pRect->top - 3 -pData->nVscrollPos; x2 = pRect->left + 3 -pData->nHscrollPos; y2 = pRect->top + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->right - 3 -pData->nHscrollPos; y1 = pRect->top - 3 -pData->nVscrollPos; x2 = pRect->right + 3 -pData->nHscrollPos; y2 = pRect->top + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->left - 3 -pData->nHscrollPos; y1 = pRect->bottom - 3 -pData->nVscrollPos; x2 = pRect->left + 3 -pData->nHscrollPos; y2 = pRect->bottom + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); x1 = pRect->right - 3 -pData->nHscrollPos; y1 = pRect->bottom - 3 -pData->nVscrollPos; x2 = pRect->right + 3 -pData->nHscrollPos; y2 = pRect->bottom + 3 -pData->nVscrollPos; Rectangle(hDC, x1, y1, x2, y2); ReleaseDC(hWnd, hDC); } L_VOID DrawManualSegmentRect(HWND hWnd, POINT ptStart, POINT ptEnd, L_INT nMode) { HDC hDC; HPEN hPen, hOldPen; HBRUSH hBrush, hOldBrush; L_INT nOldMode; hDC = GetDC(hWnd); if (!hDC) return; hPen = CreatePen(PS_SOLID, 1, RGB(255,0,0)); hBrush = GetStockBrush(NULL_BRUSH); if (!hPen || !hBrush) { DELETEDCOBJECT(); ReleaseDC(hWnd, hDC); return; } hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, hBrush); nOldMode = SetROP2(hDC, nMode); Rectangle(hDC, ptStart.x, ptStart.y, ptEnd.x, ptEnd.y); RESTOREDCOBJECT(hDC); DELETEDCOBJECT(); ReleaseDC(hWnd, hDC); } static L_VOID Child_OnMouseMove (HWND hWnd, L_INT x, L_INT y, UINT keyFlags) { LPCHILDDATA pData; L_INT x1 ,y1, x2, y2, nActX, nActY; RECT rc; RECT Rect, *pRect; L_FLOAT fFactor; L_BOOL bEnum = FALSE; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (!pData->bLBDown) return; if (pData->bManual) { if (pData->bDrawSegment) // Are we drawing a segment { DrawManualSegmentRect(hWnd, pData->ptManualStart, pData->ptManualEnd, R2_NOTXORPEN); pData->ptManualEnd.x = min(x, pData->rcView.right); pData->ptManualEnd.y = min(y, pData->rcView.bottom); DrawManualSegmentRect(hWnd, pData->ptManualStart, pData->ptManualEnd, R2_NOTXORPEN); return; } } // Are we resizing a segment? if (FindSelectionCount(pData) != 1) return; if ((pData->bMouseMove) && (FindSelectionCount(pData) > 0)) { if (x >= pData->rcView.right) x = pData->rcView.right; if (y >= pData->rcView.bottom) y = pData->rcView.bottom; if (x <= 0) x = 0; if (y <= 0) y = 0; fFactor = (L_FLOAT)(pData->fZoomVal / 100.0f); x += pData->nHscrollPos; y += pData->nVscrollPos; nActX = min((L_INT)(ceil((L_FLOAT)x / fFactor)), pData->Bitmap.Width); nActY = min((L_INT)(ceil((L_FLOAT)y / fFactor)), pData->Bitmap.Height); // Find the segment rect CopyRect(&Rect, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &Rect); pData->bUpdateSegment = TRUE; switch(pData->nLineSel) { case RESIZE_TOP: // top if (y > Rect.bottom) { bEnum = TRUE; break; } x1 = Rect.left; y1 = min(Rect.top, y); x2 = Rect.right; y2 = Rect.bottom; SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.top = nActY; break; case RESIZE_BOTTOM: // down if (y < Rect.top) { bEnum = TRUE; break; } x1 = Rect.left; y1 = Rect.top; x2 = Rect.right; y2 = max(Rect.bottom , y); SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.bottom = nActY; break; case RESIZE_LEFT: // left if (x > Rect.right) { bEnum = TRUE; break; } x1 = min(Rect.left, x); y1 = Rect.top; x2 = Rect.right; y2 = Rect.bottom; SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.left = nActX; break; case RESIZE_RIGHT: // right if (x < Rect.left) { bEnum = TRUE; break; } x1 = Rect.left; y1 = Rect.top; x2 = max(Rect.right, x); y2 = Rect.bottom; SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.right = nActX; break; case RESIZE_LEFT_TOP: // left - top if ((x > Rect.right) || (y > Rect.bottom)) { bEnum = TRUE; break; } x1 = min(Rect.left, x); y1 = min(Rect.top, y); x2 = Rect.right; y2 = Rect.bottom; SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.left = nActX; pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.top = nActY; break; case RESIZE_RIGHT_TOP: // right - top if ((x < Rect.left) || (y > Rect.bottom)) { bEnum = TRUE; break; } x1 = Rect.left; y1 = min(Rect.top, y); x2 = max(Rect.right, x); y2 = Rect.bottom; SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.right = nActX; pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.top = nActY; break; case RESIZE_LEFT_BOTTOM: // left - bottom if ((x > Rect.right) || (y < Rect.top)) { bEnum = TRUE; break; } x1 = min(Rect.left, x); y1 = Rect.top; x2 = Rect.right; y2 = max(Rect.bottom, y); SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.left = nActX; pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.bottom = nActY; break; case RESIZE_RIGHT_BOTTOM: // right - bottom if ((x < Rect.left) || (y < Rect.top)) { bEnum = TRUE; break; } x1 = Rect.left; y1 = Rect.top; x2 = max(Rect.right, x); y2 = max(Rect.bottom, y); SetRect(&rc, x1, y1, x2, y2); pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.right = nActX; pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg.bottom = nActY; break; case RESIZE_SEGMENT: CopyRect(&rc, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); x -= pData->nHscrollPos; y -= pData->nVscrollPos; nActX = (L_INT)(x / fFactor); nActY = (L_INT)(y / fFactor); rc.right -= (pData->ptClickMove.x - nActX); rc.left -= (pData->ptClickMove.x - nActX); rc.bottom -= (pData->ptClickMove.y - nActY); rc.top -= (pData->ptClickMove.y - nActY); if ((rc.right > pData->Bitmap.Width) || (rc.bottom > pData->Bitmap.Height) || (rc.left < 0) || (rc.top < 0)) { if (rc.right > pData->Bitmap.Width) { rc.left -= (rc.right - pData->Bitmap.Width); rc.right = pData->Bitmap.Width; } else if (rc.left < 0) { rc.right -= rc.left; rc.left = 0; } if (rc.bottom > pData->Bitmap.Height) { rc.top -= (rc.bottom - pData->Bitmap.Height); rc.bottom = pData->Bitmap.Height; } else if (rc.top < 0) { rc.bottom -= rc.top; rc.top = 0; } } pData->ptClickMove.x = nActX; pData->ptClickMove.y = nActY; CopyRect(&pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg, &rc); ChangeToZoom(hWnd, &rc); InflateRect(&rc, 4, 4); InvalidateRect(hWnd, &rc, TRUE); CopyRect(&rc, &Rect); break; default: pData->bUpdateSegment = FALSE; return; } pRect = &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg; ChangeToImage(hWnd, &Rect); CheckRectCoordinates(pData->nLineSel, pRect, pData->bManual, pData->bManual ? &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg : NULL, 0, pData->Bitmap.Height, &Rect); rc.left = max(0, rc.left - pData->nHscrollPos); rc.top = max(0, rc.top - pData->nVscrollPos); rc.right = min(rc.right - pData->nHscrollPos, pData->rcView.right); rc.bottom = min(rc.bottom - pData->nVscrollPos, pData->rcView.bottom); InflateRect(&rc, 4, 4); if ((rc.left < 0) || (rc.top < 0) || (rc.right > pData->rcView.right) || (rc.bottom > pData->rcView.bottom)) InvalidateRect(hWnd, &rc, TRUE); else InvalidateRect(hWnd, &rc, FALSE); UpdateWindow(hWnd); } } static L_VOID Child_OnRButtonDown (HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, UINT keyFlags) { LPCHILDDATA pData; POINT pt; RECT SegRect; L_INT i, nCount; HWND hActiveWnd; hActiveWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); if (hActiveWnd != hWnd) return; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (pData->bLBDown) return; pt.x = x + pData->nHscrollPos; pt.y = y + pData->nVscrollPos; // Check if there is a selected segment nCount = FindSelectionCount(pData); for (i = 0; i < nCount; i++) { CopyRect(&SegRect, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &SegRect); if (PtInRect(&SegRect, pt)) return; } UnSelectSegments(hWnd, pData); UpdateWindow(hWnd); } static L_VOID Child_OnLButtonDown(HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, UINT keyFlags) { LPCHILDDATA pData; RECT rcSeg; POINT pt; L_FLOAT fFactor; short uCtrlPressed; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if ((x >= -3) && (x < pData->rcView.right + 3) && (y >= -3) && (y < pData->rcView.bottom + 3)) pData->bLBDown = TRUE; pData->bUpdateSegment = FALSE; fFactor = pData->fZoomVal / 100.0f; pData->ptClickMove.x = (L_INT)(x / fFactor); pData->ptClickMove.y = (L_INT)(y / fFactor); // Are we drawing a segment? if (pData->bDrawSegment) { pData->bManual = TRUE; SetCapture(hWnd); pData->ptManualStart.x = x ; pData->ptManualStart.y = y; pData->ptManualEnd.x = x; pData->ptManualEnd.y = y; if (FindSelectionCount(pData)) UnSelectCurrentSegment(hWnd, pData, x, y); return; } // Find the segment that will be selected if (!pData->bMouseMove) { SelectSegments(hWnd, pData, x, y); } else { // Check if the Ctrl pressed uCtrlPressed = GetAsyncKeyState(VK_CONTROL); if (uCtrlPressed & 0x8000) { if (FindSelectionCount(pData) < 1) return; UnSelectCurrentSegment(hWnd, pData, x, y); return; } if (FindSelectionCount(pData) != 1) return; SetCapture(hWnd); pt.x = x + pData->nHscrollPos; pt.y = y + pData->nVscrollPos; pData->nLineSel = RESIZE_NOTHING; CopyRect(&rcSeg, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); // Find the selection line FindSelectionLine(hWnd, &rcSeg, pt); } } L_VOID UnSelectCurrentSegment(HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y) { POINT pt; RECT rcSelected; L_INT i, nCount; SetCapture(hWnd); pt.x = x + pData->nHscrollPos; pt.y = y + pData->nVscrollPos; nCount = FindSelectionCount(pData); for (i = 0; i < nCount; i++) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); if (PtInRect(&rcSelected, pt)) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); pData->pSelSegmentId[i] = -1; ShiftSegmentID(pData, i, nCount); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); InvalidateRect(hWnd, &rcSelected, TRUE); break; } } } L_VOID ShiftSegmentID(LPCHILDDATA pData, L_INT nIndex, L_INT nCount) { L_INT i; for (i = nIndex; i < nCount - 1; i++) pData->pSelSegmentId[i] = pData->pSelSegmentId[i + 1]; pData->pSelSegmentId[nCount - 1] = -1; } L_VOID FindSelectionLine(HWND hWnd, RECT* pRect, POINT pt) { LPCHILDDATA pData; RECT rcSelected; L_INT x1, x2, y1, y2; L_BOOL bFind = FALSE; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; // Find the selection rect line // top x1 = (pRect->right + pRect->left) / 2; y1 = pRect->top; x2 = (pRect->right + pRect->left) / 2; y2 = pRect->top; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_TOP; bFind = TRUE; } // bottom x1 = (pRect->right + pRect->left) / 2; y1 = pRect->bottom; x2 = (pRect->right + pRect->left) / 2; y2 = pRect->bottom; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_BOTTOM; bFind = TRUE; } // left x1 = pRect->left; y1 = (pRect->top + pRect->bottom) / 2; x2 = pRect->left; y2 = (pRect->top + pRect->bottom) / 2; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_LEFT; bFind = TRUE; } // right x1 = pRect->right; y1 = (pRect->top + pRect->bottom) / 2; x2 = pRect->right; y2 = (pRect->top + pRect->bottom) / 2; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_RIGHT; bFind = TRUE; } // Left - Top x1 = pRect->left; y1 = pRect->top; x2 = pRect->left; y2 = pRect->top; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_LEFT_TOP; bFind = TRUE; } // Right - Top x1 = pRect->right; y1 = pRect->top; x2 = pRect->right; y2 = pRect->top; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_RIGHT_TOP; bFind = TRUE; } // Left - Bottom x1 = pRect->left; y1 = pRect->bottom; x2 = pRect->left; y2 = pRect->bottom; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_LEFT_BOTTOM; bFind = TRUE; } // Right - bottom x1 = pRect->right; y1 = pRect->bottom; x2 = pRect->right; y2 = pRect->bottom; SetRect(&rcSelected, x1, y1, x2, y2); ChangeToZoom(hWnd, &rcSelected); InflateRect(&rcSelected, 3, 3); if (PtInRect(&rcSelected, pt)) { pData->nLineSel = RESIZE_RIGHT_BOTTOM; bFind = TRUE; } if (!bFind) { ChangeToZoom(hWnd, pRect); if (PtInRect(pRect, pt)) pData->nLineSel = RESIZE_SEGMENT; } InflateRect(pRect, 3, 3); ChangeToImage(hWnd, pRect); } static L_VOID Child_OnLButtonUp(HWND hWnd, L_INT x, L_INT y, UINT keyFlags) { LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (GetCapture() == hWnd) ReleaseCapture(); if (!pData->bLBDown) return; pData->bLBDown = FALSE; LButtonUp(hWnd, x, y); } L_VOID LButtonUp(HWND hWnd, L_INT x, L_INT y) { SEGMENTDATA Segment; LPCHILDDATA pData; L_VOID *pTemp = NULL; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; SET_SIZE(&Segment); /*Are we drawing a Segment ? */ if (pData->bDrawSegment && pData->bManual) { if (DrawManualSegment(hWnd, pData, x, y) == SUCCESS) ManualSegmentation(hWnd); return; } /* Did Auto/Manual segmentation rectangles change? */ if (pData->bMouseMove && pData->hSegment && pData->bUpdateSegment && (FindSelectionCount(pData) == 1)) { UpdateSegments(hWnd, pData, x, y); } // End the moveing pData->bUpdateSegment = TRUE; pData->bMouseMove = FALSE; } static L_BOOL Child_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { LPCHILDDATA pChldData; LPCREATEDATA pCreateData; L_INT nRet; // Allocate memory for window private data pCreateData = (LPCREATEDATA) CHILDCREATELPARAM(lpCreateStruct); pChldData = (LPCHILDDATA) GlobalAllocPtr (GHND, sizeof (CHILDDATA)); if (!pChldData) { MessageBox (hWnd, TEXT("An error occurred while trying to create a child window."), TEXT("ERROR"), MB_OK); return FALSE; } L_InitBitmap(&pChldData->Bitmap, sizeof(BITMAPHANDLE), 0, 0, 0); pChldData->hSegment = NULL; pChldData->hPrevSegment = NULL; pChldData->fZoomVal = 100; pChldData->bFitToWindow = TRUE; pChldData->bManual = FALSE; pChldData->bMouseMove = FALSE; pChldData->bUpdateSegment = FALSE; pChldData->bLBDown = FALSE; pChldData->nLineSel = RESIZE_NOTHING; nRet = L_MrcStartBitmapSegmentation(&pChldData->hSegment, &pChldData->Bitmap, gcrBground, gcrFground);; pChldData->nSegments = 0; pChldData->nVscrollPos = 0; pChldData->nVscrollMax = 0; pChldData->nVscrollStep = 0; pChldData->nHscrollPos = 0; pChldData->nHscrollMax = 0; pChldData->nHscrollStep = 0; pChldData->cxClient = 0; pChldData->cyClient = 0; pChldData->bDrawSegment = FALSE; pChldData->pszTitle = (LPTSTR) GlobalAllocPtr(GHND, ((lstrlen(pCreateData->pszTitle) + 1 )*sizeof(TCHAR)) ); pChldData->hPalette = NULL; pChldData->pSelSegmentId = NULL; if (pChldData->pszTitle) lstrcpy(pChldData->pszTitle, pCreateData->pszTitle); SetRect(&pChldData->rcView, 0, 0, 0, 0); // Save some window handles hwndClient = GetParent(hWnd); hwndFrame = GetParent(hwndClient); L_CopyBitmap(&pChldData->Bitmap, pCreateData->pBitmap,sizeof(BITMAPHANDLE)); L_FreeBitmap(pCreateData->pBitmap); SetWindowLong(hWnd, GWL_USERDATA, (long)pChldData); return TRUE; } L_INT EXT_CALLBACK EnumAutoSegments(HSEGMENTATION hSegment, const pSEGMENTDATA pSegment, L_INT nSegId, L_VOID L_FAR* pUserData) { LPCHILDDATA pData; HWND hWnd; L_INT nSegment; hWnd = (HWND)pUserData; pData = (LPCHILDDATA)GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return SUCCESS; AllocateSegment(pData, &nSegment); // Save the segment info CopyRect(&pData->pSegments[nSegment].SegData.rcBitmapSeg, &pSegment->rcBitmapSeg); pData->pSegments[nSegment].SegData.uType = pSegment->uType; pData->pSegments[nSegment].nSegId = nSegId; return SUCCESS; } L_BOOL ManualSegmentation(HWND hWnd) { LPCHILDDATA pData; L_TCHAR szError[MAX_PATH]; L_INT nRet, nSegment; SEGMENTDATA Segment; SET_SIZE(&Segment); pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return FALSE; // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); /*if (pData->hSegment) StopSegmentation(&pData->hSegment);*/ nRet = L_MrcStartBitmapSegmentation(&pData->hSegment, &pData->Bitmap, gcrBground, gcrFground); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to initialize segmentation process: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return FALSE; } for (nSegment = 0; nSegment < pData->nSegments; nSegment++) { CopyRect(&Segment.rcBitmapSeg, &pData->pSegments[nSegment].SegData.rcBitmapSeg); Segment.uType = pData->pSegments[nSegment].SegData.uType; // Set the new segment nRet = L_MrcCreateNewSegment(pData->hSegment, &pData->Bitmap, &Segment); if (nRet < 0) { wsprintf(szError, TEXT("An error occurred while trying to add a new segment: %d."), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); InvalidateRect(hWnd, NULL, TRUE); RefreshSegments(hWnd, pData, &Segment.rcBitmapSeg); return FALSE; } // Set the Id pData->pSegments[nSegment].nSegId = nRet; } pData->bManual = TRUE; return TRUE; } L_VOID AutoManualSegmentation(HWND hWnd) { LPCHILDDATA pData; L_TCHAR szError[MAX_PATH]; L_INT nRet; SEGMENTEXTOPTIONS SegExt; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (pData->hSegment) { if (!ManualSegmentation(hWnd)) MessageBox(hWnd, TEXT("Manual Segmentation wasn't completed successfully"), TEXT("Error"), MB_OK); } pData->nSegments = 0; FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); RemoveSelectedSegments(pData); SET_SIZE(&pData->Bitmap); if (pData->hSegment && !pData->bManual) { StopSegmentation(&pData->hSegment); nRet = L_MrcStartBitmapSegmentation(&pData->hSegment, &pData->Bitmap, gcrBground, gcrFground); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to initialize the segmentation process: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return; } } else if (!pData->hSegment) { nRet = L_MrcStartBitmapSegmentation(&pData->hSegment, &pData->Bitmap, gcrBground, gcrFground); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to initialize the segmentation process: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return; } } memcpy(&SegExt, &gSegExt, sizeof(SEGMENTEXTOPTIONS)); nRet = L_MrcSegmentBitmapExt(pData->hSegment, &pData->Bitmap, &SegExt); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to segment the bitmap: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); InvalidateRect(hWnd, NULL, TRUE); return; } if (pData->bManual) ClearSegments(hWnd); L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } L_VOID AutoSegmentation(HWND hWnd) { LPCHILDDATA pData; L_TCHAR szError[MAX_PATH]; L_INT nRet; SEGMENTATIONOPTIONS SegOpt; SEGMENTEXTOPTIONS SegExt; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; pData->nSegments = 0; FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); SET_SIZE(&pData->Bitmap); ClearSegments(hWnd); if (pData->hSegment) StopSegmentation(&pData->hSegment); nRet = L_MrcStartBitmapSegmentation(&pData->hSegment, &pData->Bitmap, gcrBground, gcrFground); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to initialize the segmentation process: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return; } memcpy(&SegOpt, &gSegOpt, sizeof(SEGMENTATIONOPTIONS)); memcpy(&SegExt, &gSegExt, sizeof(SEGMENTEXTOPTIONS)); /*if (SegOpt.uCombineFlags == COMBINE_FORCE) { MessageBox(hWnd, TEXT("Invalid combining option; the \"Force\" option cannot be used with auto segmentation. The option will be changed to \"Force Similar\" for this segmentation process"), TEXT("Warning"), MB_OK); SegOpt.uCombineFlags = COMBINE_FORCESIMILAR; }*/ nRet = L_MrcSegmentBitmapExt(pData->hSegment, &pData->Bitmap, &SegExt); if (nRet != SUCCESS) { wsprintf(szError, TEXT("An error occurred while trying to segment the bitmap: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return; } L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } static L_VOID Child_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { HCURSOR hOldCur; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); switch (id) { case IDM_FILE_SAVEMRCLEAD: SaveLeadMRC(hWnd); break; case IDM_FILE_SAVEMRC: SaveMRC(hWnd); break; case IDM_FILE_SAVEPDF: SavePDF(hWnd); break; case IDM_FILE_SAVEAS: SaveBitmap(hWnd); break; case ID_FILE_EXPORTSEGMENTS: ExportSegments(hWnd); break; case ID_FILE_IMPORTSEGMENTS: ImportSegments(hWnd); break; case IDM_EDIT_COPY: L_CopyToClipboard(hWnd, &pData->Bitmap,COPY2CB_EMPTY|COPY2CB_DIB); break; case IDM_UNDO: UndoSegmentation(hWnd, pData); break; case IDM_SELECTALLSEGMENTS: SelectAllSegments(hWnd); break; case IDM_DESELECTALL: SendMessage(hWnd, WM_KEYDOWN, VK_ESCAPE, 1); break; case IDM_DELETESEGMENT: DeleteSegment(hWnd); break; case IDM_AUTOSEGMENTATION: AutoSegmentation(hWnd); break; case IDM_AUTO_MANUAL_SEGMENTATION: AutoManualSegmentation(hWnd); break; case IDM_COLOR_HISTOGRAM: ShowHistogram(hWnd, &pData->Bitmap); break; case IDM_SEGMENTHISTOGRAM: ShowSegmentHistogram(hWnd); break; case IDM_SEGMENTTYPE: ShowSegmentType(hWnd); break; case IDM_OPTIONS: DoDialogBoxParam(IDD_OPTIONS, hWnd, (DLGPROC) OptionsDlgProc, 0); break; case IDM_SHOWSEGMENTTYPE: gbShowSegmentType = !gbShowSegmentType; InvalidateRect(hWnd, NULL, TRUE); break; case IDM_DRAW_SEGMENT: pData->bManual = TRUE; pData->bDrawSegment = TRUE; break; case IDM_DRAW_CANCELRECT: pData->bManual = FALSE; pData->bDrawSegment = FALSE; break; case IDM_COLOR_COLORRES: OpenDilaogColorRes(hWnd); break; case IDM_COLOR_UINQUECOLORS: ShowUniqueColors(hWnd, &pData->Bitmap); break; case IDM_FITTOWINDOW: pData->fZoomVal = 100; pData->bFitToWindow = TRUE; ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); break; case IDM_ZOOMING_NORMAL: pData->fZoomVal = 100; pData->bFitToWindow = FALSE; ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); break; case IDM_ZOMMING_IN: pData->bFitToWindow = FALSE; pData->fZoomVal += 10; if (pData->fZoomVal > 500) { pData->fZoomVal = 500; } ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); break; case IDM_ZOMMING_OUT: pData->bFitToWindow = FALSE; pData->fZoomVal -= 10; if (pData->fZoomVal < 10) { pData->fZoomVal = 10; } ZoomBitmap(hWnd, &pData->rcView, pData->fZoomVal, pData->Bitmap.Width, pData->Bitmap.Height); break; case IDM_SEGMENTUNIQUECOLORS: ShowSegmentUniqueColors(hWnd); break; case IDM_ENLARGESEGMENT: EnlargeSegment(hWnd); break; case IDM_SHOWINNEWWINDOW: ShowSegmentInNewWindow(hWnd); break; case IDM_SHOWSEGPROP: if (FindSelectionCount(pData) != 1) return; DoDialogBoxParam(IDD_SEGMENT_INFO, hWnd, (DLGPROC) SegmentInfoProc, 0); InvalidateRect(hWnd, NULL, TRUE); break; case IDM_CLEAR_SEGMENTS: ClearSegments(hWnd); if (pData->hSegment) { // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); StopSegmentation(&pData->hSegment); } InvalidateRect(hWnd, NULL, TRUE); break; case IDM_COMBINESEGMENTS: { CombineSegments(hWnd, pData); } break; case IDM_FILE_SAVEALL: DoDialogBoxParam(IDD_DIALOG_SAVELIST, hWnd, (DLGPROC) SaveMultiDialogProc, 0); break; } SetCursor(hOldCur); return; } L_VOID ZoomBitmap(HWND hWnd, RECT* pRect, L_FLOAT fZoomVal, L_INT nWidth, L_INT nHeight) { L_FLOAT fFactor; RECT rcClient; fFactor = fZoomVal / 100.0f; pRect->right = (L_INT)(nWidth * fFactor); pRect->bottom = (L_INT)(nHeight * fFactor); GetClientRect(hWnd, &rcClient); SendMessage(hWnd, WM_SETCURSOR, 0, 0); Child_OnSize(hWnd, (IsIconic(hWnd) ? SIZEICONIC : (IsZoomed(hWnd) ? SIZEFULLSCREEN : SIZENORMAL)), RCWIDTH (&rcClient), RCHEIGHT (&rcClient)); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } static L_VOID Child_OnSize (HWND hWnd, UINT nState, L_INT nCx, L_INT nCy) { static L_BOOL fSizeInUse = FALSE; L_INT nWidth, nHeight, nVScroll, nHScroll; DWORD dwStyle; L_FLOAT fZoomFactor; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (!fSizeInUse) { fSizeInUse = TRUE; if (!IsIconic(hWnd)) // if window is normal { if (!pData->Bitmap.Flags.Allocated || pData->bFitToWindow) { /* if bitmap is not allocated then set width and height to ZERO */ nWidth = 0; nHeight = 0; } else // if bitmap is allocated, then set the width and height to bitmap width and height { fZoomFactor = ((L_FLOAT)pData->fZoomVal / 100.0f); nWidth = (L_INT)(BITMAPWIDTH(&pData->Bitmap) * fZoomFactor); nHeight= (L_INT)(BITMAPHEIGHT(&pData->Bitmap) * fZoomFactor); } // Set client dimensions to current width and height pData->cxClient = nCx; pData->cyClient = nCy; dwStyle = GetWindowLong (hWnd, GWL_STYLE); nVScroll = GetSystemMetrics (SM_CXVSCROLL); // Get Vertical scroll arrow width nHScroll = GetSystemMetrics (SM_CXHSCROLL); // Get Horizontal scroll arrow width if (WS_VSCROLL & dwStyle) // if Vertical scroll pData->cxClient += nVScroll; if (WS_HSCROLL & dwStyle) // if Horizontal scroll pData->cyClient += nHScroll; if (pData->cxClient < nWidth) // if client width < current width { pData->cyClient -= nHScroll; if (pData->cyClient < nHeight) pData->cxClient -= nVScroll; } else if (pData->cyClient < nHeight) // if client height < current height { pData->cxClient -= nVScroll; if (pData->cxClient < nWidth) pData->cyClient -= nHScroll; } pData->nVscrollStep = max (1, pData->cyClient / SCROLL_RATIO); pData->nVscrollMax = max(0, (nHeight - pData->cyClient - 1)); pData->nVscrollPos = max (0, min (pData->nVscrollPos, pData->nVscrollMax)); pData->nHscrollStep = max (1, pData->cxClient / SCROLL_RATIO); pData->nHscrollMax = max (0, (nWidth - pData->cxClient - 1)); pData->nHscrollPos = max (0, min (pData->nHscrollPos, pData->nHscrollMax)); if (pData->Bitmap.Flags.Allocated) { if (pData->bFitToWindow) { L_INT cxRect, cyRect, nWidth, nHeight; SetRect (&pData->rcView, 0, 0, pData->cxClient, pData->cyClient); nWidth = BITMAPWIDTH(&pData->Bitmap); nHeight = BITMAPHEIGHT(&pData->Bitmap); cyRect = RCHEIGHT(&pData->rcView); cxRect = MulDiv(cyRect, nWidth, nHeight); if(cxRect > RCWIDTH(&pData->rcView)) { cxRect = RCWIDTH(&pData->rcView); cyRect = MulDiv(cxRect, nHeight, nWidth); } pData->rcView.bottom = pData->rcView.top + cyRect; pData->rcView.right = pData->rcView.left + cxRect; pData->fZoomVal = (L_FLOAT)((((L_FLOAT)RCWIDTH(&pData->rcView) / (L_FLOAT)pData->Bitmap.Width) * 100.0)/* + 0.5*/); } else { SetRect (&pData->rcView, 0, 0, nWidth, nHeight); OffsetRect (&pData->rcView, -pData->nHscrollPos, -pData->nVscrollPos); } } SetScrollRange (hWnd, SB_HORZ, 0, pData->nHscrollMax, TRUE); SetScrollPos (hWnd, SB_HORZ, pData->nHscrollPos, TRUE); SetScrollRange (hWnd, SB_VERT, 0, pData->nVscrollMax, TRUE); SetScrollPos (hWnd, SB_VERT, pData->nVscrollPos, TRUE); } else // if window is iconized { // Retain the x-client and y-client area pData->cxClient = nCx; pData->cyClient = nCy; // set client area SetRect (&pData->rcView, 0, 0, pData->cxClient, pData->cyClient); } fSizeInUse = FALSE; } FORWARD_WM_SIZE(hWnd, nState, nCx, nCy, DefMDIChildProc); InvalidateRect(hWnd, NULL, TRUE); } L_VOID ChangeToImage(HWND hWnd, RECT* pRect) { LPCHILDDATA pData; L_FLOAT fFactor; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; fFactor = pData->fZoomVal / 100.0f; pRect->left = (L_INT)(pRect->left / fFactor + 0.5); pRect->top = (L_INT)(pRect->top / fFactor + 0.5); pRect->right = (L_INT)(pRect->right / fFactor + 0.5); pRect->bottom = (L_INT)(pRect->bottom / fFactor + 0.5); } L_VOID ChangeToZoom(HWND hWnd, RECT* pRect) { LPCHILDDATA pData; L_FLOAT fFactor; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; fFactor = pData->fZoomVal / 100.0f; pRect->left = (L_INT)(pRect->left * fFactor + 0.5); pRect->top = (L_INT)(pRect->top * fFactor + 0.5); pRect->right = (L_INT)(pRect->right * fFactor + 0.5); pRect->bottom = (L_INT)(pRect->bottom * fFactor + 0.5); } static L_VOID Child_OnPaint (HWND hWnd) { LPCHILDDATA pChldData; HPALETTE oldPalette; PAINTSTRUCT ps; HBRUSH hBrush, oldBrush; HPEN hSegmentPen, hOldPen; L_INT nSegment, i; RECT rc; BeginPaint (hWnd, &ps); pChldData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pChldData) return; if ((pChldData->Bitmap.Flags.Allocated)) { if ((L_GetDisplayMode() & DISPLAYMODE_RESAMPLE) != DISPLAYMODE_RESAMPLE) L_SetDisplayMode(DISPLAYMODE_RESAMPLE|DISPLAYMODE_BICUBIC, DISPLAYMODE_RESAMPLE); if (pChldData->hPalette) { oldPalette = SelectPalette(ps.hdc, pChldData->hPalette, TRUE); RealizePalette(ps.hdc); } hBrush = GetStockBrush(NULL_BRUSH); hSegmentPen = CreatePen(PS_SOLID, 1,RGB(255,0,0)); L_PaintDC(ps.hdc, &pChldData->Bitmap, NULL, NULL, &pChldData->rcView, &ps.rcPaint, SRCCOPY); if (pChldData->pSegments) { oldBrush = SelectBrush(ps.hdc, hBrush); hOldPen = SelectObject(ps.hdc, hSegmentPen); for(nSegment = 0; nSegment < pChldData->nSegments; nSegment++) { CopyRect(&rc, &pChldData->pSegments[nSegment].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rc); OffsetRect (&rc, -pChldData->nHscrollPos, -pChldData->nVscrollPos); Rectangle(ps.hdc, rc.left, rc.top, rc.right, rc.bottom); if (!IsSegmentSelected(pChldData, nSegment) && gbShowSegmentType) { if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_BACKGROUND) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_BACKGRND, SIZE_TEXT_BACKGRND); if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_ONECOLOR) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_ONECOLOR, SIZE_TEXT_ONECOLOR); if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_TEXT_2BITBW) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_BW, SIZE_TEXT_2BIT_BW); if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_TEXT_1BIT_BW) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_1BIT_BW, SIZE_TEXT_1BIT_BW); else if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_TEXT_1BIT_COLOR) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_1BIT_COLOR, SIZE_TEXT_1BIT_COLOR); else if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_TEXT_2BIT_COLOR) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_COLOR, SIZE_TEXT_2BIT_COLOR); else if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_GRAYSCALE_2BIT) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_GRAYSCALE, SIZE_TEXT_2BIT_GRAYSCALE); else if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_GRAYSCALE_8BIT) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_8BIT_GRAYSCALE, SIZE_TEXT_2BIT_GRAYSCALE); else if (pChldData->pSegments[nSegment].SegData.uType == SEGTYPE_PICTURE) TextOut(ps.hdc, rc.left + 5, rc.top + 5, TEXT_PICTURE, SIZE_TEXT_PICTURE); } } SelectObject(ps.hdc, oldBrush); SelectObject(ps.hdc, hOldPen); } for (i = 0; i < FindSelectionCount(pChldData); i++) { CopyRect(&rc, &pChldData->pSegments[pChldData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rc); DrawSelectedLines(hWnd, &rc); } DeleteObject(hBrush); DeleteObject(hSegmentPen); if (pChldData->hPalette) SelectPalette(ps.hdc, oldPalette, TRUE); } EndPaint (hWnd, &ps); } static L_VOID Child_OnMDIActivate (HWND hWnd, L_BOOL fActive, HWND hWndActivate, HWND hWndDeactivate) { if (fActive) { Child_OnQueryNewPalette(hWnd); SendMessage(hwndClient, WM_MDISETMENU, (WPARAM) hMenuChild, (LPARAM) hMenuChildWindow); } else SendMessage(hwndClient, WM_MDISETMENU, (WPARAM) hMenuInit, (LPARAM) hMenuInitWindow); DrawMenuBar (hwndFrame); } static L_VOID Child_OnClose (HWND hWnd) { FORWARD_WM_CLOSE(hWnd, DefMDIChildProc); } static L_VOID Child_OnDestroy (HWND hWnd) { LPCHILDDATA pChldData; pChldData = (LPCHILDDATA) GetWindowLong (hWnd, GWL_USERDATA); if (pChldData) { // Free Palette if (pChldData->hPalette) DeleteObject (pChldData->hPalette); // Free bitmap if (pChldData->Bitmap.Flags.Allocated) { L_FreeBitmap(&pChldData->Bitmap); L_InitBitmap(&pChldData->Bitmap, sizeof(BITMAPHANDLE),0, 0, 0); } // Free the segmentation handle if (pChldData->hSegment) StopSegmentation(&pChldData->hSegment); if (pChldData->hPrevSegment) StopSegmentation(&pChldData->hPrevSegment); FREEPOINTER(pChldData->pszTitle); // Free segments created by auto segmentation FREEPOINTER(pChldData->pSegments); FREEPOINTER(pChldData->pSelSegmentId); // Free child data FREEPOINTER(pChldData); SetWindowLong (hWnd, GWL_USERDATA, 0); } } static L_VOID Child_OnVScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) { L_INT nScrollInc; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; bInScroll = TRUE; switch (nCode) { case SB_BOTTOM: nScrollInc = pData->nVscrollMax - pData->nVscrollPos; break; case SB_TOP: nScrollInc = -pData->nVscrollPos; break; case SB_LINEDOWN: nScrollInc = pData->nVscrollStep; break; case SB_LINEUP: nScrollInc = -pData->nVscrollStep; break; case SB_PAGEDOWN: nScrollInc = max (pData->nVscrollStep, (pData->cyClient - pData->nVscrollStep)); break; case SB_PAGEUP: nScrollInc = -max (pData->nVscrollStep, (pData->cyClient - pData->nVscrollStep)); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nScrollInc = nPos - pData->nVscrollPos; break; default: nScrollInc = 0; break; } nScrollInc = max (-pData->nVscrollPos, min (nScrollInc, (pData->nVscrollMax - pData->nVscrollPos))); if(nScrollInc) { pData->nVscrollPos += nScrollInc; OffsetRect (&pData->rcView, 0, -nScrollInc); ScrollWindow (hWnd, 0, -nScrollInc, NULL, NULL); SetScrollPos (hWnd, SB_VERT, pData->nVscrollPos, TRUE); UpdateWindow (hWnd); } bInScroll = FALSE; } static L_VOID Child_OnHScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) { L_INT nHScrollInc; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; bInScroll = TRUE; switch (nCode) { case SB_LEFT: nHScrollInc = -pData->nHscrollPos; break; case SB_RIGHT: nHScrollInc = pData->nHscrollMax - pData->nHscrollPos; break; case SB_LINELEFT: nHScrollInc = -pData->nHscrollStep; break; case SB_LINERIGHT: nHScrollInc = pData->nHscrollStep; break; case SB_PAGELEFT: nHScrollInc = -max(pData->nHscrollStep, (pData->cxClient - pData->nHscrollStep)); break; case SB_PAGERIGHT: nHScrollInc = max(pData->nHscrollStep, (pData->cxClient - pData->nHscrollStep)); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nHScrollInc = nPos - pData->nHscrollPos; break; default: nHScrollInc = 0; break; } nHScrollInc = max (-pData->nHscrollPos, min (nHScrollInc, (pData->nHscrollMax - pData->nHscrollPos))); if (nHScrollInc) { pData->nHscrollPos += nHScrollInc; OffsetRect (&pData->rcView, -nHScrollInc, 0); ScrollWindow (hWnd, -nHScrollInc, 0, NULL, NULL); SetScrollPos (hWnd, SB_HORZ, pData->nHscrollPos, TRUE); UpdateWindow (hWnd); } bInScroll = FALSE; } static L_BOOL Child_OnEraseBkgnd (HWND hWnd, HDC hDC) { HGDIOBJ hBrush; HRGN hClientRgn, hFillRgn; RECT rcView, rcClient; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return TRUE; if (IsIconic(GetParent(hWnd))) hBrush = GetStockObject (BLACK_BRUSH); else hBrush = (HBRUSH)GetClassLong(hWnd, GCL_HBRBACKGROUND); GetClientRect (hWnd, &rcClient); GetUpdateRect(hWnd, &rcView,0); if (bInScroll || pData->Bitmap.Flags.Allocated) { IntersectRect (&rcView, &pData->rcView, &rcClient); hClientRgn = CreateRectRgnIndirect (&rcClient); hFillRgn = CreateRectRgnIndirect (&rcView); CombineRgn (hFillRgn, hClientRgn, hFillRgn, RGN_DIFF); FillRgn (hDC, hFillRgn, hBrush); DeleteObject (hFillRgn); DeleteObject (hClientRgn); } else FillRect (hDC, &rcClient, hBrush); return TRUE; } L_INT SaveBitmap(HWND hWnd) { LPCHILDDATA pData; OPENFILENAME SaveFileName; SAVEDLGPARAMS FSParm; L_TCHAR szBuffer[MAX_PATH]; L_INT nRet; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return SUCCESS; memset(&SaveFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); SET_SIZE(&FSParm); FSParm.nQFactor = 2; FSParm.pBitmap = &pData->Bitmap; SaveFileName.lStructSize = sizeof(OPENFILENAME); SaveFileName.lpstrTitle = TEXT("Save As"); SaveFileName.lpstrFileTitle = FSParm.szFileName; SaveFileName.nMaxFileTitle = sizeof(FSParm.szFileName)/sizeof(L_TCHAR); FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_STAMP| DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS| DLG_SAVE_ENABLESIZING| DLG_SAVE_AUTOPROCESS| DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR; nRet = L_DlgSave (hWnd,&SaveFileName,&FSParm); if( nRet <0 ) { memset(szBuffer, 0, sizeof(szBuffer)); wsprintf(szBuffer, TEXT("Cannot save file,\nError code = %d\n"), nRet); MessageBox(hWnd, szBuffer, TEXT("Error!"), MB_OK); } return SUCCESS; } L_INT ValidateValues(HWND hDlg,LPCHILDDATA pData) { if ((gTempSegOpt.uCombineFactor < 0) || (gTempSegOpt.uCombineFactor > 100)) { MessageBox(hDlg, TEXT("Please enter a number between 0 and 100 for the ") TEXT("combining quality factor."), TEXT("Invalid Value"), MB_OK); InitValues(hDlg); return ERROR_INV_PARAMETER; } if ((gnTempQFactor < 2) || (gnTempQFactor > 255)) { if ((gnTempPictureCoder == MRC_PICTURE_COMPRESSION_LOSSLESS_CMW) || (gnTempPictureCoder == MRC_PICTURE_COMPRESSION_LOSSLESS_JPEG)) { gnTempQFactor = 2; return SUCCESS; } else { MessageBox(hDlg, TEXT("Please enter a number between 2 and 255 for the ") TEXT("MRC colored images compression quality factor."), TEXT("Invalid Value"), MB_OK); return ERROR_INV_PARAMETER; } } if ((gnTempPdfQFactor < 0) || (gnTempPdfQFactor > 255)) { if (gnTempPictureCoder > 5) { gnTempPdfQFactor = 2; return SUCCESS; } else { MessageBox(hDlg, TEXT("Please enter a number between 0 and 255 for the ") TEXT("PDF colored images compression quality factor."), TEXT("Invalid Value"), MB_OK); return ERROR_INV_PARAMETER; } } if ((gnTempGSQFactor < 2) || (gnTempGSQFactor > 255)) { if ((gnTempGrayscaleCoder8Bit == MRC_GRAYSCALE_COMPRESSION_LOSSLESS_CMW_8BIT) || (gnTempGrayscaleCoder8Bit == MRC_GRAYSCALE_COMPRESSION_LOSSLESS_JPEG_8BIT)) { gnTempGSQFactor = 2; return SUCCESS; } else { MessageBox(hDlg, TEXT("Please enter a number between 2 and 255 for the ") TEXT("grayscale images compression quality factor."), TEXT("Invalid Value"), MB_OK); return ERROR_INV_PARAMETER; } } return SUCCESS; } L_VOID DisplayCurrentTabPage(HWND hDlg) { L_INT nTab; RECT rcTab; POINT ptPoint; HWND hTabWnd = GetDlgItem(hDlg, IDC_TAB); nTab = TabCtrl_GetCurSel(hTabWnd); ShowWindow(hPage[nTab], SW_SHOW); GetWindowRect(hTabWnd, &rcTab); ptPoint.x = rcTab.left; ptPoint.y = rcTab.top; ScreenToClient(hDlg, &ptPoint); rcTab.left = ptPoint.x; rcTab.top = ptPoint.y; ptPoint.x = rcTab.right; ptPoint.y = rcTab.bottom; ScreenToClient(hDlg, &ptPoint); rcTab.right = ptPoint.x; rcTab.bottom = ptPoint.y; MoveWindow(hPage[nTab], rcTab.left + 5, rcTab.top + 25, RCWIDTH(&rcTab) - 20, RCHEIGHT(&rcTab) - 30, TRUE); } L_BOOL CALLBACK OptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LPCHILDDATA pData; HWND hWnd; int nTab; LPNMHDR lpnmhdr; hWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); pData = (LPCHILDDATA)GetWindowLong(hWnd , GWL_USERDATA); if (!pData) return FALSE; switch (message) { case WM_NOTIFY: { lpnmhdr = (LPNMHDR) lParam; if (lpnmhdr && (lpnmhdr->code == TCN_SELCHANGE)) { HWND hTabWnd = GetDlgItem(hDlg, IDC_TAB); for (nTab = 0; nTab < 5; nTab++) ShowWindow(hPage[nTab], SW_HIDE); DisplayCurrentTabPage(hDlg); } } break; case WM_INITDIALOG: OnInitOptionDialog(hDlg); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: if(ValidateValues(hDlg,pData)!= SUCCESS) return TRUE; gSegOpt = gTempSegOpt; gSegExt = gTempSegExt; gnQFactor = gnTempQFactor; gnGSQFactor = gnTempGSQFactor; gnMaskCoder = gnTempMaskCoder; gnPictureCoder = gnTempPictureCoder; gnTextCoder2Bit = gnTempTextCoder2Bit; gnGrayscale8BitCoder = gnTempGrayscaleCoder8Bit; gnGrayscale2BitCoder = gnTempGrayscaleCoder2Bit; gnPdfTextCoder2Bit = gnTempPdfTextCoder2Bit; gnPdfPictureCoder = gnTempPdfPictureCoder; gnPdfMaskCoder = gnTempPdfMaskCoder; gnPdfQFactor = gnTempPdfQFactor; gcrBground = gcrTempBground; gcrFground = gcrTempFground; for (nTab = 0; nTab < 5; nTab++) DestroyWindow(hPage[nTab]); EndDialog (hDlg, 0); return TRUE; case IDCANCEL: for (nTab = 0; nTab < 5; nTab++) DestroyWindow(hPage[nTab]); EndDialog (hDlg, 0); return TRUE; } } return FALSE; } L_VOID OnInitOptionDialog(HWND hWnd) { HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB); TCITEM Item; int i; gTempSegOpt = gSegOpt; gnTempQFactor = gnQFactor; gnTempGSQFactor = gnGSQFactor; gnTempMaskCoder = gnMaskCoder; gnTempPictureCoder = gnPictureCoder; gnTempTextCoder2Bit = gnTextCoder2Bit; gnTempGrayscaleCoder8Bit = gnGrayscale8BitCoder; gnTempGrayscaleCoder2Bit = gnGrayscale2BitCoder; gcrTempBground = gcrBground; gcrTempFground = gcrFground; memset(&Item, 0, sizeof(Item)); Item.mask = TCIF_TEXT; Item.pszText = TEXT("MRC Compressions"); Item.cchTextMax = lstrlen(TEXT("Mrc Compressions")); Item.iImage = -1; i = TabCtrl_InsertItem(hTabWnd, 0, &Item); memset(&Item, 0, sizeof(Item)); Item.mask = TCIF_TEXT; Item.pszText = TEXT("PDF Compressions"); Item.cchTextMax = lstrlen(TEXT("Pdf Compressions")); Item.iImage = -1; i = TabCtrl_InsertItem(hTabWnd, 1, &Item); memset(&Item, 0, sizeof(Item)); Item.mask = TCIF_TEXT; Item.pszText = TEXT("Segmentation"); Item.cchTextMax = lstrlen(TEXT("Segmentation")); Item.iImage = -1; TabCtrl_InsertItem(hTabWnd, 2, &Item); memset(&Item, 0, sizeof(Item)); Item.mask = TCIF_TEXT; Item.pszText = TEXT("Combine"); Item.cchTextMax = lstrlen(TEXT("Combine")); Item.iImage = -1; TabCtrl_InsertItem(hTabWnd, 3, &Item); memset(&Item, 0, sizeof(Item)); Item.mask = TCIF_TEXT; Item.pszText = TEXT("Colors"); Item.cchTextMax = lstrlen(TEXT("Colors")); Item.iImage = -1; TabCtrl_InsertItem(hTabWnd, 4, &Item); CreateDialog(hInstMain, MAKEINTRESOURCE(IDD_DIALOG_MRCCOMPRESS), hWnd, CompressionDialogProc); CreateDialog(hInstMain, MAKEINTRESOURCE(IDD_DIALOG_PDFCOMPRESS), hWnd, PdfCompressionDialogProc); CreateDialog(hInstMain, MAKEINTRESOURCE(IDD_DIALOG_SEGMENTATION), hWnd, SegmentationExtDialogProc); CreateDialog(hInstMain, MAKEINTRESOURCE(IDD_DIALOG_COMBINE), hWnd, AutoSegmentationDialogProc); CreateDialog(hInstMain, MAKEINTRESOURCE(IDD_DIALOG_COLORS), hWnd, ColorsDialogProc); ShowWindow(hPage[0], SW_SHOW); DisplayCurrentTabPage(hWnd); } /////////////////////// PdfCompression Page Functions ///////////////////////////////////////////////////////////// L_VOID PdfChangeQFactorStatus(HWND hWnd) { L_INT nCoder; nCoder = SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_GETCURSEL, 0, 0); if (nCoder > 5) EnableWindow(GetDlgItem(hWnd, IDC_PDF_QFACTOR), FALSE); else EnableWindow(GetDlgItem(hWnd, IDC_PDF_QFACTOR), TRUE); } L_VOID PdfCompressionDialogCommand(HWND hWnd, UINT uID, UINT uMsg) { BOOL bTrans; switch (uID) { case IDC_PDF_MASKCODER: if (uMsg == CBN_SELCHANGE) gnTempPdfMaskCoder = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); break; case IDC_PDF_TEXT2BITCODER: if (uMsg == CBN_SELCHANGE) gnTempPdfTextCoder2Bit = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); break; case IDC_PDF_PICTURECODER: if (uMsg == CBN_SELCHANGE) { gnTempPdfPictureCoder = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); PdfChangeQFactorStatus(hWnd); } break; case IDC_PDF_QFACTOR: if (uMsg == EN_CHANGE) gnTempPdfQFactor = GetDlgItemInt(hWnd, uID, &bTrans, FALSE); break; } } L_VOID PdfUpdateCompressionPage(HWND hWnd) { gnTempPdfQFactor = gnPdfQFactor; gnTempPdfPictureCoder = gnPdfPictureCoder; // Mask compression types SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("ZIP 1-bit")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("LZW 1-bit")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G3(1D)")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G3(2D)")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G4")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JBIG2")); // Picture compression types SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG YUV 4:2:2")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG YUV 4:1:1")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive YUV 4:2:2")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive YUV 4:1:1")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("ZIP")); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("LZW")); // Text 2 bit Colored compression types SendDlgItemMessage(hWnd, IDC_PDF_TEXT2BITCODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_PDF_TEXT2BITCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("ZIP 2-bit")); SendDlgItemMessage(hWnd, IDC_PDF_TEXT2BITCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("LZW 2-bit")); SendDlgItemMessage(hWnd, IDC_PDF_MASKCODER, CB_SETCURSEL, gnTempPdfMaskCoder, 0); SendDlgItemMessage(hWnd, IDC_PDF_PICTURECODER, CB_SETCURSEL, gnTempPdfPictureCoder, 0); SendDlgItemMessage(hWnd, IDC_PDF_TEXT2BITCODER, CB_SETCURSEL, gnTempPdfTextCoder2Bit, 0); SetDlgItemInt(hWnd, IDC_PDF_QFACTOR, gnTempPdfQFactor, FALSE); SNDMSG(GetDlgItem(hWnd, IDC_PDF_QFACTOR), EM_LIMITTEXT, 3, 0); PdfChangeQFactorStatus(hWnd); } LRESULT CALLBACK PdfCompressionDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { hPage[1] = hwnd; //LPPSHNOTIFY lppsn; switch (message) { case WM_INITDIALOG: PdfUpdateCompressionPage(hwnd); return TRUE; case WM_COMMAND: PdfCompressionDialogCommand(hwnd, LOWORD(wParam), HIWORD(wParam)); break; } return FALSE; } /////////////////////// Compression Page Functions ///////////////////////////////////////////////////////////// LRESULT CALLBACK CompressionDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { hPage[0] = hwnd; //LPPSHNOTIFY lppsn; switch (message) { case WM_INITDIALOG: UpdateCompressionPage(hwnd); return TRUE; case WM_COMMAND: CompressionDialogCommand(hwnd, LOWORD(wParam), HIWORD(wParam)); break; } return FALSE; } L_VOID CompressionDialogCommand(HWND hWnd, UINT uID, UINT uMsg) { BOOL bTrans; switch (uID) { case IDC_MASKCODER: if (uMsg == CBN_SELCHANGE) gnTempMaskCoder = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); break; case IDC_TEXT2BITCODER: if (uMsg == CBN_SELCHANGE) gnTempTextCoder2Bit = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); break; case IDC_GRAYSCALE2BITCODER: if (uMsg == CBN_SELCHANGE) gnTempGrayscaleCoder2Bit = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); break; case IDC_GRAYSCALECODER: if (uMsg == CBN_SELCHANGE) { gnTempGrayscaleCoder8Bit = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); ChangeQFactorStatus(hWnd); } break; case IDC_PICTURECODER: if (uMsg == CBN_SELCHANGE) { gnTempPictureCoder = SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); ChangeQFactorStatus(hWnd); } break; case IDC_GS_QFACTOR: if (uMsg == EN_CHANGE) gnTempGSQFactor = GetDlgItemInt(hWnd, uID, &bTrans, FALSE); break; case IDC_QFACTOR: if (uMsg == EN_CHANGE) gnTempQFactor = GetDlgItemInt(hWnd, uID, &bTrans, FALSE); break; } } L_VOID UpdateCompressionPage(HWND hWnd) { // Mask compression types SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JBIG")); SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G4")); SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G3(1D)")); SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Fax G3(2D)")); // Picture compression types SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Wavelet CMW")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Lossless Wavelet CMW")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("LEAD CMP")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Lossless JPEG")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG YUV 4:2:2")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG YUV 4:1:1")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive YUV 4:2:2")); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("JPEG Progressive YUV 4:1:1")); // Text 2 bit Colored compression types SendDlgItemMessage(hWnd, IDC_TEXT2BITCODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_TEXT2BITCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Text JBIG 2-bit")); SendDlgItemMessage(hWnd, IDC_TEXT2BITCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Text GIF 2-bit")); // Grayscale 2 bit compression types SendDlgItemMessage(hWnd, IDC_GRAYSCALE2BITCODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_GRAYSCALE2BITCODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale JBIG 2-bit")); // Grayscale 8 bit compression types SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Lossless CMW 8-bit")); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale CMW 8-bit")); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale CMP 8-bit")); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Lossless JPEG 8-bit")); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale JPEG 8-bit")); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale JPEG Progressive 8-bit")); SendDlgItemMessage(hWnd, IDC_MASKCODER, CB_SETCURSEL, gnTempMaskCoder, 0); SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_SETCURSEL, gnTempPictureCoder, 0); SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_SETCURSEL, gnTempGrayscaleCoder8Bit, 0); SendDlgItemMessage(hWnd, IDC_GRAYSCALE2BITCODER, CB_SETCURSEL, gnTempGrayscaleCoder2Bit, 0); SendDlgItemMessage(hWnd, IDC_TEXT2BITCODER, CB_SETCURSEL, gnTempTextCoder2Bit, 0); SetDlgItemInt(hWnd, IDC_QFACTOR, gnTempQFactor, FALSE); SNDMSG(GetDlgItem(hWnd, IDC_QFACTOR), EM_LIMITTEXT, 3, 0); SetDlgItemInt(hWnd, IDC_GS_QFACTOR, gnTempGSQFactor, FALSE); SNDMSG(GetDlgItem(hWnd, IDC_GS_QFACTOR), EM_LIMITTEXT, 3, 0); ChangeQFactorStatus(hWnd); } L_VOID ChangeQFactorStatus(HWND hWnd) { L_INT nCoder; nCoder = SendDlgItemMessage(hWnd, IDC_PICTURECODER, CB_GETCURSEL, 0, 0); if ((nCoder == MRC_PICTURE_COMPRESSION_LOSSLESS_CMW) || (nCoder == MRC_PICTURE_COMPRESSION_LOSSLESS_JPEG)) EnableWindow(GetDlgItem(hWnd, IDC_QFACTOR), FALSE); else EnableWindow(GetDlgItem(hWnd, IDC_QFACTOR), TRUE); nCoder = SendDlgItemMessage(hWnd, IDC_GRAYSCALECODER, CB_GETCURSEL, 0, 0); if ((nCoder == MRC_GRAYSCALE_COMPRESSION_LOSSLESS_CMW_8BIT) || (nCoder == MRC_GRAYSCALE_COMPRESSION_LOSSLESS_JPEG_8BIT)) EnableWindow(GetDlgItem(hWnd, IDC_GS_QFACTOR), FALSE); else EnableWindow(GetDlgItem(hWnd, IDC_GS_QFACTOR), TRUE); } /////////////////////////////////////// AutoSegmentation Page Functions /////////////////////////////////////////////// LRESULT CALLBACK AutoSegmentationDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { hPage[3] = hwnd; switch (message) { case WM_INITDIALOG: UpdateAutoSegmentationPage(hwnd); return TRUE; case WM_HSCROLL: HandleSlider(hwnd, (HWND)lParam, LOWORD(wParam)); break; case WM_COMMAND: AutoSegmentationDialogCommand(hwnd, LOWORD(wParam), HIWORD(wParam)); break; } return FALSE; } L_VOID HandleSlider(HWND hParent, HWND hWnd, int nCode) { HWND hSlider = GetDlgItem(hParent, IDC_SLIDER_SENSITIVITY); switch(nCode) { case TB_PAGEDOWN: case TB_PAGEUP: case TB_ENDTRACK: case TB_THUMBTRACK: gbChange = TRUE; gTempSegOpt.uCombineFactor = Trackbar_GetPos(hWnd); SetDlgItemInt(hParent, IDC_COMBINEFACTOR, gTempSegOpt.uCombineFactor, FALSE); gbChange = FALSE; break; default: return; } } L_VOID AutoSegmentationDialogCommand(HWND hWnd, UINT uID, UINT uMsg) { BOOL bTrans; switch (uID) { case IDC_COMBO_COMBININGTYPE: if (uMsg == CBN_SELCHANGE) { gTempSegOpt.uCombineFlags = (L_UINT16)SendDlgItemMessage(hWnd, uID, CB_GETCURSEL, 0, 0); } break; case IDC_COMBINEFACTOR: if ((uMsg == EN_CHANGE) && !gbChange) { gTempSegOpt.uCombineFactor = GetDlgItemInt(hWnd, uID, &bTrans, FALSE); if (gTempSegOpt.uCombineFactor > 100) { gbChange = TRUE; gTempSegOpt.uCombineFactor = 100; SetDlgItemInt(hWnd, uID, gTempSegOpt.uCombineFactor, FALSE); gbChange = FALSE; } else if (gTempSegOpt.uCombineFactor <= 0) { gbChange = TRUE; gTempSegOpt.uCombineFactor = 0; SetDlgItemInt(hWnd, uID, gTempSegOpt.uCombineFactor, FALSE); gbChange = FALSE; } Trackbar_SetPos(GetDlgItem(hWnd, IDC_SLIDER_COMBINE), TRUE, gTempSegOpt.uCombineFactor); } break; } } L_VOID UpdateCombineFactorStatus(HWND hWnd, L_BOOL bEnable) { EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_COMBINE), bEnable); EnableWindow(GetDlgItem(hWnd, IDC_COMBINEFACTOR), bEnable); } void UpdateAutoSegmentationPage(HWND hWnd) { HWND hSlider; gbChange = FALSE; hSlider = GetDlgItem(hWnd, IDC_SLIDER_SENSITIVITY); Trackbar_SetRange(hSlider, TRUE, 1, 100); Trackbar_SetPageSize(hSlider, 10); hSlider = GetDlgItem(hWnd, IDC_SLIDER_COMBINE); Trackbar_SetRange(hSlider, TRUE, 0, 100); Trackbar_SetPageSize(hSlider, 10); Trackbar_SetPos(hSlider, TRUE, gTempSegOpt.uCombineFactor); InitValues(hWnd); } L_VOID InitValues(HWND hDlg) { SetDlgItemInt(hDlg, IDC_COMBINEFACTOR, gTempSegOpt.uCombineFactor, FALSE); SendDlgItemMessage(hDlg, IDC_COMBO_COMBININGTYPE, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hDlg, IDC_COMBO_COMBININGTYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Force")); SendDlgItemMessage(hDlg, IDC_COMBO_COMBININGTYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Force Similar")); SendDlgItemMessage(hDlg, IDC_COMBO_COMBININGTYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Try")); SendDlgItemMessage(hDlg, IDC_COMBO_COMBININGTYPE, CB_SETCURSEL, gTempSegOpt.uCombineFlags, 0); } /////////////////////////////// Colors Page Functions /////////////////////////////////////////////////////// LRESULT CALLBACK ColorsDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT ps; HBRUSH hBrush; RECT rcBtn; HWND hWndBtn; POINT pt; L_INT nWidth, nHeight; hPage[4] = hwnd; switch (message) { case WM_INITDIALOG: return TRUE; case WM_PAINT: hDC = BeginPaint(hwnd, &ps); hWndBtn = GetDlgItem(hwnd, IDC_BGCOLOR); GetWindowRect(hWndBtn, &rcBtn); nWidth = rcBtn.right - rcBtn.left; nHeight = rcBtn.bottom - rcBtn.top; pt.x = rcBtn.left; pt.y = rcBtn.top; ScreenToClient(hwnd, &pt); rcBtn.left = pt.x; rcBtn.top = pt.y; rcBtn.right = rcBtn.left + nWidth; rcBtn.bottom = rcBtn.top + nHeight; hBrush = CreateSolidBrush(gcrTempBground); SelectObject(hDC, hBrush); Rectangle(hDC, rcBtn.left, rcBtn.top, rcBtn.right, rcBtn.bottom); DeleteObject(hBrush); hWndBtn = GetDlgItem(hwnd, IDC_FGCOLOR); GetWindowRect(hWndBtn, &rcBtn); nWidth = rcBtn.right - rcBtn.left; nHeight = rcBtn.bottom - rcBtn.top; pt.x = rcBtn.left; pt.y = rcBtn.top; ScreenToClient(hwnd, &pt); rcBtn.left = pt.x; rcBtn.top = pt.y; rcBtn.right = rcBtn.left + nWidth; rcBtn.bottom = rcBtn.top + nHeight; hBrush = CreateSolidBrush(gcrTempFground); SelectObject(hDC, hBrush); Rectangle(hDC, rcBtn.left, rcBtn.top, rcBtn.right, rcBtn.bottom); DeleteObject(hBrush); EndPaint(hwnd, &ps); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BTNBGCOLOR: ShowColorDialog(hwnd, &gcrTempBground); hWndBtn = GetDlgItem(hwnd, IDC_BGCOLOR); GetWindowRect(hWndBtn, &rcBtn); nWidth = rcBtn.right - rcBtn.left; nHeight = rcBtn.bottom - rcBtn.top; pt.x = rcBtn.left; pt.y = rcBtn.top; ScreenToClient(hwnd, &pt); rcBtn.left = pt.x; rcBtn.top = pt.y; rcBtn.right = rcBtn.left + nWidth; rcBtn.bottom = rcBtn.top + nHeight; InvalidateRect(hwnd, &rcBtn, TRUE); break; case IDC_BTNFGCOLOR: ShowColorDialog(hwnd, &gcrTempFground); hWndBtn = GetDlgItem(hwnd, IDC_FGCOLOR); GetWindowRect(hWndBtn, &rcBtn); nWidth = rcBtn.right - rcBtn.left; nHeight = rcBtn.bottom - rcBtn.top; pt.x = rcBtn.left; pt.y = rcBtn.top; ScreenToClient(hwnd, &pt); rcBtn.left = pt.x; rcBtn.top = pt.y; rcBtn.right = rcBtn.left + nWidth; rcBtn.bottom = rcBtn.top + nHeight; InvalidateRect(hwnd, &rcBtn, TRUE); break; } } return FALSE; } /////////////////////////////////////////////////////////////////////////////////////////////////// L_BOOL CALLBACK SegmentInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LPCHILDDATA pData; HWND hWnd, hCntWnd; RECT *prcSelected, rcTemp; L_UINT uType; L_TCHAR szInfo[256]; L_INT nLeft, nTop, nRight, nBottom; SEGMENTDATA Segment; L_INT nRet = SUCCESS, nStart, nEnd; hWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); pData = (LPCHILDDATA)GetWindowLong(hWnd , GWL_USERDATA); if (!pData) return FALSE; SET_SIZE(&Segment); switch (message) { case WM_INITDIALOG: memset(szInfo, 0, 256); if (FindSelectionCount(pData) > 1) return FALSE; prcSelected = &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg; uType = pData->pSegments[pData->pSelSegmentId[0]].SegData.uType; wsprintf(szInfo, TEXT("%d"), prcSelected->left); hCntWnd = GetDlgItem(hDlg, IDC_LEFT); SetWindowText(hCntWnd, szInfo); memset(szInfo, 0, 256); wsprintf(szInfo, TEXT("%d"), prcSelected->top); hCntWnd = GetDlgItem(hDlg, IDC_TOP); SetWindowText(hCntWnd, szInfo); memset(szInfo, 0, 256); wsprintf(szInfo, TEXT("%d"), prcSelected->right); hCntWnd = GetDlgItem(hDlg, IDC_RIGHT); SetWindowText(hCntWnd, szInfo); memset(szInfo, 0, 256); wsprintf(szInfo, TEXT("%d"), prcSelected->bottom); hCntWnd = GetDlgItem(hDlg, IDC_BOTTOM); SetWindowText(hCntWnd, szInfo); memset(szInfo, 0, 256); if (uType == SEGTYPE_BACKGROUND) lstrcpy(szInfo, TEXT("Back Ground segment")); else if (uType == SEGTYPE_ONECOLOR) lstrcpy(szInfo, TEXT("One Color segment")); else if (uType == SEGTYPE_TEXT_1BIT_BW) lstrcpy(szInfo, TEXT("Text segment 1-Bit(B & W)")); else if (uType == SEGTYPE_TEXT_1BIT_COLOR) lstrcpy(szInfo, TEXT("Text segment 1-Bit(Colored)")); else if (uType == SEGTYPE_TEXT_2BITBW) lstrcpy(szInfo, TEXT("Text segment 2-Bit(B & W)")); else if (uType == SEGTYPE_TEXT_2BIT_COLOR) lstrcpy(szInfo, TEXT("Text segment 2-Bit(Colored)")); else if (uType == SEGTYPE_GRAYSCALE_2BIT) lstrcpy(szInfo, TEXT("Grayscale 2-Bit segment")); else if (uType == SEGTYPE_GRAYSCALE_8BIT) lstrcpy(szInfo, TEXT("Grayscale 8-Bit segment")); else lstrcpy(szInfo, TEXT("Picture segment")); hCntWnd = GetDlgItem(hDlg, IDC_SEGTYPE); SetWindowText(hCntWnd, szInfo); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: prcSelected = &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg; uType = pData->pSegments[pData->pSelSegmentId[0]].SegData.uType; nStart = 0; nEnd = pData->Bitmap.Height; hCntWnd = GetDlgItem(hDlg, IDC_LEFT); GetWindowText(hCntWnd, szInfo, 256); nLeft = _ttoi(szInfo); if (nLeft < 0) { MessageBox(hDlg, TEXT("Invalid x-coordinate of the rectangle's upper-left corner"), TEXT("Error"), MB_OK); break; } hCntWnd = GetDlgItem(hDlg, IDC_TOP); GetWindowText(hCntWnd, szInfo, 256); nTop = _ttoi(szInfo); if (pData->bManual) { if (nTop < nStart) nTop = nStart; } if (nTop < 0) { MessageBox(hDlg, TEXT("Invalid y-coordinate of the rectangle's upper-left corner"), TEXT("Error"), MB_OK); break; } hCntWnd = GetDlgItem(hDlg, IDC_RIGHT); GetWindowText(hCntWnd, szInfo, 256); nRight = _ttoi(szInfo); if (nRight > pData->Bitmap.Width) { MessageBox(hDlg, TEXT("Invalid x-coordinate of the rectangle's lower-right corner"), TEXT("Error"), MB_OK); break; } hCntWnd = GetDlgItem(hDlg, IDC_BOTTOM); GetWindowText(hCntWnd, szInfo, 256); nBottom = _ttoi(szInfo); if (pData->bManual) { if (nBottom > nEnd) nBottom = nEnd; } if (nBottom > pData->Bitmap.Height) { MessageBox(hDlg, TEXT("Invalid y-coordinate of the rectangle's lower-right corner."), TEXT("Error"), MB_OK); break; } if ((nRight - nLeft) < 2) { MessageBox(hDlg, TEXT("Invalid rectangle width."), TEXT("Error"), MB_OK); break; } if ((nBottom - nTop) < 2) { MessageBox(hDlg, TEXT("Invalid rectangle height."), TEXT("Error"), MB_OK); break; } CopyRect(&rcTemp, prcSelected); prcSelected->left = nLeft; prcSelected->top = nTop; prcSelected->right = nRight; prcSelected->bottom = nBottom; NormalizeRect(prcSelected); CopyRect(&Segment.rcBitmapSeg, prcSelected); Segment.uType = uType; // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); nRet = L_MrcSetSegmentData(pData->hSegment, &pData->Bitmap, pData->pSegments[pData->pSelSegmentId[0]].nSegId, &Segment); if (nRet != SUCCESS) { CopyRect(prcSelected, &rcTemp); MessageBox(hDlg, TEXT("Could not update segment."), TEXT("Error"), MB_OK); InvalidateRect(hWnd, NULL, TRUE); EndDialog (hDlg, 0); } else { ChangeToZoom(hWnd, &rcTemp); InflateRect(&rcTemp, 3, 3); InvalidateRect(hWnd, &rcTemp, TRUE); } RefreshSegments(hWnd, pData, &Segment.rcBitmapSeg); EndDialog(hDlg, 0); return TRUE; case IDCANCEL: EndDialog(hDlg, 0); return TRUE; } } return(FALSE); } L_BOOL CALLBACK SegmentTypeProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LPCHILDDATA pData; HWND hWnd; SEGMENTDATA Segment; L_INT nRet; static L_BOOL bDrawSegment; hWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); pData = (LPCHILDDATA)GetWindowLong(hWnd , GWL_USERDATA); if (!pData) return FALSE; SET_SIZE(&Segment); switch (message) { case WM_INITDIALOG: bDrawSegment = (L_BOOL)lParam; SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Text 1-Bit(B & W)")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Text 1-Bit(Colored)")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Text 2-Bit(Colored)")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale 2-Bit")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Grayscale 8-Bit")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Picture 24-Bit")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Back Ground segment")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("One Color segment")); SendDlgItemMessage(hDlg, IDC_TYPE, CB_ADDSTRING, 0, (LPARAM)TEXT("Text segment 2-Bit(B & W)")); if (FindSelectionCount(pData) > 0) SendDlgItemMessage(hDlg, IDC_TYPE, CB_SETCURSEL, pData->pSegments[pData->pSelSegmentId[0]].SegData.uType - 1, 0); else SendDlgItemMessage(hDlg, IDC_TYPE, CB_SETCURSEL, 0, 0); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: pData->pSegments[pData->pSelSegmentId[0]].SegData.uType = SendDlgItemMessage(hDlg, IDC_TYPE, CB_GETCURSEL, 0, 0) + 1; if (pData->hSegment) { // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); } if (!bDrawSegment) { CopyRect(&Segment.rcBitmapSeg, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); Segment.uType = pData->pSegments[pData->pSelSegmentId[0]].SegData.uType; nRet = L_MrcSetSegmentData(pData->hSegment, &pData->Bitmap, pData->pSegments[pData->pSelSegmentId[0]].nSegId, &Segment); if (nRet != SUCCESS) { MessageBox(hDlg, TEXT("Could not update segment."), TEXT("Error"), MB_OK); InvalidateRect(hWnd, NULL, TRUE); EndDialog (hDlg, 0); } RefreshSegments(hWnd, pData, &Segment.rcBitmapSeg); } EndDialog (hDlg, IDOK); return(TRUE); case IDCANCEL: EndDialog (hDlg, IDCANCEL); return(TRUE); } } return(FALSE); } L_VOID OpenDilaogColorRes(HWND hWnd) { COLORRESDLGPARAMS DlgParams; L_INT nRet; LPCHILDDATA pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; memset(&DlgParams,0,sizeof(COLORRESDLGPARAMS)); SET_SIZE(&DlgParams); DlgParams.pBitmap = &pData->Bitmap ; DlgParams.nBitsPerPixel = pData->Bitmap.BitsPerPixel ; DlgParams.uColorResFlags = CRF_SLOWMATCH; DlgParams.uDlgFlags = DLG_COLORRES_SHOW_PREVIEW| DLG_COLORRES_SHOW_ORDER | DLG_COLORRES_SHOW_TOOL_ZOOMLEVEL | DLG_COLORRES_SHOW_OPENPALFILE ; DlgParams.uDlgFlagsEx = DLG_COLORRES_SHOW_BITALL | DLG_COLORRES_SHOW_DITHER_ALL | DLG_COLORRES_SHOW_PAL_ALL ; nRet = L_DlgColorRes ( hWnd, &DlgParams ) ; if( nRet == SUCCESS_DLG_OK ) { nRet = L_ColorResBitmap(&pData->Bitmap, &pData->Bitmap,sizeof(BITMAPHANDLE), DlgParams.nBitsPerPixel, DlgParams.uColorResFlags, NULL, DlgParams.hpalCustom, 0, NULL, NULL); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Error changing the color resolution"), TEXT("ERROR"), MB_OK); return; } FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); } } L_VOID NormalizeRect(RECT* pRect) { L_INT nTemp; if (pRect->left > pRect->right) { nTemp = pRect->left; pRect->left = pRect->right; pRect->right = nTemp; } if (pRect->top > pRect->bottom) { nTemp = pRect->top; pRect->top = pRect->bottom; pRect->bottom = nTemp; } } L_VOID CheckRectCoordinates(L_INT nLineSel, RECT* pRect, L_BOOL bManual, RECT* pManualSeg, L_INT nStartRow, L_INT nEndRow, RECT* pOldManualRect) { // We do not want segments less than 10X10 switch(nLineSel) { case RESIZE_TOP: // Top if ((pRect->bottom - pRect->top) < 10) pRect->top = pRect->bottom - 10; break; case RESIZE_BOTTOM:// Down if ((pRect->bottom - pRect->top) < 10) pRect->bottom = pRect->top + 10; break; case RESIZE_LEFT: // left if ((pRect->right - pRect->left) < 10) pRect->left = pRect->right - 10; break; case RESIZE_RIGHT: // right if ((pRect->right - pRect->left) < 10) pRect->right = pRect->left + 10; break; case RESIZE_LEFT_TOP: // left - top if ((pRect->right - pRect->left) < 10) pRect->left = pRect->right - 10; if ((pRect->bottom - pRect->top) < 10) pRect->top = pRect->bottom - 10; case RESIZE_RIGHT_TOP: // right - top if ((pRect->bottom - pRect->top) < 10) pRect->top = pRect->bottom - 10; if ((pRect->right - pRect->left) < 10) pRect->right = pRect->left + 10; break; case RESIZE_LEFT_BOTTOM: // left - bottom if ((pRect->right - pRect->left) < 10) pRect->left = pRect->right - 10; if ((pRect->bottom - pRect->top) < 10) pRect->bottom = pRect->top + 10; break; case RESIZE_RIGHT_BOTTOM: // right - bottom if ((pRect->right - pRect->left) < 10) pRect->right = pRect->left + 10; if ((pRect->bottom - pRect->top) < 10) pRect->bottom = pRect->top + 10; break; } // We are in manual mode? if (bManual) { if ((pRect->top < nStartRow) || (pRect->bottom > nEndRow)) { if (pManualSeg->top < nStartRow) { if (nLineSel == RESIZE_SEGMENT) pManualSeg->bottom += (nStartRow - pManualSeg->top); pManualSeg->top = nStartRow; } else if (pManualSeg->bottom > nEndRow) { if (nLineSel == RESIZE_SEGMENT) pManualSeg->top -= (pManualSeg->bottom - nEndRow); pManualSeg->bottom = nEndRow; } pManualSeg->right = pOldManualRect->right; pManualSeg->left = pOldManualRect->left; } } } L_VOID SetFileNameExt(L_TCHAR L_FAR* pszFileName, L_TCHAR L_FAR* pszExt) { L_INT nStrLen = lstrlen(pszFileName); L_TCHAR L_FAR* pTemp = pszFileName + nStrLen - 4; if (_tcsicmp(pTemp, pszExt) != 0) lstrcat(pszFileName, pszExt); } L_VOID UpdateSaveFileOption(SAVEDLGPARAMS* pFSParm, pSAVEFILEOPTION pSaveOpt) { L_GetDefaultSaveFileOption(pSaveOpt, sizeof(SAVEFILEOPTION)); pSaveOpt->PageNumber = pFSParm->nPageNumber; pSaveOpt->Flags = 0; switch(pFSParm->uSaveMulti) { case MULTIPAGE_OPERATION_REPLACE: pSaveOpt->Flags|=ESO_REPLACEPAGE; break; case MULTIPAGE_OPERATION_INSERT: pSaveOpt->Flags|=ESO_INSERTPAGE; break; case MULTIPAGE_OPERATION_APPEND: pSaveOpt->PageNumber = 2; break; case MULTIPAGE_OPERATION_OVERWRITE: pSaveOpt->PageNumber = 1; break; } pSaveOpt->Passes = pFSParm->nPasses; } L_INT SaveLeadMRC(HWND hWnd) { LPCHILDDATA pData; HCURSOR hOldCur; L_INT nRet; OPENFILENAME OpenFileName; SAVEDLGPARAMS FSParm; L_TCHAR szOpenFileFilter[] = TEXT("ALL\0")TEXT("*.*\0")TEXT("MRC\0")TEXT("*.mrc\0"); L_TCHAR szFileName[MAX_PATH], szError[MAX_PATH]; COMPRESSIONOPTIONS CmpOption; SAVEFILEOPTION SaveOpt; FILESAVEFORMAT Formats[2]; FILESAVEFORMATBPP MrcSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_LEAD_MRC}; FILESAVEFORMATBPP MrcTiffSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_TIFF24_LEAD_MRC}; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_MRC; Formats[0].nBppCount = 1; Formats[0].pFileSaveFormatBpp = MrcSub; SET_SIZE(&Formats[1]); Formats[1].nFormat = DLG_FF_SAVE_TIFF; Formats[1].nBppCount = 1; Formats[1].pFileSaveFormatBpp = MrcTiffSub; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return SUCCESS; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); memset(szFileName, 0, sizeof(szFileName)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_OVERWRITEPROMPT; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.lpstrTitle = TEXT("Save as LEAD MRC"); OpenFileName.nFilterIndex = 0; FSParm.pFileFormats = Formats; FSParm.uFileFormatsCount = 2; SET_SIZE(&FSParm); FSParm.nQFactor = 2; FSParm.nPageNumber = 1; FSParm.uSaveMulti = TRUE; FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR; nRet = L_DlgSave(hWnd, &OpenFileName, &FSParm); if(nRet != SUCCESS_DLG_OK) return nRet; SET_SIZE(&CmpOption); CmpOption.nPictureQFactor = gnQFactor; CmpOption.nMaskCoder = gnMaskCoder; CmpOption.nPictureCoder = gnPictureCoder; CmpOption.nText2BitCoder = gnTextCoder2Bit; switch(gnPictureCoder) { case MRC_PICTURE_COMPRESSION_LOSSLESS_JPEG: CmpOption.nPictureQFactor = 0; break; case MRC_PICTURE_COMPRESSION_LOSSLESS_CMW: CmpOption.nPictureQFactor = 0; break; } CmpOption.nGrayscale2BitCoder = gnGrayscale2BitCoder; CmpOption.nGrayscale8BitCoder = gnGrayscale8BitCoder; CmpOption.nGrayscale8BitFactor = gnGSQFactor; switch(gnGrayscale8BitCoder) { case MRC_GRAYSCALE_COMPRESSION_LOSSLESS_CMW_8BIT: CmpOption.nGrayscale8BitFactor = 0; break; case MRC_GRAYSCALE_COMPRESSION_LOSSLESS_JPEG_8BIT: CmpOption.nGrayscale8BitFactor = 0; break; } hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); SET_SIZE(&pData->Bitmap); // Check for manual segmentation if ((pData->nSegments > 0) && (pData->bManual)) { if (!ManualSegmentation(hWnd)) return FAILURE; } memset(&SaveOpt, 0, sizeof(SAVEFILEOPTION)); SET_SIZE(&SaveOpt); UpdateSaveFileOption(&FSParm, &SaveOpt); nRet = L_MrcSaveBitmap(pData->hSegment, &pData->Bitmap, &CmpOption, FSParm.szFileName, NULL, NULL, FSParm.nFormat, &SaveOpt); SetCursor(hOldCur); if (nRet != SUCCESS) { memset(szError, 0, sizeof(szError)); wsprintf(szError, TEXT("An error occurred while trying to save the bitmap as LEAD MRC: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return nRet; } return nRet; } L_INT SaveMRC(HWND hWnd) { LPCHILDDATA pData; HCURSOR hOldCur; L_INT nRet; OPENFILENAME OpenFileName; SAVEDLGPARAMS FSParm; L_TCHAR szOpenFileFilter[] = TEXT("ALL\0")TEXT("*.*\0")TEXT("MRC\0")TEXT("*.mrc\0"); L_TCHAR szFileName[MAX_PATH], szError[MAX_PATH]; COMPRESSIONOPTIONS CmpOption; SAVEFILEOPTION SaveOpt; FILESAVEFORMAT Formats[2]; FILESAVEFORMATBPP MrcSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_MRC}; FILESAVEFORMATBPP MrcTiffSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_TIFF24_MRC}; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_MRC; Formats[0].nBppCount = 1; Formats[0].pFileSaveFormatBpp = MrcSub; SET_SIZE(&Formats[1]); Formats[1].nFormat = DLG_FF_SAVE_TIFF; Formats[1].nBppCount = 1; Formats[1].pFileSaveFormatBpp = MrcTiffSub; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return SUCCESS; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); memset(szFileName, 0, sizeof(szFileName)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_OVERWRITEPROMPT; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.lpstrTitle = TEXT("Save as MRC"); OpenFileName.nFilterIndex = 0; FSParm.pFileFormats = Formats; FSParm.uFileFormatsCount = 2; SET_SIZE(&FSParm); FSParm.nQFactor = 2; FSParm.nPageNumber = 1; FSParm.uSaveMulti = TRUE; FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR; nRet = L_DlgSave(hWnd, &OpenFileName, &FSParm); if(nRet != SUCCESS_DLG_OK) return nRet; SET_SIZE(&CmpOption); CmpOption.nMaskCoder = gnMaskCoder; CmpOption.nPictureCoder = gnPictureCoder; CmpOption.nPictureQFactor = gnQFactor; if (CmpOption.nPictureCoder != MRC_PICTURE_COMPRESSION_JPEG) { MessageBox(hWnd, TEXT("Invalid picture compression, it will be replaced with \"JPEG compression\"."), TEXT("Warning"), MB_OK); CmpOption.nPictureCoder = MRC_PICTURE_COMPRESSION_JPEG; } hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); SET_SIZE(&pData->Bitmap); SET_SIZE(&CmpOption); // Check for manual segmentation if ((pData->nSegments > 0) && (pData->bManual)) { if (!ManualSegmentation(hWnd)) return FAILURE; } memset(&SaveOpt, 0, sizeof(SAVEFILEOPTION)); SET_SIZE(&SaveOpt); UpdateSaveFileOption(&FSParm, &SaveOpt); nRet = L_MrcSaveBitmapT44(pData->hSegment, &pData->Bitmap, &CmpOption, FSParm.szFileName, NULL, NULL, FSParm.nFormat, &SaveOpt); SetCursor(hOldCur); if (nRet != SUCCESS) { memset(szError, 0, sizeof(szError)); wsprintf(szError, TEXT("An error occurred while trying to save the bitmap as T44 MRC: %d"), nRet); MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return nRet; } return nRet; } L_INT SavePDF(HWND hWnd) { LPCHILDDATA pData; L_INT nRet; OPENFILENAME OpenFileName; SAVEDLGPARAMS FSParm; L_TCHAR szOpenFileFilter[] = TEXT("ALL\0")TEXT("*.*\0")TEXT("PDF\0")TEXT("*.pdf\0"); L_TCHAR szFileName[MAX_PATH]; FILESAVEFORMAT Formats[1]; FILESAVEFORMATBPP MrcSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_PDF1_UNCOMPRESSED}; COMPRESSIONOPTIONS CmpOption; SAVEFILEOPTION SaveOpt; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_PDF; Formats[0].nBppCount = 1; Formats[0].pFileSaveFormatBpp = MrcSub; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return SUCCESS; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); memset(szFileName, 0, sizeof(szFileName)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_OVERWRITEPROMPT; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.lpstrTitle = TEXT("Save as PDF"); OpenFileName.nFilterIndex = 0; FSParm.pFileFormats = Formats; FSParm.uFileFormatsCount = 1; SET_SIZE(&FSParm); FSParm.nQFactor = 2; FSParm.nPageNumber = 1; FSParm.uSaveMulti = TRUE; nRet = L_DlgSave(hWnd, &OpenFileName, &FSParm); if(nRet != SUCCESS_DLG_OK) return nRet; SET_SIZE(&CmpOption); CmpOption.nPictureQFactor = gnPdfQFactor; CmpOption.nMaskCoder = gnPdfMaskCoder + MRC_PDF_ONEBIT_COMPRESSION_ZIP; CmpOption.nPictureCoder = gnPdfPictureCoder + MRC_PDF_PICTURE_COMPRESSION_JPEG; CmpOption.nText2BitCoder = gnPdfTextCoder2Bit + MRC_PDF_TEXT_COMPRESSION_ZIP; memset(&SaveOpt, 0, sizeof(SAVEFILEOPTION)); SET_SIZE(&SaveOpt); UpdateSaveFileOption(&FSParm, &SaveOpt); nRet = L_MrcSaveBitmap(pData->hSegment, &pData->Bitmap, &CmpOption, FSParm.szFileName, NULL, NULL, FILE_PDF_LEAD_MRC, &SaveOpt); return nRet; } L_VOID ExportSegments(HWND hWnd) { LPCHILDDATA pData; HCURSOR hOldCur; L_INT nRet; OPENFILENAME OpenFileName; L_TCHAR szOpenFileFilter[] = TEXT("Segments files\0")TEXT("*.sgm\0"); L_TCHAR szFileName[MAX_PATH]; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(szFileName, 0, MAX_PATH); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_OVERWRITEPROMPT; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.lpstrTitle = TEXT("Export Segments"); OpenFileName.nFilterIndex = 0; if (!GetSaveFileName(&OpenFileName)) return; SetFileNameExt(OpenFileName.lpstrFile, TEXT(".sgm")); hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); nRet = L_MrcSaveSegmentation(pData->hSegment, OpenFileName.lpstrFile); SetCursor(hOldCur); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Error exporting segments."), TEXT("Error"), MB_OK); } } L_VOID ImportSegments(HWND hWnd) { HCURSOR hOldCur; LPCHILDDATA pData; OPENFILENAME OpenFileName; L_TCHAR szOpenFileFilter[] = TEXT("Segments files\0")TEXT("*.sgm\0"); L_TCHAR szFileName[MAX_PATH]; L_INT nRet; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; memset(szFileName, 0, MAX_PATH); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = 1; OpenFileName.lpstrFileTitle = NULL; OpenFileName.nMaxFileTitle = 0; OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Import Segments Files"); OpenFileName.nFileOffset = 0; OpenFileName.nFileExtension = 0; OpenFileName.lpstrDefExt = NULL; OpenFileName.lpfnHook = NULL; if (!GetOpenFileName(&OpenFileName)) return; // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); ClearSegments(hWnd); if (pData->hSegment) StopSegmentation(&pData->hSegment); hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); nRet = L_MrcLoadSegmentation(&pData->hSegment, &pData->Bitmap, OpenFileName.lpstrFile); SetCursor(hOldCur); if (nRet != SUCCESS) { if (pData->hPrevSegment) { L_MrcCopySegmentationHandle(&pData->hSegment, pData->hPrevSegment); StopSegmentation(&pData->hPrevSegment); } MessageBox(hWnd, TEXT("Error importing segments."), TEXT("Error"), MB_OK); } // Enumerate current segments L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); InvalidateRect(hWnd, NULL, TRUE); } static L_VOID Child_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange) { HDC hDC; HPALETTE hOldPalette; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if ((hWnd == hWndPaletteChange)||(hwndClient == hWndPaletteChange)) return; if (pData->Bitmap.Flags.Allocated && pData->hPalette) { hDC = GetDC (hWnd); hOldPalette = SelectPalette (hDC, pData->hPalette, TRUE); RealizePalette (hDC); InvalidateRect (hWnd, 0, FALSE); SelectPalette (hDC, hOldPalette, TRUE); ReleaseDC (hWnd, hDC); } return; } static L_BOOL Child_OnQueryNewPalette (HWND hWnd) { HDC hDC; HPALETTE hOldPalette; L_INT nNoColors = 0; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return 0; if (pData->hPalette) { DeleteObject (pData->hPalette); pData->hPalette = NULL; } if (pData->Bitmap.Flags.Allocated) { hDC = GetDC (hWnd); pData->hPalette = L_CreatePaintPalette (hDC, &pData->Bitmap); if(pData->hPalette) { hOldPalette = SelectPalette (hDC, pData->hPalette, FALSE); nNoColors = RealizePalette (hDC); if (nNoColors) InvalidateRect (hWnd, NULL, FALSE); SelectPalette (hDC, hOldPalette, TRUE); } ReleaseDC (hWnd, hDC); } return(nNoColors); } L_VOID ClearSegments(HWND hWnd) { LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (pData->pSegments || pData->pSelSegmentId) { FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); pData->nSegments = 0; } pData->bManual = FALSE; pData->bMouseMove = FALSE; pData->bLBDown = FALSE; pData->nLineSel = -1; pData->bDrawSegment = FALSE; } L_VOID ShowSegmentHistogram(HWND hWnd) { L_INT nRet; RECT rcSeg; BITMAPHANDLE SegBitmap; LPCHILDDATA pData; L_BOOL bSelected = FALSE; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; L_InitBitmap(&SegBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); if (FindSelectionCount(pData) != 1) return; CopyRect(&rcSeg, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); L_RectToBitmap(&pData->Bitmap, TOP_LEFT, &rcSeg); nRet = L_CopyBitmapRect(&SegBitmap, &pData->Bitmap, sizeof(BITMAPHANDLE), rcSeg.left, rcSeg.top, RCWIDTH(&rcSeg), RCHEIGHT(&rcSeg)); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Can't view segment histogram."), TEXT("Error"), MB_OK); return; } ShowHistogram(hWnd, &SegBitmap); if (SegBitmap.Flags.Allocated) L_FreeBitmap(&SegBitmap); } L_VOID ShowHistogram(HWND hWnd, pBITMAPHANDLE pBitmap) { HISTOGRAMDLGPARAMS DlgParam ; LPCHILDDATA pData; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; memset(&DlgParam, 0, sizeof(HISTOGRAMDLGPARAMS)); SET_SIZE(&DlgParam); DlgParam.pBitmap = pBitmap; DlgParam.crBlueChannelPen = RGB (0, 0, 255); DlgParam.crGreenChannelPen = RGB (0, 255, 0); DlgParam.crRedChannelPen = RGB (255, 0, 0); DlgParam.crMasterPen = RGB (0, 0, 0); DlgParam.uDlgFlags = DLG_HISTOGRAM_SHOW_VIEWSTYLE | DLG_HISTOGRAM_USERPENCOLORS ; L_DlgHistogram(hWnd, &DlgParam); } L_VOID ShowSegmentType(HWND hWnd) { LPCHILDDATA pData; RECT rcSelected; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; SetRect(&rcSelected, 0, 0, 0, 0); if (FindSelectionCount(pData) != 1) return; // Display the segment type dialog for the selected segment CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); if (!IsRectEmpty(&rcSelected)) DoDialogBoxParam(IDD_SEGMENT_TYPE, hWnd, (DLGPROC) SegmentTypeProc, FALSE); } L_VOID EnlargeSegment(HWND hWnd) { LPCHILDDATA pData; SEGMENTDATA Segment; L_INT i, nRet, nLeft, nRight, nTop, nBottom; LPRECT pSelRect, pRect; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; if (FindSelectionCount(pData) != 1) return; nLeft = 0; nRight = pData->Bitmap.Width; nTop = 0; nBottom = pData->Bitmap.Height; pSelRect = &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg; for (i = 0; i < pData->nSegments; i++) { if (i == pData->pSegments[pData->pSelSegmentId[0]].nSegId) continue; pRect = &pData->pSegments[i].SegData.rcBitmapSeg; // Find the left value if (CanEnlargeFromLeft(pRect, pSelRect)) { nLeft = max(nLeft, pRect->right); } } pSelRect->left = nLeft; for (i = 0; i < pData->nSegments; i++) { if (i == pData->pSegments[pData->pSelSegmentId[0]].nSegId) continue; pRect = &pData->pSegments[i].SegData.rcBitmapSeg; // Find the left value if (CanEnlargeFromTop(pRect, pSelRect)) { nTop = max(nTop, pRect->bottom); } } pSelRect->top = nTop; for (i = 0; i < pData->nSegments; i++) { if (i == pData->pSegments[pData->pSelSegmentId[0]].nSegId) continue; pRect = &pData->pSegments[i].SegData.rcBitmapSeg; // Find the left value if (CanEnlargeFromRight(pRect, pSelRect)) { nRight = min(nRight, pRect->left); } } pSelRect->right = nRight; for (i = 0; i < pData->nSegments; i++) { if (i == pData->pSegments[pData->pSelSegmentId[0]].nSegId) continue; pRect = &pData->pSegments[i].SegData.rcBitmapSeg; // Find the left value if (CanEnlargeFromBottom(pRect, pSelRect)) { nBottom = min(nBottom, pRect->top); } } pSelRect->bottom = nBottom; memcpy(&Segment, &pData->pSegments[pData->pSelSegmentId[0]].SegData, sizeof(SEGMENTDATA)); SET_SIZE(&Segment); // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); nRet = L_MrcSetSegmentData(pData->hSegment, &pData->Bitmap, pData->pSegments[pData->pSelSegmentId[0]].nSegId, &Segment); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Could not update segment."), TEXT("Error"), MB_OK); InvalidateRect(hWnd, NULL, TRUE); } // Free any allocated rectangles RefreshSegments(hWnd, pData, &Segment.rcBitmapSeg); InvalidateRect(hWnd, NULL, TRUE); } L_BOOL CanEnlargeFromLeft(LPRECT pLeftRc, LPRECT pSelRect) { if ((pLeftRc->top <= pSelRect->top) && (pLeftRc->bottom > pSelRect->top) && (pLeftRc->bottom < pSelRect->bottom) && (pLeftRc->right <= pSelRect->left)) return TRUE; else if ((pLeftRc->top >= pSelRect->top) && (pLeftRc->top < pSelRect->bottom) && (pLeftRc->bottom > pSelRect->top) && (pLeftRc->bottom <= pSelRect->bottom) && (pLeftRc->right <= pSelRect->left)) return TRUE; else if ((pLeftRc->top > pSelRect->top) && (pLeftRc->top < pSelRect->bottom) && (pLeftRc->bottom >= pSelRect->bottom) && (pLeftRc->right <= pSelRect->left)) return TRUE; else if ((pLeftRc->top <= pSelRect->top) && (pLeftRc->bottom >= pSelRect->bottom) && (pLeftRc->right <= pSelRect->left)) return TRUE; else return FALSE; } L_BOOL CanEnlargeFromTop(LPRECT pTopRc, LPRECT pSelRect) { if ((pTopRc->left <= pSelRect->left) && (pTopRc->right > pSelRect->left) && (pTopRc->right < pSelRect->right) && (pTopRc->bottom <= pSelRect->top)) return TRUE; else if ((pTopRc->left >= pSelRect->left) && (pTopRc->left < pSelRect->right) && (pTopRc->right > pSelRect->left) && (pTopRc->right <= pSelRect->right) && (pTopRc->bottom <= pSelRect->top)) return TRUE; else if ((pTopRc->left > pSelRect->left) && (pTopRc->left < pSelRect->right) && (pTopRc->right >= pSelRect->right) && (pTopRc->bottom < pSelRect->top)) return TRUE; else if ((pTopRc->left <= pSelRect->left) && (pTopRc->right >= pSelRect->right) && (pTopRc->bottom <= pSelRect->top)) return TRUE; else return FALSE; } L_BOOL CanEnlargeFromRight(LPRECT pRightRc, LPRECT pSelRect) { if ((pRightRc->top <= pSelRect->top) && (pRightRc->bottom > pSelRect->top) && (pRightRc->bottom < pSelRect->bottom) && (pRightRc->left >= pSelRect->right)) return TRUE; else if ((pRightRc->top >= pSelRect->top) && (pRightRc->top < pSelRect->bottom) && (pRightRc->bottom > pSelRect->top) && (pRightRc->bottom <= pSelRect->bottom) && (pRightRc->left >= pSelRect->right)) return TRUE; else if ((pRightRc->top > pSelRect->top) && (pRightRc->top < pSelRect->bottom) && (pRightRc->bottom >= pSelRect->bottom) && (pRightRc->left >= pSelRect->right)) return TRUE; else if ((pRightRc->top <= pSelRect->top) && (pRightRc->bottom >= pSelRect->bottom) && (pRightRc->left >= pSelRect->right)) return TRUE; else return FALSE; } L_BOOL CanEnlargeFromBottom(LPRECT pBottomRc, LPRECT pSelRect) { if ((pBottomRc->left <= pSelRect->left) && (pBottomRc->right > pSelRect->left) && (pBottomRc->right < pSelRect->right) && (pBottomRc->top >= pSelRect->bottom)) return TRUE; else if ((pBottomRc->left >= pSelRect->left) && (pBottomRc->left < pSelRect->right) && (pBottomRc->right > pSelRect->left) && (pBottomRc->right <= pSelRect->right) && (pBottomRc->top >= pSelRect->bottom)) return TRUE; else if ((pBottomRc->left > pSelRect->left) && (pBottomRc->left < pSelRect->right) && (pBottomRc->right >= pSelRect->right) && (pBottomRc->top >= pSelRect->bottom)) return TRUE; else if ((pBottomRc->left <= pSelRect->left) && (pBottomRc->right >= pSelRect->right) && (pBottomRc->top >= pSelRect->bottom)) return TRUE; else return FALSE; } L_VOID ShowSegmentInNewWindow(HWND hWnd) { LPCHILDDATA pData; BITMAPHANDLE SegBitmap; RECT rcSeg; L_BOOL bSelected = FALSE; L_UINT uType; L_INT nRet; L_TCHAR szBuffer[256]; static L_INT nSegNo = 0; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; L_InitBitmap(&SegBitmap, sizeof(BITMAPHANDLE),0, 0, 0); // Check if there is a segment selected from the manual process if (FindSelectionCount(pData) != 1) return; CopyRect(&rcSeg, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); uType = pData->pSegments[pData->pSelSegmentId[0]].SegData.uType; L_RectToBitmap(&pData->Bitmap, TOP_LEFT, &rcSeg); nRet = L_CopyBitmapRect(&SegBitmap, &pData->Bitmap, sizeof(BITMAPHANDLE), rcSeg.left, rcSeg.top, RCWIDTH(&rcSeg), RCHEIGHT(&rcSeg)); if (nRet == SUCCESS) { memset(szBuffer, 0, sizeof(szBuffer)); if (uType == SEGTYPE_TEXT_1BIT_BW) wsprintf(szBuffer, TEXT("Text 1-Bit(B & W) Segment: %d"), ++nSegNo); else if (uType == SEGTYPE_TEXT_1BIT_COLOR) wsprintf(szBuffer, TEXT("Text 1-Bit(Colored) Segment: %d"), ++nSegNo); else if (uType == SEGTYPE_TEXT_2BIT_COLOR) wsprintf(szBuffer, TEXT("Text 2-Bit(Colored) Segment: %d"), ++nSegNo); else if (uType == SEGTYPE_GRAYSCALE_2BIT) wsprintf(szBuffer, TEXT("Grayscale 2-Bit Graphic Segment: %d"), ++nSegNo); else if (uType == SEGTYPE_GRAYSCALE_8BIT) wsprintf(szBuffer, TEXT("Grayscale 8-Bit Graphic Segment: %d"), ++nSegNo); else wsprintf(szBuffer, TEXT("Picture Segment: %d"), ++nSegNo); CreateChildWindow(szBuffer, &SegBitmap, FALSE); } else { MessageBox(hWnd, TEXT("An error occurred while trying to copy the bitmap rectangle."), TEXT("Error"), MB_OK); return; } } L_VOID ShowSegmentUniqueColors(HWND hWnd) { L_INT nRet; RECT rcSeg; BITMAPHANDLE SegBitmap; LPCHILDDATA pData; L_BOOL bSelected = FALSE; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return; L_InitBitmap(&SegBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); if (FindSelectionCount(pData) != 1) return; CopyRect(&rcSeg, &pData->pSegments[pData->pSelSegmentId[0]].SegData.rcBitmapSeg); bSelected = TRUE; L_RectToBitmap(&pData->Bitmap, TOP_LEFT, &rcSeg); nRet = L_CopyBitmapRect(&SegBitmap, &pData->Bitmap, sizeof(BITMAPHANDLE), rcSeg.left, rcSeg.top, RCWIDTH(&rcSeg), RCHEIGHT(&rcSeg)); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Can't view segment histogram."), TEXT("Error"), MB_OK); return; } ShowUniqueColors(hWnd, &SegBitmap); if (SegBitmap.Flags.Allocated) L_FreeBitmap(&SegBitmap); } L_VOID ShowUniqueColors(HWND hWnd, pBITMAPHANDLE pBitmap) { L_INT nRet; L_TCHAR szColor[256]; L_UINT32 uCount; nRet = L_GetBitmapColorCount(pBitmap, &uCount); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("An error occurred while trying to get the bitmap color count"), TEXT("Error"), MB_OK); return; } memset(szColor, 0, 256); wsprintf(szColor, TEXT("Bitmap contains %lu unique colors."), uCount); MessageBox(hWnd, szColor, TEXT("Unique Colors"), MB_OK); } L_INT DrawManualSegment(HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y) { RECT rcSeg; L_INT nSegment, nRet; RemoveSelectedSegments(pData); CopyRect(&rcSeg, &pData->rcView); InflateRect(&rcSeg, -3, -3); // Get segment indexe SetRect(&rcSeg, pData->ptManualStart.x, pData->ptManualStart.y, x, y); OffsetRect(&rcSeg, pData->nHscrollPos, pData->nVscrollPos); NormalizeRect(&rcSeg); ChangeToImage(hWnd, &rcSeg); // If the coordinates outside the image, limit it. rcSeg.left = max(rcSeg.left, 0); rcSeg.top = max(rcSeg.top, 0); rcSeg.right = min(rcSeg.right, pData->Bitmap.Width - 1); rcSeg.bottom = min(rcSeg.bottom, pData->Bitmap.Height - 1); // Check if the rectangle dimensions are less than 2x2 if (((rcSeg.right - rcSeg.left) < 2) || ((rcSeg.bottom - rcSeg.top) < 2)) return FAILURE; if ((rcSeg.left >= 0) && (rcSeg.right < pData->Bitmap.Width) && (rcSeg.top >= 0) && (rcSeg.bottom < pData->Bitmap.Height)) { // Allocate segment data if(AllocateSegment(pData, &nSegment) != SUCCESS) { MessageBox(hWnd, TEXT("No memory"), TEXT("Error"), MB_OK); return FAILURE; } // Set new segment rect SetRect(&pData->pSegments[nSegment].SegData.rcBitmapSeg, rcSeg.left, rcSeg.top, min(rcSeg.right , pData->Bitmap.Width), min(rcSeg.bottom, pData->Bitmap.Height)); NormalizeRect(&pData->pSegments[nSegment].SegData.rcBitmapSeg); // Draw the old segment DrawManualSegmentRect(hWnd, pData->ptManualStart, pData->ptManualEnd, R2_NOTXORPEN); pData->ptManualEnd.x = min(x, pData->rcView.right); pData->ptManualEnd.y = min(y, pData->rcView.bottom); // Draw the new segment DrawManualSegmentRect(hWnd, pData->ptManualStart, pData->ptManualEnd, R2_COPYPEN); // Set the active segment pData->pSelSegmentId[0] = nSegment; // Set segment type pData->pSegments[nSegment].SegData.uType = SEGTYPE_TEXT_1BIT_BW; // Display segment type dialog InvalidateRect(hWnd, NULL, TRUE); nRet = DoDialogBoxParam(IDD_SEGMENT_TYPE, hWnd, (DLGPROC) SegmentTypeProc, TRUE); if (nRet == IDCANCEL) { pData->pSelSegmentId[0] = -1; if(RemoveSegment(pData, hWnd) != SUCCESS) { MessageBox(hWnd, TEXT("No memory"), TEXT("Error"), MB_OK); return FAILURE; } } } ChangeToZoom(hWnd, &rcSeg); OffsetRect(&rcSeg, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSeg, 3, 3); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); pData->bMouseMove = FALSE; return nRet; } L_VOID UpdateSegments(HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y) { L_INT nSeg, nRet, i; SEGMENTDATA Segment; RECT rcSeg; // Save new segment information nSeg = pData->pSelSegmentId[0]; CopyRect(&Segment.rcBitmapSeg, &pData->pSegments[nSeg].SegData.rcBitmapSeg); // Normalize the rectangle NormalizeRect(&Segment.rcBitmapSeg); Segment.uType = pData->pSegments[nSeg].SegData.uType; SET_SIZE(&Segment); // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); nRet = L_MrcSetSegmentData(pData->hSegment, &pData->Bitmap, pData->pSegments[nSeg].nSegId, &Segment); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Could not update segment."), TEXT("Error"), MB_OK); InvalidateRect(hWnd, NULL, TRUE); } CopyRect(&rcSeg, &pData->pSegments[nSeg].SegData.rcBitmapSeg); // Free any allocated rectangles RefreshSegments(hWnd, pData, &Segment.rcBitmapSeg); for (i = 0; i < pData->nSegments; i++) { if (EqualRect(&rcSeg, &pData->pSegments[i].SegData.rcBitmapSeg)) { pData->pSelSegmentId[0] = pData->pSegments[i].nSegId; break; } } InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); } L_INT FindNextSelectionIndex(LPCHILDDATA pData) { return FindSelectionCount(pData); } L_INT FindSelectionCount(LPCHILDDATA pData) { L_INT i, nSelCount = 0; if (!pData->pSelSegmentId) return 0; for (i = 0 ; i < pData->nSegments; i++) { if (pData->pSelSegmentId[i] != -1) nSelCount++; } return nSelCount; } L_VOID SelectSegments(HWND hWnd, LPCHILDDATA pData, L_INT x, L_INT y) { short uCtrlPressed; POINT pt; RECT rcSelected; L_INT i, j, nSelSeg, nCount; L_BOOL bSelected = FALSE; SetCapture(hWnd); pt.x = x + pData->nHscrollPos; pt.y = y + pData->nVscrollPos; for (i = 0; i < pData->nSegments; i++) { CopyRect(&rcSelected, &pData->pSegments[i].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); if (PtInRect(&rcSelected, pt)) { bSelected = TRUE; if (!IsSegmentSelected(pData, i)) { uCtrlPressed = GetAsyncKeyState(VK_CONTROL); if (uCtrlPressed & 0x8000) { nSelSeg = FindNextSelectionIndex(pData); } else { nSelSeg = 0; } if (pData->pSelSegmentId[nSelSeg] != -1) { if (uCtrlPressed & 0x8000) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[nSelSeg]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); pData->pSelSegmentId[nSelSeg] = -1; InflateRect(&rcSelected, 50, 50); if ((rcSelected.left < 0) || (rcSelected.top < 0) || (rcSelected.right > pData->rcView.right) || (rcSelected.bottom > pData->rcView.bottom)) InvalidateRect(hWnd, &rcSelected, TRUE); else InvalidateRect(hWnd, &rcSelected, FALSE); } else { nCount = FindSelectionCount(pData); for (j = 0; j < nCount; j++) { CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[j]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); pData->pSelSegmentId[j] = -1; InflateRect(&rcSelected, 50, 50); if ((rcSelected.left < 0) || (rcSelected.top < 0) || (rcSelected.right > pData->rcView.right) || (rcSelected.bottom > pData->rcView.bottom)) InvalidateRect(hWnd, &rcSelected, TRUE); else InvalidateRect(hWnd, &rcSelected, FALSE); } } UpdateWindow(hWnd); } pData->pSelSegmentId[nSelSeg] = i; CopyRect(&rcSelected, &pData->pSegments[pData->pSelSegmentId[nSelSeg]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &rcSelected); OffsetRect(&rcSelected, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&rcSelected, 50, 50); if ((rcSelected.left < 0) || (rcSelected.top < 0) || (rcSelected.right > pData->rcView.right) || (rcSelected.bottom > pData->rcView.bottom)) InvalidateRect(hWnd, &rcSelected, TRUE); else InvalidateRect(hWnd, &rcSelected, FALSE); UpdateWindow(hWnd); break; } } } if (!bSelected) { UnSelectSegments(hWnd, pData); UpdateWindow(hWnd); } } L_VOID UnSelectSegments(HWND hWnd, LPCHILDDATA pData) { int i, nCount; RECT SegRect; nCount = FindSelectionCount(pData); for (i = 0; i < nCount; i++) { CopyRect(&SegRect, &pData->pSegments[pData->pSelSegmentId[i]].SegData.rcBitmapSeg); ChangeToZoom(hWnd, &SegRect); // Remove the selection pData->pSelSegmentId[i] = -1; OffsetRect(&SegRect, -pData->nHscrollPos, -pData->nVscrollPos); InflateRect(&SegRect, 3, 3); InvalidateRect(hWnd, &SegRect, TRUE); UpdateWindow(hWnd); } } L_VOID CombineSegments(HWND hWnd, LPCHILDDATA pData) { L_INT i, nRet; if (FindSelectionCount(pData) < 2) return; // Before update the segment, take a copy for undo if (pData->hPrevSegment) StopSegmentation(&pData->hPrevSegment); L_MrcCopySegmentationHandle(&pData->hPrevSegment, pData->hSegment); for (i = 0; i < FindSelectionCount(pData) - 1; i++) { nRet = L_MrcCombineSegments(pData->hSegment, pData->pSelSegmentId[i], pData->pSelSegmentId[i + 1], gSegOpt.uCombineFlags, gSegOpt.uCombineFactor); if (nRet != SUCCESS) { MessageBox(hWnd, L_TEXT("Error combining segments; the segments are of different types or not adjacent.") L_TEXT("\nIf you want to force combining segments of different types") L_TEXT("\ngo to Preferences -> 'Segmentation and Compression Options...'") L_TEXT("\nand change the combining type to \"Force\""), L_TEXT("Error"), MB_OK); // Make the Undo if (pData->hSegment) StopSegmentation(&pData->hSegment); L_MrcCopySegmentationHandle(&pData->hSegment, pData->hPrevSegment); StopSegmentation(&pData->hPrevSegment); break; } } RefreshSegments(hWnd, pData, NULL); InvalidateRect(hWnd, NULL, TRUE); } L_VOID RemoveSelectedSegments(LPCHILDDATA pData) { if (pData->pSelSegmentId) memset(pData->pSelSegmentId, -1, sizeof(L_INT) * pData->nSegments); } L_BOOL IsSegmentSelected(LPCHILDDATA pData, L_INT nSegment) { L_INT i; if (!pData->pSelSegmentId) return 0; for (i = 0; i < pData->nSegments ; i++) { if (nSegment == pData->pSelSegmentId[i]) return TRUE; } return FALSE; } L_VOID RefreshSegments(HWND hWnd, LPCHILDDATA pData, LPRECT pRect) { pData->nSegments = 0; FREEPOINTER(pData->pSegments); FREEPOINTER(pData->pSelSegmentId); if (pRect) { ChangeToZoom(hWnd, pRect); InflateRect(pRect, 3, 3); InvalidateRect(hWnd, pRect, TRUE); } L_MrcEnumSegments(pData->hSegment, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, hWnd, 0); } L_VOID StopSegmentation(pHSEGMENTATION phSegment) { if (*phSegment) { L_MrcStopBitmapSegmentation(*phSegment); *phSegment = NULL; } } L_VOID ShowColorDialog(HWND hwnd, COLORREF* pClr) { L_INT nRet; COLORDLGPARAMS DlgParams ; SetCursor(LoadCursor(NULL, IDC_WAIT)); SetCursor(LoadCursor(NULL, IDC_ARROW)); memset(&DlgParams, 0, sizeof (COLORDLGPARAMS)); DlgParams.uStructSize = sizeof(COLORDLGPARAMS); DlgParams.uDlgFlags = DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ; DlgParams.crColor = *pClr; DlgParams.hpalCustom = NULL ; nRet = L_DlgColor( hwnd, &DlgParams ) ; if (nRet == SUCCESS_DLG_OK) *pClr = DlgParams.crColor; } /////////////////////////////////////// SegmentationExt Page Functions /////////////////////////////////////////////// LRESULT CALLBACK SegmentationExtDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { hPage[2] = hwnd; switch (message) { case WM_INITDIALOG: UpdateSegmentationExtPage(hwnd); return TRUE; case WM_HSCROLL: HandleSlider2(hwnd, (HWND)lParam, LOWORD(wParam)); break; case WM_COMMAND: SegmentationExtDialogCommand(hwnd, LOWORD(wParam), HIWORD(wParam)); break; } return FALSE; } void UpdateSegmentationExtPage(HWND hWnd) { L_INT nRangeMax[] = {100, 100, 100, 10, 300}; L_INT nRangeMin[] = {0, 0, 0, 0, 0}; L_INT nPosInit [] = {10, 50, 25, 5, 75}; L_INT nSlideNum = 5; L_INT nSlider; L_INT nSldBaseID = IDC_SLIDER_BGTHRSH; L_INT nEdtBaseID = IDC_EDIT_BGTHRSH; L_INT nIndex; gTempSegExt = gSegExt; nPosInit[0] = gTempSegExt.uBackGroundThreshold ; nPosInit[1] = gTempSegExt.uSegmentQuality; nPosInit[2] = gTempSegExt.uColorThreshold; nPosInit[3] = gTempSegExt.uCleanSize; nPosInit[4] = gTempSegExt.uCombineThreshold; ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Auto Select")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Noisy Image")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Scanned Image")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Printed Image")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Computer Generated Image")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("Photo")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), TEXT("User Defined")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB), uInputImageType); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("Auto Select")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("Poor Quality")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("Average Quality")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("Good Quality")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("Excellent Quality")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), TEXT("User Defined")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB), uOutputImageType); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), TEXT("Favor 1 bit segments")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), TEXT("Favor 2 bit segments")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), TEXT("Force 1 bit segments")); ComboBox_AddString(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), TEXT("Force 2 bit segments")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), gTempSegExt.uFlags & 0x000F); Button_SetCheck(GetDlgItem(hWnd, IDC_BKG_CHK), !(gTempSegExt.uFlags & 0x00F0)); for (nSlider = 0; nSlider < nSlideNum; nSlider++) { Trackbar_SetRange(GetDlgItem(hWnd, nSldBaseID + nSlider), TRUE, nRangeMin[nSlider], nRangeMax[nSlider]); SetDlgItemInt(hWnd, nEdtBaseID + nSlider, nPosInit[nSlider], FALSE); } nIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB)); LockOutputOptions(hWnd, nIndex == OPIMGQ_USERDEFINED); nIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB)); LockInputOptions(hWnd, nIndex == IMGPROF_USERDEFINED ); } L_VOID HandleSlider2(HWND hParent, HWND hWnd, int nCode) { L_INT nSlideNum = 5; SetDlgItemInt(hParent, GetDlgCtrlID(hWnd) - nSlideNum , Trackbar_GetPos(hWnd), TRUE); return; } L_VOID LockInputOptions(HWND hWnd, L_BOOL bLock) { EnableWindow(GetDlgItem(hWnd, IDC_EDIT_BGTHRSH), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_BGTHRSH), bLock); EnableWindow(GetDlgItem(hWnd, IDC_EDIT_CLEANSIZE), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_CLEANSIZE), bLock); EnableWindow(GetDlgItem(hWnd, IDC_EDIT_COMBTHRSH), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_COMBTHRSH), bLock); } L_VOID UpdateInPutImage(HWND hWnd) { L_UINT uIndex; uIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB)); uInputImageType = uIndex; LockInputOptions(hWnd, uIndex == IMGPROF_USERDEFINED); switch(uIndex) { case IMGPROF_AUTO: gTempSegExt.uCombineThreshold = 100; gTempSegExt.uBackGroundThreshold = 15; gTempSegExt.uCleanSize = 7; break; case IMGPROF_NOISY: gTempSegExt.uCombineThreshold = 125; gTempSegExt.uBackGroundThreshold = 25; gTempSegExt.uCleanSize = 10; break; case IMGPROF_SCANNED: gTempSegExt.uCombineThreshold = 125; gTempSegExt.uBackGroundThreshold = 15; gTempSegExt.uCleanSize = 8; break; case IMGPROF_PRINTED: gTempSegExt.uCombineThreshold = 100; gTempSegExt.uBackGroundThreshold = 10; gTempSegExt.uCleanSize = 7; break; case IMGPROF_COMPUTERGEN: gTempSegExt.uCombineThreshold = 75; gTempSegExt.uBackGroundThreshold = 10; gTempSegExt.uCleanSize = 3; break; case IMGPROF_PHOTOS: gTempSegExt.uCombineThreshold = 75; gTempSegExt.uBackGroundThreshold = 0; gTempSegExt.uCleanSize = 3; break; case IMGPROF_USERDEFINED: gTempSegExt.uCombineThreshold = gInputImgUserDef.uCombineThreshold; gTempSegExt.uBackGroundThreshold = gInputImgUserDef.uBackGroundThreshold; gTempSegExt.uCleanSize = gInputImgUserDef.uCleanSize; break; } SetDlgItemInt(hWnd, IDC_EDIT_BGTHRSH , gTempSegExt.uBackGroundThreshold, TRUE); SetDlgItemInt(hWnd, IDC_EDIT_CLEANSIZE , gTempSegExt.uCleanSize, TRUE); SetDlgItemInt(hWnd, IDC_EDIT_COMBTHRSH , gTempSegExt.uCombineThreshold, TRUE); } L_VOID LockOutputOptions(HWND hWnd, L_BOOL bLock) { EnableWindow(GetDlgItem(hWnd, IDC_EDIT_QUALITY), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_QUALITY), bLock); EnableWindow(GetDlgItem(hWnd, IDC_EDIT_CLRTHRESH), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SLIDER_CLRTHRESH), bLock); EnableWindow(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), bLock); EnableWindow(GetDlgItem(hWnd, IDC_BKG_CHK), bLock); } L_VOID UpdateOutPutImage(HWND hWnd) { L_UINT uIndex; uIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB)); uOutputImageType = uIndex; LockOutputOptions(hWnd, uIndex == OPIMGQ_USERDEFINED); switch(uIndex) { case OPIMGQ_AUTO: gTempSegExt.uSegmentQuality = 50; gTempSegExt.uColorThreshold = 25; gTempSegExt.uFlags = SGM_FAVOR_TWOBIT | SGM_WITHOUTBKGRND; break; case OPIMGQ_POOR: gTempSegExt.uSegmentQuality = 0; gTempSegExt.uColorThreshold = 30; gTempSegExt.uFlags = SGM_FORCE_ONEBIT | SGM_WITHBKGRND; break; case OPIMGQ_AVG: gTempSegExt.uSegmentQuality = 50; gTempSegExt.uColorThreshold = 25; gTempSegExt.uFlags = SGM_FAVOR_ONEBIT | SGM_WITHBKGRND; break; case OPIMGQ_GOOD: gTempSegExt.uSegmentQuality = 75; gTempSegExt.uColorThreshold = 25; gTempSegExt.uFlags = SGM_FAVOR_TWOBIT | SGM_WITHOUTBKGRND; break; case OPIMGQ_EXCELLENT: gTempSegExt.uSegmentQuality = 100; gTempSegExt.uColorThreshold = 25; gTempSegExt.uFlags = SGM_FORCE_TWOBIT | SGM_WITHOUTBKGRND; break; case OPIMGQ_USERDEFINED: gTempSegExt.uSegmentQuality = gOutputImgUserDef.uSegmentQuality; gTempSegExt.uColorThreshold = gOutputImgUserDef.uColorThreshold; gTempSegExt.uFlags = gOutputImgUserDef.uFlags; break; } ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_SEG_TYP_COMB), gTempSegExt.uFlags & 0x000F); Button_SetCheck(GetDlgItem(hWnd, IDC_BKG_CHK), !(gTempSegExt.uFlags & 0x00F0)); SetDlgItemInt(hWnd, IDC_EDIT_QUALITY , gTempSegExt.uSegmentQuality , TRUE); SetDlgItemInt(hWnd, IDC_EDIT_CLRTHRESH , gTempSegExt.uColorThreshold , TRUE); } L_VOID SegmentationExtDialogCommand(HWND hWnd, UINT uID, UINT uMsg) { L_INT nRangeMax[] = {100, 100, 100, 10, 300}; L_INT nRangeMin[] = {0, 0, 0, 0, 0}; HWND hCtl; L_INT nValue, nIndex; L_UINT nEdtBaseID, nSlideNum; nEdtBaseID = IDC_EDIT_BGTHRSH; nSlideNum = 5; switch (uID) { case IDC_SEG_IIQ_COMB: if(uMsg == CBN_SELCHANGE) { UpdateInPutImage(hWnd); } break; case IDC_SEG_OIQ_COMB: if(uMsg == CBN_SELCHANGE) { UpdateOutPutImage(hWnd); } break; case IDC_SEG_TYP_COMB: if(uMsg == CBN_SELCHANGE) { gTempSegExt.uFlags = (gTempSegExt.uFlags & 0x00F0) | ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_TYP_COMB)) & 0x000F; if(ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB)) == OPIMGQ_USERDEFINED) { gOutputImgUserDef.uFlags = gTempSegExt.uFlags; } } break; case IDC_BKG_CHK: //if(uMsg == CBN_SELCHANGE) { gTempSegExt.uFlags = ((gTempSegExt.uFlags) & 0x000F) | (!Button_GetCheck(GetDlgItem(hWnd, IDC_BKG_CHK)) << 4); if(ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB)) == OPIMGQ_USERDEFINED) { gOutputImgUserDef.uFlags = gTempSegExt.uFlags; } } } if (uID >= nEdtBaseID && uID < nEdtBaseID + nSlideNum) { if(uMsg == EN_CHANGE) { nValue = GetDlgItemInt(hWnd, uID, NULL, TRUE); hCtl = GetDlgItem(hWnd,uID + nSlideNum); nIndex = uID - nEdtBaseID; Trackbar_SetPos(hCtl, TRUE, nValue); if(nValue > nRangeMax[nIndex]) { SetDlgItemInt(hWnd, uID, nRangeMax[nIndex], TRUE); return ; } if(nValue < nRangeMin[nIndex]) { SetDlgItemInt(hWnd, uID, nRangeMin[nIndex], TRUE); return ; } switch (nIndex) { case 0: gTempSegExt.uBackGroundThreshold = nValue; break; case 1: gTempSegExt.uSegmentQuality = nValue; break; case 2: gTempSegExt.uColorThreshold = nValue; break; case 3: gTempSegExt.uCleanSize = nValue; break; case 4: gTempSegExt.uCombineThreshold = nValue; break; } if(ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_IIQ_COMB)) == IMGPROF_USERDEFINED) { gInputImgUserDef.uBackGroundThreshold = gTempSegExt.uBackGroundThreshold; gInputImgUserDef.uCleanSize = gTempSegExt.uCleanSize; gInputImgUserDef.uCombineThreshold = gTempSegExt.uCombineThreshold; } if(ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_SEG_OIQ_COMB)) == OPIMGQ_USERDEFINED) { gOutputImgUserDef.uSegmentQuality = gTempSegExt.uSegmentQuality ; gOutputImgUserDef.uColorThreshold = gTempSegExt.uColorThreshold ; } } } } //////////////////////////////Save Multi Dialog//////////////////////////////////////// L_VOID Strip(LPTSTR StripName, LPTSTR pszTitle) { L_INT nEndPos = 0; L_INT nSlashPos; L_INT nCount; L_TCHAR cX = '\0'; memset(StripName, 0, (lstrlen(StripName)*sizeof(L_TCHAR))); while(pszTitle[nEndPos] != cX) { nEndPos++; } for(nSlashPos = nEndPos; nSlashPos >= 0; nSlashPos--) { if(pszTitle[nSlashPos ] == '\\') break; } for(nCount = 0, nSlashPos++; nSlashPos < nEndPos; nSlashPos++, nCount++) { if (pszTitle[nSlashPos] == '.') break; StripName[nCount] = pszTitle[nSlashPos]; } } L_BOOL CALLBACK SaveAllListEnum(HWND hWnd, LPARAM lParam) { LPCHILDDATA pData; HWND hDlg; L_TCHAR StripName[255]; L_INT nCount; hDlg = (HWND)lParam; pData = (LPCHILDDATA) GetWindowLong(hWnd, GWL_USERDATA); if (!pData) return FALSE; memset(StripName, 0, sizeof(StripName)); Strip(StripName, pData->pszTitle); nCount = ListBox_GetCount(GetDlgItem(hDlg, IDC_MRC_SAVE_LST)); ListBox_AddString(GetDlgItem(hDlg, IDC_MRC_SAVE_LST), StripName); ListBox_SetItemData(GetDlgItem(hDlg, IDC_MRC_SAVE_LST), nCount, (LONG)pData); return TRUE; } L_VOID GetSaveAllListImages(HWND hWnd) { EnumChildWindows (hwndClient, SaveAllListEnum, (LONG)hWnd); ListBox_SetCurSel(GetDlgItem(hWnd, IDC_MRC_SAVE_LST), 0); } L_VOID RepostionUp(HWND hWnd) { HWND hWndList; L_INT nIndex; L_TCHAR StripName[255]; L_UINT uItemData; L_INT nListCount; hWndList = GetDlgItem(hWnd, IDC_MRC_SAVE_LST); nListCount = ListBox_GetCount(hWndList); nIndex = ListBox_GetCurSel(hWndList); if(nIndex == 0 ) return; ListBox_GetText(hWndList, nIndex, StripName); uItemData = ListBox_GetItemData(hWndList, nIndex); ListBox_GetItemData(hWndList, nIndex); ListBox_InsertString(hWndList, min(nListCount, max (0, nIndex - 1 )), StripName); ListBox_SetItemData(hWndList, min(nListCount, max (0, nIndex - 1 )), uItemData); ListBox_SetCurSel(hWndList, min(nListCount, max (0, nIndex - 1 ))); nListCount = ListBox_GetCount(hWndList); nIndex = ListBox_GetCurSel(hWndList); ListBox_DeleteString(hWndList, min(nListCount, max (0, nIndex + 2))); } L_VOID RepostionDown(HWND hWnd) { HWND hWndList; L_INT nIndex; L_TCHAR StripName[255]; L_UINT uItemData; L_INT nListCount; hWndList = GetDlgItem(hWnd, IDC_MRC_SAVE_LST); nListCount = ListBox_GetCount(hWndList); nIndex = ListBox_GetCurSel(hWndList); if(nIndex == nListCount - 1) return; ListBox_GetText(hWndList, nIndex, StripName); uItemData = ListBox_GetItemData(hWndList, nIndex); ListBox_GetItemData(hWndList, nIndex); ListBox_InsertString(hWndList, min(nListCount + 1, max (0, nIndex + 2)), StripName); ListBox_SetItemData(hWndList, min(nListCount + 1, max (0, nIndex + 2)), uItemData); ListBox_SetCurSel(hWndList, min(nListCount + 1, max (0, nIndex + 2))); nListCount = ListBox_GetCount(hWndList); nIndex = ListBox_GetCurSel(hWndList); ListBox_DeleteString(hWndList, min(nListCount, max (0, nIndex - 2))); } L_INT SaveListBitmap(HWND hWnd) { HCURSOR hOldCur; L_INT nRet; OPENFILENAME OpenFileName; SAVEDLGPARAMS FSParm; L_TCHAR szOpenFileFilter[] = TEXT("ALL\0")TEXT("*.*\0")TEXT("TIF\0")TEXT("*.tif\0")TEXT("PDF\0")TEXT("*.pdf\0"); L_TCHAR szFileName[MAX_PATH], szError[MAX_PATH]; COMPRESSIONOPTIONS CmpOption; SAVEFILEOPTION SaveOpt; FILESAVEFORMAT Formats[1]; FILESAVEFORMATBPP MrcSub[1] = {sizeof(FILESAVEFORMATBPP),24, DLG_FF_SAVE_SUB_TIFF24_LEAD_MRC}; L_UINT uIndex; HBITMAPLIST hList; L_UINT nListCount; L_UINT uItemData; HSEGMENTATION L_FAR *hSegmentList; L_INT i; SET_SIZE(&CmpOption); uIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_MRC_LST_SAV_CMB)); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); memset(szFileName, 0, sizeof(szFileName)); switch(uIndex) { case 0: MrcSub[0].uSubFormats = DLG_FF_SAVE_SUB_TIFF24_MRC; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_TIFF; Formats[0].nBppCount = 2; Formats[0].pFileSaveFormatBpp = MrcSub; CmpOption.nPictureCoder = MRC_PICTURE_COMPRESSION_JPEG; CmpOption.nPictureQFactor = gnQFactor; OpenFileName.lpstrTitle = TEXT("Save as Standard MRC"); switch(gnPictureCoder) { case MRC_PICTURE_COMPRESSION_LOSSLESS_JPEG: CmpOption.nPictureQFactor = 0; break; case MRC_PICTURE_COMPRESSION_LOSSLESS_CMW: CmpOption.nPictureQFactor = 0; break; } CmpOption.nMaskCoder = gnMaskCoder; break; case 1: MrcSub[0].uSubFormats = DLG_FF_SAVE_SUB_TIFF24_LEAD_MRC; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_TIFF; Formats[0].nBppCount = 2; Formats[0].pFileSaveFormatBpp = MrcSub; CmpOption.nPictureQFactor = gnQFactor; CmpOption.nMaskCoder = gnMaskCoder; CmpOption.nPictureCoder = gnPictureCoder; CmpOption.nText2BitCoder = gnTextCoder2Bit; OpenFileName.lpstrTitle = TEXT("Save as LEAD MRC"); switch(gnPictureCoder) { case MRC_PICTURE_COMPRESSION_LOSSLESS_JPEG: CmpOption.nPictureQFactor = 0; break; case MRC_PICTURE_COMPRESSION_LOSSLESS_CMW: CmpOption.nPictureQFactor = 0; break; } CmpOption.nGrayscale2BitCoder = gnGrayscale2BitCoder; CmpOption.nGrayscale8BitCoder = gnGrayscale8BitCoder; CmpOption.nGrayscale8BitFactor = gnGSQFactor; switch(gnGrayscale8BitCoder) { case MRC_GRAYSCALE_COMPRESSION_LOSSLESS_CMW_8BIT: CmpOption.nGrayscale8BitFactor = 0; break; case MRC_GRAYSCALE_COMPRESSION_LOSSLESS_JPEG_8BIT: CmpOption.nGrayscale8BitFactor = 0; break; } break; case 2: MrcSub[0].uSubFormats = DLG_FF_SAVE_PDF; SET_SIZE(&Formats[0]); Formats[0].nFormat = DLG_FF_SAVE_PDF; Formats[0].nBppCount = 2; Formats[0].pFileSaveFormatBpp = MrcSub; CmpOption.nPictureQFactor = gnQFactor; CmpOption.nMaskCoder = gnMaskCoder + MRC_PDF_ONEBIT_COMPRESSION_ZIP; CmpOption.nPictureCoder = gnPictureCoder + MRC_PDF_PICTURE_COMPRESSION_JPEG; CmpOption.nText2BitCoder = gnTextCoder2Bit + MRC_PDF_TEXT_COMPRESSION_ZIP; OpenFileName.lpstrTitle = TEXT("Save as PDF"); break; } OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_OVERWRITEPROMPT; OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.nFilterIndex = 0; FSParm.pFileFormats = Formats; FSParm.uFileFormatsCount = 1; SET_SIZE(&FSParm); FSParm.nQFactor = 2; FSParm.nPageNumber = 1; FSParm.uSaveMulti = TRUE; FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR; nRet = L_DlgSave(hWnd, &OpenFileName, &FSParm); if(nRet != SUCCESS_DLG_OK) return nRet; hOldCur = SetCursor(LoadCursor(NULL, IDC_WAIT)); nListCount = ListBox_GetCount(GetDlgItem(hWnd, IDC_MRC_SAVE_LST)); L_CreateBitmapList(&hList); hSegmentList = (HSEGMENTATION L_FAR *) GlobalAllocPtr(GHND,nListCount * sizeof(HSEGMENTATION)); for(i = 0; i < (L_INT)nListCount; i++) { uItemData = ListBox_GetItemData(GetDlgItem(hWnd, IDC_MRC_SAVE_LST), i); L_InsertBitmapListItem(hList, -1, (pBITMAPHANDLE)(&((LPCHILDDATA)uItemData)->Bitmap)); /*// Check for manual segmentation if ((((LPCHILDDATA)uItemData)->nSegments > 0) && (((LPCHILDDATA)uItemData)->bManual)) { if (!ManualSegmentation(hWnd)) return FAILURE; }*/ hSegmentList[i] = ((LPCHILDDATA)uItemData)->hSegment; } memset(&SaveOpt, 0, sizeof(SAVEFILEOPTION)); SET_SIZE(&SaveOpt); UpdateSaveFileOption(&FSParm, &SaveOpt); if(uIndex == 2) FSParm.nFormat = FILE_PDF_LEAD_MRC; nRet = L_MrcSaveBitmapList(hSegmentList, nListCount, hList, &CmpOption, FSParm.szFileName, FSParm.nFormat); SetCursor(hOldCur); if (nRet != SUCCESS) { memset(szError, 0, sizeof(szError)); switch(uIndex) { case 0: wsprintf(szError, TEXT("An error occurred while trying to save the bitmap as MRC: %d"), nRet); break; case 1: wsprintf(szError, TEXT("An error occurred while trying to save the bitmap as LEAD MRC: %d"), nRet); break; case 2: wsprintf(szError, TEXT("An error occurred while trying to save the bitmap as PDF: %d"), nRet); break; } MessageBox(hWnd, szError, TEXT("Error"), MB_OK); return nRet; } return nRet; } L_VOID SaveMultiDialogCommand(HWND hWnd, UINT uID, UINT uMsg) { switch (uID) { case IDC_MRC_LIST_UP_BUT: RepostionUp(hWnd); break; case IDC_MRC_LIST_DOWN_BUT: RepostionDown(hWnd); break; case IDSAVE: SaveListBitmap(hWnd); EndDialog (hWnd, 0); break; case IDCANCEL: EndDialog (hWnd, 0); break; } } LRESULT CALLBACK SaveMultiDialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HICON hIcon; switch (message) { case WM_INITDIALOG: GetSaveAllListImages(hWnd); ShowHorizontal ( GetDlgItem ( hWnd, IDC_MRC_SAVE_LST ) ) ; ComboBox_AddString(GetDlgItem(hWnd, IDC_MRC_LST_SAV_CMB), TEXT("Standard MRC")); ComboBox_AddString(GetDlgItem(hWnd, IDC_MRC_LST_SAV_CMB), TEXT("LEAD MRC")); ComboBox_AddString(GetDlgItem(hWnd, IDC_MRC_LST_SAV_CMB), TEXT("PDF")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_MRC_LST_SAV_CMB), 0); hIcon = LoadIcon(hInstMain, MAKEINTRESOURCE(IDI_DOWN)); SendMessage(GetDlgItem(hWnd, IDC_MRC_LIST_DOWN_BUT), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(HICON)hIcon); hIcon = LoadIcon(hInstMain, MAKEINTRESOURCE(IDI_UP)); SendMessage(GetDlgItem(hWnd, IDC_MRC_LIST_UP_BUT), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(HICON)hIcon); return TRUE; case WM_COMMAND: SaveMultiDialogCommand(hWnd, LOWORD(wParam), HIWORD(wParam)); break; } return FALSE; } L_BOOL ShowHorizontal ( HWND hList ) { L_TCHAR szItemText [ L_MAXPATH ]; SIZE sTextsize ; L_INT nLargestTextSize = 0 ; HDC hDC = NULL ; L_INT nIndex = 0 ; L_INT nListCount = 0 ; L_INT nStringLen = 0 ; L_INT nHorizontalExtent = 0 ; memset ( szItemText, 0, sizeof ( L_TCHAR ) * L_MAXPATH ) ; hDC = GetDC ( hList ) ; nListCount = ListBox_GetCount ( hList ) ; // Find the longest string in the list box. for ( nIndex = 0 ; nIndex < nListCount ; nIndex++ ) { ListBox_GetText ( hList, nIndex, szItemText ) ; nStringLen = lstrlen ( szItemText ) ; GetTextExtentPoint32 ( hDC, szItemText, nStringLen, &sTextsize ) ; if ( sTextsize.cx > nLargestTextSize ) { nLargestTextSize = sTextsize.cx ; } } ReleaseDC ( hList, hDC ) ; ListBox_GetHorizontalExtent ( hList ) ; ListBox_SetHorizontalExtent ( hList, nLargestTextSize ) ; if ( ListBox_GetHorizontalExtent ( hList ) == nLargestTextSize ) { return FALSE ; } return TRUE ; } /////////////////////////////////////PDF DBI OPTION DIALOG//////////////////////////// L_BOOL CALLBACK PdfDPIOptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hWnd, hCntWnd; L_TCHAR szInfo[256]; hWnd = FORWARD_WM_MDIGETACTIVE(hwndClient, SendMessage); switch (message) { case WM_INITDIALOG: memset(szInfo, 0, 256); wsprintf(szInfo, TEXT("%d"), DPIOptions.nXResolution); hCntWnd = GetDlgItem(hDlg, IDC_XRES); SetWindowText(hCntWnd, szInfo); memset(szInfo, 0, 256); wsprintf(szInfo, TEXT("%d"), DPIOptions.nXResolution); hCntWnd = GetDlgItem(hDlg, IDC_YRES); SetWindowText(hCntWnd, szInfo); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: hCntWnd = GetDlgItem(hDlg, IDC_XRES); GetWindowText(hCntWnd, szInfo, 256); DPIOptions.nXResolution = _ttoi(szInfo); if (DPIOptions.nXResolution < 0) { MessageBox(hDlg, TEXT("Invalid X-Resolution"), TEXT("Error"), MB_OK); break; } hCntWnd = GetDlgItem(hDlg, IDC_YRES); GetWindowText(hCntWnd, szInfo, 256); DPIOptions.nYResolution = _ttoi(szInfo); if (DPIOptions.nYResolution < 0) { MessageBox(hDlg, TEXT("Invalid Y-Resolution"), TEXT("Error"), MB_OK); break; } if(DPIOptions.nXResolution < 10 || DPIOptions.nXResolution > 1000 || DPIOptions.nYResolution < 10 || DPIOptions.nYResolution > 1000) { MessageBox(hDlg, TEXT("Invalid Resolution, the range of any resolution is between 10 and 1000 "), TEXT("Error"), MB_OK); return TRUE; } EndDialog(hDlg, TRUE); return TRUE; case IDCANCEL: EndDialog(hDlg, 0); return TRUE; } } return(FALSE); }