Remove nsmbp and fix a critical bug

This commit is contained in:
2023-03-09 21:19:17 +01:00
parent 66a35f28e6
commit 67edfa4245
15 changed files with 64 additions and 2182 deletions

View File

@ -1,5 +1,5 @@
#include <renderd7/Color.hpp>
#include <map>
#include <renderd7/Color.hpp>
#define RGBA8(r, g, b, a) \
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \

View File

@ -155,78 +155,6 @@ bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
return true;
}
extern "C" {
#include <renderd7/external/libnsbmp/libnsbmp.h>
}
static const u32 BYTES_PER_PIXEL = 4;
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
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;
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;
}
}
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;
}
return 0;
}
void RenderD7::Image::LoadPng(const std::string path) {
if (usedbgmsg) {
// RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
@ -327,7 +255,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;
}

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) {

View File

@ -547,7 +547,7 @@ Result RenderD7::Init::Minimal(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 =
@ -932,6 +932,7 @@ void RenderD7::FrameEnd() {
if (!shouldbe_disabled)
OvlHandler();
/*if (d7_hHeld & KEY_R && d7_hDown & KEY_SELECT)
{
RenderD7::LoadSettings();
}*/
@ -1103,8 +1104,8 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
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;