-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugins.cpp
executable file
·108 lines (96 loc) · 2.36 KB
/
Plugins.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//Plugins.cpp 图象处理算法API
//鲍捷,1998-1999
//1999-01-30从ViSC引入ImagePro
//1999-04-03从ImagePro摘录其中两个函数作为ImageS的范例
#include "stdafx.h"
#include "Plugins.h"
#include "dibapi.h"
#include "Resource.h"
#include "ProgDlg.h"
#include "math.h"
#include "stdlib.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//Gray二值效果
BOOL WINAPI GrayImageBinarize(BYTE FAR *pOldImage,
int OldWidth,
int OldHeight,
BYTE FAR *pNewImage,
int NewWidth,
int NewHeight,
UINT Threshold, //门限
CImageRegion *rgn
)
{
if(OldWidth!=NewWidth || OldHeight!=NewHeight
|| pOldImage==NULL || pNewImage==NULL)
return FALSE;
UINT Color;
CRect rect;
rgn->GetRgnBox(&rect);
CProgressDlg dlg(0,rect.Width(),1);
for(long i=rect.left;i<rect.right;i++)
{
for(long j=rect.top;j<rect.bottom;j++)
{
if(rgn->PtInRegion(i,j))
{
Color=GetGrayPixel(pOldImage,i,j,OldWidth,OldHeight);
if(Color>Threshold) Color=255;
else Color=0;
SetGrayPixel(pNewImage,i,j,NewWidth,NewHeight,(BYTE)Color);
}
}
if(dlg.CheckCancelButton())
{ return FALSE; }
dlg.StepIt();
}
return TRUE;
}
//鲍捷,1999-01-30
//二值效果
BOOL WINAPI ImageBinarize(HDC hOldImage,
int OldWidth,
int OldHeight,
HDC hNewImage,
int NewWidth,
int NewHeight,
UINT Threshold , //门限
CImageRegion *rgn) //二值效果
{
if(OldWidth!=NewWidth || OldHeight!=NewHeight
|| hOldImage==NULL || hNewImage==NULL)
return FALSE;
CRect rect;
rgn->GetRgnBox(&rect);
::SelectClipRgn(hNewImage,HRGN(rgn->m_hObject));
//更新原图
COLORREF Color;
UINT Lumin;
CProgressDlg dlg(0,rect.Width(),1);
for(long i=rect.left;i<rect.right;i++)
{
for(long j=rect.top;j<rect.bottom;j++)
{
// if(rgn->PtInRegion(i,j))
{
Color=::GetPixel(hOldImage,i,j);
Lumin=(298*GetRValue(Color)+
588*GetGValue(Color)+
114*GetBValue(Color)
)/1000;
if(Lumin>Threshold)
::SetPixelV(hNewImage,i,j, RGB(255,255,255) );
else
::SetPixelV(hNewImage,i,j, RGB(0,0,0) );
}
}
if(dlg.CheckCancelButton())
{ return FALSE; }
dlg.StepIt();
}
return TRUE;
}