Skip to content

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

C++

Replace the floppy on small icons' Home tiles

Leonardo Lobato8037efbbe592
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index 541cddb..53bba5e 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -573,10 +573,6 @@ 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;
@@ -586,7 +582,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, generic_floppy](
+ config.title_icon = [trust = paths.trust_store, art_cache_dir, generic_icon](
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);
@@ -599,9 +595,7 @@ 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());
- // 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) {
+ if (auto icon = own ? playden::homebrew::MakeProgramTitleIcon(*own) : 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() +
" size=" + std::to_string(own->width) + "x" + std::to_string(own->height));
diff --git a/src/homebrew/title_icon.cpp b/src/homebrew/title_icon.cpp
index c4f1fd2..633c741 100644
--- a/src/homebrew/title_icon.cpp
+++ b/src/homebrew/title_icon.cpp
@@ -63,9 +63,10 @@ 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;
+// A small icon on a PS5 title icon: a whole number of pixels per icon pixel, up to this many across
+// (9/16 of the tile: 32 pixels scale by 9 and 48 by 6), over a backdrop at this brightness.
+constexpr std::uint32_t kSmallTitleIconLimit = kTitleIconSize * 9 / 16;
+constexpr double kSmallTitleIconBrightness = 0.45;
bool Valid(const ArtworkImage& image) {
return image.width != 0 && image.height != 0 &&
@@ -93,8 +94,9 @@ struct Layer {
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) {
+// Bilinear on alpha-weighted colours, or nearest-neighbour when `pixelated`; `radius` rounds the corners
+// with anti-aliased edges.
+Layer Scale(const ArtworkImage& icon, double centre_x, double centre_y, double side, double radius, bool pixelated = false) {
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)));
@@ -106,8 +108,10 @@ Layer Scale(const ArtworkImage& icon, double centre_x, double centre_y, double s
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 double offset = pixelated ? 0.0 : 0.5;
+ const double fit_x = (x + 0.5) / scale - offset, fit_y = (y + 0.5) / scale - offset;
+ const double sx = std::clamp(pixelated ? std::floor(fit_x) : fit_x, 0.0, icon.width - 1.0);
+ const double sy = std::clamp(pixelated ? std::floor(fit_y) : fit_y, 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;
@@ -183,7 +187,7 @@ void Shadow(ArtworkImage& target, const Layer& layer, std::uint32_t blur, long d
// 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) {
+ArtworkImage Backdrop(const ArtworkImage& icon, std::uint32_t width, std::uint32_t height, double base_brightness) {
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;
@@ -229,7 +233,7 @@ ArtworkImage Backdrop(const ArtworkImage& icon, std::uint32_t width, std::uint32
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;
+ double brightness = base_brightness;
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);
@@ -254,6 +258,12 @@ ArtworkImage Backdrop(const ArtworkImage& icon, std::uint32_t width, std::uint32
bool Small(const ArtworkImage& icon) { return std::max(icon.width, icon.height) < kSmallProgramIconSide; }
+// A centred icon on its backdrop, with a shadow.
+void PlaceCentred(ArtworkImage& art, const Layer& layer, std::uint32_t square) {
+ Shadow(art, layer, static_cast<std::uint32_t>(std::lround(square * 0.04)), std::lround(square * 0.02), 0.6);
+ Composite(art, layer);
+}
+
} // namespace
bool ProgramIconIsOpaque(const ArtworkImage& icon) {
@@ -266,7 +276,7 @@ bool ProgramIconIsOpaque(const ArtworkImage& icon) {
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);
+ ArtworkImage art = Backdrop(icon, width, height, kBackdropBrightness);
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);
@@ -275,26 +285,20 @@ std::optional<ArtworkImage> ProgramIconArt(const ArtworkImage& icon, std::uint32
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);
+ PlaceCentred(art, Scale(icon, centre_x, centre_y, side, opaque ? side * kCentredIconRounding : 0.0), square);
return art;
}
-std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon, const ArtworkImage* floppy) {
+std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon) {
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);
+ if (Small(icon)) {
+ ArtworkImage art = Backdrop(icon, kTitleIconSize, kTitleIconSize, kSmallTitleIconBrightness);
+ const std::uint32_t longer = std::max(icon.width, icon.height);
+ const double side = kSmallTitleIconLimit / longer * longer;
+ const double centre = kTitleIconSize / 2.0;
+ const double radius = ProgramIconIsOpaque(icon) ? side * kCentredIconRounding : 0.0;
+ PlaceCentred(art, Scale(icon, centre, centre, side, radius, true), kTitleIconSize);
+ return MakeTitleIcon(art);
}
const auto art = ProgramIconArt(icon, kTitleIconSize, kTitleIconSize);
return art ? MakeTitleIcon(*art) : std::nullopt;
diff --git a/src/homebrew/title_icon.hpp b/src/homebrew/title_icon.hpp
index b5ec284..e3ecc2b 100644
--- a/src/homebrew/title_icon.hpp
+++ b/src/homebrew/title_icon.hpp
@@ -11,7 +11,7 @@ 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.
+// 48 pixel icon. It is centred instead, and on the console's Home scaled by whole pixels to stay sharp.
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;
@@ -31,7 +31,9 @@ bool ProgramIconIsOpaque(const ArtworkImage& icon);
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);
+// small icon, the same layout with sharper, smaller art on a darker backdrop: the icon scaled by the largest
+// whole number that fits 9/16 of the tile, without smoothing, and corners rounded if it is opaque. Each
+// Home tile is small, and a smooth upscale of an old game's icon looks blurry there.
+std::optional<std::string> MakeProgramTitleIcon(const ArtworkImage& icon);
} // namespace playden::homebrew
diff --git a/tests/homebrew_program_icon_test.cpp b/tests/homebrew_program_icon_test.cpp
index 9a27b68..a668600 100644
--- a/tests/homebrew_program_icon_test.cpp
+++ b/tests/homebrew_program_icon_test.cpp
@@ -279,9 +279,6 @@ int main() {
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);
@@ -304,14 +301,14 @@ int main() {
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));
+ CHECK(ProgramIconArt(thin, 320, 480) && ProgramIconArt(thin, 480, 320) && MakeProgramTitleIcon(thin));
}
ArtworkImage clear{1, 1, {255, 255, 255, 0}};
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.
+ // The PS5 title icon: the art at 512, or a small icon scaled by whole pixels over a darker backdrop.
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;
@@ -322,18 +319,75 @@ int main() {
stbi_image_free(pixels);
return rgb;
};
- auto at = decode(MakeProgramTitleIcon(large, &floppy), 4, 4);
+ auto at = decode(MakeProgramTitleIcon(large), 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
+ // A larger see-through icon is the same art as on the library's square, unchanged.
+ const ArtworkImage see_through = solid(kSmallProgramIconSide, 100);
+ CHECK(MakeProgramTitleIcon(see_through) == MakeTitleIcon(*ProgramIconArt(see_through, kTitleIconSize, kTitleIconSize)));
+ CHECK(MakeProgramTitleIcon(large) == MakeTitleIcon(*ProgramIconArt(large, kTitleIconSize, kTitleIconSize)));
+ // The backdrop of a small icon is at 45%, darker than the library's.
+ at = decode(MakeProgramTitleIcon(solid(16, 255)), 4, 4);
+ CHECK(at.size() == 3 && at[0] == 115 && at[1] == 0);
+ // The largest whole-number scale within 288 pixels, centred: the row through the middle crosses its edges.
+ const auto spans = [&](std::uint32_t side, int first, int last) {
+ const auto icon = MakeProgramTitleIcon(solid(side, 255));
+ const auto red = [&](int x) { const auto rgb = decode(icon, x, 256); return rgb.size() == 3 && rgb[0] == 255; };
+ return red(first) && red(last) && !red(first - 1) && !red(last + 1);
+ };
+ CHECK(spans(16, 112, 399)); // 18x
+ CHECK(spans(32, 112, 399)); // 9x
+ CHECK(spans(48, 112, 399)); // 6x
+ CHECK(spans(64, 128, 383)); // 4x
+ CHECK(spans(97, 159, 352)); // 2x
+ CHECK(spans(127, 129, 382)); // 2x
+ // A wide icon scales by its longer side, keeping its shape.
+ ArtworkImage banner{32, 16, {}};
+ for (std::uint32_t i = 0; i < 32u * 16; ++i) banner.rgba.insert(banner.rgba.end(), {255, 0, 0, 255});
+ at = decode(MakeProgramTitleIcon(banner), 256, 256 - 72);
+ CHECK(at.size() == 3 && at[0] == 255);
+ at = decode(MakeProgramTitleIcon(banner), 256, 256 - 73);
+ CHECK(at.size() == 3 && at[0] < 255);
+ // Each icon pixel stays sharp: a hard edge between two colours, with no blend across it.
+ ArtworkImage halves{32, 32, {}};
+ for (std::uint32_t y = 0; y < 32; ++y)
+ for (std::uint32_t x = 0; x < 32; ++x)
+ halves.rgba.insert(halves.rgba.end(), {static_cast<std::uint8_t>(x < 16 ? 255 : 0), 0, static_cast<std::uint8_t>(x < 16 ? 0 : 255), 255});
+ const auto sharp = MakeProgramTitleIcon(halves);
+ at = decode(sharp, 255, 256);
+ CHECK(at.size() == 3 && at[0] == 255 && at[2] == 0);
+ at = decode(sharp, 256, 256);
+ CHECK(at.size() == 3 && at[0] == 0 && at[2] == 255);
+ // An opaque small icon has rounded corners.
+ at = decode(MakeProgramTitleIcon(solid(32, 255)), 112, 112);
+ CHECK(at.size() == 3 && at[0] < 255);
+ at = decode(MakeProgramTitleIcon(solid(32, 255)), 136, 136);
+ CHECK(at.size() == 3 && at[0] == 255);
+ // A see-through one keeps its own shape: its right half is solid up to the corner, its left half clear.
+ ArtworkImage half_clear{32, 32, {}};
+ for (std::uint32_t y = 0; y < 32; ++y)
+ for (std::uint32_t x = 0; x < 32; ++x)
+ half_clear.rgba.insert(half_clear.rgba.end(), {255, 0, 0, static_cast<std::uint8_t>(x < 16 ? 0 : 255)});
+ const auto cutout = MakeProgramTitleIcon(half_clear);
+ at = decode(cutout, 399, 112);
CHECK(at.size() == 3 && at[0] == 255);
- at = decode(MakeProgramTitleIcon(small), 4, 4);
- CHECK(at.size() == 3 && at[0] < 200);
- CHECK(!MakeProgramTitleIcon(ArtworkImage{}, &floppy));
+ at = decode(cutout, 256, 256);
+ CHECK(at.size() == 3 && at[0] == 255);
+ at = decode(cutout, 255, 256);
+ CHECK(at.size() == 3 && at[0] < 255);
+ // Thin and single-pixel icons scale too, centred.
+ CHECK(spans(1, 112, 399)); // 288x
+ const ArtworkImage tall{1, 127, std::vector<std::uint8_t>(solid(1, 255).rgba.size() * 127, 255)};
+ const ArtworkImage flat{127, 1, tall.rgba};
+ const auto red_at = [&](const ArtworkImage& icon, int x, int y) {
+ const auto rgb = decode(MakeProgramTitleIcon(icon), x, y);
+ return rgb.size() == 3 && rgb[0] == 255;
+ };
+ CHECK(red_at(tall, 255, 256) && red_at(tall, 256, 256) && !red_at(tall, 254, 256) && !red_at(tall, 257, 256));
+ CHECK(red_at(flat, 256, 255) && red_at(flat, 256, 256) && !red_at(flat, 256, 254) && !red_at(flat, 256, 257));
+ // A clear single pixel leaves only the backdrop of the dark ground.
+ at = decode(MakeProgramTitleIcon(ArtworkImage{1, 1, {255, 255, 255, 0}}), 256, 256);
+ CHECK(at.size() == 3 && at[0] < 0x24);
+ CHECK(!MakeProgramTitleIcon(ArtworkImage{}));
fs::remove_all(root);
std::puts("program icon tests passed");