-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImpBrush.cpp
135 lines (105 loc) · 5.15 KB
/
ImpBrush.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// ImpBrush.cpp
//
// The implementation of virtual brush. All the other brushes inherit from it.
//
#include "ImpressionistDoc.h"
#include "ImpressionistUI.h"
#include "ImpBrush.h"
// Static class member initializations
int ImpBrush::c_nBrushCount = 0;
ImpBrush** ImpBrush::c_pBrushes = NULL;
ImpBrush::ImpBrush(ImpressionistDoc* pDoc, char* name) :
m_pDoc(pDoc),
m_pBrushName(name)
{
}
//---------------------------------------------------
// Return m_pDoc, which connects the UI and brushes
//---------------------------------------------------
ImpressionistDoc* ImpBrush::GetDocument(void)
{
return m_pDoc;
}
//---------------------------------------------------
// Return the name of the current brush
//---------------------------------------------------
char* ImpBrush::BrushName(void)
{
return m_pBrushName;
}
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
ImpressionistDoc* pDoc = GetDocument();
GLubyte color[4];
memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
color[0] = color[0] * pDoc->m_pUI->getRedChannelRatio();
color[1] = color[1] * pDoc->m_pUI->getBlueChannelRatio();
color[2] = color[2] * pDoc->m_pUI->getGreenChannelRatio();
color[3] = GLubyte(int(pDoc->m_pUI->getAlpha() *255));
glColor4ubv( color );
}
//----------------------------------------------------
// Return the gradient at the source point
// returned point.x is x gradient point.y is the y gradient
//----------------------------------------------------
Vector* ImpBrush::GetGradient (const Point source)
{
ImpressionistDoc* pDoc = GetDocument();
//0.299R + 0.587G + 0.144B
GLubyte color_source[3];
memcpy ( color_source, pDoc->GetOriginalPixel( source ), 3 );
float grayintense_source = 0.299 * color_source[0] + 0.587 * color_source[1] + 0.144 * color_source[2] ;
GLubyte color1[3];
memcpy ( color1, pDoc->GetOriginalPixel( source.x-1, source.y-1 ), 3 );
float grayintense1 = 0.299 * color1[0] + 0.587 * color1[1] + 0.144 * color1[2] ;
GLubyte color2[3];
memcpy ( color2, pDoc->GetOriginalPixel( source.x, source.y-1 ), 3 );
float grayintense2 = 0.299 * color2[0] + 0.587 * color2[1] + 0.144 * color2[2] ;
GLubyte color3[3];
memcpy ( color3, pDoc->GetOriginalPixel( source.x+1, source.y-1 ), 3 );
float grayintense3 = 0.299 * color3[0] + 0.587 * color3[1] + 0.144 * color3[2] ;
GLubyte color4[3];
memcpy ( color4, pDoc->GetOriginalPixel( source.x+2, source.y-1 ), 3 );
float grayintense4 = 0.299 * color4[0] + 0.587 * color4[1] + 0.144 * color4[2] ;
GLubyte color5[3];
memcpy ( color5, pDoc->GetOriginalPixel( source.x-1, source.y ), 3 );
float grayintense5 = 0.299 * color5[0] + 0.587 * color5[1] + 0.144 * color5[2] ;
GLubyte color6[3];
memcpy ( color6, pDoc->GetOriginalPixel( source.x+1, source.y ), 3 );
float grayintense6 = 0.299 * color6[0] + 0.587 * color6[1] + 0.144 * color6[2] ;
GLubyte color7[3];
memcpy ( color7, pDoc->GetOriginalPixel( source.x+2, source.y ), 3 );
float grayintense7 = 0.299 * color7[0] + 0.587 * color7[1] + 0.144 * color7[2] ;
GLubyte color8[3];
memcpy ( color8, pDoc->GetOriginalPixel( source.x-1, source.y+1 ), 3 );
float grayintense8 = 0.299 * color8[0] + 0.587 * color8[1] + 0.144 * color8[2] ;
GLubyte color9[3];
memcpy ( color9, pDoc->GetOriginalPixel( source.x, source.y+1 ), 3 );
float grayintense9 = 0.299 * color9[0] + 0.587 * color9[1] + 0.144 * color9[2] ;
GLubyte color10[3];
memcpy ( color10, pDoc->GetOriginalPixel( source.x+1, source.y+1 ), 3 );
float grayintense10 = 0.299 * color10[0] + 0.587 * color10[1] + 0.144 * color10[2] ;
GLubyte color11[3];
memcpy ( color11, pDoc->GetOriginalPixel( source.x+2, source.y+1 ), 3 );
float grayintense11 = 0.299 * color11[0] + 0.587 * color11[1] + 0.144 * color11[2] ;
GLubyte color12[3];
memcpy ( color12, pDoc->GetOriginalPixel( source.x-1, source.y+2 ), 3 );
float grayintense12 = 0.299 * color12[0] + 0.587 * color12[1] + 0.144 * color12[2] ;
GLubyte color13[3];
memcpy ( color13, pDoc->GetOriginalPixel( source.x, source.y+2 ), 3 );
float grayintense13 = 0.299 * color13[0] + 0.587 * color13[1] + 0.144 * color13[2] ;
GLubyte color14[3];
memcpy ( color14, pDoc->GetOriginalPixel( source.x+1, source.y+2 ), 3 );
float grayintense14 = 0.299 * color14[0] + 0.587 * color14[1] + 0.144 * color14[2] ;
float blurred_source = grayintense1 / 16 + grayintense2 / 8 + grayintense3 / 16 + grayintense5 / 8 + grayintense_source /4 + grayintense6 / 8 + grayintense8 / 16 + grayintense9 / 8 + grayintense10 / 16;
float blurred_xneighbour = grayintense2 / 16 + grayintense3 / 8 + grayintense4 / 16 + grayintense_source / 8 + grayintense6 / 4 + grayintense7 / 8 + grayintense9 / 16 + grayintense10 / 8 + grayintense11 / 16;
float blurred_yneighbour = grayintense5 / 16 + grayintense_source / 8 + grayintense6 / 16 + grayintense8 / 8 + grayintense9 / 4 + grayintense10 / 8 + grayintense12 / 16 + grayintense13 / 8 + grayintense14 / 16;
Vector* result = new Vector(blurred_xneighbour - blurred_source, blurred_source - blurred_yneighbour);
return result;
}