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);
533 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));
542 gamutPaint.drawPath(path);
543 gamutPaint.restore();
545 if (!
d->gamut.empty()) {
547 gamutPaint.setOpacity(1.0);
548 foreach (QPointF Point,
d->gamut) {
550 gamutPaint.drawEllipse(x +
d->xBias- 2, y-2, 4, 4);
559 d->painter.setOpacity(0.5);
560 d->painter.setCompositionMode(QPainter::CompositionMode_Multiply);
561 d->painter.drawPixmap(0, 0,
d->gamutMap);
562 d->painter.setOpacity(1.0);
563 d->painter.restore();
568 d->needUpdatePixmap =
false;
569 d->pixmap = QPixmap(size() * devicePixelRatioF());
570 d->pixmap.setDevicePixelRatio(devicePixelRatioF());
572 if (
d->cieTongueNeedsUpdate){
574 d->cieTongueNeedsUpdate =
false;
575 d->cietongue = QPixmap(size() * devicePixelRatioF());
576 d->cietongue.setDevicePixelRatio(devicePixelRatioF());
577 d->cietongue.fill(Qt::black);
578 d->painter.begin(&
d->cietongue);
580 int pixcols =
static_cast<int>(
d->cietongue.width()
581 /
d->cietongue.devicePixelRatioF());
582 int pixrows =
static_cast<int>(
d->cietongue.height()
583 /
d->cietongue.devicePixelRatioF());
585 d->gridside = (qMin(pixcols, pixrows)) / 512.0;
588 d->pxcols = pixcols -
d->xBias;
589 d->pxrows = pixrows -
d->yBias;
591 d->painter.setBackground(QBrush(qRgb(0, 0, 0)));
592 d->painter.setPen(qRgb(255, 255, 255));
599 d->painter.begin(&
d->cietongue);
605 d->pixmap =
d->cietongue;
607 d->painter.begin(&
d->pixmap);
609 if (
d->whitePoint[2] > 0.0)
614 if (
d->Primaries[2] != 0.0)
631 p.fillRect(0, 0, width(), height(),
632 palette().color(QPalette::Disabled, QPalette::Window));
634 QPen pen(
palette().color(QPalette::Disabled, QPalette::WindowText));
635 pen.setStyle(Qt::SolidLine);
639 p.drawRect(0, 0, width(), height());
647 if (!
d->profileDataAvailable)
649 p.fillRect(0, 0, width(), height(),
palette().color(QPalette::Active, QPalette::Window));
650 QPen pen(
palette().color(QPalette::Active, QPalette::Text));
651 pen.setStyle(Qt::SolidLine);
655 p.drawRect(0, 0, width(), height());
657 if (
d->uncalibratedColor)
659 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
660 i18n(
"Uncalibrated color space"));
665 p.drawText(0, 0, width(), height(), Qt::AlignCenter,
666 i18n(
"No profile available..."));
673 if (
d->needUpdatePixmap)
679 p.drawPixmap(0, 0,
d->pixmap);
684 QWidget::resizeEvent(event);
685 d->needUpdatePixmap =
true;
686 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()