Example #1
0
QColor ColorRangeBase::toColor(const QVariant &v, ColorRangeBase::ColorModel colormodel)
{
    if ( v.type() == QVariant::Color)
        return QColor(v.value<QColor>());
    else if ( v.type() == QVariant::String){
        QRegExp separ("[(]|,|[)]");
        QStringList parts = (v.toString()).split(separ);
        if(parts.last().isEmpty())
            parts.removeLast();
        QColor clr;
        bool ok1,ok2,ok3,ok4,ok5 =true;
        if ( parts.size() >= 5){
            double component1 = parts[1].toDouble(&ok1);
            double component2 = parts[2].toDouble(&ok2);
            double component3 = parts[3].toDouble(&ok3);
            double component4 = parts[4].toDouble(&ok4);
            double component5 =  parts.size()== 6 ? parts[5].toDouble(&ok5) : rUNDEF;
            if(! (ok1 && ok2 && ok3 && ok4 && ok5))
                return QColor();

            bool isFractional =  component1 <= 1 && component2 <= 1 && component3 <= 1 && component4 <= 1;
            if ( parts[0].toLower() == "rgba"){
                if ( isFractional){
                   clr.setRgbF(component1,component2, component3);
                   clr.setAlphaF(component4);
                }
                else{
                    clr.setRgb(component1,component2, component3);
                    clr.setAlpha(component4);
                }
            }else if ( parts[0].toLower() == "hsla"){
                if ( isFractional){
                   clr.setHslF(component1,component2, component3);
                   clr.setAlphaF(component4);
                }
                else{
                    clr.setHsl(component1,component2, component3);
                    clr.setAlpha(component4);
                }

            } else if ( parts[0].toLower() == "cmyka" && parts.size() == 6){
                if ( isFractional){
                   clr.setCmykF(component1,component2, component3, component4);
                   clr.setAlphaF(component5);
                }
                else{
                    clr.setCmyk(component1,component2, component3, component4);
                    clr.setAlpha(component5);
                }
            }
            return clr;
        }
    } else if( v.type() == QVariant::ULongLong){
        return ColorRangeBase::toColor(v.toULongLong(),colormodel);
    } else if( v.type() == QVariant::Double){
        return ColorRangeBase::toColor(v.toULongLong(),colormodel);
    }

    return QColor();
}
bool RasterCoverageConnector::handlePaletteCase(Size<> &rastersize, RasterCoverage* raster) {

    auto layerHandle = gdal()->getRasterBand(_handle->handle(), 1);
    auto paletteHandle = gdal()->getColorPalette(layerHandle);
    ColorPalette *palette = new ColorPalette();

    if (!paletteHandle)
        return false;
    int count = gdal()->getColorPaletteSize(paletteHandle);
    if ( count == 0)
        return false;
    ColorRangeBase::ColorModel model;
    GDALPaletteInterp colorType = gdal()->getPaletteColorInterpretation(paletteHandle);
    for(int i = 0; i < count; ++i) {

        GDALColorEntry *entry = gdal()->getColorPaletteEntry(paletteHandle, i);
        if ( !entry)
            continue;
        QColor clr;
        switch ( colorType){
        case GPI_RGB:
            clr.setRgb(entry->c1, entry->c2, entry->c3);
            model = ColorRangeBase::cmRGBA;
            break;
        case GPI_HLS:
            clr.setHsl(entry->c1, entry->c2, entry->c3); break;
            model = ColorRangeBase::cmHSLA;
            break;
        case GPI_CMYK:
            clr.setCmyk(entry->c1, entry->c2, entry->c3, entry->c4);
            model = ColorRangeBase::cmCYMKA;
            break;
        case GPI_Gray:
            clr.setRgb(entry->c1, entry->c1, entry->c1);
            model = ColorRangeBase::cmGREYSCALE;
        }
        clr.setAlpha(entry->c4);
        palette->add(new ColorItem(clr));

    }
    palette->defaultColorModel(model);

    _typeSize = 1;
    _gdalValueType = gdal()->rasterDataType(layerHandle);
    raster->datadefRef() = DataDefinition(IDomain("colorpalette"), reinterpret_cast<Range *>(palette));

    return true;
}
Example #3
0
QColor ColorRangeBase::toColor(quint64 clrint, ColorModel clrModel)
{

    LocalColor *localcolor = reinterpret_cast<LocalColor *>(&clrint);

    QColor clr;
    if ( clrModel == ColorRangeBase::cmRGBA){
        clr = QColor(localcolor->_component3, localcolor->_component2,localcolor->_component1);
        clr.setAlpha(localcolor->_component4);
    }
    else if ( clrModel ==  ColorRangeBase::cmHSLA){
        clr.setHsl(localcolor->_component1,localcolor->_component2, localcolor->_component3);
        clr.setAlpha(localcolor->_component4);
    } else if ( clrModel ==  ColorRangeBase::cmCYMKA){
        clr.setCmyk(localcolor->_component1,localcolor->_component2, localcolor->_component3, localcolor->_component4);
        //clr.setAlpha(localcolor->_component4); ??
    }
    return clr;
}
Example #4
0
void ColorRangeBase::loadColor(QColor& clr, QDataStream &stream){
    int c1, c2, c3, c4;

    stream >> c1 >> c2 >> c3 >> c4;

    switch (defaultColorModel()){
    case ColorRangeBase::cmRGBA:
        clr.setRgb(c1,c2,c3);
        clr.setAlpha(c4);
        break;
    case ColorRangeBase::cmHSLA:
        clr.setHsl(c1,c2,c3);
        clr.setAlpha(c4);
        break;
    case ColorRangeBase::cmCYMKA:
        clr.setCmyk(c1,c2,c3, c4);
        break;
    case ColorRangeBase::cmGREYSCALE:
        stream << clr.red();
    default:
        break;
    }
}
Example #5
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);
        }
    }
}
Example #6
0
void SceneEditor::slotColorTool()
{
    FixtureConsole* fc;
    Fixture* fxi;
    QColor color;
    quint32 cyan, magenta, yellow;
    quint32 red, green, blue;

    /* QObject cast fails unless the widget is a FixtureConsole */
    fc = qobject_cast<FixtureConsole*> (m_tab->currentWidget());
    if (fc == NULL)
        return;

    fxi = _app->doc()->fixture(fc->fixture());
    Q_ASSERT(fxi != NULL);

    cyan = fxi->channel("cyan", Qt::CaseInsensitive, QLCChannel::Colour);
    magenta = fxi->channel("magenta", Qt::CaseInsensitive, QLCChannel::Colour);
    yellow = fxi->channel("yellow", Qt::CaseInsensitive, QLCChannel::Colour);
    red = fxi->channel("red", Qt::CaseInsensitive, QLCChannel::Colour);
    green = fxi->channel("green", Qt::CaseInsensitive, QLCChannel::Colour);
    blue = fxi->channel("blue", Qt::CaseInsensitive, QLCChannel::Colour);

    if (cyan != QLCChannel::invalid() && magenta != QLCChannel::invalid() &&
            yellow != QLCChannel::invalid())
    {
        color.setCmyk(fc->channel(cyan)->sliderValue(),
                      fc->channel(magenta)->sliderValue(),
                      fc->channel(yellow)->sliderValue(), 0);

        color = QColorDialog::getColor(color);
        if (color.isValid() == true)
        {
            fc->channel(cyan)->setValue(color.cyan());
            fc->channel(magenta)->setValue(color.magenta());
            fc->channel(yellow)->setValue(color.yellow());

            fc->channel(cyan)->enable(true);
            fc->channel(magenta)->enable(true);
            fc->channel(yellow)->enable(true);
        }
    }
    else if (red != QLCChannel::invalid() && green != QLCChannel::invalid() &&
             blue != QLCChannel::invalid())
    {
        color.setRgb(fc->channel(red)->sliderValue(),
                     fc->channel(green)->sliderValue(),
                     fc->channel(blue)->sliderValue(), 0);

        color = QColorDialog::getColor(color);
        if (color.isValid() == true)
        {
            fc->channel(red)->setValue(color.red());
            fc->channel(green)->setValue(color.green());
            fc->channel(blue)->setValue(color.blue());

            fc->channel(red)->enable(true);
            fc->channel(green)->enable(true);
            fc->channel(blue)->enable(true);
        }
    }
}
Example #7
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;
}