| 388 | } |
| 389 | |
| 390 | QImage blurred(const QImage &image, const QRect &rect, int radius, bool alphaOnly = false) |
| 391 | { |
| 392 | int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 }; |
| 393 | int alpha = (radius < 1) ? 16 : ((radius > 17) ? 1 : tab[radius - 1]); |
| 394 | |
| 395 | QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
| 396 | int r1 = rect.top(); |
| 397 | int r2 = rect.bottom(); |
| 398 | int c1 = rect.left(); |
| 399 | int c2 = rect.right(); |
| 400 | |
| 401 | int bpl = result.bytesPerLine(); |
| 402 | int rgba[4]; |
| 403 | unsigned char *p; |
| 404 | |
| 405 | int i1 = 0; |
| 406 | int i2 = 3; |
| 407 | |
| 408 | if (alphaOnly) |
| 409 | i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3); |
| 410 | |
| 411 | for (int col = c1; col <= c2; col++) { |
| 412 | p = result.scanLine(r1) + col * 4; |
| 413 | for (int i = i1; i <= i2; i++) |
| 414 | rgba[i] = p[i] << 4; |
| 415 | |
| 416 | p += bpl; |
| 417 | for (int j = r1; j < r2; j++, p += bpl) |
| 418 | for (int i = i1; i <= i2; i++) |
| 419 | p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; |
| 420 | } |
| 421 | |
| 422 | for (int row = r1; row <= r2; row++) { |
| 423 | p = result.scanLine(row) + c1 * 4; |
| 424 | for (int i = i1; i <= i2; i++) |
| 425 | rgba[i] = p[i] << 4; |
| 426 | |
| 427 | p += 4; |
| 428 | for (int j = c1; j < c2; j++, p += 4) |
| 429 | for (int i = i1; i <= i2; i++) |
| 430 | p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; |
| 431 | } |
| 432 | |
| 433 | for (int col = c1; col <= c2; col++) { |
| 434 | p = result.scanLine(r2) + col * 4; |
| 435 | for (int i = i1; i <= i2; i++) |
| 436 | rgba[i] = p[i] << 4; |
| 437 | |
| 438 | p -= bpl; |
| 439 | for (int j = r1; j < r2; j++, p -= bpl) |
| 440 | for (int i = i1; i <= i2; i++) |
| 441 | p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; |
| 442 | } |
| 443 | |
| 444 | for (int row = r1; row <= r2; row++) { |
| 445 | p = result.scanLine(row) + c2 * 4; |
| 446 | for (int i = i1; i <= i2; i++) |
| 447 | rgba[i] = p[i] << 4; |
no test coverage detected