Coverage Report

Created: 2023-12-08 06:53

/src/freeimage-svn/FreeImage/trunk/Source/OpenEXR/IlmImf/ImfDeepCompositing.cpp
Line
Count
Source (jump to first uncovered line)
1
///////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (c) 2012, Weta Digital Ltd
4
// 
5
// All rights reserved.
6
// 
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
// *       Redistributions of source code must retain the above copyright
11
// notice, this list of conditions and the following disclaimer.
12
// *       Redistributions in binary form must reproduce the above
13
// copyright notice, this list of conditions and the following disclaimer
14
// in the documentation and/or other materials provided with the
15
// distribution.
16
// *       Neither the name of Weta Digital nor the names of
17
// its contributors may be used to endorse or promote products derived
18
// from this software without specific prior written permission. 
19
// 
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
//
32
///////////////////////////////////////////////////////////////////////////
33
34
#include "ImfDeepCompositing.h"
35
36
#include "ImfNamespace.h"
37
#include <algorithm>
38
#include <vector>
39
40
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
41
42
using std::sort;
43
using std::vector;
44
DeepCompositing::DeepCompositing()
45
0
{
46
0
}
47
48
DeepCompositing::~DeepCompositing()
49
0
{
50
0
}
51
52
void 
53
DeepCompositing::composite_pixel (float outputs[],
54
                                  const float* inputs[],
55
                                  const char*channel_names[],
56
                                  int num_channels,
57
                                  int num_samples,
58
                                  int sources)
59
0
{
60
0
    for(int i=0;i<num_channels;i++) outputs[i]=0.0;
61
    // no samples? do nothing
62
0
   if(num_samples==0)
63
0
   {
64
0
       return;
65
0
   }
66
   
67
0
   vector<int> sort_order;
68
0
   if(sources>1)
69
0
   {
70
0
       sort_order.resize(num_samples);
71
0
       for(int i=0;i<num_samples;i++) sort_order[i]=i;
72
0
       sort(&sort_order[0],inputs,channel_names,num_channels,num_samples,sources);
73
0
   }
74
   
75
   
76
0
   for(int i=0;i<num_samples;i++)
77
0
   {
78
0
       int s=(sources>1) ? sort_order[i] : i;
79
0
       float alpha=outputs[2]; 
80
0
       if(alpha>=1.0) return;
81
       
82
0
       for(int c=0;c<num_channels;c++)
83
0
       {
84
0
           outputs[c]+=(1.0-alpha)*inputs[c][s];
85
0
       }
86
0
   }   
87
0
}
88
89
struct sort_helper
90
{
91
    const float ** inputs;
92
    bool operator() (int a,int b) 
93
0
    {
94
0
        if(inputs[0][a] < inputs[0][b]) return true;
95
0
        if(inputs[0][a] > inputs[0][b]) return false;
96
0
        if(inputs[1][a] < inputs[1][b]) return true;
97
0
        if(inputs[1][a] > inputs[1][b]) return false;
98
0
        return a<b;
99
0
    }
100
0
    sort_helper(const float ** i) : inputs(i) {}
101
};
102
103
void
104
DeepCompositing::sort(int order[], const float* inputs[], const char* channel_names[], int num_channels, int num_samples, int sources)
105
0
{
106
0
  std::sort(order+0,order+num_samples,sort_helper(inputs));
107
0
}
108
109
110
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT