18 Commits

Author SHA1 Message Date
780025bb74 Add Some Tools and Assets to create cpp's for 0.9+ 2023-03-13 21:19:07 +01:00
f6e3c50814 Fix Crash and Fade Stuff 2023-03-12 21:37:22 +01:00
0399808eb2 Document_Fix_And0.9.3 2023-03-12 21:06:13 +01:00
cd677cf3e8 0.9.2 (NVID, SPLASH_IMG_VID, CHANGELOG_IMPL) 2023-03-11 15:56:40 +01:00
67edfa4245 Remove nsmbp and fix a critical bug 2023-03-09 21:19:17 +01:00
66a35f28e6 FastColor/RemoveFPSCheat/LLVM-Style 2023-03-07 18:09:48 +01:00
2f7a266dc5 - 2022-12-13 20:58:21 +01:00
8a0fd07275 Alpha 0.9.0 2022-12-09 14:55:19 +01:00
89299bf91e Minimalistic for hax 2.x 2022-12-07 15:29:19 +01:00
af88277680 __FixDeltatime 2022-11-30 18:28:03 +01:00
dd17a70551 Prepere 2022-11-28 20:01:56 +01:00
ec0411373b 0.8.4 2022-11-25 01:07:11 +01:00
222a13387d 0.8.4 2022-11-25 01:05:50 +01:00
c1e471f23a The ResultDecoder Update 2022-11-22 23:00:01 +01:00
6b48ba070c RenderD7 0.8.2 2022-11-18 20:57:05 +01:00
bbbfd60bb7 Fix To Prevent from Crash 2022-11-14 18:25:24 +01:00
62fa5ede9d Standarts of LLVM 2022-11-14 16:27:04 +01:00
20c3a525c8 Version 0.8.1 (StealConsole) 2022-11-14 15:25:26 +01:00
109 changed files with 24724 additions and 16765 deletions

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "3DS | Windows",
"includePath": [
"${workspaceFolder}/**",
"C:/devkitpro/libctru/include/**",
"C:/devkitpro/devkitARM/include/**",
"C:/devkitpro/devkitARM/arm-none-eabi/include/**",
"C:/devkitpro/portlibs/3ds/include/**",
"/opt/devkitpro/libctru/include/**",
"/opt/devkitpro/portlibs/**"
]
}
],
"version": 4
}

39
.vscode/settings.json vendored
View File

@ -60,6 +60,43 @@
"cuchar": "cpp",
"compare": "cpp",
"concepts": "cpp",
"numbers": "cpp"
"numbers": "cpp",
"filesystem": "cpp",
"xstring": "cpp",
"charconv": "cpp",
"format": "cpp",
"ios": "cpp",
"list": "cpp",
"locale": "cpp",
"mutex": "cpp",
"stack": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"queue": "cpp",
"semaphore": "cpp",
"hash_map": "cpp",
"set": "cpp",
"unordered_set": "cpp",
"source_location": "cpp",
"future": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"variant": "cpp"
}
}

View File

@ -39,7 +39,7 @@ PROJECT_NAME = Renderd7-nightly
# control system is used.
PROJECT_NUMBER = "v0.7.0"
PROJECT_NUMBER = "v0.9.3"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a

View File

@ -9,8 +9,8 @@ endif
include $(DEVKITARM)/3ds_rules
export renderd7_MAJOR := 0
export renderd7_MINOR := 8
export renderd7_PATCH := 0
export renderd7_MINOR := 9
export renderd7_PATCH := 3
VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH)
@ -32,7 +32,7 @@ TIME_TIME := $(shell date --iso=seconds)
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := renderd7
SOURCES := source external/source external/libnsbmp/source
SOURCES := source external/source
DATA := data
INCLUDES := include

View File

@ -1,4 +1,4 @@
# RenderD7 <img alt="LOGO" src="https://github.com/NPI-D7/RenderD7/blob/main/logo.png" height="30">
# RenderD7 <img alt="LOGO" src="https://github.com/NPI-D7/RenderD7/blob/main/logo.png" height="90">
RenderD7 is now LibRenderD7.
### Installation (Ubuntu)
first run this
@ -14,3 +14,11 @@ Make sure that `-lrenderd7` is before `-lcitro2d`, `-lcitro3d`, `-lctru`.
# RenderD7 (https://npi-d7.github.io/RenderD7/)
Simple and Easey to use UI and Graphics helper.
Create DOCS
# Credits
- NPI-D7
- Tobi-D7 Main Dev
Some Icons are From
https://icons8.de/
See Subfolder Readmes

34
assets/build_assets.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
echo "Create Directorys"
mkdir -p build
mkdir -p code
echo "Generating Spritesheets"
cd resources
for file in *.t3s
do
filename=$(basename "$file" .t3s).t3x
tex3ds -o "../build/$filename" -i "${file}"
done
echo "Converting Spritesheets into C++ Code"
cd ../code
for file in ../build/*.t3x
do
name="${file##*/}"
name="${name%.*}"
../../tools/bin/file2array "${file}" "${name}"
done
echo "Convert Npi-Intro to C++ Code"
../../tools/bin/file2array ../splash/npi_intro.nvid npi_intro
echo "Fix The Output of file2array"
for file in ./*.cpp
do
../../tools/bin/rd7f2afix "${file}" "renderd7"
done
echo "Finished!"

7
assets/clear_assets.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
echo "Deleting Directorys"
rm -rf build
rm -rf code
echo "Finished!"

View File

@ -0,0 +1,2 @@
# Source
https://icons8.de/

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

View File

@ -0,0 +1,11 @@
--atlas -f rgba -z auto
battery/battery_full.png
battery/battery_nearfull.png
battery/battery_half.png
battery/battery_low.png
battery/battery_verylow.png
battery/battery_warning.png
battery/battery_charging.png
battery/battery_empty.png
battery/battery_dead.png

View File

@ -0,0 +1,3 @@
--atlas -f rgba -z auto
renderd7_logo/renderd7_logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,19 @@
--atlas -f rgba -z auto
ui_elements/high_volume.png
ui_elements/mid_volume.png
ui_elements/low_volume.png
ui_elements/speaker_v1.png
ui_elements/no_sound.png
ui_elements/speaker.png
ui_elements/wifi_connected.png
ui_elements/wifi_disconnected.png
ui_elements/wifi_off.png
ui_elements/good_connection.png
ui_elements/mid_connection.png
ui_elements/bad_connection.png
ui_elements/no_connection.png
ui_elements/headphones.png

View File

@ -0,0 +1,2 @@
# Source
https://icons8.de/

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
assets/splash/npi_intro.mp4 Normal file

Binary file not shown.

Binary file not shown.

7
cformat.sh Executable file
View File

@ -0,0 +1,7 @@
find . -type f \( -name '*.h' -o -name '*.hpp' -o -name '*.hh' -o -name '*.ino' -o -name '*.cpp' -o -name '*.c' -o -name '*.cxx' -o -name '*.inl' \) -and -not -path './build/*' -not -path './base/external/*' -not -path './DPP/*' | while read file; do
if [[ "$file" != *"json.hpp" ]]; then
echo "Formatting $file..."
clang-format -i --style=LLVM $file
fi
done

View File

@ -1,20 +0,0 @@
Copyright (C) 2006 Richard Wilson
Copyright (C) 2008 Sean Fox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

File diff suppressed because it is too large Load Diff

386
external/source/fs.c vendored
View File

@ -1,386 +0,0 @@
#include <renderd7/external/fs.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <stdlib.h>
#define WORKING_DIR "/"
void Utils_U8_To_U16(u16 *buf, const u8 *input, size_t bufsize) {
ssize_t units = utf8_to_utf16(buf, input, bufsize);
if (units < 0)
units = 0;
buf[units] = 0;
}
FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID, fsMakePath(PATH_EMPTY, ""))))
return ret;
return 0;
}
Result FS_CloseArchive(FS_Archive archive) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_CloseArchive(archive)))
return ret;
return 0;
}
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive, fsMakePath(PATH_UTF16, path_u16), flags, attributes)))
return ret;
return 0;
}
Result FS_MakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0)))
return ret;
return 0;
}
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
return 0;
}
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
char buf[256];
char *p = NULL;
size_t len;
snprintf(buf, sizeof(buf), "%s", path);
len = strlen(buf);
if (buf[len - 1] == '/')
buf[len - 1] = 0;
for (p = buf + 1; *p; p++) {
if (*p == '/') {
*p = 0;
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
*p = '/';
}
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
}
return ret;
}
bool FS_FileExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return false;
if (R_FAILED(FSFILE_Close(handle)))
return false;
return true;
}
bool FS_DirExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16))))
return false;
if (R_FAILED(FSDIR_Close(handle)))
return false;
return true;
}
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
Result ret = 0;
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
u64 FS_GetFreeStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.freeClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetTotalStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.totalClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetUsedStorage(FS_SystemMediaType media_type) {
return 0;//(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type));
}
Result FS_RemoveFile(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RemoveDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename) {
Result ret = 0;
u16 old_filename_u16[strlen(old_filename) + 1];
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename, strlen(old_filename) + 1);
u16 new_filename_u16[strlen(new_filename) + 1];
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename, strlen(new_filename) + 1);
if (R_FAILED(ret = FSUSER_RenameFile(archive, fsMakePath(PATH_UTF16, old_filename_u16), archive, fsMakePath(PATH_UTF16, new_filename_u16))))
return ret;
return 0;
}
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname) {
Result ret = 0;
u16 old_dirname_u16[strlen(old_dirname) + 1];
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname, strlen(old_dirname) + 1);
u16 new_dirname_u16[strlen(new_dirname) + 1];
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname, strlen(new_dirname) + 1);
if (R_FAILED(ret = FSUSER_RenameDirectory(archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive, fsMakePath(PATH_UTF16, new_dirname_u16))))
return ret;
return 0;
}
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
Result ret = 0;
Handle handle;
u32 bytes_read = 0;
if (R_FAILED(ret = FS_OpenFile(&handle, archive, path, FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Read(handle, &bytes_read, 0, buf, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) {
Result ret = 0;
Handle handle;
u32 bytes_written = 0;
if (FS_FileExists(archive, path))
FS_RemoveFile(archive, path);
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_WRITE, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size, FS_WRITE_FLUSH))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
char *FS_GetFileTimestamp(const char *path) {
static char timeStr[60];
u64 mtime = 0;
if (R_SUCCEEDED(archive_getmtime(path, &mtime))) {
time_t mt = mtime;
struct tm *timeStruct = gmtime(&mt);
int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min;
int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon + 1; // January being 0
int year = timeStruct->tm_year + 1900;
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours, minutes);
}
else
return NULL;
return timeStr;
}
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
*archive = ARCHIVE_SDMC;
FS_Path filePath = {0};
unsigned int prefixlen = 0;
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
} else if (*path != '/') {
//if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid
char * actualPath = NULL;
asprintf(&actualPath, "%s%s", WORKING_DIR, path);
filePath = fsMakePath(PATH_ASCII, actualPath);
free(actualPath);
}
//if the filePath wasnt set above, set it
if (filePath.size == 0) {
filePath = fsMakePath(PATH_ASCII, path+prefixlen);
}
return filePath;
}
Result makeDirs(const char * path) {
Result ret = 0;
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) {
char bak = *(slashpos);
*(slashpos) = '\0';
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
FSUSER_CloseArchive(archive);
return ret;
}
Result openFile(Handle* fileHandle, const char * path, bool write) {
FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
return ret;
}

3185
external/source/jpgd.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

1246
external/source/jpge.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
External Librarys

View File

@ -1,4 +1,5 @@
#pragma once
#include <renderd7/StealConsole.hpp>
#include <renderd7/bmp.hpp>
#include <renderd7/renderd7.hpp>

View File

@ -13,59 +13,167 @@
#include <renderd7/Fonts/NFontApi.hpp>
namespace RenderD7 {
/// @brief Encoder
enum Encoder {
BITMAP, ///< Encode Data to Bitmap
DIRECT, ///< Encode Direct to Framebuffer(No Decoder Required)
C3D ///< Encode Directly to C3D_Tex (Just an Idea)
};
/// @brief Decoder
enum Decoder {
BITMAP2C3D, ///< Decode and Encode to C3D_Tex (Currently Fastest) (47,4ms)
BITMAP2PNG2C3D ///< Decode Bitmap end Convert to Png, then C3D (Very Slow)
///< (201,4ms)
};
/// @brief BitmapPrinetr Class
class BitmapPrinter {
public:
/// @brief Constructor
/// @param w Widrth
/// @param h Height
BitmapPrinter(int w, int h);
/// @brief Deconstructor
~BitmapPrinter();
/// @brief Dexode Bitmap File
/// @param file path to File
/// @return success ?
bool DecodeFile(std::string file);
/// @brief Set the Decoder
/// @param deccc Decoder
void SetDecoder(Decoder deccc) { decc = deccc; }
/// @brief Draw a Pixel
/// @param x pos x
/// @param y pos y
/// @param b color blue
/// @param g color green
/// @param r color red
/// @param a color alpha
void DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a);
/// @brief Draw Rectangle
/// @param x pos x
/// @param y pos y
/// @param w width
/// @param h height
/// @param line_w line width
/// @param b color blue
/// @param g color green
/// @param r color red
/// @param a colr alpha
void DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a);
/// @brief Draw a Fillif Rectangle
/// @param x pos x
/// @param y pos y
/// @param w width
/// @param h height
/// @param b color blue
/// @param g color green
/// @param r color red
/// @param a color alpha
void DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a);
/// @brief Draw Bitmap
/// @param x pos x
/// @param y pos y
/// @param map Bitmap to Print
void DrawBitmap(int x, int y, BMP map);
/// @brief Use Prebuild Bitmap
/// @param map bitmap
void UsePreMap(BMP map);
/// @brief Use Prebuild Printer Setup
/// @param printmap Printer
void UsePrePrintMap(BitmapPrinter printmap);
/// @brief Get Bitmap
/// @return Bitmap
BMP GetBitmap() { return bitmap; }
/// @brief Save to File
/// @param name Name/Path
void SaveBmp(std::string name);
/// @brief Save as Png
/// @param name Name/Path
void SavePng(std::string name);
/// @brief Setup Screen
/// @param target Screen
void CreateScreen(C3D_RenderTarget *target);
/// @brief Draw Directly to Screen With Framerate
/// @param framerate Framerate
/// @return
bool DrawScreenDirectF(int framerate);
/// @brief Draw Directly to Screen
/// @return
bool DrawScreenDirect();
/// @brief Render on Screen by Framerate
/// @param framerate Framerate
void DrawScreenF(int framerate);
/// @brief Draw to Screen
void DrawScreen();
/// @brief Update Image by Framerate
/// @param framerate Framerate
/// @return
bool UpdateScreenF(int framerate);
/// @brief Update Image
/// @return
bool UpdateScreen();
/// @brief Clear by Color
/// @param b color blue
/// @param g color green
/// @param r color red
/// @param a color alpha
void Clear(u8 b = 0, u8 g = 0, u8 r = 0, u8 a = 255);
/// @brief Clear Completly Blank
void ClearBlank();
/// @brief Get Rendered Image
/// @return Image
RenderD7::Image GetImage();
/// Test to Find out The Best Settings for BitmapPrinter
void Benchmark();
/// Setup the Benchmark
/// @brief Setup the Benchmark
/// \param framerate The Fps of the ScreenUpdates
void SetupBenchmark(int framerate);
/// @brief Check if Benchmark is Running
/// @return is running or not
bool IsBenchmarkRunning() { return this->benchmark; }
/// @brief Draw a Dubug Text
/// @param x pos x
/// @param y pos y
/// @param t_size Size of the Text
/// @param color Color of the Text
/// @param text String of the Text
void DrawDebugText(int x, int y, int t_size, u32 color, std::string text);
/// @brief Draw a Text width NFontApi (TTF)
/// @param x pos x
/// @param y pos y
/// @param t_size size of the Text
/// @param color Color of The Text
/// @param text String of The Text
/// @param font TTF Font
void DrawText(int x, int y, float t_size, u32 color, std::string text,
RenderD7::NFontApi font);
private:
// funcs
/// @brief Decode 2 RenderD7::Image
/// @param deccc Decoder
/// @return
bool Decode(Decoder deccc);
/// @brief Draw Char Func
/// @param posX pos x
/// @param posY pos y
/// @param t_size size
/// @param color color
/// @param character char
void DrawDebugChar(u32 posX, u32 posY, int t_size, u32 color, char character);
/// @brief NFont Draw Char
/// @param posX pos x
/// @param posY pos y
/// @param t_size size
/// @param color color
/// @param character char
/// @param font ttf
void DrawChar(int posX, int posY, float t_size, u32 color, char character,
RenderD7::NFontApi font);
// parameter

View File

@ -12,20 +12,39 @@
namespace RenderD7 {
namespace Color {
/// @brief RGBA Struct
struct rgba {
/// @brief rgba Colors
uint8_t r, g, b, a;
};
/// @brief RGBA Class
class RGBA {
public:
/// @brief Construct
/// @param r
/// @param g
/// @param b
/// @param a
RGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
: m_r(r), m_g(g), m_b(b), m_a(a) {}
/// @brief Get as Uint32
/// @return color
uint32_t toRGBA() const {
return (m_r << 24) | (m_g << 16) | (m_b << 8) | m_a;
}
uint8_t m_r, m_g, m_b, m_a;
};
/// @brief Convert RGB to Hex
/// @param r
/// @param g
/// @param b
/// @return Hex-String
std::string RGB2Hex(int r, int g, int b);
uint32_t Hex(const std::string color, uint8_t a = 255);
/// @brief Hex to U32
/// @param color
/// @param a
/// @return Color32
uint32_t Hex(const std::string &color, uint8_t a = 255);
} // namespace Color
} // namespace RenderD7

View File

@ -6,22 +6,105 @@
namespace RenderD7 {
namespace Draw {
/// @brief Draw Rectangle
/// @param x Pos X
/// @param y Pos Y
/// @param w Width
/// @param h Height
/// @param color Color
/// @return success ?
bool Rect(float x, float y, float w, float h, u32 color);
/// @brief Draw a not filled Rectangle
/// @param p1x Pos X
/// @param p1y Pos Y
/// @param w Width
/// @param h Height
/// @param color Color
/// @param scale Scale
/// @return success ?
bool NFRect(float p1x, float p1y, float w, float h, u32 color, float scale = 1);
/// @brief Draw A Pixel
/// @param x Pos X
/// @param y Pos Y
/// @param color Color
/// @return success ?
bool Px(float x, float y, u32 color);
/// @brief Draw a Centered Text
/// @param x Pos X
/// @param y Pos Y
/// @param size Scale of the Text
/// @param color Color of The Text
/// @param Text Striing to Display
/// @param maxWidth Width to Calculate Centered Pos
/// @param maxHeight Height to Calculate Centered Pos
/// @param fnt Custom Font
void TextCentered(float x, float y, float size, u32 color, std::string Text,
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
/// @brief Draw a Text
/// @param x Pos X
/// @param y Pos Y
/// @param size Scale of the Text
/// @param color Color of The Text
/// @param Text Striing to Display
/// @param maxWidth Width to Calculate Centered Pos
/// @param maxHeight Height to Calculate Centered Pos
/// @param fnt Custom Font
void Text(float x, float y, float size, u32 color, std::string Text,
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
/// @brief Draw a Text Set to the Right
/// @param x Pos X
/// @param y Pos Y
/// @param size Scale of the Text
/// @param color Color of The Text
/// @param Text Striing to Display
/// @param maxWidth Width to Calculate Centered Pos
/// @param maxHeight Height to Calculate Centered Pos
/// @param fnt Custom Font
void TextRight(float x, float y, float size, u32 color, std::string Text,
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
/// @brief Get Width of Text
/// @param size Size of the Text
/// @param Text String of The text
/// @param fnt Custom Font
/// @return The Size
float GetTextWidth(float size, std::string Text, C2D_Font fnt = nullptr);
/// @brief Get Text Size
/// @param size Size of The Text
/// @param width Width of the Text
/// @param height Height of The Text
/// @param Text String of Text
/// @param fnt Custom Font
void GetTextSize(float size, float *width, float *height, std::string Text,
C2D_Font fnt = nullptr);
/// @brief Get Height of the Text
/// @param size Size of the Text
/// @param Text String of the Text
/// @param fnt Custom Font
/// @return The Height
float GetTextHeight(float size, std::string Text, C2D_Font fnt = nullptr);
/// @brief Load A .bcfnt
/// @param fnt Output Font
/// @param Path path of The File
/// @return Result Code
Result LoadFont(C2D_Font &fnt, const char *Path = "");
/// @brief Unload a Font
/// @param fnt Font to Unload
/// @return Result Code
Result UnloadFont(C2D_Font &fnt);
/// @brief Draw a Circle
/// @param x Pos X
/// @param y Pos Y
/// @param radius Radius of the Circle
/// @param color Color of the circle
/// @return success ?
bool Circle(float x, float y, float radius, u32 color);
/// @brief Draw A Citro2D Image
/// @param img Image to Draw
/// @param x Pos X
/// @param y Pos Y
/// @param scaleX Scale of X-Axis
/// @param scaleY Scale of Y-Axis
/// @return success ?
bool Image(C2D_Image img, float x, float y, float scaleX = 1.0f,
float scaleY = 1.0f);
} // namespace Draw

View File

@ -4,102 +4,20 @@
#include <string>
#include <vector>
#include <physfs.h>
#define RD7_FSYS_GETINFO(path) \
({ \
RenderD7::FileSystem::Info inf; \
RenderD7::FileSystem::GetInfo(path, inf); \
inf; \
})
namespace RenderD7 {
namespace FileSystem {
static constexpr auto MAX_STAMP = 0x20000000000000LL;
enum FileMode { FileMode_Open, FileMode_Read, FileMode_Write, FileMode_Closed };
enum FileType {
FileType_File,
FileType_Directory,
FileType_SymLink,
FileType_Other
/// @brief A Directory Entry
struct Entry {
/// @brief Patf of The Entry
std::string path;
/// @brief Name of The Entry
std::string name;
/// @brief Directory or File
bool dir = false;
};
struct File {
PHYSFS_file *handle;
FileMode mode;
File() {
this->handle = nullptr;
this->mode = FileMode_Closed;
}
int64_t GetSize() {
if (this->handle == nullptr)
return 0;
return (int64_t)PHYSFS_fileLength(this->handle);
}
};
struct Info {
int64_t size;
int64_t mod_time;
FileType type;
};
int Init(const char *argv);
void Initialize();
/*
** mounts a specific directory for physfs to search in
** this is typically a main directory
*/
bool SetSource(const char *source);
/*
** mounts a specific directory as a "save" directory
** if appended, it will be added to the search path
*/
bool SetIdentity(const char *name, bool append);
static std::string savePath;
/* gets the last physfs error */
const char *GetPhysfsError();
/* strips any duplicate slashes */
std::string Normalize(const std::string &input);
/* gets the user directory from physfs */
std::string GetUserDirectory();
/* gets the save directory */
std::string GetSaveDirectory();
/* sets up the writing directory for physfs */
bool SetupWriteDirectory();
/* gets a list of files in a directory */
void GetDirectoryItems(const char *directory, std::vector<std::string> &items);
/* gets the size, mod_time, and type of a file */
bool GetInfo(const char *filename, Info &info);
/* creates a new directory */
bool CreateDirectory(const char *name);
bool CloseFile(File &file);
/* creates a new file */
bool OpenFile(File &file, const char *name, FileMode mode);
/* writes to a file */
bool WriteFile(File &file, const void *data, int64_t size);
/* reads a file's content */
int64_t ReadFile(File &file, void *destination, int64_t size);
/// @brief Gets All Entrys of A Directory into a Vector
/// @param path The Path of the Directory
/// @return The Vector of found Entrys
std::vector<RenderD7::FileSystem::Entry> GetDirContent(std::string path);
} // namespace FileSystem
} // namespace RenderD7

View File

@ -16,9 +16,11 @@ namespace RenderD7 {
/// Image Class
class Image {
public:
/// @brief Constructor
Image() {}
/// @brief Deconstructor
~Image();
/// @brief Unload The Image
void Unload();
/// Load Image from Png
/// \param path path to png file
@ -27,6 +29,8 @@ public:
/// \param buffer the frame buffer
void LoadPFromBuffer(const std::vector<u8> &buffer);
void LoadFromBitmap(BMP bitmap);
void LoadJpg(std::string path);
void LoadPixels(int w, int h, int bpp, void *buffer);
/// Draw the Image directly
/// \param x The x position
/// \param y the y position

View File

@ -2,16 +2,26 @@
#include <memory>
namespace RenderD7 {
/// @brief The Overlay Class (Used for Toasts for example)
class Ovl {
public:
/// @brief Deconstructor
virtual ~Ovl() {}
/// @brief Function Called to Draw this
virtual void Draw() const = 0;
/// @brief Logic of the Overlay
virtual void Logic() = 0;
/// @brief Should the overlay be killed
/// @return Killed or Not
inline bool IsKilled() { return this->iskilled; }
/// @brief Kill The Overlay
inline void Kill() { iskilled = true; }
private:
/// @param iskilled For IsKilled();
bool iskilled = false;
};
/// @brief Add an Overlay to the stack
/// @param scene Overlay to push to Stack
void AddOvl(std::unique_ptr<RenderD7::Ovl> scene);
} // namespace RenderD7

View File

@ -0,0 +1,51 @@
#pragma once
#include <3ds.h>
#include <string>
namespace RenderD7 {
/// @brief Decoder for 3ds Result Codes
class ResultDecoder {
public:
/// @brief Constructor
ResultDecoder() {}
/// @brief Deconstructor
~ResultDecoder() {}
/// @brief Load a Result into Decoder
/// @param rescode Result Code
void Load(Result rescode);
/// @brief Load A Hex Converted Code into Decoder
/// @param rescode Result-Hex Code
void Load(std::string rescode);
/// @brief Get Hex Code
/// @return Hex-Code
std::string GetCode();
/// @brief Get Level Name
/// @return Level Name
std::string GetLevel();
/// @brief Get Level Value
/// @return Level Value
int GetLevelInt();
/// @brief Get The Mosule Name
/// @return Module Name
std::string GetModule();
/// @brief Get The Module Value
/// @return Module Value
int GetModuleInt();
/// @brief Get The Description
/// @return Description
std::string GetDescription();
/// @brief Get The Description Valur
/// @return Description Value
int GetDescriptionInt();
/// @brief Get the Summary
/// @return Summary
std::string GetSummary();
/// @brief Get the Summary Value
/// @return Summary Value
int GetSummaryInt();
private:
/// @param m_rescode Result code
Result m_rescode;
};
} // namespace RenderD7

View File

@ -2,12 +2,15 @@
#include <citro2d.h>
#include <citro3d.h>
/// \param Top Tob-Screen Target
extern C3D_RenderTarget *Top;
/// \param TopRight Top-Right-Screen Target (Never atually used)
extern C3D_RenderTarget *TopRight;
/// \param Bottom Bottom-Screen Target
extern C3D_RenderTarget *Bottom;
namespace RenderD7 {
/// Set current RenderScreen
/// \param target The RenderTarget Top, Bottom
/// @brief Begin Drawing On Specific Screen
/// @param target The Screen Target (Top, Bottom or TopTight)
void OnScreen(C3D_RenderTarget *target);
} // namespace RenderD7

View File

@ -3,19 +3,20 @@
#include <citro3d.h>
namespace RenderD7 {
/** The Spritesheet Class */
/// @brief SpriteSheet Class
class Sheet {
public:
/// Construct sheet
/// @brief Constructor
Sheet();
// Deconstruct sheet
/// @brief Deconstructor
~Sheet();
/// Load a Sritesheet
/// \param path Path to the Spritesheet (.t3x)
/// @brief Load A Spritesheet File
/// @param path Path to the t3x
/// @return Result Code
Result Load(const char *path);
/// Unload the Spritesheet
/// @brief Unload the Sheet
void Free();
/// The Spritesheet
/// \param spritesheet The Sheet
C2D_SpriteSheet spritesheet;
};
} // namespace RenderD7

View File

@ -7,7 +7,7 @@
#include <renderd7/Sheet.hpp>
namespace RenderD7 {
/// Sprite Class
/// @brief Sprite Class
class Sprite {
public:
/// \brief Construct Sprite
@ -21,19 +21,44 @@ public:
/// \brief Load a Sprite From SpriteSheet
/// \param img the Image to load from.(RenderD7::Image)
void FromImage(RenderD7::Image *img);
/// @brief Draw the Sprite
/// @return success ?
bool Draw();
/// @brief Set the Center Position
/// @param x X Pos
/// @param y Y Pos
void SetCenter(float x, float y);
/// @brief Set the Sprite's Position
/// @param x X Pos
/// @param y Y Pos
void SetPos(float x, float y);
/// @brief Set The Sprite's Scale
/// @param x Scale on X-Axis
/// @param y Scale on Y-Axis
void SetScale(float x, float y);
/// @brief Set the Sprite's Rotation
/// @param rotation ratation
void SetRotation(float rotation);
/// @brief Rotate the Sprite
/// @param speed Speed to Rotate
void Rotate(float speed);
/// @brief Get Tje Sprite's Width
/// @return Width
float getWidth();
float getHeigh();
/// @brief Get the Sprite's Height
/// @return Height
float getHeight();
/// @brief Get The Sprite's X Position
/// @return X Position
float getPosX();
/// @brief Get the Sprite's Y Position
/// @return Y Position
float getPosY();
private:
/// @param tint ImageTint (unused)
C2D_ImageTint tint;
/// @param sprite The Sprite
C2D_Sprite sprite;
};
} // namespace RenderD7

View File

@ -7,19 +7,35 @@
#include <citro3d.h>
namespace RenderD7 {
/// @brief SpriteSheetAnimation Class
class SpriteSheetAnimation : public RenderD7::Sprite {
public:
/// @brief Constructor
SpriteSheetAnimation();
/// @brief Deconstructor
~SpriteSheetAnimation();
/// @brief Setup an Animation
/// @param sheet Input Spritesheet
/// @param imagecount Count of Images
/// @param startimage Where to Start the Loop
/// @param frame_begin Current Time (Should be 0)
/// @param frame_finish Time Length
void Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage,
float frame_begin, float frame_finish);
/// @brief Play the Animation
/// @param timespeed Speed of the animation
void Play(float timespeed);
private:
/// @param images Count of Images
size_t images;
/// @param imgs Another Count of images ???
size_t imgs = 0;
/// @param D_totaltime Current Time
float D_totaltime;
/// @param sheet The Sheet of Images
RenderD7::Sheet *sheet;
/// @param time Total Time from frame_finish
float time;
};
} // namespace RenderD7

View File

@ -0,0 +1,21 @@
#pragma once
#include <sstream>
#include <string>
namespace RenderD7 {
/// @brief StealConsole Class
class StealConsole {
public:
/// @brief Constructor
StealConsole();
/// @brief Deconstructor
~StealConsole();
/// @brief The Stolen Stdout
/// @return Stdout as string
std::string GetStdout();
private:
/// @param stolen_stdout Stolen Stdout
std::stringstream stolen_stdout;
};
} // namespace RenderD7

View File

@ -0,0 +1,13 @@
#pragma once
#include <3ds.h>
#include <vector>
namespace RenderD7 {
namespace Tasks {
/// @brief Push A Task
/// @param entrypoint Function of Your Task
void create(ThreadFunc entrypoint);
/// @brief Destroy all Tasks
void destroy(void);
} // namespace Tasks
} // namespace RenderD7

View File

@ -2,6 +2,12 @@
#include <string>
namespace RenderD7 {
/// @brief Format a String
/// @param fmt_str Format To
/// @param ... Additional Args
/// @return Formatted String
std::string FormatString(std::string fmt_str, ...);
/// @brief Get Current Time as String
/// @return Time-String
std::string GetTimeStr(void);
} // namespace RenderD7

View File

@ -6,17 +6,25 @@
#include <renderd7/Screen.hpp>
namespace RenderD7 {
/// @brief Toast Class
class Toast : public RenderD7::Ovl {
public:
/// @brief Constructor
/// @param head Displayed String in Head
/// @param msg Displayed String in Message Box
Toast(std::string head, std::string msg);
/// @brief Override for Draw
void Draw(void) const override;
/// @brief Override for Logic
void Logic() override;
private:
RenderD7::BitmapPrinter toast = RenderD7::BitmapPrinter(400, 70);
RenderD7::Image *toastrendered;
/// @param head The Header Text
/// @param nsg The Message-Box Text
std::string head, msg;
/// @param msgposy Position Y of The Toast
int msgposy = 240;
/// @param delay Delay of the Toast
int delay = 0;
};
} // namespace RenderD7

View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char battery_icons[];
extern size_t battery_icons_size;

View File

@ -5,6 +5,7 @@
#include <sstream>
#include <stdexcept>
#include <vector>
using namespace std;
#pragma pack(push, 1)
@ -48,7 +49,8 @@ struct BMPColorHeader {
};
#pragma pack(pop)
struct BMP {
class BMP {
public:
BMPFileHeader file_header;
BMPInfoHeader bmp_info_header;
BMPColorHeader bmp_color_header;
@ -62,8 +64,8 @@ struct BMP {
inp.read((char *)&file_header, sizeof(file_header));
if (file_header.file_type != 0x4D42) {
return 50; // throw std::runtime_error("Error! Unrecognized file
// format.");
return 50;
// throw std::runtime_error("Error! Unrecognized file format.");
}
inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
@ -78,9 +80,8 @@ struct BMP {
check_color_header(bmp_color_header);
} else {
// std::cerr << "Error! The file \"" << fname << "\" does not seem to
// contain bit mask information\n";
return 51; // throw std::runtime_error("Error! Unrecognized file
// format.");
// contain bit mask information\n"; return 51;//throw
// std::runtime_error("Error! Unrecognized file format.");
}
}
@ -137,12 +138,14 @@ struct BMP {
std::stringstream inp;
std::copy(buffer.begin(), buffer.end(),
std::ostream_iterator<unsigned char>(inp, "\n"));
std::cout << buffer.size() << std::endl;
if (inp) {
inp.read((char *)&file_header, sizeof(file_header));
if (file_header.file_type != 0x4D42) {
return 50; // throw std::runtime_error("Error! Unrecognized file
// format.");
return 50;
// throw std::runtime_error("Error! Unrecognized file format. Header " +
// std::to_string(file_header.file_type));
}
inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
@ -158,8 +161,8 @@ struct BMP {
} else {
// std::cerr << "Error! The file \"" << fname << "\" does not seem to
// contain bit mask information\n";
return 51; // throw std::runtime_error("Error! Unrecognized file
// format.");
return 51;
// throw std::runtime_error("Error! Unrecognized file format. Size");
}
}
@ -181,8 +184,10 @@ struct BMP {
file_header.file_size = file_header.offset_data;
if (bmp_info_header.height < 0) {
return 52; // throw std::runtime_error("The program can treat only BMP
// images with the origin in the bottom left corner!");
return 52;
// throw std::runtime_error("The program can treat only BMP images with
// "
// "the origin in the bottom left corner!");
}
data.resize(bmp_info_header.width * bmp_info_header.height *
@ -206,8 +211,8 @@ struct BMP {
bmp_info_header.height * static_cast<uint32_t>(padding_row.size());
}
} else {
return 53; // throw std::runtime_error("Unable to open the input image
// file "+std::string(fname));
return 53;
// throw std::runtime_error("Unable to open the input image buffer");
}
return 0;
}
@ -525,108 +530,14 @@ struct BMP {
}
}
int OrganizeAverageRed() {
int ColorRed[bmp_info_header.height][bmp_info_header.width];
int ColorGreen[bmp_info_header.height][bmp_info_header.width];
;
int ColorBlue[bmp_info_header.height][bmp_info_header.width];
float pixels = bmp_info_header.height * bmp_info_header.width;
float intensity = 0;
float sum = 0;
uint32_t channels = bmp_info_header.bit_count / 8;
cout << "The Width of the image is " << bmp_info_header.width << endl;
cout << "The height of the image is " << bmp_info_header.height << endl;
for (int y = 0; y < bmp_info_header.height; ++y) {
for (int x = 0; x < bmp_info_header.width; ++x) {
// cout << channels*(y*bmp_info_header.width+x) << endl;
// Read red
ColorBlue[y][x] = data[channels * (y * bmp_info_header.width + x) + 0];
ColorGreen[y][x] = data[channels * (y * bmp_info_header.width + x) + 1];
ColorRed[y][x] = data[channels * (y * bmp_info_header.width + x) + 2];
}
}
for (int y = 0; y < bmp_info_header.height; y++) {
for (int x = 0; x < bmp_info_header.width; x++) {
sum = ColorRed[y][x] + sum -
((ColorBlue[y][x]) / 2 + (ColorGreen[y][x]) / 2);
}
}
intensity = sum / pixels;
cout << intensity << endl;
return intensity;
}
int OrganizeAverageGreen() {
int ColorRed[bmp_info_header.height][bmp_info_header.width];
int ColorGreen[bmp_info_header.height][bmp_info_header.width];
;
int ColorBlue[bmp_info_header.height][bmp_info_header.width];
float pixels = bmp_info_header.height * bmp_info_header.width;
float intensity = 0;
float sum = 0;
uint32_t channels = bmp_info_header.bit_count / 8;
cout << "The Width of the image is " << bmp_info_header.width << endl;
cout << "The height of the image is " << bmp_info_header.height << endl;
for (int y = 0; y < bmp_info_header.height; ++y) {
for (int x = 0; x < bmp_info_header.width; ++x) {
// cout << channels*(y*bmp_info_header.width+x) << endl;
// Read Green
ColorBlue[y][x] = data[channels * (y * bmp_info_header.width + x) + 0];
ColorGreen[y][x] = data[channels * (y * bmp_info_header.width + x) + 1];
ColorRed[y][x] = data[channels * (y * bmp_info_header.width + x) + 2];
}
}
for (int y = 0; y < bmp_info_header.height; y++) {
for (int x = 0; x < bmp_info_header.width; x++) {
sum = ColorGreen[y][x] + sum -
((ColorBlue[y][x]) / 2 + (ColorRed[y][x]) / 2);
}
}
intensity = sum / pixels;
cout << intensity << endl;
return intensity;
}
int OrganizeAverageBlue() {
int ColorRed[bmp_info_header.height][bmp_info_header.width];
int ColorGreen[bmp_info_header.height][bmp_info_header.width];
;
int ColorBlue[bmp_info_header.height][bmp_info_header.width];
float pixels = bmp_info_header.height * bmp_info_header.width;
float intensity = 0;
float sum = 0;
uint32_t channels = bmp_info_header.bit_count / 8;
cout << "The Width of the image is " << bmp_info_header.width << endl;
cout << "The height of the image is " << bmp_info_header.height << endl;
for (int y = 0; y < bmp_info_header.height; ++y) {
for (int x = 0; x < bmp_info_header.width; ++x) {
// cout << channels*(y*bmp_info_header.width+x) << endl;
// Read Blue
ColorBlue[y][x] = data[channels * (y * bmp_info_header.width + x) + 0];
ColorGreen[y][x] = data[channels * (y * bmp_info_header.width + x) + 1];
ColorRed[y][x] = data[channels * (y * bmp_info_header.width + x) + 2];
}
}
for (int y = 0; y < bmp_info_header.height; y++) {
for (int x = 0; x < bmp_info_header.width; x++) {
sum = ColorBlue[y][x] + sum -
((ColorGreen[y][x]) / 2 + (ColorRed[y][x]) / 2);
}
}
intensity = sum / pixels;
cout << intensity << endl;
return intensity;
}
unsigned set_pixel(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R,
uint8_t A) {
if (x0 >= (uint32_t)bmp_info_header.width ||
y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) {
return 59; // throw std::runtime_error("The point is outside the image
// boundaries!");
return 59;
// std::string errr = "The point is outside the image boundaries! -> " +
// std::to_string(x0) + "," + std::to_string(y0); throw
// std::runtime_error(errr);
}
uint32_t channels = bmp_info_header.bit_count / 8;
data[channels * (y0 * bmp_info_header.width + x0) + 0] = B;
@ -643,8 +554,9 @@ struct BMP {
uint32_t y1 = this->bmp_info_header.height - y0;
if (x0 >= (uint32_t)bmp_info_header.width ||
y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) {
return; // throw std::runtime_error("The point is outside the image
// boundaries!");
return;
// throw std::runtime_error("The point is outside the image boundaries! ->
// " + std::to_string(x0) + "," + std::to_string(y1));
}
uint32_t channels = bmp_info_header.bit_count / 8;
@ -656,6 +568,52 @@ struct BMP {
}
}
uint32_t get_pixel(uint32_t x0, uint32_t y0) {
if (x0 >= (uint32_t)bmp_info_header.width ||
y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) {
return 59; // throw std::runtime_error("The point is outside the image
// boundaries!");
}
uint32_t channels = bmp_info_header.bit_count / 8;
uint32_t outcol = 0;
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
uint8_t alpha = 255;
blue = data[channels * (y0 * bmp_info_header.width + x0) + 0];
green = data[channels * (y0 * bmp_info_header.width + x0) + 1];
red = data[channels * (y0 * bmp_info_header.width + x0) + 2];
if (channels == 4) {
alpha = data[channels * (y0 * bmp_info_header.width + x0) + 3];
}
outcol = ((red << 24) | (green << 16) | (blue << 8) | alpha);
return outcol;
}
uint32_t get_pixel_df(uint32_t x0, uint32_t y0) {
uint32_t y1 = this->bmp_info_header.height - y0;
if (x0 >= (uint32_t)bmp_info_header.width ||
y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) {
return 0; // throw std::runtime_error("The point is outside the image
// boundaries!");
}
uint32_t channels = bmp_info_header.bit_count / 8;
uint32_t outcol = 0;
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
uint8_t alpha = 255;
blue = data[channels * (y0 * bmp_info_header.width + x0) + 0];
green = data[channels * (y0 * bmp_info_header.width + x0) + 1];
red = data[channels * (y0 * bmp_info_header.width + x0) + 2];
if (channels == 4) {
alpha = data[channels * (y0 * bmp_info_header.width + x0) + 3];
}
outcol = ((red << 24) | (green << 16) | (blue << 8) | alpha);
return outcol;
}
unsigned draw_rectangle(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h,
uint8_t B, uint8_t G, uint8_t R, uint8_t A,
uint8_t line_w) {

View File

@ -4,13 +4,18 @@
#include <iostream>
namespace BitmapConverter {
// returns 0 if all went ok, non-0 if error
// output image is always given in RGBA (with alpha channel), even if it's a BMP
// without alpha channel
/// returns 0 if all went ok, non-0 if error
/// output image is always given in RGBA (with alpha channel), even if it's a
/// BMP without alpha channel
unsigned decodeBMP(std::vector<unsigned char> &image, unsigned &w, unsigned &h,
const std::vector<unsigned char> &bmp);
/// @brief Convert A File
/// @param filename
/// @return data
std::vector<unsigned char> ConvertFile(std::string filename);
/// @brief Convert data
/// @param data
/// @return data
std::vector<unsigned char> ConvertData(std::vector<unsigned char> data);
} // namespace BitmapConverter

View File

@ -1,29 +0,0 @@
#include <3ds.h>
extern FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
Result FS_CloseArchive(FS_Archive archive);
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path);
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes);
Result FS_MakeDir(FS_Archive archive, const char *path);
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
bool FS_FileExists(FS_Archive archive, const char *path);
bool FS_DirExists(FS_Archive archive, const char *path);
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size);
u64 FS_GetFreeStorage(FS_SystemMediaType media_type);
u64 FS_GetTotalStorage(FS_SystemMediaType media_type);
u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
Result FS_RemoveFile(FS_Archive archive, const char *path);
Result FS_RemoveDir(FS_Archive archive, const char *path);
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path);
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename);
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname);
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf);
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size);
char *FS_GetFileTimestamp(const char *path);
Result makeDirs(const char * path);
Result openFile(Handle* fileHandle, const char * path, bool write);

422
include/renderd7/external/jpgd.h vendored Normal file
View File

@ -0,0 +1,422 @@
// jpgd.h - C++ class for JPEG decompression.
// Richard Geldreich <richgel99@gmail.com>
// See jpgd.cpp for license (Public Domain or Apache 2.0).
#ifndef JPEG_DECODER_H
#define JPEG_DECODER_H
#include <assert.h>
#include <cinttypes>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _MSC_VER
#define JPGD_NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define JPGD_NORETURN __attribute__((noreturn))
#else
#define JPGD_NORETURN
#endif
#define JPGD_HUFF_TREE_MAX_LENGTH 512
#define JPGD_HUFF_CODE_SIZE_MAX_LENGTH 256
namespace jpgd {
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef unsigned int uint;
typedef signed int int32;
// Loads a JPEG image from a memory buffer or a file.
// req_comps can be 1 (grayscale), 3 (RGB), or 4 (RGBA).
// On return, width/height will be set to the image's dimensions, and
// actual_comps will be set to the either 1 (grayscale) or 3 (RGB). Notes: For
// more control over where and how the source data is read, see the
// decompress_jpeg_image_from_stream() function below, or call the jpeg_decoder
// class directly. Requesting a 8 or 32bpp image is currently a little faster
// than 24bpp because the jpeg_decoder class itself currently always unpacks to
// either 8 or 32bpp.
unsigned char *decompress_jpeg_image_from_memory(const unsigned char *pSrc_data,
int src_data_size, int *width,
int *height, int *actual_comps,
int req_comps,
uint32_t flags = 0);
unsigned char *decompress_jpeg_image_from_file(const char *pSrc_filename,
int *width, int *height,
int *actual_comps, int req_comps,
uint32_t flags = 0);
// Success/failure error codes.
enum jpgd_status {
JPGD_SUCCESS = 0,
JPGD_FAILED = -1,
JPGD_DONE = 1,
JPGD_BAD_DHT_COUNTS = -256,
JPGD_BAD_DHT_INDEX,
JPGD_BAD_DHT_MARKER,
JPGD_BAD_DQT_MARKER,
JPGD_BAD_DQT_TABLE,
JPGD_BAD_PRECISION,
JPGD_BAD_HEIGHT,
JPGD_BAD_WIDTH,
JPGD_TOO_MANY_COMPONENTS,
JPGD_BAD_SOF_LENGTH,
JPGD_BAD_VARIABLE_MARKER,
JPGD_BAD_DRI_LENGTH,
JPGD_BAD_SOS_LENGTH,
JPGD_BAD_SOS_COMP_ID,
JPGD_W_EXTRA_BYTES_BEFORE_MARKER,
JPGD_NO_ARITHMITIC_SUPPORT,
JPGD_UNEXPECTED_MARKER,
JPGD_NOT_JPEG,
JPGD_UNSUPPORTED_MARKER,
JPGD_BAD_DQT_LENGTH,
JPGD_TOO_MANY_BLOCKS,
JPGD_UNDEFINED_QUANT_TABLE,
JPGD_UNDEFINED_HUFF_TABLE,
JPGD_NOT_SINGLE_SCAN,
JPGD_UNSUPPORTED_COLORSPACE,
JPGD_UNSUPPORTED_SAMP_FACTORS,
JPGD_DECODE_ERROR,
JPGD_BAD_RESTART_MARKER,
JPGD_BAD_SOS_SPECTRAL,
JPGD_BAD_SOS_SUCCESSIVE,
JPGD_STREAM_READ,
JPGD_NOTENOUGHMEM,
JPGD_TOO_MANY_SCANS
};
// Input stream interface.
// Derive from this class to read input data from sources other than files or
// memory. Set m_eof_flag to true when no more data is available. The decoder is
// rather greedy: it will keep on calling this method until its internal input
// buffer is full, or until the EOF flag is set. It the input stream contains
// data after the JPEG stream's EOI (end of image) marker it will probably be
// pulled into the internal buffer. Call the get_total_bytes_read() method to
// determine the actual size of the JPEG stream after successful decoding.
class jpeg_decoder_stream {
public:
jpeg_decoder_stream() {}
virtual ~jpeg_decoder_stream() {}
// The read() method is called when the internal input buffer is empty.
// Parameters:
// pBuf - input buffer
// max_bytes_to_read - maximum bytes that can be written to pBuf
// pEOF_flag - set this to true if at end of stream (no more bytes remaining)
// Returns -1 on error, otherwise return the number of bytes actually written
// to the buffer (which may be 0). Notes: This method will be called in a loop
// until you set *pEOF_flag to true or the internal buffer is full.
virtual int read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag) = 0;
};
// stdio FILE stream class.
class jpeg_decoder_file_stream : public jpeg_decoder_stream {
jpeg_decoder_file_stream(const jpeg_decoder_file_stream &);
jpeg_decoder_file_stream &operator=(const jpeg_decoder_file_stream &);
FILE *m_pFile;
bool m_eof_flag, m_error_flag;
public:
jpeg_decoder_file_stream();
virtual ~jpeg_decoder_file_stream();
bool open(const char *Pfilename);
void close();
virtual int read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag);
};
// Memory stream class.
class jpeg_decoder_mem_stream : public jpeg_decoder_stream {
const uint8 *m_pSrc_data;
uint m_ofs, m_size;
public:
jpeg_decoder_mem_stream() : m_pSrc_data(NULL), m_ofs(0), m_size(0) {}
jpeg_decoder_mem_stream(const uint8 *pSrc_data, uint size)
: m_pSrc_data(pSrc_data), m_ofs(0), m_size(size) {}
virtual ~jpeg_decoder_mem_stream() {}
bool open(const uint8 *pSrc_data, uint size);
void close() {
m_pSrc_data = NULL;
m_ofs = 0;
m_size = 0;
}
virtual int read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag);
};
// Loads JPEG file from a jpeg_decoder_stream.
unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream,
int *width, int *height,
int *actual_comps,
int req_comps,
uint32_t flags = 0);
enum {
JPGD_IN_BUF_SIZE = 8192,
JPGD_MAX_BLOCKS_PER_MCU = 10,
JPGD_MAX_HUFF_TABLES = 8,
JPGD_MAX_QUANT_TABLES = 4,
JPGD_MAX_COMPONENTS = 4,
JPGD_MAX_COMPS_IN_SCAN = 4,
JPGD_MAX_BLOCKS_PER_ROW = 16384,
JPGD_MAX_HEIGHT = 32768,
JPGD_MAX_WIDTH = 32768
};
typedef int16 jpgd_quant_t;
typedef int16 jpgd_block_coeff_t;
class jpeg_decoder {
public:
enum { cFlagBoxChromaFiltering = 1, cFlagDisableSIMD = 2 };
// Call get_error_code() after constructing to determine if the stream is
// valid or not. You may call the get_width(), get_height(), etc. methods
// after the constructor is called. You may then either destruct the object,
// or begin decoding the image by calling begin_decoding(), then decode() on
// each scanline.
jpeg_decoder(jpeg_decoder_stream *pStream, uint32_t flags = 0);
~jpeg_decoder();
// Call this method after constructing the object to begin decompression.
// If JPGD_SUCCESS is returned you may then call decode() on each scanline.
int begin_decoding();
// Returns the next scan line.
// For grayscale images, pScan_line will point to a buffer containing 8-bit
// pixels (get_bytes_per_pixel() will return 1). Otherwise, it will always
// point to a buffer containing 32-bit RGBA pixels (A will always be 255, and
// get_bytes_per_pixel() will return 4). Returns JPGD_SUCCESS if a scan line
// has been returned. Returns JPGD_DONE if all scan lines have been returned.
// Returns JPGD_FAILED if an error occurred. Call get_error_code() for a more
// info.
int decode(const void **pScan_line, uint *pScan_line_len);
inline jpgd_status get_error_code() const { return m_error_code; }
inline int get_width() const { return m_image_x_size; }
inline int get_height() const { return m_image_y_size; }
inline int get_num_components() const { return m_comps_in_frame; }
inline int get_bytes_per_pixel() const { return m_dest_bytes_per_pixel; }
inline int get_bytes_per_scan_line() const {
return m_image_x_size * get_bytes_per_pixel();
}
// Returns the total number of bytes actually consumed by the decoder (which
// should equal the actual size of the JPEG file).
inline int get_total_bytes_read() const { return m_total_bytes_read; }
private:
jpeg_decoder(const jpeg_decoder &);
jpeg_decoder &operator=(const jpeg_decoder &);
typedef void (*pDecode_block_func)(jpeg_decoder *, int, int, int);
struct huff_tables {
bool ac_table;
uint look_up[256];
uint look_up2[256];
uint8 code_size[JPGD_HUFF_CODE_SIZE_MAX_LENGTH];
uint tree[JPGD_HUFF_TREE_MAX_LENGTH];
};
struct coeff_buf {
uint8 *pData;
int block_num_x, block_num_y;
int block_len_x, block_len_y;
int block_size;
};
struct mem_block {
mem_block *m_pNext;
size_t m_used_count;
size_t m_size;
char m_data[1];
};
jmp_buf m_jmp_state;
uint32_t m_flags;
mem_block *m_pMem_blocks;
int m_image_x_size;
int m_image_y_size;
jpeg_decoder_stream *m_pStream;
int m_progressive_flag;
uint8 m_huff_ac[JPGD_MAX_HUFF_TABLES];
uint8 *m_huff_num[JPGD_MAX_HUFF_TABLES]; // pointer to number of Huffman codes
// per bit size
uint8 *
m_huff_val[JPGD_MAX_HUFF_TABLES]; // pointer to Huffman codes per bit size
jpgd_quant_t
*m_quant[JPGD_MAX_QUANT_TABLES]; // pointer to quantization tables
int m_scan_type; // Gray, Yh1v1, Yh1v2, Yh2v1, Yh2v2 (CMYK111, CMYK4114 no
// longer supported)
int m_comps_in_frame; // # of components in frame
int m_comp_h_samp[JPGD_MAX_COMPONENTS]; // component's horizontal sampling
// factor
int m_comp_v_samp[JPGD_MAX_COMPONENTS]; // component's vertical sampling
// factor
int m_comp_quant[JPGD_MAX_COMPONENTS]; // component's quantization table
// selector
int m_comp_ident[JPGD_MAX_COMPONENTS]; // component's ID
int m_comp_h_blocks[JPGD_MAX_COMPONENTS];
int m_comp_v_blocks[JPGD_MAX_COMPONENTS];
int m_comps_in_scan; // # of components in scan
int m_comp_list[JPGD_MAX_COMPS_IN_SCAN]; // components in this scan
int m_comp_dc_tab[JPGD_MAX_COMPONENTS]; // component's DC Huffman coding table
// selector
int m_comp_ac_tab[JPGD_MAX_COMPONENTS]; // component's AC Huffman coding table
// selector
int m_spectral_start; // spectral selection start
int m_spectral_end; // spectral selection end
int m_successive_low; // successive approximation low
int m_successive_high; // successive approximation high
int m_max_mcu_x_size; // MCU's max. X size in pixels
int m_max_mcu_y_size; // MCU's max. Y size in pixels
int m_blocks_per_mcu;
int m_max_blocks_per_row;
int m_mcus_per_row, m_mcus_per_col;
int m_mcu_org[JPGD_MAX_BLOCKS_PER_MCU];
int m_total_lines_left; // total # lines left in image
int m_mcu_lines_left; // total # lines left in this MCU
int m_num_buffered_scanlines;
int m_real_dest_bytes_per_scan_line;
int m_dest_bytes_per_scan_line; // rounded up
int m_dest_bytes_per_pixel; // 4 (RGB) or 1 (Y)
huff_tables *m_pHuff_tabs[JPGD_MAX_HUFF_TABLES];
coeff_buf *m_dc_coeffs[JPGD_MAX_COMPONENTS];
coeff_buf *m_ac_coeffs[JPGD_MAX_COMPONENTS];
int m_eob_run;
int m_block_y_mcu[JPGD_MAX_COMPONENTS];
uint8 *m_pIn_buf_ofs;
int m_in_buf_left;
int m_tem_flag;
uint8 m_in_buf_pad_start[64];
uint8 m_in_buf[JPGD_IN_BUF_SIZE + 128];
uint8 m_in_buf_pad_end[64];
int m_bits_left;
uint m_bit_buf;
int m_restart_interval;
int m_restarts_left;
int m_next_restart_num;
int m_max_mcus_per_row;
int m_max_blocks_per_mcu;
int m_max_mcus_per_col;
uint m_last_dc_val[JPGD_MAX_COMPONENTS];
jpgd_block_coeff_t *m_pMCU_coefficients;
int m_mcu_block_max_zag[JPGD_MAX_BLOCKS_PER_MCU];
uint8 *m_pSample_buf;
uint8 *m_pSample_buf_prev;
int m_crr[256];
int m_cbb[256];
int m_crg[256];
int m_cbg[256];
uint8 *m_pScan_line_0;
uint8 *m_pScan_line_1;
jpgd_status m_error_code;
int m_total_bytes_read;
bool m_ready_flag;
bool m_eof_flag;
bool m_sample_buf_prev_valid;
bool m_has_sse2;
inline int check_sample_buf_ofs(int ofs) const {
assert(ofs >= 0);
assert(ofs < m_max_blocks_per_row * 64);
return ofs;
}
void free_all_blocks();
JPGD_NORETURN void stop_decoding(jpgd_status status);
void *alloc(size_t n, bool zero = false);
void *alloc_aligned(size_t nSize, uint32_t align = 16, bool zero = false);
void word_clear(void *p, uint16 c, uint n);
void prep_in_buffer();
void read_dht_marker();
void read_dqt_marker();
void read_sof_marker();
void skip_variable_marker();
void read_dri_marker();
void read_sos_marker();
int next_marker();
int process_markers();
void locate_soi_marker();
void locate_sof_marker();
int locate_sos_marker();
void init(jpeg_decoder_stream *pStream, uint32_t flags);
void create_look_ups();
void fix_in_buffer();
void transform_mcu(int mcu_row);
coeff_buf *coeff_buf_open(int block_num_x, int block_num_y, int block_len_x,
int block_len_y);
inline jpgd_block_coeff_t *coeff_buf_getp(coeff_buf *cb, int block_x,
int block_y);
void load_next_row();
void decode_next_row();
void make_huff_table(int index, huff_tables *pH);
void check_quant_tables();
void check_huff_tables();
bool calc_mcu_block_order();
int init_scan();
void init_frame();
void process_restart();
void decode_scan(pDecode_block_func decode_block_func);
void init_progressive();
void init_sequential();
void decode_start();
void decode_init(jpeg_decoder_stream *pStream, uint32_t flags);
void H2V2Convert();
uint32_t H2V2ConvertFiltered();
void H2V1Convert();
void H2V1ConvertFiltered();
void H1V2Convert();
void H1V2ConvertFiltered();
void H1V1Convert();
void gray_convert();
void find_eoi();
inline uint get_char();
inline uint get_char(bool *pPadding_flag);
inline void stuff_char(uint8 q);
inline uint8 get_octet();
inline uint get_bits(int num_bits);
inline uint get_bits_no_markers(int numbits);
inline int huff_decode(huff_tables *pH);
inline int huff_decode(huff_tables *pH, int &extrabits);
// Clamps a value between 0-255.
static inline uint8 clamp(int i) {
if (static_cast<uint>(i) > 255)
i = (((~i) >> 31) & 0xFF);
return static_cast<uint8>(i);
}
int decode_next_mcu_row();
static void decode_block_dc_first(jpeg_decoder *pD, int component_id,
int block_x, int block_y);
static void decode_block_dc_refine(jpeg_decoder *pD, int component_id,
int block_x, int block_y);
static void decode_block_ac_first(jpeg_decoder *pD, int component_id,
int block_x, int block_y);
static void decode_block_ac_refine(jpeg_decoder *pD, int component_id,
int block_x, int block_y);
};
} // namespace jpgd
#endif // JPEG_DECODER_H

478
include/renderd7/external/jpgd_idct.h vendored Normal file
View File

@ -0,0 +1,478 @@
// Copyright 2009 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works
// of this software for any purpose and without fee, provided, that the above
// copyright notice and this statement appear in all copies. Intel makes no
// representations about the suitability of this software for any purpose. THIS
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
// any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//
// From:
// https://software.intel.com/sites/default/files/m/d/4/1/d/8/UsingIntelAVXToImplementIDCT-r1_5.pdf
// https://software.intel.com/file/29048
//
// Requires SSE
//
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <immintrin.h>
#ifdef _MSC_VER
#define JPGD_SIMD_ALIGN(type, name) __declspec(align(16)) type name
#else
#define JPGD_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
#endif
#include <cinttypes>
#define BITS_INV_ACC 4
#define SHIFT_INV_ROW 16 - BITS_INV_ACC
#define SHIFT_INV_COL 1 + BITS_INV_ACC
const short IRND_INV_ROW = 1024 * (6 - BITS_INV_ACC); // 1 << (SHIFT_INV_ROW-1)
const short IRND_INV_COL = 16 * (BITS_INV_ACC - 3); // 1 << (SHIFT_INV_COL-1)
const short IRND_INV_CORR = IRND_INV_COL - 1; // correction -1.0 and round
JPGD_SIMD_ALIGN(short, shortM128_one_corr[8]) = {1, 1, 1, 1, 1, 1, 1, 1};
JPGD_SIMD_ALIGN(short, shortM128_round_inv_row[8]) = {
IRND_INV_ROW, 0, IRND_INV_ROW, 0, IRND_INV_ROW, 0, IRND_INV_ROW, 0};
JPGD_SIMD_ALIGN(short, shortM128_round_inv_col[8]) = {
IRND_INV_COL, IRND_INV_COL, IRND_INV_COL, IRND_INV_COL,
IRND_INV_COL, IRND_INV_COL, IRND_INV_COL, IRND_INV_COL};
JPGD_SIMD_ALIGN(short, shortM128_round_inv_corr[8]) = {
IRND_INV_CORR, IRND_INV_CORR, IRND_INV_CORR, IRND_INV_CORR,
IRND_INV_CORR, IRND_INV_CORR, IRND_INV_CORR, IRND_INV_CORR};
JPGD_SIMD_ALIGN(short, shortM128_tg_1_16[8]) = {
13036, 13036, 13036, 13036,
13036, 13036, 13036, 13036}; // tg * (2<<16) + 0.5
JPGD_SIMD_ALIGN(short, shortM128_tg_2_16[8]) = {
27146, 27146, 27146, 27146,
27146, 27146, 27146, 27146}; // tg * (2<<16) + 0.5
JPGD_SIMD_ALIGN(short, shortM128_tg_3_16[8]) = {
-21746, -21746, -21746, -21746,
-21746, -21746, -21746, -21746}; // tg * (2<<16) + 0.5
JPGD_SIMD_ALIGN(short, shortM128_cos_4_16[8]) = {
-19195, -19195, -19195, -19195,
-19195, -19195, -19195, -19195}; // cos * (2<<16) + 0.5
//-----------------------------------------------------------------------------
// Table for rows 0,4 - constants are multiplied on cos_4_16
// w15 w14 w11 w10 w07 w06 w03 w02
// w29 w28 w25 w24 w21 w20 w17 w16
// w31 w30 w27 w26 w23 w22 w19 w18
// movq -> w05 w04 w01 w00
JPGD_SIMD_ALIGN(short, shortM128_tab_i_04[]) = {
16384, 21407, 16384, 8867,
16384, -8867, 16384, -21407, // w13 w12 w09 w08
16384, 8867, -16384, -21407, // w07 w06 w03 w02
-16384, 21407, 16384, -8867, // w15 w14 w11 w10
22725, 19266, 19266, -4520, // w21 w20 w17 w16
12873, -22725, 4520, -12873, // w29 w28 w25 w24
12873, 4520, -22725, -12873, // w23 w22 w19 w18
4520, 19266, 19266, -22725}; // w31 w30 w27 w26
// Table for rows 1,7 - constants are multiplied on cos_1_16
// movq -> w05 w04 w01 w00
JPGD_SIMD_ALIGN(short, shortM128_tab_i_17[]) = {
22725, 29692, 22725, 12299,
22725, -12299, 22725, -29692, // w13 w12 w09 w08
22725, 12299, -22725, -29692, // w07 w06 w03 w02
-22725, 29692, 22725, -12299, // w15 w14 w11 w10
31521, 26722, 26722, -6270, // w21 w20 w17 w16
17855, -31521, 6270, -17855, // w29 w28 w25 w24
17855, 6270, -31521, -17855, // w23 w22 w19 w18
6270, 26722, 26722, -31521}; // w31 w30 w27 w26
// Table for rows 2,6 - constants are multiplied on cos_2_16
// movq -> w05 w04 w01 w00
JPGD_SIMD_ALIGN(short, shortM128_tab_i_26[]) = {
21407, 27969, 21407, 11585,
21407, -11585, 21407, -27969, // w13 w12 w09 w08
21407, 11585, -21407, -27969, // w07 w06 w03 w02
-21407, 27969, 21407, -11585, // w15 w14 w11 w10
29692, 25172, 25172, -5906, // w21 w20 w17 w16
16819, -29692, 5906, -16819, // w29 w28 w25 w24
16819, 5906, -29692, -16819, // w23 w22 w19 w18
5906, 25172, 25172, -29692}; // w31 w30 w27 w26
// Table for rows 3,5 - constants are multiplied on cos_3_16
// movq -> w05 w04 w01 w00
JPGD_SIMD_ALIGN(short, shortM128_tab_i_35[]) = {
19266, 25172, 19266, 10426,
19266, -10426, 19266, -25172, // w13 w12 w09 w08
19266, 10426, -19266, -25172, // w07 w06 w03 w02
-19266, 25172, 19266, -10426, // w15 w14 w11 w10
26722, 22654, 22654, -5315, // w21 w20 w17 w16
15137, -26722, 5315, -15137, // w29 w28 w25 w24
15137, 5315, -26722, -15137, // w23 w22 w19 w18
5315, 22654, 22654, -26722}; // w31 w30 w27 w26
JPGD_SIMD_ALIGN(short, shortM128_128[8]) = {128, 128, 128, 128,
128, 128, 128, 128};
void idctSSEShortU8(const short *pInput, uint8_t *pOutputUB) {
__m128i r_xmm0, r_xmm4;
__m128i r_xmm1, r_xmm2, r_xmm3, r_xmm5, r_xmm6, r_xmm7;
__m128i row0, row1, row2, row3, row4, row5, row6, row7;
short *pTab_i_04 = shortM128_tab_i_04;
short *pTab_i_26 = shortM128_tab_i_26;
// Get pointers for this input and output
pTab_i_04 = shortM128_tab_i_04;
pTab_i_26 = shortM128_tab_i_26;
// Row 1 and Row 3
r_xmm0 = _mm_load_si128((__m128i *)pInput);
r_xmm4 = _mm_load_si128((__m128i *)(&pInput[2 * 8]));
// *** Work on the data in xmm0
// low shuffle mask = 0xd8 = 11 01 10 00
// get short 2 and short 0 into ls 32-bits
r_xmm0 = _mm_shufflelo_epi16(r_xmm0, 0xd8);
// copy short 2 and short 0 to all locations
r_xmm1 = _mm_shuffle_epi32(r_xmm0, 0);
// add to those copies
r_xmm1 = _mm_madd_epi16(r_xmm1, *((__m128i *)pTab_i_04));
// shuffle mask = 0x55 = 01 01 01 01
// copy short 3 and short 1 to all locations
r_xmm3 = _mm_shuffle_epi32(r_xmm0, 0x55);
// high shuffle mask = 0xd8 = 11 01 10 00
// get short 6 and short 4 into bit positions 64-95
// get short 7 and short 5 into bit positions 96-127
r_xmm0 = _mm_shufflehi_epi16(r_xmm0, 0xd8);
// add to short 3 and short 1
r_xmm3 = _mm_madd_epi16(r_xmm3, *((__m128i *)&pTab_i_04[16]));
// shuffle mask = 0xaa = 10 10 10 10
// copy short 6 and short 4 to all locations
r_xmm2 = _mm_shuffle_epi32(r_xmm0, 0xaa);
// shuffle mask = 0xaa = 11 11 11 11
// copy short 7 and short 5 to all locations
r_xmm0 = _mm_shuffle_epi32(r_xmm0, 0xff);
// add to short 6 and short 4
r_xmm2 = _mm_madd_epi16(r_xmm2, *((__m128i *)&pTab_i_04[8]));
// *** Work on the data in xmm4
// high shuffle mask = 0xd8 11 01 10 00
// get short 6 and short 4 into bit positions 64-95
// get short 7 and short 5 into bit positions 96-127
r_xmm4 = _mm_shufflehi_epi16(r_xmm4, 0xd8);
// (xmm0 short 2 and short 0 plus pSi) + some constants
r_xmm1 = _mm_add_epi32(r_xmm1, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_shufflelo_epi16(r_xmm4, 0xd8);
r_xmm0 = _mm_madd_epi16(r_xmm0, *((__m128i *)&pTab_i_04[24]));
r_xmm5 = _mm_shuffle_epi32(r_xmm4, 0);
r_xmm6 = _mm_shuffle_epi32(r_xmm4, 0xaa);
r_xmm5 = _mm_madd_epi16(r_xmm5, *((__m128i *)&shortM128_tab_i_26[0]));
r_xmm1 = _mm_add_epi32(r_xmm1, r_xmm2);
r_xmm2 = r_xmm1;
r_xmm7 = _mm_shuffle_epi32(r_xmm4, 0x55);
r_xmm6 = _mm_madd_epi16(r_xmm6, *((__m128i *)&shortM128_tab_i_26[8]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm3);
r_xmm4 = _mm_shuffle_epi32(r_xmm4, 0xff);
r_xmm2 = _mm_sub_epi32(r_xmm2, r_xmm0);
r_xmm7 = _mm_madd_epi16(r_xmm7, *((__m128i *)&shortM128_tab_i_26[16]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm1);
r_xmm2 = _mm_srai_epi32(r_xmm2, 12);
r_xmm5 = _mm_add_epi32(r_xmm5, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_madd_epi16(r_xmm4, *((__m128i *)&shortM128_tab_i_26[24]));
r_xmm5 = _mm_add_epi32(r_xmm5, r_xmm6);
r_xmm6 = r_xmm5;
r_xmm0 = _mm_srai_epi32(r_xmm0, 12);
r_xmm2 = _mm_shuffle_epi32(r_xmm2, 0x1b);
row0 = _mm_packs_epi32(r_xmm0, r_xmm2);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm7);
r_xmm6 = _mm_sub_epi32(r_xmm6, r_xmm4);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm5);
r_xmm6 = _mm_srai_epi32(r_xmm6, 12);
r_xmm4 = _mm_srai_epi32(r_xmm4, 12);
r_xmm6 = _mm_shuffle_epi32(r_xmm6, 0x1b);
row2 = _mm_packs_epi32(r_xmm4, r_xmm6);
// Row 5 and row 7
r_xmm0 = _mm_load_si128((__m128i *)(&pInput[4 * 8]));
r_xmm4 = _mm_load_si128((__m128i *)(&pInput[6 * 8]));
r_xmm0 = _mm_shufflelo_epi16(r_xmm0, 0xd8);
r_xmm1 = _mm_shuffle_epi32(r_xmm0, 0);
r_xmm1 = _mm_madd_epi16(r_xmm1, *((__m128i *)pTab_i_04));
r_xmm3 = _mm_shuffle_epi32(r_xmm0, 0x55);
r_xmm0 = _mm_shufflehi_epi16(r_xmm0, 0xd8);
r_xmm3 = _mm_madd_epi16(r_xmm3, *((__m128i *)&pTab_i_04[16]));
r_xmm2 = _mm_shuffle_epi32(r_xmm0, 0xaa);
r_xmm0 = _mm_shuffle_epi32(r_xmm0, 0xff);
r_xmm2 = _mm_madd_epi16(r_xmm2, *((__m128i *)&pTab_i_04[8]));
r_xmm4 = _mm_shufflehi_epi16(r_xmm4, 0xd8);
r_xmm1 = _mm_add_epi32(r_xmm1, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_shufflelo_epi16(r_xmm4, 0xd8);
r_xmm0 = _mm_madd_epi16(r_xmm0, *((__m128i *)&pTab_i_04[24]));
r_xmm5 = _mm_shuffle_epi32(r_xmm4, 0);
r_xmm6 = _mm_shuffle_epi32(r_xmm4, 0xaa);
r_xmm5 = _mm_madd_epi16(r_xmm5, *((__m128i *)&shortM128_tab_i_26[0]));
r_xmm1 = _mm_add_epi32(r_xmm1, r_xmm2);
r_xmm2 = r_xmm1;
r_xmm7 = _mm_shuffle_epi32(r_xmm4, 0x55);
r_xmm6 = _mm_madd_epi16(r_xmm6, *((__m128i *)&shortM128_tab_i_26[8]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm3);
r_xmm4 = _mm_shuffle_epi32(r_xmm4, 0xff);
r_xmm2 = _mm_sub_epi32(r_xmm2, r_xmm0);
r_xmm7 = _mm_madd_epi16(r_xmm7, *((__m128i *)&shortM128_tab_i_26[16]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm1);
r_xmm2 = _mm_srai_epi32(r_xmm2, 12);
r_xmm5 = _mm_add_epi32(r_xmm5, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_madd_epi16(r_xmm4, *((__m128i *)&shortM128_tab_i_26[24]));
r_xmm5 = _mm_add_epi32(r_xmm5, r_xmm6);
r_xmm6 = r_xmm5;
r_xmm0 = _mm_srai_epi32(r_xmm0, 12);
r_xmm2 = _mm_shuffle_epi32(r_xmm2, 0x1b);
row4 = _mm_packs_epi32(r_xmm0, r_xmm2);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm7);
r_xmm6 = _mm_sub_epi32(r_xmm6, r_xmm4);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm5);
r_xmm6 = _mm_srai_epi32(r_xmm6, 12);
r_xmm4 = _mm_srai_epi32(r_xmm4, 12);
r_xmm6 = _mm_shuffle_epi32(r_xmm6, 0x1b);
row6 = _mm_packs_epi32(r_xmm4, r_xmm6);
// Row 4 and row 2
pTab_i_04 = shortM128_tab_i_35;
pTab_i_26 = shortM128_tab_i_17;
r_xmm0 = _mm_load_si128((__m128i *)(&pInput[3 * 8]));
r_xmm4 = _mm_load_si128((__m128i *)(&pInput[1 * 8]));
r_xmm0 = _mm_shufflelo_epi16(r_xmm0, 0xd8);
r_xmm1 = _mm_shuffle_epi32(r_xmm0, 0);
r_xmm1 = _mm_madd_epi16(r_xmm1, *((__m128i *)pTab_i_04));
r_xmm3 = _mm_shuffle_epi32(r_xmm0, 0x55);
r_xmm0 = _mm_shufflehi_epi16(r_xmm0, 0xd8);
r_xmm3 = _mm_madd_epi16(r_xmm3, *((__m128i *)&pTab_i_04[16]));
r_xmm2 = _mm_shuffle_epi32(r_xmm0, 0xaa);
r_xmm0 = _mm_shuffle_epi32(r_xmm0, 0xff);
r_xmm2 = _mm_madd_epi16(r_xmm2, *((__m128i *)&pTab_i_04[8]));
r_xmm4 = _mm_shufflehi_epi16(r_xmm4, 0xd8);
r_xmm1 = _mm_add_epi32(r_xmm1, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_shufflelo_epi16(r_xmm4, 0xd8);
r_xmm0 = _mm_madd_epi16(r_xmm0, *((__m128i *)&pTab_i_04[24]));
r_xmm5 = _mm_shuffle_epi32(r_xmm4, 0);
r_xmm6 = _mm_shuffle_epi32(r_xmm4, 0xaa);
r_xmm5 = _mm_madd_epi16(r_xmm5, *((__m128i *)&pTab_i_26[0]));
r_xmm1 = _mm_add_epi32(r_xmm1, r_xmm2);
r_xmm2 = r_xmm1;
r_xmm7 = _mm_shuffle_epi32(r_xmm4, 0x55);
r_xmm6 = _mm_madd_epi16(r_xmm6, *((__m128i *)&pTab_i_26[8]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm3);
r_xmm4 = _mm_shuffle_epi32(r_xmm4, 0xff);
r_xmm2 = _mm_sub_epi32(r_xmm2, r_xmm0);
r_xmm7 = _mm_madd_epi16(r_xmm7, *((__m128i *)&pTab_i_26[16]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm1);
r_xmm2 = _mm_srai_epi32(r_xmm2, 12);
r_xmm5 = _mm_add_epi32(r_xmm5, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_madd_epi16(r_xmm4, *((__m128i *)&pTab_i_26[24]));
r_xmm5 = _mm_add_epi32(r_xmm5, r_xmm6);
r_xmm6 = r_xmm5;
r_xmm0 = _mm_srai_epi32(r_xmm0, 12);
r_xmm2 = _mm_shuffle_epi32(r_xmm2, 0x1b);
row3 = _mm_packs_epi32(r_xmm0, r_xmm2);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm7);
r_xmm6 = _mm_sub_epi32(r_xmm6, r_xmm4);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm5);
r_xmm6 = _mm_srai_epi32(r_xmm6, 12);
r_xmm4 = _mm_srai_epi32(r_xmm4, 12);
r_xmm6 = _mm_shuffle_epi32(r_xmm6, 0x1b);
row1 = _mm_packs_epi32(r_xmm4, r_xmm6);
// Row 6 and row 8
r_xmm0 = _mm_load_si128((__m128i *)(&pInput[5 * 8]));
r_xmm4 = _mm_load_si128((__m128i *)(&pInput[7 * 8]));
r_xmm0 = _mm_shufflelo_epi16(r_xmm0, 0xd8);
r_xmm1 = _mm_shuffle_epi32(r_xmm0, 0);
r_xmm1 = _mm_madd_epi16(r_xmm1, *((__m128i *)pTab_i_04));
r_xmm3 = _mm_shuffle_epi32(r_xmm0, 0x55);
r_xmm0 = _mm_shufflehi_epi16(r_xmm0, 0xd8);
r_xmm3 = _mm_madd_epi16(r_xmm3, *((__m128i *)&pTab_i_04[16]));
r_xmm2 = _mm_shuffle_epi32(r_xmm0, 0xaa);
r_xmm0 = _mm_shuffle_epi32(r_xmm0, 0xff);
r_xmm2 = _mm_madd_epi16(r_xmm2, *((__m128i *)&pTab_i_04[8]));
r_xmm4 = _mm_shufflehi_epi16(r_xmm4, 0xd8);
r_xmm1 = _mm_add_epi32(r_xmm1, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_shufflelo_epi16(r_xmm4, 0xd8);
r_xmm0 = _mm_madd_epi16(r_xmm0, *((__m128i *)&pTab_i_04[24]));
r_xmm5 = _mm_shuffle_epi32(r_xmm4, 0);
r_xmm6 = _mm_shuffle_epi32(r_xmm4, 0xaa);
r_xmm5 = _mm_madd_epi16(r_xmm5, *((__m128i *)&pTab_i_26[0]));
r_xmm1 = _mm_add_epi32(r_xmm1, r_xmm2);
r_xmm2 = r_xmm1;
r_xmm7 = _mm_shuffle_epi32(r_xmm4, 0x55);
r_xmm6 = _mm_madd_epi16(r_xmm6, *((__m128i *)&pTab_i_26[8]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm3);
r_xmm4 = _mm_shuffle_epi32(r_xmm4, 0xff);
r_xmm2 = _mm_sub_epi32(r_xmm2, r_xmm0);
r_xmm7 = _mm_madd_epi16(r_xmm7, *((__m128i *)&pTab_i_26[16]));
r_xmm0 = _mm_add_epi32(r_xmm0, r_xmm1);
r_xmm2 = _mm_srai_epi32(r_xmm2, 12);
r_xmm5 = _mm_add_epi32(r_xmm5, *((__m128i *)shortM128_round_inv_row));
r_xmm4 = _mm_madd_epi16(r_xmm4, *((__m128i *)&pTab_i_26[24]));
r_xmm5 = _mm_add_epi32(r_xmm5, r_xmm6);
r_xmm6 = r_xmm5;
r_xmm0 = _mm_srai_epi32(r_xmm0, 12);
r_xmm2 = _mm_shuffle_epi32(r_xmm2, 0x1b);
row5 = _mm_packs_epi32(r_xmm0, r_xmm2);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm7);
r_xmm6 = _mm_sub_epi32(r_xmm6, r_xmm4);
r_xmm4 = _mm_add_epi32(r_xmm4, r_xmm5);
r_xmm6 = _mm_srai_epi32(r_xmm6, 12);
r_xmm4 = _mm_srai_epi32(r_xmm4, 12);
r_xmm6 = _mm_shuffle_epi32(r_xmm6, 0x1b);
row7 = _mm_packs_epi32(r_xmm4, r_xmm6);
r_xmm1 = _mm_load_si128((__m128i *)shortM128_tg_3_16);
r_xmm2 = row5;
r_xmm3 = row3;
r_xmm0 = _mm_mulhi_epi16(row5, r_xmm1);
r_xmm1 = _mm_mulhi_epi16(r_xmm1, r_xmm3);
r_xmm5 = _mm_load_si128((__m128i *)shortM128_tg_1_16);
r_xmm6 = row7;
r_xmm4 = _mm_mulhi_epi16(row7, r_xmm5);
r_xmm0 = _mm_adds_epi16(r_xmm0, r_xmm2);
r_xmm5 = _mm_mulhi_epi16(r_xmm5, row1);
r_xmm1 = _mm_adds_epi16(r_xmm1, r_xmm3);
r_xmm7 = row6;
r_xmm0 = _mm_adds_epi16(r_xmm0, r_xmm3);
r_xmm3 = _mm_load_si128((__m128i *)shortM128_tg_2_16);
r_xmm2 = _mm_subs_epi16(r_xmm2, r_xmm1);
r_xmm7 = _mm_mulhi_epi16(r_xmm7, r_xmm3);
r_xmm1 = r_xmm0;
r_xmm3 = _mm_mulhi_epi16(r_xmm3, row2);
r_xmm5 = _mm_subs_epi16(r_xmm5, r_xmm6);
r_xmm4 = _mm_adds_epi16(r_xmm4, row1);
r_xmm0 = _mm_adds_epi16(r_xmm0, r_xmm4);
r_xmm0 = _mm_adds_epi16(r_xmm0, *((__m128i *)shortM128_one_corr));
r_xmm4 = _mm_subs_epi16(r_xmm4, r_xmm1);
r_xmm6 = r_xmm5;
r_xmm5 = _mm_subs_epi16(r_xmm5, r_xmm2);
r_xmm5 = _mm_adds_epi16(r_xmm5, *((__m128i *)shortM128_one_corr));
r_xmm6 = _mm_adds_epi16(r_xmm6, r_xmm2);
// Intermediate results, needed later
__m128i temp3, temp7;
temp7 = r_xmm0;
r_xmm1 = r_xmm4;
r_xmm0 = _mm_load_si128((__m128i *)shortM128_cos_4_16);
r_xmm4 = _mm_adds_epi16(r_xmm4, r_xmm5);
r_xmm2 = _mm_load_si128((__m128i *)shortM128_cos_4_16);
r_xmm2 = _mm_mulhi_epi16(r_xmm2, r_xmm4);
// Intermediate results, needed later
temp3 = r_xmm6;
r_xmm1 = _mm_subs_epi16(r_xmm1, r_xmm5);
r_xmm7 = _mm_adds_epi16(r_xmm7, row2);
r_xmm3 = _mm_subs_epi16(r_xmm3, row6);
r_xmm6 = row0;
r_xmm0 = _mm_mulhi_epi16(r_xmm0, r_xmm1);
r_xmm5 = row4;
r_xmm5 = _mm_adds_epi16(r_xmm5, r_xmm6);
r_xmm6 = _mm_subs_epi16(r_xmm6, row4);
r_xmm4 = _mm_adds_epi16(r_xmm4, r_xmm2);
r_xmm4 = _mm_or_si128(r_xmm4, *((__m128i *)shortM128_one_corr));
r_xmm0 = _mm_adds_epi16(r_xmm0, r_xmm1);
r_xmm0 = _mm_or_si128(r_xmm0, *((__m128i *)shortM128_one_corr));
r_xmm2 = r_xmm5;
r_xmm5 = _mm_adds_epi16(r_xmm5, r_xmm7);
r_xmm1 = r_xmm6;
r_xmm5 = _mm_adds_epi16(r_xmm5, *((__m128i *)shortM128_round_inv_col));
r_xmm2 = _mm_subs_epi16(r_xmm2, r_xmm7);
r_xmm7 = temp7;
r_xmm6 = _mm_adds_epi16(r_xmm6, r_xmm3);
r_xmm6 = _mm_adds_epi16(r_xmm6, *((__m128i *)shortM128_round_inv_col));
r_xmm7 = _mm_adds_epi16(r_xmm7, r_xmm5);
r_xmm7 = _mm_srai_epi16(r_xmm7, SHIFT_INV_COL);
r_xmm1 = _mm_subs_epi16(r_xmm1, r_xmm3);
r_xmm1 = _mm_adds_epi16(r_xmm1, *((__m128i *)shortM128_round_inv_corr));
r_xmm3 = r_xmm6;
r_xmm2 = _mm_adds_epi16(r_xmm2, *((__m128i *)shortM128_round_inv_corr));
r_xmm6 = _mm_adds_epi16(r_xmm6, r_xmm4);
// Store results for row 0
//_mm_store_si128((__m128i *) pOutput, r_xmm7);
__m128i r0 = r_xmm7;
r_xmm6 = _mm_srai_epi16(r_xmm6, SHIFT_INV_COL);
r_xmm7 = r_xmm1;
r_xmm1 = _mm_adds_epi16(r_xmm1, r_xmm0);
// Store results for row 1
//_mm_store_si128((__m128i *) (&pOutput[1*8]), r_xmm6);
__m128i r1 = r_xmm6;
r_xmm1 = _mm_srai_epi16(r_xmm1, SHIFT_INV_COL);
r_xmm6 = temp3;
r_xmm7 = _mm_subs_epi16(r_xmm7, r_xmm0);
r_xmm7 = _mm_srai_epi16(r_xmm7, SHIFT_INV_COL);
// Store results for row 2
//_mm_store_si128((__m128i *) (&pOutput[2*8]), r_xmm1);
__m128i r2 = r_xmm1;
r_xmm5 = _mm_subs_epi16(r_xmm5, temp7);
r_xmm5 = _mm_srai_epi16(r_xmm5, SHIFT_INV_COL);
// Store results for row 7
//_mm_store_si128((__m128i *) (&pOutput[7*8]), r_xmm5);
__m128i r7 = r_xmm5;
r_xmm3 = _mm_subs_epi16(r_xmm3, r_xmm4);
r_xmm6 = _mm_adds_epi16(r_xmm6, r_xmm2);
r_xmm2 = _mm_subs_epi16(r_xmm2, temp3);
r_xmm6 = _mm_srai_epi16(r_xmm6, SHIFT_INV_COL);
r_xmm2 = _mm_srai_epi16(r_xmm2, SHIFT_INV_COL);
// Store results for row 3
//_mm_store_si128((__m128i *) (&pOutput[3*8]), r_xmm6);
__m128i r3 = r_xmm6;
r_xmm3 = _mm_srai_epi16(r_xmm3, SHIFT_INV_COL);
// Store results for rows 4, 5, and 6
//_mm_store_si128((__m128i *) (&pOutput[4*8]), r_xmm2);
//_mm_store_si128((__m128i *) (&pOutput[5*8]), r_xmm7);
//_mm_store_si128((__m128i *) (&pOutput[6*8]), r_xmm3);
__m128i r4 = r_xmm2;
__m128i r5 = r_xmm7;
__m128i r6 = r_xmm3;
r0 = _mm_add_epi16(*(const __m128i *)shortM128_128, r0);
r1 = _mm_add_epi16(*(const __m128i *)shortM128_128, r1);
r2 = _mm_add_epi16(*(const __m128i *)shortM128_128, r2);
r3 = _mm_add_epi16(*(const __m128i *)shortM128_128, r3);
r4 = _mm_add_epi16(*(const __m128i *)shortM128_128, r4);
r5 = _mm_add_epi16(*(const __m128i *)shortM128_128, r5);
r6 = _mm_add_epi16(*(const __m128i *)shortM128_128, r6);
r7 = _mm_add_epi16(*(const __m128i *)shortM128_128, r7);
((__m128i *)pOutputUB)[0] = _mm_packus_epi16(r0, r1);
((__m128i *)pOutputUB)[1] = _mm_packus_epi16(r2, r3);
((__m128i *)pOutputUB)[2] = _mm_packus_epi16(r4, r5);
((__m128i *)pOutputUB)[3] = _mm_packus_epi16(r6, r7);
}

186
include/renderd7/external/jpge.h vendored Normal file
View File

@ -0,0 +1,186 @@
// jpge.h - C++ class for JPEG compression.
// Public Domain or Apache 2.0, Richard Geldreich <richgel99@gmail.com>
// Alex Evans: Added RGBA support, linear memory allocator.
#ifndef JPEG_ENCODER_H
#define JPEG_ENCODER_H
namespace jpge {
typedef unsigned char uint8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned int uint;
// JPEG chroma subsampling factors. Y_ONLY (grayscale images) and H2V2 (color
// images) are the most common.
enum subsampling_t { Y_ONLY = 0, H1V1 = 1, H2V1 = 2, H2V2 = 3 };
// JPEG compression parameters structure.
struct params {
inline params()
: m_quality(85), m_subsampling(H2V2), m_no_chroma_discrim_flag(false),
m_two_pass_flag(false), m_use_std_tables(false) {}
inline bool check() const {
if ((m_quality < 1) || (m_quality > 100))
return false;
if ((uint)m_subsampling > (uint)H2V2)
return false;
return true;
}
// Quality: 1-100, higher is better. Typical values are around 50-95.
int m_quality;
// m_subsampling:
// 0 = Y (grayscale) only
// 1 = YCbCr, no subsampling (H1V1, YCbCr 1x1x1, 3 blocks per MCU)
// 2 = YCbCr, H2V1 subsampling (YCbCr 2x1x1, 4 blocks per MCU)
// 3 = YCbCr, H2V2 subsampling (YCbCr 4x1x1, 6 blocks per MCU-- very common)
subsampling_t m_subsampling;
// Disables CbCr discrimination - only intended for testing.
// If true, the Y quantization table is also used for the CbCr channels.
bool m_no_chroma_discrim_flag;
bool m_two_pass_flag;
// By default we use the same quantization tables as mozjpeg's default.
// Set to true to use the traditional tables from JPEG Annex K.
bool m_use_std_tables;
};
// Writes JPEG image to a file.
// num_channels must be 1 (Y) or 3 (RGB), image pitch must be
// width*num_channels.
bool compress_image_to_jpeg_file(const char *pFilename, int width, int height,
int num_channels, const uint8 *pImage_data,
const params &comp_params = params());
// Writes JPEG image to memory buffer.
// On entry, buf_size is the size of the output buffer pointed at by pBuf, which
// should be at least ~1024 bytes. If return value is true, buf_size will be set
// to the size of the compressed data.
bool compress_image_to_jpeg_file_in_memory(
void *pBuf, int &buf_size, int width, int height, int num_channels,
const uint8 *pImage_data, const params &comp_params = params());
// Output stream abstract class - used by the jpeg_encoder class to write to the
// output stream. put_buf() is generally called with len==JPGE_OUT_BUF_SIZE
// bytes, but for headers it'll be called with smaller amounts.
class output_stream {
public:
virtual ~output_stream(){};
virtual bool put_buf(const void *Pbuf, int len) = 0;
template <class T> inline bool put_obj(const T &obj) {
return put_buf(&obj, sizeof(T));
}
};
// Lower level jpeg_encoder class - useful if more control is needed than the
// above helper functions.
class jpeg_encoder {
public:
jpeg_encoder();
~jpeg_encoder();
// Initializes the compressor.
// pStream: The stream object to use for writing compressed data.
// params - Compression parameters structure, defined above.
// width, height - Image dimensions.
// channels - May be 1, or 3. 1 indicates grayscale, 3 indicates RGB source
// data. Returns false on out of memory or if a stream write fails.
bool init(output_stream *pStream, int width, int height, int src_channels,
const params &comp_params = params());
const params &get_params() const { return m_params; }
// Deinitializes the compressor, freeing any allocated memory. May be called
// at any time.
void deinit();
uint get_total_passes() const { return m_params.m_two_pass_flag ? 2 : 1; }
inline uint get_cur_pass() { return m_pass_num; }
// Call this method with each source scanline.
// width * src_channels bytes per scanline is expected (RGB or Y format).
// You must call with NULL after all scanlines are processed to finish
// compression. Returns false on out of memory or if a stream write fails.
bool process_scanline(const void *pScanline);
private:
jpeg_encoder(const jpeg_encoder &);
jpeg_encoder &operator=(const jpeg_encoder &);
typedef int32 sample_array_t;
output_stream *m_pStream;
params m_params;
uint8 m_num_components;
uint8 m_comp_h_samp[3], m_comp_v_samp[3];
int m_image_x, m_image_y, m_image_bpp, m_image_bpl;
int m_image_x_mcu, m_image_y_mcu;
int m_image_bpl_xlt, m_image_bpl_mcu;
int m_mcus_per_row;
int m_mcu_x, m_mcu_y;
uint8 *m_mcu_lines[16];
uint8 m_mcu_y_ofs;
sample_array_t m_sample_array[64];
int16 m_coefficient_array[64];
int32 m_quantization_tables[2][64];
uint m_huff_codes[4][256];
uint8 m_huff_code_sizes[4][256];
uint8 m_huff_bits[4][17];
uint8 m_huff_val[4][256];
uint32 m_huff_count[4][256];
int m_last_dc_val[3];
enum { JPGE_OUT_BUF_SIZE = 2048 };
uint8 m_out_buf[JPGE_OUT_BUF_SIZE];
uint8 *m_pOut_buf;
uint m_out_buf_left;
uint32 m_bit_buffer;
uint m_bits_in;
uint8 m_pass_num;
bool m_all_stream_writes_succeeded;
void optimize_huffman_table(int table_num, int table_len);
void emit_byte(uint8 i);
void emit_word(uint i);
void emit_marker(int marker);
void emit_jfif_app0();
void emit_dqt();
void emit_sof();
void emit_dht(uint8 *bits, uint8 *val, int index, bool ac_flag);
void emit_dhts();
void emit_sos();
void emit_markers();
void compute_huffman_table(uint *codes, uint8 *code_sizes, uint8 *bits,
uint8 *val);
void compute_quant_table(int32 *dst, int16 *src);
void adjust_quant_table(int32 *dst, int32 *src);
void first_pass_init();
bool second_pass_init();
bool jpg_open(int p_x_res, int p_y_res, int src_channels);
void load_block_8_8_grey(int x);
void load_block_8_8(int x, int y, int c);
void load_block_16_8(int x, int c);
void load_block_16_8_8(int x, int c);
void load_quantized_coefficients(int component_num);
void flush_output_buffer();
void put_bits(uint bits, uint len);
void code_coefficients_pass_one(int component_num);
void code_coefficients_pass_two(int component_num);
void code_block(int component_num);
void process_mcu_row();
bool terminate_pass_one();
bool terminate_pass_two();
bool process_end_of_image();
void load_mcu(const void *src);
void clear();
void init();
};
} // namespace jpge
#endif // JPEG_ENCODER

View File

@ -1,250 +0,0 @@
/*
* Copyright 2006 Richard Wilson <richard.wilson@netsurf-browser.org>
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
*
* This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
/**
* \file
* Bitmap file decoding interface.
*/
#ifndef libnsbmp_h_
#define libnsbmp_h_
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/* bmp flags */
#define BMP_NEW 0
/** image is opaque (as opposed to having an alpha mask) */
#define BMP_OPAQUE (1 << 0)
/** memory should be wiped */
#define BMP_CLEAR_MEMORY (1 << 1)
/**
* error return values
*/
typedef enum {
BMP_OK = 0,
BMP_INSUFFICIENT_MEMORY = 1,
BMP_INSUFFICIENT_DATA = 2,
BMP_DATA_ERROR = 3
} bmp_result;
/**
* encoding types
*/
typedef enum {
BMP_ENCODING_RGB = 0,
BMP_ENCODING_RLE8 = 1,
BMP_ENCODING_RLE4 = 2,
BMP_ENCODING_BITFIELDS = 3
} bmp_encoding;
/* API for Bitmap callbacks */
typedef void* (*bmp_bitmap_cb_create)(int width, int height, unsigned int state);
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char* (*bmp_bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
/**
* The Bitmap callbacks function table
*/
typedef struct bmp_bitmap_callback_vt_s {
/** Callback to allocate bitmap storage. */
bmp_bitmap_cb_create bitmap_create;
/** Called to free bitmap storage. */
bmp_bitmap_cb_destroy bitmap_destroy;
/** Return a pointer to the pixel data in a bitmap. */
bmp_bitmap_cb_get_buffer bitmap_get_buffer;
/** Find the width of a pixel row in bytes. */
bmp_bitmap_cb_get_bpp bitmap_get_bpp;
} bmp_bitmap_callback_vt;
/**
* bitmap image
*/
typedef struct bmp_image {
/** callbacks for bitmap functions */
bmp_bitmap_callback_vt bitmap_callbacks;
/** pointer to BMP data */
uint8_t *bmp_data;
/** width of BMP (valid after _analyse) */
uint32_t width;
/** heigth of BMP (valid after _analyse) */
uint32_t height;
/** whether the image has been decoded */
bool decoded;
/** decoded image */
void *bitmap;
/* Internal members are listed below */
/** total number of bytes of BMP data available */
uint32_t buffer_size;
/** pixel encoding type */
bmp_encoding encoding;
/** offset of bitmap data */
uint32_t bitmap_offset;
/** bits per pixel */
uint16_t bpp;
/** number of colours */
uint32_t colours;
/** colour table */
uint32_t *colour_table;
/** whether to use bmp's limited transparency */
bool limited_trans;
/** colour to display for "transparent" pixels when using limited
* transparency
*/
uint32_t trans_colour;
/** scanlines are top to bottom */
bool reversed;
/** image is part of an ICO, mask follows */
bool ico;
/** true if the bitmap does not contain an alpha channel */
bool opaque;
/** four bitwise mask */
uint32_t mask[4];
/** four bitwise shifts */
int32_t shift[4];
/** colour representing "transparency" in the bitmap */
uint32_t transparent_index;
} bmp_image;
typedef struct ico_image {
bmp_image bmp;
struct ico_image *next;
} ico_image;
/**
* icon image collection
*/
typedef struct ico_collection {
/** callbacks for bitmap functions */
bmp_bitmap_callback_vt bitmap_callbacks;
/** width of largest BMP */
uint16_t width;
/** heigth of largest BMP */
uint16_t height;
/* Internal members are listed below */
/** pointer to ICO data */
uint8_t *ico_data;
/** total number of bytes of ICO data available */
uint32_t buffer_size;
/** root of linked list of images */
ico_image *first;
} ico_collection;
/**
* Initialises bitmap ready for analysing the bitmap.
*
* \param bmp The Bitmap to initialise
* \param callbacks The callbacks the library will call on operations.
* \return BMP_OK on success or appropriate error code.
*/
bmp_result bmp_create(bmp_image *bmp, bmp_bitmap_callback_vt *callbacks);
/**
* Initialises icon ready for analysing the icon
*
* \param bmp The Bitmap to initialise
* \param callbacks The callbacks the library will call on operations.
* \return BMP_OK on success or appropriate error code.
*/
bmp_result ico_collection_create(ico_collection *ico,
bmp_bitmap_callback_vt *callbacks);
/**
* Analyse a BMP prior to decoding.
*
* This will scan the data provided and perform checks to ensure the data is a
* valid BMP and prepare the bitmap image structure ready for decode.
*
* This function must be called and resturn BMP_OK before bmp_decode() as it
* prepares the bmp internal state for the decode process.
*
* \param bmp the BMP image to analyse.
* \param size The size of data in cdata.
* \param data The bitmap source data.
* \return BMP_OK on success or error code on faliure.
*/
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data);
/**
* Analyse an ICO prior to decoding.
*
* This function will scan the data provided and perform checks to ensure the
* data is a valid ICO.
*
* This function must be called before ico_find().
*
* \param ico the ICO image to analyse
* \param size The size of data in cdata.
* \param data The bitmap source data.
* \return BMP_OK on success
*/
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data);
/**
* Decode a BMP
*
* This function decodes the BMP data such that bmp->bitmap is a valid
* image. The state of bmp->decoded is set to TRUE on exit such that it
* can easily be identified which BMPs are in a fully decoded state.
*
* \param bmp the BMP image to decode
* \return BMP_OK on success
*/
bmp_result bmp_decode(bmp_image *bmp);
/**
* Decode a BMP using "limited transparency"
*
* Bitmaps do not have native transparency support. However, there is a
* "trick" that is used in some instances in which the first pixel of the
* bitmap becomes the "transparency index". The decoding application can
* replace this index with whatever background colour it chooses to
* create the illusion of transparency.
*
* When to use transparency is at the discretion of the decoding
* application.
*
* \param bmp the BMP image to decode
* \param colour the colour to use as "transparent"
* \return BMP_OK on success
*/
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t transparent_colour);
/**
* Finds the closest BMP within an ICO collection
*
* This function finds the BMP with dimensions as close to a specified set
* as possible from the images in the collection.
*
* \param ico the ICO collection to examine
* \param width the preferred width (0 to use ICO header width)
* \param height the preferred height (0 to use ICO header height)
*/
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height);
/**
* Finalise a BMP prior to destruction.
*
* \param bmp the BMP image to finalise.
*/
void bmp_finalise(bmp_image *bmp);
/**
* Finalise an ICO prior to destruction.
*
* \param ico the ICO image to finalise,
*/
void ico_finalise(ico_collection *ico);
#endif

View File

@ -1,27 +0,0 @@
/*
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
#include <stdio.h>
#ifndef _LIBNSBMP_LOG_H_
#define _LIBNSBMP_LOG_H_
#ifdef NDEBUG
# define LOG(x) ((void) 0)
#else
# ifdef __GNUC__
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
# elif defined(__CC_NORCROFT)
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
# else
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
# endif
#endif
#endif

File diff suppressed because it is too large Load Diff

222
include/renderd7/external/nvid.hpp vendored Normal file
View File

@ -0,0 +1,222 @@
#pragma once
#include <cstdint>
#include <fstream>
#include <iostream>
#include <memory.h>
#include <memory>
#include <renderd7/external/jpgd.h>
#include <renderd7/external/jpge.h>
#include <sstream>
#include <vector>
struct NVID_Header {
char magic[4]; // Magic
int framerate; // Only Up to 60
int width; // Width
int height; // Height
uint32_t framecount; // Count of Frames
};
struct NVID_Frame {
char magic[4]; // Magic
uint32_t framesize; // Size of Frame
};
struct NVID_Image {
int framenum; // Register of Frame
int w; // Width of Frame
int h; // Height of Frame
int bpp; // bpp of Frame
void *pBuf; // Buffer
};
inline void CreateHeader(NVID_Header &header) {
header.magic[0] = 'N';
header.magic[1] = 'V';
header.magic[2] = 'I';
header.magic[3] = 'D';
}
inline void CreateFrame(NVID_Frame &frame) {
frame.magic[0] = 'N';
frame.magic[1] = 'F';
frame.magic[2] = 'R';
frame.magic[3] = 'M';
}
inline bool CheckHeader(NVID_Header &header) {
if (header.magic[0] == 'N' && header.magic[1] == 'V' &&
header.magic[2] == 'I' && header.magic[3] == 'D')
return true;
return false;
}
inline bool CheckFrame(NVID_Frame &frame) {
if (frame.magic[0] == 'N' && frame.magic[1] == 'F' && frame.magic[2] == 'R' &&
frame.magic[3] == 'M')
return true;
return false;
}
inline std::vector<std::unique_ptr<NVID_Image>>
LoadNVID(const std::string &path) {
std::vector<std::unique_ptr<NVID_Image>> res;
std::ifstream nvid_file(path, std::ios::binary | std::ios::in);
if (!nvid_file) {
std::cerr << "Failed to open NVID file: " << path << std::endl;
return res;
}
NVID_Header header;
nvid_file.read(reinterpret_cast<char *>(&header), sizeof(header));
if (!CheckHeader(header)) {
std::cerr << "Invalid NVID header" << std::endl;
return res;
}
for (int i = 0; i < (int)header.framecount; i++) {
NVID_Frame frame;
nvid_file.read(reinterpret_cast<char *>(&frame), sizeof(frame));
if (!CheckFrame(frame)) {
std::cerr << "Invalid NVID frame" << std::endl;
return res;
}
std::vector<uint8_t> compressed_data(frame.framesize);
nvid_file.read(reinterpret_cast<char *>(compressed_data.data()),
compressed_data.size());
int width, height, components;
unsigned char *decompressed_data = jpgd::decompress_jpeg_image_from_memory(
compressed_data.data(), compressed_data.size(), &width, &height,
&components, 3);
if (!decompressed_data) {
std::cerr << "Failed to decompress JPEG data" << std::endl;
return res;
}
auto image = std::make_unique<NVID_Image>();
image->bpp = components;
image->w = width;
image->h = height;
image->framenum = i;
image->pBuf = decompressed_data;
res.push_back(std::move(image));
}
return res;
}
inline std::vector<std::unique_ptr<NVID_Image>> LoadMemNVID(const void *data,
size_t size) {
std::vector<std::unique_ptr<NVID_Image>> res;
std::istringstream nvid_stream(
std::string(reinterpret_cast<const char *>(data), size));
NVID_Header header;
nvid_stream.read(reinterpret_cast<char *>(&header), sizeof(header));
if (!CheckHeader(header)) {
std::cerr << "Invalid NVID header" << std::endl;
return res;
}
for (int i = 0; i < (int)header.framecount; i++) {
NVID_Frame frame;
nvid_stream.read(reinterpret_cast<char *>(&frame), sizeof(frame));
if (!CheckFrame(frame)) {
std::cerr << "Invalid NVID frame" << std::endl;
return res;
}
std::vector<uint8_t> compressed_data(frame.framesize);
nvid_stream.read(reinterpret_cast<char *>(compressed_data.data()),
compressed_data.size());
int width, height, components;
unsigned char *decompressed_data = jpgd::decompress_jpeg_image_from_memory(
compressed_data.data(), compressed_data.size(), &width, &height,
&components, 3);
if (!decompressed_data) {
std::cerr << "Failed to decompress JPEG data" << std::endl;
return res;
}
auto image = std::make_unique<NVID_Image>();
image->bpp = components;
image->w = width;
image->h = height;
image->framenum = i;
image->pBuf = decompressed_data;
res.push_back(std::move(image));
}
return res;
}
class NVID_Stream {
public:
NVID_Stream(const std::string &path)
: file_(path, std::ios::binary | std::ios::in) {
if (!file_) {
std::cout << "Failed to open NVID file: " << path << std::endl;
return;
} else {
file_.read(reinterpret_cast<char *>(&header_), sizeof(header_));
if (!CheckHeader(header_)) {
std::cout << "Invalid NVID header" << std::endl;
return;
}
}
}
NVID_Stream(const void *data, std::size_t size) {
if (!data || size < sizeof(header_)) {
std::cout << "Invalid NVID data" << std::endl;
return;
} else {
memcpy(&header_, data, sizeof(header_));
if (!CheckHeader(header_)) {
std::cout << "Invalid NVID header" << std::endl;
return;
}
}
}
~NVID_Stream() { file_.close(); }
bool ReadNext(NVID_Image &image) {
if (!file_) {
return false;
}
NVID_Frame frame;
file_.read(reinterpret_cast<char *>(&frame), sizeof(frame));
if (!CheckFrame(frame)) {
std::cout << "Invalid NVID frame" << std::endl;
return false;
}
std::vector<uint8_t> compressed_data(frame.framesize);
file_.read(reinterpret_cast<char *>(compressed_data.data()),
compressed_data.size());
int width, height, components;
unsigned char *decompressed_data = jpgd::decompress_jpeg_image_from_memory(
compressed_data.data(), compressed_data.size(), &width, &height,
&components, 3);
if (!decompressed_data) {
std::cout << "Failed to decompress JPEG data" << std::endl;
return false;
}
image.bpp = components;
image.w = width;
image.h = height;
image.framenum = current_frame_++;
image.pBuf = decompressed_data;
return true;
}
private:
std::ifstream file_;
NVID_Header header_;
int current_frame_ = 0;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,14 +2,17 @@
#include <renderd7/external/json.hpp>
#include <string>
/// RenderD7::Lang
namespace RenderD7::Lang {
/// Get the 3ds System Language
namespace RenderD7 {
namespace Lang {
/// @brief Get 3ds System lang! [en] by default
/// @return Sytemlang as string
std::string getSys();
/// Get a translated string
/// \param key The Key so the code can find your string
/// @brief Get The Translation String
/// @param key Key of Translation
/// @return The Translated String
std::string get(const std::string &key);
/// Load the lang file from dir structure en/app.json for sample
/// \param lang the folder name en, fr, de ... . I prefer geSys()
/// @brief Load A Language json
/// @param lang The Language Key [en], [de], etc, or getSys()
void load(const std::string &lang);
} // namespace RenderD7::Lang
} // namespace Lang
} // namespace RenderD7

View File

@ -5,23 +5,26 @@
#include <time.h>
#include <unistd.h>
/** Log Class */
/// @brief Log Class
class Log {
public:
/** Construct */
/// @brief Constructor
Log();
/** Deconstruct */
/// @brief Deconstructor
~Log();
/// Init the log file
/// \param filename name for the file
/// @brief Init the Logger
/// @param filename Filename[_data_time.log]
void Init(const char *filename);
/// Write Text to logfile
/// \param debug_text your text
/// @brief Write a String to the File
/// @param debug_text string
void Write(std::string debug_text);
/// Get the date
/// @brief Get the Date
/// @return Date as string fmt[data_time]
std::string logDate(void);
/// Format to logstyle
/// \param fmt_str the formatted style
/// @brief Format a string like sprintf
/// @param fmt_str the string wich defines the fmt
/// @param ... Additional Data
/// @return Formatted String
std::string format(const std::string &fmt_str, ...);
private:

View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char npi_intro[];
extern size_t npi_intro_size;

View File

@ -20,7 +20,6 @@
#include <unistd.h>
#include <vector>
#include <codecvt>
#include <renderd7/BitmapPrinter.hpp>
@ -28,10 +27,12 @@
#include <renderd7/Draw.hpp>
#include <renderd7/Image.hpp>
#include <renderd7/Ovl.hpp>
#include <renderd7/ResultDecoder.hpp>
#include <renderd7/Screen.hpp>
#include <renderd7/Sheet.hpp>
#include <renderd7/Sprite.hpp>
#include <renderd7/SpriteAnimation.hpp>
#include <renderd7/Tasks.hpp>
#include <renderd7/Time.hpp>
#include <renderd7/Toast.hpp>
#include <renderd7/bmp.hpp>
@ -43,240 +44,387 @@
#include <renderd7/stringtool.hpp>
#include <renderd7/thread.hpp>
extern "C" {
#include <renderd7/external/fs.h>
}
#define RENDERD7VSTRING "0.8.0"
#define RENDERD7VSTRING "0.9.3"
#define CHANGELOG \
"0.8.0: Implement BitmapPrinter\n0.7.3: Implement Over Render Overlay " \
"Framework\n0.7.2: Implement MT to csv file saving. Add RGB2HEX. \n0.7.1: " \
"Add the New Overlay Handler. Its Just in code and does nothing yet. " \
"\n0.7.0: Made Big Progress In the MT Ovl but it still crashes On a Scnd " \
"C3D_FrameEnd(). Implement 800px but doesn't work that good. \n0.6.2: Fix " \
"Crash when exiting trouth Home Menu. \n0.6.10: rewrite Threadsystem, " \
"Improve framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left " \
"Function.\nadd changelog\n0.6.01: add Threading system."
"0.9.3: Completly Documanted Everything\nFix typo in " \
"Sprite::getHeight()\nRemove Deprecated/Useless Stuff\n0.9.2: Add " \
"NpiSplashVideo\nNvid Support(v0.0.1)\nAdd " \
"Basic RenderD7 " \
"Splash\nFaster Graphics Init\nFade Effects\nFix Screen for this " \
"Changelog\n0.9.1: Fix Critical bug in\nSpritesheet animations\nFix " \
"Color " \
"Conver(Hex)\n0.9.0: Remove Stupid try of Console\nAdd Services list and " \
"Clean up " \
"Code.\nAlso added Minimal Init for hax2.x\n0.8.5: Fix Deltatime \n0.8.4: " \
"A lot of Fixes and new\nFeatures for BitmapPrinter! \n0.8.3: Addet " \
"Overlaycount to Info\nand Addet ResultDecoder for errors.\n0.8.2: Fix a " \
"lot of Stuff and\nadd c++17 based filesystem class.\n0.8.1: Add abillity " \
"to Get Stdout as string\nto render it to the screen.\n0.8.0: Implement " \
"BitmapPrinter\n0.7.3: Implement Over\nRender Overlay Framework\n0.7.2: " \
"Implement MT to csv file\nsaving.(removed) Add RGB2HEX.\n0.7.1: Add the " \
"New Overlay Handler. Its\nJust in code and does nothing yet.\n0.7.0: Made " \
"Big Progress In the MT\nOvl but it still crashes On\na Scnd " \
"C3D_FrameEnd()." \
"\nImplement 800px but\ndoesn't work that good. \n0.6.2: Fix Crash when " \
"exiting\ntrouth Home Menu.\n0.6.10: rewrite Threadsystem,\nImprove " \
"framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left " \
"Function\n(Right since 0.7.0).\nadd changelog\n0.6.01: add Threading " \
"system.\n0.6.0: Better " \
"Scene Management\n0.5.0: Fixed some Bugs!\n0.4.0: Trying to fix " \
"Filesystem and Bugs!\n0.3.0: Recreate D7-Core into RenderD7!\n0.2.0: " \
"Trying to create Animations of\nImages instead of Sheets!\n0.1.0: Initial " \
"Release of\nD7-Core sprite animation plugin!"
#define DEFAULT_CENTER 0.5f
/*extern C3D_RenderTarget* Top;
extern C3D_RenderTarget* TopRight;
extern C3D_RenderTarget* Bottom;*/
/// @param d7_hDown Current Key Down
extern u32 d7_hDown;
/// @param d7_hHeld Current Key Held
extern u32 d7_hHeld;
/// @param d7_hUp Current Key Up
extern u32 d7_hUp;
/// @param d7_touch Current Touch Position
extern touchPosition d7_touch;
/// @param dspststus Dsp Status String
extern std::string dspststus;
/// @param rd7_do_splash Config Value To Enable RenderD7 Splash
extern bool rd7_do_splash;
/// RenderD7
namespace RenderD7 {
/// @brief Get Deltatime
/// @return Deltatime
float GetDeltaTime();
enum kbd { SWKBD, BKBD };
enum kbd_type { NUMPAD, STANDARD };
struct TObject {
int x; // Position X
int y; // Position Y
int w; // Button Width
int h; // Button Height
std::string text = ""; // Text
float correctx = 0; // Correct X Position
float correcty = 0; // Correct Y Position
float txtsize = 0.7f; // Set Text Size
/// @brief Keyboard
enum kbd {
/// @brief libctru Keyboard
SWKBD,
/// @brief Unk (Not Usable)
BKBD
};
/// @brief Keyboar Type
enum kbd_type { NUMPAD, STANDARD };
/// @brief A Button
struct TObject {
int x; ///< Position X
int y; ///< Position Y
int w; ///< Button Width
int h; ///< Button Height
std::string text = ""; ///< Text
float correctx = 0; ///< Correct X Position
float correcty = 0; ///< Correct Y Position
float txtsize = 0.7f; ///< Set Text Size
};
/// @brief Scene Class
class Scene {
public:
/// @brief Stack of the Scenes
static std::stack<std::unique_ptr<Scene>> scenes;
/// @brief Deconstructor
virtual ~Scene() {}
/// @brief Logic To Overide
/// @param hDown Key Down
/// @param hHeld Key Held
/// @param hUp Key Up
/// @param touch Touch Position
virtual void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) = 0;
/// @brief Draw Func to Override
virtual void Draw() const = 0;
// virtual void Ovl() const = 0;
/// @brief Push a Scene to Stack
/// @param scene Scene to Push
/// @param fade FadeEffect (Not Correctly Implementet yet)
static void Load(std::unique_ptr<Scene> scene, bool fade = false);
/// @brief Go Back a Scene
static void Back();
/// @brief do the Draw (Called in RenderD7::MainLoop())
static void doDraw();
/// @brief do the Logic (Called in RenderD7::MainLoop())
/// @param hDown Key Down
/// @param hHeld Key Held
/// @param hUp Key Up
/// @param touch Touch Positon
static void doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch);
// static void HandleOvl();
};
/// @brief Integrated Setting Menu of RenderD7
class RSettings : public RenderD7::Scene {
private:
enum RState { RSETTINGS, RINFO };
/// @brief Calculate the Changelog Screen Stuff
/// @param lines vector of Lines
/// @param screen_index Current Screen
/// @param screens Count of Possible Screens
void calculate_screens(const std::vector<std::string> &lines,
int &screen_index, int &screens);
/// @brief State (Define for Menus)
enum RState { RSETTINGS, RINFO, RSERVICES, RCLOG };
/// @param m_state Current menu State (Default=MainMenu aka RSETTINGS)
RenderD7::RSettings::RState m_state = RenderD7::RSettings::RState::RSETTINGS;
std::string rd7srstate = "false";
std::string csvstate = "false";
std::string mtovlstate = "false";
std::string fpsstate = "60";
std::string mtscreenstate = "Top";
std::string mttxtcolstate = "#ffffff";
std::string mtcola = "255";
std::string mttxtcola = "255";
/// @param screens Count of Changelog Screens
int screens = 0;
/// @param screen_index Current Changelog Screen
int screen_index = 0;
/// @param lines Vector of Changelog-Lines
std::vector<std::string> lines;
/// @param rd7srstate State of RenderD7 Super Reselution
std::string rd7srstate = "false";
/// @param mtovlstate State of Metricks Overlay
std::string mtovlstate = "false";
/// @param fpsstate Value of Forced Framerate
std::string fpsstate = "60";
/// @param mtscreenstate Screen the Overlay is Set to
std::string mtscreenstate = "Top";
/// @param buttons Vector of Buttons
std::vector<RenderD7::TObject> buttons = {
{20, 35, 120, 35, "RD7SR", -11, 10},
{20, 85, 120, 35, "MT_CSV", -15, 9},
{20, 135, 120, 35, "MT_OVL", -19, 10},
{20, 185, 120, 35, "FPS", 6, 10},
{180, 35, 120, 35, "MTSCREEN", -29, 10},
{180, 85, 120, 35, "DSPERR", -13, 10},
{20, 35, 120, 35, "RD7SR", -8, 10},
{20, 85, 120, 35, "Changelog", -24, 11},
{20, 135, 120, 35, "Metrik-Ovl", -23, 10},
{20, 185, 120, 35, "NOTYET", -13, 10},
{180, 35, 120, 35, "MTSCREEN", -27, 10},
{180, 85, 120, 35, "NOTYET", -13, 10},
{180, 135, 120, 35, "INFO", 2, 10},
{180, 185, 120, 35, "", -13, 10}};
{180, 185, 120, 35, "Services", -13, 10}};
public:
/// @brief Constructor
RSettings();
/// @brief Override for Draw
/// @param
void Draw(void) const override;
/// @brief Deconstructor
~RSettings();
/// @brief Override for Logic
/// @param hDown Key Down
/// @param hHeld Key Held
/// @param hUp Key Up
/// @param touch Touch Position
void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) override;
};
/// @brief Show Up the RenderD7-Settings Menu
void LoadSettings();
/// @brief DspNotFound Error Toast (Deprectated)
class DSP_NF : public RenderD7::Ovl {
public:
/// @brief Constructor
DSP_NF();
/// @brief Override for Draw
void Draw(void) const override;
/// @brief Override for Logic
void Logic() override;
private:
/// @param msgposy Y Position of Toast
int msgposy = 240;
/// @param delay Delay of Toast
int delay = 0;
};
/// @brief Get A Rendom Int
/// @param b From
/// @param e To
/// @return Random Int
int GetRandomInt(int b, int e);
/// @brief DrawMetrikOvl (YOUR OWN RISK)
void DrawMetrikOvl();
/// @brief Draw Image from RenderD7 Sheet
/// @param sheet Spritesheet
/// @param index Image index Value
/// @param x Pos X
/// @param y Pos Y
/// @param scaleX Scale on X-Axis
/// @param scaleY Scale on Y-Axis
/// @return success ?
bool DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x, float y,
float scaleX = 1.0, float scaleY = 1.0);
/// @brief Display the Npi-D7 Video Intro (NVID)
void DoNpiIntro();
/// @brief Fade In
/// @param duration Duration in Frames
void FadeIn();
/// @brief Fade Out
/// @param duration Duration in Frames
void FadeOut();
/// @brief Display Fade Effects
void FadeDisplay();
namespace Error {
/// @brief DEPRECATED Display Error for n Seconds
/// @param toptext Head Text
/// @param errortext Error Text
/// @param timesec Time n to Display in Seconds
void DisplayError(std::string toptext, std::string errortext, int timesec = 3);
/// @brief Display A Fatal Error
/// @param toptext Head Text
/// @param errortext Error Text
void DisplayFatalError(std::string toptext, std::string errortext);
} // namespace Error
namespace Init {
/// @brief Init Default RenderD7
/// @param app_name Name of Your App
/// @return ResCode
Result Main(std::string app_name = "RD7Game");
/// @brief Init Minimal RenderD7 (For better Hax2.x support)
/// @param app_name Name of Your App
/// @return ResCode
Result Minimal(std::string app_name = "RD7Game");
/// @brief Reload the Graphics Engine
/// @return ResCode
Result Reload();
/// @brief Init Graphics Only (NOT SUPPORTET use Reload)
void Graphics();
void NdspFirm(bool useit = false);
} // namespace Init
namespace Exit {
void Main();
/// @brief Init Ndsp for Sounds
void NdspFirm();
} // namespace Init
namespace Exit {
/// @brief Exit Default RenderD7
void Main();
/// @brief Exit Minimal RenderD7
void Minimal();
/// @brief Exit Ndsp
void NdspFirm();
/// @brief DEPRECATED Exit Graphics
void Graphics();
} // namespace Exit
namespace Msg {
/// @brief Display A Message
/// @param titletxt Header Text
/// @param subtext Message Text
/// @param target Screen
void Display(std::string titletxt, std::string subtext,
C3D_RenderTarget *target);
/// @brief Display A Message Wit Progress
/// @param titletext Header Text
/// @param subtext Message Text
/// @param current Current Progress
/// @param total Total Progress
/// @param prgbarcolor Color of Progressbar
void DisplayWithProgress(std::string titletext, std::string subtext,
float current, float total, u32 prgbarcolor);
} // namespace Msg
namespace Convert {
/// @brief Convert a String to Flaot
/// @param inp Input String
/// @return Float
inline float StringtoFloat(std::string inp) { return std::atof(inp.c_str()); }
/// @brief Convert String to Int
/// @param inp Input String
/// @return Int
inline int StringtoInt(std::string inp) { return std::atoi(inp.c_str()); }
inline bool FloatToBool(float inp) {
if (inp == 1)
return true;
else
return false;
}
/// @brief Convert a Float to Bool
/// @param inp Input Float
/// @return Bool
inline bool FloatToBool(float inp) { return (inp == 1 ? true : false); }
} // namespace Convert
/// @brief DEPRECATED DirContent
struct DirContent {
std::string name;
std::string path;
bool isDir;
std::string name; ///< Content Name
std::string path; ///< Content Path
bool isDir; ///< Is Directory
};
namespace FS {
/// @brief Check if File exists
/// @param path Path to the File
/// @return exists or not
bool FileExist(const std::string &path);
}
} // namespace FS
/// @brief Check if Ndsp is Init
/// @return is or not
bool IsNdspInit();
/// @brief Setup RenderD7 Logs
void SetupLog(void);
/// @brief Get Current Framerate as String
/// @return Framerate String
std::string GetFramerate();
/// @brief MainLoop of RenderD7s
/// @return Is Still Running or not
bool MainLoop();
/// @brief Exit App (brak the MainLoop)
void ExitApp();
/// @brief Clear the Citro2D TextBuffers
/// @param
void ClearTextBufs(void);
/// @brief Open A Keyboard (SWKBD)
/// @param lenght Length of the string
/// @param tp Type of The Keyboard
/// @return the string if pressed Ok
std::string Kbd(int lenght, SwkbdType tp);
/// @brief Draw Overlays And end the Frame. DO NEVER USE C3D_FRAMEEND cause it
/// breaks Overlay crash Security
void FrameEnd();
/// @brief Enable/Disable RenderD7 Super Reselution
void ToggleRD7SR();
/// @brief Check if RD7SR is Enabled
/// @return is or not
bool IsRD7SR();
/// @brief Textless Button
struct TLBtn {
int x; // Position X
int y; // Position Y
int w; // Button Width
int h; // Button Height
int x; ///< Position X
int y; ///< Position Y
int w; ///< Button Width
int h; ///< Button Height
};
struct ScrollList1 {
std::string Text = "";
};
struct ScrollList2 {
float x;
float y;
float w;
float h;
std::string Text = "";
};
/*enum ListType
{
ONE,
TWO
};*/
void DrawList1(RenderD7::ScrollList1 &l, float txtsize, C3D_RenderTarget *t);
/// @brief Draw Buttons
/// @param tobjects Vector of Buttons
/// @param color Color of the Buttons
/// @param txtcolor Color of The Text
/// @param selection Positon of Selection
/// @param selbgcolor Selection BackgroundColor
/// @param selcolor Selection Color
void DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color,
u32 txtcolor, int selection = -1,
u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"),
u32 selcolor = RenderD7::Color::Hex("#000000"));
/// @brief Draw A Single Button
/// @param tobject Button
/// @param tobjectindex Button Index
/// @param color Color of the Button
/// @param txtcolor Color of The Text
void DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex,
u32 color, u32 txtcolor);
/// @brief Touched A Button
/// @param touch Touch Position
/// @param button Button
/// @return is touched or not
bool touchTObj(touchPosition touch, RenderD7::TObject button);
/// @brief Touched A Textless Button
/// @param touch Touch Position
/// @param button Button
/// @return is touched or not
bool touchTLBtn(touchPosition touch, RenderD7::TLBtn button);
/// @brief Draw Textless Buttons
/// @param tobjects Vector of Buttons
/// @param color Color of the Buttons
/// @param selection Positon of Selection
/// @param selbgcolor Selection BackgroundColor
/// @param selcolor Selection Color
void DrawTLBtns(std::vector<RenderD7::TLBtn> btns, u32 color,
int selection = -1,
u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"),
u32 selcolor = RenderD7::Color::Hex("#000000"));
struct Checkbox {
float x, y, s;
bool is_chexked = false;
u32 outcol, incol, chcol;
};
void DrawCheckbox(Checkbox box);
class Console {
public:
Console();
Console(int x, int y, int w, int h, u8 a = 255);
Console(int x, int y, int w, int h, RenderD7::Color::rgba col);
Console(int x, int y, int w, int h, std::string name,
RenderD7::Color::rgba col = {255, 255, 255, 255},
RenderD7::Color::rgba barcol = {0, 0, 0, 255},
RenderD7::Color::rgba outlinecol = {222, 222, 222, 255});
void On(C3D_RenderTarget *t_cscreen);
bool Update();
~Console();
private:
std::vector<std::string> m_lines;
int x, y, w, h;
std::string m_name = "";
C3D_RenderTarget *cscreen;
bool m_nconsole = false;
bool m_mconsole = false;
RenderD7::Color::rgba color = {255, 255, 255, 255};
RenderD7::Color::rgba outlinecol = {222, 222, 222, 255};
RenderD7::Color::rgba barcolor = {0, 0, 0, 255};
};
/// @brief DEPRECATED USE RenderD7::FileSystem
/// @param dircontent Vector of Content output
/// @param extensions Extensions
void GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent,
const std::vector<std::string> &extensions);
/// @brief DEPRECATED USE RenderD7::FileSystem
/// @param dircontent Vector of Content output
void GetDirContents(std::vector<RenderD7::DirContent> &dircontent);
} // namespace RenderD7

View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char renderd7_logo[];
extern size_t renderd7_logo_size;

View File

@ -11,17 +11,20 @@ public:
/// \param channel the channel 1-23
/// \param toloop true:loop the sound, false: don't loop
sound(const std::string &path, int channel = 1, bool toloop = false);
/** deconstruct the sound */
/// @brief Deconstructor
~sound();
/** play the sound */
/// @brief Play the sound
void play();
/** stop the sound */
/// @brief Stop the sound
void stop();
private:
/// \param dataSize the Size of the filedata
/// \param dataSize Size of the filedata
u32 dataSize;
/// \param waveBuf For ndsp
ndspWaveBuf waveBuf;
u8 *data = NULL;
/// \param data Memmory data of the sound
uint8_t *data = NULL;
/// \param chnl Channel of the sound
int chnl;
};

View File

@ -4,6 +4,10 @@
#include <string>
namespace RenderD7 {
/// @brief Check if A String ends with
/// @param name Input String
/// @param extensions Extensions to Check for
/// @return Ends with or not
inline bool NameIsEndingWith(const std::string &name,
const std::vector<std::string> &extensions) {
if (name.substr(0, 2) == "._")
@ -24,6 +28,7 @@ inline bool NameIsEndingWith(const std::string &name,
return false;
}
} // namespace RenderD7
template <class T> T GetFileName(T const &path, T const &delims = "/\\") {
return path.substr(path.find_last_of(delims) + 1);
}

View File

@ -10,20 +10,6 @@ using CTRU_Thread = Thread;
#define THREAD_STACK_SIZE 0x1000
namespace RenderD7 {
namespace Threads {
inline bool threadrunning = false;
struct Thread {
Handle handle;
void (*ep)(void);
bool finished;
void *stacktop;
};
bool Create();
bool Join();
void Exit();
} // namespace Threads
class Thread {
public:
/**

View File

@ -1,18 +0,0 @@
#include <renderd7/Clock.hpp>
namespace rnd7 {
enum class TweenType : int { Position = 1, Color, Alpha };
enum class TweenLoop : int {
None = 1,
Loop = 2,
};
enum class TweenDirection : int { Current, Forward, Backward };
enum class TweenState : int { Playing = 1, Stopped };
class Tween {
public:
Tween(float from, float to, float duration, TweenLoop loop, TweenState state);
};
} // namespace rnd7

View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char ui_elements[];
extern size_t ui_elements_size;

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -463,3 +463,13 @@ bool RenderD7::BitmapPrinter::Decode(Decoder deccc) {
}
return res;
}
void RenderD7::BitmapPrinter::DrawBitmap(int x, int y, BMP map) {
for (int i = 0; i < map.bmp_info_header.width; i++) {
for (int j = 0; j < map.bmp_info_header.height; j++) {
bitmap.set_pixel(
x + i, (bitmap.bmp_info_header.height - 1) - (y + j),
UNPACK_BGRA(map.get_pixel(i, (map.bmp_info_header.height - 1) - j)));
}
}
}

View File

@ -1,18 +1,40 @@
#include <map>
#include <renderd7/Color.hpp>
#define RGBA8(r, g, b, a) \
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \
(((a)&0xFF) << 24))
uint32_t RenderD7::Color::Hex(const std::string color, uint8_t a) {
// uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
// if (color.length() < 7 ||
// std::regex_search(color.substr(1),
// std::regex("[^0-9A-Fa-f]"))) { // invalid color.
// return RenderD7::Color::Hex("#000000", 0);
// }
// int r = std::stoi(color.substr(1, 2), nullptr, 16);
// int g = std::stoi(color.substr(3, 2), nullptr, 16);
// int b = std::stoi(color.substr(5, 2), nullptr, 16);
// return RGBA8(r, g, b, a);
// }
// Lookup-Table für Hex-to-Dez-Konvertierung
static const std::map<char, int> HEX_TO_DEC = {
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11},
{'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
if (color.length() < 7 ||
std::regex_search(color.substr(1),
std::regex("[^0-9A-Fa-f]"))) { // invalid color.
std::find_if(color.begin() + 1, color.end(),
[](char c) { return !std::isxdigit(c); }) != color.end()) {
return RenderD7::Color::Hex("#000000", 0);
}
int r = std::stoi(color.substr(1, 2), nullptr, 16);
int g = std::stoi(color.substr(3, 2), nullptr, 16);
int b = std::stoi(color.substr(5, 2), nullptr, 16);
int r = HEX_TO_DEC.at(color[1]) * 16 + HEX_TO_DEC.at(color[2]);
int g = HEX_TO_DEC.at(color[3]) * 16 + HEX_TO_DEC.at(color[4]);
int b = HEX_TO_DEC.at(color[5]) * 16 + HEX_TO_DEC.at(color[6]);
return RGBA8(r, g, b, a);
}

View File

@ -5,340 +5,17 @@
#include <memory>
#include <renderd7/Ovl.hpp>
#include <renderd7/Toast.hpp>
#include <renderd7/stringtool.hpp>
const char *RenderD7::FileSystem::GetPhysfsError() {
return PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
}
#include <filesystem>
std::string RenderD7::FileSystem::Normalize(const std::string &input) {
std::string out;
bool seenSep = false, isSep = false;
for (size_t i = 0; i < input.size(); ++i) {
isSep = (input[i] == '/');
if (!isSep || !seenSep)
out += input[i];
seenSep = isSep;
std::vector<RenderD7::FileSystem::Entry>
RenderD7::FileSystem::GetDirContent(std::string path) {
std::vector<RenderD7::FileSystem::Entry> res;
for (const auto &entry :
std::filesystem::directory_iterator(std::filesystem::path(path))) {
res.push_back({entry.path().string(), GetFileName(entry.path().string()),
entry.is_directory()});
}
return out;
}
void RenderD7::FileSystem::Initialize() { RenderD7::FileSystem::savePath = ""; }
int RenderD7::FileSystem::Init(const char *argv) {
int res = PHYSFS_init(argv);
if (res != 1) {
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
}
return res;
}
bool RenderD7::FileSystem::SetSource(const char *source) {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
std::string searchPath = source;
if (!PHYSFS_mount(searchPath.c_str(), NULL, 1))
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
return true;
}
bool RenderD7::FileSystem::SetIdentity(const char *name, bool append) {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
std::string old = RenderD7::FileSystem::savePath;
RenderD7::FileSystem::savePath = RenderD7::FileSystem::Normalize(
RenderD7::FileSystem::GetUserDirectory() + "/save/" + name);
printf("Save Path set to %s\n", savePath.c_str());
if (!old.empty())
PHYSFS_unmount(old.c_str());
int success = PHYSFS_mount(savePath.c_str(), NULL, append);
printf("Save Path mounted %d\n", success);
PHYSFS_setWriteDir(nullptr);
return true;
}
std::string RenderD7::FileSystem::GetSaveDirectory() {
return RenderD7::FileSystem::Normalize(
RenderD7::FileSystem::GetUserDirectory() + "/save");
}
bool RenderD7::FileSystem::SetupWriteDirectory() {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
if (RenderD7::FileSystem::savePath.empty())
RenderD7::AddOvl(
std::make_unique<RenderD7::Toast>("PHYSFS-Error", "Path is Empty"));
return false;
std::string tmpWritePath = RenderD7::FileSystem::savePath;
std::string tmpDirectoryPath = RenderD7::FileSystem::savePath;
if (RenderD7::FileSystem::savePath.find(
RenderD7::FileSystem::GetUserDirectory()) == 0) {
tmpWritePath = RenderD7::FileSystem::GetUserDirectory();
tmpDirectoryPath =
savePath.substr(RenderD7::FileSystem::GetUserDirectory().length());
/* strip leading '/' characters from the path we want to create */
size_t startPosition = tmpDirectoryPath.find_first_not_of('/');
if (startPosition != std::string::npos)
tmpDirectoryPath = tmpDirectoryPath.substr(startPosition);
}
if (!PHYSFS_setWriteDir(tmpWritePath.c_str())) {
printf("Failed to set write dir to %s\n", tmpWritePath.c_str());
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Failed to set write dir to %s\n",
tmpWritePath.c_str())));
return false;
}
if (!RenderD7::FileSystem::CreateDirectory(tmpDirectoryPath.c_str())) {
printf("Failed to create dir %s\n", tmpDirectoryPath.c_str());
/* clear the write directory in case of error */
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FormatString("Failed to create dir %s\n",
tmpDirectoryPath.c_str())));
PHYSFS_setWriteDir(nullptr);
return false;
}
if (!PHYSFS_setWriteDir(savePath.c_str())) {
printf("Failed to set write dir to %s\n", savePath.c_str());
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Failed to set write dir to %s\n",
savePath.c_str())));
return false;
}
if (!PHYSFS_mount(savePath.c_str(), nullptr, 0)) {
printf("Failed to mount write dir (%s)\n",
RenderD7::FileSystem::GetPhysfsError());
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Failed to mount write dir (%s)\n",
RenderD7::FileSystem::GetPhysfsError())));
/* clear the write directory in case of error */
PHYSFS_setWriteDir(nullptr);
return false;
}
return true;
}
std::string RenderD7::FileSystem::GetUserDirectory() {
return RenderD7::FileSystem::Normalize(
PHYSFS_getPrefDir("npi-d7", "renderd7"));
}
bool RenderD7::FileSystem::GetInfo(const char *filename,
RenderD7::FileSystem::Info &info) {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
PHYSFS_Stat stat = {};
if (!PHYSFS_stat(filename, &stat))
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
info.mod_time =
std::min<int64_t>(stat.modtime, RenderD7::FileSystem::MAX_STAMP);
info.size = std::min<int64_t>(stat.filesize, RenderD7::FileSystem::MAX_STAMP);
if (stat.filetype == PHYSFS_FILETYPE_REGULAR)
info.type = RenderD7::FileSystem::FileType_File;
else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
info.type = RenderD7::FileSystem::FileType_Directory;
else if (stat.filetype == PHYSFS_FILETYPE_SYMLINK)
info.type = RenderD7::FileSystem::FileType_SymLink;
else
info.type = RenderD7::FileSystem::FileType_Other;
return true;
}
void RenderD7::FileSystem::GetDirectoryItems(const char *path,
std::vector<std::string> &items) {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return;
char **results = PHYSFS_enumerateFiles(path);
if (results == nullptr)
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return;
for (char **item = results; *item != 0; item++)
items.push_back(*item);
PHYSFS_freeList(results);
}
bool RenderD7::FileSystem::OpenFile(File &file, const char *name,
FileMode mode) {
if (mode == FileMode_Closed)
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
if (file.handle)
RenderD7::FileSystem::CloseFile(file);
if (mode == FileMode_Read && !PHYSFS_exists(name)) {
printf("Could not open file %s, does not exist.\n", name);
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Could not open file %s, does not exist.\n",
name)));
return false;
}
if ((mode == FileMode_Write) &&
(PHYSFS_getWriteDir() == nullptr &&
RenderD7::FileSystem::SetupWriteDirectory())) {
printf("Could not set write directory.\n");
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Could not set write directory.\n")));
return false;
}
PHYSFS_getLastErrorCode();
switch (mode) {
case FileMode_Read:
file.handle = PHYSFS_openRead(name);
break;
case FileMode_Write:
file.handle = PHYSFS_openWrite(name);
break;
default:
break;
}
if (!file.handle) {
const char *error = RenderD7::FileSystem::GetPhysfsError();
if (error == nullptr)
error = "unknown error";
printf("Could not open file %s (%s)\n", name, error);
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Could not open file %s (%s)\n", name, error)));
return false;
}
file.mode = mode;
return true;
}
bool RenderD7::FileSystem::CloseFile(File &file) {
if (file.handle == nullptr || !PHYSFS_close(file.handle))
return false;
file.handle = nullptr;
return true;
}
bool RenderD7::FileSystem::CreateDirectory(const char *name) {
if (!PHYSFS_isInit())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
if (PHYSFS_getWriteDir() == nullptr &&
!RenderD7::FileSystem::SetupWriteDirectory())
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
if (!PHYSFS_mkdir(name))
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
return true;
}
int64_t RenderD7::FileSystem::ReadFile(File &file, void *destination,
int64_t size) {
if (!file.handle || file.mode != FileMode_Read) {
printf("File is not opened for reading.\n");
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", "File is not opened for reading.\n"));
return 0;
}
if (size > file.GetSize())
size = file.GetSize();
else if (size < 0) {
printf("Invalid read size %lld\n", size);
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error",
RenderD7::FormatString("Invalid read size %lld\n", size)));
return 0;
}
return PHYSFS_readBytes(file.handle, destination, (PHYSFS_uint64)size);
}
bool RenderD7::FileSystem::WriteFile(File &file, const void *data,
int64_t size) {
if (!file.handle || file.mode != FileMode_Write) {
printf("File is not opened for writing.\n");
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", "File is not opened for writing.\n"));
return false;
}
int64_t written = PHYSFS_writeBytes(file.handle, data, (PHYSFS_uint64)size);
if (written != size) {
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"PHYSFS-Error", RenderD7::FileSystem::GetPhysfsError()));
return false;
}
return true;
}

View File

@ -1,8 +1,24 @@
#include <renderd7/Image.hpp>
#include <renderd7/Ovl.hpp>
#include <renderd7/Toast.hpp>
#include <renderd7/external/stb_image.h>
extern bool usedbgmsg;
void convert24to32(unsigned char *inputImage, int width, int height,
unsigned char *outputImage) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int i = (y * width + x) * 3; // index of current pixel in input image
int j = (y * width + x) * 4; // index of current pixel in output image
outputImage[j] = inputImage[i]; // copy red channel
outputImage[j + 1] = inputImage[i + 1]; // copy green channel
outputImage[j + 2] = inputImage[i + 2]; // copy blue channel
outputImage[j + 3] = 255; // set alpha channel to 255 (fully opaque)
}
}
}
static u32 GetNextPowerOf2(u32 v) {
v--;
v |= v >> 1;
@ -75,76 +91,82 @@ static bool C3DTexToC2DImage(C2D_Image *texture, u32 width, u32 height,
return false;
}
extern "C" {
#include <renderd7/external/libnsbmp/libnsbmp.h>
}
static const u32 BYTES_PER_PIXEL = 4;
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex,
u8 *buf, u32 size, u32 width, u32 height,
GPU_TEXCOLOR format) {
// RGBA -> ABGR
for (u32 row = 0; row < width; row++) {
for (u32 col = 0; col < height; col++) {
u32 z = (row + col * width) * 4;
namespace LIBBMP {
static void *bitmap_create(int width, int height,
[[maybe_unused]] unsigned int state) {
/* ensure a stupidly large (>50Megs or so) bitmap is not created */
if ((static_cast<long long>(width) * static_cast<long long>(height)) >
(MAX_IMAGE_BYTES / BYTES_PER_PIXEL))
return nullptr;
u8 r = *(u8 *)(buf + z);
u8 g = *(u8 *)(buf + z + 1);
u8 b = *(u8 *)(buf + z + 2);
u8 a = *(u8 *)(buf + z + 3);
return std::calloc(width * height, BYTES_PER_PIXEL);
}
static unsigned char *bitmap_get_buffer(void *bitmap) {
assert(bitmap);
return static_cast<unsigned char *>(bitmap);
}
static size_t bitmap_get_bpp([[maybe_unused]] void *bitmap) {
return BYTES_PER_PIXEL;
}
static void bitmap_destroy(void *bitmap) {
assert(bitmap);
std::free(bitmap);
}
} // namespace LIBBMP
unsigned Image_to_C3D(C2D_Image img, const std::vector<unsigned char> &bmpc) {
bmp_bitmap_callback_vt bitmap_callbacks = {
LIBBMP::bitmap_create, LIBBMP::bitmap_destroy, LIBBMP::bitmap_get_buffer,
LIBBMP::bitmap_get_bpp};
bmp_result code = BMP_OK;
bmp_image bmp;
bmp_create(&bmp, &bitmap_callbacks);
code = bmp_analyse(&bmp, bmpc.size(), (u8 *)bmpc.data());
if (code != BMP_OK) {
bmp_finalise(&bmp);
return 1;
}
code = bmp_decode(&bmp);
if (code != BMP_OK) {
if ((code != BMP_INSUFFICIENT_DATA) && (code != BMP_DATA_ERROR)) {
bmp_finalise(&bmp);
return 2;
}
/* skip if the decoded image would be ridiculously large */
if ((bmp.width * bmp.height) > 200000) {
bmp_finalise(&bmp);
return 3;
*(buf + z) = a;
*(buf + z + 1) = b;
*(buf + z + 2) = g;
*(buf + z + 3) = r;
}
}
C2D_Image *texture = new C2D_Image();
bool ret = C3DTexToC2DImage(texture, static_cast<u32>(bmp.width),
static_cast<u32>(bmp.height),
static_cast<u8 *>(bmp.bitmap));
bmp_finalise(&bmp);
delete texture;
if (!ret) {
return 4;
u32 w_pow2 = GetNextPowerOf2(width);
u32 h_pow2 = GetNextPowerOf2(height);
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);
C3D_TexInit(tex, (u16)w_pow2, (u16)h_pow2, format);
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) +
((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;
memcpy(&((u8 *)tex->data)[dst_pos], &((u8 *)buf)[src_pos], pixel_size);
}
}
return 0;
C3D_TexFlush(tex);
tex->border = 0x00000000;
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
linearFree(buf);
}
bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
stbi_uc *image = NULL;
int width = 0, height = 0;
int nc;
image = stbi_load(path, &width, &height, &nc, 4);
if (width > 1024 || height > 1024) {
stbi_image_free(image);
return false;
}
C3D_Tex *tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4),
(u32)width, (u32)height, GPU_RGBA8);
texture->tex = tex;
texture->subtex = subtex;
stbi_image_free(image);
return true;
}
void RenderD7::Image::LoadPng(const std::string path) {
@ -247,7 +269,9 @@ bool RenderD7::Image::Draw(float x, float y, float scaleX, float scaleY) {
void RenderD7::Image::LoadFromBitmap(BMP bitmap) {
loadet = false;
unsigned error = Image_to_C3D(this->img, bitmap.DATA());
unsigned error =
C3DTexToC2DImage(&this->img, bitmap.bmp_info_header.width,
bitmap.bmp_info_header.height, bitmap.data.data());
if (error == 0) {
this->loadet = true;
}
@ -257,4 +281,60 @@ void RenderD7::Image::LoadFromBitmap(BMP bitmap) {
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"Bmp - Error", "Code: " + std::to_string(error)));
}
}
}
namespace RenderD7 {
void Image::LoadJpg(std::string path) {
if (usedbgmsg) {
// RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
}
if (loadet) {
C3D_TexDelete(this->img.tex);
loadet = false;
}
IMG_LoadImageFile(&this->img, path.c_str());
loadet = true;
}
void Image::LoadPixels(int w, int h, int bpp, void *buffer) {
if (loadet) {
C3D_TexDelete(this->img.tex);
loadet = false;
}
unsigned width, height;
width = w;
height = h;
uint8_t *ImageBuffer = new uint8_t[w * h * 4];
if (bpp == 3)
convert24to32((uint8_t *)buffer, width, height, ImageBuffer);
img.tex = new C3D_Tex;
img.subtex =
new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f,
width / 512.0f, 1.0f - (height / 512.0f)});
C3D_TexInit(img.tex, 512, 512, GPU_RGBA8);
C3D_TexSetFilter(img.tex, GPU_LINEAR, GPU_LINEAR);
img.tex->border = 0xFFFFFFFF;
C3D_TexSetWrap(img.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
for (u32 x = 0; x < width && x < 512; x++) {
for (u32 y = 0; y < height && y < 512; y++) {
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
4;
const u32 srcPos = (y * width + x) * 4;
((uint8_t *)img.tex->data)[dstPos + 0] = ImageBuffer[srcPos + 3];
((uint8_t *)img.tex->data)[dstPos + 1] = ImageBuffer[srcPos + 2];
((uint8_t *)img.tex->data)[dstPos + 2] = ImageBuffer[srcPos + 1];
((uint8_t *)img.tex->data)[dstPos + 3] = ImageBuffer[srcPos + 0];
}
}
delete[] ImageBuffer;
loadet = true;
}
} // namespace RenderD7

422
source/ResultDecoder.cpp Normal file
View File

@ -0,0 +1,422 @@
#include <map>
#include <renderd7/ResultDecoder.hpp>
#include <sstream>
static std::map<int, std::string> modules = {
{0, "common"},
{1, "kernel"},
{2, "util"},
{3, "file server"},
{4, "loader server"},
{5, "tcb"},
{6, "os"},
{7, "dbg"},
{8, "dmnt"},
{9, "pdn"},
{10, "gsp"},
{11, "i2c"},
{12, "gpio"},
{13, "dd"},
{14, "codec"},
{15, "spi"},
{16, "pxi"},
{17, "fs"},
{18, "di"},
{19, "hid"},
{20, "cam"},
{21, "pi"},
{22, "pm"},
{23, "pm_low"},
{24, "fsi"},
{25, "srv"},
{26, "ndm"},
{27, "nwm"},
{28, "soc"},
{29, "ldr"},
{30, "acc"},
{31, "romfs"},
{32, "am"},
{33, "hio"},
{34, "updater"},
{35, "mic"},
{36, "fnd"},
{37, "mp"},
{38, "mpwl"},
{39, "ac"},
{40, "http"},
{41, "dsp"},
{42, "snd"},
{43, "dlp"},
{44, "hio_low"},
{45, "csnd"},
{46, "ssl"},
{47, "am_low"},
{48, "nex"},
{49, "friends"},
{50, "rdt"},
{51, "applet"},
{52, "nim"},
{53, "ptm"},
{54, "midi"},
{55, "mc"},
{56, "swc"},
{57, "fatfs"},
{58, "ngc"},
{59, "card"},
{60, "cardnor"},
{61, "sdmc"},
{62, "boss"},
{63, "dbm"},
{64, "config"},
{65, "ps"},
{66, "cec"},
{67, "ir"},
{68, "uds"},
{69, "pl"},
{70, "cup"},
{71, "gyroscope"},
{72, "mcu"},
{73, "ns"},
{74, "news"},
{75, "ro"},
{76, "gd"},
{77, "card spi"},
{78, "ec"},
{79, "web browser"},
{80, "test"},
{81, "enc"},
{82, "pia"},
{83, "act"},
{84, "vctl"},
{85, "olv"},
{86, "neia"},
{87, "npns"},
{90, "avd"},
{91, "l2b"},
{92, "mvd"},
{93, "nfc"},
{94, "uart"},
{95, "spm"},
{96, "qtm"},
{97, "nfp"},
{254, "application"},
};
static std::map<int, std::string> levels = {
{0, "Success"}, {1, "Info"}, {25, "Status"},
{26, "Temporary"}, {27, "Permanent"}, {28, "Usage"},
{29, "Reinitialize"}, {30, "Reset"}, {31, "Fatal"},
};
static std::map<int, std::string> summaries = {
{0, "Success"},
{1, "Nothing happened"},
{2, "Would block"},
{3, "Out of resource"},
{4, "Not found"},
{5, "Invalid state"},
{6, "Not supported"},
{7, "Invalid argument"},
{8, "Wrong argument"},
{9, "Canceled"},
{10, "Status changed"},
{11, "Internal"},
{63, "Invalid result value"},
};
static std::map<int, std::string> desccommon = {
{0, "Success"},
{1000, "Invalid selection"},
{1001, "Too large"},
{1002, "Not authorized"},
{1003, "Already done"},
{1004, "Invalid size"},
{1005, "Invalid enum value"},
{1006, "Invalid combination"},
{1007, "No data"},
{1008, "Busy"},
{1009, "Misaligned address"},
{1010, "Misaligned size"},
{1011, "Out of memory"},
{1012, "Not implemented"},
{1013, "Invalid address"},
{1014, "Invalid pointer"},
{1015, "Invalid handle"},
{1016, "Not initialized"},
{1017, "Already initialized"},
{1018, "Not found"},
{1019, "Cancel requested"},
{1020, "Already exists"},
{1021, "Out of range"},
{1022, "Timeout"},
{1023, "Invalid result value"},
};
static std::map<int, std::string> desckernel = {
{2, "Invalid memory permissions."},
};
static std::map<int, std::string> descos = {
{10, "Not enough memory."},
{26, "Session closed by remote."},
{47, "Invalid command header."},
};
// Need to Fix The Range based Values
static std::map<int, std::string> descfs = {
{101, "Archive not mounted or mount-point not found."},
{120, "Title or object not found."},
{141, "Gamecard not inserted."},
{230, "Invalid open flags or permissions."},
{391, "NCCH hash check failed."},
{302, "RSA or AES-MAC verification failed."},
{395, "RomFS or Savedata hash check failed."},
{630, "Command not allowed, or missing permissions."},
{702, "Invalid path."},
{761, "Incorrect ExeFS read size."},
{100, "[Media] not found."},
{180, "Exists already."},
{200, "Not enough space."},
{220, "Invalidated archive."},
{230, "Unacceptable or write protected."},
{340, "0x01"},
{360, "Bad format."},
{390, "Verification failure."},
{400, "0x01"},
{600, "Out of resources."},
{630, "Access denied."},
{661, "0x01"},
{700, "Invalid argument."},
{730, "Not initialized."},
{750, "Already initialized."},
{760, "Not supported."},
{780, "0x01"},
};
static std::map<int, std::string> descsrv = {
{5, "Invalid string length (service name length is zero or longer than 8 "
"chars)."},
{6, "Access to service denied (requested a service the application does "
"not have access to)."},
{7, "String size does not match contents (service name contains unexpected "
"null byte)."},
};
static std::map<int, std::string> descnwm = {
{2, "This error usually indicates the wifi chipset in the console is dying "
"or dead."},
};
static std::map<int, std::string> descam = {
{4, "Invalid ticket version."},
{32, "Empty CIA."},
{37, "Invalid NCCH."},
{39, "Invalid title version."},
{43, "Database doesn\"t exist, or it failed to open."},
{44, "Trying to uninstall system-app."},
{106, "Invalid signature/CIA. Usually happens when developer UNITINFO is "
"enabled in Luma3DS."},
{393, "Invalid database."},
};
static std::map<int, std::string> deschttp = {
{105, "Request timed out."},
};
static std::map<int, std::string> descnim = {
{1, "Invalid string IPC paramater (non null terminated at its indicated "
"length)."},
{12, "Invalid country code returned by CFG module reading config save "
"0xB0000."},
{13, "Zero string length console serial number or '000000000000000' "
"returned by CFG's SecureInfoGetSerialNo."},
{18, "General data reading error of NIM's .dat files from its system save, "
"bad data or bad data lengths."},
{22, "General invalid data or length of data returned from nintendo "
"servers. (Only applicable for some operations)"},
{25, "IntegrityVerificationSeed is waiting on servers to be synced into "
"console. Can't processed with online services without sync being "
"completed first over IPC request."},
{26, "Unavailable/unaccessable IntegrityVerificationSeed on Nintendo "
"servers. May happen if NIM is told to import "
"IntegrityVerificationSeed from servers at any time other than after "
"the successful System Transfer reboot."},
{27, "Invalid country language code returned by CFG module reading config "
"save 0xA0002."},
{37, "Service is in Standby Mode. (eShop ban? General service is down? "
"This caused by a server response flag on account information. "
"Account is not referring to NNID.)"},
{39, "HTTP Status non 200. (Only applicable for some operations)"},
{40, "General XML read/write error while processing Auto Delivery XMLs."},
{41, "General XML read/write error while processing Auto Delivery XMLs. "
"(Stubbed virtual call was called)"},
{58,
"Invalid NPNS token returned by CFG module reading config save 0xF0006."},
{67, "HTTP Status 404 while trying to download a game's seed."},
{68, "HTTP Status 503 while trying to download a game's seed."},
};
static std::map<int, std::string> descmvd = {
{271, "Invalid configuration."},
};
static std::map<int, std::string> descqtm = {
{8, "Camera is already in use or busy."},
};
// Need to Fix The Range based Values
static std::map<int, std::string> descapplication = {
{0, "The application raised an error. Please consult the application's "
"source code or ask the author for assistance with it."},
{1024, "0x01"},
};
namespace RenderD7 {
void ResultDecoder::Load(Result rescode) { this->m_rescode = rescode; }
void ResultDecoder::Load(std::string rescode) {
std::stringstream ss;
ss << rescode;
ss >> std::hex >> this->m_rescode;
}
std::string RenderD7::ResultDecoder::GetCode() {
std::stringstream ss;
ss << std::hex << m_rescode;
std::string reshex(ss.str());
return reshex;
}
std::string ResultDecoder::GetLevel() {
std::string res = levels.at(this->GetLevelInt()) + " (" +
std::to_string(this->GetLevelInt()) + ")";
return res;
}
int ResultDecoder::GetLevelInt() { return R_LEVEL(m_rescode); }
std::string ResultDecoder::GetModule() {
std::string res = modules.at(this->GetModuleInt()) + " (" +
std::to_string(this->GetModuleInt()) + ")";
return res;
}
int ResultDecoder::GetModuleInt() { return R_MODULE(m_rescode); }
std::string ResultDecoder::GetDescription() {
std::string res = "Desc Not Implemented!";
switch (this->GetModuleInt()) {
case 0:
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
break;
case 1:
if ((desckernel.find(this->GetDescriptionInt()) == desckernel.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = desckernel.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 6:
if ((descos.find(this->GetDescriptionInt()) == descos.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descos.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 17:
if ((descfs.find(this->GetDescriptionInt()) == descfs.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descfs.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 25:
if ((descsrv.find(this->GetDescriptionInt()) == descsrv.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descsrv.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 27:
if ((descnwm.find(this->GetDescriptionInt()) == descnwm.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descnwm.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 32:
if ((descam.find(this->GetDescriptionInt()) == descam.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descam.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 40:
if ((deschttp.find(this->GetDescriptionInt()) == deschttp.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = deschttp.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 52:
if ((descnim.find(this->GetDescriptionInt()) == descnim.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descnim.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 92:
if ((descmvd.find(this->GetDescriptionInt()) == descmvd.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descmvd.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 96:
if ((descqtm.find(this->GetDescriptionInt()) == descqtm.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descqtm.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
case 254:
if ((descapplication.find(this->GetDescriptionInt()) ==
descapplication.end())) {
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
} else {
res = descapplication.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
}
break;
default:
res = desccommon.at(this->GetDescriptionInt()) + " (" +
std::to_string(this->GetDescriptionInt()) + ")";
break;
}
return res;
}
int ResultDecoder::GetDescriptionInt() { return R_DESCRIPTION(m_rescode); }
std::string ResultDecoder::GetSummary() {
std::string res = summaries.at(this->GetSummaryInt()) + " (" +
std::to_string(this->GetSummaryInt()) + ")";
return res;
}
int ResultDecoder::GetSummaryInt() { return R_SUMMARY(m_rescode); }
} // namespace RenderD7

View File

@ -22,7 +22,7 @@ void RenderD7::Sprite::SetRotation(float rotation) {
void RenderD7::Sprite::Rotate(float speed) {
C2D_SpriteRotateDegrees(&this->sprite, speed);
}
float RenderD7::Sprite::getHeigh() { return this->sprite.params.pos.h; }
float RenderD7::Sprite::getHeight() { return this->sprite.params.pos.h; }
float RenderD7::Sprite::getWidth() { return this->sprite.params.pos.w; }
float RenderD7::Sprite::getPosX() { return this->sprite.params.pos.x; }
float RenderD7::Sprite::getPosY() { return this->sprite.params.pos.y; }

View File

@ -4,7 +4,7 @@
extern Log renderd7log;
RenderD7::SpriteSheetAnimation::SpriteSheetAnimation() {
renderd7log.Write("SpriteSheetAnimation createt!");
//
}
RenderD7::SpriteSheetAnimation::~SpriteSheetAnimation() {
//
@ -15,13 +15,13 @@ void RenderD7::SpriteSheetAnimation::Setup(RenderD7::Sheet *sheet,
float frame_begin,
float frame_finish) {
D_totaltime = frame_begin;
renderd7log.Write("frame_begin success");
this->images = imagecount;
renderd7log.Write("imagecount success");
this->sheet = sheet;
renderd7log.Write("sheet success");
this->time = frame_finish;
renderd7log.Write("frame_finish success");
RenderD7::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
}
void RenderD7::SpriteSheetAnimation::Play(float timespeed) {

24
source/StealConsole.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
#include <renderd7/StealConsole.hpp>
namespace RenderD7 {
StealConsole::StealConsole() {
std::streambuf *old = std::cout.rdbuf(this->stolen_stdout.rdbuf());
if (old) {
// To prevent from unused error
}
}
StealConsole::~StealConsole() {
// Do Nothing Here
}
std::string StealConsole::GetStdout() {
if (this->stolen_stdout.str().length() < 400) {
return this->stolen_stdout.str();
} else {
return this->stolen_stdout.str().substr(stolen_stdout.str().length() - 400);
}
return "";
}
} // namespace RenderD7

22
source/Tasks.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <renderd7/Tasks.hpp>
#include <3ds.h>
#include <stdio.h>
#include <string.h>
static std::vector<Thread> threads;
void RenderD7::Tasks::create(ThreadFunc entrypoint) {
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
Thread thread = threadCreate((ThreadFunc)entrypoint, NULL, 64 * 1024,
prio - 1, -2, false);
threads.push_back(thread);
}
void RenderD7::Tasks::destroy(void) {
for (u32 i = 0; i < threads.size(); i++) {
threadJoin(threads.at(i), U64_MAX);
threadFree(threads.at(i));
}
}

View File

@ -4,14 +4,6 @@
RenderD7::Toast::Toast(std::string head, std::string msg) {
this->head = head;
this->msg = msg;
/*this->toast = RenderD7::BitmapPrinter(400, 70);
this->toast.ClearBlank();
this->toast.DrawRectFilled(0, 0, 400, 70, 40, 40, 40, 255);
this->toast.DrawRectFilled(0, 0, 400, 25, 70, 70, 70, 255);
this->toast.DrawDebugText(4, 5, 0, RenderD7::Color::Hex("#ffffff"),
this->head); this->toast.DrawDebugText(4, 40, 0,
RenderD7::Color::Hex("#ffffff"), this->msg);
this->toastrendered->LoadPFromBuffer(BitmapConverter::ConvertData(toast.GetBitmap().DATA()));*/
}
void RenderD7::Toast::Draw(void) const {
@ -22,7 +14,6 @@ void RenderD7::Toast::Draw(void) const {
head);
RenderD7::Draw::Text(2, msgposy + 30, 0.6f, RenderD7::Color::Hex("#ffffff"),
msg);
// toastrendered->Draw(0, msgposy);
}
void RenderD7::Toast::Logic() {

5
source/battery_icons.cpp Normal file

File diff suppressed because one or more lines are too long

5
source/npi_intro.cpp Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,28 @@
#include <regex>
#include <renderd7/external/nvid.hpp>
#include <renderd7/log.hpp>
#include <renderd7/npi_intro.hpp>
#include <renderd7/renderd7.hpp>
#include <renderd7/renderd7_logo.hpp>
#define TICKS_PER_MSEC 268111.856
#define D7_NOTHING C2D_Color32(0, 0, 0, 0)
#define CFGVER "3"
#define CFGVER "4"
Log renderd7log;
float animtime;
bool isndspinit = false;
bool running = true;
std::stack<std::unique_ptr<RenderD7::Scene>> RenderD7::Scene::scenes;
std::unique_ptr<RenderD7::Scene> tmpFadeS;
std::stack<std::unique_ptr<RenderD7::Ovl>> overlays;
bool usedbgmsg = false;
std::string dspststus = "Not Initialisized!";
int cobj___;
int maxobj__;
bool rd7_do_splash = false;
// INI::INIFile cfgfile;
std::unique_ptr<INI::INIFile> cfgfile = nullptr;
@ -55,6 +62,7 @@ std::string mt_fps;
std::string mt_cpu;
std::string mt_gpu;
std::string mt_cmd;
std::string mt_lfr;
bool shouldbe_disabled = false;
int cnttttt = 0;
@ -65,14 +73,6 @@ bool metrikd = false;
// double mt_fpsgraph[320];
std::vector<int> mt_fpsgraph(320);
// Metrik-CSV
std::string csvpc;
bool mt_dumpcsv = false; // Logs the Fps and stuff to csv. It saves every second
// to not loose performence.
bool mt_csvloop = false; // Saves In Every Frame but slows down performens.
// mt_dumpcsv must be enabled.
std::ofstream mt_csv;
std::string mt_cname;
//-------------------------------------------
bool currentScreen = false;
@ -84,11 +84,80 @@ C3D_RenderTarget *Bottom;
#define DSEVENWHITE C2D_Color32(255, 255, 255, 255)
u64 delta_time;
u64 last_tm;
float dtm;
// Screen Fade
bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false;
int fadealpha = 0;
int fadecolor = 0;
bool waitFade = false;
bool FadeExit = false;
bool SceneFadeWait = false;
// Sercices
int sv_gfx = 0;
int sv_dsp = 0;
int sv_cfgu = 0;
int sv_apt = 0;
int sv_romfs = 0;
std::vector<std::string> string_to_lines(std::string input_str) {
std::vector<std::string> lines;
std::stringstream ss(input_str);
std::string line;
while (std::getline(ss, line)) {
lines.push_back(line);
}
return lines;
}
void Npifade() {
if (fadein) {
if (fadealpha < 255) {
fadealpha += 3;
} else {
fadein = false;
}
} else if (fadeout) {
if (fadealpha > 0) {
fadealpha -= 3;
} else {
fadeout = false;
}
} else {
if (waitFade)
waitFade = false;
if (FadeExit)
running = false;
if (SceneFadeWait) {
RenderD7::Scene::scenes.push(std::move(tmpFadeS));
SceneFadeWait = false;
}
// No fade
}
RenderD7::OnScreen(Top);
RenderD7::Draw::Rect(0, 0, RenderD7::IsRD7SR() ? 800 : 400, 240,
((fadealpha << 24) | 0x00000000));
RenderD7::OnScreen(Bottom);
RenderD7::Draw::Rect(0, 0, 320, 240, ((fadealpha << 24) | 0x00000000));
}
void PushSplash() {
C2D_SpriteSheet sheet;
sheet = C2D_SpriteSheetLoadFromMem((void *)renderd7_logo, renderd7_logo_size);
// Display for 2 Sec
for (int x = 0; x < 120; x++) {
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, DSEVENBLACK);
C2D_TargetClear(Bottom, DSEVENBLACK);
RenderD7::ClearTextBufs();
RenderD7::OnScreen(Top);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sheet, 0), 400 / 2 - 300 / 2,
240 / 2 - 100 / 2, 0.5);
C3D_FrameEnd(0);
}
C2D_SpriteSheetFree(sheet);
}
std::string _FMT_(const std::string &fmt_str, ...) {
va_list ap;
@ -122,7 +191,7 @@ void screenon() {
gspLcdExit();
}
float RenderD7::GetDeltaTime() { return delta_time; }
float RenderD7::GetDeltaTime() { return (float)dtm; }
bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x,
float y, float scaleX, float scaleY) {
@ -134,17 +203,17 @@ bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x,
}
return false;
}
void RenderD7::Init::NdspFirm(bool useit) {
if (useit) {
if (access("sdmc:/3ds/dspfirm.cdc", F_OK) != -1) {
ndspInit();
isndspinit = true;
dspststus = "Initialisized success!";
} else {
dspststus = "Not found: dspfirm.cdc";
renderd7log.Write("RenderD7: SoundEngine Error! ndspfirm not found!");
RenderD7::AddOvl(std::make_unique<RenderD7::DSP_NF>());
}
void RenderD7::Init::NdspFirm() {
if (access("sdmc:/3ds/dspfirm.cdc", F_OK) != -1) {
Result res;
res = ndspInit();
sv_dsp = R_FAILED(res) ? 1 : 2;
isndspinit = true;
dspststus = "Initialisized success!";
} else {
dspststus = "Not found: dspfirm.cdc";
renderd7log.Write("RenderD7: SoundEngine Error! ndspfirm not found!");
RenderD7::AddOvl(std::make_unique<RenderD7::DSP_NF>());
}
}
void RenderD7::Exit::NdspFirm() {
@ -263,7 +332,11 @@ void RenderD7::Scene::doLogic(u32 hDown, u32 hHeld, u32 hUp,
}
void RenderD7::Scene::Load(std::unique_ptr<Scene> scene, bool fade) {
Scene::scenes.push(std::move(scene));
if (fade) {
tmpFadeS = std::move(scene);
SceneFadeWait = true;
} else
Scene::scenes.push(std::move(scene));
}
void RenderD7::Scene::Back() {
@ -291,6 +364,14 @@ std::string RenderD7::GetFramerate() {
bool RenderD7::MainLoop() {
if (!aptMainLoop())
return false;
// Deltatime
uint64_t currentTime = svcGetSystemTick();
dtm = ((float)(currentTime / (float)TICKS_PER_MSEC) -
(float)(last_tm / (float)TICKS_PER_MSEC)) /
1000.f;
last_tm = currentTime;
hidScanInput();
d7_hDown = hidKeysDown();
d7_hUp = hidKeysUp();
@ -306,7 +387,8 @@ bool RenderD7::MainLoop() {
RenderD7::Scene::doDraw();
RenderD7::Scene::doLogic(d7_hDown, d7_hHeld, d7_hUp, d7_touch);
cnttttt++;
if (cnttttt > 90) {
//Disably Overlays For one Frame
if (cnttttt > 1) {
shouldbe_disabled = false;
cnttttt = 0;
}
@ -344,6 +426,7 @@ void RenderD7::Exit::Graphics() {
Result RenderD7::Init::Main(std::string app_name) {
gfxInitDefault();
sv_gfx = 2;
// consoleInit(GFX_TOP, NULL);
Result res = cfguInit();
if (R_SUCCEEDED(res)) {
@ -356,9 +439,26 @@ Result RenderD7::Init::Main(std::string app_name) {
gfxSetWide(consoleModel != 3);
}
printf("rd7sr\n");
aptInit();
romfsInit();
cfguInit();
res = aptInit();
sv_apt = R_FAILED(res) ? 1 : 2;
res = romfsInit();
sv_romfs = R_FAILED(res) ? 1 : 2;
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
C2D_Prepare();
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
TextBuf = C2D_TextBufNew(4096);
Font = C2D_FontLoadSystem(CFG_REGION_USA);
printf("Graphical Interface\n");
last_tm = svcGetSystemTick();
if (rd7_do_splash)
PushSplash();
res = cfguInit();
sv_cfgu = R_FAILED(res) ? 1 : 2;
printf("stuff\n");
if (cobj___) {
maxobj__ = cobj___;
@ -369,13 +469,9 @@ Result RenderD7::Init::Main(std::string app_name) {
D_app_name = app_name;
cfgpath = "sdmc:/RenderD7/Apps/";
cfgpath += D_app_name;
csvpc = "sdmc:/RenderD7/Apps/";
csvpc += D_app_name;
csvpc += "/mt";
mkdir("sdmc:/RenderD7/", 0777);
mkdir("sdmc:/RenderD7/Apps", 0777);
mkdir(cfgpath.c_str(), 0777);
mkdir(csvpc.c_str(), 0777);
bool renew = false;
printf("folderset\n");
if (FS::FileExist(cfgpath + "/config.ini")) {
@ -411,8 +507,6 @@ Result RenderD7::Init::Main(std::string app_name) {
cfgstruct["metrik-settings"]["ColorA"] = "255";
cfgstruct["metrik-settings"]["Color"] = "#000000";
cfgstruct["metrik-settings"]["txtSize"] = "0.7f";
cfgstruct["metrik-settings"]["dumpcsv"] = "0";
cfgstruct["metrik-settings"]["dumpcsvloop"] = "0";
cfgfile->write(cfgstruct);
}
if (renew)
@ -422,7 +516,7 @@ Result RenderD7::Init::Main(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
////C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor =
@ -439,10 +533,6 @@ Result RenderD7::Init::Main(std::string app_name) {
rd7_superreselution =
RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["settings"]["super-reselution"]));
mt_dumpcsv = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["dumpcsv"]));
mt_csvloop = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["dumpcsvloop"]));
printf("read\n");
// Check if citra
s64 citracheck = 0;
@ -458,20 +548,22 @@ Result RenderD7::Init::Main(std::string app_name) {
}
printf("rd7sr\n");
// consoleInit(GFX_BOTTOM, NULL);
if (mt_dumpcsv) {
mt_cname = csvpc;
mt_cname += "/";
mt_cname += Date();
mt_cname += ".csv";
FILE *logfile = fopen((mt_cname.c_str()), "w");
fclose(logfile);
mt_csv.open((mt_cname), std::ofstream::app);
mt_csv << "FPS,CPU,GPU,CMD\n";
mt_csv.close();
}
printf("csv\n");
// RenderD7::Msg::Display("RenderD7", "RenderD7 init success!\nWaiting for
// MainLoop!", Top);
return 0;
}
Result RenderD7::Init::Minimal(std::string app_name) {
D_app_name = app_name;
Result res_;
gfxInitDefault();
sv_gfx = 2;
res_ = romfsInit();
sv_romfs = R_FAILED(res_) ? 1 : 2;
osSetSpeedupEnable(true);
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
C2D_Prepare();
@ -480,9 +572,91 @@ Result RenderD7::Init::Main(std::string app_name) {
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
TextBuf = C2D_TextBufNew(4096);
Font = C2D_FontLoadSystem(CFG_REGION_USA);
printf("Graphical Interface\n");
// RenderD7::Msg::Display("RenderD7", "RenderD7 init success!\nWaiting for
// MainLoop!", Top);
if (rd7_do_splash)
PushSplash();
// Check if citra
s64 citracheck = 0;
svcGetSystemInfo(&citracheck, 0x20000, 0);
is_citra = citracheck ? true : false;
if (cobj___) {
maxobj__ = cobj___;
}
if (!cobj___) {
maxobj__ = C2D_DEFAULT_MAX_OBJECTS;
}
cfgpath = "sdmc:/RenderD7/Apps/";
cfgpath += D_app_name;
mkdir("sdmc:/RenderD7/", 0777);
mkdir("sdmc:/RenderD7/Apps", 0777);
mkdir(cfgpath.c_str(), 0777);
bool renew = false;
printf("folderset\n");
if (FS::FileExist(cfgpath + "/config.ini")) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
std::string version = cfgstruct["info"]["version"];
if (version != CFGVER)
renew = true;
}
printf("vercheck\n");
renderd7log.Write("Point At: " + std::to_string(__LINE__) + " : " +
GetFileName<std::string>(__FILE__));
if (!FS::FileExist(cfgpath + "/config.ini") || renew) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
renderd7log.Write("Point At: " + std::to_string(__LINE__) + " : " +
GetFileName<std::string>(__FILE__));
cfgfile->read(cfgstruct);
renderd7log.Write("Point At: " + std::to_string(__LINE__) + " : " +
GetFileName<std::string>(__FILE__));
cfgstruct["info"]["version"] = CFGVER;
cfgstruct["info"]["renderd7ver"] = RENDERD7VSTRING;
cfgstruct["settings"]["doscreentimeout"] = "0";
cfgstruct["settings"]["forcetimeoutLB"] = "1";
cfgstruct["settings"]["forceFrameRate"] = "60";
cfgstruct["settings"]["super-reselution"] = "0";
cfgstruct["settings"]["renderer"] = "c3d_c2d";
renderd7log.Write("Point At: " + std::to_string(__LINE__) + " : " +
GetFileName<std::string>(__FILE__));
cfgstruct["metrik-settings"]["enableoverlay"] = "0";
cfgstruct["metrik-settings"]["Screen"] = "0";
cfgstruct["metrik-settings"]["txtColor"] = "#ffffff";
cfgstruct["metrik-settings"]["txtColorA"] = "255";
cfgstruct["metrik-settings"]["ColorA"] = "255";
cfgstruct["metrik-settings"]["Color"] = "#000000";
cfgstruct["metrik-settings"]["txtSize"] = "0.7f";
cfgfile->write(cfgstruct);
}
if (renew)
printf("renew\n");
renderd7log.Write("Point At: " + std::to_string(__LINE__) + " : " +
GetFileName<std::string>(__FILE__));
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"];
// C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor =
RenderD7::Color::Hex(cfgstruct["metrik-settings"]["txtColor"],
(u8)RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["txtColorA"]));
mt_color = RenderD7::Color::Hex(cfgstruct["metrik-settings"]["Color"],
(u8)RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["ColorA"]));
mt_txtSize =
RenderD7::Convert::StringtoFloat(cfgstruct["metrik-settings"]["txtSize"]);
mt_screen =
RenderD7::Convert::StringtoInt(cfgstruct["metrik-settings"]["Screen"]);
rd7_superreselution =
RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["settings"]["super-reselution"]));
printf("boost\n");
if (!is_citra && rd7_superreselution) {
if (consoleModel != 3)
gfxSetWide(true);
}
return 0;
}
@ -520,8 +694,6 @@ bool RenderD7::IsRD7SR() { return gfxIsWide(); }
void RenderD7::Exit::Main() {
cfgfile->write(cfgstruct);
if (RenderD7::Threads::threadrunning)
RenderD7::Threads::Exit();
C2D_TextBufDelete(TextBuf);
C2D_Fini();
C3D_Fini();
@ -529,6 +701,14 @@ void RenderD7::Exit::Main() {
gfxExit();
romfsExit();
cfguExit();
}
void RenderD7::Exit::Minimal() {
cfgfile->write(cfgstruct);
C2D_TextBufDelete(TextBuf);
C2D_Fini();
C3D_Fini();
gfxExit();
romfsExit();
}
@ -585,8 +765,20 @@ void RenderD7::DrawTLBtns(std::vector<RenderD7::TLBtn> btns, u32 color,
}
void RenderD7::ExitApp() {
if (!rd7settings)
running = false;
if (!rd7settings) {
if (waitFade) {
FadeExit = true;
} else
running = false;
} else {
// Normally Forbidden
fadein = false;
waitFade = false;
RenderD7::FadeIn();
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"RenderD7", "Exiting in Settings is Not Allowed!\nPress B to Get Out "
"and then Exit."));
}
}
bool RenderD7::touchTObj(touchPosition touch, RenderD7::TObject button) {
@ -693,11 +885,25 @@ bool RenderD7::IsNdspInit() {
}
}
void RenderD7::DrawList1(RenderD7::ScrollList1 &l, float txtsize,
C3D_RenderTarget *t) {
RenderD7::OnScreen(t);
RenderD7::Draw::Rect(0, 0, 400, 240, RenderD7::Color::Hex("#dddddd"));
RenderD7::Draw::Text(0, 0, 0.8f, RenderD7::Color::Hex("#ffffff"), l.Text);
std::string priv_fmt_bytes(int bytes) {
char out[32];
if (bytes == 1)
snprintf(out, sizeof(out), "%d Byte", bytes);
else if (bytes < 1024)
snprintf(out, sizeof(out), "%d Bytes", bytes);
else if (bytes < 1024 * 1024)
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024)
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
else
snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
return out;
}
void RenderD7::DrawMetrikOvl() {
@ -727,6 +933,7 @@ void RenderD7::DrawMetrikOvl() {
mt_cmd =
"CMD: " + std::to_string(C3D_GetCmdBufUsage() * 100.0f).substr(0, 4) +
"%/" + std::to_string(C3D_GetCmdBufUsage()).substr(0, 4) + "ms";
mt_lfr = "Linear: " + priv_fmt_bytes(linearSpaceFree());
RenderD7::Draw::Rect(0, 0, RenderD7::Draw::GetTextWidth(mt_txtSize, mt_fps),
RenderD7::Draw::GetTextHeight(mt_txtSize, mt_fps),
mt_color);
@ -739,6 +946,9 @@ void RenderD7::DrawMetrikOvl() {
RenderD7::Draw::Rect(0, 90, RenderD7::Draw::GetTextWidth(mt_txtSize, mt_cmd),
RenderD7::Draw::GetTextHeight(mt_txtSize, mt_cmd),
mt_color);
RenderD7::Draw::Rect(0, 110, RenderD7::Draw::GetTextWidth(mt_txtSize, mt_lfr),
RenderD7::Draw::GetTextHeight(mt_txtSize, mt_lfr),
mt_color);
RenderD7::Draw::Rect(0, infoy, RenderD7::Draw::GetTextWidth(mt_txtSize, info),
RenderD7::Draw::GetTextHeight(mt_txtSize, info),
mt_color);
@ -746,6 +956,7 @@ void RenderD7::DrawMetrikOvl() {
RenderD7::Draw::Text(0, 50, mt_txtSize, mt_txtcolor, mt_cpu);
RenderD7::Draw::Text(0, 70, mt_txtSize, mt_txtcolor, mt_gpu);
RenderD7::Draw::Text(0, 90, mt_txtSize, mt_txtcolor, mt_cmd);
RenderD7::Draw::Text(0, 110, mt_txtSize, mt_txtcolor, mt_lfr);
RenderD7::Draw::Text(0, infoy, mt_txtSize, mt_txtcolor, info);
/*for (int z = 0; z < (int)mt_fpsgraph.size(); z++)
@ -797,23 +1008,9 @@ int lp = 0;
void RenderD7::FrameEnd() {
if (metrikd && !shouldbe_disabled)
RenderD7::DrawMetrikOvl();
if (!shouldbe_disabled)
if (!shouldbe_disabled) {
OvlHandler();
/*if (d7_hHeld & KEY_R && d7_hDown & KEY_SELECT)
{
RenderD7::LoadSettings();
}*/
if (mt_dumpcsv && lp == 60) {
std::string _mt_fps = RenderD7::GetFramerate();
std::string _mt_cpu = std::to_string(C3D_GetProcessingTime()).substr(0, 4);
std::string _mt_gpu = std::to_string(C3D_GetDrawingTime()).substr(0, 4);
std::string _mt_cmd = std::to_string(C3D_GetCmdBufUsage()).substr(0, 4);
mt_csv.open((mt_cname), std::ofstream::app);
std::string fmt_ =
_mt_fps + "," + _mt_cpu + "," + _mt_gpu + "," + _mt_cmd + "\n";
mt_csv << fmt_;
mt_csv.close();
lp = 0;
Npifade();
}
lp++;
@ -821,12 +1018,29 @@ void RenderD7::FrameEnd() {
}
RenderD7::RSettings::RSettings() {
aptSetHomeAllowed(false);
RenderD7::FadeIn();
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
rd7settings = true;
lines = string_to_lines(CHANGELOG);
calculate_screens(lines, screen_index, screens);
}
RenderD7::RSettings::~RSettings() { cfgfile->write(cfgstruct); }
RenderD7::RSettings::~RSettings() {
cfgfile->write(cfgstruct);
aptSetHomeAllowed(false);
}
std::vector<std::string> StrHelper(std::string input) {
std::string ss(input);
std::istringstream in(ss);
std::vector<std::string> test1;
std::copy(std::istream_iterator<std::string>(in),
std::istream_iterator<std::string>(), std::back_inserter(test1));
return test1;
}
void RenderD7::RSettings::Draw(void) const {
if (m_state == RSETTINGS) {
@ -837,8 +1051,6 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::Draw::TextRight(400, 0, 0.7f, RenderD7::Color::Hex("#ffffff"),
RENDERD7VSTRING);
RenderD7::Draw::Text(0, 30, 0.7f, DSEVENBLACK, "RD7SR: " + rd7srstate);
RenderD7::Draw::Text(0, 50, 0.7f, DSEVENBLACK,
"Metrik to Csv: " + csvstate);
RenderD7::Draw::Text(0, 70, 0.7f, DSEVENBLACK,
"Metrik Overlay: " + mtovlstate);
RenderD7::Draw::Text(0, 90, 0.7f, DSEVENBLACK, "Force FPS: " + fpsstate);
@ -856,6 +1068,62 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::DrawTObjects(buttons, RenderD7::Color::Hex("#111111"),
RenderD7::Color::Hex("#eeeeee"));
} else if (m_state == RSERVICES) {
RenderD7::OnScreen(Top);
RenderD7::Draw::Rect(0, 0, 400, 21, RenderD7::Color::Hex("#111111"));
RenderD7::Draw::Rect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, DSEVENWHITE, "RenderD7->Services");
RenderD7::Draw::TextRight(400, 0, 0.7f, RenderD7::Color::Hex("#ffffff"),
RENDERD7VSTRING);
RenderD7::Draw::Text(0, 30, 0.7f, DSEVENBLACK,
"gfx: " + std::string(sv_gfx == 0 ? "Not Init"
: sv_gfx == 2 ? "Success"
: "Failed"));
RenderD7::Draw::Text(0, 50, 0.7f, DSEVENBLACK,
"Apt: " + std::string(sv_apt == 0 ? "Not Init"
: sv_apt == 2 ? "Success"
: "Failed"));
RenderD7::Draw::Text(0, 70, 0.7f, DSEVENBLACK,
"Romfs: " + std::string(sv_romfs == 0 ? "Not Init"
: sv_romfs == 2 ? "Success"
: "Failed"));
RenderD7::Draw::Text(0, 90, 0.7f, DSEVENBLACK,
"cfgu: " + std::string(sv_cfgu == 0 ? "Not Init"
: sv_cfgu == 2 ? "Success"
: "Failed"));
RenderD7::Draw::Text(0, 110, 0.7f, DSEVENBLACK,
"NDSP: " + std::string(sv_dsp == 0 ? "Not Init"
: sv_dsp == 2 ? "Success"
: "Failed"));
RenderD7::OnScreen(Bottom);
RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"),
"Press B to Get back!");
} else if (m_state == RCLOG) {
RenderD7::OnScreen(Top);
int start_index = screen_index * 9;
int end_index = std::min((int)lines.size(), start_index + 9);
RenderD7::Draw::Rect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee"));
for (int i = start_index; i < end_index; i++) {
RenderD7::Draw::Text(5, 23 + 20 * (i - start_index), 0.7f, DSEVENBLACK,
lines[i]);
}
RenderD7::Draw::Rect(0, 219, 400, 21, RenderD7::Color::Hex("#111111"));
RenderD7::Draw::Text(0, 220, 0.7f, RenderD7::Color::Hex("#ffffff"),
"Site: " + std::to_string(screen_index + 1) + "/" +
std::to_string(screens + 1));
RenderD7::Draw::Rect(0, 0, 400, 21, RenderD7::Color::Hex("#111111"));
RenderD7::Draw::Text(0, 0, 0.7f, DSEVENWHITE, "RenderD7->Changelog");
RenderD7::Draw::TextRight(400, 0, 0.7f, RenderD7::Color::Hex("#ffffff"),
RENDERD7VSTRING);
RenderD7::OnScreen(Bottom);
RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"),
"Press B to Get back!");
} else if (m_state == RINFO) {
std::string rd7ver = RENDERD7VSTRING;
std::string rd7cfgver = CFGVER;
@ -877,17 +1145,17 @@ void RenderD7::RSettings::Draw(void) const {
"RenderD7-Build-Time: \n" + buildtime);
RenderD7::Draw::Text(0, 150, 0.7f, DSEVENBLACK,
"RenderD7-Commit: " + commit);
RenderD7::Draw::Text(0, 170, 0.7f, DSEVENBLACK,
"RenderD7-Overlays: " +
std::to_string(overlays.size()));
/*RenderD7::Draw::Text(0, 130, 0.7f, DSEVENBLACK, "Metrik Text RGB: " +
mttxtcolstate); RenderD7::Draw::Text(0, 150, 0.7f, DSEVENBLACK, "Metrik
Alpha: " + mtcola); RenderD7::Draw::Text(0, 170, 0.7f, DSEVENBLACK, "Metrik
Text Alpha: " + mttxtcola);*/
RenderD7::OnScreen(Bottom);
std::string verc = "Config Version: ";
verc += CFGVER;
RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"), verc);
RenderD7::DrawTObjects(buttons, RenderD7::Color::Hex("#111111"),
RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"),
"Press B to Get back!");
}
}
std::string RenderD7::Kbd(int lenght, SwkbdType tp) {
@ -907,51 +1175,44 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
touchPosition touch) {
if (m_state == RSETTINGS) {
rd7srstate = rd7_superreselution ? "true" : "false";
csvstate = mt_dumpcsv ? "true" : "false";
mtovlstate = metrikd ? "true" : "false";
fpsstate = cfgstruct["settings"]["forceFrameRate"];
mtscreenstate = mt_screen ? "Bottom" : "Top";
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[0]) &&
!metrikd) {
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
"RenderD7",
"RenderD7-Super-Reselution Does not\nWork Correctly yet!"));
RenderD7::ToggleRD7SR();
cfgstruct["settings"]["super-reselution"] =
rd7_superreselution ? "1" : "0";
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[1])) {
mt_dumpcsv = mt_dumpcsv ? false : true;
cfgstruct["metrik-settings"]["dumpcsv"] = mt_dumpcsv ? "1" : "0";
if (mt_dumpcsv) {
mt_cname = csvpc;
mt_cname += "/";
mt_cname += Date();
mt_cname += ".csv";
FILE *logfile = fopen((mt_cname.c_str()), "w");
fclose(logfile);
mt_csv.open((mt_cname), std::ofstream::app);
mt_csv << "FPS,CPU,GPU,CMD\n";
mt_csv.close();
}
m_state = RCLOG;
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[2])) {
metrikd = metrikd ? false : true;
cfgstruct["metrik-settings"]["enableoverlay"] = metrikd ? "1" : "0";
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) &&
/*if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) &&
!metrikd) {
cfgstruct["settings"]["forceFrameRate"] = Kbd(2, SWKBD_TYPE_NUMPAD);
C3D_FrameRate(RenderD7::Convert::StringtoFloat(
cfgstruct["settings"]["forceFrameRate"]));
}
// C3D_FrameRate(RenderD7::Convert::StringtoFloat(
// cfgstruct["settings"]["forceFrameRate"]));
}*/
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[4])) {
mt_screen = mt_screen ? 0 : 1;
cfgstruct["metrik-settings"]["screen"] = mt_screen ? "1" : "0";
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[5])) {
/*if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[5])) {
RenderD7::AddOvl(std::make_unique<RenderD7::DSP_NF>());
}
}*/
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[6])) {
m_state = RINFO;
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[7])) {
m_state = RSERVICES;
}
if (d7_hDown & KEY_B) {
cfgfile->write(cfgstruct);
rd7settings = false;
@ -963,6 +1224,30 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
m_state = RSETTINGS;
}
}
if (m_state == RSERVICES) {
if (d7_hDown & KEY_B) {
m_state = RSETTINGS;
}
}
if (m_state == RCLOG) {
if (d7_hDown & KEY_B) {
m_state = RSETTINGS;
}
if (d7_hDown & KEY_R)
if (screen_index < screens)
screen_index++;
if (d7_hDown & KEY_L)
if (screen_index > 0)
screen_index--;
}
}
void RenderD7::RSettings::calculate_screens(
const std::vector<std::string> &lines, int &screen_index, int &screens) {
int num_lines = lines.size();
screens = (num_lines + 8) / 9; // round up to nearest multiple of 9
screen_index = 0;
screens -= 1;
}
void RenderD7::LoadSettings() {
@ -973,46 +1258,81 @@ void RenderD7::AddOvl(std::unique_ptr<RenderD7::Ovl> overlay) {
overlays.push(std::move(overlay));
}
RenderD7::Console::Console() {
this->x = 0;
this->y = 0;
this->w = 320;
this->h = 240;
this->color = {0, 0, 0, 255};
void RenderD7::DoNpiIntro() {
// May be stream in future
/*NVID_Stream* stream = new NVID_Stream(npi_intro, npi_intro_size);
int c = 0;
float xc = 0;
NVID_Image nimg;
RenderD7::Image img;
uint64_t lastT = osGetTime();
stream->ReadNext(nimg);
while(true)
{
shouldbe_disabled = true;
cnttttt = 0;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, RenderD7::Color::Hex("#000000"));
C2D_TargetClear(Bottom, RenderD7::Color::Hex("#000000"));
RenderD7::ClearTextBufs();
RenderD7::OnScreen(Top);
img.LoadPixels(nimg.w, nimg.h, nimg.bpp, nimg.pBuf);
img.Draw(0, 0);
xc += osGetTime() - lastT;
lastT = osGetTime();
if (xc > 24 / 60) {
c++;
if(!stream->ReadNext(nimg))
break;
xc = 0;
}
if (c > 59)
break;
C3D_FrameEnd(0);
}*/
auto images = LoadMemNVID(npi_intro, npi_intro_size);
int c = 0;
float xc = 0;
RenderD7::Image img;
uint64_t lastT = osGetTime();
while (c < 59) {
shouldbe_disabled = true;
cnttttt = 0;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, RenderD7::Color::Hex("#000000"));
C2D_TargetClear(Bottom, RenderD7::Color::Hex("#000000"));
RenderD7::ClearTextBufs();
RenderD7::OnScreen(Top);
img.LoadPixels(images[c]->w, images[c]->h, images[c]->bpp, images[c]->pBuf);
img.Draw(0, 0);
xc += osGetTime() - lastT;
lastT = osGetTime();
if (xc > 24 / 60) {
c++;
xc = 0;
}
if (c > (int)(images.size() - 1))
c = 0;
C3D_FrameEnd(0);
}
}
RenderD7::Console::Console(int x, int y, int w, int h, u8 a) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->color = {0, 0, 0, a};
void RenderD7::FadeOut() {
if (!waitFade) {
fadein = true;
fadealpha = 0;
waitFade = true;
}
}
RenderD7::Console::Console(int x, int y, int w, int h,
RenderD7::Color::rgba col) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->color = col;
}
RenderD7::Console::Console(int x, int y, int w, int h, std::string name,
RenderD7::Color::rgba col,
RenderD7::Color::rgba barcol,
RenderD7::Color::rgba outlinecol) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->color = col;
this->outlinecol = outlinecol;
this->barcolor = barcol;
this->m_name = name;
}
RenderD7::Console::~Console() {}
void RenderD7::Console::On(C3D_RenderTarget *t_cscreen) {
this->cscreen = t_cscreen;
}
bool RenderD7::Console::Update() {
bool dr_sc = true;
return dr_sc;
void RenderD7::FadeIn() {
if (!waitFade) {
fadeout = true;
fadealpha = 255;
waitFade = true;
}
}
void RenderD7::FadeDisplay() { Npifade(); }

Some files were not shown because too many files have changed in this diff Show More