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();
61 for (
int y = 0; y < image.height(); y++ )
63 line = ( QRgb * )image.scanLine( y );
64 for (
int x = 0; x < image.width(); x++ )
66 int gray = 0.21 * qRed( line[x] ) + 0.72 * qGreen( line[x] ) + 0.07 * qBlue( line[x] );
67 line[x] = qRgb( gray, gray, gray );
71 painter->drawImage( offset, image );
76 QImage bwImage = image.convertToFormat( QImage::Format_Mono );
77 painter->drawImage( offset, bwImage );
85 for (
int y = 0; y < image.height(); y++ )
87 line = ( QRgb * )image.scanLine( y );
88 for (
int x = 0; x < image.width(); x++ )
90 line[x] = simulateColorBlindness( line[x], mMode );
94 painter->drawImage( offset, image );
103 int red = qRed( originalColor );
104 int green = qGreen( originalColor );
105 int blue = qBlue( originalColor );
109 double L = ( 17.8824 * red ) + ( 43.5161 * green ) + ( 4.11935 * blue );
110 double M = ( 3.45565 * red ) + ( 27.1554 * green ) + ( 3.86714 * blue );
111 double S = ( 0.0299566 * red ) + ( 0.184309 * green ) + ( 1.46709 * blue );
117 simulateProtanopeLMS( L, M, S );
120 simulateDeuteranopeLMS( L, M, S );
128 red = ( 0.080944 * L ) + ( -0.130504 * M ) + ( 0.116721 * S );
129 green = ( -0.0102485 * L ) + ( 0.0540194 * M ) + ( -0.113615 * S );
130 blue = ( -0.000365294 * L ) + ( -0.00412163 * M ) + ( 0.693513 * S );
133 red = std::max( std::min( 255, red ), 0 );
134 green = std::max( std::min( 255, green ), 0 );
135 blue = std::max( std::min( 255, blue ), 0 );
137 return qRgb( red, green, blue );
140 void QgsPreviewEffect::simulateProtanopeLMS(
double &L,
double &M,
double &S )
144 L = ( 2.02344 * M ) + ( -2.52581 * S );
147 void QgsPreviewEffect::simulateDeuteranopeLMS(
double &L,
double &M,
double &S )
151 M = ( 0.494207 * L ) + ( 1.24827 * S );