diff --git a/src/libOpenImageIO/deepdata.cpp b/src/libOpenImageIO/deepdata.cpp index ff015fb346..dba16b661d 100644 --- a/src/libOpenImageIO/deepdata.cpp +++ b/src/libOpenImageIO/deepdata.cpp @@ -1033,7 +1033,8 @@ namespace { // Comparator functor for depth sorting sample indices of a deep pixel. class SampleComparator { public: - SampleComparator(const DeepData& dd, int pixel, int zchan, int zbackchan) + SampleComparator(const DeepData& dd, int64_t pixel, int zchan, + int zbackchan) : deepdata(dd) , pixel(pixel) , zchan(zchan) @@ -1057,7 +1058,7 @@ class SampleComparator { private: const DeepData& deepdata; - int pixel; + int64_t pixel; int zchan, zbackchan; }; @@ -1071,7 +1072,7 @@ DeepData::sort(int64_t pixel) int zchan = m_impl->m_z_channel; if (zchan < 0) return; // No channel labeled Z -- we don't know what to do - int zbackchan = m_impl->m_z_channel; + int zbackchan = m_impl->m_zback_channel; if (zbackchan < 0) zbackchan = zchan; int nsamples = samples(pixel); @@ -1121,14 +1122,9 @@ DeepData::merge_overlaps(int64_t pixel) continue; // Not color or alpha if (alphachan == c) continue; // Adjust the alphas in a second pass below - float a1 = (alphachan < 0) - ? 1.0f - : clamp(deep_value(pixel, alphachan, s - 1), - 0.0f, 1.0f); - float a2 = (alphachan < 0) - ? 1.0f - : clamp(deep_value(pixel, alphachan, s), 0.0f, - 1.0f); + float a1 = clamp(deep_value(pixel, alphachan, s - 1), 0.0f, + 1.0f); + float a2 = clamp(deep_value(pixel, alphachan, s), 0.0f, 1.0f); float c1 = deep_value(pixel, c, s - 1); float c2 = deep_value(pixel, c, s); float am = a1 + a2 - a1 * a2; @@ -1155,14 +1151,9 @@ DeepData::merge_overlaps(int64_t pixel) int alphachan = m_impl->m_myalphachannel[c]; if (alphachan != c) continue; // This pass is only for alphas - float a1 = (alphachan < 0) - ? 1.0f - : clamp(deep_value(pixel, alphachan, s - 1), - 0.0f, 1.0f); - float a2 = (alphachan < 0) - ? 1.0f - : clamp(deep_value(pixel, alphachan, s), 0.0f, - 1.0f); + float a1 = clamp(deep_value(pixel, alphachan, s - 1), 0.0f, + 1.0f); + float a2 = clamp(deep_value(pixel, alphachan, s), 0.0f, 1.0f); float am = a1 + a2 - a1 * a2; set_deep_value(pixel, c, s - 1, am); // setting alpha } diff --git a/testsuite/python-deep/ref/out.txt b/testsuite/python-deep/ref/out.txt index 8b268040d7..788944e73c 100644 --- a/testsuite/python-deep/ref/out.txt +++ b/testsuite/python-deep/ref/out.txt @@ -104,19 +104,19 @@ Testing sort... Before z sort, dd has 2 pixels, 6 channels. Channel indices: Z= 4 Zback= 5 A= 3 AR= 3 AG= 3 AB= 3 Nsamples[ 0 ] = 4 (capacity= 4 ) samples: - 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 / + 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 / 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 / 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 / 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 / Nsamples[ 1 ] = 4 (capacity= 4 ) samples: - 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 / + 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 / 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 / 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 / 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 / After z sort of pixel 1, dd has 2 pixels, 6 channels. Channel indices: Z= 4 Zback= 5 A= 3 AR= 3 AG= 3 AB= 3 Nsamples[ 0 ] = 4 (capacity= 4 ) samples: - 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 / + 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 / 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 / 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 / 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 / @@ -124,7 +124,7 @@ After z sort of pixel 1, dd has 2 pixels, 6 channels. 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 / 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 / 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 / - 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 / + 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 / Testing merge_overlaps... Before merge_overlaps, dd has 2 pixels, 6 channels. diff --git a/testsuite/python-deep/src/test_deep.py b/testsuite/python-deep/src/test_deep.py index 14208eeceb..251735afc4 100755 --- a/testsuite/python-deep/src/test_deep.py +++ b/testsuite/python-deep/src/test_deep.py @@ -134,6 +134,8 @@ def test_sample_sort () : dd.set_deep_value (p, 3, s, 0.5) # A dd.set_deep_value (p, 4, s, 20.0 - s) # Z: decreasing! dd.set_deep_value (p, 5, s, 20.0 - s + 0.5) # Zback + # Make sample 0's Z tie with sample 1's so that sort falls back to Zback + dd.set_deep_value (p, 4, 0, 19) # sample 0, Z=19 (was 20) print_deep_image (dd, "Before z sort,") dd.sort (1) print_deep_image (dd, "After z sort of pixel 1,")