MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / scaleNearest

Function scaleNearest

source/core/StarImageScaling.cpp:7–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5namespace Star {
6
7Image scaleNearest(Image const& srcImage, Vec2F const& scale) {
8 Vec2U srcSize = srcImage.size();
9 Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
10 destSize[0] = max(destSize[0], 1u);
11 destSize[1] = max(destSize[1], 1u);
12
13 Image destImage(destSize, srcImage.pixelFormat());
14
15 for (unsigned y = 0; y < destSize[1]; ++y) {
16 for (unsigned x = 0; x < destSize[0]; ++x)
17 destImage.set({x, y}, srcImage.clamp(Vec2I::round(vdiv(Vec2F(x, y), scale))));
18 }
19 return destImage;
20}
21
22Image scaleBilinear(Image const& srcImage, Vec2F const& scale) {
23 Vec2U srcSize = srcImage.size();

Callers 1

processImageOperationFunction · 0.85

Calls 7

roundFunction · 0.85
vmultFunction · 0.85
vdivFunction · 0.85
pixelFormatMethod · 0.80
sizeMethod · 0.45
setMethod · 0.45
clampMethod · 0.45

Tested by

no test coverage detected