Skip to content

Commit 629becd

Browse files
authored
fix(deepdata): correct Zback channel in sort(), change int pixel to int64_t (#5241)
- Fix sort(), incorrectly using the front Z channel in a place where it should have instead used Zback channel. - Widen pixel indices from int to int64_t (internal only, follow-up to #2363). - Cleanup unreachable branches in merge_overlaps(). Modified the `DeepData::sort` test to include samples with a tied front Z, so it verifies the Zback fallback. Signed-off-by: Luna Kim <177369799+luna-y-kim@users.noreply.github.com>
1 parent b0de7d4 commit 629becd

3 files changed

Lines changed: 16 additions & 23 deletions

File tree

src/libOpenImageIO/deepdata.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,8 @@ namespace {
10331033
// Comparator functor for depth sorting sample indices of a deep pixel.
10341034
class SampleComparator {
10351035
public:
1036-
SampleComparator(const DeepData& dd, int pixel, int zchan, int zbackchan)
1036+
SampleComparator(const DeepData& dd, int64_t pixel, int zchan,
1037+
int zbackchan)
10371038
: deepdata(dd)
10381039
, pixel(pixel)
10391040
, zchan(zchan)
@@ -1057,7 +1058,7 @@ class SampleComparator {
10571058

10581059
private:
10591060
const DeepData& deepdata;
1060-
int pixel;
1061+
int64_t pixel;
10611062
int zchan, zbackchan;
10621063
};
10631064

@@ -1071,7 +1072,7 @@ DeepData::sort(int64_t pixel)
10711072
int zchan = m_impl->m_z_channel;
10721073
if (zchan < 0)
10731074
return; // No channel labeled Z -- we don't know what to do
1074-
int zbackchan = m_impl->m_z_channel;
1075+
int zbackchan = m_impl->m_zback_channel;
10751076
if (zbackchan < 0)
10761077
zbackchan = zchan;
10771078
int nsamples = samples(pixel);
@@ -1121,14 +1122,9 @@ DeepData::merge_overlaps(int64_t pixel)
11211122
continue; // Not color or alpha
11221123
if (alphachan == c)
11231124
continue; // Adjust the alphas in a second pass below
1124-
float a1 = (alphachan < 0)
1125-
? 1.0f
1126-
: clamp(deep_value(pixel, alphachan, s - 1),
1127-
0.0f, 1.0f);
1128-
float a2 = (alphachan < 0)
1129-
? 1.0f
1130-
: clamp(deep_value(pixel, alphachan, s), 0.0f,
1131-
1.0f);
1125+
float a1 = clamp(deep_value(pixel, alphachan, s - 1), 0.0f,
1126+
1.0f);
1127+
float a2 = clamp(deep_value(pixel, alphachan, s), 0.0f, 1.0f);
11321128
float c1 = deep_value(pixel, c, s - 1);
11331129
float c2 = deep_value(pixel, c, s);
11341130
float am = a1 + a2 - a1 * a2;
@@ -1155,14 +1151,9 @@ DeepData::merge_overlaps(int64_t pixel)
11551151
int alphachan = m_impl->m_myalphachannel[c];
11561152
if (alphachan != c)
11571153
continue; // This pass is only for alphas
1158-
float a1 = (alphachan < 0)
1159-
? 1.0f
1160-
: clamp(deep_value(pixel, alphachan, s - 1),
1161-
0.0f, 1.0f);
1162-
float a2 = (alphachan < 0)
1163-
? 1.0f
1164-
: clamp(deep_value(pixel, alphachan, s), 0.0f,
1165-
1.0f);
1154+
float a1 = clamp(deep_value(pixel, alphachan, s - 1), 0.0f,
1155+
1.0f);
1156+
float a2 = clamp(deep_value(pixel, alphachan, s), 0.0f, 1.0f);
11661157
float am = a1 + a2 - a1 * a2;
11671158
set_deep_value(pixel, c, s - 1, am); // setting alpha
11681159
}

testsuite/python-deep/ref/out.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,27 @@ Testing sort...
104104
Before z sort, dd has 2 pixels, 6 channels.
105105
Channel indices: Z= 4 Zback= 5 A= 3 AR= 3 AG= 3 AB= 3
106106
Nsamples[ 0 ] = 4 (capacity= 4 ) samples:
107-
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 20.00 / [5 Zback] 20.50 /
107+
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 20.50 /
108108
sample 1 : [0 R] 0.10 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 19.50 /
109109
sample 2 : [0 R] 0.20 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 18.00 / [5 Zback] 18.50 /
110110
sample 3 : [0 R] 0.30 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 17.00 / [5 Zback] 17.50 /
111111
Nsamples[ 1 ] = 4 (capacity= 4 ) samples:
112-
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 20.00 / [5 Zback] 20.50 /
112+
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 20.50 /
113113
sample 1 : [0 R] 0.10 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 19.50 /
114114
sample 2 : [0 R] 0.20 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 18.00 / [5 Zback] 18.50 /
115115
sample 3 : [0 R] 0.30 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 17.00 / [5 Zback] 17.50 /
116116
After z sort of pixel 1, dd has 2 pixels, 6 channels.
117117
Channel indices: Z= 4 Zback= 5 A= 3 AR= 3 AG= 3 AB= 3
118118
Nsamples[ 0 ] = 4 (capacity= 4 ) samples:
119-
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 20.00 / [5 Zback] 20.50 /
119+
sample 0 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 20.50 /
120120
sample 1 : [0 R] 0.10 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 19.50 /
121121
sample 2 : [0 R] 0.20 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 18.00 / [5 Zback] 18.50 /
122122
sample 3 : [0 R] 0.30 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 17.00 / [5 Zback] 17.50 /
123123
Nsamples[ 1 ] = 4 (capacity= 4 ) samples:
124124
sample 0 : [0 R] 0.30 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 17.00 / [5 Zback] 17.50 /
125125
sample 1 : [0 R] 0.20 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 18.00 / [5 Zback] 18.50 /
126126
sample 2 : [0 R] 0.10 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 19.50 /
127-
sample 3 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 20.00 / [5 Zback] 20.50 /
127+
sample 3 : [0 R] 0.00 / [1 G] 0.00 / [2 B] 0.00 / [3 A] 0.50 / [4 Z] 19.00 / [5 Zback] 20.50 /
128128

129129
Testing merge_overlaps...
130130
Before merge_overlaps, dd has 2 pixels, 6 channels.

testsuite/python-deep/src/test_deep.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def test_sample_sort () :
134134
dd.set_deep_value (p, 3, s, 0.5) # A
135135
dd.set_deep_value (p, 4, s, 20.0 - s) # Z: decreasing!
136136
dd.set_deep_value (p, 5, s, 20.0 - s + 0.5) # Zback
137+
# Make sample 0's Z tie with sample 1's so that sort falls back to Zback
138+
dd.set_deep_value (p, 4, 0, 19) # sample 0, Z=19 (was 20)
137139
print_deep_image (dd, "Before z sort,")
138140
dd.sort (1)
139141
print_deep_image (dd, "After z sort of pixel 1,")

0 commit comments

Comments
 (0)