Ejemplo n.º 1
0
Range *ColorPalette::clone() const
{
    ColorPalette *palette = new ColorPalette();
    for(const auto& item : _colors){
        palette->add( item->clone());
    }
    palette->defaultColorModel(defaultColorModel());

    return palette;
}
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;
}
bool CreatePaletteDomain::execute(ExecutionContext *ctx, SymbolTable &symTable)
{
    if (_prepState == sNOTPREPARED)
        if((_prepState = prepare(ctx, symTable)) != sPREPARED)
            return false;

    IColorDomain colordomain;
    colordomain.prepare();
    colordomain->setDescription(_domaindesc);

    if ( _parentdomain.isValid())
        colordomain->setParent(_parentdomain);
    ColorPalette *palette = new ColorPalette();
    for(int i=0; i < _items.size(); ++i){
        palette->add(new ColorItem(_items[i]));
    }
    colordomain->range(palette);

    QVariant value;
    value.setValue<IDomain>(colordomain);
    ctx->setOutput(symTable,value,colordomain->name(),itDOMAIN,colordomain->source());

    return true;
}