MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / generateMipmaps

Function generateMipmaps

engine/Poseidon/Graphics/Textures/PAAEncoder.cpp:45–67  ·  view source on GitHub ↗

Generate mipmap levels from RGBA source using stb_image_resize2

Source from the content-addressed store, hash-verified

43
44// Generate mipmap levels from RGBA source using stb_image_resize2
45static std::vector<Image> generateMipmaps(const Image& rgba, int maxLevels)
46{
47 std::vector<Image> levels;
48 levels.push_back(rgba);
49
50 int w = rgba.width();
51 int h = rgba.height();
52
53 for (int level = 1; level < maxLevels && (w > 1 || h > 1); ++level)
54 {
55 int nw = std::max(w / 2, 1);
56 int nh = std::max(h / 2, 1);
57
58 std::vector<uint8_t> resized(nw * nh * 4);
59 stbir_resize_uint8_linear(levels.back().data().data(), w, h, w * 4, resized.data(), nw, nh, nw * 4, STBIR_RGBA);
60
61 levels.push_back(Image::FromRGBA(nw, nh, std::move(resized)));
62 w = nw;
63 h = nh;
64 }
65
66 return levels;
67}
68
69// Encode a single mipmap level's pixel data in the target format
70static std::vector<uint8_t> encodeLevel(const Image& rgbaLevel, PixelFormat fmt)

Callers 1

WritePAAFunction · 0.85

Calls 2

widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected