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};
157 QWidget(parent), d(new
Private)
159 d->whitePoint = {0.34773, 0.35952, 1.0};
160 d->gamut = QPolygonF();
170 return (
int) floor(val *
d->gridside + 0.5);
175 d->profileDataAvailable = profileData;
180 d->needUpdatePixmap =
true;
191 if (colorants.size()==3){
192 d->Primaries= colorants;
194 d->whitePoint = whitepoint;
195 d->needUpdatePixmap =
true;
197 d->profileDataAvailable =
true;
206 d->whitePoint = whitepoint;
207 d->needUpdatePixmap =
true;
209 d->profileDataAvailable =
true;
213 d->whitePoint = whitepoint;
214 d->needUpdatePixmap =
true;
216 d->profileDataAvailable =
true;
220 d->whitePoint = whitepoint;
221 d->needUpdatePixmap =
true;
223 d->profileDataAvailable =
true;
227 d->whitePoint = whitepoint;
228 d->needUpdatePixmap =
true;
230 d->profileDataAvailable =
true;
234 d->whitePoint = whitepoint;
235 d->needUpdatePixmap =
true;
237 d->profileDataAvailable =
true;
242 d->profileDataAvailable = dataAvailable;
246 icx = (int) floor((xy.x() * (
d->pxcols - 1)) + .5);
247 icy = (int) floor(((
d->pxrows - 1) - xy.y() * (
d->pxrows - 1)) + .5);
252 d->painter.drawLine(x1 +
d->xBias, y1, x2 +
d->xBias, y2);
257 d->painter.drawText(QPoint(
d->xBias + x, y), txt);
264 double cx = ((double)x) / (
d->pxcols * devicePixelRatioF() - 1);
265 double cy = 1.0 - ((double)y) / (
d->pxrows * devicePixelRatioF() - 1);
266 double cz = 1.0 - cx - cy;
278 KoColor colXYZ(data, xyzColorSpace);
280 return qRgb(colRGB.red(), colRGB.green(), colRGB.blue());
288 for (
int x = 380; x <= 700; x += 5) {
289 int ix = (x - 380) / 5;
313 QImage Img =
d->cietongue.toImage();
314 Img.setDevicePixelRatio(devicePixelRatioF());
318 for (
int y = 0; y <
d->pxrows * devicePixelRatioF(); ++y) {
323 for (x = 0; x <
d->pxcols * devicePixelRatioF(); ++x) {
324 if (QColor(Img.pixel(x +
d->xBias, y)) != QColor(Qt::black))
326 for (xe = (
d->pxcols * devicePixelRatioF()) - 1; xe >= x;
328 if (QColor(Img.pixel(xe +
d->xBias, y)) != QColor(Qt::black))
338 if (x < d->
pxcols * devicePixelRatioF()) {
339 for ( ; x <= xe; ++x)
342 Img.setPixel(x +
d->xBias, y,
Color);
347 d->cietongue = QPixmap::fromImage(Img, Qt::AvoidDither);
348 d->cietongue.setDevicePixelRatio(devicePixelRatioF());
354 font.setPointSize(6);
355 d->painter.setFont(font);
357 d->painter.setPen(qRgb(255, 255, 255));
362 for (
int y = 1; y <= 9; y += 1)
365 int xstart = (y * (
d->pxcols - 1)) / 10;
366 int ystart = (y * (
d->pxrows - 1)) / 10;
368 QTextStream(&s) << y;
372 QTextStream(&s) << 10 - y;
380 d->painter.setPen(qRgb(128, 128, 128));
381 d->painter.setOpacity(0.5);
383 for (
int y = 1; y <= 9; y += 1)
385 int xstart = (y * (
d->pxcols - 1)) / 10;
386 int ystart = (y * (
d->pxrows - 1)) / 10;
391 d->painter.setOpacity(1.0);
397 font.setPointSize(5);
398 d->painter.setFont(font);
400 for (
int x = 450; x <= 650; x += (x > 470 && x < 600) ? 5 : 10)
403 int bx = 0, by = 0, tx, ty;
420 int ix = (x - 380) / 5;
427 tx = icx + ((x < 520) ?
grids(-2) : ((x >= 535) ?
grids(2) : 0));
428 ty = icy + ((x < 520) ? 0 : ((x >= 535) ?
grids(-1) :
grids(-2)));
430 d->painter.setPen(qRgb(255, 255, 255));
436 QTextStream(&wl) << x;
447 d->painter.setRenderHint(QPainter::Antialiasing);
448 d->painter.setPen(qRgb(r, g, b));
449 d->painter.drawEllipse(icx +
d->xBias- sz/2, icy-sz/2, sz, sz);
450 d->painter.setPen(qRgb(r/2, g/2, b/2));
452 d->painter.drawEllipse(icx +
d->xBias- sz2/2, icy-sz2/2, sz2, sz2);
453 d->painter.restore();
457 return QPointF(xy.
x, xy.
y);
463 d->painter.setPen(qRgb(80, 80, 80));
464 d->painter.setRenderHint(QPainter::Antialiasing);
470 int x1, y1, x2, y2, x3, y3;
490 d->painter.restore();
500 d->gamutMap = QPixmap(size() * devicePixelRatioF());
501 d->gamutMap.setDevicePixelRatio(devicePixelRatioF());
502 d->gamutMap.fill(Qt::black);
504 gamutPaint.begin(&
d->gamutMap);
507 gamutPaint.setRenderHint(QPainter::Antialiasing);
508 path.setFillRule(Qt::WindingFill);
509 gamutPaint.setBrush(Qt::white);
510 gamutPaint.setPen(Qt::white);
514 gamutPaint.setOpacity(0.5);
516 path.moveTo(QPointF(x +
d->xBias,y));
518 path.lineTo(QPointF(x +
d->xBias,y));
520 path.lineTo(QPointF(x +
d->xBias,y));
522 path.lineTo(QPointF(x +
d->xBias,y));
523 gamutPaint.drawPath(path);
524 gamutPaint.restore();
526 if (!
d->gamut.empty()) {
528 gamutPaint.setOpacity(1.0);
529 foreach (QPointF Point,
d->gamut) {
531 gamutPaint.drawEllipse(x +
d->xBias- 2, y-2, 4, 4);
540 d->painter.setOpacity(0.5);
541 d->painter.setCompositionMode(QPainter::CompositionMode_Multiply);
542 d->painter.drawPixmap(0, 0,
d->gamutMap);
543 d->painter.setOpacity(1.0);
544 d->painter.restore();
549 d->needUpdatePixmap =
false;
550 d->pixmap = QPixmap(size() * devicePixelRatioF());
551 d->pixmap.setDevicePixelRatio(devicePixelRatioF());
553 if (
d->cieTongueNeedsUpdate){
555 d->cieTongueNeedsUpdate =
false;
556 d->cietongue = QPixmap(size() * devicePixelRatioF());
557 d->cietongue.setDevicePixelRatio(devicePixelRatioF());
558 d->cietongue.fill(Qt::black);
559 d->painter.begin(&
d->cietongue);
561 int pixcols =
static_cast<int>(
d->cietongue.width()
562 /
d->cietongue.devicePixelRatioF());
563 int pixrows =
static_cast<int>(
d->cietongue.height()
564 /
d->cietongue.devicePixelRatioF());
566 d->gridside = (qMin(pixcols, pixrows)) / 512.0;
569 d->pxcols = pixcols -
d->xBias;
570 d->pxrows = pixrows -
d->yBias;
572 d->painter.setBackground(QBrush(qRgb(0, 0, 0)));
573 d->painter.setPen(qRgb(255, 255, 255));
580 d->painter.begin(&
d->cietongue);
586 d->pixmap =
d->cietongue;
588 d->painter.begin(&
d->pixmap);
590 if (
d->whitePoint.Y > 0.0)
595 if (!
d->Primaries.isEmpty())
612 p.fillRect(0, 0, width(), height(),
613 palette().color(QPalette::Disabled, QPalette::Window));
615 QPen pen(
palette().color(QPalette::Disabled, QPalette::WindowText));
616 pen.setStyle(Qt::SolidLine);
620 p.drawRect(0, 0, width(), height());
628 if (!
d->profileDataAvailable)
630 p.fillRect(0, 0, width(), height(),
palette().color(QPalette::Active, QPalette::Window));
631 QPen pen(
palette().color(QPalette::Active, QPalette::Text));
632 pen.setStyle(Qt::SolidLine);
636 p.drawRect(0, 0, width(), height());
638 if (
d->uncalibratedColor)
640 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
641 i18n(
"Uncalibrated color space"));
646 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
647 i18n(
"No profile available..."));
654 if (
d->needUpdatePixmap)
660 p.drawPixmap(0, 0,
d->pixmap);
665 QWidget::resizeEvent(event);
666 d->needUpdatePixmap =
true;
667 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()