|
Packit |
0d464f |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Copyright (c) 2012, Weta Digital Ltd
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// All rights reserved.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
0d464f |
// modification, are permitted provided that the following conditions are
|
|
Packit |
0d464f |
// met:
|
|
Packit |
0d464f |
// * Redistributions of source code must retain the above copyright
|
|
Packit |
0d464f |
// notice, this list of conditions and the following disclaimer.
|
|
Packit |
0d464f |
// * Redistributions in binary form must reproduce the above
|
|
Packit |
0d464f |
// copyright notice, this list of conditions and the following disclaimer
|
|
Packit |
0d464f |
// in the documentation and/or other materials provided with the
|
|
Packit |
0d464f |
// distribution.
|
|
Packit |
0d464f |
// * Neither the name of Weta Digital nor the names of
|
|
Packit |
0d464f |
// its contributors may be used to endorse or promote products derived
|
|
Packit |
0d464f |
// from this software without specific prior written permission.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
0d464f |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
0d464f |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit |
0d464f |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
0d464f |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
0d464f |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
0d464f |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
0d464f |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
0d464f |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
0d464f |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
0d464f |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include "ImfDeepCompositing.h"
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include "ImfNamespace.h"
|
|
Packit |
0d464f |
#include <algorithm>
|
|
Packit |
0d464f |
#include <vector>
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
using std::sort;
|
|
Packit |
0d464f |
using std::vector;
|
|
Packit |
0d464f |
DeepCompositing::DeepCompositing()
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
DeepCompositing::~DeepCompositing()
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
DeepCompositing::composite_pixel (float outputs[],
|
|
Packit |
0d464f |
const float* inputs[],
|
|
Packit |
0d464f |
const char*channel_names[],
|
|
Packit |
0d464f |
int num_channels,
|
|
Packit |
0d464f |
int num_samples,
|
|
Packit |
0d464f |
int sources)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for(int i=0;i
|
|
Packit |
0d464f |
// no samples? do nothing
|
|
Packit |
0d464f |
if(num_samples==0)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
vector<int> sort_order;
|
|
Packit |
0d464f |
if(sources>1)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
sort_order.resize(num_samples);
|
|
Packit |
0d464f |
for(int i=0;i
|
|
Packit |
0d464f |
sort(&sort_order[0],inputs,channel_names,num_channels,num_samples,sources);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for(int i=0;i
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
int s=(sources>1) ? sort_order[i] : i;
|
|
Packit |
0d464f |
float alpha=outputs[2];
|
|
Packit |
0d464f |
if(alpha>=1.0) return;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for(int c=0;c
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
outputs[c]+=(1.0-alpha)*inputs[c][s];
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
struct sort_helper
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
const float ** inputs;
|
|
Packit |
0d464f |
bool operator() (int a,int b)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
if(inputs[0][a] < inputs[0][b]) return true;
|
|
Packit |
0d464f |
if(inputs[0][a] > inputs[0][b]) return false;
|
|
Packit |
0d464f |
if(inputs[1][a] < inputs[1][b]) return true;
|
|
Packit |
0d464f |
if(inputs[1][a] > inputs[1][b]) return false;
|
|
Packit |
0d464f |
return a
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
sort_helper(const float ** i) : inputs(i) {}
|
|
Packit |
0d464f |
};
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
DeepCompositing::sort(int order[], const float* inputs[], const char* channel_names[], int num_channels, int num_samples, int sources)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
std::sort(order+0,order+num_samples,sort_helper(inputs));
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
|