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;
}