1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
600 const qreal delta = radiusScale * d->radius + 1; |
600 const qreal delta = radiusScale * d->radius + 1; |
601 return rect.adjusted(-delta, -delta, delta, delta); |
601 return rect.adjusted(-delta, -delta, delta, delta); |
602 } |
602 } |
603 |
603 |
604 template <int shift> |
604 template <int shift> |
605 inline int static_shift(int value) |
605 inline int qt_static_shift(int value) |
606 { |
606 { |
607 if (shift == 0) |
607 if (shift == 0) |
608 return value; |
608 return value; |
609 else if (shift > 0) |
609 else if (shift > 0) |
610 return value << (uint(shift) & 0x1f); |
610 return value << (uint(shift) & 0x1f); |
611 else |
611 else |
612 return value >> (uint(-shift) & 0x1f); |
612 return value >> (uint(-shift) & 0x1f); |
613 } |
613 } |
614 |
614 |
615 template<int aprec, int zprec> |
615 template<int aprec, int zprec> |
616 inline void blurinner(uchar *bptr, int &zR, int &zG, int &zB, int &zA, int alpha) |
616 inline void qt_blurinner(uchar *bptr, int &zR, int &zG, int &zB, int &zA, int alpha) |
617 { |
617 { |
618 QRgb *pixel = (QRgb *)bptr; |
618 QRgb *pixel = (QRgb *)bptr; |
619 |
619 |
620 #define Z_MASK (0xff << zprec) |
620 #define Z_MASK (0xff << zprec) |
621 const int A_zprec = static_shift<zprec - 24>(*pixel) & Z_MASK; |
621 const int A_zprec = qt_static_shift<zprec - 24>(*pixel) & Z_MASK; |
622 const int R_zprec = static_shift<zprec - 16>(*pixel) & Z_MASK; |
622 const int R_zprec = qt_static_shift<zprec - 16>(*pixel) & Z_MASK; |
623 const int G_zprec = static_shift<zprec - 8>(*pixel) & Z_MASK; |
623 const int G_zprec = qt_static_shift<zprec - 8>(*pixel) & Z_MASK; |
624 const int B_zprec = static_shift<zprec>(*pixel) & Z_MASK; |
624 const int B_zprec = qt_static_shift<zprec>(*pixel) & Z_MASK; |
625 #undef Z_MASK |
625 #undef Z_MASK |
626 |
626 |
627 const int zR_zprec = zR >> aprec; |
627 const int zR_zprec = zR >> aprec; |
628 const int zG_zprec = zG >> aprec; |
628 const int zG_zprec = zG >> aprec; |
629 const int zB_zprec = zB >> aprec; |
629 const int zB_zprec = zB >> aprec; |
634 zB += alpha * (B_zprec - zB_zprec); |
634 zB += alpha * (B_zprec - zB_zprec); |
635 zA += alpha * (A_zprec - zA_zprec); |
635 zA += alpha * (A_zprec - zA_zprec); |
636 |
636 |
637 #define ZA_MASK (0xff << (zprec + aprec)) |
637 #define ZA_MASK (0xff << (zprec + aprec)) |
638 *pixel = |
638 *pixel = |
639 static_shift<24 - zprec - aprec>(zA & ZA_MASK) |
639 qt_static_shift<24 - zprec - aprec>(zA & ZA_MASK) |
640 | static_shift<16 - zprec - aprec>(zR & ZA_MASK) |
640 | qt_static_shift<16 - zprec - aprec>(zR & ZA_MASK) |
641 | static_shift<8 - zprec - aprec>(zG & ZA_MASK) |
641 | qt_static_shift<8 - zprec - aprec>(zG & ZA_MASK) |
642 | static_shift<-zprec - aprec>(zB & ZA_MASK); |
642 | qt_static_shift<-zprec - aprec>(zB & ZA_MASK); |
643 #undef ZA_MASK |
643 #undef ZA_MASK |
644 } |
644 } |
645 |
645 |
646 const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3); |
646 const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3); |
647 |
647 |
648 template<int aprec, int zprec> |
648 template<int aprec, int zprec> |
649 inline void blurinner_alphaOnly(uchar *bptr, int &z, int alpha) |
649 inline void qt_blurinner_alphaOnly(uchar *bptr, int &z, int alpha) |
650 { |
650 { |
651 const int A_zprec = int(*(bptr)) << zprec; |
651 const int A_zprec = int(*(bptr)) << zprec; |
652 const int z_zprec = z >> aprec; |
652 const int z_zprec = z >> aprec; |
653 z += alpha * (A_zprec - z_zprec); |
653 z += alpha * (A_zprec - z_zprec); |
654 *(bptr) = z >> (zprec + aprec); |
654 *(bptr) = z >> (zprec + aprec); |
655 } |
655 } |
656 |
656 |
657 template<int aprec, int zprec, bool alphaOnly> |
657 template<int aprec, int zprec, bool alphaOnly> |
658 inline void blurrow(QImage & im, int line, int alpha) |
658 inline void qt_blurrow(QImage & im, int line, int alpha) |
659 { |
659 { |
660 uchar *bptr = im.scanLine(line); |
660 uchar *bptr = im.scanLine(line); |
661 |
661 |
662 int zR = 0, zG = 0, zB = 0, zA = 0; |
662 int zR = 0, zG = 0, zB = 0, zA = 0; |
663 |
663 |
666 |
666 |
667 const int stride = im.depth() >> 3; |
667 const int stride = im.depth() >> 3; |
668 const int im_width = im.width(); |
668 const int im_width = im.width(); |
669 for (int index = 0; index < im_width; ++index) { |
669 for (int index = 0; index < im_width; ++index) { |
670 if (alphaOnly) |
670 if (alphaOnly) |
671 blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha); |
671 qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha); |
672 else |
672 else |
673 blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha); |
673 qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha); |
674 bptr += stride; |
674 bptr += stride; |
675 } |
675 } |
676 |
676 |
677 bptr -= stride; |
677 bptr -= stride; |
678 |
678 |
679 for (int index = im_width - 2; index >= 0; --index) { |
679 for (int index = im_width - 2; index >= 0; --index) { |
680 bptr -= stride; |
680 bptr -= stride; |
681 if (alphaOnly) |
681 if (alphaOnly) |
682 blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha); |
682 qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha); |
683 else |
683 else |
684 blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha); |
684 qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha); |
685 } |
685 } |
686 } |
686 } |
687 |
687 |
688 /* |
688 /* |
689 * expblur(QImage &img, int radius) |
689 * expblur(QImage &img, int radius) |
721 : qRound((1<<aprec)*(1 - qPow(cutOffIntensity * (1 / qreal(255)), 1 / radius))); |
721 : qRound((1<<aprec)*(1 - qPow(cutOffIntensity * (1 / qreal(255)), 1 / radius))); |
722 |
722 |
723 int img_height = img.height(); |
723 int img_height = img.height(); |
724 for (int row = 0; row < img_height; ++row) { |
724 for (int row = 0; row < img_height; ++row) { |
725 for (int i = 0; i <= improvedQuality; ++i) |
725 for (int i = 0; i <= improvedQuality; ++i) |
726 blurrow<aprec, zprec, alphaOnly>(img, row, alpha); |
726 qt_blurrow<aprec, zprec, alphaOnly>(img, row, alpha); |
727 } |
727 } |
728 |
728 |
729 QImage temp(img.height(), img.width(), img.format()); |
729 QImage temp(img.height(), img.width(), img.format()); |
730 if (transposed >= 0) { |
730 if (transposed >= 0) { |
731 if (img.depth() == 8) { |
731 if (img.depth() == 8) { |
754 } |
754 } |
755 |
755 |
756 img_height = temp.height(); |
756 img_height = temp.height(); |
757 for (int row = 0; row < img_height; ++row) { |
757 for (int row = 0; row < img_height; ++row) { |
758 for (int i = 0; i <= improvedQuality; ++i) |
758 for (int i = 0; i <= improvedQuality; ++i) |
759 blurrow<aprec, zprec, alphaOnly>(temp, row, alpha); |
759 qt_blurrow<aprec, zprec, alphaOnly>(temp, row, alpha); |
760 } |
760 } |
761 |
761 |
762 if (transposed == 0) { |
762 if (transposed == 0) { |
763 qt_memrotate90(reinterpret_cast<const quint32*>(temp.bits()), |
763 qt_memrotate90(reinterpret_cast<const quint32*>(temp.bits()), |
764 temp.width(), temp.height(), temp.bytesPerLine(), |
764 temp.width(), temp.height(), temp.bytesPerLine(), |
951 QRect srcRect = rect; |
951 QRect srcRect = rect; |
952 if (rect.isNull()) { |
952 if (rect.isNull()) { |
953 srcRect = dest.rect(); |
953 srcRect = dest.rect(); |
954 destRect = dest.rect(); |
954 destRect = dest.rect(); |
955 } |
955 } |
956 if (image != dest) { |
956 if (&image != &dest) { |
957 destRect.moveTo(QPoint(0, 0)); |
957 destRect.moveTo(QPoint(0, 0)); |
958 } |
958 } |
959 |
959 |
960 unsigned int *data = (unsigned int *)image.bits(); |
960 unsigned int *data = (unsigned int *)image.bits(); |
961 unsigned int *outData = (unsigned int *)dest.bits(); |
961 unsigned int *outData = (unsigned int *)dest.bits(); |