Skip to content

Commit

Permalink
More code in cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jul 8, 2023
1 parent bd9dbe8 commit 7b0692a
Show file tree
Hide file tree
Showing 3 changed files with 437 additions and 412 deletions.
31 changes: 0 additions & 31 deletions libs/yocto/yocto_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,37 +174,6 @@ constexpr kernel vec3f saturate(const vec3f& rgb, float saturation,
return max(grey + (rgb - grey) * (saturation * 2), 0);
}

// Convert channels
template <size_t M, typename T, size_t N>
constexpr kernel vec<T, M> convert_channels(const vec<T, N>& color) {
constexpr auto a1 = std::is_same_v<T, byte> ? (byte)255 : 1.0f;
if constexpr (N == M) {
return color;
} else if constexpr (N == 1) {
if constexpr (M == 1) return {color[0]};
if constexpr (M == 2) return {color[0], a1};
if constexpr (M == 3) return {color[0], color[0], color[0]};
if constexpr (M == 4) return {color[0], color[0], color[0], a1};
} else if constexpr (N == 2) {
if constexpr (M == 1) return {color[0]};
if constexpr (M == 2) return {color[0], color[1]};
if constexpr (M == 3) return {color[0], color[0], color[0]};
if constexpr (M == 4) return {color[0], color[0], color[0], color[1]};
} else if constexpr (N == 3) {
if constexpr (M == 1) return {mean(color[0])};
if constexpr (M == 2) return {mean(color[0]), a1};
if constexpr (M == 3) return {color[0], color[1], color[2]};
if constexpr (M == 4) return {color[0], color[1], color[2], a1};
} else if constexpr (N == 4) {
if constexpr (M == 1) return {mean(color[0])};
if constexpr (M == 2) return {mean(color[0]), color[3]};
if constexpr (M == 3) return {color[0], color[1], color[2]};
if constexpr (M == 4) return {color[0], color[1], color[2], color[3]};
} else {
return vec<T, M>{0};
}
}

#ifndef __CUDACC__

// Filmic tonemapping
Expand Down
Loading

0 comments on commit 7b0692a

Please sign in to comment.