-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCAniImageFill.cpp
215 lines (165 loc) · 4.25 KB
/
CAniImageFill.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// CAniImageFill.cpp
//
// CAniImageFill class
// Copyright (c) 2012 by Kronosaur Productions, LLC. All Rights Reserved.
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "Reanimator.h"
#define PROP_OPACITY CONSTLIT("opacity")
CAniImageFill::CAniImageFill (const CG32bitImage *pImage, bool bFreeImage, bool bMask0) :
m_pImage(pImage),
m_bFreeImage(bFreeImage),
m_bMask0(bMask0),
m_dwOpacity(255),
m_xOrigin(0),
m_yOrigin(0)
// CAniImageFill constructor
{
if (m_pImage)
{
if (m_pImage->GetWidth() == 0 || m_pImage->GetHeight() == 0)
{
if (bFreeImage)
delete m_pImage;
m_pImage = NULL;
}
}
}
CAniImageFill::~CAniImageFill (void)
// CAniImageFill destructor
{
if (m_pImage && m_bFreeImage)
delete m_pImage;
}
void CAniImageFill::CalcTile (int x, int y, int *retxTile, int *retyTile)
// CalcTile
//
// Calculates the upper-left coords of the source image.
{
int xTile = x - m_xOrigin;
if (xTile >= 0)
xTile = xTile % m_pImage->GetWidth();
else
xTile = m_pImage->GetWidth() - ((-xTile) % m_pImage->GetWidth());
int yTile = y - m_yOrigin;
if (yTile >= 0)
yTile = yTile % m_pImage->GetHeight();
else
yTile = m_pImage->GetHeight() - ((-yTile) % m_pImage->GetHeight());
// Done
*retxTile = xTile;
*retyTile = yTile;
}
void CAniImageFill::Fill (SAniPaintCtx &Ctx, int x, int y, int cxWidth, int cyHeight)
// Fill
//
// Fill
{
if (m_pImage == NULL)
return;
int xTile;
int yTile;
CalcTile(x, y, &xTile, &yTile);
int yDest = y;
int yLeft = cyHeight;
while (yLeft)
{
int cyTile = Min(yLeft, m_pImage->GetHeight() - yTile);
int xDest = x;
int xLeft = cxWidth;
while (xLeft)
{
int cxTile = Min(xLeft, m_pImage->GetWidth() - xTile);
if (m_bMask0)
CGDraw::BltMask0(Ctx.Dest, xDest, yDest, *m_pImage, xTile, yTile, cxTile, cyTile);
else
Ctx.Dest.Blt(xTile, yTile, cxTile, cyTile, (BYTE)m_dwOpacity, *m_pImage, xDest, yDest);
xDest += cxTile;
xLeft -= cxTile;
xTile = 0;
}
yDest += cyTile;
yLeft -= cyTile;
yTile = 0;
}
}
void CAniImageFill::Fill (SAniPaintCtx &Ctx, int x, int y, const TArray<SSimpleRasterLine> &Lines)
// Fill
//
// Files the set of lines
{
if (m_pImage == NULL)
return;
SSimpleRasterLine *pLine = &Lines[0];
SSimpleRasterLine *pLineEnd = pLine + Lines.GetCount();
while (pLine < pLineEnd)
{
int xDest = x + pLine->x;
int yDest = y + pLine->y;
int xTile;
int yTile;
CalcTile(xDest, yDest, &xTile, &yTile);
int xSolidTile = xTile;
int xLeft = pLine->cxLength;
while (xLeft)
{
int cxTile = Min(xLeft, m_pImage->GetWidth() - xTile);
if (m_bMask0)
CGDraw::BltMask0(Ctx.Dest, xDest, yDest, *m_pImage, xSolidTile, yTile, yTile, 1);
else
Ctx.Dest.Blt(xSolidTile, yTile, cxTile, 1, (BYTE)m_dwOpacity, *m_pImage, xDest, yDest);
xDest += cxTile;
xLeft -= cxTile;
xSolidTile = 0;
}
// Edges
if (pLine->byLeftEdge)
{
int xSrc = (xTile > 0 ? xTile - 1 : m_pImage->GetWidth() - 1);
DWORD dwOpacity = m_dwOpacity * pLine->byLeftEdge / 255;
CG32bitPixel rgbColor = m_pImage->GetPixel(xSrc, yTile);
if (m_bMask0 && rgbColor.AsDWORD() == 0xFF000000)
{}
else
Ctx.Dest.SetPixelTrans(x + pLine->x - 1, yDest, rgbColor, (BYTE)dwOpacity);
}
if (pLine->byRightEdge)
{
int xSrc = (x + pLine->cxLength) % m_pImage->GetWidth();
DWORD dwOpacity = m_dwOpacity * pLine->byRightEdge / 255;
CG32bitPixel rgbColor = m_pImage->GetPixel(xSrc, yTile);
if (m_bMask0 && rgbColor.AsDWORD() == 0xFF000000)
{}
else
Ctx.Dest.SetPixelTrans(x + pLine->x + pLine->cxLength, yDest, rgbColor, (BYTE)dwOpacity);
}
pLine++;
}
}
void CAniImageFill::Fill (SAniPaintCtx &Ctx, int x, int y, const CG16bitBinaryRegion &Region)
// Fill
//
// Fills the region
{
if (m_pImage == NULL)
return;
// LATER
}
void CAniImageFill::InitDefaults (CAniPropertySet &Properties)
// InitDefaults
//
// Initializes animatron properties to defaults
{
}
void CAniImageFill::InitPaint (SAniPaintCtx &Ctx, int xOrigin, int yOrigin, CAniPropertySet &Properties)
// InitPaint
//
// Initializes internal cache from properties
{
m_dwOpacity = Properties.GetOpacity(PROP_OPACITY) * Ctx.dwOpacityToDest / 255;
m_xOrigin = xOrigin;
m_yOrigin = yOrigin;
}