Splash previews

This commit is contained in:
2017-09-09 00:12:16 -04:00
parent 1103885baf
commit ef456c7e9e
6 changed files with 75 additions and 9 deletions

View File

@@ -47,4 +47,6 @@ int splash_count;
Result get_splashes(Splash_s** splashes_list, int *splash_count);
void splash_install(Splash_s splash_to_install);
void splash_delete();
void load_splash_preview(Splash_s *splash);
#endif

View File

@@ -121,6 +121,8 @@ void take_picture(void)
}
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
pp2d_draw_texture(TEXTURE_QR, 0, 0);
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Hold \uE005 To Quit");
pp2d_end_draw();
free(rgba8_buf);
pp2d_free_texture(TEXTURE_QR);

View File

@@ -287,12 +287,13 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
pp2d_end_draw();
return;
}
Splash_s current_splash = splashes_list[selected_splash];
if (preview_mode)
{
// TODO: Splash Previews
pp2d_begin_draw(GFX_TOP);
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 0, 0, 400, 240);
pp2d_draw_on(GFX_BOTTOM);
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40, 240, 320, 240);
} else {
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");

View File

@@ -115,7 +115,7 @@ u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
u64 size;
FSFILE_GetSize(file, &size);
*buf = malloc(size);
*buf = calloc(1, size);
FSFILE_Read(file, NULL, 0, *buf, size);
FSFILE_Close(file);
return size;
@@ -139,7 +139,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
unz_file_info *file_info = malloc(sizeof(unz_file_info));
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
file_size = file_info->uncompressed_size;
*buf = malloc(file_size);
*buf = calloc(1, file_size);
unzOpenCurrentFile(zip_handle);
unzReadCurrentFile(zip_handle, *buf, file_size);
unzCloseCurrentFile(zip_handle);

View File

@@ -158,11 +158,17 @@ int main(void)
if (kDown & KEY_Y)
{
if (!preview_mode)
{
if (!splash_mode)
{
if (!current_theme->has_preview)
load_theme_preview(current_theme);
preview_mode = current_theme->has_preview;
} else {
load_splash_preview(current_splash);
preview_mode = true;
}
}
else
preview_mode = false;

View File

@@ -29,6 +29,61 @@
#include "themes.h"
#include "pp2d/pp2d/pp2d.h"
void load_splash_preview(Splash_s *splash)
{
//free the previously loaded preview. wont do anything if there wasnt one
pp2d_free_texture(TEXTURE_PREVIEW);
char *preview_buffer = NULL;
u64 size = 0;
if (!(splash->is_zip))
{
u16 path_to_preview[0x106] = {0};
strucat(path_to_preview, splash->path);
struacat(path_to_preview, "/preview.png");
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
} else {
size = zip_file_to_buf("preview.png", splash->path, &preview_buffer);
}
if (!size)
{
free(preview_buffer);
return;
}
u8 * image = NULL;
unsigned int width = 0, height = 0;
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
if (result == 0) // no error
{
for (u32 i = 0; i < width; i++)
{
for (u32 j = 0; j < height; j++)
{
u32 p = (i + j*width) * 4;
u8 r = *(u8*)(image + p);
u8 g = *(u8*)(image + p + 1);
u8 b = *(u8*)(image + p + 2);
u8 a = *(u8*)(image + p + 3);
*(image + p) = a;
*(image + p + 1) = b;
*(image + p + 2) = g;
*(image + p + 3) = r;
}
}
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
}
free(image);
free(preview_buffer);
}
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
{
char *info_buffer = NULL;