Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/config/ui_preferences_display_background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const cfg_auto_combo_option<BackgroundFillType> g_background_fill_options
{ _T("Default"), BackgroundFillType::Default },
{ _T("Solid colour"), BackgroundFillType::SolidColour },
{ _T("Gradient"), BackgroundFillType::Gradient },
{ _T("Average image colour"), BackgroundFillType::AverageImageColor },
};

static const cfg_auto_combo_option<BackgroundImageType> g_background_image_options[] = {
Expand All @@ -48,7 +49,7 @@ static const cfg_auto_combo_option<BackgroundImageType> g_background_image_optio
{ _T("Custom image"), BackgroundImageType::CustomImage },
};

static cfg_auto_combo<BackgroundFillType, 3> cfg_background_fill_type(GUID_CFG_BACKGROUND_MODE,
static cfg_auto_combo<BackgroundFillType, 4> cfg_background_fill_type(GUID_CFG_BACKGROUND_MODE,
IDC_BACKGROUND_FILL_TYPE,
BackgroundFillType::Default,
g_background_fill_options);
Expand Down
66 changes: 66 additions & 0 deletions src/img_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,41 @@ void transpose_image_noalloc(int width, int height, const uint8_t* in_pixels, ui
}
}
}

RGBAColour compute_average_colour(const Image& img)
{
if(!img.valid())
{
return {};
}

uint64_t total_r = 0;
uint64_t total_g = 0;
uint64_t total_b = 0;

for(int y=0; y<img.height; y++)
{
for(int x=0; x<img.width; x++)
{
uint8_t* px = img.pixels + (y * img.width + x) * 4;
total_r += px[0];
total_g += px[1];
total_b += px[2];
}
}

const uint64_t num_pixels = img.width * img.height;
if(num_pixels == 0)
{
return {};
}

uint8_t avg_r = (uint8_t)(total_r / num_pixels);
uint8_t avg_g = (uint8_t)(total_g / num_pixels);
uint8_t avg_b = (uint8_t)(total_b / num_pixels);

return {avg_r, avg_g, avg_b, 255};
}
}
Image transpose_image(const Image& img)
{
Expand Down Expand Up @@ -526,6 +561,37 @@ static void boxblur_horizontal_noalloc(int width, int height, const uint8_t* in_
}
}
}

RGBAColour compute_average_colour(const Image& img)
{
if(!img.valid())
{
return {};
}

uint64_t total_r = 0;
uint64_t total_g = 0;
uint64_t total_b = 0;

for(int y=0; y<img.height; y++)
{
for(int x=0; x<img.width; x++)
{
uint8_t* px = img.pixels + (y * img.width + x) * 4;
total_r += px[0];
total_g += px[1];
total_b += px[2];
}
}

const uint64_t num_pixels = img.width * img.height;
uint8_t avg_r = (uint8_t)(total_r / num_pixels);
uint8_t avg_g = (uint8_t)(total_g / num_pixels);
uint8_t avg_b = (uint8_t)(total_b / num_pixels);

return {avg_r, avg_g, avg_b, 255};
}

static Image image_boxblur_linear_horizontal(const Image& img, int radius)
{
uint8_t* pixels = (uint8_t*)malloc(img.width * img.height * 4);
Expand Down
1 change: 1 addition & 0 deletions src/img_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Image lerp_image(const Image& lhs, const Image& rhs, double t);
Image lerp_offset_image(const Image& full_img, const Image& offset_img, CPoint offset, double t);
Image resize_image(const Image& input, int out_width, int out_height);
Image transpose_image(const Image& input);
RGBAColour compute_average_colour(const Image& img);
Image blur_image(const Image& input, int radius);

void toggle_image_rgba_bgra_inplace(Image& img);
1 change: 1 addition & 0 deletions src/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum class BackgroundFillType : int
Default = 0,
SolidColour = 1,
Gradient = 2,
AverageImageColor = 3,
};

enum class BackgroundImageType : int
Expand Down
17 changes: 16 additions & 1 deletion src/ui_lyrics_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void LyricPanel::compute_background_image()
}

Image bg_colour = {};
const BackgroundImageType img_type = preferences::background::image_type();
switch(preferences::background::fill_type())
{
case BackgroundFillType::Default:
Expand Down Expand Up @@ -173,10 +174,24 @@ void LyricPanel::compute_background_image()
botleft,
botright);
}
break;

case BackgroundFillType::AverageImageColor:
{
RGBAColour colour = from_colorref(defaultui::background_colour());
if(img_type == BackgroundImageType::AlbumArt)
{
colour = compute_average_colour(m_albumart_original);
}
else if(img_type == BackgroundImageType::CustomImage)
{
colour = compute_average_colour(m_custom_img_original);
}
bg_colour = generate_background_colour(client_rect.Width(), client_rect.Height(), colour);
}
break;
}

const BackgroundImageType img_type = preferences::background::image_type();
if(img_type == BackgroundImageType::None)
{
m_background_img = std::move(bg_colour);
Expand Down
Loading