1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| void ColorChooser::loadForegroundPixmap(QRgb rgbBg)
{
// build foreground/background pixmap. for the foreground color we use black or white,
// whichever is furthest in rgb space from the background color
int width = ChooserWidth + 2 * ChooserPadding;
QImage imageScale(width, m_scaleHeight, 32);
int rBg, gBg, bBg;
QColor colorBg(rgbBg);
colorBg.rgb(&rBg, &gBg, &bBg);
QRgb rgbFg;
int distanceBlack = (rBg - 0) * (rBg - 0) + (gBg - 0) * (gBg - 0) + (bBg - 0) * (bBg - 0);
int distanceWhite = (rBg - 255) * (rBg - 255) + (gBg - 255) * (gBg - 255) + (bBg - 255) * (bBg - 255);
if (distanceWhite > distanceBlack)
rgbFg = Qt::white.rgb();
else
rgbFg = Qt::black.rgb();
for (int x = 0; x < width; x++)
for (int y = 0; y < m_scaleHeight; y++)
{
// show an triangle with bottom side on the left, and point on the right
if (x < (y * width) / (m_scaleHeight - 2 * ChooserFrame))
setPixelRGB(&imageScale, x, y, rgbBg);
else
setPixelRGB(&imageScale, x, y, rgbFg);
}
pixmapForeground.convertFromImage(imageScale, Qt::ThresholdDither);
if (m_discretizeMethod == DiscretizeForeground)
{
scaleCanvas->setBackgroundPixmap(pixmapForeground);
scaleCanvas->update();
}
} |
Partager