changed .clang-format
This commit is contained in:
+139
-133
@@ -22,157 +22,163 @@
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
// Frames
|
||||
Frames::Frames()
|
||||
{
|
||||
DebugCount::increase("images");
|
||||
}
|
||||
|
||||
Frames::Frames(const QVector<Frame<QPixmap>> &frames)
|
||||
: items_(frames)
|
||||
{
|
||||
assertInGuiThread();
|
||||
DebugCount::increase("images");
|
||||
|
||||
if (this->animated()) {
|
||||
DebugCount::increase("animated images");
|
||||
|
||||
this->gifTimerConnection_ = getApp()->emotes->gifTimer.signal.connect(
|
||||
[this] { this->advance(); });
|
||||
}
|
||||
}
|
||||
|
||||
Frames::~Frames()
|
||||
{
|
||||
assertInGuiThread();
|
||||
DebugCount::decrease("images");
|
||||
|
||||
if (this->animated()) {
|
||||
DebugCount::decrease("animated images");
|
||||
// Frames
|
||||
Frames::Frames()
|
||||
{
|
||||
DebugCount::increase("images");
|
||||
}
|
||||
|
||||
this->gifTimerConnection_.disconnect();
|
||||
}
|
||||
Frames::Frames(const QVector<Frame<QPixmap>> &frames)
|
||||
: items_(frames)
|
||||
{
|
||||
assertInGuiThread();
|
||||
DebugCount::increase("images");
|
||||
|
||||
void Frames::advance()
|
||||
{
|
||||
this->durationOffset_ += GIF_FRAME_LENGTH;
|
||||
if (this->animated()) {
|
||||
DebugCount::increase("animated images");
|
||||
|
||||
while (true) {
|
||||
this->index_ %= this->items_.size();
|
||||
|
||||
if (this->index_ >= this->items_.size()) {
|
||||
this->index_ = this->index_;
|
||||
}
|
||||
|
||||
if (this->durationOffset_ > this->items_[this->index_].duration) {
|
||||
this->durationOffset_ -= this->items_[this->index_].duration;
|
||||
this->index_ = (this->index_ + 1) % this->items_.size();
|
||||
} else {
|
||||
break;
|
||||
this->gifTimerConnection_ =
|
||||
getApp()->emotes->gifTimer.signal.connect(
|
||||
[this] { this->advance(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Frames::animated() const
|
||||
{
|
||||
return this->items_.size() > 1;
|
||||
}
|
||||
Frames::~Frames()
|
||||
{
|
||||
assertInGuiThread();
|
||||
DebugCount::decrease("images");
|
||||
|
||||
boost::optional<QPixmap> Frames::current() const
|
||||
{
|
||||
if (this->items_.size() == 0) return boost::none;
|
||||
return this->items_[this->index_].image;
|
||||
}
|
||||
if (this->animated()) {
|
||||
DebugCount::decrease("animated images");
|
||||
}
|
||||
|
||||
boost::optional<QPixmap> Frames::first() const
|
||||
{
|
||||
if (this->items_.size() == 0) return boost::none;
|
||||
return this->items_.front().image;
|
||||
}
|
||||
this->gifTimerConnection_.disconnect();
|
||||
}
|
||||
|
||||
// functions
|
||||
QVector<Frame<QImage>> readFrames(QImageReader &reader, const Url &url)
|
||||
{
|
||||
QVector<Frame<QImage>> frames;
|
||||
void Frames::advance()
|
||||
{
|
||||
this->durationOffset_ += GIF_FRAME_LENGTH;
|
||||
|
||||
while (true) {
|
||||
this->index_ %= this->items_.size();
|
||||
|
||||
if (this->index_ >= this->items_.size()) {
|
||||
this->index_ = this->index_;
|
||||
}
|
||||
|
||||
if (this->durationOffset_ > this->items_[this->index_].duration) {
|
||||
this->durationOffset_ -= this->items_[this->index_].duration;
|
||||
this->index_ = (this->index_ + 1) % this->items_.size();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Frames::animated() const
|
||||
{
|
||||
return this->items_.size() > 1;
|
||||
}
|
||||
|
||||
boost::optional<QPixmap> Frames::current() const
|
||||
{
|
||||
if (this->items_.size() == 0) return boost::none;
|
||||
return this->items_[this->index_].image;
|
||||
}
|
||||
|
||||
boost::optional<QPixmap> Frames::first() const
|
||||
{
|
||||
if (this->items_.size() == 0) return boost::none;
|
||||
return this->items_.front().image;
|
||||
}
|
||||
|
||||
// functions
|
||||
QVector<Frame<QImage>> readFrames(QImageReader &reader, const Url &url)
|
||||
{
|
||||
QVector<Frame<QImage>> frames;
|
||||
|
||||
if (reader.imageCount() == 0) {
|
||||
log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
return frames;
|
||||
}
|
||||
|
||||
QImage image;
|
||||
for (int index = 0; index < reader.imageCount(); ++index) {
|
||||
if (reader.read(&image)) {
|
||||
QPixmap::fromImage(image);
|
||||
|
||||
int duration = std::max(20, reader.nextImageDelay());
|
||||
frames.push_back(Frame<QImage>{image, duration});
|
||||
}
|
||||
}
|
||||
|
||||
if (frames.size() == 0) {
|
||||
log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
}
|
||||
|
||||
if (reader.imageCount() == 0) {
|
||||
log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
return frames;
|
||||
}
|
||||
|
||||
QImage image;
|
||||
for (int index = 0; index < reader.imageCount(); ++index) {
|
||||
if (reader.read(&image)) {
|
||||
QPixmap::fromImage(image);
|
||||
|
||||
int duration = std::max(20, reader.nextImageDelay());
|
||||
frames.push_back(Frame<QImage>{image, duration});
|
||||
}
|
||||
}
|
||||
|
||||
if (frames.size() == 0) {
|
||||
log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
// parsed
|
||||
template <typename Assign>
|
||||
void assignDelayed(
|
||||
std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>> &queued,
|
||||
std::mutex &mutex, std::atomic_bool &loadedEventQueued)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
int i = 0;
|
||||
|
||||
while (!queued.empty()) {
|
||||
queued.front().first(queued.front().second);
|
||||
queued.pop();
|
||||
|
||||
if (++i > 50) {
|
||||
QTimer::singleShot(
|
||||
3, [&] { assignDelayed(queued, mutex, loadedEventQueued); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
loadedEventQueued = false;
|
||||
}
|
||||
|
||||
template <typename Assign>
|
||||
auto makeConvertCallback(const QVector<Frame<QImage>> &parsed, Assign assign)
|
||||
{
|
||||
return [parsed, assign] {
|
||||
// convert to pixmap
|
||||
auto frames = QVector<Frame<QPixmap>>();
|
||||
std::transform(parsed.begin(), parsed.end(), std::back_inserter(frames),
|
||||
[](auto &frame) {
|
||||
return Frame<QPixmap>{
|
||||
QPixmap::fromImage(frame.image), frame.duration};
|
||||
});
|
||||
|
||||
// put into stack
|
||||
static std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>> queued;
|
||||
static std::mutex mutex;
|
||||
|
||||
// parsed
|
||||
template <typename Assign>
|
||||
void assignDelayed(
|
||||
std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>> &queued,
|
||||
std::mutex &mutex, std::atomic_bool &loadedEventQueued)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
queued.emplace(assign, frames);
|
||||
int i = 0;
|
||||
|
||||
static std::atomic_bool loadedEventQueued{false};
|
||||
while (!queued.empty()) {
|
||||
queued.front().first(queued.front().second);
|
||||
queued.pop();
|
||||
|
||||
if (!loadedEventQueued) {
|
||||
loadedEventQueued = true;
|
||||
|
||||
QTimer::singleShot(
|
||||
100, [=] { assignDelayed(queued, mutex, loadedEventQueued); });
|
||||
if (++i > 50) {
|
||||
QTimer::singleShot(3, [&] {
|
||||
assignDelayed(queued, mutex, loadedEventQueued);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
loadedEventQueued = false;
|
||||
}
|
||||
|
||||
template <typename Assign>
|
||||
auto makeConvertCallback(const QVector<Frame<QImage>> &parsed,
|
||||
Assign assign)
|
||||
{
|
||||
return [parsed, assign] {
|
||||
// convert to pixmap
|
||||
auto frames = QVector<Frame<QPixmap>>();
|
||||
std::transform(parsed.begin(), parsed.end(),
|
||||
std::back_inserter(frames), [](auto &frame) {
|
||||
return Frame<QPixmap>{
|
||||
QPixmap::fromImage(frame.image),
|
||||
frame.duration};
|
||||
});
|
||||
|
||||
// put into stack
|
||||
static std::queue<std::pair<Assign, QVector<Frame<QPixmap>>>>
|
||||
queued;
|
||||
static std::mutex mutex;
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
queued.emplace(assign, frames);
|
||||
|
||||
static std::atomic_bool loadedEventQueued{false};
|
||||
|
||||
if (!loadedEventQueued) {
|
||||
loadedEventQueued = true;
|
||||
|
||||
QTimer::singleShot(100, [=] {
|
||||
assignDelayed(queued, mutex, loadedEventQueued);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// IMAGE2
|
||||
|
||||
Reference in New Issue
Block a user