Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149// SPDX-License-Identifier: GPL-3.0-or-later// Contact sheets for XP PE icon groups and toolbar bitmap strips. Nothing// extracted is shipped; this reads the user's XP media through XPlasma.#include "app/media.h"#include "core/dib.h"#include "core/icons.h"#include "core/pe.h"
#include <QFile>#include <QFileInfo>#include <QGuiApplication>#include <QPainter>#include <QRegularExpression>#include <QSet>#include <QTextStream>
#include <optional>
namespace {
struct Cell{ QString label; QImage image;};
std::optional<QSet<QString>> requested(const QStringList &args){ QSet<QString> ids; static const QRegularExpression number(QStringLiteral("^([0-9]+)(?:-([0-9]+))?$")); for (const QString &arg : args) { const auto m = number.match(arg); if (!m.hasMatch()) return std::nullopt; bool firstValid = false, lastValid = false; const int first = m.captured(1).toInt(&firstValid); const int last = m.hasCaptured(2) ? m.captured(2).toInt(&lastValid) : first; if (!m.hasCaptured(2)) lastValid = firstValid; if (!firstValid || !lastValid || last < first || last > 100000 || last - first > 10000) return std::nullopt; for (int id = first; id <= last; ++id) ids.insert(QString::number(id)); } return ids;}
QImage icon(const xpl::PeResources &pe, const QString &id){ const auto images = xpl::iconGroup(pe, id); if (images.isEmpty()) return {}; auto it = images.lowerBound(32); if (it == images.end()) --it; return it->image.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation);}
QList<Cell> cells(const xpl::PeResources &pe, bool bitmaps, const QSet<QString> &ids){ QList<Cell> out; for (const xpl::Resource *r : pe.ofType(bitmaps ? u"2" : u"14")) { if (!ids.isEmpty() && !ids.contains(r->name)) continue; if (!bitmaps) { if (const QImage image = icon(pe, r->name); !image.isNull()) out.append({r->name, image}); continue; } const QImage strip = xpl::decodeDib(r->data).image; // Toolbar strips are a row of square, native-size glyphs. Other // bitmaps (e.g. backgrounds or animation sheets) are not icons. if (strip.isNull() || strip.height() > 48 || strip.width() % strip.height() != 0) continue; const int size = strip.height(); for (int i = 0; i < strip.width() / size; ++i) out.append({QStringLiteral("%1:%2").arg(r->name).arg(i), strip.copy(i * size, 0, size, size)}); } return out;}
QImage sheet(const QList<Cell> &cells){ constexpr int columns = 12, width = 64, height = 56; QImage page(columns * width, ((cells.size() + columns - 1) / columns) * height, QImage::Format_ARGB32_Premultiplied); page.fill(Qt::white); QPainter p(&page); p.setFont(QFont(QStringLiteral("Sans Serif"), 9)); for (int i = 0; i < cells.size(); ++i) { const int x = (i % columns) * width, y = (i / columns) * height; const QImage &icon = cells.at(i).image; p.drawImage(x + (width - icon.width()) / 2, y + (36 - icon.height()) / 2, icon); p.setPen(Qt::black); p.drawText(QRect(x, y + 36, width, 18), Qt::AlignCenter, cells.at(i).label); p.setPen(QColor(230, 230, 230)); p.drawRect(x, y, width - 1, height - 1); } return page;}
} // namespace
int main(int argc, char **argv){ QGuiApplication app(argc, argv); QTextStream err(stderr), out(stdout); QStringList args = app.arguments().mid(1); const bool bitmaps = args.removeAll(QStringLiteral("--bitmaps")) != 0; if (args.size() < 2) { err << "usage: xplasma-icons-sheet FILE OUT.png [--bitmaps] [ID|FIRST-LAST ...]\n" "FILE is a PE path or an XP system filename (e.g. shell32.dll).\n" "--bitmaps labels individual toolbar cells as RESOURCE:INDEX.\n"; return 2; } const QString source = args.takeFirst(), destination = args.takeFirst(); const auto ids = requested(args); if (!ids) { err << "invalid resource id or range\n"; return 2; } QString why; QByteArray bytes; if (QFileInfo::exists(source)) { QFile file(source); if (!file.open(QIODevice::ReadOnly)) { err << file.errorString() << '\n'; return 1; } bytes = file.readAll(); } else if (const auto xp = xpl::media::systemFile(source, &why)) { bytes = *xp; } else { err << why << '\n'; return 1; } const auto pe = xpl::PeResources::parse(bytes, &why); if (!pe) { err << why << '\n'; return 1; } const auto found = cells(*pe, bitmaps, *ids); if (found.isEmpty() || !sheet(found).save(destination)) { err << "no usable resource cells, or cannot write " << destination << '\n'; return 1; } out << destination << ": " << found.size() << " cells\n"; return 0;}