Skip to content

Commit

Permalink
Take screenshots to share your argon gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillem96 committed Jan 2, 2019
1 parent 7de16aa commit d4e757a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/core/custom-gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ bool render_custom_background();
/* Renders custom title, returns false if title.bmp does not exist */
bool render_custom_title();

/* Tool to take screenshots */
int screenshot(void* params);

#endif
54 changes: 54 additions & 0 deletions src/core/custom-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

#include "core/custom-gui.h"
#include "gfx/gfx.h"
#include "mem/heap.h"
#include "utils/fs_utils.h"

#include <string.h>

bool render_custom_background()
{
u8* custom_bg = (u8*)sd_file_read(CUSTOM_BG_PATH);
Expand All @@ -40,3 +43,54 @@ bool render_custom_title()
return true;
}

int screenshot(void* params)
{
//width, height, and bitcount are the key factors:
s32 width = 720;
s32 height = 1280;
u16 bitcount = 32;//<- 24-bit bitmap

//take padding in to account
int width_in_bytes = ((width * bitcount + 31) / 32) * 4;

//total image size in bytes, not including header
u32 imagesize = width_in_bytes * height;

//this value is always 40, it's the sizeof(BITMAPINFOHEADER)
const u32 biSize = 40;

//bitmap bits start after headerfile,
//this is sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
const u32 bfOffBits = 54;

//total file size:
u32 filesize = 54 + imagesize;

//number of planes is usually 1
const u16 biPlanes = 1;

//create header:
//copy to buffer instead of BITMAPFILEHEADER and BITMAPINFOHEADER
//to avoid problems with structure packing
unsigned char header[54] = { 0 };
memcpy(header, "BM", 2);
memcpy(header + 2 , &filesize, 4);
memcpy(header + 10, &bfOffBits, 4);
memcpy(header + 14, &biSize, 4);
memcpy(header + 18, &width, 4);
memcpy(header + 22, &height, 4);
memcpy(header + 26, &biPlanes, 2);
memcpy(header + 28, &bitcount, 2);
memcpy(header + 34, &imagesize, 4);

u8* buff = (u8*)malloc(imagesize + 54);
memcpy(buff, header, 54);
memcpy(buff + 54, g_gfx_ctxt.fb, imagesize);
sd_save_to_file(buff, imagesize + 54, "argon/screenshot.bmp");
free(buff);

g_gfx_con.scale = 2;
gfx_con_setpos(&g_gfx_con, 0, 665);
gfx_printf(&g_gfx_con, " Screenshot saved!\n Found it at argon/screenshot.bmp");
return 0;
}
5 changes: 5 additions & 0 deletions src/menu/gui/gui_argon_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static void generate_payloads_entries(char* payloads, gui_menu_t* menu)
}
}

int screenshot(void*);

/* Init needed menus for ArgonNX */
void gui_init_argon_menu(void)
{
Expand All @@ -112,6 +114,9 @@ void gui_init_argon_menu(void)

generate_payloads_entries(dirlist(PAYLOADS_DIR, "*.bin", false), menu);

gui_menu_append_entry(menu,
gui_create_menu_entry_no_bitmap("Screenshot", 700, 680, 150, 100, (int (*)(void *))screenshot, NULL));

/* Generate reboot rcm and shutdown entry */
gui_menu_append_entry(menu,
gui_create_menu_entry_no_bitmap("Power off", 900, 680, 150, 100, (int (*)(void *))power_off, NULL));
Expand Down

0 comments on commit d4e757a

Please sign in to comment.