Fix T46641: Bicubic transform on ID channel is not bicubic

Better support of bicubic sampling of ID mask output.

The idea is to generate ID mask into a temporary buffer which is then being
interpolated using current sampling method.

This works fine for upscaling or rotating the ID mask but does not work for
scaling down. This is much-much bigger problem of the compositor design and
can't really be solved currently. Same will happen with other nodes like
blur for example.

Reviewers: campbellbarton

Subscribers: ania

Differential Revision: https://developer.blender.org/D1612
This commit is contained in:
Sergey Sharybin 2015-11-08 08:16:04 +05:00
parent 03e8202b7b
commit 63f2f82f92
Notes: blender-bot 2023-02-14 08:28:50 +01:00
Referenced by issue #46641, Bicubic transform on ID channel is not bicubic
2 changed files with 17 additions and 37 deletions

View File

@ -26,26 +26,23 @@ IDMaskOperation::IDMaskOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_VALUE);
this->m_inputProgram = NULL;
}
void IDMaskOperation::initExecution()
{
this->m_inputProgram = this->getInputSocketReader(0);
this->setComplex(true);
}
void IDMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
void *IDMaskOperation::initializeTileData(rcti *rect)
{
float inputValue[4];
this->m_inputProgram->readSampled(inputValue, x, y, sampler);
/* 'round' since sampling may adjust value slightly.
* ID-mask input are originally integers too. */
const float a = (roundf(inputValue[0]) == this->m_objectIndex) ? 1.0f : 0.0f;
output[0] = a;
void *buffer = getInputOperation(0)->initializeTileData(rect);
return buffer;
}
void IDMaskOperation::deinitExecution()
void IDMaskOperation::executePixel(float output[4],
int x,
int y,
void *data)
{
this->m_inputProgram = NULL;
MemoryBuffer *input_buffer = (MemoryBuffer *)data;
const int buffer_width = input_buffer->getWidth();
float *buffer = input_buffer->getBuffer();
int buffer_index = (y * buffer_width + x);
output[0] = (roundf(buffer[buffer_index]) == this->m_objectIndex) ? 1.0f : 0.0f;
}

View File

@ -27,30 +27,13 @@
class IDMaskOperation : public NodeOperation {
private:
/**
* Cached reference to the inputProgram
*/
SocketReader *m_inputProgram;
float m_objectIndex;
public:
IDMaskOperation();
/**
* the inner loop of this program
*/
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
/**
* Initialize the execution
*/
void initExecution();
/**
* Deinitialize the execution
*/
void deinitExecution();
void *initializeTileData(rcti *rect);
void executePixel(float output[4], int x, int y, void *data);
void setObjectIndex(float objectIndex) { this->m_objectIndex = objectIndex; }
};