add image interface, remove lodepng from video_core/core, address more comments, fix comments

remove unnecessary conversion
This commit is contained in:
Khangaroo
2019-08-06 22:56:56 -04:00
committed by James Rowe
parent 5940361b81
commit b81c15941e
16 changed files with 208 additions and 55 deletions

View File

@@ -142,6 +142,8 @@ add_executable(citra-qt
multiplayer/validation.h
uisettings.cpp
uisettings.h
qt_image_interface.cpp
qt_image_interface.h
updater/updater.cpp
updater/updater.h
updater/updater_p.h

View File

@@ -51,6 +51,7 @@
#include "citra_qt/main.h"
#include "citra_qt/multiplayer/state.h"
#include "citra_qt/uisettings.h"
#include "citra_qt/qt_image_interface.h"
#include "citra_qt/updater/updater.h"
#include "citra_qt/util/clickable_label.h"
#include "common/common_paths.h"
@@ -2059,6 +2060,9 @@ int main(int argc, char* argv[]) {
Core::System::GetInstance().RegisterMiiSelector(std::make_shared<QtMiiSelector>(main_window));
Core::System::GetInstance().RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window));
// Register Qt image interface
Core::System::GetInstance().RegisterImageInterface(std::make_shared<QtImageInterface>());
main_window.show();
QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window,

View File

@@ -0,0 +1,46 @@
// Copyright 2019 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QBuffer>
#include <QImage>
#include <QString>
#include "common/logging/log.h"
#include "core/frontend/image_interface.h"
#include "qt_image_interface.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();
// Write RGBA8 to vector
for (u32 y = 1; y < image.height() + 1; y++) {
for (u32 x = 1; x < image.width() + 1; x++) {
const QColor pixel(image.pixel(y, x));
dst.push_back(pixel.red());
dst.push_back(pixel.green());
dst.push_back(pixel.blue());
dst.push_back(pixel.alpha());
}
}
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);
if (!image.save(QString::fromStdString(path))) {
LOG_ERROR(Frontend, "Failed to save {}", path);
return false;
}
return true;
}

View File

@@ -0,0 +1,14 @@
// Copyright 2019 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "core/frontend/image_interface.h"
class QtImageInterface final : public Frontend::ImageInterface {
public:
bool DecodePNG(std::vector<u8>& dst, u32& width, u32& height, const std::string& path) override;
bool EncodePNG(const std::string& path, const std::vector<u8>& src, u32 width,
u32 height) override;
};