Beispiel #1
0
static quint64 code64(const ScColor & col) {
	int C, M, Y, K, R, G, B;
	quint64 result=0;
	if (col.getColorModel() == colorModelRGB)
	{
		col.getRGB( &R, &G, &B );
		QColor color = QColor(R, G, B);
		color.getCmyk(&C, &M, &Y, &K);
	}
	else
	{
		col.getCMYK( &C, &M, &Y, &K );
		R = 255-qMin(255, C + K);
		G = 255-qMin(255, M + K);
		B = 255-qMin(255, Y + K);
	}
	result |= col.getColorModel() == colorModelRGB ? 1 : 0;
	result |= col.isSpotColor() ? 64 : 0;
	result |= col.isRegistrationColor() ? 32 : 0;
	result <<= 8;
	result |= C;
	result <<= 8;
	result |= M;
	result <<= 8;
	result |= Y;
	result <<= 8;
	result |= K;
	result <<= 8;
	result |= R;
	result <<= 8;
	result |= G;
	result <<= 8;
	result |= B;
	return result;
}
Beispiel #2
0
static quint64 code64(const ScColor & col)
{
	int C = 0;
	int M = 0;
	int Y = 0;
	int K = 0;
	int R = 0;
	int G = 0;
	int B = 0;
	quint64 result = 0;
	if (col.getColorModel() == colorModelRGB)
	{
		col.getRGB( &R, &G, &B );
		QColor color = QColor(R, G, B);
		color.getCmyk(&C, &M, &Y, &K);
	}
	else if (col.getColorModel() == colorModelCMYK)
	{
		col.getCMYK( &C, &M, &Y, &K );
		R = 255-qMin(255, C + K);
		G = 255-qMin(255, M + K);
		B = 255-qMin(255, Y + K);
	}
	else
	{
		double L, a, b;
		col.getLab(&L, &a, &b);
		R = qRound(L);
		G = qRound(a);
		B = qRound(b);
	}
	result |= col.getColorModel() == colorModelRGB ? 1 : 0;
	result |= col.isSpotColor() ? 64 : 0;
	result |= col.isRegistrationColor() ? 32 : 0;
	result <<= 8;
	result |= C;
	result <<= 8;
	result |= M;
	result <<= 8;
	result |= Y;
	result <<= 8;
	result |= K;
	result <<= 8;
	result |= R;
	result <<= 8;
	result |= G;
	result <<= 8;
	result |= B;
	return result;
}
Beispiel #3
0
void ScColor::fromQColor(QColor color)
{
	if (color.spec() == QColor::Cmyk)
	{
		int c, m, y, k;
		color.getCmyk(&c, &m, &y, &k);
		setColor(c, m, y, k);
	}
	else
	{
		int r, g, b;
		color.getRgb(&r, &g, &b);
		setColorRGB(r, g, b);
	}
}
Beispiel #4
0
void tst_QColor::setCmyk()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            color.setCmyk(0, 0, 0, 0, a);
            QCOMPARE(color.alpha(), a);

            int c, m, y, k, a2;
            color.getCmyk(&c, &m, &y, &k, &a2);
            QCOMPARE(a2, a);
        }

        {
            // 0.0-1.0
            qreal a = A / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, 0.0, 0.0, a);
            QCOMPARE(color.alphaF(), a);

            qreal c, m, y, k, a2;
            color.getCmykF(&c, &m, &y, &k, &a2);
            QCOMPARE(a2, a);
        }
    }

    for (int C = 0; C <= USHRT_MAX; ++C) {
        {
            // 0-255
            int c = C >> 8;
            color.setCmyk(c, 0, 0, 0, 0);
            QCOMPARE(color.cyan(), c);

            int c2, m, y, k, a;
            color.getCmyk(&c2, &m, &y, &k, &a);
            QCOMPARE(c2, c);
        }

        {
            // 0.0-1.0
            qreal c = C / qreal(USHRT_MAX);
            color.setCmykF(c, 0.0, 0.0, 0.0, 0.0);
            QCOMPARE(color.cyanF(), c);

            qreal c2, m, y, k, a;
            color.getCmykF(&c2, &m, &y, &k, &a);
            QCOMPARE(c2, c);
        }
    }

    for (int M = 0; M <= USHRT_MAX; ++M) {
        {
            // 0-255
            int m = M >> 8;
            color.setCmyk(0, m, 0, 0, 0);
            QCOMPARE(color.magenta(), m);

            int c, m2, y, k, a;
            color.getCmyk(&c, &m2, &y, &k, &a);
            QCOMPARE(m2, m);
        }

        {
            // 0.0-1.0
            qreal m = M / qreal(USHRT_MAX);
            color.setCmykF(0.0, m, 0.0, 0.0, 0.0);
            QCOMPARE(color.magentaF(), m);

            qreal c, m2, y, k, a;
            color.getCmykF(&c, &m2, &y, &k, &a);
            QCOMPARE(m2, m);
        }
    }

    for (int Y = 0; Y <= USHRT_MAX; ++Y) {
        {
            // 0-255
            int y = Y >> 8;
            color.setCmyk(0, 0, y, 0, 0);
            QCOMPARE(color.yellow(), y);

            int c, m, y2, k, a;
            color.getCmyk(&c, &m, &y2, &k, &a);
            QCOMPARE(y2, y);
        }

        {
            // 0.0-1.0
            qreal y = Y / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, y, 0.0, 0.0);
            QCOMPARE(color.yellowF(), y);

            qreal c, m, y2, k, a;
            color.getCmykF(&c, &m, &y2, &k, &a);
            QCOMPARE(y2, y);
        }
    }

    for (int K = 0; K <= USHRT_MAX; ++K) {
        {
            // 0-255
            int k = K >> 8;
            color.setCmyk(0, 0, 0, k, 0);
            QCOMPARE(color.black(), k);

            int c, m, y, k2, a;
            color.getCmyk(&c, &m, &y, &k2, &a);
            QCOMPARE(k2, k);
        }

        {
            // 0.0-1.0
            qreal k = K / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, 0.0, k, 0.0);
            QCOMPARE(color.blackF(), k);

            qreal c, m, y, k2, a;
            color.getCmykF(&c, &m, &y, &k2, &a);
            QCOMPARE(k2, k);
        }
    }
}
Beispiel #5
0
QColor color_selector::change_param_by_type (QColor color, int value, color_single_selector_type type)
{
  int h = 0, s, v, l, r, g, b, a, c, m, y, k;
  switch (type)
    {
    case color_single_selector_type::HSV_SATURATION:
    case color_single_selector_type::HSV_HUE:
    case color_single_selector_type::HSV_VALUE:
    case color_single_selector_type::HSV_ALPHA:
      color.getHsv (&h, &s, &v, &a);
      break;
    case color_single_selector_type::HSL_HUE:
    case color_single_selector_type::HSL_SATURATION:
    case color_single_selector_type::HSL_LIGHTNESS:
    case color_single_selector_type::HSL_ALPHA:
      color.getHsl (&h, &s, &l, &a);
      break;

    case color_single_selector_type::RGB_RED:
    case color_single_selector_type::RGB_GREEN:
    case color_single_selector_type::RGB_BLUE:
    case color_single_selector_type::RGB_ALPHA:
      color.getRgb (&r, &g, &b, &a);
      break;

    case color_single_selector_type::CMYK_CYAN:
    case color_single_selector_type::CMYK_MAGENTA:
    case color_single_selector_type::CMYK_YELLOW:
    case color_single_selector_type::CMYK_BLACK:
    case color_single_selector_type::CMYK_ALPHA:
      color.getCmyk (&c, &m, &y, &k, &a);
      break;
    }

  if (value < 0)
    value = 0;

  if (value > get_param_maximum_by_type (type))
    value = get_param_maximum_by_type (type);

  if (h < 0)
    h = 0;

  switch (type)
    {
    case color_single_selector_type::HSL_HUE:
      color.setHsl (value, s, l, a);
      break;
    case color_single_selector_type::HSV_HUE:
      color.setHsv (value, s, v, a);
      break;
    case color_single_selector_type::HSL_LIGHTNESS:
      color.setHsl (h, s, value, a);
      break;
    case color_single_selector_type::HSL_SATURATION:
      color.setHsl (h, value, l, a);
      break;
    case color_single_selector_type::HSV_SATURATION:
      color.setHsv (h, value, v, a);
      break;
    case color_single_selector_type::HSV_VALUE:
      color.setHsv (h, s, value, a);
      break;
    case color_single_selector_type::RGB_RED:
      color.setRgb (value, g, b, a);
      break;
    case color_single_selector_type::RGB_GREEN:
      color.setRgb (r, value, b, a);
      break;
    case color_single_selector_type::RGB_BLUE:
      color.setRgb (r, g, value, a);
      break;
    case color_single_selector_type::RGB_ALPHA:
      color.setRgb (r, g, b, value);
      break;
    case color_single_selector_type::CMYK_CYAN:
      color.setCmyk (value, m, y, k, a);
      break;
    case color_single_selector_type::CMYK_MAGENTA:
      color.setCmyk (c, value, y, k, a);
      break;
    case color_single_selector_type::CMYK_YELLOW:
      color.setCmyk (c, m, value, k, a);
      break;
    case color_single_selector_type::CMYK_BLACK:
      color.setCmyk (c, m, y, value, a);
      break;
    case color_single_selector_type::HSL_ALPHA:
      color.setHsl (h, s, l, value);
      break;
    case color_single_selector_type::HSV_ALPHA:
      color.setHsv (h, s, v, value);
      break;
    case color_single_selector_type::CMYK_ALPHA:
      color.setCmyk (c, m, y, k, value);
      break;
    }

  return color;
}