From 1d4640c85c97b0e21d00b5b2b6b5815889163c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 15 Jun 2024 06:01:04 +0200 Subject: [PATCH] Code cleanup --- src/sprites.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sprites.cpp b/src/sprites.cpp index d03540c..3b9b046 100644 --- a/src/sprites.cpp +++ b/src/sprites.cpp @@ -95,6 +95,25 @@ bool Sprites::load(const QString &jsonFile, const QString &imageFile) QImage Sprites::sprite(const Sprite &sprite, const QColor &color, qreal scale) { + _lock.lock(); + if (_init <= 0) { + if (_init < 0) { + _lock.unlock(); + return QImage(); + } + + _img = QImage(_imageFile); + if (_img.isNull()) { + qWarning() << _imageFile << ": invalid sprite atlas image"; + _init = -1; + _lock.unlock(); + return QImage(); + } + + _init = 1; + } + _lock.unlock(); + if (!_img.rect().contains(sprite.rect())) return QImage(); @@ -118,25 +137,6 @@ QImage Sprites::icon(const QString &name, const QColor &color, qreal size) if (name.isNull()) return QImage(); - _lock.lock(); - if (_init <= 0) { - if (_init < 0) { - _lock.unlock(); - return QImage(); - } - - _img = QImage(_imageFile); - if (_img.isNull()) { - qWarning() << _imageFile << ": invalid sprite atlas image"; - _init = -1; - _lock.unlock(); - return QImage(); - } - - _init = 1; - } - _lock.unlock(); - QMap::const_iterator it = _sprites.constFind(name); if (it == _sprites.constEnd()) return QImage();