MCPcopy Create free account
hub / github.com/beefytech/Beef / Resize

Function Resize

BeefTools/ImgCreate/ImgCreate.cpp:9–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7USING_NS_BF;
8
9void Resize(ImageData* srcImage, int srcX, int srcY, int srcScale, ImageData* destImage, int destX, int destY, int scale)
10{
11 if (srcScale > scale)
12 {
13 struct Color
14 {
15 uint8 mElems[4];
16 };
17
18 struct ColorT
19 {
20 float mElems[4];
21 };
22
23 ColorT colorT = { 0 };
24
25 int sampleScale = srcScale / scale;
26 float totalDiv = 0;
27 for (int srcYOfs = 0; srcYOfs < sampleScale; srcYOfs++)
28 {
29 for (int srcXOfs = 0; srcXOfs < sampleScale; srcXOfs++)
30 {
31 auto color = *(Color*)&srcImage->mBits[(srcX - srcImage->mX + srcXOfs) + (srcY - srcImage->mY + srcYOfs)*srcImage->mWidth];
32
33 totalDiv += 1.0f;
34
35 float alpha = color.mElems[3];
36 colorT.mElems[0] += color.mElems[0] * alpha;
37 colorT.mElems[1] += color.mElems[1] * alpha;
38 colorT.mElems[2] += color.mElems[2] * alpha;
39 colorT.mElems[3] += alpha;
40 }
41 }
42
43 Color outColor;
44 float alpha = colorT.mElems[3] / totalDiv;
45 float valScale = 0;
46 if (alpha > 0)
47 valScale = 1 / alpha / totalDiv;
48 outColor.mElems[0] = (int)round(colorT.mElems[0] * valScale);
49 outColor.mElems[1] = (int)round(colorT.mElems[1] * valScale);
50 outColor.mElems[2] = (int)round(colorT.mElems[2] * valScale);
51 outColor.mElems[3] = (int)round(alpha);
52
53 destImage->mBits[destX + destY * destImage->mWidth] = *(uint32*)&outColor;
54 }
55 else
56 {
57 uint32 color = srcImage->mBits[(srcX - srcImage->mX) + (srcY - srcImage->mY)*srcImage->mWidth];
58 destImage->mBits[destX + destY * destImage->mWidth] = color;
59 }
60}
61
62void ConvImage(const StringImpl& baseName, int wantSize)
63{

Callers 13

ConvImageFunction · 0.85
mainFunction · 0.85
ResizeMethod · 0.85
InsertMethod · 0.85
ReserveMethod · 0.85
GrowReserveMethod · 0.85
GrowFrontMethod · 0.85
ArrayImplClass · 0.85
ResizeMethod · 0.85
InsertMethod · 0.85
ReserveMethod · 0.85
DequeImplClass · 0.85

Calls 1

roundFunction · 0.85

Tested by

no test coverage detected