* @brief Horizontal pass of a box-blur with the given radius. */
| 1712 | * @brief Horizontal pass of a box-blur with the given radius. |
| 1713 | */ |
| 1714 | static void boxBlurHorizontal(const QImage& src, QImage& dst, int radius) |
| 1715 | { |
| 1716 | const int w = src.width(); |
| 1717 | const int h = src.height(); |
| 1718 | const auto& inv = blurReciprocalTable(); |
| 1719 | for (int y = 0; y < h; ++y) { |
| 1720 | const QRgb* srow = reinterpret_cast<const QRgb*>(src.constScanLine(y)); |
| 1721 | QRgb* drow = reinterpret_cast<QRgb*>(dst.scanLine(y)); |
| 1722 | for (int x = 0; x < w; ++x) { |
| 1723 | int r = 0, g = 0, b = 0, a = 0, n = 0; |
| 1724 | const int x0 = qMax(0, x - radius); |
| 1725 | const int x1 = qMin(w - 1, x + radius); |
| 1726 | for (int k = x0; k <= x1; ++k) { |
| 1727 | r += qRed(srow[k]); |
| 1728 | g += qGreen(srow[k]); |
| 1729 | b += qBlue(srow[k]); |
| 1730 | a += qAlpha(srow[k]); |
| 1731 | ++n; |
| 1732 | } |
| 1733 | const int64_t recip = inv[n]; |
| 1734 | drow[x] = qRgba(static_cast<int>((r * recip) >> kBlurReciprocalShift), |
| 1735 | static_cast<int>((g * recip) >> kBlurReciprocalShift), |
| 1736 | static_cast<int>((b * recip) >> kBlurReciprocalShift), |
| 1737 | static_cast<int>((a * recip) >> kBlurReciprocalShift)); |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | /** |
| 1743 | * @brief Vertical pass of a box-blur with the given radius. |
no test coverage detected