Skip to content

Commit

Permalink
butano: color_effect::blend added
Browse files Browse the repository at this point in the history
  • Loading branch information
GValiente committed Oct 31, 2023
1 parent a7e0f61 commit 490a69c
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 70 deletions.
9 changes: 9 additions & 0 deletions butano/hw/include/bn_hw_palettes.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ namespace bn::hw::palettes

void hue_shift(const color* source_colors_ptr, int value, int count, color* destination_colors_ptr);

inline void blend(const color* first_source_colors_ptr, const color* second_source_colors_ptr,
int intensity, int count, color* destination_colors_ptr)
{
auto first_tonc_src_ptr = const_cast<COLOR*>(reinterpret_cast<const COLOR*>(first_source_colors_ptr));
auto second_tonc_src_ptr = const_cast<COLOR*>(reinterpret_cast<const COLOR*>(second_source_colors_ptr));
auto tonc_dst_ptr = reinterpret_cast<COLOR*>(destination_colors_ptr);
clr_blend_fast(first_tonc_src_ptr, second_tonc_src_ptr, tonc_dst_ptr, unsigned(count), unsigned(intensity));
}

inline void fade(const color* source_colors_ptr, color fade_color, int intensity, int count,
color* destination_colors_ptr)
{
Expand Down
37 changes: 23 additions & 14 deletions butano/include/bn_color_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,55 +92,64 @@ void invert(const span<const color>& source_colors_ref, span<color> destination_

/**
* @brief Applies a grayscale effect to all referenced colors.
* @param grayscale_intensity Grayscale effect intensity in the range [0..1].
* @param intensity Grayscale effect intensity in the range [0..1].
* @param colors_ref Colors reference.
*/
void grayscale(fixed grayscale_intensity, span<color> colors_ref);
void grayscale(fixed intensity, span<color> colors_ref);

/**
* @brief Applies a grayscale effect to all colors referenced by source_colors_ref,
* storing the result in destination_colors_ref.
* @param source_colors_ref Source colors reference.
* @param grayscale_intensity Grayscale effect intensity in the range [0..1].
* @param intensity Grayscale effect intensity in the range [0..1].
* @param destination_colors_ref Destination colors reference.
*/
void grayscale(const span<const color>& source_colors_ref, fixed grayscale_intensity,
span<color> destination_colors_ref);
void grayscale(const span<const color>& source_colors_ref, fixed intensity, span<color> destination_colors_ref);

/**
* @brief Applies a hue shift effect to all referenced colors.
* @param hue_shift_intensity Hue shift effect intensity in the range [0..1].
* @param intensity Hue shift effect intensity in the range [0..1].
* @param colors_ref Colors reference.
*/
void hue_shift(fixed hue_shift_intensity, span<color> colors_ref);
void hue_shift(fixed intensity, span<color> colors_ref);

/**
* @brief Applies a hue shift effect to all colors referenced by source_colors_ref,
* storing the result in destination_colors_ref.
* @param source_colors_ref Source colors reference.
* @param hue_shift_intensity Hue shift effect intensity in the range [0..1].
* @param intensity Hue shift effect intensity in the range [0..1].
* @param destination_colors_ref Destination colors reference.
*/
void hue_shift(const span<const color>& source_colors_ref, fixed hue_shift_intensity,
span<color> destination_colors_ref);
void hue_shift(const span<const color>& source_colors_ref, fixed intensity, span<color> destination_colors_ref);

/**
* @brief Blends two color arrays referenced by first_source_colors_ref and second_source_colors_ref,
* storing the result in destination_colors_ref.
* @param first_source_colors_ref First source colors reference.
* @param second_source_colors_ref Second source colors reference.
* @param weight Blend weight in the range [0..1].
* @param destination_colors_ref Destination colors reference.
*/
void blend(const span<const color>& first_source_colors_ref, const span<const color>& second_source_colors_ref,
fixed weight, span<color> destination_colors_ref);

/**
* @brief Applies a fade effect to all referenced colors.
* @param fade_color Fade effect color.
* @param fade_intensity Fade effect intensity in the range [0..1].
* @param intensity Fade effect intensity in the range [0..1].
* @param colors_ref Colors reference.
*/
void fade(color fade_color, fixed fade_intensity, span<color> colors_ref);
void fade(color fade_color, fixed intensity, span<color> colors_ref);

/**
* @brief Applies a fade effect to all colors referenced by source_colors_ref,
* storing the result in destination_colors_ref.
* @param source_colors_ref Source colors reference.
* @param fade_color Fade effect color.
* @param fade_intensity Fade effect intensity in the range [0..1].
* @param intensity Fade effect intensity in the range [0..1].
* @param destination_colors_ref Destination colors reference.
*/
void fade(const span<const color>& source_colors_ref, color fade_color, fixed fade_intensity,
void fade(const span<const color>& source_colors_ref, color fade_color, fixed intensity,
span<color> destination_colors_ref);

/**
Expand Down
5 changes: 5 additions & 0 deletions butano/include/bn_documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,11 @@
* @tableofcontents
*
*
* @section changelog_16_2_0 16.2.0 (next release)
*
* bn::color_effect::blend added.
*
*
* @section changelog_16_1_0 16.1.0
*
* * Sprite affine mats management CPU usage reduced.
Expand Down
55 changes: 33 additions & 22 deletions butano/src/bn_color_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ void invert(const span<const color>& source_colors_ref, span<color> destination_
}
}

void grayscale(fixed grayscale_intensity, span<color> colors_ref)
void grayscale(fixed intensity, span<color> colors_ref)
{
BN_ASSERT(grayscale_intensity >= 0 && grayscale_intensity <= 1,
"Invalid grayscale intensity: ", grayscale_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

if(int value = fixed_t<5>(grayscale_intensity).data())
if(int value = fixed_t<5>(intensity).data())
{
int colors_count = colors_ref.size();
BN_ASSERT(colors_count <= hw::palettes::colors(), "Invalid colors count: ", colors_count);
Expand All @@ -123,63 +122,75 @@ void grayscale(fixed grayscale_intensity, span<color> colors_ref)
}
}

void grayscale(const span<const color>& source_colors_ref, fixed grayscale_intensity,
void grayscale(const span<const color>& source_colors_ref, fixed intensity,
span<color> destination_colors_ref)
{
int colors_count = source_colors_ref.size();
BN_ASSERT(colors_count <= hw::palettes::colors(), "Invalid source colors count: ", colors_count);
BN_ASSERT(destination_colors_ref.size() >= colors_count, "Invalid destination colors count: ",
destination_colors_ref.size(), " - ", colors_count);
BN_ASSERT(grayscale_intensity >= 0 && grayscale_intensity <= 1,
"Invalid grayscale intensity: ", grayscale_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

int value = fixed_t<5>(grayscale_intensity).data();
int value = fixed_t<5>(intensity).data();
hw::palettes::grayscale(source_colors_ref.data(), value, colors_count, destination_colors_ref.data());
}

void hue_shift(fixed hue_shift_intensity, span<color> colors_ref)
void hue_shift(fixed intensity, span<color> colors_ref)
{
BN_ASSERT(hue_shift_intensity >= 0 && hue_shift_intensity <= 1,
"Invalid hue shift intensity: ", hue_shift_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

if(int value = fixed_t<5>(hue_shift_intensity).data())
if(int value = fixed_t<5>(intensity).data())
{
hw::palettes::hue_shift(colors_ref.data(), value, colors_ref.size(), colors_ref.data());
}
}

void hue_shift(const span<const color>& source_colors_ref, fixed hue_shift_intensity,
void hue_shift(const span<const color>& source_colors_ref, fixed intensity,
span<color> destination_colors_ref)
{
int colors_count = source_colors_ref.size();
BN_ASSERT(destination_colors_ref.size() >= colors_count, "Invalid destination colors count: ",
destination_colors_ref.size(), " - ", colors_count);
BN_ASSERT(hue_shift_intensity >= 0 && hue_shift_intensity <= 1,
"Invalid hue shift intensity: ", hue_shift_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

int value = fixed_t<5>(hue_shift_intensity).data();
int value = fixed_t<5>(intensity).data();
hw::palettes::hue_shift(source_colors_ref.data(), value, colors_count, destination_colors_ref.data());
}

void fade(color fade_color, fixed fade_intensity, span<color> colors_ref)
void fade(color fade_color, fixed intensity, span<color> colors_ref)
{
BN_ASSERT(fade_intensity >= 0 && fade_intensity <= 1, "Invalid fade intensity: ", fade_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

if(int value = fixed_t<5>(fade_intensity).data())
if(int value = fixed_t<5>(intensity).data())
{
hw::palettes::fade(colors_ref.data(), fade_color, value, colors_ref.size(), colors_ref.data());
}
}

void fade(const span<const color>& source_colors_ref, color fade_color, fixed fade_intensity,
void blend(const span<const color>& first_source_colors_ref, const span<const color>& second_source_colors_ref,
fixed weight, span<color> destination_colors_ref)
{
int colors_count = first_source_colors_ref.size();
BN_ASSERT(second_source_colors_ref.size() == colors_count, "Invalid second source colors count: ",
second_source_colors_ref.size(), " - ", colors_count);
BN_ASSERT(destination_colors_ref.size() >= colors_count, "Invalid destination colors count: ",
destination_colors_ref.size(), " - ", colors_count);
BN_ASSERT(weight >= 0 && weight <= 1, "Invalid weight: ", weight);

int value = fixed_t<5>(weight).data();
hw::palettes::blend(first_source_colors_ref.data(), second_source_colors_ref.data(), value, colors_count,
destination_colors_ref.data());
}

void fade(const span<const color>& source_colors_ref, color fade_color, fixed intensity,
span<color> destination_colors_ref)
{
int colors_count = source_colors_ref.size();
BN_ASSERT(destination_colors_ref.size() >= colors_count, "Invalid destination colors count: ",
destination_colors_ref.size(), " - ", colors_count);
BN_ASSERT(fade_intensity >= 0 && fade_intensity <= 1, "Invalid fade intensity: ", fade_intensity);
BN_ASSERT(intensity >= 0 && intensity <= 1, "Invalid intensity: ", intensity);

int value = fixed_t<5>(fade_intensity).data();
int value = fixed_t<5>(intensity).data();
hw::palettes::fade(source_colors_ref.data(), fade_color, value, colors_count, destination_colors_ref.data());
}

Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.html

Large diffs are not rendered by default.

Loading

0 comments on commit 490a69c

Please sign in to comment.