30#include <QPainterPath>
36#include <klocalizedstring.h>
132 bool profileDataAvailable {
false};
133 bool needUpdatePixmap {
false};
134 bool cieTongueNeedsUpdate {
true};
135 bool uncalibratedColor {
false};
142 double gridside {0.0};
150 QVector <double> Primaries {9};
151 QVector <double> whitePoint {3};
157 QWidget(parent), d(new
Private)
159 d->Primaries.resize(9);
160 d->Primaries.fill(0.0);
161 d->whitePoint.resize(3);
162 d->whitePoint<<0.34773<<0.35952<<1.0;
163 d->gamut = QPolygonF();
173 return (
int) floor(val *
d->gridside + 0.5);
178 d->profileDataAvailable = profileData;
183 d->needUpdatePixmap =
true;
194 if (colorants.size()==9){
195 d->Primaries= colorants;
197 d->whitePoint = whitepoint;
198 d->needUpdatePixmap =
true;
200 d->profileDataAvailable =
true;
207 if (whitepoint.size()==3){
210 d->whitePoint = whitepoint;
211 d->needUpdatePixmap =
true;
213 d->profileDataAvailable =
true;
220 if (whitepoint.size()==3){
221 d->whitePoint = whitepoint;
222 d->needUpdatePixmap =
true;
224 d->profileDataAvailable =
true;
231 if (whitepoint.size()==3){
232 d->whitePoint = whitepoint;
233 d->needUpdatePixmap =
true;
235 d->profileDataAvailable =
true;
242 if (whitepoint.size()==3){
243 d->whitePoint = whitepoint;
244 d->needUpdatePixmap =
true;
246 d->profileDataAvailable =
true;
253 if (whitepoint.size()==3){
254 d->whitePoint = whitepoint;
255 d->needUpdatePixmap =
true;
257 d->profileDataAvailable =
true;
265 d->profileDataAvailable = dataAvailable;
269 icx = (int) floor((xy.x() * (
d->pxcols - 1)) + .5);
270 icy = (int) floor(((
d->pxrows - 1) - xy.y() * (
d->pxrows - 1)) + .5);
275 d->painter.drawLine(x1 +
d->xBias, y1, x2 +
d->xBias, y2);
280 d->painter.drawText(QPoint(
d->xBias + x, y), txt);
287 double cx = ((double)x) / (
d->pxcols * devicePixelRatioF() - 1);
288 double cy = 1.0 - ((double)y) / (
d->pxrows * devicePixelRatioF() - 1);
289 double cz = 1.0 - cx - cy;
301 KoColor colXYZ(data, xyzColorSpace);
303 return qRgb(colRGB.red(), colRGB.green(), colRGB.blue());
311 for (
int x = 380; x <= 700; x += 5) {
312 int ix = (x - 380) / 5;
336 QImage Img =
d->cietongue.toImage();
337 Img.setDevicePixelRatio(devicePixelRatioF());
341 for (
int y = 0; y <
d->pxrows * devicePixelRatioF(); ++y) {
346 for (x = 0; x <
d->pxcols * devicePixelRatioF(); ++x) {
347 if (QColor(Img.pixel(x +
d->xBias, y)) != QColor(Qt::black))
349 for (xe = (
d->pxcols * devicePixelRatioF()) - 1; xe >= x;
351 if (QColor(Img.pixel(xe +
d->xBias, y)) != QColor(Qt::black))
361 if (x < d->
pxcols * devicePixelRatioF()) {
362 for ( ; x <= xe; ++x)
365 Img.setPixel(x +
d->xBias, y,
Color);
370 d->cietongue = QPixmap::fromImage(Img, Qt::AvoidDither);
371 d->cietongue.setDevicePixelRatio(devicePixelRatioF());
377 font.setPointSize(6);
378 d->painter.setFont(font);
380 d->painter.setPen(qRgb(255, 255, 255));
385 for (
int y = 1; y <= 9; y += 1)
388 int xstart = (y * (
d->pxcols - 1)) / 10;
389 int ystart = (y * (
d->pxrows - 1)) / 10;
391 QTextStream(&s) << y;
395 QTextStream(&s) << 10 - y;
403 d->painter.setPen(qRgb(128, 128, 128));
404 d->painter.setOpacity(0.5);
406 for (
int y = 1; y <= 9; y += 1)
408 int xstart = (y * (
d->pxcols - 1)) / 10;
409 int ystart = (y * (
d->pxrows - 1)) / 10;
414 d->painter.setOpacity(1.0);
420 font.setPointSize(5);
421 d->painter.setFont(font);
423 for (
int x = 450; x <= 650; x += (x > 470 && x < 600) ? 5 : 10)
426 int bx = 0, by = 0, tx, ty;
443 int ix = (x - 380) / 5;
450 tx = icx + ((x < 520) ?
grids(-2) : ((x >= 535) ?
grids(2) : 0));
451 ty = icy + ((x < 520) ? 0 : ((x >= 535) ?
grids(-1) :
grids(-2)));
453 d->painter.setPen(qRgb(255, 255, 255));
459 QTextStream(&wl) << x;
470 d->painter.setRenderHint(QPainter::Antialiasing);
471 d->painter.setPen(qRgb(r, g, b));
472 d->painter.drawEllipse(icx +
d->xBias- sz/2, icy-sz/2, sz, sz);
473 d->painter.setPen(qRgb(r/2, g/2, b/2));
475 d->painter.drawEllipse(icx +
d->xBias- sz2/2, icy-sz2/2, sz2, sz2);
476 d->painter.restore();
482 d->painter.setPen(qRgb(80, 80, 80));
483 d->painter.setRenderHint(QPainter::Antialiasing);
489 int x1, y1, x2, y2, x3, y3;
491 mapPoint(x1, y1, (QPointF(
d->Primaries[0],
d->Primaries[1])) );
492 mapPoint(x2, y2, (QPointF(
d->Primaries[3],
d->Primaries[4])) );
493 mapPoint(x3, y3, (QPointF(
d->Primaries[6],
d->Primaries[7])) );
509 d->painter.restore();
519 d->gamutMap = QPixmap(size() * devicePixelRatioF());
520 d->gamutMap.setDevicePixelRatio(devicePixelRatioF());
521 d->gamutMap.fill(Qt::black);
523 gamutPaint.begin(&
d->gamutMap);
526 gamutPaint.setRenderHint(QPainter::Antialiasing);
527 path.setFillRule(Qt::WindingFill);
528 gamutPaint.setBrush(Qt::white);
529 gamutPaint.setPen(Qt::white);
531 if (!
d->gamut.empty()) {
532 gamutPaint.setOpacity(0.5);
534 mapPoint(x, y, (QPointF(
d->Primaries[0],
d->Primaries[1])) );
535 path.moveTo(QPointF(x +
d->xBias,y));
536 mapPoint(x, y, (QPointF(
d->Primaries[3],
d->Primaries[4])) );
537 path.lineTo(QPointF(x +
d->xBias,y));
538 mapPoint(x, y, (QPointF(
d->Primaries[6],
d->Primaries[7])) );
539 path.lineTo(QPointF(x +
d->xBias,y));
540 mapPoint(x, y, (QPointF(
d->Primaries[0],
d->Primaries[1])) );
541 path.lineTo(QPointF(x +
d->xBias,y));
543 gamutPaint.drawPath(path);
544 gamutPaint.setOpacity(1.0);
545 foreach (QPointF Point,
d->gamut) {
547 gamutPaint.drawEllipse(x +
d->xBias- 2, y-2, 4, 4);
556 d->painter.setOpacity(0.5);
557 d->painter.setCompositionMode(QPainter::CompositionMode_Multiply);
558 d->painter.drawPixmap(0, 0,
d->gamutMap);
559 d->painter.setOpacity(1.0);
560 d->painter.restore();
565 d->needUpdatePixmap =
false;
566 d->pixmap = QPixmap(size() * devicePixelRatioF());
567 d->pixmap.setDevicePixelRatio(devicePixelRatioF());
569 if (
d->cieTongueNeedsUpdate){
571 d->cieTongueNeedsUpdate =
false;
572 d->cietongue = QPixmap(size() * devicePixelRatioF());
573 d->cietongue.setDevicePixelRatio(devicePixelRatioF());
574 d->cietongue.fill(Qt::black);
575 d->painter.begin(&
d->cietongue);
577 int pixcols =
static_cast<int>(
d->cietongue.width()
578 /
d->cietongue.devicePixelRatioF());
579 int pixrows =
static_cast<int>(
d->cietongue.height()
580 /
d->cietongue.devicePixelRatioF());
582 d->gridside = (qMin(pixcols, pixrows)) / 512.0;
585 d->pxcols = pixcols -
d->xBias;
586 d->pxrows = pixrows -
d->yBias;
588 d->painter.setBackground(QBrush(qRgb(0, 0, 0)));
589 d->painter.setPen(qRgb(255, 255, 255));
596 d->painter.begin(&
d->cietongue);
602 d->pixmap =
d->cietongue;
604 d->painter.begin(&
d->pixmap);
606 if (
d->whitePoint[2] > 0.0)
611 if (
d->Primaries[2] != 0.0)
628 p.fillRect(0, 0, width(), height(),
629 palette().color(QPalette::Disabled, QPalette::Window));
631 QPen pen(
palette().color(QPalette::Disabled, QPalette::WindowText));
632 pen.setStyle(Qt::SolidLine);
636 p.drawRect(0, 0, width(), height());
644 if (!
d->profileDataAvailable)
646 p.fillRect(0, 0, width(), height(),
palette().color(QPalette::Active, QPalette::Window));
647 QPen pen(
palette().color(QPalette::Active, QPalette::Text));
648 pen.setStyle(Qt::SolidLine);
652 p.drawRect(0, 0, width(), height());
654 if (
d->uncalibratedColor)
656 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
657 i18n(
"Uncalibrated color space"));
662 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
663 i18n(
"No profile available..."));
670 if (
d->needUpdatePixmap)
676 p.drawPixmap(0, 0,
d->pixmap);
681 QWidget::resizeEvent(event);
682 d->needUpdatePixmap =
true;
683 d->cieTongueNeedsUpdate =
true;
void toQColor(QColor *c) const
a convenience method for the above.
rgba palette[MAX_PALETTE]
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()