use oss-nvjpg for loading jpeg images (homebrew, games and themezer).
slightly faster loading on avg compared to stbi.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "dumper.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "i18n.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
#include "ui/menus/game_menu.hpp"
|
||||
#include "ui/sidebar.hpp"
|
||||
@@ -318,11 +319,15 @@ void FakeNacpEntry(ThreadResultData& e) {
|
||||
|
||||
bool LoadControlImage(Entry& e) {
|
||||
if (!e.image && e.control) {
|
||||
ON_SCOPE_EXIT(e.control.reset());
|
||||
|
||||
TimeStamp ts;
|
||||
e.image = nvgCreateImageMem(App::GetVg(), 0, e.control->icon, e.jpeg_size);
|
||||
e.control.reset();
|
||||
log_write("\t\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs());
|
||||
return true;
|
||||
const auto image = ImageLoadFromMemory({e.control->icon, e.jpeg_size}, ImageFlag_JPEG);
|
||||
if (!image.data.empty()) {
|
||||
e.image = nvgCreateImageRGBA(App::GetVg(), image.w, image.h, 0, image.data.data());
|
||||
log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "i18n.hpp"
|
||||
#include "download.hpp"
|
||||
#include "dumper.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
@@ -965,7 +966,13 @@ void Menu::OnChangeIndex(s64 new_index) {
|
||||
|
||||
const auto& e = m_entries[m_entry_index];
|
||||
const auto jpeg_size = e.control_size - sizeof(NacpStruct);
|
||||
m_icon = nvgCreateImageMem(App::GetVg(), 0, e.control->icon, jpeg_size);
|
||||
|
||||
TimeStamp ts;
|
||||
const auto image = ImageLoadFromMemory({e.control->icon, jpeg_size}, ImageFlag_JPEG);
|
||||
if (!image.data.empty()) {
|
||||
m_icon = nvgCreateImageRGBA(App::GetVg(), image.w, image.h, 0, image.data.data());
|
||||
log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "owo.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "i18n.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
#include <minIni.h>
|
||||
#include <utility>
|
||||
@@ -175,9 +176,17 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
||||
// really, switch-tools should handle this by resizing the image before
|
||||
// adding it to the nro, as well as validate its a valid jpeg.
|
||||
const auto icon = nro_get_icon(e.path, e.icon_size, e.icon_offset);
|
||||
TimeStamp ts;
|
||||
if (!icon.empty()) {
|
||||
e.image = nvgCreateImageMem(vg, 0, icon.data(), icon.size());
|
||||
image_load_count++;
|
||||
const auto image = ImageLoadFromMemory(icon, ImageFlag_JPEG);
|
||||
if (!image.data.empty()) {
|
||||
e.image = nvgCreateImageRGBA(vg, image.w, image.h, 0, image.data.data());
|
||||
log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs());
|
||||
image_load_count++;
|
||||
} else {
|
||||
// prevent loading of this icon again as it's already failed.
|
||||
e.icon_offset = e.icon_size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "swkbd.hpp"
|
||||
#include "i18n.hpp"
|
||||
#include "threaded_file_transfer.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
#include <minIni.h>
|
||||
#include <stb_image.h>
|
||||
@@ -134,19 +135,14 @@ auto loadThemeImage(ThemeEntry& e) -> bool {
|
||||
}
|
||||
auto vg = App::GetVg();
|
||||
|
||||
fs::FsNativeSd fs;
|
||||
std::vector<u8> image_buf;
|
||||
|
||||
const auto path = apiBuildIconCache(e);
|
||||
if (R_FAILED(fs.read_entire_file(path, image_buf))) {
|
||||
log_write("failed to load image from file: %s\n", path.s);
|
||||
} else {
|
||||
int channels_in_file;
|
||||
auto buf = stbi_load_from_memory(image_buf.data(), image_buf.size(), &image.w, &image.h, &channels_in_file, 4);
|
||||
if (buf) {
|
||||
ON_SCOPE_EXIT(stbi_image_free(buf));
|
||||
image.image = nvgCreateImageRGBA(vg, image.w, image.h, 0, buf);
|
||||
}
|
||||
TimeStamp ts;
|
||||
const auto data = ImageLoadFromFile(path, ImageFlag_JPEG);
|
||||
if (!data.data.empty()) {
|
||||
image.w = data.w;
|
||||
image.h = data.h;
|
||||
image.image = nvgCreateImageRGBA(vg, data.w, data.h, 0, data.data.data());
|
||||
log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs());
|
||||
}
|
||||
|
||||
if (!image.image) {
|
||||
|
||||
Reference in New Issue
Block a user