Skip to content

Commit e6ee25d

Browse files
authored
Merge pull request #95 from charlesangus/fix-keymix-edge
fix keymix edge
2 parents b58b107 + 0773970 commit e6ee25d

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/DeepCKeymix.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ class DeepCKeymix : public DeepFilterOp
147147
if (!input0())
148148
return;
149149

150-
ChannelSet requestChannels = channels;
151-
requestChannels += Mask_Deep;
150+
ChannelSet requestChannels = _processChannelSet;
152151
requests.push_back(RequestData(input0(), box, requestChannels, count));
153152

154153
if (_aOp != nullptr)
@@ -163,17 +162,20 @@ class DeepCKeymix : public DeepFilterOp
163162

164163
bool doDeepEngine(DD::Image::Box box, const ChannelSet &requestedChannels, DeepOutputPlane &plane) override
165164
{
165+
166+
ChannelSet process = requestedChannels;
167+
process += _processChannelSet;
168+
166169
DeepOp *_bOp = input0();
167170
if (!_bOp)
168171
return true;
169172

170173
DeepPlane bPlane;
171-
if (!_bOp->deepEngine(box, requestedChannels, bPlane))
174+
if (!_bOp->deepEngine(box, process, bPlane))
172175
return false;
173176

174-
DeepInPlaceOutputPlane outPlane(requestedChannels, box);
177+
DeepInPlaceOutputPlane outPlane(process, box);
175178
outPlane.reserveSamples(bPlane.getTotalSampleCount());
176-
177179
if (_bypass)
178180
{
179181
for (Box::iterator it = box.begin(), itEnd = box.end(); it != itEnd; ++it)
@@ -200,7 +202,7 @@ class DeepCKeymix : public DeepFilterOp
200202
else
201203
{
202204
DeepPlane aPlane;
203-
if (!_aOp->deepEngine(box, requestedChannels, aPlane))
205+
if (!_aOp->deepEngine(box, process, aPlane))
204206
return false;
205207

206208
float maskVal;
@@ -217,13 +219,12 @@ class DeepCKeymix : public DeepFilterOp
217219
{
218220
_maskOp->get(it.y, box.x(), box.r(), maskChannel, maskRow);
219221
maskVal = maskRow[maskChannel][it.x];
220-
maskVal = clamp(maskVal);
222+
maskVal = clamp(maskVal, 0.0f, 1.0f);
221223
currentYRow = it.y;
222224
}
223225
else
224226
{
225-
maskVal = maskRow[maskChannel][it.x];
226-
maskVal = clamp(maskVal);
227+
maskVal = clamp(maskRow[maskChannel][it.x], 0.0f, 1.0f);
227228
}
228229

229230
if (invertMask)
@@ -235,15 +236,14 @@ class DeepCKeymix : public DeepFilterOp
235236
DeepPixel bPixel = bPlane.getPixel(it);
236237

237238
size_t inPixelSamples;
238-
239239
int aSampleNo = aPixel.getSampleCount();
240240
int bSampleNo = bPixel.getSampleCount();
241241

242242
if (maskVal == 0.0f)
243243
{
244244
inPixelSamples = bSampleNo;
245245
}
246-
else if (maskVal * mix == 1.0f)
246+
else if (maskVal * mix >= 1.0f)
247247
{
248248
inPixelSamples = aSampleNo;
249249
}
@@ -268,26 +268,28 @@ class DeepCKeymix : public DeepFilterOp
268268
float mixing = maskVal * mix;
269269
for (size_t sampleNo = 0; sampleNo < inPixelSamples; sampleNo++)
270270
{
271-
foreach (z, requestedChannels)
271+
foreach (z, process)
272272
{
273+
float &outData = outPixel.getWritableUnorderedSample(sampleNo, z);
274+
273275
int cIndex = colourIndex(z);
274276

275-
float &outData = outPixel.getWritableUnorderedSample(sampleNo, z);
276-
if (maskVal == 0.0f)
277+
if ((mixing <= 0.0f))
277278
{
278279
outData = bPixel.getUnorderedSample(sampleNo, z);
279280
}
280-
else if (mixing == 1.0f)
281-
{
282-
outData = aPixel.getUnorderedSample(sampleNo, z);
283-
}
284-
else
281+
if ((mixing > 0.0f) && (mixing < 1.0f))
285282
{
283+
if ((z == Chan_DeepFront) || (z == Chan_DeepBack))
284+
continue;
285+
286+
float bInData = 0.0f;
287+
286288
if (sampleNo < bSampleNo)
287289
{
288-
const float &bInData = bInPixelChannels.contains(z)
289-
? bPixel.getUnorderedSample(sampleNo, z)
290-
: 0.0f;
290+
bInData = bInPixelChannels.contains(z)
291+
? bPixel.getUnorderedSample(sampleNo, z)
292+
: 0.0f;
291293

292294
outData = (1.0f - mixing) * bInData;
293295
}
@@ -296,9 +298,13 @@ class DeepCKeymix : public DeepFilterOp
296298
const float &aInData = aInPixelChannels.contains(z)
297299
? aPixel.getUnorderedSample(sampleNo - bSampleNo, z)
298300
: 0.0f;
299-
outData = aInData * mixing;
301+
outData = (aInData * mixing) + bInData;
300302
}
301303
}
304+
if (mixing >= 1.0f)
305+
{
306+
outData = aPixel.getUnorderedSample(sampleNo, z);
307+
}
302308
}
303309
}
304310
}

0 commit comments

Comments
 (0)