From 8b098fa91a8ae837d445d68e50af76fc24edca89 Mon Sep 17 00:00:00 2001 From: Wolfvak Date: Sun, 26 May 2019 00:03:02 -0300 Subject: [PATCH] improvements over the last couple of RGB565 related commits --- arm9/source/common/screenshot.c | 13 ++++++++----- arm9/source/game/smdh.c | 4 ++-- arm9/source/system/mymalloc.c | 23 +++++++++++++++++++++++ arm9/source/system/mymalloc.h | 1 + arm9/source/system/png.c | 24 ++---------------------- arm9/source/utils/gameutil.c | 4 ++-- common/common.h | 1 + 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/arm9/source/common/screenshot.c b/arm9/source/common/screenshot.c index 93b0dc9..285a633 100644 --- a/arm9/source/common/screenshot.c +++ b/arm9/source/common/screenshot.c @@ -46,15 +46,18 @@ void CreateScreenshot(void) { png = PNG_Compress(buffer, snap_w, snap_h, &png_size); if (png && png_size) { - fvx_qwrite(filename, png, 0, png_size, NULL); + u16 *buffer_top = buffer, *buffer_bottom = buffer + bot_offset; // "snap effect" - /*memcpy(buffer_b, BOT_SCREEN, SCREEN_SIZE_BOT); - memcpy(buffer_t, TOP_SCREEN, SCREEN_SIZE_TOP); + memcpy(buffer_bottom, BOT_SCREEN, SCREEN_SIZE_BOT); + memcpy(buffer_top, TOP_SCREEN, SCREEN_SIZE_TOP); memset(BOT_SCREEN, 0, SCREEN_SIZE_BOT); memset(TOP_SCREEN, 0, SCREEN_SIZE_TOP); - memcpy(BOT_SCREEN, buffer_b, SCREEN_SIZE_BOT); - memcpy(TOP_SCREEN, buffer_t, SCREEN_SIZE_TOP);*/ + + fvx_qwrite(filename, png, 0, png_size, NULL); + + memcpy(BOT_SCREEN, buffer_bottom, SCREEN_SIZE_BOT); + memcpy(TOP_SCREEN, buffer_top, SCREEN_SIZE_TOP); } // what to do on error...? diff --git a/arm9/source/game/smdh.c b/arm9/source/game/smdh.c index 8ad0acd..2720131 100644 --- a/arm9/source/game/smdh.c +++ b/arm9/source/game/smdh.c @@ -47,12 +47,12 @@ u32 GetSmdhPublisher(char* pub, const Smdh* smdh) { return 0; } -// small icons are 24x24 => 0x6C0 byte in RGB888 +// small icons are 24x24 => 0x480 bytes in RGB565 u32 GetSmdhIconSmall(u16* icon, const Smdh* smdh) { return ConvertSmdhIcon(icon, smdh->icon_small, SMDH_DIM_ICON_SMALL, SMDH_DIM_ICON_SMALL); } -// big icons are 48x48 => 0x1B00 byte in RGB888 +// big icons are 48x48 => 0x1200 byte in RGB565 u32 GetSmdhIconBig(u16* icon, const Smdh* smdh) { return ConvertSmdhIcon(icon, smdh->icon_big, SMDH_DIM_ICON_BIG, SMDH_DIM_ICON_BIG); } diff --git a/arm9/source/system/mymalloc.c b/arm9/source/system/mymalloc.c index 09d3ffe..2e2f80b 100644 --- a/arm9/source/system/mymalloc.c +++ b/arm9/source/system/mymalloc.c @@ -10,6 +10,29 @@ void* my_malloc(size_t size) { return ptr ? (((char*) ptr) + sizeof(size_t)) : NULL; } +void *my_realloc(void *ptr, size_t new_size) { + if (!ptr) + return my_malloc(new_size); + + if (ptr && !new_size) { + my_free(ptr); + return NULL; + } + + void *real_ptr = (char*)ptr - sizeof(size_t); + size_t old_size = *(size_t*)real_ptr; + + total_allocated -= old_size; + total_allocated += new_size; + + void *new_ptr = realloc(real_ptr, new_size + sizeof(size_t)); + if (new_ptr) { + return (char*)new_ptr + sizeof(size_t); + } + + return new_ptr; +} + void my_free(void* ptr) { void* ptr_fix = (char*) ptr - sizeof(size_t); total_allocated -= *(size_t*) ptr_fix; diff --git a/arm9/source/system/mymalloc.h b/arm9/source/system/mymalloc.h index f5266f2..42548bd 100644 --- a/arm9/source/system/mymalloc.h +++ b/arm9/source/system/mymalloc.h @@ -3,6 +3,7 @@ #include void* my_malloc(size_t size); +void *my_realloc(void *ptr, size_t new_size); void my_free(void* ptr); size_t mem_allocated(void); size_t my_malloc_test(void); diff --git a/arm9/source/system/png.c b/arm9/source/system/png.c index da4b4e9..8177217 100644 --- a/arm9/source/system/png.c +++ b/arm9/source/system/png.c @@ -4,8 +4,7 @@ #include "lodepng.h" #include "png.h" -#ifndef MONITOR_HEAP -// dest and src can overlap +// dest and src can be the same static inline void _rgb24_to_rgb565(u16 *dest, const u8 *src, size_t dim) { for (size_t i = 0; i < dim; i++) { @@ -18,7 +17,7 @@ static inline void _rgb24_to_rgb565(u16 *dest, const u8 *src, size_t dim) } } -// dest and src CAN NOT overlap +// dest and src CAN NOT be the same static inline void _rgb565_to_rgb24(u8 *dest, const u16 *src, size_t dim) { for (size_t i = 0; i < dim; i++) { @@ -77,22 +76,3 @@ u8 *PNG_Compress(const u16 *fb, u32 w, u32 h, size_t *png_sz) return img; } -#else -u8 *PNG_Decompress(const u8 *png, size_t png_len, u32 *w, u32 *h) -{ - (void) png; - (void) w; - (void) h; - (void) png_len; - return NULL; -} - -u8 *PNG_Compress(u8 *fb, u32 w, u32 h, size_t *png_sz) -{ - (void) fb; - (void) png_sz; - (void) w; - (void) h; - return NULL; -} -#endif diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index 512ebde..d8b4db0 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -1971,7 +1971,7 @@ u32 LoadSmdhFromGameFile(const char* path, Smdh* smdh) { u32 ShowSmdhTitleInfo(Smdh* smdh) { const u8 smdh_magic[] = { SMDH_MAGIC }; const u32 lwrap = 24; - u16 icon[SMDH_SIZE_ICON_BIG]; + u16 icon[SMDH_SIZE_ICON_BIG / sizeof(u16)]; char desc_l[SMDH_SIZE_DESC_LONG+1]; char desc_s[SMDH_SIZE_DESC_SHORT+1]; char pub[SMDH_SIZE_PUBLISHER+1]; @@ -1992,7 +1992,7 @@ u32 ShowSmdhTitleInfo(Smdh* smdh) { u32 ShowTwlIconTitleInfo(TwlIconData* twl_icon) { const u32 lwrap = 24; - u16 icon[TWLICON_SIZE_ICON]; + u16 icon[TWLICON_SIZE_ICON / sizeof(u16)]; char desc[TWLICON_SIZE_DESC+1]; if ((GetTwlIcon(icon, twl_icon) != 0) || (GetTwlTitle(desc, twl_icon) != 0)) diff --git a/common/common.h b/common/common.h index 39c400f..2edb114 100755 --- a/common/common.h +++ b/common/common.h @@ -15,6 +15,7 @@ # ifdef MONITOR_HEAP #include "mymalloc.h" #define malloc my_malloc +#define realloc my_realloc #define free my_free # endif #endif