Skip to content

Commit d5bef73

Browse files
committed
fix(deepdata): correct Zback channel in sort(), change int pixel to int64_t
- Fix sort() using the front Z channel instead of Zback channel. - Widen pixel indices from int to int64_t (leftover from AcademySoftwareFoundation#2363). - Cleanup unreachable branches in merge_overlaps(). Signed-off-by: Luna Kim <177369799+luna-y-kim@users.noreply.github.com>
1 parent 264514d commit d5bef73

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

src/include/OpenImageIO/deepdata.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ class OIIO_API DeepData {
188188
/// Merge the samples of `src`'s pixel into this `DeepData`'s pixel.
189189
/// Return `true` if ok, `false` if the operation could not be
190190
/// performed.
191-
void merge_deep_pixels(int64_t pixel, const DeepData& src, int srcpixel);
191+
void merge_deep_pixels(int64_t pixel, const DeepData& src,
192+
int64_t srcpixel);
192193

193194
/// Return the z depth at which the pixel reaches full opacity.
194195
float opaque_z(int64_t pixel) const;

src/libOpenImageIO/deepdata.cpp

Lines changed: 12 additions & 20 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
}
@@ -1176,7 +1167,8 @@ DeepData::merge_overlaps(int64_t pixel)
11761167

11771168

11781169
void
1179-
DeepData::merge_deep_pixels(int64_t pixel, const DeepData& src, int srcpixel)
1170+
DeepData::merge_deep_pixels(int64_t pixel, const DeepData& src,
1171+
int64_t srcpixel)
11801172
{
11811173
int srcsamples = src.samples(srcpixel);
11821174
if (srcsamples == 0)

0 commit comments

Comments
 (0)