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 | #include "fsITexture.h"
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/fsPoint.h>
#include "fsIImage.h"
void fsITexture::filterModeSet(fsFilterMode pNewMode)
{
filterModeSetDo(pNewMode);
}
void fsITexture::wrapModeSet(fsWrapMode pNewMode)
{
wrapModeSetDo(pNewMode);
}
std::shared_ptr<fsITexture> fsITexture::cloneSubSection(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
return doCloneSubSection(pBlend, pOffset);
}
void fsITexture::blend(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
return doBlend(pBlend, pOffset);
}
void fsITexture::finalise()
{
if (mImage)
{
createFromImage(mImage.get());
mImage.reset();
}
}
fsSColour4B fsITexture::pixelGet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow)
{
return pixelGetDo(pU, pV, pCol, pRow);
}
void fsITexture::pixelSet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow, fsSColour4B const& pPixel)
{
doPixelSet(pU, pV, pCol, pRow, pPixel);
}
void fsITexture::textureCopyThroughStencil(std::shared_ptr<fsITexture> pSrc, std::shared_ptr<fsITexture> pStencil,
fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY, fsS32 pAlphaHitMaskThreshold)
{
doTextureCopyThroughStencil(pSrc, pStencil, pU, pV, pX, pY, pAlphaHitMaskThreshold);
}
void fsITexture::textureCopyInto(std::shared_ptr<fsITexture> pSrc, fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY)
{
doTextureCopyInto(pSrc, pU, pV, pX, pY);
}
void fsITexture::alpha8TexDataGet(std::shared_ptr<fsITexture> const pTextureWithHitmap, std::vector<fsU8>& pAlphaData,
fsS32 pU, fsS32 pV, fsS32 pW, fsS32 pH, fsPoint const& pPotDimensions) const
{
fsAssert(!pTextureWithHitmap->mHitMap.empty(), "Source texture does not have a hitmap.\n");
for (fsS32 row = 0; row < pH; ++row)
{
for (fsS32 col = 0; col < pW; ++col)
{
fsU8 const alphaValue = pTextureWithHitmap->hitTest(fsPoint(pU + col, pV + row)) ? 0xff : 0x00;
pAlphaData[col + (row * pPotDimensions.x)] = alphaValue;
}
}
}
fsS32 fsITexture::roundToPow2(fsS32 pDimension)
{
fsS32 pow2 = 16; // MW [11/4/2014|11:49] - Smallest texture dimension on 3DS
while (pow2 < pDimension)
{
pow2 *= 2;
}
return pow2;
}
void fsITexture::hitMapStore(fsU8 pAlphaThreshold/* = 0*/)
{
const fsS32 imgW = imageWidthGet();
const fsS32 imgH = imageHeightGet();
int pixelCount = imgW * imgH;
while ((pixelCount & mByteMask) != 0)
{
++pixelCount;
}
mHitMap.resize(scaleDownToBits(pixelCount));
fsU32 curr = 0;
unsigned char currByte = 0;
int currBit = 0;
for (int currRow = 0; currRow < imgH; ++currRow)
{
for (int currCol = 0; currCol < imgW; ++currCol)
{
if (alphaValueGet(currCol, currRow) > pAlphaThreshold)
{
currByte |= (1 << currBit);
}
if (++currBit > mByteMask)
{
mHitMap[curr++] = currByte;
currByte = currBit = 0;
}
}
}
if (currBit)
{
mHitMap[curr] = currByte;
}
}
fsBool fsITexture::hasHitMapGet() const
{
return !mHitMap.empty();
}
fsBool fsITexture::hitTest(fsPoint const& pLocalPoint) const
{
fsAssert(!mHitMap.empty(), "Attempting to perform a hit text on a fsITexture that does not have a hit map.\n");
if (pLocalPoint.x < 0 || pLocalPoint.y < 0
|| pLocalPoint.x >= imageWidthGet() || pLocalPoint.y >= imageHeightGet())
{
return false;
}
fsS32 dataOff = pLocalPoint.x + (pLocalPoint.y * imageWidthGet());
fsS32 currBit = dataOff & mByteMask;
dataOff = scaleDownToBits(dataOff);
return ((mHitMap[dataOff] & (1 << currBit)) != 0);
}
fsS32 fsITexture::scaleDownToBits(fsS32 pVal)
{
return pVal >> 3;
}
void fsITexture::maskFileLoad(const fsCResourceName& pImageFileName, fsBool pUVAnimation)<--- The member function 'fsITexture::maskFileLoad' can be static.
{
// fsStr filename = pImageFileName.nameGet();
// filename.replaceAll(".png", "-m");
// filename += ".png";
// if (fsIFile::fileExistsGet(fsCResourceName(filename, pImageFileName.locationGet())))
// {
// mMaskImage = new ax::Image();
// mMaskImage->initWithImageFile(filename.utf8Get());
// }
}
fsITexture::fsITexture():
mWidth(0),
mHeight(0)
{
}
fsITexture::~fsITexture()
{
}
|