boostorg / boostorg/gil

Channel arithmetics

Open
#204 2 comments 0 reactions 2 assignees Claimed by @stefanseefeld View on GitHub
cat/enhancement cat/feature cat/performance status/need-feedback
Dominant language
C++
Stars
199
Forks
171
Avg merge
1d 14h
Merged PRs (30d)
10

Description

Not really an issue but a following up of the discussion in #191.

# Type conversions / promotions

Let's consider for instance the current implementation of `channel_divides_t`:

```c++
template
struct channel_divides_t {
ChannelR operator()(typename channel_traits::const_reference ch1,
typename channel_traits::const_reference ch2) const {
return ChannelR(ch1)/ChannelR(ch2);
}
};
```

The current casting / promotion policy of the channel values is "explicit conversion of operands", but this is problematic for some use cases. Given `ChannelR = int`:

- `int{128} / int{0.8};` (current implementation) gives div by zero.
- `int{128 / d0.8};` gives the expected result.

# Optimization

The current implementation comes with the following warning:

```c++
/// this is a generic implementation; user should specialize it for better performance
```

Does anyone knows what the original authors had in mind?

# Pixel arithmetic operators

I wonder if we could offer pixel arithmetic with operators, something like this:

```c++
template
pixel& operator+(const Pixel& rhs)
{
static_transform(*this, rhs, pixel_plus_t());
return *this;
}
```

Expression templates could be used to remove the temporary values but that may be overkill.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.