23 QGraphicsEffect( parent ),
24 mMode( PreviewGrayscale )
46 if ( sourceIsPixmap() )
49 pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
54 pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
55 painter->setWorldTransform( QTransform() );
58 QImage image = pixmap.toImage();
66 for (
int y = 0; y < image.height(); y++ )
68 line = ( QRgb * )image.scanLine( y );
69 for (
int x = 0; x < image.width(); x++ )
71 int gray = 0.21 * qRed( line[x] ) + 0.72 * qGreen( line[x] ) + 0.07 * qBlue( line[x] );
72 line[x] = qRgb( gray, gray, gray );
76 painter->drawImage( offset, image );
81 QImage bwImage = image.convertToFormat( QImage::Format_Mono );
82 painter->drawImage( offset, bwImage );
90 for (
int y = 0; y < image.height(); y++ )
92 line = ( QRgb * )image.scanLine( y );
93 for (
int x = 0; x < image.width(); x++ )
95 line[x] = simulateColorBlindness( line[x], mMode );
99 painter->drawImage( offset, image );
108 int red = qRed( originalColor );
109 int green = qGreen( originalColor );
110 int blue = qBlue( originalColor );
114 double L = ( 17.8824 * red ) + ( 43.5161 * green ) + ( 4.11935 * blue );
115 double M = ( 3.45565 * red ) + ( 27.1554 * green ) + ( 3.86714 * blue );
116 double S = ( 0.0299566 * red ) + ( 0.184309 * green ) + ( 1.46709 * blue );
122 simulateProtanopeLMS( L, M, S );
125 simulateDeuteranopeLMS( L, M, S );
133 red = ( 0.080944 * L ) + ( -0.130504 * M ) + ( 0.116721 * S );
134 green = ( -0.0102485 * L ) + ( 0.0540194 * M ) + ( -0.113615 * S );
135 blue = ( -0.000365294 * L ) + ( -0.00412163 * M ) + ( 0.693513 * S );
138 red = qMax( qMin( 255, red ), 0 );
139 green = qMax( qMin( 255, green ), 0 );
140 blue = qMax( qMin( 255, blue ), 0 );
142 return qRgb( red, green, blue );
145 void QgsPreviewEffect::simulateProtanopeLMS(
double& L,
double &M,
double &S )
149 L = ( 2.02344 * M ) + ( -2.52581 * S );
152 void QgsPreviewEffect::simulateDeuteranopeLMS(
double& L,
double &M,
double &S )
156 M = ( 0.494207 * L ) + ( 1.24827 * S );