示例#1
0
bool KisKraLoadVisitor::loadPaintDeviceFrame(KisPaintDeviceSP device, const QString &location, DevicePolicy policy)
{
    if (m_store->open(location)) {
        if (!policy.read(device, m_store->device())) {
            m_errorMessages << i18n("Could not read pixel data: %1.", location);
            device->disconnect();
            m_store->close();
            return false;
        }
        m_store->close();
    } else {
        m_errorMessages << i18n("Could not load pixel data: %1.", location);
        return false;
    }
    if (m_store->open(location + ".defaultpixel")) {
        int pixelSize = device->colorSpace()->pixelSize();
        if (m_store->size() == pixelSize) {
            KoColor color(Qt::transparent, device->colorSpace());
            m_store->read((char*)color.data(), pixelSize);
            policy.setDefaultPixel(device, color);
        }
        m_store->close();
    }

    return true;
}
bool KisKraSaveVisitor::savePaintDevice(KisPaintDeviceSP device,
                                        QString location)
{
    // Layer data
    KisConfig cfg;
    m_store->setCompressionEnabled(cfg.compressKra());

    if (m_store->open(location)) {
        if (!device->write(*m_writer)) {
            device->disconnect();
            m_store->close();
            return false;
        }

        m_store->close();
    }
    if (m_store->open(location + ".defaultpixel")) {
        m_store->write((char*)device->defaultPixel(), device->colorSpace()->pixelSize());
        m_store->close();
    }
    m_store->setCompressionEnabled(true);
    return true;
}