4 Commits

Author SHA1 Message Date
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
8 changed files with 129 additions and 119 deletions

View File

@ -10,7 +10,7 @@ include $(DEVKITARM)/3ds_rules
export renderd7_MAJOR := 0 export renderd7_MAJOR := 0
export renderd7_MINOR := 8 export renderd7_MINOR := 8
export renderd7_PATCH := 3 export renderd7_PATCH := 5
VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH) VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH)

View File

@ -35,6 +35,7 @@ public:
void DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a); void DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a);
void DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a); void DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a);
void DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a); void DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a);
void DrawBitmap(int x, int y, BMP map);
void UsePreMap(BMP map); void UsePreMap(BMP map);
void UsePrePrintMap(BitmapPrinter printmap); void UsePrePrintMap(BitmapPrinter printmap);
BMP GetBitmap() { return bitmap; } BMP GetBitmap() { return bitmap; }

View File

@ -0,0 +1,8 @@
#pragma once
#include <3ds.h>
#include <vector>
namespace Tasks {
void create(ThreadFunc entrypoint);
void destroy(void);
} // namespace Tasks

View File

@ -5,6 +5,7 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
using namespace std; using namespace std;
#pragma pack(push, 1) #pragma pack(push, 1)
@ -48,7 +49,8 @@ struct BMPColorHeader {
}; };
#pragma pack(pop) #pragma pack(pop)
struct BMP { class BMP {
public:
BMPFileHeader file_header; BMPFileHeader file_header;
BMPInfoHeader bmp_info_header; BMPInfoHeader bmp_info_header;
BMPColorHeader bmp_color_header; BMPColorHeader bmp_color_header;
@ -62,8 +64,8 @@ struct BMP {
inp.read((char *)&file_header, sizeof(file_header)); inp.read((char *)&file_header, sizeof(file_header));
if (file_header.file_type != 0x4D42) { if (file_header.file_type != 0x4D42) {
return 50; // throw std::runtime_error("Error! Unrecognized file return 50;
// format."); // throw std::runtime_error("Error! Unrecognized file format.");
} }
inp.read((char *)&bmp_info_header, sizeof(bmp_info_header)); inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
@ -78,9 +80,8 @@ struct BMP {
check_color_header(bmp_color_header); check_color_header(bmp_color_header);
} else { } else {
// std::cerr << "Error! The file \"" << fname << "\" does not seem to // std::cerr << "Error! The file \"" << fname << "\" does not seem to
// contain bit mask information\n"; // contain bit mask information\n"; return 51;//throw
return 51; // throw std::runtime_error("Error! Unrecognized file // std::runtime_error("Error! Unrecognized file format.");
// format.");
} }
} }
@ -137,12 +138,14 @@ struct BMP {
std::stringstream inp; std::stringstream inp;
std::copy(buffer.begin(), buffer.end(), std::copy(buffer.begin(), buffer.end(),
std::ostream_iterator<unsigned char>(inp, "\n")); std::ostream_iterator<unsigned char>(inp, "\n"));
std::cout << buffer.size() << std::endl;
if (inp) { if (inp) {
inp.read((char *)&file_header, sizeof(file_header)); inp.read((char *)&file_header, sizeof(file_header));
if (file_header.file_type != 0x4D42) { if (file_header.file_type != 0x4D42) {
return 50; // throw std::runtime_error("Error! Unrecognized file return 50;
// format."); // 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)); inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
@ -158,8 +161,8 @@ struct BMP {
} else { } else {
// std::cerr << "Error! The file \"" << fname << "\" does not seem to // std::cerr << "Error! The file \"" << fname << "\" does not seem to
// contain bit mask information\n"; // contain bit mask information\n";
return 51; // throw std::runtime_error("Error! Unrecognized file return 51;
// format."); // throw std::runtime_error("Error! Unrecognized file format. Size");
} }
} }
@ -181,8 +184,10 @@ struct BMP {
file_header.file_size = file_header.offset_data; file_header.file_size = file_header.offset_data;
if (bmp_info_header.height < 0) { if (bmp_info_header.height < 0) {
return 52; // throw std::runtime_error("The program can treat only BMP return 52;
// images with the origin in the bottom left corner!"); // 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 * 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()); bmp_info_header.height * static_cast<uint32_t>(padding_row.size());
} }
} else { } else {
return 53; // throw std::runtime_error("Unable to open the input image return 53;
// file "+std::string(fname)); // throw std::runtime_error("Unable to open the input image buffer");
} }
return 0; 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, unsigned set_pixel(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R,
uint8_t A) { uint8_t A) {
if (x0 >= (uint32_t)bmp_info_header.width || if (x0 >= (uint32_t)bmp_info_header.width ||
y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) { y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) {
return 59; // throw std::runtime_error("The point is outside the image return 59;
// boundaries!"); // 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; uint32_t channels = bmp_info_header.bit_count / 8;
data[channels * (y0 * bmp_info_header.width + x0) + 0] = B; 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; uint32_t y1 = this->bmp_info_header.height - y0;
if (x0 >= (uint32_t)bmp_info_header.width || if (x0 >= (uint32_t)bmp_info_header.width ||
y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) { y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) {
return; // throw std::runtime_error("The point is outside the image return;
// boundaries!"); // 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; 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, 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 B, uint8_t G, uint8_t R, uint8_t A,
uint8_t line_w) { uint8_t line_w) {

View File

@ -43,14 +43,15 @@
#include <renderd7/stringtool.hpp> #include <renderd7/stringtool.hpp>
#include <renderd7/thread.hpp> #include <renderd7/thread.hpp>
extern "C" { extern "C" {
#include <renderd7/external/fs.h> #include <renderd7/external/fs.h>
} }
#define RENDERD7VSTRING "0.8.3" #define RENDERD7VSTRING "0.8.5"
#define CHANGELOG \ #define CHANGELOG \
"0.8.3: Addet Overlaycount to Info and Addet ResultDecoder for " \ "0.8.5: Fix Deltatime 0.8.4: A lot of Fixes and new Features for " \
"BitmapPrinter! 0.8.3: Addet " \
"Overlaycount to Info and Addet ResultDecoder for " \
"errors.0.8.2: Fix a lot of Stuff and add c++17 based filesystem " \ "errors.0.8.2: Fix a lot of Stuff and add c++17 based filesystem " \
"class.\n0.8.1: " \ "class.\n0.8.1: " \
"Add abillity to Get Stdout as string to render it to the " \ "Add abillity to Get Stdout as string to render it to the " \

View File

@ -463,3 +463,13 @@ bool RenderD7::BitmapPrinter::Decode(Decoder deccc) {
} }
return res; 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)));
}
}
}

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 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 Tasks::destroy(void) {
for (u32 i = 0; i < threads.size(); i++) {
threadJoin(threads.at(i), U64_MAX);
threadFree(threads.at(i));
}
}

View File

@ -2,6 +2,7 @@
#include <renderd7/log.hpp> #include <renderd7/log.hpp>
#include <renderd7/renderd7.hpp> #include <renderd7/renderd7.hpp>
#define TICKS_PER_MSEC 268111.856
#define D7_NOTHING C2D_Color32(0, 0, 0, 0) #define D7_NOTHING C2D_Color32(0, 0, 0, 0)
#define CFGVER "3" #define CFGVER "3"
@ -84,6 +85,8 @@ C3D_RenderTarget *Bottom;
#define DSEVENWHITE C2D_Color32(255, 255, 255, 255) #define DSEVENWHITE C2D_Color32(255, 255, 255, 255)
u64 delta_time; u64 delta_time;
u64 last_tm;
float dtm;
// Screen Fade // Screen Fade
bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false; bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false;
@ -122,7 +125,7 @@ void screenon() {
gspLcdExit(); gspLcdExit();
} }
float RenderD7::GetDeltaTime() { return delta_time; } float RenderD7::GetDeltaTime() { return (float)dtm; }
bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x, bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x,
float y, float scaleX, float scaleY) { float y, float scaleX, float scaleY) {
@ -291,6 +294,12 @@ std::string RenderD7::GetFramerate() {
bool RenderD7::MainLoop() { bool RenderD7::MainLoop() {
if (!aptMainLoop()) if (!aptMainLoop())
return false; 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(); hidScanInput();
d7_hDown = hidKeysDown(); d7_hDown = hidKeysDown();
d7_hUp = hidKeysUp(); d7_hUp = hidKeysUp();
@ -481,6 +490,7 @@ Result RenderD7::Init::Main(std::string app_name) {
TextBuf = C2D_TextBufNew(4096); TextBuf = C2D_TextBufNew(4096);
Font = C2D_FontLoadSystem(CFG_REGION_USA); Font = C2D_FontLoadSystem(CFG_REGION_USA);
printf("Graphical Interface\n"); printf("Graphical Interface\n");
last_tm = svcGetSystemTick();
// RenderD7::Msg::Display("RenderD7", "RenderD7 init success!\nWaiting for // RenderD7::Msg::Display("RenderD7", "RenderD7 init success!\nWaiting for
// MainLoop!", Top); // MainLoop!", Top);
return 0; return 0;