Cleanup ImageConverter

Fix Logo
This commit is contained in:
tobid7 2024-06-14 20:55:55 +02:00
parent b6798fa069
commit f7c0c83ac2
12 changed files with 111 additions and 127 deletions

10
.vscode/launch.json vendored
View File

@ -13,7 +13,10 @@
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/opt/devkitPro/devkitARM/bin/arm-none-eabi-gdb",
/// LINUX
//"miDebuggerPath": "/opt/devkitPro/devkitARM/bin/arm-none-eabi-gdb",
/// WINDOWS
"miDebuggerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-gdb.exe",
"miDebuggerServerAddress": "192.168.2.220:4003",
"setupCommands": [
{
@ -35,7 +38,10 @@
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/opt/devkitPro/devkitARM/bin/arm-none-eabi-gdb",
/// LINUX
//"miDebuggerPath": "/opt/devkitPro/devkitARM/bin/arm-none-eabi-gdb",
/// WINDOWS
"miDebuggerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-gdb.exe",
"miDebuggerServerAddress": "localhost:4003",
"setupCommands": [
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,20 +1,20 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// THIS FILE WAS GENERATED BY generate_assets.py!!!

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1 +0,0 @@
vcx

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -24,19 +24,20 @@ int main() {
RD7::Ftrace::Beg("app", "app_init");
RD7::Init::Main("rd7tf");
RD7::FadeIn();
auto fnt = RD7::Font::New("romfs:/roboto_bold.bcfnt");
RD7::TextFont(fnt);
// RD7::Init::NdspFirm();
RD7::Scene::Load(std::make_unique<Sample>());
auto img = RD7::Image::New();
img->Load("romfs:/icons/icon.png");
RD7::Ftrace::End("app", "app_init");
while (RD7::MainLoop()) {
RD7::OnScreen(Top);
RD7::R2()->OnScreen(R2Screen_Top);
UI7::GetForegroundList()->AddImage(R7Vec2(), img);
RD7::Ftrace::Beg("app", "app_mainloop");
if (d7_hDown & KEY_START) {
RD7::FadeOut();
RD7::ExitApp();
}
RD7::OnScreen(Top);
RD7::R2()->OnScreen(R2Screen_Top);
RD7::FrameEnd();
RD7::Ftrace::End("app", "app_mainloop");
}

View File

@ -42,16 +42,7 @@ static void Wave(int index, R7Vec2 position, R7Vec2 size, float time,
// Just to make sure...
y_position = std::min(y_position, position.y + size.y - (90 - shrink));
if (dbg)
DV2::TriangleLined(
R7Vec2(x_position, y_position),
R7Vec2(x_position + 300, y_position + (90 - shrink)),
R7Vec2(x_position - 300, y_position + (90 - shrink)),
RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect,
.36f + .38f * color_effect)
.toRGBA());
else
DV2::TriangleSolid(
RD7::R2()->AddTriangle(
R7Vec2(x_position, y_position),
R7Vec2(x_position + 300, y_position + (90 - shrink)),
R7Vec2(x_position - 300, y_position + (90 - shrink)),
@ -61,7 +52,7 @@ static void Wave(int index, R7Vec2 position, R7Vec2 size, float time,
}
void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) {
DV2::RectFilledSolid(position, size, 0xff64c9fd);
RD7::R2()->AddRect(position, size, 0xff64c9fd);
int i = 0;
for (; i < 44; i++) Wave(i, position, size, time, dbg);
}
@ -69,14 +60,9 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) {
R7Vec2 testv2 = R7Vec2(48, 48);
std::vector<int*> img;
void display_icon(void* v, R7Vec2 p) { DV2::RFS(p, testv2, 0xff00ffff); }
void display_icon(void* v, R7Vec2 p) { RD7::R2()->AddRect(p, testv2, 0xff00ffff); }
Sample::Sample() {
auto t = RD7::FileSystem::GetDirContent("sdmc:/music/");
for (const auto& it : t) {
names.push_back(it.name);
files.push_back(it.path);
}
auto ti = new int;
ti[0] = 0;
for (int i = 0; i < 256; i++) {
@ -92,20 +78,10 @@ Sample::~Sample() {
void Sample::Draw() const {
// Draw Things to Screen:
// Step 1 -> Select Screen
RD7::OnScreen(Top);
RD7::R2()->OnScreen(R2Screen_Top);
// Step 2 -> Draw Things
// The hbloader Triangle Wave
DrawWave(R7Vec2(0, 0), R7Vec2(400, 240), RD7::GetTime(), debug_background);
// For Example A Rect with Draw2 and StyleColorApi
// And the RFS Wrapper for RectFilledSolid lol
/*DV2::RFS(R7Vec2(0, 0), R7Vec2(400, 20),
RD7::StyleColor(RD7Color_Header));
// As the Top bar is Dark you need TextColor2
RD7::RedirectColor(RD7Color_Text, RD7Color_Text2);
DV2::Text(R7Vec2(5, 2), "RenderD7 - Test Framework");
DV2::Text(R7Vec2(395, 2), RENDERD7VSTRING,
RD7TextFlags_AlignRight);
RD7::UndoColorEdit(RD7Color_Text);*/
if (UI7::BeginMenu("RenderD7 Test Framework")) {
if (state == State_Menu) {
UI7::Label("SZS: " + std::to_string(img.size()));
@ -114,7 +90,7 @@ void Sample::Draw() const {
}
UI7::EndMenu();
}
RD7::OnScreen(Bottom);
RD7::R2()->OnScreen(R2Screen_Bottom);
if (UI7::BeginMenu("Control Center")) {
if (state == State_Menu) {
if (UI7::Button("RenderD7 Settings"))
@ -128,11 +104,6 @@ void Sample::Draw() const {
UI7::SameLine();
UI7::Checkbox("UI7-Debug", UI7::IsDebugging());
UI7::InputText("Search", search__, "Tap Here");
UI7::Label("Text Control:");
if (UI7::Button("text++")) txt_size += 0.01;
UI7::SameLine();
if (UI7::Button("text--")) txt_size -= 0.01;
UI7::SameLine();
if (UI7::Button("def")) txt_size = 0.5;
UI7::Label("GridControl: ");
if (UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
@ -144,7 +115,6 @@ void Sample::Draw() const {
}
void Sample::Logic() {
RD7::CustomTextSize(txt_size);
for (const auto& it : shared_requests) {
if (it.first == 1U) {
if (it.second) RD7::LoadSettings();

View File

@ -50,59 +50,59 @@ static void __rd7i_r24r32(std::vector<uint8_t> &out,
}
}
static void __rd7i_c3dc2d__(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *buf,
u32 size, u32 width, u32 height) {
// RGBA -> ABGR
for (u32 row = 0; row < width; row++) {
for (u32 col = 0; col < height; col++) {
u32 z = (row + col * width) * 4;
u8 r = *(u8 *)(buf + z);
u8 g = *(u8 *)(buf + z + 1);
u8 b = *(u8 *)(buf + z + 2);
u8 a = *(u8 *)(buf + z + 3);
*(buf + z) = a;
*(buf + z + 1) = b;
*(buf + z + 2) = g;
*(buf + z + 3) = r;
static void __rd7i_maketex__(C3D_Tex* tex, Tex3DS_SubTexture* sub, std::vector<unsigned char>& buf, int w, int h) {
if(!tex || !sub)
{
_rd7i_logger()->Write("Invalid Inpit (objects have no adress!)");
return;
}
// RGBA -> Abgr
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
int pos = (x+y*w)*4;
auto r = buf[pos+0];
auto g = buf[pos+1];
auto b = buf[pos+2];
auto a = buf[pos+3];
buf[pos+0] = a;
buf[pos+1] = b;
buf[pos+2] = g;
buf[pos+3] = r;
}
}
u32 w_pow2 = __rd7i_gp2o__(width);
u32 h_pow2 = __rd7i_gp2o__(height);
// Pow2
int wp2 = __rd7i_gp2o__(w);
int hp2 = __rd7i_gp2o__(h);
subtex->width = (u16)width;
subtex->height = (u16)height;
subtex->left = 0.0f;
subtex->top = 1.0f;
subtex->right = (width / (float)w_pow2);
subtex->bottom = 1.0 - (height / (float)h_pow2);
sub->width = (u16)w;
sub->height = (u16)h;
sub->left = 0.0f;
sub->top = 1.0f;
sub->right = ((float)w / (float)wp2);
sub->bottom = 1.0 - ((float)h / (float)hp2);
C3D_TexInit(tex, (u16)w_pow2, (u16)h_pow2, GPU_RGBA8);
// Texture Setup
C3D_TexInit(tex, (u16)wp2, (u16)hp2, GPU_RGBA8);
C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
u32 pixel_size = (size / width / height);
memset(tex->data, 0, tex->size);
for (u32 x = 0; x < width; x++) {
for (u32 y = 0; y < height; y++) {
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) +
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int dst_pos = ((((y >> 3) * (wp2 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
pixel_size;
u32 src_pos = (y * width + x) * pixel_size;
4;
int src_pos = (y * w + x) * 4;
memcpy(&((u8 *)tex->data)[dst_pos], &((u8 *)buf)[src_pos], pixel_size);
memcpy(&((unsigned char *)tex->data)[dst_pos], &buf[src_pos], 4);
}
}
C3D_TexFlush(tex);
tex->border = 0x00000000;
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
// linearFree(buf);
}
namespace RenderD7 {
@ -116,7 +116,7 @@ void Image::Load(const std::string &path) {
Delete();
// Setup Func and Load Data
int w, h, c = 0;
uint8_t *image = stbi_load(path.c_str(), &w, &h, &c, 4);
unsigned char *image = stbi_load(path.c_str(), &w, &h, &c, 4);
if (image == nullptr) {
_rd7i_logger()->Write("Failed to Load Image: " + path);
return;
@ -129,23 +129,21 @@ void Image::Load(const std::string &path) {
return;
}
std::vector<uint8_t> wimg(w * h * 4);
std::vector<unsigned char> wimg;
if (c == 3) {
_rd7i_logger()->Write("Convert Image to RGBA");
stbi_image_free(image);
image = stbi_load(path.c_str(), &w, &h, &c, 3);
__rd7i_r24r32(wimg, std::vector<uint8_t>(image, image + (w * h * 3)), w, h);
wimg.resize(w*h*4);
__rd7i_r24r32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)), w, h);
} else {
// Maybe find a better solution later
for (size_t i = 0; i < wimg.size(); i++) {
wimg[i] = image[i];
}
}
wimg.assign(&image[0], &image[(w*h*4)-1]);
stbi_image_free(image);
}
// Create C2D_Image
C3D_Tex *tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
__rd7i_c3dc2d__(tex, subtex, wimg.data(), (u32)(w * h * 4), (u32)w, (u32)h);
__rd7i_maketex__(tex, subtex, wimg, w, h);
img.tex = tex;
img.subtex = subtex;
}
@ -156,15 +154,24 @@ void Image::From_NIMG(const nimg &image) {
if (image.width > 1024 || image.height > 1024) return;
C3D_Tex *tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
__rd7i_c3dc2d__(tex, subtex, (u8 *)image.pixel_buffer.data(),
(u32)image.pixel_buffer.size(), (u32)image.width,
(u32)image.height);
std::vector<unsigned char> mdpb = image.pixel_buffer;
__rd7i_maketex__(tex, subtex, mdpb, image.width, image.height);
img.tex = tex;
img.subtex = subtex;
}
C2D_Image Image::Get() { return img; }
C2D_Image &Image::GetRef() { return img; }
C2D_Image Image::Get() {
if(!Loadet()) {
_rd7i_logger()->Write("Image not Loadet!");
}
return img;
}
C2D_Image &Image::GetRef() {
if(!Loadet()) {
_rd7i_logger()->Write("Image not Loadet!");
}
return img;
}
void Image::Set(const C2D_Image &i) {
Delete();

View File

@ -148,8 +148,9 @@ void R2Base::Process() {
line++;
}
} else if (it.type == 4) {
if(it.img->Loadet())
if(it.img->Loadet()) {
C2D_DrawImageAt(it.img->Get(), it.pos.x, it.pos.y, 0.5f);
}
} else if (it.type == 5) {
// TODO: Move the Draw Func into this API
it.spr->Draw();

File diff suppressed because one or more lines are too long