// Unlike traditional mipmap generation, our implementation generates all levels from the original
// image, under the premise that this produces a higher quality result.
-void generateMipmaps(const LinearImage& source, Filter filter, LinearImage* result, uint32_t mips) {
- mips = std::min(mips, getMipmapCount(source));
+void generateMipmaps(const LinearImage& source, Filter filter, LinearImage* result, uint32_t mipCount) {
+ mipCount = std::min(mipCount, getMipmapCount(source));
uint32_t width = source.getWidth();
uint32_t height = source.getHeight();
- for (uint32_t n = 0; n < mips; ++n) {
+ for (uint32_t n = 0; n < mipCount; ++n) {
width = std::max(width >> 1u, 1u);
height = std::max(height >> 1u, 1u);
result[n] = resampleImage(source, width, height, filter);
"44444 41014 40704 41014 44444 44444 41014 40704 41014 44444");
uint32_t count = getMipmapCount(src);
ASSERT_EQ(count, 3);
- vector<LinearImage> mips(count);
- generateMipmaps(src, filter, mips.data(), count);
+ vector<LinearImage> mipmaps(count);
+ generateMipmaps(src, filter, mipmaps.data(), count);
updateOrCompare(src, "mip0_5x10.png");
for (uint32_t index = 0; index < count; ++index) {
- updateOrCompare(mips[index], "mip" + std::to_string(index + 1) + "_5x10.png");
+ updateOrCompare(mipmaps[index], "mip" + std::to_string(index + 1) + "_5x10.png");
}
// Test color space with a classic RED => GREEN color gradient.
src = resampleImage(src, 200, 100, Filter::NEAREST);
count = getMipmapCount(src);
ASSERT_EQ(count, 7);
- mips.resize(count);
- generateMipmaps(src, filter, mips.data(), count);
+ mipmaps.resize(count);
+ generateMipmaps(src, filter, mipmaps.data(), count);
updateOrCompare(src, "mip0_200x100.png");
for (uint32_t index = 0; index < count; ++index) {
- updateOrCompare(mips[index], "mip" + std::to_string(index + 1) + "_200x100.png");
+ updateOrCompare(mipmaps[index], "mip" + std::to_string(index + 1) + "_200x100.png");
}
}