23 : QGraphicsEffect( parent )
24 , mMode( PreviewGrayscale )
41 if ( sourceIsPixmap() )
44 pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
49 pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
50 painter->setWorldTransform( QTransform() );
53 QImage image = pixmap.toImage();
59 const QImage bwImage = image.convertToFormat( QImage::Format_Mono );
60 painter->drawImage( offset, bwImage );
70 for (
int y = 0; y < image.height(); y++ )
72 line = ( QRgb * )image.scanLine( y );
73 for (
int x = 0; x < image.width(); x++ )
75 line[x] = simulateColorBlindness( line[x], mMode );
79 painter->drawImage( offset, image );
88 int red = qRed( originalColor );
89 int green = qGreen( originalColor );
90 int blue = qBlue( originalColor );
102 simulateGrayscale( r, g, b, red, green, blue );
105 simulateProtanope( r, g, b, red, green, blue );
108 simulateDeuteranope( r, g, b, red, green, blue );
111 simulateTritanope( r, g, b, red, green, blue );
118 r = std::max( std::min( 255, r ), 0 );
119 g = std::max( std::min( 255, g ), 0 );
120 b = std::max( std::min( 255, b ), 0 );
122 return qRgb( r, g, b );
125 void QgsPreviewEffect::simulateGrayscale(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
127 r = ( 0.2126 * red ) + ( 0.7152 * green ) + ( 0.0722 * blue );
132 void QgsPreviewEffect::simulateProtanope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
134 r = ( 0.152286 * red ) + ( 1.052583 * green ) + ( -0.204868 * blue );
135 g = ( 0.114503 * red ) + ( 0.786281 * green ) + ( 0.099216 * blue );
136 b = ( -0.003882 * red ) + ( -0.048116 * green ) + ( 1.051998 * blue );
139 void QgsPreviewEffect::simulateDeuteranope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
141 r = ( 0.367322 * red ) + ( 0.860646 * green ) + ( -0.227968 * blue );
142 g = ( 0.280085 * red ) + ( 0.672501 * green ) + ( 0.047413 * blue );
143 b = ( -0.011820 * red ) + ( 0.042940 * green ) + ( 0.968881 * blue );
146 void QgsPreviewEffect::simulateTritanope(
int &r,
int &g,
int &b,
int &red,
int &green,
int &blue )
148 r = ( 1.255528 * red ) + ( -0.076749 * green ) + ( -0.178779 * blue );
149 g = ( -0.078411 * red ) + ( 0.930809 * green ) + ( 0.147602 * blue );
150 b = ( 0.004733 * red ) + ( 0.691367 * green ) + ( 0.303900 * blue );
void draw(QPainter *painter) override
void setMode(PreviewMode mode)
Sets the mode for the preview effect, which controls how the effect modifies a widgets appearance.
PreviewMode mode() const
Returns the mode used for the preview effect.
QgsPreviewEffect(QObject *parent)