Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Make a full tile from a game program's icon

Leonardo Lobatod0f7a9d5912b
diff --git a/src/homebrew/program_icon.cpp b/src/homebrew/program_icon.cpp
index 6327e48..fee62e8 100644
--- a/src/homebrew/program_icon.cpp
+++ b/src/homebrew/program_icon.cpp
@@ -4,6 +4,7 @@
#include "homebrew/program_icon.hpp"
#include "homebrew/artwork_backend.hpp"
+#include "homebrew/title_icon.hpp"
#include <algorithm>
#include <cstring>
@@ -324,7 +325,9 @@ std::optional<ArtworkImage> ProgramIconArtworkBackend::Load(const ArtworkKey& ke
const auto path = ProgramIconPath(key.source);
if (!path) return next_.Load(key, cancel);
if (cancel.load(std::memory_order_acquire)) return std::nullopt;
- return ReadProgramIcon(host_prefix_ + *path);
+ // The library shows a poster made from the icon, shaped like the store's covers.
+ const auto icon = ReadProgramIcon(host_prefix_ + *path);
+ return icon ? ProgramIconArt(*icon, kProgramIconPosterWidth, kProgramIconPosterHeight) : std::nullopt;
}
} // namespace playden::homebrew
diff --git a/src/homebrew/program_icon.hpp b/src/homebrew/program_icon.hpp
index bfcafcc..208244a 100644
--- a/src/homebrew/program_icon.hpp
+++ b/src/homebrew/program_icon.hpp
@@ -30,7 +30,8 @@ inline std::string ProgramIconSource(const std::string& console_path) {
std::optional<std::string> ProgramIconPath(const std::string& source);
// Loads program-icon sources from the game's files (a console path under `host_prefix` on the desktop
-// build) and passes every other source to `next`. Both outlive it.
+// build), as a 2:3 poster made from the icon (homebrew/title_icon.hpp ProgramIconArt), and passes every
+// other source to `next`. Both outlive it.
class ProgramIconArtworkBackend final : public ArtworkBackend {
public:
ProgramIconArtworkBackend(ArtworkBackend& next, std::string host_prefix = "");
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index c127383..458ef4e 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -571,6 +571,10 @@ int main() {
std::fclose(file);
if (!bytes.empty()) generic_icon = std::move(bytes);
}
+ // The generic icon as an image: a small program icon goes on its floppy's label.
+ std::optional<playden::homebrew::ArtworkImage> generic_floppy;
+ if (generic_icon)
+ generic_floppy = playden::homebrew::DecodeArtwork(std::vector<std::uint8_t>(generic_icon->begin(), generic_icon->end()));
// Owned DLC: the game's looked-up DLC that the last license read of this account grants.
config.owned_dlc = [&library_backend, &licensed_depots](std::uint64_t steam_id, std::uint32_t app_id) {
std::vector<std::uint32_t> owned;
@@ -580,7 +584,7 @@ int main() {
if (grant->apps.count(dlc)) owned.push_back(dlc);
return owned;
};
- config.title_icon = [trust = paths.trust_store, art_cache_dir, generic_icon](
+ config.title_icon = [trust = paths.trust_store, art_cache_dir, generic_icon, generic_floppy](
const playden::GameId& game, const std::filesystem::path& program) -> std::optional<std::string> {
// A store with no cover for the game (an imported one) gets the generic icon.
const auto source = playden::homebrew::CoverUrl(game);
@@ -593,9 +597,12 @@ int main() {
if (auto icon = cover ? playden::homebrew::MakeTitleIcon(*cover) : std::nullopt) return icon;
// An imported game, or a Steam game without a cover: the icon inside its program.
const auto own = program.empty() ? std::nullopt : playden::homebrew::ReadProgramIcon(program.string());
- if (auto icon = own ? playden::homebrew::MakeProgramTitleIcon(*own) : std::nullopt) {
+ // A small icon goes on the generic floppy; a larger one makes the whole tile.
+ if (auto icon = own ? playden::homebrew::MakeProgramTitleIcon(*own, generic_floppy ? &*generic_floppy : nullptr)
+ : std::nullopt) {
playden::app::AppendLogLine(log_root, "runtime.log", "title icon app=" + playden::ToKey(game) +
- " uses the program's icon: no cover program=" + program.filename().string());
+ " uses the program's icon: no cover program=" + program.filename().string() +
+ " size=" + std::to_string(own->width) + "x" + std::to_string(own->height));
return icon;
}
playden::app::AppendLogLine(log_root, "runtime.log", "title icon app=" + playden::ToKey(game) +
diff --git a/src/homebrew/title_icon.cpp b/src/homebrew/title_icon.cpp
index 15c9a0c..c4f1fd2 100644
--- a/src/homebrew/title_icon.cpp
+++ b/src/homebrew/title_icon.cpp
@@ -1,4 +1,4 @@
-// title_icon.cpp - A game's PS5 title icon from its store cover art.
+// title_icon.cpp - A game's PS5 title icon from its store cover art, or its program's icon.
// Copyright (c) 2026 Playden contributors
// SPDX-License-Identifier: MIT
#include "homebrew/title_icon.hpp"
@@ -50,47 +50,254 @@ std::optional<std::string> MakeTitleIcon(const ArtworkImage& cover) {
return png;
}
-std::optional<ArtworkImage> ProgramIconTile(const ArtworkImage& icon, std::uint32_t side) {
- if (icon.width == 0 || icon.height == 0 || side == 0 || side > kMaxArtworkDimension ||
- icon.rgba.size() != static_cast<std::size_t>(icon.width) * icon.height * 4)
- return std::nullopt;
- // The UI's placeholder tile colour, so the icon sits on the same dark ground.
- constexpr std::uint8_t kGround[3] = {0x24, 0x20, 0x1d};
- ArtworkImage tile;
- tile.width = tile.height = side;
- tile.rgba.resize(static_cast<std::size_t>(side) * side * 4);
- for (std::size_t i = 0; i < tile.rgba.size(); i += 4)
- tile.rgba[i] = kGround[0], tile.rgba[i + 1] = kGround[1], tile.rgba[i + 2] = kGround[2], tile.rgba[i + 3] = 255;
- // Two thirds of the tile, keeping the icon's shape; bilinear, on alpha-weighted colours.
- const double scale = side * 2.0 / 3.0 / std::max(icon.width, icon.height);
- const auto box_w = static_cast<std::uint32_t>(std::max(1.0, icon.width * scale));
- const auto box_h = static_cast<std::uint32_t>(std::max(1.0, icon.height * scale));
- const std::uint32_t left = (side - box_w) / 2, top = (side - box_h) / 2;
- const auto at = [&](std::uint32_t x, std::uint32_t y) { return &icon.rgba[(static_cast<std::size_t>(y) * icon.width + x) * 4]; };
- for (std::uint32_t y = 0; y < box_h; ++y)
- for (std::uint32_t x = 0; x < box_w; ++x) {
+namespace {
+
+// The UI's placeholder tile colour: what shows through a see-through icon.
+constexpr std::uint8_t kGround[3] = {0x24, 0x20, 0x1d};
+// The backdrop: the icon averaged down to this many cells on its longer side, at this brightness.
+constexpr std::uint32_t kBackdropCells = 16;
+constexpr double kBackdropBrightness = 0.65;
+// A poster darkens from the lower part of its square down to this at the bottom, so its title reads.
+constexpr double kTitleAreaBrightness = 0.5;
+constexpr double kTitleAreaStart = 0.8;
+// A centred icon's share of the square, and the rounding of an opaque one's corners.
+constexpr double kCentredIconShare = 0.62;
+constexpr double kCentredIconRounding = 0.08;
+// The generic floppy's label, in its 512-pixel art (assets/branding/generic-title-icon.png).
+constexpr double kFloppyLabel[4] = {78, 214, 432, 462};
+constexpr double kFloppyLabelPadding = 14;
+
+bool Valid(const ArtworkImage& image) {
+ return image.width != 0 && image.height != 0 &&
+ image.rgba.size() == static_cast<std::size_t>(image.width) * image.height * 4;
+}
+
+ArtworkImage Blank(std::uint32_t width, std::uint32_t height) {
+ ArtworkImage image;
+ image.width = width, image.height = height;
+ image.rgba.assign(static_cast<std::size_t>(width) * height * 4, 255);
+ return image;
+}
+
+std::uint8_t* Pixel(ArtworkImage& image, std::uint32_t x, std::uint32_t y) {
+ return &image.rgba[(static_cast<std::size_t>(y) * image.width + x) * 4];
+}
+const std::uint8_t* Pixel(const ArtworkImage& image, std::uint32_t x, std::uint32_t y) {
+ return &image.rgba[(static_cast<std::size_t>(y) * image.width + x) * 4];
+}
+
+// An icon scaled to fit a side x side box, keeping its shape, as premultiplied RGBA (0..1) at its place.
+struct Layer {
+ long left = 0, top = 0;
+ std::uint32_t width = 0, height = 0;
+ std::vector<double> rgba;
+};
+
+// Bilinear on alpha-weighted colours; `radius` rounds the corners with anti-aliased edges.
+Layer Scale(const ArtworkImage& icon, double centre_x, double centre_y, double side, double radius) {
+ const double scale = side / std::max(icon.width, icon.height);
+ Layer layer;
+ layer.width = static_cast<std::uint32_t>(std::max(1.0, std::round(icon.width * scale)));
+ layer.height = static_cast<std::uint32_t>(std::max(1.0, std::round(icon.height * scale)));
+ layer.left = std::lround(centre_x - layer.width / 2.0);
+ layer.top = std::lround(centre_y - layer.height / 2.0);
+ layer.rgba.resize(static_cast<std::size_t>(layer.width) * layer.height * 4);
+ // A thin icon's corners can round no further than half its shorter side.
+ radius = std::min(radius, std::min(layer.width, layer.height) / 2.0);
+ for (std::uint32_t y = 0; y < layer.height; ++y)
+ for (std::uint32_t x = 0; x < layer.width; ++x) {
const double sx = std::clamp((x + 0.5) / scale - 0.5, 0.0, icon.width - 1.0);
const double sy = std::clamp((y + 0.5) / scale - 0.5, 0.0, icon.height - 1.0);
const auto x0 = static_cast<std::uint32_t>(sx), y0 = static_cast<std::uint32_t>(sy);
const std::uint32_t x1 = std::min(x0 + 1, icon.width - 1), y1 = std::min(y0 + 1, icon.height - 1);
const double fx = sx - x0, fy = sy - y0;
- const std::uint8_t* corners[4] = {at(x0, y0), at(x1, y0), at(x0, y1), at(x1, y1)};
+ const std::uint8_t* corners[4] = {Pixel(icon, x0, y0), Pixel(icon, x1, y0), Pixel(icon, x0, y1), Pixel(icon, x1, y1)};
const double weights[4] = {(1 - fx) * (1 - fy), fx * (1 - fy), (1 - fx) * fy, fx * fy};
double colour[3] = {0, 0, 0}, alpha = 0;
for (int c = 0; c < 4; ++c) {
const double a = weights[c] * corners[c][3] / 255.0;
alpha += a;
- for (int k = 0; k < 3; ++k) colour[k] += a * corners[c][k];
+ for (int k = 0; k < 3; ++k) colour[k] += a * corners[c][k] / 255.0;
+ }
+ double coverage = 1.0;
+ if (radius > 0) {
+ const double px = x + 0.5, py = y + 0.5;
+ const double cx = std::clamp(px, radius, layer.width - radius), cy = std::clamp(py, radius, layer.height - radius);
+ coverage = std::clamp(radius - std::hypot(px - cx, py - cy) + 0.5, 0.0, 1.0);
}
- auto* out = &tile.rgba[(static_cast<std::size_t>(top + y) * side + left + x) * 4];
- for (int k = 0; k < 3; ++k) out[k] = static_cast<std::uint8_t>(std::lround(colour[k] + (1 - alpha) * out[k]));
+ double* out = &layer.rgba[(static_cast<std::size_t>(y) * layer.width + x) * 4];
+ for (int k = 0; k < 3; ++k) out[k] = colour[k] * coverage;
+ out[3] = alpha * coverage;
+ }
+ return layer;
+}
+
+void Composite(ArtworkImage& target, const Layer& layer) {
+ for (std::uint32_t y = 0; y < layer.height; ++y)
+ for (std::uint32_t x = 0; x < layer.width; ++x) {
+ const long tx = layer.left + static_cast<long>(x), ty = layer.top + static_cast<long>(y);
+ if (tx < 0 || ty < 0 || tx >= static_cast<long>(target.width) || ty >= static_cast<long>(target.height)) continue;
+ const double* in = &layer.rgba[(static_cast<std::size_t>(y) * layer.width + x) * 4];
+ std::uint8_t* out = Pixel(target, static_cast<std::uint32_t>(tx), static_cast<std::uint32_t>(ty));
+ for (int k = 0; k < 3; ++k)
+ out[k] = static_cast<std::uint8_t>(std::clamp(std::lround(in[k] * 255.0 + (1 - in[3]) * out[k]), 0L, 255L));
}
- return tile;
}
-std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon) {
- const auto tile = ProgramIconTile(icon, kTitleIconSize);
- return tile ? MakeTitleIcon(*tile) : std::nullopt;
+// A soft shadow of the layer's shape, `blur` pixels wide and `drop` pixels lower, darkening the target.
+void Shadow(ArtworkImage& target, const Layer& layer, std::uint32_t blur, long drop, double strength) {
+ const std::uint32_t width = layer.width + 2 * blur, height = layer.height + 2 * blur;
+ std::vector<double> mask(static_cast<std::size_t>(width) * height, 0.0), pass(mask.size());
+ for (std::uint32_t y = 0; y < layer.height; ++y)
+ for (std::uint32_t x = 0; x < layer.width; ++x)
+ mask[static_cast<std::size_t>(y + blur) * width + x + blur] = layer.rgba[(static_cast<std::size_t>(y) * layer.width + x) * 4 + 3];
+ // Three box blurs come close to a Gaussian.
+ const long reach = std::max<long>(1, blur / 3);
+ for (int round = 0; round < 3; ++round)
+ for (int vertical = 0; vertical < 2; ++vertical) {
+ const std::uint32_t lines = vertical ? width : height, length = vertical ? height : width;
+ for (std::uint32_t line = 0; line < lines; ++line) {
+ const auto index = [&](long i) {
+ return vertical ? static_cast<std::size_t>(i) * width + line : static_cast<std::size_t>(line) * width + i;
+ };
+ double sum = 0;
+ for (long i = -reach; i <= reach; ++i) sum += i >= 0 && i < static_cast<long>(length) ? mask[index(i)] : 0.0;
+ for (long i = 0; i < static_cast<long>(length); ++i) {
+ pass[index(i)] = sum / (2 * reach + 1);
+ if (i - reach >= 0) sum -= mask[index(i - reach)];
+ if (i + reach + 1 < static_cast<long>(length)) sum += mask[index(i + reach + 1)];
+ }
+ }
+ mask.swap(pass);
+ }
+ for (std::uint32_t y = 0; y < height; ++y)
+ for (std::uint32_t x = 0; x < width; ++x) {
+ const long tx = layer.left - static_cast<long>(blur) + static_cast<long>(x);
+ const long ty = layer.top - static_cast<long>(blur) + drop + static_cast<long>(y);
+ if (tx < 0 || ty < 0 || tx >= static_cast<long>(target.width) || ty >= static_cast<long>(target.height)) continue;
+ const double keep = 1.0 - strength * mask[static_cast<std::size_t>(y) * width + x];
+ std::uint8_t* out = Pixel(target, static_cast<std::uint32_t>(tx), static_cast<std::uint32_t>(ty));
+ for (int k = 0; k < 3; ++k) out[k] = static_cast<std::uint8_t>(std::lround(out[k] * keep));
+ }
+}
+
+// The icon over the dark ground, covering width x height, averaged into a few cells, blurred among them
+// and smoothed back up: a heavy blur for little work. Darkened, and more so towards a tall image's bottom.
+ArtworkImage Backdrop(const ArtworkImage& icon, std::uint32_t width, std::uint32_t height) {
+ const double scale = std::max(static_cast<double>(width) / icon.width, static_cast<double>(height) / icon.height);
+ const double window_w = width / scale, window_h = height / scale;
+ const double origin_x = (icon.width - window_w) / 2, origin_y = (icon.height - window_h) / 2;
+ const std::uint32_t cells_x = std::max<std::uint32_t>(1, width >= height ? kBackdropCells : kBackdropCells * width / height);
+ const std::uint32_t cells_y = std::max<std::uint32_t>(1, height >= width ? kBackdropCells : kBackdropCells * height / width);
+ std::vector<double> cells(static_cast<std::size_t>(cells_x) * cells_y * 3);
+ for (std::uint32_t cy = 0; cy < cells_y; ++cy)
+ for (std::uint32_t cx = 0; cx < cells_x; ++cx) {
+ const auto x0 = static_cast<std::uint32_t>(origin_x + window_w * cx / cells_x);
+ const auto y0 = static_cast<std::uint32_t>(origin_y + window_h * cy / cells_y);
+ const auto x1 = std::clamp(static_cast<std::uint32_t>(origin_x + window_w * (cx + 1) / cells_x), x0 + 1, icon.width);
+ const auto y1 = std::clamp(static_cast<std::uint32_t>(origin_y + window_h * (cy + 1) / cells_y), y0 + 1, icon.height);
+ double sum[3] = {0, 0, 0};
+ for (std::uint32_t y = y0; y < y1; ++y)
+ for (std::uint32_t x = x0; x < x1; ++x) {
+ const std::uint8_t* p = Pixel(icon, x, y);
+ for (int k = 0; k < 3; ++k) sum[k] += (p[k] * p[3] + kGround[k] * (255.0 - p[3])) / 255.0;
+ }
+ const double count = static_cast<double>(x1 - x0) * (y1 - y0);
+ for (int k = 0; k < 3; ++k) cells[(static_cast<std::size_t>(cy) * cells_x + cx) * 3 + k] = sum[k] / count;
+ }
+ // Two 3x3 box blurs over the cells, so no cell's edge shows once scaled up.
+ for (int round = 0; round < 2; ++round) {
+ std::vector<double> blurred(cells.size());
+ for (std::uint32_t cy = 0; cy < cells_y; ++cy)
+ for (std::uint32_t cx = 0; cx < cells_x; ++cx)
+ for (int k = 0; k < 3; ++k) {
+ double sum = 0;
+ for (int dy = -1; dy <= 1; ++dy)
+ for (int dx = -1; dx <= 1; ++dx) {
+ const auto x = static_cast<std::uint32_t>(std::clamp<long>(static_cast<long>(cx) + dx, 0, cells_x - 1));
+ const auto y = static_cast<std::uint32_t>(std::clamp<long>(static_cast<long>(cy) + dy, 0, cells_y - 1));
+ sum += cells[(static_cast<std::size_t>(y) * cells_x + x) * 3 + k];
+ }
+ blurred[(static_cast<std::size_t>(cy) * cells_x + cx) * 3 + k] = sum / 9;
+ }
+ cells.swap(blurred);
+ }
+ ArtworkImage image = Blank(width, height);
+ const std::uint32_t square = std::min(width, height);
+ for (std::uint32_t y = 0; y < height; ++y) {
+ const double gy = std::clamp((y + 0.5) * cells_y / height - 0.5, 0.0, cells_y - 1.0);
+ const auto y0 = static_cast<std::uint32_t>(gy);
+ const std::uint32_t y1 = std::min(y0 + 1, cells_y - 1);
+ const double ty = gy - y0, fy = ty * ty * (3 - 2 * ty);
+ double brightness = kBackdropBrightness;
+ const double fade_top = square * kTitleAreaStart;
+ if (height > square && y >= fade_top)
+ brightness *= 1.0 - (1.0 - kTitleAreaBrightness) * (y + 1.0 - fade_top) / (height - fade_top);
+ for (std::uint32_t x = 0; x < width; ++x) {
+ const double gx = std::clamp((x + 0.5) * cells_x / width - 0.5, 0.0, cells_x - 1.0);
+ const auto x0 = static_cast<std::uint32_t>(gx);
+ const std::uint32_t x1 = std::min(x0 + 1, cells_x - 1);
+ const double tx = gx - x0, fx = tx * tx * (3 - 2 * tx);
+ const auto cell = [&](std::uint32_t cx, std::uint32_t cy, int k) {
+ return cells[(static_cast<std::size_t>(cy) * cells_x + cx) * 3 + k];
+ };
+ std::uint8_t* out = Pixel(image, x, y);
+ for (int k = 0; k < 3; ++k) {
+ const double value = (1 - fx) * (1 - fy) * cell(x0, y0, k) + fx * (1 - fy) * cell(x1, y0, k) +
+ (1 - fx) * fy * cell(x0, y1, k) + fx * fy * cell(x1, y1, k);
+ out[k] = static_cast<std::uint8_t>(std::lround(value * brightness));
+ }
+ }
+ }
+ return image;
+}
+
+bool Small(const ArtworkImage& icon) { return std::max(icon.width, icon.height) < kSmallProgramIconSide; }
+
+} // namespace
+
+bool ProgramIconIsOpaque(const ArtworkImage& icon) {
+ if (!Valid(icon)) return false;
+ std::size_t solid = 0;
+ for (std::size_t i = 3; i < icon.rgba.size(); i += 4) solid += icon.rgba[i] >= 224;
+ return solid * 100 >= static_cast<std::size_t>(icon.width) * icon.height * 99;
+}
+
+std::optional<ArtworkImage> ProgramIconArt(const ArtworkImage& icon, std::uint32_t width, std::uint32_t height) {
+ if (!Valid(icon) || width == 0 || height == 0 || width > kMaxArtworkDimension || height > kMaxArtworkDimension)
+ return std::nullopt;
+ ArtworkImage art = Backdrop(icon, width, height);
+ const std::uint32_t square = std::min(width, height);
+ const double centre_x = width / 2.0, centre_y = square / 2.0;
+ const bool opaque = ProgramIconIsOpaque(icon);
+ if (opaque && !Small(icon)) {
+ Composite(art, Scale(icon, centre_x, centre_y, square, 0.0));
+ return art;
+ }
+ const double side = square * kCentredIconShare;
+ const Layer layer = Scale(icon, centre_x, centre_y, side, opaque ? side * kCentredIconRounding : 0.0);
+ Shadow(art, layer, static_cast<std::uint32_t>(std::lround(square * 0.04)), std::lround(square * 0.02), 0.6);
+ Composite(art, layer);
+ return art;
+}
+
+std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon, const ArtworkImage* floppy) {
+ if (!Valid(icon)) return std::nullopt;
+ if (Small(icon) && floppy != nullptr && Valid(*floppy) && floppy->width == floppy->height) {
+ // The icon on the floppy's label, scaled with the floppy's own size.
+ ArtworkImage tile = *floppy;
+ const double unit = tile.width / 512.0;
+ const double left = kFloppyLabel[0] * unit, top = kFloppyLabel[1] * unit;
+ const double right = kFloppyLabel[2] * unit, bottom = kFloppyLabel[3] * unit;
+ const double side = std::min(right - left, bottom - top) - 2 * kFloppyLabelPadding * unit;
+ const bool opaque = ProgramIconIsOpaque(icon);
+ const Layer layer = Scale(icon, (left + right) / 2, (top + bottom) / 2, side, opaque ? side / 14 : 0.0);
+ Shadow(tile, layer, static_cast<std::uint32_t>(std::lround(6 * unit)), std::lround(4 * unit), 0.45);
+ Composite(tile, layer);
+ return MakeTitleIcon(tile);
+ }
+ const auto art = ProgramIconArt(icon, kTitleIconSize, kTitleIconSize);
+ return art ? MakeTitleIcon(*art) : std::nullopt;
}
} // namespace playden::homebrew
diff --git a/src/homebrew/title_icon.hpp b/src/homebrew/title_icon.hpp
index df421d2..b5ec284 100644
--- a/src/homebrew/title_icon.hpp
+++ b/src/homebrew/title_icon.hpp
@@ -10,15 +10,28 @@
namespace playden::homebrew {
inline constexpr std::uint32_t kTitleIconSize = 512;
+// A program icon smaller than this (on its longer side) is too blurry to fill a tile: an old game's 32 or
+// 48 pixel icon. On the console's Home it goes on the generic floppy's label instead.
+inline constexpr std::uint32_t kSmallProgramIconSide = 128;
+// The size of a library poster made from a program icon: the 2:3 shape of the store's covers.
+inline constexpr std::uint32_t kProgramIconPosterWidth = 320;
+inline constexpr std::uint32_t kProgramIconPosterHeight = 480;
// The centred square of the cover, scaled to 512x512 by area averaging and
// encoded as an opaque RGB PNG. Nothing for an empty or malformed image.
std::optional<std::string> MakeTitleIcon(const ArtworkImage& cover);
-// A game without cover art: its program's own icon (homebrew/program_icon.hpp), scaled to fill
-// two thirds of a dark 512x512 tile and centred, encoded as MakeTitleIcon does.
-std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon);
-// The same tile as an image, for the UI's artwork.
-std::optional<ArtworkImage> ProgramIconTile(const ArtworkImage& icon, std::uint32_t side);
+// Whether an icon is a full picture with no see-through background (99% of its pixels nearly opaque).
+bool ProgramIconIsOpaque(const ArtworkImage& icon);
+
+// Art for a game without a cover, from its program's own icon (homebrew/program_icon.hpp), as an opaque
+// width x height image. A blurred, darkened copy of the icon covers it all. The icon goes in the top square
+// (all of a square image): a large opaque icon fills that square; a small or see-through one sits in its
+// middle, with a shadow. Below the square, a poster gets darker so the game's title reads over it.
+std::optional<ArtworkImage> ProgramIconArt(const ArtworkImage& icon, std::uint32_t width, std::uint32_t height);
+
+// The PS5 title icon of a game without a cover, encoded as MakeTitleIcon does: ProgramIconArt, or, for a
+// small icon, the icon on the label of `floppy` (the generic title icon) when it is given.
+std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon, const ArtworkImage* floppy = nullptr);
} // namespace playden::homebrew
diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cpp
index 59caa5c..662fec7 100644
--- a/src/homebrew/view.cpp
+++ b/src/homebrew/view.cpp
@@ -11,6 +11,7 @@
#include "homebrew/queue_layout.hpp"
#include "homebrew/simulation.hpp"
#include "homebrew/store_art.hpp"
+#include "homebrew/title_icon.hpp"
#include <ctime>
#include "gfx/draw_list.hpp"
@@ -1757,7 +1758,7 @@ class Render::Impl
? (game.art_failed || game.art_pending || !game.id.steam_app() ? 0 : art_[texture_index])
: (live_artwork_ && current_state_ && !current_state_->account().id.empty()
? store_texture(game.id, CoverUrl(game)) : 0);
- // No cover from the store: the icon inside the game's program, over its colour (#213).
+ // No cover from the store: a poster made from the icon inside the game's program (#213).
const std::uint32_t icon = simulated || texture != 0 ? 0 : program_icon_texture(game.id, CoverUrl(game));
const TileStatus status = tile_status(game.id);
// Glow first: it is a filled soft shape, and the art must cover its middle so only the
@@ -1767,18 +1768,30 @@ class Render::Impl
scene_.glow(rect.inset(-7.0F), 13.0F, 24.0F, kAccent.with_alpha(0.5F * amount));
if (texture != 0)
scene_.image(texture, rect, gfx::kFullUv, kText, 8.0F);
+ else if (icon != 0)
+ {
+ // The icon fills the poster's top square; the darker part below it names the game. A
+ // thumbnail (the Queue's) is too narrow for words: its row names the game.
+ scene_.image(icon, rect, gfx::kFullUv, kText, 8.0F);
+ if (rect.w >= 120.0F)
+ {
+ const float placeholder = title_overlay ? 1.0F - amount : 1.0F;
+ const float area_top = rect.y + rect.h * static_cast<float>(kProgramIconPosterWidth) /
+ static_cast<float>(kProgramIconPosterHeight);
+ // Above the bottom strip, where the size badge and the download mark go.
+ const float area_middle = (area_top + rect.y + rect.h - 44.0F) * 0.5F;
+ const ui::FontRef &face = font_for(game.title, fonts_.display);
+ const std::size_t lines = std::min<std::size_t>(2, face.font->wrap(game.title, 24.0F, rect.w - 32.0F).size());
+ const float first = area_middle - static_cast<float>(lines) * 28.0F * 0.5F + 19.0F;
+ ui::paragraph(scene_, face, game.title, rect.cx(), first, 24.0F, rect.w - 32.0F, 28.0F,
+ kText.with_alpha(placeholder), 2, gfx::Align::center);
+ }
+ }
else
{
scene_.gradient_rect(rect, 8.0F, id_color(game.id), gfx::Color::rgb(0x24201D));
// A thumbnail (the Queue's) is too narrow for words: its row names the game.
const bool words_fit = rect.w >= 120.0F;
- if (icon != 0)
- {
- // Above the title on a tile; alone, and larger, on a thumbnail.
- const float side = words_fit ? std::min(rect.w * 0.5F, rect.h * 0.36F) : std::min(rect.w, rect.h) * 0.72F;
- const float centre = words_fit ? rect.y + rect.h * 0.34F : rect.cy();
- scene_.image(icon, {rect.cx() - side * 0.5F, centre - side * 0.5F, side, side}, gfx::kFullUv, kText, 0.0F);
- }
if (words_fit && game.art_pending)
{
ui::text(scene_, fonts_.display, "Artwork loading", rect.cx(), rect.y + rect.h * 0.52F,
@@ -1789,8 +1802,8 @@ class Render::Impl
// The focus overlay names a focused tile, so the placeholder need not repeat it.
const float placeholder = title_overlay ? 1.0F - amount : 1.0F;
const ui::FontRef &face = font_for(game.title, fonts_.display);
- ui::paragraph(scene_, face, game.title, rect.cx(), rect.y + rect.h * (icon != 0 ? 0.62F : 0.42F),
- 28.0F, rect.w - 36.0F, 31.0F, kText.with_alpha(placeholder), icon != 0 ? 3 : 4, gfx::Align::center);
+ ui::paragraph(scene_, face, game.title, rect.cx(), rect.y + rect.h * 0.42F,
+ 28.0F, rect.w - 36.0F, 31.0F, kText.with_alpha(placeholder), 4, gfx::Align::center);
}
}
const bool downloading = status.job != nullptr &&
@@ -2523,8 +2536,8 @@ class Render::Impl
return url.empty() || !live_artwork_ ? 0 : live_artwork_->TextureFor(id, url, width, height);
}
- // The icon inside a prepared game's program (program_icon.hpp), for a game whose store has no cover
- // or whose cover failed to load; 0 otherwise, and while the cover may still come.
+ // The poster made from the icon inside a prepared game's program (program_icon.hpp), for a game whose
+ // store has no cover or whose cover failed to load; 0 otherwise, and while the cover may still come.
std::uint32_t program_icon_texture(GameId id, const std::string &cover_url)
{
if (!live_artwork_ || current_state_ == nullptr) return 0;
@@ -2585,13 +2598,11 @@ class Render::Impl
scene_.image(cover, rect, gfx::kFullUv, kText, 6.0F);
return;
}
- // No cover: the game's colour, with its program's icon when there is one.
- scene_.gradient_rect(rect, 6.0F, id_color(id), gfx::Color::rgb(0x24201D));
+ // No cover: the poster made from its program's icon, else the game's colour.
if (const std::uint32_t icon = program_icon_texture(id, CoverUrl(id)))
- {
- const float side = std::min(rect.w, rect.h) * 0.72F;
- scene_.image(icon, {rect.cx() - side * 0.5F, rect.cy() - side * 0.5F, side, side}, gfx::kFullUv, kText, 0.0F);
- }
+ scene_.image(icon, rect, gfx::kFullUv, kText, 6.0F);
+ else
+ scene_.gradient_rect(rect, 6.0F, id_color(id), gfx::Color::rgb(0x24201D));
}
// The Saves tab: filter chips and Sync all over one list of games with saves on this console.
diff --git a/tests/homebrew_artwork_graphical_test.cpp b/tests/homebrew_artwork_graphical_test.cpp
index 85a1be0..2313329 100644
--- a/tests/homebrew_artwork_graphical_test.cpp
+++ b/tests/homebrew_artwork_graphical_test.cpp
@@ -1,5 +1,6 @@
#include "homebrew/artwork.hpp"
#include "homebrew/program_icon.hpp"
+#include "homebrew/title_icon.hpp"
#include "homebrew/render.hpp"
#include "homebrew/simulation.hpp"
#include "gfx/gl_program.hpp"
@@ -19,14 +20,14 @@ struct Backend final : ArtworkBackend {
std::optional<ArtworkImage> Load(const ArtworkKey& key, const std::atomic<bool>& cancel) override {
while (!release && !cancel) std::this_thread::sleep_for(1ms);
if (cancel) return std::nullopt;
- // The program's icon: a 32x32 orange disc on a transparent ground.
+ // The program's icon, a 32x32 orange disc on a transparent ground, as the poster the real backend makes.
if (ProgramIconPath(key.source)) {
ArtworkImage icon{32,32,std::vector<std::uint8_t>(32*32*4,0)};
for (int y=0;y<32;++y) for (int x=0;x<32;++x)
if ((x-16)*(x-16)+(y-16)*(y-16)<15*15) {
auto* p=&icon.rgba[(y*32+x)*4]; p[0]=240; p[1]=140; p[2]=30; p[3]=255;
}
- return icon;
+ return ProgramIconArt(icon,kProgramIconPosterWidth,kProgramIconPosterHeight);
}
if (key.game_id == SteamId(44)) return std::nullopt;
ArtworkImage result{64,96,{}};
diff --git a/tests/homebrew_program_icon_test.cpp b/tests/homebrew_program_icon_test.cpp
index 4deddc8..9a27b68 100644
--- a/tests/homebrew_program_icon_test.cpp
+++ b/tests/homebrew_program_icon_test.cpp
@@ -254,28 +254,86 @@ int main() {
const std::atomic<bool> cancel{false};
const playden::GameId game = playden::GameId::Steam(10);
icon = backend.Load({1, game, ProgramIconSource("/Game/Bands.exe")}, cancel);
- CHECK(icon && icon->width == 4 && next.asked.empty());
+ CHECK(icon && icon->width == kProgramIconPosterWidth && icon->height == kProgramIconPosterHeight && next.asked.empty());
CHECK(!backend.Load({1, game, ProgramIconSource("/Game/Missing.exe")}, cancel) && next.asked.empty());
icon = backend.Load({1, game, "https://cdn.cloudflare.steamstatic.com/steam/apps/10/library_600x900.jpg"}, cancel);
CHECK(icon && icon->width == 1 && next.asked.size() == 1);
- // The tile: the icon two thirds of the side, centred on the dark ground; transparency shows the ground.
- ArtworkImage half{2, 2, {255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255}};
- auto tile = ProgramIconTile(half, 300);
- CHECK(tile && tile->width == 300 && tile->height == 300);
- CHECK(Pixel(*tile, 0, 0)[0] == 0x24 && Pixel(*tile, 0, 0)[3] == 255);
- CHECK(Pixel(*tile, 150, 150)[0] == 255 && Pixel(*tile, 150, 150)[1] == 0);
- CHECK(Pixel(*tile, 40, 150)[0] == 0x24); // outside the 200-pixel box
+ // Program icon art: a large opaque icon fills the top square; the part below it is darker.
+ const auto solid = [](std::uint32_t side, std::uint8_t alpha) {
+ ArtworkImage image{side, side, {}};
+ for (std::uint32_t i = 0; i < side * side; ++i) image.rgba.insert(image.rgba.end(), {255, 0, 0, alpha});
+ return image;
+ };
+ const ArtworkImage large = solid(kSmallProgramIconSide, 255);
+ CHECK(ProgramIconIsOpaque(large) && !ProgramIconIsOpaque(solid(8, 200)));
+ auto art = ProgramIconArt(large, 320, 480);
+ CHECK(art && art->width == 320 && art->height == 480 && art->rgba.size() == 320u * 480 * 4);
+ CHECK(Pixel(*art, 2, 2)[0] == 255 && Pixel(*art, 160, 160)[0] == 255 && Pixel(*art, 317, 317)[0] == 255);
+ CHECK(Pixel(*art, 160, 330)[0] < 170 && Pixel(*art, 160, 478)[0] < Pixel(*art, 160, 330)[0]);
+ CHECK(Pixel(*art, 160, 400)[1] == 0 && Pixel(*art, 160, 400)[3] == 255);
+ // A small one, or a see-through one, sits in the middle of the square over the darker backdrop.
+ for (const auto& centred : {solid(kSmallProgramIconSide - 1, 255), solid(kSmallProgramIconSide, 100)}) {
+ art = ProgramIconArt(centred, 300, 300);
+ CHECK(art && art->height == 300);
+ CHECK(Pixel(*art, 4, 4)[0] < 200 && Pixel(*art, 150, 150)[0] > Pixel(*art, 4, 4)[0]);
+ }
+ CHECK(Pixel(*ProgramIconArt(solid(kSmallProgramIconSide - 1, 255), 300, 300), 150, 150)[0] == 255);
+ // A stand-in for the generic floppy: plain grey.
+ ArtworkImage floppy{256, 256, std::vector<std::uint8_t>(256u * 256 * 4, 100)};
+ for (std::size_t i = 3; i < floppy.rgba.size(); i += 4) floppy.rgba[i] = 255;
+ // Opaque means at least 99% of the pixels at alpha 224 or more.
+ CHECK(ProgramIconIsOpaque(solid(10, 224)) && !ProgramIconIsOpaque(solid(10, 223)));
+ ArtworkImage gaps = solid(10, 255);
+ gaps.rgba[3] = 0; // 1 in 100
+ CHECK(ProgramIconIsOpaque(gaps));
+ gaps.rgba[7] = 0; // 2 in 100
+ CHECK(!ProgramIconIsOpaque(gaps));
+ // 128 pixels fill the square; 127 do not. A wide icon fits its width; a wide image keeps the square centred.
+ CHECK(Pixel(*ProgramIconArt(solid(128, 255), 300, 300), 2, 2)[0] == 255);
+ CHECK(Pixel(*ProgramIconArt(solid(127, 255), 300, 300), 2, 2)[0] < 255);
+ ArtworkImage wide{256, 128, {}};
+ for (std::uint32_t i = 0; i < 256u * 128; ++i) wide.rgba.insert(wide.rgba.end(), {255, 0, 0, 255});
+ art = ProgramIconArt(wide, 320, 480);
+ CHECK(art && Pixel(*art, 2, 160)[0] == 255 && Pixel(*art, 160, 10)[0] < 255);
+ art = ProgramIconArt(solid(128, 255), 480, 320);
+ CHECK(art && Pixel(*art, 240, 160)[0] == 255 && Pixel(*art, 4, 160)[0] < 255);
+ for (const auto& [w, h] : {std::pair<std::uint32_t, std::uint32_t>{1, 1}, {1, 480}, {480, 1}})
+ CHECK(ProgramIconArt(solid(128, 255), w, h) && ProgramIconArt(solid(16, 100), w, h));
+ // A thin opaque icon still gets rounded corners within its own size.
+ for (const auto& [w, h] : {std::pair<std::uint32_t, std::uint32_t>{1, 127}, {127, 1}}) {
+ ArtworkImage thin{w, h, {}};
+ for (std::uint32_t i = 0; i < w * h; ++i) thin.rgba.insert(thin.rgba.end(), {255, 0, 0, 255});
+ CHECK(ProgramIconArt(thin, 320, 480) && ProgramIconArt(thin, 480, 320) && MakeProgramTitleIcon(thin, &floppy));
+ }
ArtworkImage clear{1, 1, {255, 255, 255, 0}};
- tile = ProgramIconTile(clear, 30);
- CHECK(tile && Pixel(*tile, 15, 15)[0] == 0x24);
- CHECK(!ProgramIconTile(ArtworkImage{}, 30) && !ProgramIconTile(half, 0));
- const auto png = MakeProgramTitleIcon(half);
- int width = 0, height = 0, components = 0;
- auto* pixels = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(png->data()), static_cast<int>(png->size()),
- &width, &height, &components, 3);
- CHECK(pixels && width == 512 && height == 512 && pixels[0] == 0x24 && pixels[(256 * 512 + 256) * 3] == 255);
- stbi_image_free(pixels);
+ art = ProgramIconArt(clear, 30, 30); // nothing but the dark ground
+ CHECK(art && Pixel(*art, 15, 15)[0] < 0x24);
+ CHECK(!ProgramIconArt(ArtworkImage{}, 30, 30) && !ProgramIconArt(large, 0, 30) && !ProgramIconArt(large, 30, kMaxArtworkDimension + 1));
+
+ // The PS5 title icon: the art at 512, or a small icon on the floppy's label.
+ const auto decode = [](const std::optional<std::string>& png, int x, int y) {
+ std::vector<std::uint8_t> rgb;
+ int width = 0, height = 0, components = 0;
+ if (!png) return rgb;
+ auto* pixels = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(png->data()), static_cast<int>(png->size()),
+ &width, &height, &components, 3);
+ if (pixels && width == 512 && height == 512) rgb.assign(pixels + (y * 512 + x) * 3, pixels + (y * 512 + x) * 3 + 3);
+ stbi_image_free(pixels);
+ return rgb;
+ };
+ auto at = decode(MakeProgramTitleIcon(large, &floppy), 4, 4);
+ CHECK(at.size() == 3 && at[0] == 255 && at[1] == 0);
+ const ArtworkImage small = solid(16, 255);
+ at = decode(MakeProgramTitleIcon(small, &floppy), 4, 4);
+ CHECK(at.size() == 3 && at[0] == 100 && at[1] == 100); // the floppy itself
+ at = decode(MakeProgramTitleIcon(small, &floppy), 255, 338);
+ CHECK(at.size() == 3 && at[0] == 255 && at[1] == 0); // the middle of its label
+ at = decode(MakeProgramTitleIcon(small), 255, 255); // no floppy: the art
+ CHECK(at.size() == 3 && at[0] == 255);
+ at = decode(MakeProgramTitleIcon(small), 4, 4);
+ CHECK(at.size() == 3 && at[0] < 200);
+ CHECK(!MakeProgramTitleIcon(ArtworkImage{}, &floppy));
fs::remove_all(root);
std::puts("program icon tests passed");