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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 |
#include "fsCImage.h"
#include "fsCore/fsSColour.h"
#include "fsCore/src/fsCResourceName.h"
#include "fsCore/src/fsNCoreUtils.h"
#include "fsCore/src/debug/fsAssert.h"
std::map<fsS32, fsS32> fsCImage::mPixelFormats = {
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_GRAYSCALE, 8),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, 16),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R5G6B5, 16),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R8G8B8, 24),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R5G5B5A1, 16),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R4G4B4A4, 16),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 32),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R32, 32),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R32G32B32, 96),
std::pair<fsS32, fsS32>(PIXELFORMAT_UNCOMPRESSED_R32G32B32A32, 128),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_DXT1_RGB, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_DXT1_RGBA, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_DXT3_RGBA, 8),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_DXT5_RGBA, 8),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_ETC1_RGB, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_ETC2_RGB, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA, 8),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_PVRT_RGB, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_PVRT_RGBA, 4),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA, 8),
std::pair<fsS32, fsS32>(PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA, 2),
};
void fsCImage::doAlphaChannelsCombine(fsIImage const* pBlend, fsPoint const& pOffset)
{
}
std::unique_ptr<fsIImage> fsCImage::doCloneSubSection(fsIImage const* pBlend, fsPoint const& pOffset) const
{
const fsS32 width = pBlend->dimensionsGet().x;
const fsS32 height = pBlend->dimensionsGet().y;
const fsU32 bpp = 32;
const fsS32 stride = width * bpp / 8;
const fsS32 pixelCount = stride * height;
fsU8* originalImageData = new fsU8[pixelCount];
auto* originalTexels = reinterpret_cast<fsSColour4B*>(originalImageData);<--- Variable 'originalTexels' can be declared as pointer to const<--- Variable 'originalTexels' is assigned a value that is never used.
for (fsS32 currRow = 0; currRow < height; ++currRow)
{
std::memcpy(originalImageData + stride * currRow,
reinterpret_cast<fsSColour4B*>(mImage->data) + pOffset.x
+ (((pOffset.y + currRow)) * mImage->width), stride);
}
auto ret = std::unique_ptr<fsIImage>(new fsCImage());
static_cast<fsCImage*>(ret.get())->mImage = std::make_unique<Image>(::GenImageColor(width, height, BLANK));
// static_cast<fsCImage*>(ret.get())->mImage->initWithRawData(originalImageData, pixelCount, width, height, bpp);
delete[] originalImageData;
return ret;
}
std::unique_ptr<fsIImage> fsCImage::doCreateFromAlpha8Data(std::vector<fsU8>& pAlphaData, fsS32 pImgW, fsS32 pImgH, fsPoint const& pPOTDimenions)
{
//cocos2d::Size size(pImgW, pImgH);
fsS32 const bytesPerPixel = {4};
fsS32 const stride = {pPOTDimenions.x * bytesPerPixel};
fsS32 const alpthaStride = {pPOTDimenions.x};
std::vector<fsU8> imgData(stride * pPOTDimenions.y, 0);
for (fsS32 row = 0; row < pImgH; ++row)
{
for (fsS32 col = 0; col < pImgW; ++col)
{
fsS32 const newIndex = col * 4 + (row * stride);
fsU8 const alphaValue = pAlphaData[col + (row * alpthaStride)];
imgData[newIndex + 0] = imgData[newIndex + 1] = imgData[newIndex + 2] = imgData[newIndex + 3] = alphaValue;
}
}
auto ret = std::unique_ptr<fsIImage>(new fsCImage());
static_cast<fsCImage*>(ret.get())->mImage = std::make_unique<Image>(::GenImageColor(pPOTDimenions.x, pPOTDimenions.y, BLANK));
// static_cast<fsCImage*>(ret.get())->mImage->initWithRawData(imgData.data(), pPOTDimenions.x * 4 * pPOTDimenions.y * sizeof(fsU8),
// pPOTDimenions.x, pPOTDimenions.y, bytesPerPixel * 8);
return ret;
}
void fsCImage::doPremultipliedAlphaReverse()
{
}
fsSColour4B fsCImage::doPixelGet(fsPoint const& pOffset) const
{
fsU8* imgPixel = (fsU8*)mImage->data;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
imgPixel += (pOffset.x + (pOffset.y * strideGet())) * bytesPerPixelGet(mImage.get()) / 8;
fsSColour4B pixel;
if (mImage->format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
pixel.mR = *(imgPixel + 0);
pixel.mG = *(imgPixel + 1);
pixel.mB = *(imgPixel + 2);
pixel.mA = *(imgPixel + 3);
}
else if (mImage->format == PIXELFORMAT_UNCOMPRESSED_R8G8B8)
{
pixel.mR = *(imgPixel + 0);
pixel.mG = *(imgPixel + 1);
pixel.mB = *(imgPixel + 2);
pixel.mA = 255;
}
return pixel;
}
fsS32 fsCImage::bytesPerPixelGet(::Image const* pImage) const<--- The member function 'fsCImage::bytesPerPixelGet' can be static.
{
return mPixelFormats[pImage->format];
}
fsS32 fsCImage::strideGet() const
{
return mImage->width;
}
fsU8 fsCImage::doAlphaGet(fsPoint const& pPos) const
{
if (mImage)<--- Assuming that condition 'mImage' is not redundant
{
const fsU8* texelData = static_cast<fsU8*>(mImage->data);
const fsS8 bytesPerPixel = bytesPerPixelGet(mImage.get()) / 8;
const fsS32 lineStride = mImage->width;
const fsS32 offset = pPos.x + (pPos.y * lineStride);
const auto imgFmt = mImage->format;
if (imgFmt == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
return *(texelData + offset * bytesPerPixel + 3);
}
if (imgFmt == PIXELFORMAT_UNCOMPRESSED_R8G8B8)
{
return 0xff;
}
fsAssert(false, "Unhandled image format (%d). Not returning default value.\n", mImage->format);
}
else
{
fsAssert(mImage != nullptr, "Trying to read image data after it has been uploaded to VRAM.\n");<--- Condition 'mImage!=nullptr' is always false
}
return 0xff;
}
void fsCImage::doTextureCopyThroughStencil(fsIImage const* pSrc, fsIImage const* const pStencil,
fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY)
{
const auto dimensions = pStencil->dimensionsGet();
auto stencilImpl = static_cast<fsCImage const* const>(pStencil)->mImage.get();
auto srcImpl = static_cast<fsCImage const* const>(pSrc)->mImage.get();
const fsBool noAlphaChannel = srcImpl->format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
const fsS32 myBpp = bytesPerPixelGet(mImage.get()) / 8;
const fsS32 stencilcBpp = bytesPerPixelGet(stencilImpl) / 8;
const fsS32 srcBpp = bytesPerPixelGet(srcImpl) / 8;
for (fsS32 currRow = 0; currRow < dimensions.y; ++currRow)
{
for (fsS32 currCol = 0; currCol < dimensions.x; ++currCol)
{
if (fsU8 alpha = pStencil->alphaGet({pU + currCol, pV + currRow}))
{
fsU8* stencil = static_cast<fsU8*>(stencilImpl->data) + (pU + currCol) * stencilcBpp +<--- Variable 'stencil' can be declared as pointer to const
((pV + currRow) * stencilImpl->width * stencilcBpp);
fsU8* srcTexel = static_cast<fsU8*>(srcImpl->data) + (pU + pX + currCol) * srcBpp +<--- Variable 'srcTexel' can be declared as pointer to const
((pV + pY + currRow) * srcImpl->width * srcBpp);
fsU8* destTexel = static_cast<fsU8*>(mImage->data) + (pU + currCol) * myBpp +
((pV + currRow) * mImage->width * myBpp);
const fsF32 bpp = 255.f;
fsF32 rDest = *(srcTexel + 0) / bpp * *(stencil + 0) / bpp * 2.f;
fsF32 gDest = *(srcTexel + 1) / bpp * *(stencil + 1) / bpp * 2.f;
fsF32 bDest = *(srcTexel + 2) / bpp * *(stencil + 2) / bpp * 2.f;
fsF32 aDest = *(srcTexel + 3) / bpp * *(stencil + 3) / bpp * 2.f;
if (noAlphaChannel)
{
aDest = *(stencil + 3) / bpp * 2.f;
}
fsNCoreUtils::clamp(rDest, 0.f, 1.f);
fsNCoreUtils::clamp(gDest, 0.f, 1.f);
fsNCoreUtils::clamp(bDest, 0.f, 1.f);
fsNCoreUtils::clamp(aDest, 0.f, 1.f);
*(destTexel + 0) = static_cast<fsU8>(bpp * (rDest));
*(destTexel + 1) = static_cast<fsU8>(bpp * (gDest));
*(destTexel + 2) = static_cast<fsU8>(bpp * (bDest));
*(destTexel + 3) = static_cast<fsU8>(bpp * (aDest));
}
}
}
}
void fsCImage::doTextureCopyInto(fsIImage const* const pSrc, fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY)
{
const auto diminesions = pSrc->dimensionsGet();
auto srcImpl = static_cast<fsCImage const* const>(pSrc)->mImage.get();
const fsS32 destBpp = bytesPerPixelGet(mImage.get()) / 8;
const fsS32 srcBpp = bytesPerPixelGet(srcImpl) / 8;
for (fsS32 currRow = 0; currRow < diminesions.y; ++currRow)
{
for (fsS32 currCol = 0; currCol < diminesions.x; ++currCol)
{
fsU8* destTexel = static_cast<fsU8*>(mImage->data) + (pU + pX + currCol) * destBpp +
((pV + pY + currRow) * mImage->width * destBpp);
fsU8* srcTexel = static_cast<fsU8*>(srcImpl->data) + (pU + currCol) * srcBpp +<--- Variable 'srcTexel' can be declared as pointer to const
((pV + currRow) * srcImpl->width * srcBpp);
*(destTexel + 0) = *(srcTexel + 0);
*(destTexel + 1) = *(srcTexel + 1);
*(destTexel + 2) = *(srcTexel + 2);
*(destTexel + 3) = *(srcTexel + 3);
}
}
}
void fsCImage::doPixelSet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow, const fsSColour4B& pPixel)
{
fsU32 newPixel = 0;
fsU32* destPixel = (fsU32*)mImage->data;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
destPixel += pU + pCol + ((pV + pRow) * strideGet());
if (mImage->format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
newPixel = static_cast<fsU8>(pPixel.mA) << 24 |
static_cast<fsU8>(pPixel.mB) << 16 |
static_cast<fsU8>(pPixel.mG) << 8 |
static_cast<fsU8>(pPixel.mR);
}
(*destPixel) = newPixel;
}
fsPoint fsCImage::doDimensionsGet() const
{
return {mImage->width, mImage->height };
}
void fsCImage::doCreate(const fsPoint& pDimensions)
{
mImage = std::make_unique<Image>(::GenImageColor(pDimensions.x, pDimensions.y, BLANK));
}
void fsCImage::doCreate(const fsCResourceName& pImageFileName)
{
mImage = std::make_unique<::Image>(::LoadImage(pImageFileName.nameGet().utf8Get()));
}
fsCImage::fsCImage()
{
}
fsCImage::~fsCImage()
{
}
|