Commit 6d920bb1 authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Fix backward compatibility of adjustment curves

Older versions supported fewer adjustable channels, so we can no longer
assume the count in configuration data to matches exactly.

BUG: 396625
parent b418fc41
......@@ -262,9 +262,10 @@ KoColorTransformation* KisCrossChannelFilter::createTransformation(const KoColor
const QList<KisCubicCurve> &curves = configBC->curves();
const QVector<int> &drivers = configBC->driverChannels();
const QVector<VirtualChannelInfo> virtualChannels = KisMultiChannelFilter::getVirtualChannels(cs);
const QVector<VirtualChannelInfo> virtualChannels =
KisMultiChannelFilter::getVirtualChannels(cs, originalTransfers.size());
if (originalTransfers.size() != int(virtualChannels.size())) {
if (originalTransfers.size() > int(virtualChannels.size())) {
// We got an illegal number of colorchannels :(
return 0;
}
......
......@@ -65,7 +65,7 @@ bool KisMultiChannelFilter::needsTransparentPixels(const KisFilterConfigurationS
return cs->colorModelId() == AlphaColorModelID;
}
QVector<VirtualChannelInfo> KisMultiChannelFilter::getVirtualChannels(const KoColorSpace *cs)
QVector<VirtualChannelInfo> KisMultiChannelFilter::getVirtualChannels(const KoColorSpace *cs, int maxChannels)
{
const bool supportsLightness =
cs->colorModelId() != LABAColorModelID &&
......@@ -102,6 +102,10 @@ QVector<VirtualChannelInfo> KisMultiChannelFilter::getVirtualChannels(const KoCo
vchannels << VirtualChannelInfo(VirtualChannelInfo::LIGHTNESS, -1, 0, cs);
}
if (maxChannels >= 0 && vchannels.size() > maxChannels) {
vchannels.resize(maxChannels);
}
return vchannels;
}
......@@ -375,12 +379,19 @@ void KisMultiChannelConfigWidget::setConfiguration(const KisPropertiesConfigurat
setConfiguration(defaultConfiguration);
return;
}
} else if (cfg->curves().size() != int(m_virtualChannels.size())) {
warnKrita << "WARNING: trying to load a curve with incorrect number of channels!";
} else if (cfg->curves().size() > m_virtualChannels.size()) {
warnKrita << "WARNING: trying to load a curve with invalid number of channels!";
warnKrita << "WARNING: expected:" << m_virtualChannels.size();
warnKrita << "WARNING: got:" << cfg->curves().size();
return;
} else {
if (cfg->curves().size() < m_virtualChannels.size()) {
// The configuration does not cover all our channels.
// This happens when loading a document from an older version, which supported fewer channels.
// Reset to make sure the unspecified channels have their default values.
resetCurves();
}
for (int ch = 0; ch < cfg->curves().size(); ch++) {
m_curves[ch] = cfg->curves()[ch];
}
......
......@@ -40,7 +40,12 @@ class KisMultiChannelFilter : public KisColorTransformationFilter
public:
bool needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const override;
static QVector<VirtualChannelInfo> getVirtualChannels(const KoColorSpace *cs);
/**
* Get a list of adjustable channels for the color space.
* If maxChannels is non-negative, the number of channels is capped to the number. This is useful configurations
* from older documents (created in versions which supported fewer channels).
*/
static QVector<VirtualChannelInfo> getVirtualChannels(const KoColorSpace *cs, int maxChannels = -1);
static int findChannel(const QVector<VirtualChannelInfo> &virtualChannels, const VirtualChannelInfo::Type &channelType);
protected:
......
......@@ -175,9 +175,10 @@ KoColorTransformation* KisPerChannelFilter::createTransformation(const KoColorSp
* transforms in display order? Why on Earth it works?! Is it
* documented anywhere?
*/
const QVector<VirtualChannelInfo> virtualChannels = KisMultiChannelFilter::getVirtualChannels(cs);
const QVector<VirtualChannelInfo> virtualChannels =
KisMultiChannelFilter::getVirtualChannels(cs, originalTransfers.size());
if (originalTransfers.size() != int(virtualChannels.size())) {
if (originalTransfers.size() > int(virtualChannels.size())) {
// We got an illegal number of colorchannels :(
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment