2019-08-07 02:56:56 +00:00
|
|
|
// Copyright 2019 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QString>
|
2019-08-14 05:04:50 +00:00
|
|
|
#include "citra_qt/qt_image_interface.h"
|
2019-08-07 02:56:56 +00:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
|
|
|
|
bool QtImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
|
|
|
|
const std::string& path) {
|
|
|
|
QImage image(QString::fromStdString(path));
|
|
|
|
|
|
|
|
if (image.isNull()) {
|
|
|
|
LOG_ERROR(Frontend, "Failed to open {} for decoding", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
width = image.width();
|
|
|
|
height = image.height();
|
|
|
|
|
2019-08-14 05:04:50 +00:00
|
|
|
image = image.convertToFormat(QImage::Format_RGBA8888);
|
|
|
|
|
2019-08-07 02:56:56 +00:00
|
|
|
// Write RGBA8 to vector
|
2019-08-14 05:04:50 +00:00
|
|
|
dst = std::vector<u8>(image.constBits(), image.constBits() + (width * height * 4));
|
2019-08-07 02:56:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QtImageInterface::EncodePNG(const std::string& path, const std::vector<u8>& src, u32 width,
|
|
|
|
u32 height) {
|
|
|
|
QImage image(src.data(), width, height, QImage::Format_RGBA8888);
|
|
|
|
|
2019-08-07 18:21:47 +00:00
|
|
|
if (!image.save(QString::fromStdString(path), "PNG")) {
|
2019-08-07 02:56:56 +00:00
|
|
|
LOG_ERROR(Frontend, "Failed to save {}", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2019-10-12 15:25:27 +00:00
|
|
|
}
|