Qt: implement GetOpaqueImageArea

This commit is contained in:
Megamouse 2017-09-15 21:01:54 +02:00 committed by Ivan
parent 85b9809b39
commit 77a75305c7
2 changed files with 40 additions and 0 deletions

View File

@ -141,6 +141,45 @@ QPixmap gui_settings::colorizedPixmap(const QPixmap& old_pixmap, const QColor& o
return pixmap;
}
QImage gui_settings::GetOpaqueImageArea(const QString& path)
{
QImage image = QImage(path);
int w_min = 0;
int w_max = image.width();
int h_min = 0;
int h_max = image.height();
for (int y = 0; y < image.height(); ++y)
{
QRgb *row = (QRgb*)image.scanLine(y);
bool rowFilled = false;
for (int x = 0; x < image.width(); ++x)
{
if (qAlpha(row[x]))
{
rowFilled = true;
w_min = std::max(w_min, x);
if (w_max > x)
{
w_max = x;
x = w_min;
}
}
}
if (rowFilled)
{
h_max = std::min(h_max, y);
h_min = y;
}
}
return image.copy(QRect(QPoint(w_max, h_max), QPoint(w_min, h_min)));
}
void gui_settings::SetValue(const GUI_SAVE& entry, const QVariant& value)
{
m_settings.beginGroup(entry.key);

View File

@ -195,6 +195,7 @@ public:
*/
static QIcon colorizedIcon(const QIcon& icon, const QColor& oldColor, const QColor& newColor, bool useSpecialMasks = false, bool colorizeAll = false);
static QPixmap colorizedPixmap(const QPixmap& old_pixmap, const QColor& oldColor, const QColor& newColor, bool useSpecialMasks = false, bool colorizeAll = false);
static QImage GetOpaqueImageArea(const QString& path);
public Q_SLOTS:
void Reset(bool removeMeta = false);