diff --git a/src/text_shaper/shaper.cpp b/src/text_shaper/shaper.cpp index 048ef2a906..55e36e0b7c 100644 --- a/src/text_shaper/shaper.cpp +++ b/src/text_shaper/shaper.cpp @@ -30,29 +30,37 @@ namespace vector& outputBitmap) noexcept { outputBitmap.resize(outputSize.area() * NumComponents); - uint8_t* d = outputBitmap.data(); - for (size_t i = 0, sr = 0; i < *outputSize.height; i++, sr += factor) + + auto index = [&](size_t i, size_t j, size_t component) { + return 4 * i * unbox(outputSize.width) + j * 4 + component; + }; + + for (auto i: ::ranges::views::iota(size_t { 0 }, unbox(outputSize.height))) { - for (size_t j = 0, sc = 0; j < *outputSize.width; j++, sc += factor, d += 4) + for (auto j: ::ranges::views::iota(size_t { 0 }, unbox(outputSize.width))) { - // calculate area average + // calculate area average std::array components { {} }; unsigned int count = 0; - for (size_t y = sr; y < min(sr + factor, unbox(inputSize.height)); y++) + for (auto y: ::ranges::views::iota(i * factor, + min((i + 1) * factor, unbox(inputSize.height)))) { uint8_t const* p = - inputBitmap.data() + (y * unbox(inputSize.width) * 4) + (sc * 4); - for (auto x = sc; x < min(sc + factor, unbox(inputSize.width)); x++, count++) + inputBitmap.data() + (y * unbox(inputSize.width) * 4) + (j * factor * 4); + for ([[maybe_unused]] auto _: ::ranges::views::iota( + j * factor, min((j + 1) * factor, unbox(inputSize.width)))) { - for (size_t i = 0; i < NumComponents; ++i) - components[i] += *(p++); + ++count; + for (auto componentIndex: ::ranges::views::iota(size_t { 0 }, NumComponents)) + components[componentIndex] += *(p++); } } if (count) { - for (size_t i = 0; i < NumComponents; ++i) - d[i] = static_cast(components[i] / count); + for (auto componentIndex: ::ranges::views::iota(size_t { 0 }, NumComponents)) + outputBitmap[index(i, j, componentIndex)] = + static_cast(components[componentIndex] / count); } } } @@ -85,7 +93,7 @@ tuple scale(rasterized_glyph const& bitmap, vtbackend:: ratio, factor); - vector dest; + vector dest {}; switch (bitmap.format) { case bitmap_format::rgba: @@ -99,35 +107,6 @@ tuple scale(rasterized_glyph const& bitmap, vtbackend:: break; } - // for (unsigned i = 0, sr = 0; i < *newSize.height; i++, sr += factor) - // { - // for (unsigned j = 0, sc = 0; j < *newSize.width; j++, sc += factor, d += 4) - // { - // // calculate area average - // unsigned int r = 0, g = 0, b = 0, a = 0, count = 0; - // for (unsigned y = sr; y < min(sr + factor, bitmap.bitmapSize.height.as()); y++) - // { - // uint8_t const* p = bitmap.bitmap.data() + (y * *bitmap.bitmapSize.width * 4) + sc * 4; - // for (unsigned x = sc; x < min(sc + factor, bitmap.bitmapSize.width.as()); - // x++, count++) - // { - // b += *(p++); - // g += *(p++); - // r += *(p++); - // a += *(p++); - // } - // } - // - // if (count) - // { - // d[0] = static_cast(b / count); - // d[1] = static_cast(g / count); - // d[2] = static_cast(r / count); - // d[3] = static_cast(a / count); - // } - // } - // } - auto output = rasterized_glyph {}; output.format = bitmap.format; output.bitmapSize = newSize; diff --git a/src/vtrasterizer/TextClusterGrouper_test.cpp b/src/vtrasterizer/TextClusterGrouper_test.cpp index 42ffa89713..4b7c668f94 100644 --- a/src/vtrasterizer/TextClusterGrouper_test.cpp +++ b/src/vtrasterizer/TextClusterGrouper_test.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include