mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 05:32:47 +00:00
Deprecated PCX code in favor of PNG.
This commit is contained in:
parent
03014a72ee
commit
19209918a7
@ -7,7 +7,7 @@ rwildcard = $(foreach d, $(wildcard $1*), \
|
||||
|
||||
FLAVOR ?= GodMode9
|
||||
README := README.md
|
||||
SPLASH = resources/$(FLAVOR)_splash.pcx
|
||||
SPLASH = resources/$(FLAVOR)_splash.png
|
||||
|
||||
ifeq ($(FLAVOR),SafeMode9)
|
||||
CFLAGS += -DSAFEMODE
|
||||
|
@ -73,7 +73,7 @@ GodMode9 provides access to system data via drives, a listing of what each drive
|
||||
* __`K: AESKEYDB IMAGE`__: An `aeskeydb.bin` image can be mounted and accessed via this drive. The drive shows all keys inside the aeskeydb.bin. This is read-only.
|
||||
* __`T: TICKET.DB IMAGE`__: Ticket database files can be mounted and accessed via this drive. This provides easy and quick access to all tickets inside the `ticket.db`. This is read-only.
|
||||
* __`M: MEMORY VIRTUAL`__: This provides access to various memory regions. This is protected by a special write permission, and caution is advised when doing modifications inside this drive. This drive also gives access to `boot9.bin`, `boot11.bin` (boot9strap only) and `otp.mem` (sighaxed systems only).
|
||||
* __`V: VRAM VIRTUAL`__: This drive resides in the first VRAM bank and contains files essential to GodMode9. The font (in PBM format), the splash logo (in PCX format) and the readme file are found there, as well as any file that is provided inside the `data` folder at build time. This is read-only.
|
||||
* __`V: VRAM VIRTUAL`__: This drive resides in the first VRAM bank and contains files essential to GodMode9. The font (in PBM format), the splash logo (in PNG format) and the readme file are found there, as well as any file that is provided inside the `data` folder at build time. This is read-only.
|
||||
* __`Z: LAST SEARCH`__: After a search operation, search results are found inside this drive. The drive can be accessed at a later point to return to the former search results.
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "keydb.h"
|
||||
#include "ctrtransfer.h"
|
||||
#include "scripting.h"
|
||||
#include "pcx.h"
|
||||
#include "png.h"
|
||||
#include "ui.h" // only for font file detection
|
||||
|
||||
u64 IdentifyFileType(const char* path) {
|
||||
@ -17,7 +17,7 @@ u64 IdentifyFileType(const char* path) {
|
||||
const u8 tickdb_magic[] = { TICKDB_MAGIC };
|
||||
const u8 smdh_magic[] = { SMDH_MAGIC };
|
||||
const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC };
|
||||
const u8 pcx_magic[] = { PCX_MAGIC };
|
||||
const u8 png_magic[] = { PNG_MAGIC };
|
||||
|
||||
if (!path) return 0; // safety
|
||||
u8 header[0x200] __attribute__((aligned(32))); // minimum required size
|
||||
@ -118,9 +118,9 @@ u64 IdentifyFileType(const char* path) {
|
||||
(GetNcchInfoVersion((NcchInfoHeader*) data)) &&
|
||||
(strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) {
|
||||
return BIN_NCCHNFO; // ncchinfo.bin file
|
||||
} else if ((fsize > sizeof(pcx_magic)) && (memcmp(data, pcx_magic, sizeof(pcx_magic)) == 0) &&
|
||||
(strncasecmp(ext, "pcx", 4) == 0)) {
|
||||
return GFX_PCX;
|
||||
} else if ((strncasecmp(ext, "png", 4) == 0) &&
|
||||
(fsize > sizeof(png_magic)) && (memcmp(data, png_magic, sizeof(png_magic)) == 0)) {
|
||||
return GFX_PNG;
|
||||
} else if (ext && ((strncasecmp(ext, "cdn", 4) == 0) || (strncasecmp(ext, "nus", 4) == 0))) {
|
||||
char path_cetk[256];
|
||||
char* ext_cetk = path_cetk + (ext - path);
|
||||
|
@ -29,7 +29,7 @@
|
||||
#define BIN_LEGKEY (1ULL<<24)
|
||||
#define TXT_SCRIPT (1ULL<<25)
|
||||
#define TXT_GENERIC (1ULL<<26)
|
||||
#define GFX_PCX (1ULL<<27)
|
||||
#define GFX_PNG (1ULL<<27)
|
||||
#define FONT_PBM (1ULL<<28)
|
||||
#define NOIMG_NAND (1ULL<<29)
|
||||
#define HDR_NAND (1ULL<<30)
|
||||
@ -65,7 +65,7 @@
|
||||
#define FTYPE_KEYINSTALL(tp) (tp&(BIN_KEYDB))
|
||||
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
|
||||
#define FTYPE_FONT(tp) (tp&(FONT_PBM))
|
||||
#define FTYPE_GFX(tp) (tp&(GFX_PCX))
|
||||
#define FTYPE_GFX(tp) (tp&(GFX_PNG))
|
||||
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
|
||||
#define FTYPE_INSTALLABLE(tp) (tp&(SYS_FIRM))
|
||||
#define FTPYE_AGBSAVE(tp) (tp&(SYS_AGBSAVE))
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "unittype.h"
|
||||
#include "entrypoints.h"
|
||||
#include "bootfirm.h"
|
||||
#include "pcx.h"
|
||||
#include "png.h"
|
||||
#include "timer.h"
|
||||
#include "rtc.h"
|
||||
#include "power.h"
|
||||
@ -47,8 +47,9 @@ typedef struct {
|
||||
|
||||
u32 SplashInit(const char* modestr) {
|
||||
u64 splash_size;
|
||||
u8* splash = FindVTarFileInfo(VRAM0_SPLASH_PCX, &splash_size);
|
||||
u8* bitmap = (u8*) malloc(SCREEN_SIZE_TOP);
|
||||
u32 splash_width, splash_height;
|
||||
u8* splash = FindVTarFileInfo(VRAM0_SPLASH_PNG, &splash_size);
|
||||
u8* bitmap = NULL;
|
||||
const char* namestr = FLAVOR " " VERSION;
|
||||
const char* loadstr = "booting...";
|
||||
const u32 pos_xb = 10;
|
||||
@ -58,10 +59,11 @@ u32 SplashInit(const char* modestr) {
|
||||
|
||||
ClearScreenF(true, true, COLOR_STD_BG);
|
||||
|
||||
if (splash && bitmap && PCX_Decompress(bitmap, SCREEN_SIZE_TOP, splash, splash_size)) {
|
||||
PCXHdr* hdr = (PCXHdr*) (void*) splash;
|
||||
DrawBitmap(TOP_SCREEN, -1, -1, PCX_Width(hdr), PCX_Height(hdr), bitmap);
|
||||
} else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(" VRAM0_SPLASH_PCX " not found)");
|
||||
if (splash) {
|
||||
bitmap = PNG_Decompress(splash, splash_size, &splash_width, &splash_height);
|
||||
DrawBitmap(TOP_SCREEN, -1, -1, splash_width, splash_height, bitmap);
|
||||
} else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(" VRAM0_SPLASH_PNG " not found)");
|
||||
|
||||
if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr),
|
||||
SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr);
|
||||
|
||||
@ -406,27 +408,20 @@ u32 SdFormatMenu(void) {
|
||||
u32 FileGraphicsViewer(const char* path) {
|
||||
const u32 max_size = SCREEN_SIZE(ALT_SCREEN);
|
||||
u64 filetype = IdentifyFileType(path);
|
||||
u8* bitmap = (u8*) malloc(max_size);
|
||||
u8* bitmap = NULL;
|
||||
u8* input = (u8*)malloc(max_size);
|
||||
u32 w = 0;
|
||||
u32 h = 0;
|
||||
u32 ret = 1;
|
||||
|
||||
if (!bitmap || !input) {
|
||||
if (bitmap) free(bitmap);
|
||||
if (input) free(input);
|
||||
return 1;
|
||||
}
|
||||
if (!input)
|
||||
return ret;
|
||||
|
||||
u32 input_size = FileGetData(path, input, max_size, 0);
|
||||
if (input_size && (input_size < max_size)) {
|
||||
if (filetype & GFX_PCX) {
|
||||
if (PCX_Decompress(bitmap, max_size, input, input_size)) {
|
||||
PCXHdr* hdr = (PCXHdr*) (void*) input;
|
||||
w = PCX_Width(hdr);
|
||||
h = PCX_Height(hdr);
|
||||
ret = 0;
|
||||
}
|
||||
if (filetype & GFX_PNG) {
|
||||
bitmap = PNG_Decompress(input, input_size, &w, &h);
|
||||
if (bitmap != NULL) ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,8 +433,8 @@ u32 FileGraphicsViewer(const char* path) {
|
||||
ClearScreenF(true, true, COLOR_STD_BG);
|
||||
} else ret = 1;
|
||||
|
||||
free(bitmap);
|
||||
free(input);
|
||||
if (bitmap) free(bitmap);
|
||||
if (input) free(input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1091,7 +1086,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
|
||||
(filetype & BIN_NCCHNFO)? "NCCHinfo options..." :
|
||||
(filetype & TXT_SCRIPT) ? "Execute GM9 script" :
|
||||
(filetype & FONT_PBM) ? "Set as active font" :
|
||||
(filetype & GFX_PCX) ? "View PCX bitmap file" :
|
||||
(filetype & GFX_PNG) ? "View PNG file" :
|
||||
(filetype & HDR_NAND) ? "Rebuild NCSD header" :
|
||||
(filetype & NOIMG_NAND) ? "Rebuild NCSD header" : "???";
|
||||
optionstr[hexviewer-1] = "Show in Hexeditor";
|
||||
@ -1265,7 +1260,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
|
||||
if (install > 0) optionstr[install-1] = "Install FIRM";
|
||||
if (boot > 0) optionstr[boot-1] = "Boot FIRM";
|
||||
if (script > 0) optionstr[script-1] = "Execute GM9 script";
|
||||
if (view > 0) optionstr[font-1] = "View PCX bitmap file";
|
||||
if (view > 0) optionstr[view-1] = "View PNG file";
|
||||
if (font > 0) optionstr[font-1] = "Set as active font";
|
||||
if (agbexport > 0) optionstr[agbexport-1] = "Dump GBA VC save";
|
||||
if (agbimport > 0) optionstr[agbimport-1] = "Inject GBA VC save";
|
||||
@ -1730,7 +1725,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
|
||||
}
|
||||
else if (user_select == view) { // view gfx
|
||||
if (FileGraphicsViewer(file_path) != 0)
|
||||
ShowPrompt(false, "%s\nError: Cannot view file");
|
||||
ShowPrompt(false, "%s\nError: Cannot view file\n(Hint: maybe it's too big)", pathstr);
|
||||
return 0;
|
||||
}
|
||||
else if (user_select == agbexport) { // export GBA VC save
|
||||
|
@ -1,62 +0,0 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "pcx.h"
|
||||
|
||||
// Define __PCX_INVERT_RGB to have the buffer output in BGR24
|
||||
#define __PCX_INVERT_RGB
|
||||
|
||||
|
||||
static inline int PCX_Validate(const PCXHdr *hdr) {
|
||||
return (hdr != NULL &&
|
||||
hdr->manufacturer == 10 &&
|
||||
PCX_Encoding(hdr) == 1 &&
|
||||
PCX_PlaneCount(hdr) == 1 &&
|
||||
PCX_BitsPerPixel(hdr) == 8) ? 1 : 0;
|
||||
}
|
||||
|
||||
int PCX_Decompress(u8 *out_buf, size_t out_maxlen, const u8 *pcx_data, size_t pcx_len) {
|
||||
const PCXHdr *pcx = (const PCXHdr*)pcx_data;
|
||||
const u8 *pcx_palette, *out_start, *out_end, *pcx_bitmap, *pcx_end;
|
||||
int mrk, palind;
|
||||
|
||||
if (PCX_Validate(pcx) == 0 || (size_t) (PCX_BitmapSize(pcx) * 3) > out_maxlen)
|
||||
return -1;
|
||||
|
||||
pcx_end = pcx_data + pcx_len - 769;
|
||||
out_end = out_buf + out_maxlen;
|
||||
out_start = out_buf;
|
||||
pcx_bitmap = PCX_Bitmap(pcx);
|
||||
pcx_palette = PCX_Palette(pcx, pcx_len);
|
||||
|
||||
while (pcx_bitmap < pcx_end && out_buf < out_end) {
|
||||
mrk = *(pcx_bitmap++);
|
||||
|
||||
if (mrk >= 0xC0) {
|
||||
mrk -= 0xC0;
|
||||
palind = *(pcx_bitmap++) * 3;
|
||||
|
||||
if ((out_buf + mrk) > out_end) {
|
||||
// TODO: report the buffer overflow somehow
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
palind = mrk * 3;
|
||||
mrk = 1;
|
||||
}
|
||||
|
||||
while (mrk--) {
|
||||
#ifdef __PCX_INVERT_RGB
|
||||
*(out_buf++) = pcx_palette[palind + 2];
|
||||
*(out_buf++) = pcx_palette[palind + 1];
|
||||
*(out_buf++) = pcx_palette[palind + 0];
|
||||
#else
|
||||
*(out_buf++) = pcx_palette[palind + 0];
|
||||
*(out_buf++) = pcx_palette[palind + 1];
|
||||
*(out_buf++) = pcx_palette[palind + 2];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return (out_buf - out_start);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#define PCX_MAGIC 0x0A, 0x05, 0x01, 0x08
|
||||
|
||||
typedef struct {
|
||||
u8 manufacturer;
|
||||
u8 version;
|
||||
u8 enc;
|
||||
u8 bpp;
|
||||
u16 minx;
|
||||
u16 miny;
|
||||
u16 maxx;
|
||||
u16 maxy;
|
||||
u16 hres;
|
||||
u16 vres;
|
||||
u8 egapalette[48];
|
||||
u8 reserved;
|
||||
u8 clrplanes;
|
||||
u16 bytesperline;
|
||||
u16 palettetype;
|
||||
u8 resv_[58];
|
||||
} __attribute__((packed)) PCXHdr;
|
||||
|
||||
#define PCX_Width(hdr) (hdr->maxx - hdr->minx + 1)
|
||||
#define PCX_Height(hdr) (hdr->maxy - hdr->miny + 1)
|
||||
#define PCX_BitsPerPixel(hdr) (hdr->bpp)
|
||||
#define PCX_BitmapSize(hdr) (PCX_Width(hdr) * PCX_Height(hdr))
|
||||
#define PCX_MaxColors(hdr) (1<<PCX_BitsPerPixel(hdr))
|
||||
#define PCX_PlaneCount(hdr) (hdr->clrplanes)
|
||||
#define PCX_Encoding(hdr) (hdr->enc)
|
||||
#define PCX_Palette(hdr, pcx_len) (((u8*)hdr) + pcx_len - 768)
|
||||
#define PCX_Bitmap(hdr) (((u8*)hdr) + sizeof(PCXHdr))
|
||||
|
||||
int PCX_Decompress(u8 *out_buf, size_t out_maxlen, const u8 *pcx_data, size_t pcx_len);
|
@ -6,17 +6,15 @@
|
||||
|
||||
#include "ui.h"
|
||||
|
||||
u8 *PNG_Decompress(const u8 *png, size_t png_len, size_t *w, size_t *h)
|
||||
u8 *PNG_Decompress(const u8 *png, size_t png_len, u32 *w, u32 *h)
|
||||
{
|
||||
u8 *img;
|
||||
u32 res;
|
||||
size_t w_, h_;
|
||||
|
||||
res = lodepng_decode24(&img, &w_, &h_, png, png_len);
|
||||
if (res) {
|
||||
ShowPrompt(false, "PNG error: %s", lodepng_error_text(res));
|
||||
if (res)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// maybe process in batches of 3 pixels / 12 bytes at a time?
|
||||
for (size_t i = 0; i < (w_ * h_ * 3); i += 3) {
|
||||
|
@ -4,4 +4,6 @@
|
||||
#include "common.h"
|
||||
#include "lodepng/lodepng.h"
|
||||
|
||||
u8 *PNG_Decompress(const u8 *png, size_t png_len, size_t *w, size_t *h);
|
||||
#define PNG_MAGIC 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A
|
||||
|
||||
u8 *PNG_Decompress(const u8 *png, size_t png_len, u32 *w, u32 *h);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define VRAM0_FONT_PBM "font_default.pbm"
|
||||
#define VRAM0_SCRIPTS "scripts"
|
||||
#define VRAM0_README_MD "README.md"
|
||||
#define VRAM0_SPLASH_PCX FLAVOR "_splash.pcx"
|
||||
#define VRAM0_SPLASH_PNG FLAVOR "_splash.png"
|
||||
|
||||
|
||||
#define VRAM0_OFFSET 0x18000000
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "sha.h"
|
||||
#include "hid.h"
|
||||
#include "ui.h"
|
||||
#include "pcx.h"
|
||||
#include "png.h"
|
||||
|
||||
|
||||
#define _MAX_ARGS 4
|
||||
@ -1657,20 +1657,25 @@ bool ExecuteGM9Script(const char* path_script) {
|
||||
ClearScreen(TOP_SCREEN, COLOR_STD_BG);
|
||||
if (preview_mode > 2) {
|
||||
char* preview_str = get_var("PREVIEW_MODE", NULL);
|
||||
u32 pcx_size = fvx_qsize(preview_str);
|
||||
u8* pcx = (u8*) malloc(SCREEN_SIZE_TOP);
|
||||
u8* bitmap = (u8*) malloc(SCREEN_SIZE_TOP);
|
||||
if (pcx && bitmap && pcx_size && (pcx_size < SCREEN_SIZE_TOP) &&
|
||||
(pcx_size == FileGetData(preview_str, pcx, pcx_size, 0)) &&
|
||||
(PCX_Decompress(bitmap, SCREEN_SIZE_TOP, pcx, pcx_size))) {
|
||||
PCXHdr* hdr = (PCXHdr*) (void*) pcx;
|
||||
DrawBitmap(TOP_SCREEN, -1, -1, PCX_Width(hdr), PCX_Height(hdr), bitmap);
|
||||
u32 bitmap_width, bitmap_height;
|
||||
u8* bitmap = NULL;
|
||||
|
||||
u8* png = (u8*) malloc(SCREEN_SIZE_TOP);
|
||||
if (png) {
|
||||
u32 png_size = FileGetData(preview_str, png, SCREEN_SIZE_TOP, 0);
|
||||
if (png_size && png_size < SCREEN_SIZE_TOP)
|
||||
bitmap = PNG_Decompress(png, png_size, &bitmap_width, &bitmap_height);
|
||||
free(png);
|
||||
}
|
||||
|
||||
if (bitmap) {
|
||||
DrawBitmap(TOP_SCREEN, -1, -1, bitmap_width, bitmap_height, bitmap);
|
||||
free(bitmap);
|
||||
} else {
|
||||
if (strncmp(preview_str, "off", _VAR_CNT_LEN) == 0) preview_str = "(preview disabled)";
|
||||
DrawStringCenter(TOP_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, preview_str);
|
||||
}
|
||||
if (pcx) free(pcx);
|
||||
if (bitmap) free(bitmap);
|
||||
|
||||
preview_mode = 0;
|
||||
}
|
||||
preview_mode_local = preview_mode;
|
||||
|
Binary file not shown.
BIN
resources/GodMode9_splash.png
Normal file
BIN
resources/GodMode9_splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
BIN
resources/SafeMode9_splash.png
Normal file
BIN
resources/SafeMode9_splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -106,10 +106,10 @@ labelsel -o -s "Select a preview mode." lsmenu_*
|
||||
goto lsmain
|
||||
|
||||
# So, here's our example menu. It shows off the new PREVIEW_MODE settings if you were
|
||||
# not already familiar with them (you can use a path to a .pcx file or plain text in quotes).
|
||||
# not already familiar with them (you can use a path to a .png file or plain text in quotes).
|
||||
|
||||
@lsmenu_Image
|
||||
set PREVIEW_MODE V:/GodMode9_splash.pcx
|
||||
set PREVIEW_MODE V:/GodMode9_splash.png
|
||||
echo "This is image preview mode."
|
||||
goto resume_script
|
||||
|
||||
@ -161,7 +161,7 @@ strsplit MENUCHOICE $[FULLCHOICE] "/"
|
||||
# Now that we have our menu selection nice and trimmed, time to process it.
|
||||
|
||||
if chk $[MENUCHOICE] "Image"
|
||||
set PREVIEW_MODE V:/GodMode9_splash.pcx
|
||||
set PREVIEW_MODE V:/GodMode9_splash.png
|
||||
echo "This is image preview mode."
|
||||
elif chk $[MENUCHOICE] "Text"
|
||||
set PREVIEW_MODE "GodMode9"
|
||||
|
@ -22,8 +22,8 @@ elif ask "?set PREVIEW_MODE quick?"
|
||||
set PREVIEW_MODE quick
|
||||
elif ask "?set PREVIEW_MODE full?"
|
||||
set PREVIEW_MODE full
|
||||
elif ask "?set PREVIEW_MODE V:/GodMode9_splash.pcx?"
|
||||
set PREVIEW_MODE V:/GodMode9_splash.pcx
|
||||
elif ask "?set PREVIEW_MODE V:/GodMode9_splash.png?"
|
||||
set PREVIEW_MODE V:/GodMode9_splash.png
|
||||
elif ask "?set PREVIEW_MODE 'No preview for you, sorry'?"
|
||||
set PREVIEW_MODE "No preview for you, sorry"
|
||||
else
|
||||
@ -52,8 +52,8 @@ goto chooser
|
||||
set PREVIEW_MODE full
|
||||
goto chooser
|
||||
|
||||
@choice_Preview_PCX
|
||||
set PREVIEW_MODE V:/GodMode9_splash.pcx
|
||||
@choice_Preview_png
|
||||
set PREVIEW_MODE V:/GodMode9_splash.png
|
||||
goto chooser
|
||||
|
||||
@choice_Preview_custom
|
||||
|
Loading…
x
Reference in New Issue
Block a user