improvements over the last couple of RGB565 related commits

This commit is contained in:
Wolfvak 2019-05-26 00:03:02 -03:00 committed by d0k3
parent 256f2465d8
commit 8b098fa91a
7 changed files with 39 additions and 31 deletions

View File

@ -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...?

View File

@ -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);
}

View File

@ -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;

View File

@ -3,6 +3,7 @@
#include <stddef.h>
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);

View File

@ -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

View File

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

View File

@ -15,6 +15,7 @@
# ifdef MONITOR_HEAP
#include "mymalloc.h"
#define malloc my_malloc
#define realloc my_realloc
#define free my_free
# endif
#endif