├── README.es.txt ├── lib ├── libpng.a └── libwiilight.a ├── data └── background ├── source ├── stub.S ├── menu.h ├── wad.h ├── gui.h ├── restart.h ├── sys.h ├── wpad.h ├── utils.h ├── usbstorage.h ├── title.h ├── wkb.h ├── nand.h ├── video.h ├── restart.c ├── fat.h ├── wkb.c ├── fat.c ├── gui.c ├── wpad.c ├── globals.h ├── nand.c ├── sys.c ├── video.c ├── title.c ├── usbstorage.c ├── wad.c ├── libpng │ ├── pngu │ │ ├── pngu.h │ │ └── pngu.c │ └── pngconf.h ├── wad-manager.c └── menu.c ├── channel ├── WadManager 1.4 wiiNinja.wad ├── WadManager.v1.4.with.Folders.Animated.Channel.wad └── WadManager1.4.Sorg.wiiNinja.Mod2.Animated.Channel.wad ├── include └── wiilight.h ├── Revisions.txt ├── README.Enh.Mod.txt ├── wm_config.txt ├── README.txt ├── wad-manager-with-dir.pnproj ├── Readme.Mod.txt ├── Makefile └── LICENSE.txt /README.es.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/README.es.txt -------------------------------------------------------------------------------- /lib/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/lib/libpng.a -------------------------------------------------------------------------------- /data/background: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/data/background -------------------------------------------------------------------------------- /lib/libwiilight.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/lib/libwiilight.a -------------------------------------------------------------------------------- /source/stub.S: -------------------------------------------------------------------------------- 1 | .rodata 2 | 3 | .globl bgData 4 | .balign 32 5 | bgData: 6 | .incbin "../data/background" 7 | -------------------------------------------------------------------------------- /source/menu.h: -------------------------------------------------------------------------------- 1 | #ifndef _MENU_H_ 2 | #define _MENU_H_ 3 | 4 | /* Prototypes */ 5 | void Menu_Loop(void); 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /channel/WadManager 1.4 wiiNinja.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/channel/WadManager 1.4 wiiNinja.wad -------------------------------------------------------------------------------- /source/wad.h: -------------------------------------------------------------------------------- 1 | #ifndef _WAD_H_ 2 | #define _WAD_H_ 3 | 4 | /* Prototypes */ 5 | s32 Wad_Install(FILE *); 6 | s32 Wad_Uninstall(FILE *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /source/gui.h: -------------------------------------------------------------------------------- 1 | #ifndef _GUI_H_ 2 | #define _GUI_H_ 3 | 4 | /* Prototypes */ 5 | void Gui_InitConsole(void); 6 | void Gui_DrawBackground(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /source/restart.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESTART_H_ 2 | #define _RESTART_H_ 3 | 4 | /* Prototypes */ 5 | void Restart(void); 6 | void Restart_Wait(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /channel/WadManager.v1.4.with.Folders.Animated.Channel.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/channel/WadManager.v1.4.with.Folders.Animated.Channel.wad -------------------------------------------------------------------------------- /channel/WadManager1.4.Sorg.wiiNinja.Mod2.Animated.Channel.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torne/Wad-Manager-with-Directory/master/channel/WadManager1.4.Sorg.wiiNinja.Mod2.Animated.Channel.wad -------------------------------------------------------------------------------- /include/wiilight.h: -------------------------------------------------------------------------------- 1 | void WIILIGHT_Init(); 2 | void WIILIGHT_TurnOn(); 3 | int WIILIGHT_GetLevel(); 4 | int WIILIGHT_SetLevel(int level); 5 | 6 | void WIILIGHT_Toggle(); 7 | void WIILIGHT_TurnOff(); 8 | -------------------------------------------------------------------------------- /source/sys.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_H_ 2 | #define _SYS_H_ 3 | 4 | /* Prototypes */ 5 | void Sys_Init(void); 6 | void Sys_Reboot(void); 7 | void Sys_Shutdown(void); 8 | void Sys_LoadMenu(void); 9 | s32 Sys_GetCerts(signed_blob **, u32 *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /source/wpad.h: -------------------------------------------------------------------------------- 1 | #ifndef _WPAD_H_ 2 | #define _WPAD_H_ 3 | 4 | #include 5 | 6 | /* Prototypes */ 7 | s32 Wpad_Init(void); 8 | void Wpad_Disconnect(void); 9 | u32 Wpad_GetButtons(void); 10 | u32 Wpad_WaitButtons(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /source/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | /* Constants */ 5 | #define KB_SIZE 1024.0 6 | #define MB_SIZE 1048576.0 7 | #define GB_SIZE 1073741824.0 8 | 9 | /* Macros */ 10 | #define round_up(x,n) (-(-(x) & -(n))) 11 | 12 | /* Prototypes */ 13 | u32 swap32(u32); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /source/usbstorage.h: -------------------------------------------------------------------------------- 1 | #ifndef _USBSTORAGE_H_ 2 | #define _USBSTORAGE_H_ 3 | 4 | /* Prototypes */ 5 | s32 USBStorage_GetCapacity(u32 *); 6 | 7 | bool USBStorage_Init(void); 8 | bool USBStorage_Deinit(void); 9 | bool USBStorage_ReadSectors(u32, u32, void *); 10 | bool USBStorage_WriteSectors(u32, u32, void *); 11 | 12 | /* Disc interface */ 13 | extern const DISC_INTERFACE __io_usb2storage; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /source/title.h: -------------------------------------------------------------------------------- 1 | #ifndef _TITLE_H_ 2 | #define _TITLE_H_ 3 | 4 | /* Constants */ 5 | #define BLOCK_SIZE 1024 6 | 7 | /* Prototypes */ 8 | s32 Title_GetList(u64 **, u32 *); 9 | s32 Title_GetTicketViews(u64, tikview **, u32 *); 10 | s32 Title_GetTMD(u64, signed_blob **, u32 *); 11 | s32 Title_GetVersion(u64, u16 *); 12 | s32 Title_GetSysVersion(u64, u64 *); 13 | s32 Title_GetSize(u64, u32 *); 14 | s32 Title_GetIOSVersions(u8 **, u32 *); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /source/wkb.h: -------------------------------------------------------------------------------- 1 | #ifndef _WKB_H_ 2 | #define _WKB_H_ 3 | 4 | //#include 5 | //#include 6 | //#include 7 | //#include 8 | #include // u8, u16, etc... 9 | 10 | #include 11 | #include 12 | 13 | /* Prototypes */ 14 | s32 WkbInit(void); 15 | u32 WkbWaitKey (void); 16 | //void Wpad_Disconnect(void); 17 | //u32 Wpad_GetButtons(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /source/nand.h: -------------------------------------------------------------------------------- 1 | #ifndef _NAND_H_ 2 | #define _NAND_H_ 3 | 4 | /* 'NAND Device' structure */ 5 | typedef struct { 6 | /* Device name */ 7 | char *name; 8 | 9 | /* Mode value */ 10 | u32 mode; 11 | 12 | /* Un/mount command */ 13 | u32 mountCmd; 14 | u32 umountCmd; 15 | } nandDevice; 16 | 17 | 18 | /* Prototypes */ 19 | s32 Nand_Mount(nandDevice *); 20 | s32 Nand_Unmount(nandDevice *); 21 | s32 Nand_Enable(nandDevice *); 22 | s32 Nand_Disable(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /source/video.h: -------------------------------------------------------------------------------- 1 | #ifndef _VIDEO_H_ 2 | #define _VIDEO_H_ 3 | 4 | #include "libpng/pngu/pngu.h" 5 | 6 | /* Prototypes */ 7 | void Con_Init(u32, u32, u32, u32); 8 | void Con_Clear(void); 9 | void Con_ClearLine(void); 10 | void Con_FgColor(u32, u8); 11 | void Con_BgColor(u32, u8); 12 | void Con_FillRow(u32, u32, u8); 13 | 14 | void Video_Configure(GXRModeObj *); 15 | void Video_SetMode(void); 16 | void Video_Clear(s32); 17 | void Video_DrawPng(IMGCTX, PNGUPROP, u16, u16); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Revisions.txt: -------------------------------------------------------------------------------- 1 | 2 | 2009-05-09: Original version from Waninkoko's v1.4 3 | 4 | 2009-05-09: mod1 - With folders support 5 | 6 | 2009-05-13: mod2 - When entering a subfolder, the cursor will be at the top of the page. 7 | 8 | 2009-07-28: v1.5 from Waninkoko 9 | 10 | 2009-07-29: v1.5.mod1 - FOlder support for v1.5 11 | 12 | 2009-07-29: v1.5.mod2 - Added wm_config.txt with password and startupPath 13 | 14 | 2009-07-30: v1.5.mod3 - Added to wm_config.txt: cIOS select, Wad Source path, and Nand source path 15 | Added wiilight by mariomaniac33 16 | -------------------------------------------------------------------------------- /README.Enh.Mod.txt: -------------------------------------------------------------------------------- 1 | read ReadMe.txt and ReadMe.Mod.txt before 2 | 3 | This enhanced mod based on WAD Manager 1.4 Mod v1 by wiiNinja. 4 | 5 | Includes enhancements: 6 | - Device selection combined with IOS selection for shorter startup. 7 | - Bigger console window with 16 entries per page (instead 8) 8 | - browse from root(/) folder (intead of /wad) 9 | - "B" button returns to parent folder until root. On root - returns to device selection. 10 | - remember/restore list position on enter/exit directory 11 | - remember last used IOS when back to device selection (instead forced IOS249) 12 | - fixes for some minor bugs 13 | 14 | Sorg. 15 | -------------------------------------------------------------------------------- /source/restart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "nand.h" 5 | #include "sys.h" 6 | #include "wpad.h" 7 | #include "video.h" 8 | 9 | 10 | void Restart(void) 11 | { 12 | Con_Clear (); 13 | printf("\n Restarting Wii..."); 14 | fflush(stdout); 15 | 16 | /* Disable NAND emulator */ 17 | Nand_Disable(); 18 | 19 | /* Load system menu */ 20 | Sys_LoadMenu(); 21 | } 22 | 23 | void Restart_Wait(void) 24 | { 25 | printf("\n"); 26 | 27 | printf(" Press any button to restart..."); 28 | fflush(stdout); 29 | 30 | /* Wait for button */ 31 | Wpad_WaitButtons(); 32 | 33 | /* Restart */ 34 | Restart(); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /source/fat.h: -------------------------------------------------------------------------------- 1 | #ifndef _FAT_H_ 2 | #define _FAT_H_ 3 | 4 | /* libfat header */ 5 | #include 6 | #include 7 | 8 | /* SD headers */ 9 | #include 10 | #include 11 | 12 | 13 | /* 'FAT Device' structure */ 14 | typedef struct { 15 | /* Device mount point */ 16 | char *mount; 17 | 18 | /* Device name */ 19 | char *name; 20 | 21 | /* Device interface */ 22 | const DISC_INTERFACE *interface; 23 | } fatDevice; 24 | 25 | /* 'FAT File' structure */ 26 | typedef struct { 27 | /* Filename */ 28 | char filename[128]; 29 | 30 | /* Filestat */ 31 | struct stat filestat; 32 | } fatFile; 33 | 34 | 35 | /* Prototypes */ 36 | s32 Fat_Mount(fatDevice *); 37 | void Fat_Unmount(fatDevice *); 38 | char *Fat_ToFilename(const char *); 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /source/wkb.c: -------------------------------------------------------------------------------- 1 | #include "wkb.h" 2 | 3 | /* 4 | 5 | s32 USBKeyboard_Open(const eventcallback cb); 6 | void USBKeyboard_Close(void); 7 | 8 | bool USBKeyboard_IsConnected(void); 9 | s32 USBKeyboard_Scan(void); 10 | 11 | s32 USBKeyboard_SetLed(const USBKeyboard_led led, bool on); 12 | s32 USBKeyboard_ToggleLed(const USBKeyboard_led led); 13 | */ 14 | 15 | s32 WkbInit(void) 16 | { 17 | s32 retval = 0; 18 | 19 | retval = USBKeyboard_Initialize(); 20 | 21 | return (retval); 22 | 23 | } // WkbInit 24 | 25 | s32 WkbDeInit(void) 26 | { 27 | s32 retval = 0; 28 | 29 | retval = USBKeyboard_Deinitialize(); 30 | 31 | return (retval); 32 | 33 | } // WkbDeInit 34 | 35 | u32 WkbWaitKey (void) 36 | { 37 | u32 retval = 0; 38 | 39 | // Stub 40 | return (retval); 41 | 42 | } // WkbWaitKey 43 | 44 | //void Wpad_Disconnect(void); 45 | //u32 Wpad_GetButtons(void); 46 | 47 | 48 | -------------------------------------------------------------------------------- /source/fat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "fat.h" 6 | 7 | 8 | s32 Fat_Mount(fatDevice *dev) 9 | { 10 | s32 ret; 11 | 12 | /* Initialize interface */ 13 | ret = dev->interface->startup(); 14 | if (!ret) 15 | return -1; 16 | 17 | /* Mount device */ 18 | ret = fatMountSimple(dev->mount, dev->interface); 19 | if (!ret) 20 | return -1; 21 | 22 | return 0; 23 | } 24 | 25 | void Fat_Unmount(fatDevice *dev) 26 | { 27 | /* Unmount device */ 28 | fatUnmount(dev->mount); 29 | 30 | /* Shutdown interface */ 31 | dev->interface->shutdown(); 32 | } 33 | 34 | char *Fat_ToFilename(const char *filename) 35 | { 36 | static char buffer[128]; 37 | 38 | u32 cnt, idx, len; 39 | 40 | /* Clear buffer */ 41 | memset(buffer, 0, sizeof(buffer)); 42 | 43 | /* Get filename length */ 44 | len = strlen(filename); 45 | 46 | for (cnt = idx = 0; idx < len; idx++) { 47 | char c = filename[idx]; 48 | 49 | /* Valid characters */ 50 | if ( (c >= '#' && c <= ')') || (c >= '-' && c <= '.') || 51 | (c >= '0' && c <= '9') || (c >= 'A' && c <= 'z') || 52 | (c >= 'a' && c <= 'z') || (c == '!') ) 53 | buffer[cnt++] = c; 54 | } 55 | 56 | return buffer; 57 | } 58 | -------------------------------------------------------------------------------- /source/gui.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "video.h" 6 | 7 | /* Constants */ 8 | #define CONSOLE_XCOORD 48 9 | #define CONSOLE_YCOORD 94 10 | #define CONSOLE_WIDTH 544 11 | #define CONSOLE_HEIGHT 336 12 | 13 | 14 | s32 __Gui_DrawPng(void *img, u32 x, u32 y) 15 | { 16 | IMGCTX ctx = NULL; 17 | PNGUPROP imgProp; 18 | 19 | s32 ret; 20 | 21 | /* Select PNG data */ 22 | ctx = PNGU_SelectImageFromBuffer(img); 23 | if (!ctx) { 24 | ret = -1; 25 | goto out; 26 | } 27 | 28 | /* Get image properties */ 29 | ret = PNGU_GetImageProperties(ctx, &imgProp); 30 | if (ret != PNGU_OK) { 31 | ret = -1; 32 | goto out; 33 | } 34 | 35 | /* Draw image */ 36 | Video_DrawPng(ctx, imgProp, x, y); 37 | 38 | /* Success */ 39 | ret = 0; 40 | 41 | out: 42 | /* Free memory */ 43 | if (ctx) 44 | PNGU_ReleaseImageContext(ctx); 45 | 46 | return ret; 47 | } 48 | 49 | 50 | void Gui_InitConsole(void) 51 | { 52 | /* Initialize console */ 53 | Con_Init(CONSOLE_XCOORD, CONSOLE_YCOORD, CONSOLE_WIDTH, CONSOLE_HEIGHT); 54 | } 55 | 56 | void Gui_DrawBackground(void) 57 | { 58 | extern char bgData[]; 59 | 60 | /* Draw background */ 61 | __Gui_DrawPng(bgData, 0, 0); 62 | } 63 | -------------------------------------------------------------------------------- /wm_config.txt: -------------------------------------------------------------------------------- 1 | ;Config file format 2 | ; 3 | ; wm_config.txt resides in sd:/wad, and it is optional. You will get all the 4 | ; prompts if you don't have this file. 5 | ; The param keywords are case-sensitive at this point. 6 | ; No spaces precede the keyword on a line 7 | ; If you don't have a password in the config file, the default is no password 8 | ; If you don't have a startupPath, the default is /wad 9 | ; If you don't have any of the other parameters, it will prompt you for it 10 | ; To bypass any of the params, just comment out the line using a ";" at the beginning of the line 11 | ; Blank lines are ignored. 12 | ; 13 | ; Password=your_password (LRUD only, where L=left, R=right, U=up, D=down on the 14 | ; WiiMote or GC Controller, max 10 characters) 15 | ; StartupPath=startupPath (starting at the root dir "/"). Be sure that the path exists, 16 | ; else you will get an error. 17 | ; 18 | Password=UDLRUD 19 | 20 | ; StartupPath: 21 | StartupPath=/wad 22 | 23 | ; cIOS: 249, 222, whatever 24 | cIOSVersion=249 25 | 26 | ; FatDevice: sd usb usb2 gcsda gcsdb 27 | FatDevice=sd 28 | 29 | ; NANDDevice: Disable SD USB 30 | ; Note that WM will prompt for NAND device only if you selected cIOS=249 31 | NANDDevice=Disable 32 | -------------------------------------------------------------------------------- /source/wpad.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "sys.h" 5 | #include "wpad.h" 6 | //#include "wkb.h" 7 | 8 | /* Constants */ 9 | #define MAX_WIIMOTES 4 10 | 11 | 12 | void __Wpad_PowerCallback(s32 chan) 13 | { 14 | /* Poweroff console */ 15 | Sys_Shutdown(); 16 | } 17 | 18 | 19 | s32 Wpad_Init(void) 20 | { 21 | s32 ret; 22 | 23 | /* Initialize Wiimote subsystem */ 24 | ret = WPAD_Init(); 25 | if (ret < 0) 26 | return ret; 27 | 28 | /* Set POWER button callback */ 29 | WPAD_SetPowerButtonCallback(__Wpad_PowerCallback); 30 | 31 | return ret; 32 | } 33 | 34 | void Wpad_Disconnect(void) 35 | { 36 | u32 cnt; 37 | 38 | /* Disconnect Wiimotes */ 39 | for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) 40 | WPAD_Disconnect(cnt); 41 | 42 | /* Shutdown Wiimote subsystem */ 43 | WPAD_Shutdown(); 44 | } 45 | 46 | u32 Wpad_GetButtons(void) 47 | { 48 | u32 buttons = 0, cnt; 49 | 50 | /* Scan pads */ 51 | WPAD_ScanPads(); 52 | 53 | /* Get pressed buttons */ 54 | for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) 55 | buttons |= WPAD_ButtonsDown(cnt); 56 | 57 | return buttons; 58 | } 59 | 60 | u32 Wpad_WaitButtons(void) 61 | { 62 | u32 buttons = 0; 63 | 64 | /* Wait for button pressing */ 65 | while (!buttons) { 66 | buttons = Wpad_GetButtons(); 67 | VIDEO_WaitVSync(); 68 | } 69 | 70 | return buttons; 71 | } 72 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | +----------------------------+ 2 | | WAD Manager v1.5 | 3 | | developed by Waninkoko | 4 | +----------------------------+ 5 | | www.teknoconsolas.es | 6 | +----------------------------+ 7 | 8 | 9 | [ DISCLAIMER ]: 10 | 11 | - THIS APPLICATION COMES WITH NO WARRANTY AT ALL, NEITHER EXPRESS NOR IMPLIED. 12 | I DO NOT TAKE ANY RESPONSIBILITY FOR ANY DAMAGE IN YOUR WII CONSOLE 13 | BECAUSE OF A IMPROPER USAGE OF THIS SOFTWARE. 14 | 15 | 16 | [ DESCRIPTION ]: 17 | 18 | - WAD Manager is an application that allows you to (un)install 19 | WAD packages. 20 | 21 | It lists all the available WAD packages in a storage device 22 | so you can select which one to (un)install. 23 | 24 | 25 | [ SUPPORTED DEVICES ]: 26 | 27 | - SDGecko. 28 | - Internal SD slot (with SDHC support). 29 | - USB device (1.1 and 2.0). 30 | 31 | 32 | [ HOW TO USE ]: 33 | 34 | 1. Create a folder called "wad" in the root of the storage device. 35 | 2. Copy all the WAD packages in the folder created in the step 1. 36 | 3. Run the application with any method to load homebrew. 37 | 38 | 39 | [ NOTES ]: 40 | 41 | - To use the NAND emulation is necessary to have a COMPLETE copy 42 | of the NAND filesystem in the root of the FAT device. 43 | 44 | 45 | [ KUDOS ]: 46 | 47 | - Team Twiizers/devkitPRO 48 | - svpe 49 | - kwiirk 50 | - All my betatesters. 51 | -------------------------------------------------------------------------------- /source/globals.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOBALS_H_ 2 | #define _GLOBALS_H_ 3 | 4 | // Constants 5 | #define CIOS_VERSION 249 6 | #define ENTRIES_PER_PAGE 16 7 | #define MAX_FILE_PATH_LEN 1024 8 | #define MAX_DIR_LEVELS 10 9 | #define WAD_DIRECTORY "/" 10 | #define WAD_ROOT_DIRECTORY "/wad" 11 | 12 | #define MAX_PASSWORD_LENGTH 10 13 | #define MAX_FAT_DEVICE_LENGTH 10 14 | #define MAX_NAND_DEVICE_LENGTH 10 15 | 16 | #define WM_CONFIG_FILE_PATH "sd:/wad/wm_config.txt" 17 | 18 | 19 | // These are indices into the fatDevice fdevList 20 | #define FAT_DEVICE_INDEX_WII_SD 0 21 | #define FAT_DEVICE_INDXE_USB 1 22 | #define FAT_DEVICE_INDEX_USB2 2 23 | #define FAT_DEVICE_INDEX_GC_SDA 3 24 | #define FAT_DEVICE_INDEX_GC_SDB 4 25 | #define FAT_DEVICE_INDEX_INVALID -1 26 | 27 | // These are the indices into the nandDevice ndevList 28 | #define NAND_DEVICE_INDEX_DISABLE 0 29 | #define NAND_DEVICE_INDEX_SD 1 30 | #define NAND_DEVICE_INDEX_USB 2 31 | #define NAND_DEVICE_INDEX_INVALID -1 32 | 33 | #define CIOS_VERSION_INVALID -1 34 | 35 | // For the WiiLight 36 | #define WII_LIGHT_OFF 0 37 | #define WII_LIGHT_ON 1 38 | 39 | typedef struct 40 | { 41 | char password[MAX_PASSWORD_LENGTH]; 42 | char startupPath [256]; 43 | int cIOSVersion; 44 | int fatDeviceIndex; 45 | int nandDeviceIndex; 46 | } CONFIG; 47 | 48 | 49 | extern CONFIG gConfig; 50 | extern nandDevice ndevList[]; 51 | extern fatDevice fdevList[]; 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /source/nand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "nand.h" 5 | 6 | /* Buffer */ 7 | static u32 inbuf[8] ATTRIBUTE_ALIGN(32); 8 | 9 | 10 | s32 Nand_Mount(nandDevice *dev) 11 | { 12 | s32 fd, ret; 13 | 14 | /* Open FAT module */ 15 | fd = IOS_Open("fat", 0); 16 | if (fd < 0) 17 | return fd; 18 | 19 | /* Mount device */ 20 | ret = IOS_Ioctlv(fd, dev->mountCmd, 0, 0, NULL); 21 | 22 | /* Close FAT module */ 23 | IOS_Close(fd); 24 | 25 | return ret; 26 | } 27 | 28 | s32 Nand_Unmount(nandDevice *dev) 29 | { 30 | s32 fd, ret; 31 | 32 | /* Open FAT module */ 33 | fd = IOS_Open("fat", 0); 34 | if (fd < 0) 35 | return fd; 36 | 37 | /* Unmount device */ 38 | ret = IOS_Ioctlv(fd, dev->umountCmd, 0, 0, NULL); 39 | 40 | /* Close FAT module */ 41 | IOS_Close(fd); 42 | 43 | return ret; 44 | } 45 | 46 | s32 Nand_Enable(nandDevice *dev) 47 | { 48 | s32 fd, ret; 49 | 50 | /* Open /dev/fs */ 51 | fd = IOS_Open("/dev/fs", 0); 52 | if (fd < 0) 53 | return fd; 54 | 55 | /* Set input buffer */ 56 | inbuf[0] = dev->mode; 57 | 58 | /* Enable NAND emulator */ 59 | ret = IOS_Ioctl(fd, 100, inbuf, sizeof(inbuf), NULL, 0); 60 | 61 | /* Close /dev/fs */ 62 | IOS_Close(fd); 63 | 64 | return ret; 65 | } 66 | 67 | s32 Nand_Disable(void) 68 | { 69 | s32 fd, ret; 70 | 71 | /* Open /dev/fs */ 72 | fd = IOS_Open("/dev/fs", 0); 73 | if (fd < 0) 74 | return fd; 75 | 76 | /* Set input buffer */ 77 | inbuf[0] = 0; 78 | 79 | /* Disable NAND emulator */ 80 | ret = IOS_Ioctl(fd, 100, inbuf, sizeof(inbuf), NULL, 0); 81 | 82 | /* Close /dev/fs */ 83 | IOS_Close(fd); 84 | 85 | return ret; 86 | } 87 | -------------------------------------------------------------------------------- /wad-manager-with-dir.pnproj: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/sys.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "sys.h" 6 | 7 | /* Constants */ 8 | #define CERTS_LEN 0x280 9 | 10 | /* Variables */ 11 | static const char certs_fs[] ATTRIBUTE_ALIGN(32) = "/sys/cert.sys"; 12 | 13 | 14 | void __Sys_ResetCallback(void) 15 | { 16 | /* Reboot console */ 17 | Sys_Reboot(); 18 | } 19 | 20 | void __Sys_PowerCallback(void) 21 | { 22 | /* Poweroff console */ 23 | Sys_Shutdown(); 24 | } 25 | 26 | 27 | void Sys_Init(void) 28 | { 29 | /* Initialize video subsytem */ 30 | VIDEO_Init(); 31 | 32 | /* Set RESET/POWER button callback */ 33 | SYS_SetResetCallback(__Sys_ResetCallback); 34 | SYS_SetPowerCallback(__Sys_PowerCallback); 35 | } 36 | 37 | void Sys_Reboot(void) 38 | { 39 | /* Restart console */ 40 | STM_RebootSystem(); 41 | } 42 | 43 | void Sys_Shutdown(void) 44 | { 45 | /* Poweroff console */ 46 | if(CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE) { 47 | s32 ret; 48 | 49 | /* Set LED mode */ 50 | ret = CONF_GetIdleLedMode(); 51 | if(ret >= 0 && ret <= 2) 52 | STM_SetLedMode(ret); 53 | 54 | /* Shutdown to idle */ 55 | STM_ShutdownToIdle(); 56 | } else { 57 | /* Shutdown to standby */ 58 | STM_ShutdownToStandby(); 59 | } 60 | } 61 | 62 | void Sys_LoadMenu(void) 63 | { 64 | u32 *stub = (u32 *)0x80001800; 65 | 66 | /* Homebrew Channel stub */ 67 | if (*stub) 68 | exit(0); 69 | 70 | /* Return to the Wii system menu */ 71 | SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); 72 | } 73 | 74 | s32 Sys_GetCerts(signed_blob **certs, u32 *len) 75 | { 76 | static signed_blob certificates[CERTS_LEN] ATTRIBUTE_ALIGN(32); 77 | 78 | s32 fd, ret; 79 | 80 | /* Open certificates file */ 81 | fd = IOS_Open(certs_fs, 1); 82 | if (fd < 0) 83 | return fd; 84 | 85 | /* Read certificates */ 86 | ret = IOS_Read(fd, certificates, sizeof(certificates)); 87 | 88 | /* Close file */ 89 | IOS_Close(fd); 90 | 91 | /* Set values */ 92 | if (ret > 0) { 93 | *certs = certificates; 94 | *len = sizeof(certificates); 95 | } 96 | 97 | return ret; 98 | } 99 | -------------------------------------------------------------------------------- /Readme.Mod.txt: -------------------------------------------------------------------------------- 1 | I built this for my own use, but thought I'd share. 2 | 3 | This is based from Waninkoko's Wad Manager v1.4. I added support for the 4 | wad manager to handle folders. Use it as you would with the original wad 5 | manager, only now you can have up to 9 levels of folder under the "wad" 6 | folder. 7 | 8 | Summary: 9 | 10 | * The sd:\wad folder now can have folders in it 11 | * Each folder can have up to 9 directories deep 12 | * I've tested install/uninstall wads 13 | * I've tested traversing directories 14 | * I noticed that some directories may appear as all upper case. I don't know why; but 15 | it does not interfere with the function of the wad manager, so I just leave it alone. 16 | * I have not tried directories with spaces in the names. I don't think anything 17 | detrimental will happen, since the wad file names can have spaces in them 18 | 19 | If you use it and find anomalies, please let me know. 20 | 21 | wiiNinja 22 | 5/9/2009 23 | ------------------------------------------------------ 24 | 25 | Sorg's Enhancements: 26 | 27 | read ReadMe.txt and ReadMe.Mod.txt before 28 | 29 | This enhanced mod based on WAD Manager 1.4 Mod v1 by wiiNinja. 30 | 31 | Includes enhancements: 32 | - Device selection combined with IOS selection for shorter startup. 33 | - Bigger console window with 16 entries per page (instead 8) 34 | - browse from root(/) folder (intead of /wad) 35 | - "B" button returns to parent folder until root. On root - returns to device selection. 36 | - remember/restore list position on enter/exit directory 37 | - remember last used IOS when back to device selection (instead forced IOS249) 38 | - fixes for some minor bugs 39 | 40 | Sorg. 41 | 42 | ------------------------------------------------------ 43 | 5/15/2009-wiiNinja 44 | 45 | * Added support for the GameCube controller. This is a feature most everyone won't 46 | use normally, but will be needed in some SHTF situations. 47 | 48 | 7/29/2009: v1.5.Mod2 49 | 50 | * Merged Waninkoko's v1.5 51 | * Added stuff password 52 | * Added startupPath 53 | * Added handling from wm_config.txt in sd:/wad 54 | 55 | 8/1/2009: v1.5.Mod3 56 | 57 | * Added to wm_config.txt: cIOS select, Wad Source path, and Nand source path 58 | * Added wiilight mod by mariomaniac33 59 | -------------------------------------------------------------------------------- /source/video.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "sys.h" 5 | #include "video.h" 6 | 7 | /* Video variables */ 8 | static void *framebuffer = NULL; 9 | static GXRModeObj *vmode = NULL; 10 | 11 | 12 | void Con_Init(u32 x, u32 y, u32 w, u32 h) 13 | { 14 | /* Create console in the framebuffer */ 15 | CON_InitEx(vmode, x, y, w, h); 16 | } 17 | 18 | void Con_Clear(void) 19 | { 20 | /* Clear console */ 21 | printf("\x1b[2J"); 22 | fflush(stdout); 23 | } 24 | 25 | void Con_ClearLine(void) 26 | { 27 | s32 cols, rows; 28 | u32 cnt; 29 | 30 | printf("\r"); 31 | fflush(stdout); 32 | 33 | /* Get console metrics */ 34 | CON_GetMetrics(&cols, &rows); 35 | 36 | /* Erase line */ 37 | for (cnt = 1; cnt < cols; cnt++) { 38 | printf(" "); 39 | fflush(stdout); 40 | } 41 | 42 | printf("\r"); 43 | fflush(stdout); 44 | } 45 | 46 | void Con_FgColor(u32 color, u8 bold) 47 | { 48 | /* Set foreground color */ 49 | printf("\x1b[%u;%um", color + 30, bold); 50 | fflush(stdout); 51 | } 52 | 53 | void Con_BgColor(u32 color, u8 bold) 54 | { 55 | /* Set background color */ 56 | printf("\x1b[%u;%um", color + 40, bold); 57 | fflush(stdout); 58 | } 59 | 60 | void Con_FillRow(u32 row, u32 color, u8 bold) 61 | { 62 | s32 cols, rows; 63 | u32 cnt; 64 | 65 | /* Set color */ 66 | printf("\x1b[%u;%um", color + 40, bold); 67 | fflush(stdout); 68 | 69 | /* Get console metrics */ 70 | CON_GetMetrics(&cols, &rows); 71 | 72 | /* Save current row and col */ 73 | printf("\x1b[s"); 74 | fflush(stdout); 75 | 76 | /* Move to specified row */ 77 | printf("\x1b[%u;0H", row); 78 | fflush(stdout); 79 | 80 | /* Fill row */ 81 | for (cnt = 0; cnt < cols; cnt++) { 82 | printf(" "); 83 | fflush(stdout); 84 | } 85 | 86 | /* Load saved row and col */ 87 | printf("\x1b[u"); 88 | fflush(stdout); 89 | 90 | /* Set default color */ 91 | Con_BgColor(0, 0); 92 | Con_FgColor(7, 1); 93 | } 94 | 95 | void Video_Configure(GXRModeObj *rmode) 96 | { 97 | /* Configure the video subsystem */ 98 | VIDEO_Configure(rmode); 99 | 100 | /* Setup video */ 101 | VIDEO_SetBlack(FALSE); 102 | VIDEO_Flush(); 103 | VIDEO_WaitVSync(); 104 | 105 | if (rmode->viTVMode & VI_NON_INTERLACE) 106 | VIDEO_WaitVSync(); 107 | } 108 | 109 | void Video_SetMode(void) 110 | { 111 | /* Select preferred video mode */ 112 | vmode = VIDEO_GetPreferredMode(NULL); 113 | 114 | /* Allocate memory for the framebuffer */ 115 | framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); 116 | 117 | /* Configure the video subsystem */ 118 | VIDEO_Configure(vmode); 119 | 120 | /* Setup video */ 121 | VIDEO_SetNextFramebuffer(framebuffer); 122 | VIDEO_SetBlack(FALSE); 123 | VIDEO_Flush(); 124 | VIDEO_WaitVSync(); 125 | 126 | if (vmode->viTVMode & VI_NON_INTERLACE) 127 | VIDEO_WaitVSync(); 128 | 129 | /* Clear the screen */ 130 | Video_Clear(COLOR_BLACK); 131 | } 132 | 133 | void Video_Clear(s32 color) 134 | { 135 | VIDEO_ClearFrameBuffer(vmode, framebuffer, color); 136 | } 137 | 138 | void Video_DrawPng(IMGCTX ctx, PNGUPROP imgProp, u16 x, u16 y) 139 | { 140 | PNGU_DECODE_TO_COORDS_YCbYCr(ctx, x, y, imgProp.imgWidth, imgProp.imgHeight, vmode->fbWidth, vmode->xfbHeight, framebuffer); 141 | } 142 | -------------------------------------------------------------------------------- /source/title.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "utils.h" 8 | 9 | 10 | s32 Title_GetList(u64 **outbuf, u32 *outlen) 11 | { 12 | u64 *titles = NULL; 13 | 14 | u32 len, nb_titles; 15 | s32 ret; 16 | 17 | /* Get number of titles */ 18 | ret = ES_GetNumTitles(&nb_titles); 19 | if (ret < 0) 20 | return ret; 21 | 22 | /* Calculate buffer lenght */ 23 | len = round_up(sizeof(u64) * nb_titles, 32); 24 | 25 | /* Allocate memory */ 26 | titles = memalign(32, len); 27 | if (!titles) 28 | return -1; 29 | 30 | /* Get titles */ 31 | ret = ES_GetTitles(titles, nb_titles); 32 | if (ret < 0) 33 | goto err; 34 | 35 | /* Set values */ 36 | *outbuf = titles; 37 | *outlen = nb_titles; 38 | 39 | return 0; 40 | 41 | err: 42 | /* Free memory */ 43 | if (titles) 44 | free(titles); 45 | 46 | return ret; 47 | } 48 | 49 | s32 Title_GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen) 50 | { 51 | tikview *views = NULL; 52 | 53 | u32 nb_views; 54 | s32 ret; 55 | 56 | /* Get number of ticket views */ 57 | ret = ES_GetNumTicketViews(tid, &nb_views); 58 | if (ret < 0) 59 | return ret; 60 | 61 | /* Allocate memory */ 62 | views = (tikview *)memalign(32, sizeof(tikview) * nb_views); 63 | if (!views) 64 | return -1; 65 | 66 | /* Get ticket views */ 67 | ret = ES_GetTicketViews(tid, views, nb_views); 68 | if (ret < 0) 69 | goto err; 70 | 71 | /* Set values */ 72 | *outbuf = views; 73 | *outlen = nb_views; 74 | 75 | return 0; 76 | 77 | err: 78 | /* Free memory */ 79 | if (views) 80 | free(views); 81 | 82 | return ret; 83 | } 84 | 85 | s32 Title_GetTMD(u64 tid, signed_blob **outbuf, u32 *outlen) 86 | { 87 | void *p_tmd = NULL; 88 | 89 | u32 len; 90 | s32 ret; 91 | 92 | /* Get TMD size */ 93 | ret = ES_GetStoredTMDSize(tid, &len); 94 | if (ret < 0) 95 | return ret; 96 | 97 | /* Allocate memory */ 98 | p_tmd = memalign(32, round_up(len, 32)); 99 | if (!p_tmd) 100 | return -1; 101 | 102 | /* Read TMD */ 103 | ret = ES_GetStoredTMD(tid, p_tmd, len); 104 | if (ret < 0) 105 | goto err; 106 | 107 | /* Set values */ 108 | *outbuf = p_tmd; 109 | *outlen = len; 110 | 111 | return 0; 112 | 113 | err: 114 | /* Free memory */ 115 | if (p_tmd) 116 | free(p_tmd); 117 | 118 | return ret; 119 | } 120 | 121 | s32 Title_GetVersion(u64 tid, u16 *outbuf) 122 | { 123 | signed_blob *p_tmd = NULL; 124 | tmd *tmd_data = NULL; 125 | 126 | u32 len; 127 | s32 ret; 128 | 129 | /* Get title TMD */ 130 | ret = Title_GetTMD(tid, &p_tmd, &len); 131 | if (ret < 0) 132 | return ret; 133 | 134 | /* Retrieve TMD info */ 135 | tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); 136 | 137 | /* Set values */ 138 | *outbuf = tmd_data->title_version; 139 | 140 | /* Free memory */ 141 | free(p_tmd); 142 | 143 | return 0; 144 | } 145 | 146 | s32 Title_GetSysVersion(u64 tid, u64 *outbuf) 147 | { 148 | signed_blob *p_tmd = NULL; 149 | tmd *tmd_data = NULL; 150 | 151 | u32 len; 152 | s32 ret; 153 | 154 | /* Get title TMD */ 155 | ret = Title_GetTMD(tid, &p_tmd, &len); 156 | if (ret < 0) 157 | return ret; 158 | 159 | /* Retrieve TMD info */ 160 | tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); 161 | 162 | /* Set values */ 163 | *outbuf = tmd_data->sys_version; 164 | 165 | /* Free memory */ 166 | free(p_tmd); 167 | 168 | return 0; 169 | } 170 | 171 | s32 Title_GetSize(u64 tid, u32 *outbuf) 172 | { 173 | signed_blob *p_tmd = NULL; 174 | tmd *tmd_data = NULL; 175 | 176 | u32 cnt, len, size = 0; 177 | s32 ret; 178 | 179 | /* Get title TMD */ 180 | ret = Title_GetTMD(tid, &p_tmd, &len); 181 | if (ret < 0) 182 | return ret; 183 | 184 | /* Retrieve TMD info */ 185 | tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); 186 | 187 | /* Calculate title size */ 188 | for (cnt = 0; cnt < tmd_data->num_contents; cnt++) { 189 | tmd_content *content = &tmd_data->contents[cnt]; 190 | 191 | /* Add content size */ 192 | size += content->size; 193 | } 194 | 195 | /* Set values */ 196 | *outbuf = size; 197 | 198 | /* Free memory */ 199 | free(p_tmd); 200 | 201 | return 0; 202 | } 203 | 204 | s32 Title_GetIOSVersions(u8 **outbuf, u32 *outlen) 205 | { 206 | u8 *buffer = NULL; 207 | u64 *list = NULL; 208 | 209 | u32 count, cnt, idx; 210 | s32 ret; 211 | 212 | /* Get title list */ 213 | ret = Title_GetList(&list, &count); 214 | if (ret < 0) 215 | return ret; 216 | 217 | /* Count IOS */ 218 | for (cnt = idx = 0; idx < count; idx++) { 219 | u32 tidh = (list[idx] >> 32); 220 | u32 tidl = (list[idx] & 0xFFFFFFFF); 221 | 222 | /* Title is IOS */ 223 | if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255)) 224 | cnt++; 225 | } 226 | 227 | /* Allocate memory */ 228 | buffer = (u8 *)memalign(32, cnt); 229 | if (!buffer) { 230 | ret = -1; 231 | goto out; 232 | } 233 | 234 | /* Copy IOS */ 235 | for (cnt = idx = 0; idx < count; idx++) { 236 | u32 tidh = (list[idx] >> 32); 237 | u32 tidl = (list[idx] & 0xFFFFFFFF); 238 | 239 | /* Title is IOS */ 240 | if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255)) 241 | buffer[cnt++] = (u8)(tidl & 0xFF); 242 | } 243 | 244 | /* Set values */ 245 | *outbuf = buffer; 246 | *outlen = cnt; 247 | 248 | goto out; 249 | 250 | out: 251 | /* Free memory */ 252 | if (list) 253 | free(list); 254 | 255 | return ret; 256 | } 257 | -------------------------------------------------------------------------------- /source/usbstorage.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------- 2 | 3 | usbstorage_starlet.c -- USB mass storage support, inside starlet 4 | Copyright (C) 2009 Kwiirk 5 | 6 | If this driver is linked before libogc, this will replace the original 7 | usbstorage driver by svpe from libogc 8 | This software is provided 'as-is', without any express or implied 9 | warranty. In no event will the authors be held liable for any 10 | damages arising from the use of this software. 11 | 12 | Permission is granted to anyone to use this software for any 13 | purpose, including commercial applications, and to alter it and 14 | redistribute it freely, subject to the following restrictions: 15 | 16 | 1. The origin of this software must not be misrepresented; you 17 | must not claim that you wrote the original software. If you use 18 | this software in a product, an acknowledgment in the product 19 | documentation would be appreciated but is not required. 20 | 21 | 2. Altered source versions must be plainly marked as such, and 22 | must not be misrepresented as being the original software. 23 | 24 | 3. This notice may not be removed or altered from any source 25 | distribution. 26 | 27 | -------------------------------------------------------------*/ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /* IOCTL commands */ 35 | #define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) 36 | #define USB_IOCTL_UMS_INIT (UMS_BASE+0x1) 37 | #define USB_IOCTL_UMS_GET_CAPACITY (UMS_BASE+0x2) 38 | #define USB_IOCTL_UMS_READ_SECTORS (UMS_BASE+0x3) 39 | #define USB_IOCTL_UMS_WRITE_SECTORS (UMS_BASE+0x4) 40 | #define USB_IOCTL_UMS_READ_STRESS (UMS_BASE+0x5) 41 | #define USB_IOCTL_UMS_SET_VERBOSE (UMS_BASE+0x6) 42 | 43 | #define UMS_HEAPSIZE 0x8000 44 | 45 | /* Variables */ 46 | static char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb/ehc"; 47 | 48 | static s32 hid = -1, fd = -1; 49 | static u32 sector_size; 50 | 51 | 52 | inline s32 __USBStorage_isMEM2Buffer(const void *buffer) 53 | { 54 | u32 high_addr = ((u32)buffer) >> 24; 55 | 56 | return (high_addr == 0x90) || (high_addr == 0xD0); 57 | } 58 | 59 | 60 | s32 USBStorage_GetCapacity(u32 *_sector_size) 61 | { 62 | if (fd > 0) { 63 | s32 ret; 64 | 65 | ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", §or_size); 66 | 67 | if (ret && _sector_size) 68 | *_sector_size = sector_size; 69 | 70 | return ret; 71 | } 72 | 73 | return IPC_ENOENT; 74 | } 75 | 76 | bool USBStorage_Init(void) 77 | { 78 | s32 ret; 79 | 80 | /* Already open */ 81 | if (fd > 0) 82 | return 0; 83 | 84 | /* Create heap */ 85 | if (hid < 0) { 86 | hid = iosCreateHeap(UMS_HEAPSIZE); 87 | if (hid < 0) 88 | return false; 89 | } 90 | 91 | /* Open USB device */ 92 | fd = IOS_Open(fs, 0); 93 | if (fd < 0) 94 | return false; 95 | 96 | /* Initialize USB storage */ 97 | IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":"); 98 | 99 | /* Get device capacity */ 100 | ret = USBStorage_GetCapacity(NULL); 101 | if (!ret) 102 | goto err; 103 | 104 | return true; 105 | 106 | err: 107 | /* Close USB device */ 108 | if (fd > 0) { 109 | IOS_Close(fd); 110 | fd = -1; 111 | } 112 | 113 | return false; 114 | } 115 | 116 | bool USBStorage_Deinit(void) 117 | { 118 | /* Close USB device */ 119 | if (fd > 0) { 120 | IOS_Close(fd); 121 | fd = -1; 122 | } 123 | 124 | return true; 125 | } 126 | 127 | bool USBStorage_IsInserted(void) 128 | { 129 | return (USBStorage_GetCapacity(NULL)) ? true : false; 130 | } 131 | 132 | bool USBStorage_ReadSectors(u32 sector, u32 numSectors, void *buffer) 133 | { 134 | void *buf = (void *)buffer; 135 | u32 len = (sector_size * numSectors); 136 | 137 | s32 ret; 138 | 139 | /* Device not opened */ 140 | if (fd < 0) 141 | return false; 142 | 143 | /* MEM1 buffer */ 144 | if (!__USBStorage_isMEM2Buffer(buffer)) { 145 | /* Allocate memory */ 146 | buf = iosAlloc(hid, len); 147 | if (!buf) 148 | return false; 149 | } 150 | 151 | /* Read data */ 152 | ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", sector, numSectors, buf, len); 153 | 154 | /* Copy data */ 155 | if (buf != buffer) { 156 | memcpy(buffer, buf, len); 157 | iosFree(hid, buf); 158 | } 159 | 160 | return true; 161 | } 162 | 163 | bool USBStorage_WriteSectors(u32 sector, u32 numSectors, const void *buffer) 164 | { 165 | void *buf = (void *)buffer; 166 | u32 len = (sector_size * numSectors); 167 | 168 | s32 ret; 169 | 170 | /* Device not opened */ 171 | if (fd < 0) 172 | return false; 173 | 174 | /* MEM1 buffer */ 175 | if (!__USBStorage_isMEM2Buffer(buffer)) { 176 | /* Allocate memory */ 177 | buf = iosAlloc(hid, len); 178 | if (!buf) 179 | return false; 180 | 181 | /* Copy data */ 182 | memcpy(buf, buffer, len); 183 | } 184 | 185 | /* Write data */ 186 | ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, numSectors, buf, len); 187 | 188 | /* Free memory */ 189 | if (buf != buffer) 190 | iosFree(hid, buf); 191 | 192 | return true; 193 | } 194 | 195 | bool USBStorage_ClearStatus(void) 196 | { 197 | return true; 198 | } 199 | 200 | 201 | const DISC_INTERFACE __io_usb2storage = { 202 | DEVICE_TYPE_WII_USB, 203 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_USB, 204 | (FN_MEDIUM_STARTUP)&USBStorage_Init, 205 | (FN_MEDIUM_ISINSERTED)&USBStorage_IsInserted, 206 | (FN_MEDIUM_READSECTORS)&USBStorage_ReadSectors, 207 | (FN_MEDIUM_WRITESECTORS)&USBStorage_WriteSectors, 208 | (FN_MEDIUM_CLEARSTATUS)&USBStorage_ClearStatus, 209 | (FN_MEDIUM_SHUTDOWN)&USBStorage_Deinit 210 | }; 211 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | #DEVKITPRO = /opt/devkitPPC 7 | #DEVKITPPC = /opt/devkitPPC 8 | 9 | ifeq ($(strip $(DEVKITPPC)),) 10 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 11 | endif 12 | 13 | include $(DEVKITPPC)/wii_rules 14 | 15 | #--------------------------------------------------------------------------------- 16 | # TARGET is the name of the output 17 | # BUILD is the directory where object files & intermediate files will be placed 18 | # SOURCES is a list of directories containing source code 19 | # INCLUDES is a list of directories containing extra header files 20 | #--------------------------------------------------------------------------------- 21 | TARGET := $(notdir $(CURDIR)) 22 | BUILD := build 23 | SOURCES := source include source/libpng source/libpng/pngu 24 | DATA := data 25 | INCLUDES := 26 | 27 | #--------------------------------------------------------------------------------- 28 | # options for code generation 29 | #--------------------------------------------------------------------------------- 30 | 31 | CFLAGS = -Os -Wall $(MACHDEP) $(INCLUDE) 32 | CXXFLAGS = $(CFLAGS) 33 | 34 | LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map 35 | 36 | #--------------------------------------------------------------------------------- 37 | # any extra libraries we wish to link with the project 38 | #--------------------------------------------------------------------------------- 39 | LIBS := -lpng -lfat -lwiiuse -lbte -logc -lm -lz -lwiilight 40 | 41 | #--------------------------------------------------------------------------------- 42 | # list of directories containing libraries, this must be the top level containing 43 | # include and lib 44 | #--------------------------------------------------------------------------------- 45 | LIBDIRS := $(CURDIR) 46 | 47 | #--------------------------------------------------------------------------------- 48 | # no real need to edit anything past this point unless you need to add additional 49 | # rules for different file extensions 50 | #--------------------------------------------------------------------------------- 51 | ifneq ($(BUILD),$(notdir $(CURDIR))) 52 | #--------------------------------------------------------------------------------- 53 | 54 | export OUTPUT := $(CURDIR)/$(TARGET) 55 | 56 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | 70 | #--------------------------------------------------------------------------------- 71 | # use CXX for linking C++ projects, CC for standard C 72 | #--------------------------------------------------------------------------------- 73 | ifeq ($(strip $(CPPFILES)),) 74 | export LD := $(CC) 75 | else 76 | export LD := $(CXX) 77 | endif 78 | 79 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 80 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 81 | $(sFILES:.s=.o) $(SFILES:.S=.o) 82 | 83 | #--------------------------------------------------------------------------------- 84 | # build a list of include paths 85 | #--------------------------------------------------------------------------------- 86 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 87 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 88 | -I$(CURDIR)/$(BUILD) \ 89 | -I$(LIBOGC_INC) 90 | 91 | #--------------------------------------------------------------------------------- 92 | # build a list of library paths 93 | #--------------------------------------------------------------------------------- 94 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 95 | -L$(LIBOGC_LIB) 96 | 97 | export OUTPUT := $(CURDIR)/$(TARGET) 98 | .PHONY: $(BUILD) clean 99 | 100 | #--------------------------------------------------------------------------------- 101 | $(BUILD): 102 | @[ -d $@ ] || mkdir -p $@ 103 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 104 | 105 | #--------------------------------------------------------------------------------- 106 | clean: 107 | @echo clean ... 108 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 109 | 110 | #--------------------------------------------------------------------------------- 111 | run: 112 | wiiload $(TARGET).dol 113 | 114 | 115 | #--------------------------------------------------------------------------------- 116 | else 117 | 118 | DEPENDS := $(OFILES:.o=.d) 119 | 120 | #--------------------------------------------------------------------------------- 121 | # main targets 122 | #--------------------------------------------------------------------------------- 123 | $(OUTPUT).dol: $(OUTPUT).elf 124 | $(OUTPUT).elf: $(OFILES) 125 | 126 | #--------------------------------------------------------------------------------- 127 | # This rule links in binary data with the .jpg extension 128 | #--------------------------------------------------------------------------------- 129 | %.jpg.o : %.jpg 130 | #--------------------------------------------------------------------------------- 131 | @echo $(notdir $<) 132 | $(bin2o) 133 | 134 | -include $(DEPENDS) 135 | 136 | #--------------------------------------------------------------------------------- 137 | endif 138 | #--------------------------------------------------------------------------------- 139 | 140 | -------------------------------------------------------------------------------- /source/wad.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "title.h" 7 | #include "utils.h" 8 | #include "video.h" 9 | #include "wad.h" 10 | 11 | /* 'WAD Header' structure */ 12 | typedef struct { 13 | /* Header length */ 14 | u32 header_len; 15 | 16 | /* WAD type */ 17 | u16 type; 18 | 19 | u16 padding; 20 | 21 | /* Data length */ 22 | u32 certs_len; 23 | u32 crl_len; 24 | u32 tik_len; 25 | u32 tmd_len; 26 | u32 data_len; 27 | u32 footer_len; 28 | } ATTRIBUTE_PACKED wadHeader; 29 | 30 | /* Variables */ 31 | static u8 wadBuffer[BLOCK_SIZE] ATTRIBUTE_ALIGN(32); 32 | 33 | 34 | s32 __Wad_ReadFile(FILE *fp, void *outbuf, u32 offset, u32 len) 35 | { 36 | s32 ret; 37 | 38 | /* Seek to offset */ 39 | fseek(fp, offset, SEEK_SET); 40 | 41 | /* Read data */ 42 | ret = fread(outbuf, len, 1, fp); 43 | if (ret < 0) 44 | return ret; 45 | 46 | return 0; 47 | } 48 | 49 | s32 __Wad_ReadAlloc(FILE *fp, void **outbuf, u32 offset, u32 len) 50 | { 51 | void *buffer = NULL; 52 | s32 ret; 53 | 54 | /* Allocate memory */ 55 | buffer = memalign(32, len); 56 | if (!buffer) 57 | return -1; 58 | 59 | /* Read file */ 60 | ret = __Wad_ReadFile(fp, buffer, offset, len); 61 | if (ret < 0) { 62 | free(buffer); 63 | return ret; 64 | } 65 | 66 | /* Set pointer */ 67 | *outbuf = buffer; 68 | 69 | return 0; 70 | } 71 | 72 | s32 __Wad_GetTitleID(FILE *fp, wadHeader *header, u64 *tid) 73 | { 74 | signed_blob *p_tik = NULL; 75 | tik *tik_data = NULL; 76 | 77 | u32 offset = 0; 78 | s32 ret; 79 | 80 | /* Ticket offset */ 81 | offset += round_up(header->header_len, 64); 82 | offset += round_up(header->certs_len, 64); 83 | offset += round_up(header->crl_len, 64); 84 | 85 | /* Read ticket */ 86 | ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len); 87 | if (ret < 0) 88 | goto out; 89 | 90 | /* Ticket data */ 91 | tik_data = (tik *)SIGNATURE_PAYLOAD(p_tik); 92 | 93 | /* Copy title ID */ 94 | *tid = tik_data->titleid; 95 | 96 | out: 97 | /* Free memory */ 98 | if (p_tik) 99 | free(p_tik); 100 | 101 | return ret; 102 | } 103 | 104 | 105 | s32 Wad_Install(FILE *fp) 106 | { 107 | wadHeader *header = NULL; 108 | signed_blob *p_certs = NULL, *p_crl = NULL, *p_tik = NULL, *p_tmd = NULL; 109 | 110 | tmd *tmd_data = NULL; 111 | 112 | u32 cnt, offset = 0; 113 | s32 ret; 114 | 115 | printf("\t\t>> Reading WAD data..."); 116 | fflush(stdout); 117 | 118 | /* WAD header */ 119 | ret = __Wad_ReadAlloc(fp, (void *)&header, offset, sizeof(wadHeader)); 120 | if (ret < 0) 121 | goto err; 122 | else 123 | offset += round_up(header->header_len, 64); 124 | 125 | /* WAD certificates */ 126 | ret = __Wad_ReadAlloc(fp, (void *)&p_certs, offset, header->certs_len); 127 | if (ret < 0) 128 | goto err; 129 | else 130 | offset += round_up(header->certs_len, 64); 131 | 132 | /* WAD crl */ 133 | if (header->crl_len) { 134 | ret = __Wad_ReadAlloc(fp, (void *)&p_crl, offset, header->crl_len); 135 | if (ret < 0) 136 | goto err; 137 | else 138 | offset += round_up(header->crl_len, 64); 139 | } 140 | 141 | /* WAD ticket */ 142 | ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len); 143 | if (ret < 0) 144 | goto err; 145 | else 146 | offset += round_up(header->tik_len, 64); 147 | 148 | /* WAD TMD */ 149 | ret = __Wad_ReadAlloc(fp, (void *)&p_tmd, offset, header->tmd_len); 150 | if (ret < 0) 151 | goto err; 152 | else 153 | offset += round_up(header->tmd_len, 64); 154 | 155 | Con_ClearLine(); 156 | 157 | printf("\t\t>> Installing ticket..."); 158 | fflush(stdout); 159 | 160 | /* Install ticket */ 161 | ret = ES_AddTicket(p_tik, header->tik_len, p_certs, header->certs_len, p_crl, header->crl_len); 162 | if (ret < 0) 163 | goto err; 164 | 165 | Con_ClearLine(); 166 | 167 | printf("\r\t\t>> Installing title..."); 168 | fflush(stdout); 169 | 170 | /* Install title */ 171 | ret = ES_AddTitleStart(p_tmd, header->tmd_len, p_certs, header->certs_len, p_crl, header->crl_len); 172 | if (ret < 0) 173 | goto err; 174 | 175 | /* Get TMD info */ 176 | tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); 177 | 178 | /* Install contents */ 179 | for (cnt = 0; cnt < tmd_data->num_contents; cnt++) { 180 | tmd_content *content = &tmd_data->contents[cnt]; 181 | 182 | u32 idx = 0, len; 183 | s32 cfd; 184 | 185 | Con_ClearLine(); 186 | 187 | printf("\r\t\t>> Installing content #%02d...", content->cid); 188 | fflush(stdout); 189 | 190 | /* Encrypted content size */ 191 | len = round_up(content->size, 64); 192 | 193 | /* Install content */ 194 | cfd = ES_AddContentStart(tmd_data->title_id, content->cid); 195 | if (cfd < 0) { 196 | ret = cfd; 197 | goto err; 198 | } 199 | 200 | /* Install content data */ 201 | while (idx < len) { 202 | u32 size; 203 | 204 | /* Data length */ 205 | size = (len - idx); 206 | if (size > BLOCK_SIZE) 207 | size = BLOCK_SIZE; 208 | 209 | /* Read data */ 210 | ret = __Wad_ReadFile(fp, &wadBuffer, offset, size); 211 | if (ret < 0) 212 | goto err; 213 | 214 | /* Install data */ 215 | ret = ES_AddContentData(cfd, wadBuffer, size); 216 | if (ret < 0) 217 | goto err; 218 | 219 | /* Increase variables */ 220 | idx += size; 221 | offset += size; 222 | } 223 | 224 | /* Finish content installation */ 225 | ret = ES_AddContentFinish(cfd); 226 | if (ret < 0) 227 | goto err; 228 | } 229 | 230 | Con_ClearLine(); 231 | 232 | printf("\r\t\t>> Finishing installation..."); 233 | fflush(stdout); 234 | 235 | /* Finish title install */ 236 | ret = ES_AddTitleFinish(); 237 | if (ret >= 0) { 238 | printf(" OK!\n"); 239 | goto out; 240 | } 241 | 242 | err: 243 | printf(" ERROR! (ret = %d)\n", ret); 244 | 245 | /* Cancel install */ 246 | ES_AddTitleCancel(); 247 | 248 | out: 249 | /* Free memory */ 250 | if (header) 251 | free(header); 252 | if (p_certs) 253 | free(p_certs); 254 | if (p_crl) 255 | free(p_crl); 256 | if (p_tik) 257 | free(p_tik); 258 | if (p_tmd) 259 | free(p_tmd); 260 | 261 | return ret; 262 | } 263 | 264 | s32 Wad_Uninstall(FILE *fp) 265 | { 266 | wadHeader *header = NULL; 267 | tikview *viewData = NULL; 268 | 269 | u64 tid; 270 | u32 viewCnt; 271 | s32 ret; 272 | 273 | printf("\t\t>> Reading WAD data..."); 274 | fflush(stdout); 275 | 276 | /* WAD header */ 277 | ret = __Wad_ReadAlloc(fp, (void *)&header, 0, sizeof(wadHeader)); 278 | if (ret < 0) { 279 | printf(" ERROR! (ret = %d)\n", ret); 280 | goto out; 281 | } 282 | 283 | /* Get title ID */ 284 | ret = __Wad_GetTitleID(fp, header, &tid); 285 | if (ret < 0) { 286 | printf(" ERROR! (ret = %d)\n", ret); 287 | goto out; 288 | } 289 | 290 | Con_ClearLine(); 291 | 292 | printf("\t\t>> Deleting tickets..."); 293 | fflush(stdout); 294 | 295 | /* Get ticket views */ 296 | ret = Title_GetTicketViews(tid, &viewData, &viewCnt); 297 | if (ret < 0) 298 | printf(" ERROR! (ret = %d)\n", ret); 299 | 300 | /* Delete tickets */ 301 | if (ret >= 0) { 302 | u32 cnt; 303 | 304 | /* Delete all tickets */ 305 | for (cnt = 0; cnt < viewCnt; cnt++) { 306 | ret = ES_DeleteTicket(&viewData[cnt]); 307 | if (ret < 0) 308 | break; 309 | } 310 | 311 | if (ret < 0) 312 | printf(" ERROR! (ret = %d\n", ret); 313 | else 314 | printf(" OK!\n"); 315 | } 316 | 317 | printf("\t\t>> Deleting title contents..."); 318 | fflush(stdout); 319 | 320 | /* Delete title contents */ 321 | ret = ES_DeleteTitleContent(tid); 322 | if (ret < 0) 323 | printf(" ERROR! (ret = %d)\n", ret); 324 | else 325 | printf(" OK!\n"); 326 | 327 | 328 | printf("\t\t>> Deleting title..."); 329 | fflush(stdout); 330 | 331 | /* Delete title */ 332 | ret = ES_DeleteTitle(tid); 333 | if (ret < 0) 334 | printf(" ERROR! (ret = %d)\n", ret); 335 | else 336 | printf(" OK!\n"); 337 | 338 | out: 339 | /* Free memory */ 340 | if (header) 341 | free(header); 342 | 343 | return ret; 344 | } 345 | -------------------------------------------------------------------------------- /source/libpng/pngu/pngu.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************************** 2 | 3 | PNGU Version : 0.2a 4 | 5 | Coder : frontier 6 | 7 | More info : http://frontier-dev.net 8 | 9 | ********************************************************************************************/ 10 | #ifndef __PNGU__ 11 | #define __PNGU__ 12 | 13 | // Return codes 14 | #define PNGU_OK 0 15 | #define PNGU_ODD_WIDTH 1 16 | #define PNGU_ODD_STRIDE 2 17 | #define PNGU_INVALID_WIDTH_OR_HEIGHT 3 18 | #define PNGU_FILE_IS_NOT_PNG 4 19 | #define PNGU_UNSUPPORTED_COLOR_TYPE 5 20 | #define PNGU_NO_FILE_SELECTED 6 21 | #define PNGU_CANT_OPEN_FILE 7 22 | #define PNGU_CANT_READ_FILE 8 23 | #define PNGU_LIB_ERROR 9 24 | 25 | // Color types 26 | #define PNGU_COLOR_TYPE_GRAY 1 27 | #define PNGU_COLOR_TYPE_GRAY_ALPHA 2 28 | #define PNGU_COLOR_TYPE_PALETTE 3 29 | #define PNGU_COLOR_TYPE_RGB 4 30 | #define PNGU_COLOR_TYPE_RGB_ALPHA 5 31 | #define PNGU_COLOR_TYPE_UNKNOWN 6 32 | 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | // Types 39 | typedef unsigned char PNGU_u8; 40 | typedef unsigned short PNGU_u16; 41 | typedef unsigned int PNGU_u32; 42 | typedef unsigned long long PNGU_u64; 43 | 44 | typedef struct 45 | { 46 | PNGU_u8 r; 47 | PNGU_u8 g; 48 | PNGU_u8 b; 49 | } PNGUCOLOR; 50 | 51 | typedef struct 52 | { 53 | PNGU_u32 imgWidth; // In pixels 54 | PNGU_u32 imgHeight; // In pixels 55 | PNGU_u32 imgBitDepth; // In bitx 56 | PNGU_u32 imgColorType; // PNGU_COLOR_TYPE_* 57 | PNGU_u32 validBckgrnd; // Non zero if there is a background color 58 | PNGUCOLOR bckgrnd; // Backgroun color 59 | PNGU_u32 numTrans; // Number of transparent colors 60 | PNGUCOLOR *trans; // Transparent colors 61 | } PNGUPROP; 62 | 63 | // Image context, always initialize with SelectImageFrom* and free with ReleaseImageContext 64 | struct _IMGCTX; 65 | typedef struct _IMGCTX *IMGCTX; 66 | 67 | 68 | /**************************************************************************** 69 | * Pixel conversion * 70 | ****************************************************************************/ 71 | 72 | // Macro to convert RGB8 values to RGB565 73 | #define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) ) 74 | 75 | // Macro to convert RGBA8 values to RGB5A3 76 | #define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \ 77 | (0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \ 78 | (((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4))) 79 | 80 | // Function to convert two RGB8 values to YCbYCr 81 | PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2); 82 | 83 | // Function to convert an YCbYCr to two RGB8 values. 84 | void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2); 85 | 86 | 87 | /**************************************************************************** 88 | * Image context handling * 89 | ****************************************************************************/ 90 | 91 | // Selects a PNG file, previosly loaded into a buffer, and creates an image context for subsequent procesing. 92 | IMGCTX PNGU_SelectImageFromBuffer (const void *buffer); 93 | 94 | // Selects a PNG file, from any devoptab device, and creates an image context for subsequent procesing. 95 | IMGCTX PNGU_SelectImageFromDevice (const char *filename); 96 | 97 | // Frees resources associated with an image context. Always call this function when you no longer need the IMGCTX. 98 | void PNGU_ReleaseImageContext (IMGCTX ctx); 99 | 100 | 101 | /**************************************************************************** 102 | * Miscelaneous * 103 | ****************************************************************************/ 104 | 105 | // Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors. 106 | int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties); 107 | 108 | 109 | /**************************************************************************** 110 | * Image conversion * 111 | ****************************************************************************/ 112 | 113 | // Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions, 114 | // destination address and stride in pixels (stride = buffer width - image width). 115 | int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); 116 | 117 | // Macro for decoding an image inside a buffer at given coordinates. 118 | #define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ 119 | \ 120 | PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ 121 | (coordX) * 2, (bufferWidth) - (imgWidth)) 122 | 123 | // Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions, 124 | // destination address and stride in pixels (stride = buffer width - image width). 125 | int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); 126 | 127 | // Macro for decoding an image inside a buffer at given coordinates. 128 | #define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ 129 | \ 130 | PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ 131 | (coordX) * 2, (bufferWidth) - (imgWidth)) 132 | 133 | // Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions, 134 | // destination address, stride in pixels and default alpha value, which is used if the source image 135 | // doesn't have an alpha channel. 136 | int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha); 137 | 138 | // Macro for decoding an image inside a buffer at given coordinates. 139 | #define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \ 140 | \ 141 | PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ 142 | (coordX) * 2, (bufferWidth) - (imgWidth), default_alpha) 143 | 144 | // Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions 145 | // and destination address. 146 | int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer); 147 | 148 | // Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions, 149 | // destination address and default alpha value, which is used if the source image doesn't have an alpha channel. 150 | int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha); 151 | 152 | // Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions, 153 | // destination address and default alpha value, which is used if the source image doesn't have an alpha channel. 154 | int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha); 155 | 156 | // Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to 157 | // specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width). 158 | int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); 159 | 160 | // Macro for encoding an image stored into an YCbYCr buffer at given coordinates. 161 | #define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ 162 | \ 163 | PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ 164 | (coordX) * 2, (bufferWidth) - (imgWidth)) 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif 171 | 172 | -------------------------------------------------------------------------------- /source/wad-manager.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "gui.h" 10 | #include "menu.h" 11 | #include "restart.h" 12 | #include "sys.h" 13 | #include "video.h" 14 | #include "wpad.h" 15 | #include "fat.h" 16 | #include "nand.h" 17 | #include "globals.h" 18 | 19 | // Globals 20 | CONFIG gConfig; 21 | 22 | // Prototypes 23 | extern u32 WaitButtons (void); 24 | void CheckPassword (void); 25 | void SetDefaultConfig (void); 26 | int ReadConfigFile (char *configFilePath); 27 | int GetIntParam (char *inputStr); 28 | int GetStartupPath (char *startupPath, char *inputStr); 29 | int GetStringParam (char *outParam, char *inputStr, int maxChars); 30 | 31 | // Default password Up-Down-Left-Right-Up-Down 32 | //#define PASSWORD "UDLRUD" 33 | void CheckPassword (void) 34 | { 35 | char curPassword [11]; // Max 10 characters password, NULL terminated 36 | int count = 0; 37 | 38 | if (strlen (gConfig.password) == 0) 39 | return; 40 | 41 | // Ask user for a password. Press "B" to restart Wii 42 | printf("[+] [Enter Password to Continue]:\n\n"); 43 | 44 | printf(">> Press A to continue.\n"); 45 | printf(">> Press B button to restart your Wii.\n"); 46 | 47 | /* Wait for user answer */ 48 | for (;;) 49 | { 50 | u32 buttons = WaitButtons(); 51 | 52 | if (buttons & WPAD_BUTTON_A) 53 | { 54 | // A button, validate the pw 55 | curPassword [count] = 0; 56 | //if (strcmp (curPassword, PASSWORD) == 0) 57 | if (strcmp (curPassword, gConfig.password) == 0) 58 | { 59 | printf(">> Password Accepted...\n"); 60 | break; 61 | } 62 | else 63 | { 64 | printf ("\n"); 65 | printf(">> Incorrect Password. Try again...\n"); 66 | printf("[+] [Enter Password to Continue]:\n\n"); 67 | printf(">> Press A to continue.\n"); 68 | printf(">> Press B button to restart your Wii.\n"); 69 | count = 0; 70 | } 71 | } 72 | else if (buttons & WPAD_BUTTON_B) 73 | // B button, restart 74 | Restart(); 75 | else 76 | { 77 | if (count < 10) 78 | { 79 | // Other buttons, build the password 80 | if (buttons & WPAD_BUTTON_LEFT) 81 | { 82 | curPassword [count++] = 'L'; 83 | printf ("*"); 84 | } 85 | else if (buttons & WPAD_BUTTON_RIGHT) 86 | { 87 | curPassword [count++] = 'R'; 88 | printf ("*"); 89 | } 90 | else if (buttons & WPAD_BUTTON_UP) 91 | { 92 | curPassword [count++] = 'U'; 93 | printf ("*"); 94 | } 95 | else if (buttons & WPAD_BUTTON_DOWN) 96 | { 97 | curPassword [count++] = 'D'; 98 | printf ("*"); 99 | } 100 | else if (buttons & WPAD_BUTTON_1) 101 | { 102 | curPassword [count++] = '1'; 103 | printf ("*"); 104 | } 105 | else if (buttons & WPAD_BUTTON_2) 106 | { 107 | curPassword [count++] = '2'; 108 | printf ("*"); 109 | } 110 | } 111 | } 112 | } 113 | } 114 | 115 | void Disclaimer(void) 116 | { 117 | /* Print disclaimer */ 118 | printf("[+] [DISCLAIMER]:\n\n"); 119 | 120 | printf(" THIS APPLICATION COMES WITH NO WARRANTY AT ALL,\n"); 121 | printf(" NEITHER EXPRESS NOR IMPLIED.\n"); 122 | printf(" I DO NOT TAKE ANY RESPONSIBILITY FOR ANY DAMAGE IN YOUR\n"); 123 | printf(" WII CONSOLE BECAUSE OF A IMPROPER USAGE OF THIS SOFTWARE.\n\n"); 124 | 125 | printf(">> If you agree, press A button to continue.\n"); 126 | printf(">> Otherwise, press B button to restart your Wii.\n"); 127 | 128 | /* Wait for user answer */ 129 | for (;;) { 130 | //u32 buttons = Wpad_WaitButtons(); 131 | u32 buttons = WaitButtons(); 132 | 133 | /* A button */ 134 | if (buttons & WPAD_BUTTON_A) 135 | break; 136 | 137 | /* B button */ 138 | if (buttons & WPAD_BUTTON_B) 139 | Restart(); 140 | } 141 | } 142 | 143 | int main(int argc, char **argv) 144 | { 145 | /* Initialize subsystems */ 146 | Sys_Init(); 147 | 148 | /* Set video mode */ 149 | Video_SetMode(); 150 | 151 | /* Initialize console */ 152 | Gui_InitConsole(); 153 | 154 | /* Draw background */ 155 | Gui_DrawBackground(); 156 | 157 | /* Initialize Wiimote and GC Controller */ 158 | Wpad_Init(); 159 | PAD_Init (); 160 | WIILIGHT_Init(); 161 | 162 | /* Print disclaimer */ 163 | //Disclaimer(); 164 | 165 | // Set the defaults 166 | SetDefaultConfig (); 167 | 168 | // Read the config file 169 | ReadConfigFile (WM_CONFIG_FILE_PATH); 170 | 171 | // Check password 172 | CheckPassword (); 173 | 174 | /* Menu loop */ 175 | Menu_Loop(); 176 | 177 | /* Restart Wii */ 178 | Restart_Wait(); 179 | 180 | return 0; 181 | } 182 | 183 | 184 | int ReadConfigFile (char *configFilePath) 185 | { 186 | int retval = 0; 187 | FILE *fptr; 188 | char *tmpStr = malloc (MAX_FILE_PATH_LEN); 189 | char tmpOutStr [40]; 190 | int i; 191 | 192 | if (tmpStr == NULL) 193 | return (-1); 194 | 195 | fatDevice *fdev = &fdevList[0]; 196 | s32 ret = Fat_Mount(fdev); 197 | 198 | if (ret < 0) 199 | { 200 | printf(" ERROR! (ret = %d)\n", ret); 201 | // goto err; 202 | retval = -1; 203 | } 204 | else 205 | { 206 | // Read the file 207 | fptr = fopen (configFilePath, "rb"); 208 | if (fptr != NULL) 209 | { 210 | // Read the options 211 | char done = 0; 212 | 213 | while (!done) 214 | { 215 | if (fgets (tmpStr, MAX_FILE_PATH_LEN, fptr) == NULL) 216 | done = 1; 217 | else if (isalpha(tmpStr[0])) 218 | { 219 | // Get the password 220 | if (strncmp (tmpStr, "Password", 8) == 0) 221 | { 222 | // Get password 223 | // GetPassword (gConfig.password, tmpStr); 224 | GetStringParam (gConfig.password, tmpStr, MAX_PASSWORD_LENGTH); 225 | 226 | // If password is too long, ignore it 227 | if (strlen (gConfig.password) > 10) 228 | { 229 | gConfig.password [0] = 0; 230 | printf ("Password longer than 10 characters; will be ignored. Press a button...\n"); 231 | WaitButtons (); 232 | } 233 | } 234 | 235 | // Get startup path 236 | else if (strncmp (tmpStr, "StartupPath", 11) == 0) 237 | { 238 | // Get startup Path 239 | GetStartupPath (gConfig.startupPath, tmpStr); 240 | } 241 | 242 | // cIOS 243 | else if (strncmp (tmpStr, "cIOSVersion", 11) == 0) 244 | { 245 | // Get cIOSVersion 246 | gConfig.cIOSVersion = (u8)GetIntParam (tmpStr); 247 | } 248 | 249 | // FatDevice 250 | else if (strncmp (tmpStr, "FatDevice", 9) == 0) 251 | { 252 | // Get fatDevice 253 | GetStringParam (tmpOutStr, tmpStr, MAX_FAT_DEVICE_LENGTH); 254 | for (i = 0; i < 5; i++) 255 | { 256 | if (strncmp (fdevList[i].mount, tmpOutStr, 2) == 0) 257 | { 258 | gConfig.fatDeviceIndex = i; 259 | } 260 | } 261 | } 262 | 263 | // NandDevice 264 | else if (strncmp (tmpStr, "NANDDevice", 10) == 0) 265 | { 266 | // Get fatDevice 267 | GetStringParam (tmpOutStr, tmpStr, MAX_NAND_DEVICE_LENGTH); 268 | for (i = 0; i < 3; i++) 269 | { 270 | if (strncmp (ndevList[i].name, tmpOutStr, 2) == 0) 271 | { 272 | gConfig.nandDeviceIndex = i; 273 | } 274 | } 275 | } 276 | } 277 | } // EndWhile 278 | 279 | // Close the config file 280 | fclose (fptr); 281 | } 282 | else 283 | { 284 | // If the wm_config.txt file is not found, just take the default config params 285 | //printf ("Config file is not found\n"); // This is for testing only 286 | //WaitButtons(); 287 | } 288 | Fat_Unmount(fdev); 289 | } 290 | 291 | // Free memory 292 | free (tmpStr); 293 | 294 | return (retval); 295 | } // ReadConfig 296 | 297 | 298 | void SetDefaultConfig (void) 299 | { 300 | // Default password is NULL or no password 301 | gConfig.password [0] = 0; 302 | 303 | // Default startup folder 304 | strcpy (gConfig.startupPath, WAD_ROOT_DIRECTORY); 305 | 306 | gConfig.cIOSVersion = CIOS_VERSION_INVALID; // Means that user has to select later 307 | gConfig.fatDeviceIndex = FAT_DEVICE_INDEX_INVALID; // Means that user has to select 308 | gConfig.nandDeviceIndex = NAND_DEVICE_INDEX_INVALID; // Means that user has to select 309 | 310 | } // SetDefaultConfig 311 | 312 | 313 | int GetStartupPath (char *startupPath, char *inputStr) 314 | { 315 | int i = 0; 316 | int len = strlen (inputStr); 317 | 318 | // Find the "=" 319 | while ((inputStr [i] != '=') && (i < len)) 320 | { 321 | i++; 322 | } 323 | i++; 324 | 325 | // Get to the "/" 326 | while ((inputStr [i] != '/') && (i < len)) 327 | { 328 | i++; 329 | } 330 | 331 | // Get the startup Path 332 | int count = 0; 333 | while (isascii(inputStr [i]) && (i < len) && (inputStr [i] != '\n') && 334 | (inputStr [i] != '\r') && (inputStr [i] != ' ')) 335 | { 336 | startupPath [count++] = inputStr [i++]; 337 | } 338 | startupPath [count] = 0; // NULL terminate 339 | 340 | return (0); 341 | } // GetStartupPath 342 | 343 | int GetIntParam (char *inputStr) 344 | { 345 | int retval = 0; 346 | int i = 0; 347 | int len = strlen (inputStr); 348 | char outParam [40]; 349 | 350 | // Find the "=" 351 | while ((inputStr [i] != '=') && (i < len)) 352 | { 353 | i++; 354 | } 355 | i++; 356 | 357 | // Get to the first alpha numeric character 358 | while ((isdigit(inputStr [i]) == 0) && (i < len)) 359 | { 360 | i++; 361 | } 362 | 363 | // Get the string param 364 | int outCount = 0; 365 | while ((isdigit(inputStr [i])) && (i < len) && (outCount < 40)) 366 | { 367 | outParam [outCount++] = inputStr [i++]; 368 | } 369 | outParam [outCount] = 0; // NULL terminate 370 | retval = atoi (outParam); 371 | 372 | return (retval); 373 | } // GetIntParam 374 | 375 | 376 | int GetStringParam (char *outParam, char *inputStr, int maxChars) 377 | { 378 | int i = 0; 379 | int len = strlen (inputStr); 380 | 381 | // Find the "=" 382 | while ((inputStr [i] != '=') && (i < len)) 383 | { 384 | i++; 385 | } 386 | i++; 387 | 388 | // Get to the first alpha character 389 | while ((isalpha(inputStr [i]) == 0) && (i < len)) 390 | { 391 | i++; 392 | } 393 | 394 | // Get the string param 395 | int outCount = 0; 396 | while ((isalnum(inputStr [i])) && (i < len) && (outCount < maxChars)) 397 | { 398 | outParam [outCount++] = inputStr [i++]; 399 | } 400 | outParam [outCount] = 0; // NULL terminate 401 | 402 | return (0); 403 | } // GetStringParam 404 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /source/menu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "fat.h" 9 | #include "nand.h" 10 | #include "restart.h" 11 | #include "title.h" 12 | #include "usbstorage.h" 13 | #include "utils.h" 14 | #include "video.h" 15 | #include "wad.h" 16 | #include "wpad.h" 17 | #include 18 | #include "globals.h" 19 | 20 | /* FAT device list */ 21 | //static fatDevice fdevList[] = { 22 | fatDevice fdevList[] = { 23 | { "sd", "Wii SD Slot", &__io_wiisd }, 24 | { "usb", "USB Mass Storage Device", &__io_usbstorage }, 25 | { "usb2", "USB 2.0 Mass Storage Device", &__io_usb2storage }, 26 | { "gcsda", "SD Gecko (Slot A)", &__io_gcsda }, 27 | { "gcsdb", "SD Gecko (Slot B)", &__io_gcsdb }, 28 | }; 29 | 30 | /* NAND device list */ 31 | //static nandDevice ndevList[] = { 32 | nandDevice ndevList[] = { 33 | { "Disable", 0, 0x00, 0x00 }, 34 | { "SD/SDHC Card", 1, 0xF0, 0xF1 }, 35 | { "USB 2.0 Mass Storage Device", 2, 0xF2, 0xF3 }, 36 | }; 37 | 38 | 39 | /* FAT device */ 40 | static fatDevice *fdev = NULL; 41 | static nandDevice *ndev = NULL; 42 | 43 | // wiiNinja: Define a buffer holding the previous path names as user 44 | // traverses the directory tree. Max of 10 levels is define at this point 45 | static u8 gDirLevel = 0; 46 | static char gDirList [MAX_DIR_LEVELS][MAX_FILE_PATH_LEN]; 47 | static s32 gSeleted[MAX_DIR_LEVELS]; 48 | static s32 gStart[MAX_DIR_LEVELS]; 49 | 50 | /* Macros */ 51 | #define NB_FAT_DEVICES (sizeof(fdevList) / sizeof(fatDevice)) 52 | #define NB_NAND_DEVICES (sizeof(ndevList) / sizeof(nandDevice)) 53 | 54 | // Local prototypes: wiiNinja 55 | void WaitPrompt (char *prompt); 56 | int PushCurrentDir(char *dirStr, s32 Selected, s32 Start); 57 | char *PopCurrentDir(s32 *Selected, s32 *Start); 58 | bool IsListFull (void); 59 | char *PeekCurrentDir (void); 60 | u32 WaitButtons(void); 61 | u32 Pad_GetButtons(void); 62 | void WiiLightControl (int state); 63 | 64 | s32 __Menu_IsGreater(const void *p1, const void *p2) 65 | { 66 | u32 n1 = *(u32 *)p1; 67 | u32 n2 = *(u32 *)p2; 68 | 69 | /* Equal */ 70 | if (n1 == n2) 71 | return 0; 72 | 73 | return (n1 > n2) ? 1 : -1; 74 | } 75 | 76 | 77 | s32 __Menu_EntryCmp(const void *p1, const void *p2) 78 | { 79 | fatFile *f1 = (fatFile *)p1; 80 | fatFile *f2 = (fatFile *)p2; 81 | 82 | /* Compare entries */ // wiiNinja: Include directory 83 | if ((f1->filestat.st_mode & S_IFDIR) && !(f2->filestat.st_mode & S_IFDIR)) 84 | return (-1); 85 | else if (!(f1->filestat.st_mode & S_IFDIR) && (f2->filestat.st_mode & S_IFDIR)) 86 | return (1); 87 | else 88 | return strcmp(f1->filename, f2->filename); 89 | } 90 | 91 | char gFileName[MAX_FILE_PATH_LEN]; 92 | s32 __Menu_RetrieveList(char *inPath, fatFile **outbuf, u32 *outlen) 93 | { 94 | fatFile *buffer = NULL; 95 | DIR_ITER *dir = NULL; 96 | 97 | struct stat filestat; 98 | 99 | //char dirpath[256], filename[768]; 100 | u32 cnt; 101 | 102 | /* Generate dirpath */ 103 | //sprintf(dirpath, "%s:" WAD_DIRECTORY, fdev->mount); 104 | 105 | /* Open directory */ 106 | dir = diropen(inPath); 107 | if (!dir) 108 | return -1; 109 | 110 | /* Count entries */ 111 | for (cnt = 0; !dirnext(dir, gFileName, &filestat);) { 112 | // if (!(filestat.st_mode & S_IFDIR)) // wiiNinja 113 | cnt++; 114 | } 115 | 116 | if (cnt > 0) { 117 | /* Allocate memory */ 118 | buffer = malloc(sizeof(fatFile) * cnt); 119 | if (!buffer) { 120 | dirclose(dir); 121 | return -2; 122 | } 123 | 124 | /* Reset directory */ 125 | dirreset(dir); 126 | 127 | /* Get entries */ 128 | for (cnt = 0; !dirnext(dir, gFileName, &filestat);) 129 | { 130 | bool addFlag = false; 131 | 132 | if (filestat.st_mode & S_IFDIR) // wiiNinja 133 | { 134 | // Add only the item ".." which is the previous directory 135 | // AND if we're not at the root directory 136 | if ((strcmp (gFileName, "..") == 0) && (gDirLevel > 1)) 137 | addFlag = true; 138 | else if (strcmp (gFileName, ".") != 0) 139 | addFlag = true; 140 | } 141 | else 142 | { 143 | if(strlen(gFileName)>4) 144 | { 145 | if(!stricmp(gFileName+strlen(gFileName)-4, ".wad")) 146 | addFlag = true; 147 | } 148 | } 149 | 150 | if (addFlag == true) 151 | { 152 | fatFile *file = &buffer[cnt++]; 153 | 154 | /* File name */ 155 | strcpy(file->filename, gFileName); 156 | 157 | /* File stats */ 158 | file->filestat = filestat; 159 | } 160 | } 161 | 162 | /* Sort list */ 163 | qsort(buffer, cnt, sizeof(fatFile), __Menu_EntryCmp); 164 | } 165 | 166 | /* Close directory */ 167 | dirclose(dir); 168 | 169 | /* Set values */ 170 | *outbuf = buffer; 171 | *outlen = cnt; 172 | 173 | return 0; 174 | } 175 | 176 | 177 | void Menu_SelectIOS(void) 178 | { 179 | u8 *iosVersion = NULL; 180 | u32 iosCnt; 181 | u8 tmpVersion; 182 | 183 | u32 cnt; 184 | s32 ret, selected = 0; 185 | bool found = false; 186 | 187 | /* Get IOS versions */ 188 | ret = Title_GetIOSVersions(&iosVersion, &iosCnt); 189 | if (ret < 0) 190 | return; 191 | 192 | /* Sort list */ 193 | qsort(iosVersion, iosCnt, sizeof(u8), __Menu_IsGreater); 194 | 195 | if (gConfig.cIOSVersion < 0) 196 | tmpVersion = CIOS_VERSION; 197 | else 198 | { 199 | tmpVersion = (u8)gConfig.cIOSVersion; 200 | // For debugging only 201 | //printf ("User pre-selected cIOS: %i\n", tmpVersion); 202 | //WaitButtons(); 203 | } 204 | 205 | /* Set default version */ 206 | for (cnt = 0; cnt < iosCnt; cnt++) { 207 | u8 version = iosVersion[cnt]; 208 | 209 | /* Custom IOS available */ 210 | //if (version == CIOS_VERSION) 211 | if (version == tmpVersion) 212 | { 213 | selected = cnt; 214 | found = true; 215 | break; 216 | } 217 | 218 | /* Current IOS */ 219 | if (version == IOS_GetVersion()) 220 | selected = cnt; 221 | } 222 | 223 | /* Ask user for IOS version */ 224 | if ((gConfig.cIOSVersion < 0) || (found == false)) 225 | { 226 | for (;;) 227 | { 228 | /* Clear console */ 229 | Con_Clear(); 230 | 231 | printf("\t>> Select IOS version to use: < IOS%d >\n\n", iosVersion[selected]); 232 | 233 | printf("\t Press LEFT/RIGHT to change IOS version.\n\n"); 234 | 235 | printf("\t Press A button to continue.\n"); 236 | printf("\t Press HOME button to restart.\n\n"); 237 | 238 | u32 buttons = WaitButtons(); 239 | 240 | /* LEFT/RIGHT buttons */ 241 | if (buttons & WPAD_BUTTON_LEFT) { 242 | if ((--selected) <= -1) 243 | selected = (iosCnt - 1); 244 | } 245 | if (buttons & WPAD_BUTTON_RIGHT) { 246 | if ((++selected) >= iosCnt) 247 | selected = 0; 248 | } 249 | 250 | /* HOME button */ 251 | if (buttons & WPAD_BUTTON_HOME) 252 | Restart(); 253 | 254 | /* A button */ 255 | if (buttons & WPAD_BUTTON_A) 256 | break; 257 | } 258 | } 259 | 260 | 261 | u8 version = iosVersion[selected]; 262 | 263 | if (IOS_GetVersion() != version) { 264 | /* Shutdown subsystems */ 265 | Wpad_Disconnect(); 266 | 267 | /* Load IOS */ 268 | ret = IOS_ReloadIOS(version); 269 | 270 | /* Initialize subsystems */ 271 | Wpad_Init(); 272 | } 273 | } 274 | 275 | void Menu_FatDevice(void) 276 | { 277 | s32 ret, selected = 0; 278 | 279 | /* Unmount FAT device */ 280 | if (fdev) 281 | Fat_Unmount(fdev); 282 | 283 | /* Select source device */ 284 | if (gConfig.fatDeviceIndex < 0) 285 | { 286 | for (;;) { 287 | /* Clear console */ 288 | Con_Clear(); 289 | 290 | /* Selected device */ 291 | fdev = &fdevList[selected]; 292 | 293 | printf("\t>> Select source device: < %s >\n\n", fdev->name); 294 | 295 | printf("\t Press LEFT/RIGHT to change the selected device.\n\n"); 296 | 297 | printf("\t Press A button to continue.\n"); 298 | printf("\t Press HOME button to restart.\n\n"); 299 | 300 | u32 buttons = WaitButtons(); 301 | 302 | /* LEFT/RIGHT buttons */ 303 | if (buttons & WPAD_BUTTON_LEFT) { 304 | if ((--selected) <= -1) 305 | selected = (NB_FAT_DEVICES - 1); 306 | } 307 | if (buttons & WPAD_BUTTON_RIGHT) { 308 | if ((++selected) >= NB_FAT_DEVICES) 309 | selected = 0; 310 | } 311 | 312 | /* HOME button */ 313 | if (buttons & WPAD_BUTTON_HOME) 314 | Restart(); 315 | 316 | /* A button */ 317 | if (buttons & WPAD_BUTTON_A) 318 | break; 319 | } 320 | } 321 | else 322 | { 323 | fdev = &fdevList[gConfig.fatDeviceIndex]; 324 | } 325 | 326 | printf("[+] Mounting device, please wait..."); 327 | fflush(stdout); 328 | 329 | /* Mount FAT device */ 330 | ret = Fat_Mount(fdev); 331 | if (ret < 0) { 332 | printf(" ERROR! (ret = %d)\n", ret); 333 | goto err; 334 | } else 335 | printf(" OK!\n"); 336 | 337 | return; 338 | 339 | err: 340 | WiiLightControl (WII_LIGHT_OFF); 341 | printf("\n"); 342 | printf(" Press any button to continue...\n"); 343 | 344 | WaitButtons(); 345 | 346 | /* Prompt menu again */ 347 | Menu_FatDevice(); 348 | } 349 | 350 | void Menu_NandDevice(void) 351 | { 352 | s32 ret, selected = 0; 353 | 354 | /* Disable NAND emulator */ 355 | if (ndev) { 356 | Nand_Unmount(ndev); 357 | Nand_Disable(); 358 | } 359 | 360 | /* Select source device */ 361 | if (gConfig.nandDeviceIndex < 0) 362 | { 363 | for (;;) { 364 | /* Clear console */ 365 | Con_Clear(); 366 | 367 | /* Selected device */ 368 | ndev = &ndevList[selected]; 369 | 370 | printf("\t>> Select NAND emulator device: < %s >\n\n", ndev->name); 371 | 372 | printf("\t Press LEFT/RIGHT to change the selected device.\n\n"); 373 | 374 | printf("\t Press A button to continue.\n"); 375 | printf("\t Press HOME button to restart.\n\n"); 376 | 377 | u32 buttons = WaitButtons(); 378 | 379 | /* LEFT/RIGHT buttons */ 380 | if (buttons & WPAD_BUTTON_LEFT) { 381 | if ((--selected) <= -1) 382 | selected = (NB_NAND_DEVICES - 1); 383 | } 384 | if (buttons & WPAD_BUTTON_RIGHT) { 385 | if ((++selected) >= NB_NAND_DEVICES) 386 | selected = 0; 387 | } 388 | 389 | /* HOME button */ 390 | if (buttons & WPAD_BUTTON_HOME) 391 | Restart(); 392 | 393 | /* A button */ 394 | if (buttons & WPAD_BUTTON_A) 395 | break; 396 | } 397 | } 398 | else 399 | { 400 | ndev = &ndevList[gConfig.nandDeviceIndex]; 401 | } 402 | 403 | /* No NAND device */ 404 | if (!ndev->mode) 405 | return; 406 | 407 | printf("[+] Enabling NAND emulator..."); 408 | fflush(stdout); 409 | 410 | /* Mount NAND device */ 411 | ret = Nand_Mount(ndev); 412 | if (ret < 0) { 413 | printf(" ERROR! (ret = %d)\n", ret); 414 | goto err; 415 | } 416 | 417 | /* Enable NAND emulator */ 418 | ret = Nand_Enable(ndev); 419 | if (ret < 0) { 420 | printf(" ERROR! (ret = %d)\n", ret); 421 | goto err; 422 | } else 423 | printf(" OK!\n"); 424 | 425 | return; 426 | 427 | err: 428 | printf("\n"); 429 | printf(" Press any button to continue...\n"); 430 | 431 | WaitButtons(); 432 | 433 | /* Prompt menu again */ 434 | Menu_NandDevice(); 435 | } 436 | 437 | char gTmpFilePath[MAX_FILE_PATH_LEN]; 438 | void Menu_WadManage(fatFile *file, char *inFilePath) 439 | { 440 | FILE *fp = NULL; 441 | 442 | //char filepath[128]; 443 | f32 filesize; 444 | 445 | u32 mode = 0; 446 | 447 | /* File size in megabytes */ 448 | filesize = (file->filestat.st_size / MB_SIZE); 449 | 450 | for (;;) { 451 | /* Clear console */ 452 | Con_Clear(); 453 | 454 | printf("[+] WAD Filename : %s\n", file->filename); 455 | printf(" WAD Filesize : %.2f MB\n\n\n", filesize); 456 | 457 | 458 | printf("[+] Select action: < %s WAD >\n\n", (!mode) ? "Install" : "Uninstall"); 459 | 460 | printf(" Press LEFT/RIGHT to change selected action.\n\n"); 461 | 462 | printf(" Press A to continue.\n"); 463 | printf(" Press B to go back to the menu.\n\n"); 464 | 465 | u32 buttons = WaitButtons(); 466 | 467 | /* LEFT/RIGHT buttons */ 468 | if (buttons & (WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT)) 469 | mode ^= 1; 470 | 471 | /* A button */ 472 | if (buttons & WPAD_BUTTON_A) 473 | break; 474 | 475 | /* B button */ 476 | if (buttons & WPAD_BUTTON_B) 477 | return; 478 | } 479 | 480 | /* Clear console */ 481 | Con_Clear(); 482 | 483 | printf("[+] Opening \"%s\", please wait...", file->filename); 484 | fflush(stdout); 485 | 486 | /* Generate filepath */ 487 | // sprintf(filepath, "%s:" WAD_DIRECTORY "/%s", fdev->mount, file->filename); 488 | sprintf(gTmpFilePath, "%s/%s", inFilePath, file->filename); // wiiNinja 489 | 490 | /* Open WAD */ 491 | fp = fopen(gTmpFilePath, "rb"); 492 | if (!fp) { 493 | printf(" ERROR!\n"); 494 | goto out; 495 | } else 496 | printf(" OK!\n\n"); 497 | 498 | printf("[+] %s WAD, please wait...\n", (!mode) ? "Installing" : "Uninstalling"); 499 | 500 | /* Do install/uninstall */ 501 | WiiLightControl (WII_LIGHT_ON); 502 | if (!mode) 503 | Wad_Install(fp); 504 | else 505 | Wad_Uninstall(fp); 506 | WiiLightControl (WII_LIGHT_OFF); 507 | 508 | out: 509 | /* Close file */ 510 | if (fp) 511 | fclose(fp); 512 | 513 | printf("\n"); 514 | printf(" Press any button to continue...\n"); 515 | 516 | /* Wait for button */ 517 | WaitButtons(); 518 | } 519 | 520 | void Menu_WadList(void) 521 | { 522 | char str [100]; 523 | fatFile *fileList = NULL; 524 | u32 fileCnt; 525 | s32 ret, selected = 0, start = 0; 526 | char *tmpPath = malloc (MAX_FILE_PATH_LEN); 527 | 528 | // wiiNinja: check for malloc error 529 | if (tmpPath == NULL) 530 | { 531 | ret = -999; // What am I gonna use here? 532 | printf(" ERROR! Out of memory (ret = %d)\n", ret); 533 | return; 534 | } 535 | 536 | printf("[+] Retrieving file list..."); 537 | fflush(stdout); 538 | 539 | gDirLevel = 0; 540 | 541 | // wiiNinja: The root is always the primary folder 542 | // But if the user has a /wad directory, just go there. This makes 543 | // both sides of the argument win 544 | sprintf(tmpPath, "%s:" WAD_DIRECTORY, fdev->mount); 545 | PushCurrentDir(tmpPath,0,0); 546 | //if (strcmp (WAD_DIRECTORY, WAD_ROOT_DIRECTORY) != 0) 547 | if (strcmp (WAD_DIRECTORY, gConfig.startupPath) != 0) 548 | { 549 | // If the directory can be successfully opened, it must exists 550 | //DIR_ITER *tmpDirPtr = NULL; 551 | //tmpDirPtr = diropen(WAD_ROOT_DIRECTORY); 552 | //if (tmpDirPtr) 553 | //{ 554 | // dirclose (tmpDirPtr); 555 | 556 | // Now push the /wad directory as the current operating folder 557 | //sprintf(tmpPath, "%s:" WAD_ROOT_DIRECTORY, fdev->mount); 558 | sprintf(tmpPath, "%s:%s", fdev->mount, gConfig.startupPath); 559 | //printf ("\nThe final startupPath is: %s\n", tmpPath); 560 | //WaitButtons (); 561 | PushCurrentDir(tmpPath,0,0); // wiiNinja 562 | //} 563 | } 564 | 565 | /* Retrieve filelist */ 566 | getList: 567 | if (fileList) 568 | { 569 | free (fileList); 570 | fileList = NULL; 571 | } 572 | 573 | ret = __Menu_RetrieveList(tmpPath, &fileList, &fileCnt); 574 | if (ret < 0) { 575 | printf(" ERROR! (ret = %d)\n", ret); 576 | goto err; 577 | } 578 | 579 | /* No files */ 580 | if (!fileCnt) { 581 | printf(" No files found!\n"); 582 | goto err; 583 | } 584 | 585 | for (;;) 586 | { 587 | u32 cnt; 588 | s32 index; 589 | 590 | /* Clear console */ 591 | Con_Clear(); 592 | 593 | /** Print entries **/ 594 | cnt = strlen(tmpPath); 595 | if(cnt>30) 596 | index = cnt-30; 597 | else 598 | index = 0; 599 | 600 | printf("[+] WAD files on [%s]:\n\n", tmpPath+index); 601 | 602 | /* Print entries */ 603 | for (cnt = start; cnt < fileCnt; cnt++) 604 | { 605 | fatFile *file = &fileList[cnt]; 606 | f32 filesize = file->filestat.st_size / MB_SIZE; 607 | 608 | /* Entries per page limit */ 609 | if ((cnt - start) >= ENTRIES_PER_PAGE) 610 | break; 611 | 612 | strncpy(str, file->filename, 48); 613 | str[48]=0; 614 | 615 | /* Print filename */ 616 | //printf("\t%2s %s (%.2f MB)\n", (cnt == selected) ? ">>" : " ", file->filename, filesize); 617 | if (file->filestat.st_mode & S_IFDIR) // wiiNinja 618 | printf("\t%2s [%s]\n", (cnt == selected) ? ">>" : " ", str); 619 | else 620 | printf("\t%2s %s (%.2f MB)\n", (cnt == selected) ? ">>" : " ", str, filesize); 621 | 622 | } 623 | 624 | printf("\n"); 625 | 626 | printf("[+] Press A button to (un)install a WAD file.\n"); 627 | if(gDirLevel>1) 628 | printf(" Press B button to go up-level DIR"); 629 | else 630 | printf(" Press B button to select a storage device"); 631 | 632 | /** Controls **/ 633 | u32 buttons = WaitButtons(); 634 | 635 | /* DPAD buttons */ 636 | if (buttons & (WPAD_BUTTON_UP | WPAD_BUTTON_LEFT)) { 637 | selected -= (buttons & WPAD_BUTTON_LEFT) ? ENTRIES_PER_PAGE : 1; 638 | 639 | if (selected <= -1) 640 | selected = (fileCnt - 1); 641 | } 642 | if (buttons & (WPAD_BUTTON_DOWN | WPAD_BUTTON_RIGHT)) { 643 | selected += (buttons & WPAD_BUTTON_RIGHT) ? ENTRIES_PER_PAGE : 1; 644 | 645 | if (selected >= fileCnt) 646 | selected = 0; 647 | } 648 | 649 | /* HOME button */ 650 | if (buttons & WPAD_BUTTON_HOME) 651 | Restart(); 652 | 653 | /* A button */ 654 | if (buttons & WPAD_BUTTON_A) 655 | { 656 | fatFile *tmpFile = &fileList[selected]; 657 | char *tmpCurPath; 658 | if (tmpFile->filestat.st_mode & S_IFDIR) // wiiNinja 659 | { 660 | if (strcmp (tmpFile->filename, "..") == 0) 661 | { 662 | selected = 0; 663 | start = 0; 664 | 665 | // Previous dir 666 | tmpCurPath = PopCurrentDir(&selected, &start); 667 | if (tmpCurPath != NULL) 668 | sprintf(tmpPath, "%s", tmpCurPath); 669 | 670 | goto getList; 671 | } 672 | else if (IsListFull () == true) 673 | { 674 | WaitPrompt ("Maximum number of directory levels is reached.\n"); 675 | } 676 | else 677 | { 678 | tmpCurPath = PeekCurrentDir (); 679 | if (tmpCurPath != NULL) 680 | { 681 | if(gDirLevel>1) 682 | sprintf(tmpPath, "%s/%s", tmpCurPath, tmpFile->filename); 683 | else 684 | sprintf(tmpPath, "%s%s", tmpCurPath, tmpFile->filename); 685 | } 686 | // wiiNinja: Need to PopCurrentDir 687 | PushCurrentDir (tmpPath, selected, start); 688 | selected = 0; 689 | start = 0; 690 | goto getList; 691 | } 692 | } 693 | else 694 | { 695 | tmpCurPath = PeekCurrentDir (); 696 | if (tmpCurPath != NULL) 697 | Menu_WadManage(tmpFile, tmpCurPath); 698 | } 699 | } 700 | 701 | /* B button */ 702 | if (buttons & WPAD_BUTTON_B) 703 | { 704 | if(gDirLevel<=1) 705 | { 706 | return; 707 | } 708 | 709 | char *tmpCurPath; 710 | selected = 0; 711 | start = 0; 712 | // Previous dir 713 | tmpCurPath = PopCurrentDir(&selected, &start); 714 | if (tmpCurPath != NULL) 715 | sprintf(tmpPath, "%s", tmpCurPath); 716 | goto getList; 717 | //return; 718 | } 719 | 720 | /** Scrolling **/ 721 | /* List scrolling */ 722 | index = (selected - start); 723 | 724 | if (index >= ENTRIES_PER_PAGE) 725 | start += index - (ENTRIES_PER_PAGE - 1); 726 | if (index <= -1) 727 | start += index; 728 | } 729 | 730 | err: 731 | printf("\n"); 732 | printf(" Press any button to continue...\n"); 733 | 734 | free (tmpPath); 735 | 736 | /* Wait for button */ 737 | WaitButtons(); 738 | } 739 | 740 | 741 | void Menu_Loop(void) 742 | { 743 | u8 iosVersion; 744 | 745 | /* Select IOS menu */ 746 | Menu_SelectIOS(); 747 | 748 | /* Retrieve IOS version */ 749 | iosVersion = IOS_GetVersion(); 750 | 751 | /* NAND device menu */ 752 | if (iosVersion == CIOS_VERSION) 753 | Menu_NandDevice(); 754 | 755 | for (;;) { 756 | /* FAT device menu */ 757 | Menu_FatDevice(); 758 | 759 | /* WAD list menu */ 760 | Menu_WadList(); 761 | } 762 | } 763 | 764 | // Start of wiiNinja's added routines 765 | 766 | int PushCurrentDir (char *dirStr, s32 Selected, s32 Start) 767 | { 768 | int retval = 0; 769 | 770 | // Store dirStr into the list and increment the gDirLevel 771 | // WARNING: Make sure dirStr is no larger than MAX_FILE_PATH_LEN 772 | if (gDirLevel < MAX_DIR_LEVELS) 773 | { 774 | strcpy (gDirList [gDirLevel], dirStr); 775 | gSeleted[gDirLevel]=Selected; 776 | gStart[gDirLevel]=Start; 777 | gDirLevel++; 778 | //if (gDirLevel >= MAX_DIR_LEVELS) 779 | // gDirLevel = 0; 780 | } 781 | else 782 | retval = -1; 783 | 784 | return (retval); 785 | } 786 | 787 | char *PopCurrentDir(s32 *Selected, s32 *Start) 788 | { 789 | if (gDirLevel > 1) 790 | gDirLevel--; 791 | else 792 | gDirLevel = 0; 793 | 794 | *Selected = gSeleted[gDirLevel]; 795 | *Start = gStart[gDirLevel]; 796 | return PeekCurrentDir(); 797 | } 798 | 799 | bool IsListFull (void) 800 | { 801 | if (gDirLevel < MAX_DIR_LEVELS) 802 | return (false); 803 | else 804 | return (true); 805 | } 806 | 807 | char *PeekCurrentDir (void) 808 | { 809 | // Return the current path 810 | if (gDirLevel > 0) 811 | return (gDirList [gDirLevel-1]); 812 | else 813 | return (NULL); 814 | } 815 | 816 | void WaitPrompt (char *prompt) 817 | { 818 | printf("\n%s", prompt); 819 | printf(" Press any button to continue...\n"); 820 | 821 | /* Wait for button */ 822 | WaitButtons(); 823 | } 824 | 825 | u32 Pad_GetButtons(void) 826 | { 827 | u32 buttons = 0, cnt; 828 | 829 | /* Scan pads */ 830 | PAD_ScanPads(); 831 | 832 | /* Get pressed buttons */ 833 | //for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) 834 | for (cnt = 0; cnt < 4; cnt++) 835 | buttons |= PAD_ButtonsDown(cnt); 836 | 837 | return buttons; 838 | } 839 | 840 | 841 | // Routine to wait for a button from either the Wiimote or a gamecube 842 | // controller. The return value will mimic the WPAD buttons to minimize 843 | // the amount of changes to the original code, that is expecting only 844 | // Wiimote button presses. Note that the "HOME" button on the Wiimote 845 | // is mapped to the "SELECT" button on the Gamecube Ctrl. (wiiNinja 5/15/2009) 846 | u32 WaitButtons(void) 847 | { 848 | u32 buttons = 0; 849 | u32 buttonsGC = 0; 850 | 851 | /* Wait for button pressing */ 852 | while (!buttons && !buttonsGC) 853 | { 854 | // GC buttons 855 | buttonsGC = Pad_GetButtons (); 856 | 857 | // Wii buttons 858 | buttons = Wpad_GetButtons(); 859 | 860 | VIDEO_WaitVSync(); 861 | } 862 | 863 | if (buttonsGC) 864 | { 865 | if(buttonsGC & PAD_BUTTON_A) 866 | { 867 | //printf ("Button A on the GC controller\n"); 868 | buttons |= WPAD_BUTTON_A; 869 | } 870 | else if(buttonsGC & PAD_BUTTON_B) 871 | { 872 | //printf ("Button B on the GC controller\n"); 873 | buttons |= WPAD_BUTTON_B; 874 | } 875 | else if(buttonsGC & PAD_BUTTON_LEFT) 876 | { 877 | //printf ("Button LEFT on the GC controller\n"); 878 | buttons |= WPAD_BUTTON_LEFT; 879 | } 880 | else if(buttonsGC & PAD_BUTTON_RIGHT) 881 | { 882 | //printf ("Button RIGHT on the GC controller\n"); 883 | buttons |= WPAD_BUTTON_RIGHT; 884 | } 885 | else if(buttonsGC & PAD_BUTTON_DOWN) 886 | { 887 | //printf ("Button DOWN on the GC controller\n"); 888 | buttons |= WPAD_BUTTON_DOWN; 889 | } 890 | else if(buttonsGC & PAD_BUTTON_UP) 891 | { 892 | //printf ("Button UP on the GC controller\n"); 893 | buttons |= WPAD_BUTTON_UP; 894 | } 895 | else if(buttonsGC & PAD_BUTTON_START) 896 | { 897 | //printf ("Button START on the GC controller\n"); 898 | buttons |= WPAD_BUTTON_HOME; 899 | } 900 | } 901 | 902 | return buttons; 903 | } // WaitButtons 904 | 905 | 906 | void WiiLightControl (int state) 907 | { 908 | switch (state) 909 | { 910 | case WII_LIGHT_ON: 911 | /* Turn on Wii Light */ 912 | WIILIGHT_SetLevel(255); 913 | WIILIGHT_TurnOn(); 914 | break; 915 | 916 | case WII_LIGHT_OFF: 917 | default: 918 | /* Turn off Wii Light */ 919 | WIILIGHT_SetLevel(0); 920 | WIILIGHT_TurnOn(); 921 | WIILIGHT_Toggle(); 922 | break; 923 | } 924 | } // WiiLightControl 925 | 926 | -------------------------------------------------------------------------------- /source/libpng/pngu/pngu.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************************** 2 | 3 | PNGU Version : 0.2a 4 | 5 | Coder : frontier 6 | 7 | More info : http://frontier-dev.net 8 | 9 | ********************************************************************************************/ 10 | #include 11 | #include 12 | #include "pngu.h" 13 | #include "../png.h" 14 | 15 | 16 | // Constants 17 | #define PNGU_SOURCE_BUFFER 1 18 | #define PNGU_SOURCE_DEVICE 2 19 | 20 | 21 | // Prototypes of helper functions 22 | int pngu_info (IMGCTX ctx); 23 | int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha); 24 | void pngu_free_info (IMGCTX ctx); 25 | void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length); 26 | void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length); 27 | void pngu_flush_data_to_buffer (png_structp png_ptr); 28 | int pngu_clamp (int value, int min, int max); 29 | 30 | 31 | // PNGU Image context struct 32 | struct _IMGCTX 33 | { 34 | int source; 35 | void *buffer; 36 | char *filename; 37 | PNGU_u32 cursor; 38 | 39 | PNGU_u32 propRead; 40 | PNGUPROP prop; 41 | 42 | PNGU_u32 infoRead; 43 | png_structp png_ptr; 44 | png_infop info_ptr; 45 | FILE *fd; 46 | 47 | png_bytep *row_pointers; 48 | png_bytep img_data; 49 | }; 50 | 51 | 52 | // PNGU Implementation // 53 | 54 | IMGCTX PNGU_SelectImageFromBuffer (const void *buffer) 55 | { 56 | IMGCTX ctx = NULL; 57 | 58 | if (!buffer) 59 | return NULL; 60 | 61 | ctx = malloc (sizeof (struct _IMGCTX)); 62 | if (!ctx) 63 | return NULL; 64 | 65 | ctx->buffer = (void *) buffer; 66 | ctx->source = PNGU_SOURCE_BUFFER; 67 | ctx->cursor = 0; 68 | ctx->filename = NULL; 69 | ctx->propRead = 0; 70 | ctx->infoRead = 0; 71 | 72 | return ctx; 73 | } 74 | 75 | 76 | IMGCTX PNGU_SelectImageFromDevice (const char *filename) 77 | { 78 | IMGCTX ctx = NULL; 79 | 80 | if (!filename) 81 | return NULL; 82 | 83 | ctx = malloc (sizeof (struct _IMGCTX)); 84 | if (!ctx) 85 | return NULL; 86 | 87 | ctx->buffer = NULL; 88 | ctx->source = PNGU_SOURCE_DEVICE; 89 | ctx->cursor = 0; 90 | 91 | ctx->filename = malloc (strlen (filename) + 1); 92 | if (!ctx->filename) 93 | { 94 | free (ctx); 95 | return NULL; 96 | } 97 | strcpy(ctx->filename, filename); 98 | 99 | ctx->propRead = 0; 100 | ctx->infoRead = 0; 101 | 102 | return ctx; 103 | } 104 | 105 | 106 | void PNGU_ReleaseImageContext (IMGCTX ctx) 107 | { 108 | if (!ctx) 109 | return; 110 | 111 | if (ctx->filename) 112 | free (ctx->filename); 113 | 114 | if ((ctx->propRead) && (ctx->prop.trans)) 115 | free (ctx->prop.trans); 116 | 117 | pngu_free_info (ctx); 118 | 119 | free (ctx); 120 | } 121 | 122 | 123 | int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *imgprop) 124 | { 125 | int res; 126 | 127 | if (!ctx->propRead) 128 | { 129 | res = pngu_info (ctx); 130 | if (res != PNGU_OK) 131 | return res; 132 | } 133 | 134 | *imgprop = ctx->prop; 135 | 136 | return PNGU_OK; 137 | } 138 | 139 | 140 | int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) 141 | { 142 | int result; 143 | PNGU_u32 x, y, buffWidth; 144 | 145 | // width needs to be divisible by two 146 | if (width % 2) 147 | return PNGU_ODD_WIDTH; 148 | 149 | // stride needs to be divisible by two 150 | if (stride % 2) 151 | return PNGU_ODD_STRIDE; 152 | 153 | result = pngu_decode (ctx, width, height, 1); 154 | if (result != PNGU_OK) 155 | return result; 156 | 157 | // Copy image to the output buffer 158 | buffWidth = (width + stride) / 2; 159 | for (y = 0; y < height; y++) 160 | for (x = 0; x < (width / 2); x++) 161 | ((PNGU_u32 *)buffer)[y*buffWidth+x] = PNGU_RGB8_TO_YCbYCr (*(ctx->row_pointers[y]+x*6), *(ctx->row_pointers[y]+x*6+1), *(ctx->row_pointers[y]+x*6+2), 162 | *(ctx->row_pointers[y]+x*6+3), *(ctx->row_pointers[y]+x*6+4), *(ctx->row_pointers[y]+x*6+5)); 163 | 164 | // Free resources 165 | free (ctx->img_data); 166 | free (ctx->row_pointers); 167 | 168 | // Success 169 | return PNGU_OK; 170 | } 171 | 172 | 173 | int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) 174 | { 175 | int result; 176 | PNGU_u32 x, y, buffWidth; 177 | 178 | result = pngu_decode (ctx, width, height, 1); 179 | if (result != PNGU_OK) 180 | return result; 181 | 182 | buffWidth = width + stride; 183 | 184 | // Copy image to the output buffer 185 | for (y = 0; y < height; y++) 186 | for (x = 0; x < width; x++) 187 | ((PNGU_u16 *)buffer)[y*buffWidth+x] = 188 | (((PNGU_u16) (ctx->row_pointers[y][x*3] & 0xF8)) << 8) | 189 | (((PNGU_u16) (ctx->row_pointers[y][x*3+1] & 0xFC)) << 3) | 190 | (((PNGU_u16) (ctx->row_pointers[y][x*3+2] & 0xF8)) >> 3); 191 | 192 | // Free resources 193 | free (ctx->img_data); 194 | free (ctx->row_pointers); 195 | 196 | // Success 197 | return PNGU_OK; 198 | } 199 | 200 | 201 | int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha) 202 | { 203 | int result; 204 | PNGU_u32 x, y, buffWidth; 205 | 206 | result = pngu_decode (ctx, width, height, 0); 207 | if (result != PNGU_OK) 208 | return result; 209 | 210 | buffWidth = width + stride; 211 | 212 | // Check is source image has an alpha channel 213 | if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) 214 | { 215 | // Alpha channel present, copy image to the output buffer 216 | for (y = 0; y < height; y++) 217 | memcpy (buffer + (y * buffWidth * 4), ctx->row_pointers[y], width * 4); 218 | } 219 | else 220 | { 221 | // No alpha channel present, copy image to the output buffer 222 | for (y = 0; y < height; y++) 223 | for (x = 0; x < width; x++) 224 | ((PNGU_u32 *)buffer)[y*buffWidth+x] = 225 | (((PNGU_u32) ctx->row_pointers[y][x*3]) << 24) | 226 | (((PNGU_u32) ctx->row_pointers[y][x*3+1]) << 16) | 227 | (((PNGU_u32) ctx->row_pointers[y][x*3+2]) << 8) | 228 | ((PNGU_u32) default_alpha); 229 | } 230 | 231 | // Free resources 232 | free (ctx->img_data); 233 | free (ctx->row_pointers); 234 | 235 | // Success 236 | return PNGU_OK; 237 | } 238 | 239 | 240 | int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer) 241 | { 242 | int result; 243 | PNGU_u32 x, y, qwidth, qheight; 244 | 245 | // width and height need to be divisible by four 246 | if ((width % 4) || (height % 4)) 247 | return PNGU_INVALID_WIDTH_OR_HEIGHT; 248 | 249 | result = pngu_decode (ctx, width, height, 1); 250 | if (result != PNGU_OK) 251 | return result; 252 | 253 | // Copy image to the output buffer 254 | qwidth = width / 4; 255 | qheight = height / 4; 256 | 257 | for (y = 0; y < qheight; y++) 258 | for (x = 0; x < qwidth; x++) 259 | { 260 | int blockbase = (y * qwidth + x) * 4; 261 | 262 | PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); 263 | PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); 264 | ((PNGU_u64 *) buffer)[blockbase] = 265 | (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | 266 | (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | 267 | (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | 268 | (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); 269 | 270 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); 271 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); 272 | ((PNGU_u64 *) buffer)[blockbase+1] = 273 | (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | 274 | (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | 275 | (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | 276 | (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); 277 | 278 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); 279 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); 280 | ((PNGU_u64 *) buffer)[blockbase+2] = 281 | (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | 282 | (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | 283 | (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | 284 | (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); 285 | 286 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); 287 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); 288 | ((PNGU_u64 *) buffer)[blockbase+3] = 289 | (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | 290 | (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | 291 | (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | 292 | (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); 293 | } 294 | 295 | // Free resources 296 | free (ctx->img_data); 297 | free (ctx->row_pointers); 298 | 299 | // Success 300 | return PNGU_OK; 301 | } 302 | 303 | 304 | int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha) 305 | { 306 | int result; 307 | PNGU_u32 x, y, qwidth, qheight; 308 | PNGU_u64 alphaMask; 309 | 310 | // width and height need to be divisible by four 311 | if ((width % 4) || (height % 4)) 312 | return PNGU_INVALID_WIDTH_OR_HEIGHT; 313 | 314 | result = pngu_decode (ctx, width, height, 0); 315 | if (result != PNGU_OK) 316 | return result; 317 | 318 | // Init some vars 319 | qwidth = width / 4; 320 | qheight = height / 4; 321 | 322 | // Check is source image has an alpha channel 323 | if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) 324 | { 325 | // Alpha channel present, copy image to the output buffer 326 | for (y = 0; y < qheight; y++) 327 | for (x = 0; x < qwidth; x++) 328 | { 329 | int blockbase = (y * qwidth + x) * 4; 330 | PNGU_u64 tmp; 331 | 332 | PNGU_u64 fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16)); 333 | PNGU_u64 fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16+8)); 334 | // If first pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 335 | if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) 336 | tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); 337 | else 338 | tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); 339 | 340 | // If second pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 341 | if ((fieldA & 0xE0ULL) == 0xE0ULL) 342 | tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); 343 | else 344 | tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); 345 | 346 | // If third pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 347 | if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) 348 | tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); 349 | else 350 | tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); 351 | 352 | // If fourth pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 353 | if ((fieldB & 0xE0ULL) == 0xE0ULL) 354 | tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); 355 | else 356 | tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); 357 | ((PNGU_u64 *) buffer)[blockbase] = tmp; 358 | 359 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16)); 360 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16+8)); 361 | if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) 362 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 363 | tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); 364 | else 365 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 366 | tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); 367 | 368 | if ((fieldA & 0xE0ULL) == 0xE0ULL) 369 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 370 | tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); 371 | else 372 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 373 | tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); 374 | 375 | if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) 376 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 377 | tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); 378 | else 379 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 380 | tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); 381 | 382 | if ((fieldB & 0xE0ULL) == 0xE0ULL) 383 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 384 | tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); 385 | else 386 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 387 | tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); 388 | ((PNGU_u64 *) buffer)[blockbase+1] = tmp; 389 | 390 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16)); 391 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16+8)); 392 | if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) 393 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 394 | tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); 395 | else 396 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 397 | tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); 398 | 399 | if ((fieldA & 0xE0ULL) == 0xE0ULL) 400 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 401 | tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); 402 | else 403 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 404 | tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); 405 | 406 | if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) 407 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 408 | tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); 409 | else 410 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 411 | tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); 412 | 413 | if ((fieldB & 0xE0ULL) == 0xE0ULL) 414 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 415 | tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); 416 | else 417 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 418 | tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); 419 | ((PNGU_u64 *) buffer)[blockbase+2] = tmp; 420 | 421 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16)); 422 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16+8)); 423 | if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) 424 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 425 | tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); 426 | else 427 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 428 | tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); 429 | 430 | if ((fieldA & 0xE0ULL) == 0xE0ULL) 431 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 432 | tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); 433 | else 434 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 435 | tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); 436 | 437 | if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) 438 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 439 | tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); 440 | else 441 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 442 | tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); 443 | 444 | if ((fieldB & 0xE0ULL) == 0xE0ULL) 445 | // Opaque pixel, so set MSB to 1 and encode colors in RGB555 446 | tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); 447 | else 448 | // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 449 | tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); 450 | ((PNGU_u64 *) buffer)[blockbase+3] = tmp; 451 | } 452 | } 453 | else 454 | { 455 | // No alpha channel present, copy image to the output buffer 456 | default_alpha = (default_alpha >> 5); 457 | if (default_alpha == 7) 458 | { 459 | // The user wants an opaque texture, so set MSB to 1 and encode colors in RGB555 460 | alphaMask = 0x8000800080008000ULL; 461 | 462 | for (y = 0; y < qheight; y++) 463 | for (x = 0; x < qwidth; x++) 464 | { 465 | int blockbase = (y * qwidth + x) * 4; 466 | 467 | PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); 468 | PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); 469 | ((PNGU_u64 *) buffer)[blockbase] = 470 | alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | 471 | ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | 472 | ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | 473 | ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); 474 | 475 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); 476 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); 477 | ((PNGU_u64 *) buffer)[blockbase+1] = 478 | alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | 479 | ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | 480 | ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | 481 | ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); 482 | 483 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); 484 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); 485 | ((PNGU_u64 *) buffer)[blockbase+2] = 486 | alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | 487 | ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | 488 | ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | 489 | ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); 490 | 491 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); 492 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); 493 | ((PNGU_u64 *) buffer)[blockbase+3] = 494 | alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | 495 | ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | 496 | ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | 497 | ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); 498 | } 499 | } 500 | else 501 | { 502 | // The user wants a translucid texture, so set MSB to 0 and encode colors in ARGB3444 503 | default_alpha = (default_alpha << 4); 504 | alphaMask = (((PNGU_u64) default_alpha) << 56) | (((PNGU_u64) default_alpha) << 40) | 505 | (((PNGU_u64) default_alpha) << 24) | (((PNGU_u64) default_alpha) << 8); 506 | 507 | for (y = 0; y < qheight; y++) 508 | for (x = 0; x < qwidth; x++) 509 | { 510 | int blockbase = (y * qwidth + x) * 4; 511 | 512 | PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); 513 | PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); 514 | ((PNGU_u64 *) buffer)[blockbase] = 515 | alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | 516 | ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | 517 | ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | 518 | ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); 519 | 520 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); 521 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); 522 | ((PNGU_u64 *) buffer)[blockbase+1] = 523 | alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | 524 | ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | 525 | ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | 526 | ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); 527 | 528 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); 529 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); 530 | ((PNGU_u64 *) buffer)[blockbase+2] = 531 | alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | 532 | ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | 533 | ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | 534 | ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); 535 | 536 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); 537 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); 538 | ((PNGU_u64 *) buffer)[blockbase+3] = 539 | alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | 540 | ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | 541 | ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | 542 | ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); 543 | } 544 | } 545 | } 546 | 547 | // Free resources 548 | free (ctx->img_data); 549 | free (ctx->row_pointers); 550 | 551 | // Success 552 | return PNGU_OK; 553 | } 554 | 555 | 556 | int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha) 557 | { 558 | int result; 559 | PNGU_u32 x, y, qwidth, qheight; 560 | PNGU_u64 alphaMask; 561 | 562 | // width and height need to be divisible by four 563 | if ((width % 4) || (height % 4)) 564 | return PNGU_INVALID_WIDTH_OR_HEIGHT; 565 | 566 | result = pngu_decode (ctx, width, height, 0); 567 | if (result != PNGU_OK) 568 | return result; 569 | 570 | // Init some variables 571 | qwidth = width / 4; 572 | qheight = height / 4; 573 | 574 | // Check is source image has an alpha channel 575 | if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) 576 | { 577 | // Alpha channel present, copy image to the output buffer 578 | for (y = 0; y < qheight; y++) 579 | for (x = 0; x < qwidth; x++) 580 | { 581 | int blockbase = (y * qwidth + x) * 8; 582 | 583 | PNGU_u64 fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16)); 584 | PNGU_u64 fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16+8)); 585 | ((PNGU_u64 *) buffer)[blockbase] = 586 | ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | 587 | ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | 588 | ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | 589 | ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); 590 | ((PNGU_u64 *) buffer)[blockbase+4] = 591 | ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | 592 | ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); 593 | 594 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16)); 595 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16+8)); 596 | ((PNGU_u64 *) buffer)[blockbase+1] = 597 | ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | 598 | ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | 599 | ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | 600 | ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); 601 | ((PNGU_u64 *) buffer)[blockbase+5] = 602 | ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | 603 | ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); 604 | 605 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16)); 606 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16+8)); 607 | ((PNGU_u64 *) buffer)[blockbase+2] = 608 | ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | 609 | ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | 610 | ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | 611 | ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); 612 | ((PNGU_u64 *) buffer)[blockbase+6] = 613 | ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | 614 | ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); 615 | 616 | fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16)); 617 | fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16+8)); 618 | ((PNGU_u64 *) buffer)[blockbase+3] = 619 | ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | 620 | ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | 621 | ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | 622 | ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); 623 | ((PNGU_u64 *) buffer)[blockbase+7] = 624 | ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | 625 | ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); 626 | } 627 | } 628 | else 629 | { 630 | // No alpha channel present, copy image to the output buffer 631 | alphaMask = (((PNGU_u64)default_alpha) << 56) | (((PNGU_u64)default_alpha) << 40) | 632 | (((PNGU_u64)default_alpha) << 24) | (((PNGU_u64)default_alpha) << 8); 633 | 634 | for (y = 0; y < qheight; y++) 635 | for (x = 0; x < qwidth; x++) 636 | { 637 | int blockbase = (y * qwidth + x) * 8; 638 | 639 | PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); 640 | PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); 641 | ((PNGU_u64 *) buffer)[blockbase] = 642 | (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | 643 | ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); 644 | ((PNGU_u64 *) buffer)[blockbase+4] = 645 | (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | 646 | ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); 647 | 648 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); 649 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); 650 | ((PNGU_u64 *) buffer)[blockbase+1] = 651 | (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | 652 | ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); 653 | ((PNGU_u64 *) buffer)[blockbase+5] = 654 | (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | 655 | ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); 656 | 657 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); 658 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); 659 | ((PNGU_u64 *) buffer)[blockbase+2] = 660 | (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | 661 | ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); 662 | ((PNGU_u64 *) buffer)[blockbase+6] = 663 | (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | 664 | ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); 665 | 666 | field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); 667 | field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); 668 | ((PNGU_u64 *) buffer)[blockbase+3] = 669 | (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | 670 | ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); 671 | ((PNGU_u64 *) buffer)[blockbase+7] = 672 | (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | 673 | ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); 674 | } 675 | } 676 | 677 | // Free resources 678 | free (ctx->img_data); 679 | free (ctx->row_pointers); 680 | 681 | // Success 682 | return PNGU_OK; 683 | } 684 | 685 | 686 | int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) 687 | { 688 | png_uint_32 rowbytes; 689 | PNGU_u32 x, y, buffWidth; 690 | 691 | // Erase from the context any readed info 692 | pngu_free_info (ctx); 693 | ctx->propRead = 0; 694 | 695 | // Check if the user has selected a file to write the image 696 | if (ctx->source == PNGU_SOURCE_BUFFER); 697 | 698 | else if (ctx->source == PNGU_SOURCE_DEVICE) 699 | { 700 | // Open file 701 | if (!(ctx->fd = fopen (ctx->filename, "wb"))) 702 | return PNGU_CANT_OPEN_FILE; 703 | } 704 | 705 | else 706 | return PNGU_NO_FILE_SELECTED; 707 | 708 | // Allocation of libpng structs 709 | ctx->png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 710 | if (!(ctx->png_ptr)) 711 | { 712 | if (ctx->source == PNGU_SOURCE_DEVICE) 713 | fclose (ctx->fd); 714 | return PNGU_LIB_ERROR; 715 | } 716 | 717 | ctx->info_ptr = png_create_info_struct (ctx->png_ptr); 718 | if (!(ctx->info_ptr)) 719 | { 720 | png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); 721 | if (ctx->source == PNGU_SOURCE_DEVICE) 722 | fclose (ctx->fd); 723 | return PNGU_LIB_ERROR; 724 | } 725 | 726 | if (ctx->source == PNGU_SOURCE_BUFFER) 727 | { 728 | // Installation of our custom data writer function 729 | ctx->cursor = 0; 730 | png_set_write_fn (ctx->png_ptr, ctx, pngu_write_data_to_buffer, pngu_flush_data_to_buffer); 731 | } 732 | else if (ctx->source == PNGU_SOURCE_DEVICE) 733 | { 734 | // Default data writer uses function fwrite, so it needs to use our FILE* 735 | png_init_io (ctx->png_ptr, ctx->fd); 736 | } 737 | 738 | // Setup output file properties 739 | png_set_IHDR (ctx->png_ptr, ctx->info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, 740 | PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); 741 | 742 | // Allocate memory to store the image in RGB format 743 | rowbytes = width * 3; 744 | if (rowbytes % 4) 745 | rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary 746 | 747 | ctx->img_data = malloc (rowbytes * height); 748 | if (!ctx->img_data) 749 | { 750 | png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); 751 | if (ctx->source == PNGU_SOURCE_DEVICE) 752 | fclose (ctx->fd); 753 | return PNGU_LIB_ERROR; 754 | } 755 | 756 | ctx->row_pointers = malloc (sizeof (png_bytep) * height); 757 | if (!ctx->row_pointers) 758 | { 759 | png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); 760 | if (ctx->source == PNGU_SOURCE_DEVICE) 761 | fclose (ctx->fd); 762 | return PNGU_LIB_ERROR; 763 | } 764 | 765 | // Encode YCbYCr image into RGB8 format 766 | buffWidth = (width + stride) / 2; 767 | for (y = 0; y < height; y++) 768 | { 769 | ctx->row_pointers[y] = ctx->img_data + (y * rowbytes); 770 | 771 | for (x = 0; x < (width / 2); x++) 772 | PNGU_YCbYCr_TO_RGB8 ( ((PNGU_u32 *)buffer)[y*buffWidth+x], 773 | ((PNGU_u8 *) ctx->row_pointers[y]+x*6), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+1), 774 | ((PNGU_u8 *) ctx->row_pointers[y]+x*6+2), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+3), 775 | ((PNGU_u8 *) ctx->row_pointers[y]+x*6+4), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+5) ); 776 | } 777 | 778 | // Tell libpng where is our image data 779 | png_set_rows (ctx->png_ptr, ctx->info_ptr, ctx->row_pointers); 780 | 781 | // Write file header and image data 782 | png_write_png (ctx->png_ptr, ctx->info_ptr, PNG_TRANSFORM_IDENTITY, NULL); 783 | 784 | // Tell libpng we have no more data to write 785 | png_write_end (ctx->png_ptr, (png_infop) NULL); 786 | 787 | // Free resources 788 | free (ctx->img_data); 789 | free (ctx->row_pointers); 790 | png_destroy_write_struct (&(ctx->png_ptr), &(ctx->info_ptr)); 791 | if (ctx->source == PNGU_SOURCE_DEVICE) 792 | fclose (ctx->fd); 793 | 794 | // Success 795 | return PNGU_OK; 796 | } 797 | 798 | 799 | // This function is taken from a libogc example 800 | PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2) 801 | { 802 | int y1, cb1, cr1, y2, cb2, cr2, cb, cr; 803 | 804 | y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000; 805 | cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000; 806 | cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000; 807 | 808 | y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000; 809 | cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000; 810 | cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000; 811 | 812 | cb = (cb1 + cb2) >> 1; 813 | cr = (cr1 + cr2) >> 1; 814 | 815 | return (PNGU_u32) ((y1 << 24) | (cb << 16) | (y2 << 8) | cr); 816 | } 817 | 818 | 819 | void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2) 820 | { 821 | PNGU_u8 *val = (PNGU_u8 *) &ycbycr; 822 | int r, g, b; 823 | 824 | r = 1.371f * (val[3] - 128); 825 | g = - 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128); 826 | b = 1.732f * (val[1] - 128); 827 | 828 | *r1 = pngu_clamp (val[0] + r, 0, 255); 829 | *g1 = pngu_clamp (val[0] + g, 0, 255); 830 | *b1 = pngu_clamp (val[0] + b, 0, 255); 831 | 832 | *r2 = pngu_clamp (val[2] + r, 0, 255); 833 | *g2 = pngu_clamp (val[2] + g, 0, 255); 834 | *b2 = pngu_clamp (val[2] + b, 0, 255); 835 | } 836 | 837 | 838 | int pngu_info (IMGCTX ctx) 839 | { 840 | png_byte magic[8]; 841 | png_uint_32 width; 842 | png_uint_32 height; 843 | png_color_16p background; 844 | png_bytep trans; 845 | png_color_16p trans_values; 846 | int scale, i; 847 | 848 | // Check if there is a file selected and if it is a valid .png 849 | if (ctx->source == PNGU_SOURCE_BUFFER) 850 | memcpy (magic, ctx->buffer, 8); 851 | 852 | else if (ctx->source == PNGU_SOURCE_DEVICE) 853 | { 854 | // Open file 855 | if (!(ctx->fd = fopen (ctx->filename, "rb"))) 856 | return PNGU_CANT_OPEN_FILE; 857 | 858 | // Load first 8 bytes into magic buffer 859 | if (fread (magic, 1, 8, ctx->fd) != 8) 860 | { 861 | fclose (ctx->fd); 862 | return PNGU_CANT_READ_FILE; 863 | } 864 | } 865 | 866 | else 867 | return PNGU_NO_FILE_SELECTED;; 868 | 869 | if (png_sig_cmp(magic, 0, 8) != 0) 870 | { 871 | if (ctx->source == PNGU_SOURCE_DEVICE) 872 | fclose (ctx->fd); 873 | return PNGU_FILE_IS_NOT_PNG; 874 | } 875 | 876 | // Allocation of libpng structs 877 | ctx->png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 878 | if (!(ctx->png_ptr)) 879 | { 880 | if (ctx->source == PNGU_SOURCE_DEVICE) 881 | fclose (ctx->fd); 882 | return PNGU_LIB_ERROR; 883 | } 884 | 885 | ctx->info_ptr = png_create_info_struct (ctx->png_ptr); 886 | if (!(ctx->info_ptr)) 887 | { 888 | if (ctx->source == PNGU_SOURCE_DEVICE) 889 | fclose (ctx->fd); 890 | png_destroy_read_struct (&(ctx->png_ptr), (png_infopp)NULL, (png_infopp)NULL); 891 | return PNGU_LIB_ERROR; 892 | } 893 | 894 | if (ctx->source == PNGU_SOURCE_BUFFER) 895 | { 896 | // Installation of our custom data provider function 897 | ctx->cursor = 0; 898 | png_set_read_fn (ctx->png_ptr, ctx, pngu_read_data_from_buffer); 899 | } 900 | else if (ctx->source == PNGU_SOURCE_DEVICE) 901 | { 902 | // Default data provider uses function fread, so it needs to use our FILE* 903 | png_init_io (ctx->png_ptr, ctx->fd); 904 | png_set_sig_bytes (ctx->png_ptr, 8); // We have read 8 bytes already to check PNG authenticity 905 | } 906 | 907 | // Read png header 908 | png_read_info (ctx->png_ptr, ctx->info_ptr); 909 | 910 | // Query image properties if they have not been queried before 911 | if (!ctx->propRead) 912 | { 913 | png_get_IHDR(ctx->png_ptr, ctx->info_ptr, &width, &height, 914 | (int *) &(ctx->prop.imgBitDepth), 915 | (int *) &(ctx->prop.imgColorType), 916 | NULL, NULL, NULL); 917 | 918 | ctx->prop.imgWidth = width; 919 | ctx->prop.imgHeight = height; 920 | switch (ctx->prop.imgColorType) 921 | { 922 | case PNG_COLOR_TYPE_GRAY: 923 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_GRAY; 924 | break; 925 | case PNG_COLOR_TYPE_GRAY_ALPHA: 926 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_GRAY_ALPHA; 927 | break; 928 | case PNG_COLOR_TYPE_PALETTE: 929 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_PALETTE; 930 | break; 931 | case PNG_COLOR_TYPE_RGB: 932 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_RGB; 933 | break; 934 | case PNG_COLOR_TYPE_RGB_ALPHA: 935 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_RGB_ALPHA; 936 | break; 937 | default: 938 | ctx->prop.imgColorType = PNGU_COLOR_TYPE_UNKNOWN; 939 | break; 940 | } 941 | 942 | // Constant used to scale 16 bit values to 8 bit values 943 | scale = 1; 944 | if (ctx->prop.imgBitDepth == 16) 945 | scale = 256; 946 | 947 | // Query background color, if any. 948 | ctx->prop.validBckgrnd = 0; 949 | if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA)) && 950 | (png_get_bKGD (ctx->png_ptr, ctx->info_ptr, &background))) 951 | { 952 | ctx->prop.validBckgrnd = 1; 953 | ctx->prop.bckgrnd.r = background->red / scale; 954 | ctx->prop.bckgrnd.g = background->green / scale; 955 | ctx->prop.bckgrnd.b = background->blue / scale; 956 | } 957 | else if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA)) && 958 | (png_get_bKGD (ctx->png_ptr, ctx->info_ptr, &background))) 959 | { 960 | ctx->prop.validBckgrnd = 1; 961 | ctx->prop.bckgrnd.r = ctx->prop.bckgrnd.g = ctx->prop.bckgrnd.b = background->gray / scale; 962 | } 963 | 964 | // Query list of transparent colors, if any. 965 | ctx->prop.numTrans = 0; 966 | ctx->prop.trans = NULL; 967 | if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA)) && 968 | (png_get_tRNS (ctx->png_ptr, ctx->info_ptr, &trans, (int *) &(ctx->prop.numTrans), &trans_values))) 969 | { 970 | if (ctx->prop.numTrans) 971 | { 972 | ctx->prop.trans = malloc (sizeof (PNGUCOLOR) * ctx->prop.numTrans); 973 | if (ctx->prop.trans) 974 | for (i = 0; i < ctx->prop.numTrans; i++) 975 | { 976 | ctx->prop.trans[i].r = trans_values[i].red / scale; 977 | ctx->prop.trans[i].g = trans_values[i].green / scale; 978 | ctx->prop.trans[i].b = trans_values[i].blue / scale; 979 | } 980 | else 981 | ctx->prop.numTrans = 0; 982 | } 983 | } 984 | else if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA)) && 985 | (png_get_tRNS (ctx->png_ptr, ctx->info_ptr, &trans, (int *) &(ctx->prop.numTrans), &trans_values))) 986 | { 987 | if (ctx->prop.numTrans) 988 | { 989 | ctx->prop.trans = malloc (sizeof (PNGUCOLOR) * ctx->prop.numTrans); 990 | if (ctx->prop.trans) 991 | for (i = 0; i < ctx->prop.numTrans; i++) 992 | ctx->prop.trans[i].r = ctx->prop.trans[i].g = ctx->prop.trans[i].b = 993 | trans_values[i].gray / scale; 994 | else 995 | ctx->prop.numTrans = 0; 996 | } 997 | } 998 | 999 | ctx->propRead = 1; 1000 | } 1001 | 1002 | // Success 1003 | ctx->infoRead = 1; 1004 | 1005 | return PNGU_OK; 1006 | } 1007 | 1008 | 1009 | int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha) 1010 | { 1011 | png_uint_32 rowbytes; 1012 | int i; 1013 | 1014 | // Read info if it hasn't been read before 1015 | if (!ctx->infoRead) 1016 | { 1017 | i = pngu_info (ctx); 1018 | if (i != PNGU_OK) 1019 | return i; 1020 | } 1021 | 1022 | // Check if the user has specified the real width and height of the image 1023 | if ( (ctx->prop.imgWidth != width) || (ctx->prop.imgHeight != height) ) 1024 | return PNGU_INVALID_WIDTH_OR_HEIGHT; 1025 | 1026 | // Check if color type is supported by PNGU 1027 | if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_PALETTE) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_UNKNOWN) ) 1028 | return PNGU_UNSUPPORTED_COLOR_TYPE; 1029 | 1030 | // Scale 16 bit samples to 8 bit 1031 | if (ctx->prop.imgBitDepth == 16) 1032 | png_set_strip_16 (ctx->png_ptr); 1033 | 1034 | // Remove alpha channel if we don't need it 1035 | if (stripAlpha && ((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA))) 1036 | png_set_strip_alpha (ctx->png_ptr); 1037 | 1038 | // Expand 1, 2 and 4 bit samples to 8 bit 1039 | if (ctx->prop.imgBitDepth < 8) 1040 | png_set_packing (ctx->png_ptr); 1041 | 1042 | // Transform grayscale images to RGB 1043 | if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) ) 1044 | png_set_gray_to_rgb (ctx->png_ptr); 1045 | 1046 | // Flush transformations 1047 | png_read_update_info (ctx->png_ptr, ctx->info_ptr); 1048 | 1049 | // Allocate memory to store the image 1050 | rowbytes = png_get_rowbytes (ctx->png_ptr, ctx->info_ptr); 1051 | if (rowbytes % 4) 1052 | rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary 1053 | 1054 | ctx->img_data = malloc (rowbytes * ctx->prop.imgHeight); 1055 | if (!ctx->img_data) 1056 | { 1057 | pngu_free_info (ctx); 1058 | return PNGU_LIB_ERROR; 1059 | } 1060 | 1061 | ctx->row_pointers = malloc (sizeof (png_bytep) * ctx->prop.imgHeight); 1062 | if (!ctx->row_pointers) 1063 | { 1064 | free (ctx->img_data); 1065 | pngu_free_info (ctx); 1066 | return PNGU_LIB_ERROR; 1067 | } 1068 | 1069 | for (i = 0; i < ctx->prop.imgHeight; i++) 1070 | ctx->row_pointers[i] = ctx->img_data + (i * rowbytes); 1071 | 1072 | // Transform the image and copy it to our allocated memory 1073 | png_read_image (ctx->png_ptr, ctx->row_pointers); 1074 | 1075 | // Free resources 1076 | pngu_free_info (ctx); 1077 | 1078 | // Success 1079 | return PNGU_OK; 1080 | } 1081 | 1082 | 1083 | void pngu_free_info (IMGCTX ctx) 1084 | { 1085 | if (ctx->infoRead) 1086 | { 1087 | if (ctx->source == PNGU_SOURCE_DEVICE) 1088 | fclose (ctx->fd); 1089 | 1090 | png_destroy_read_struct (&(ctx->png_ptr), &(ctx->info_ptr), (png_infopp)NULL); 1091 | 1092 | ctx->infoRead = 0; 1093 | } 1094 | } 1095 | 1096 | 1097 | // Custom data provider function used for reading from memory buffers. 1098 | void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length) 1099 | { 1100 | IMGCTX ctx = (IMGCTX) png_get_io_ptr (png_ptr); 1101 | memcpy (data, ctx->buffer + ctx->cursor, length); 1102 | ctx->cursor += length; 1103 | } 1104 | 1105 | 1106 | // Custom data writer function used for writing to memory buffers. 1107 | void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length) 1108 | { 1109 | IMGCTX ctx = (IMGCTX) png_get_io_ptr (png_ptr); 1110 | memcpy (ctx->buffer + ctx->cursor, data, length); 1111 | ctx->cursor += length; 1112 | } 1113 | 1114 | 1115 | // Custom data flusher function used for writing to memory buffers. 1116 | void pngu_flush_data_to_buffer (png_structp png_ptr) 1117 | { 1118 | // Nothing to do here 1119 | } 1120 | 1121 | 1122 | // Function used in YCbYCr to RGB decoding 1123 | int pngu_clamp (int value, int min, int max) 1124 | { 1125 | if (value < min) 1126 | value = min; 1127 | else if (value > max) 1128 | value = max; 1129 | 1130 | return value; 1131 | } 1132 | 1133 | -------------------------------------------------------------------------------- /source/libpng/pngconf.h: -------------------------------------------------------------------------------- 1 | 2 | /* pngconf.h - machine configurable file for libpng 3 | * 4 | * libpng version 1.2.29 - May 8, 2008 5 | * For conditions of distribution and use, see copyright notice in png.h 6 | * Copyright (c) 1998-2008 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | */ 10 | 11 | /* Any machine specific code is near the front of this file, so if you 12 | * are configuring libpng for a machine, you may want to read the section 13 | * starting here down to where it starts to typedef png_color, png_text, 14 | * and png_info. 15 | */ 16 | 17 | #ifndef PNGCONF_H 18 | #define PNGCONF_H 19 | 20 | #define PNG_1_2_X 21 | 22 | /* 23 | * PNG_USER_CONFIG has to be defined on the compiler command line. This 24 | * includes the resource compiler for Windows DLL configurations. 25 | */ 26 | #ifdef PNG_USER_CONFIG 27 | # ifndef PNG_USER_PRIVATEBUILD 28 | # define PNG_USER_PRIVATEBUILD 29 | # endif 30 | #include "pngusr.h" 31 | #endif 32 | 33 | /* PNG_CONFIGURE_LIBPNG is set by the "configure" script. */ 34 | #ifdef PNG_CONFIGURE_LIBPNG 35 | #ifdef HAVE_CONFIG_H 36 | #include "config.h" 37 | #endif 38 | #endif 39 | 40 | /* 41 | * Added at libpng-1.2.8 42 | * 43 | * If you create a private DLL you need to define in "pngusr.h" the followings: 44 | * #define PNG_USER_PRIVATEBUILD 46 | * e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons." 47 | * #define PNG_USER_DLLFNAME_POSTFIX 51 | * e.g. // private DLL "libpng13gx.dll" 52 | * #define PNG_USER_DLLFNAME_POSTFIX "gx" 53 | * 54 | * The following macros are also at your disposal if you want to complete the 55 | * DLL VERSIONINFO structure. 56 | * - PNG_USER_VERSIONINFO_COMMENTS 57 | * - PNG_USER_VERSIONINFO_COMPANYNAME 58 | * - PNG_USER_VERSIONINFO_LEGALTRADEMARKS 59 | */ 60 | 61 | #ifdef __STDC__ 62 | #ifdef SPECIALBUILD 63 | # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\ 64 | are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.") 65 | #endif 66 | 67 | #ifdef PRIVATEBUILD 68 | # pragma message("PRIVATEBUILD is deprecated.\ 69 | Use PNG_USER_PRIVATEBUILD instead.") 70 | # define PNG_USER_PRIVATEBUILD PRIVATEBUILD 71 | #endif 72 | #endif /* __STDC__ */ 73 | 74 | #ifndef PNG_VERSION_INFO_ONLY 75 | 76 | /* End of material added to libpng-1.2.8 */ 77 | 78 | /* Added at libpng-1.2.19, removed at libpng-1.2.20 because it caused trouble 79 | Restored at libpng-1.2.21 */ 80 | #if !defined(PNG_NO_WARN_UNINITIALIZED_ROW) && \ 81 | !defined(PNG_WARN_UNINITIALIZED_ROW) 82 | # define PNG_WARN_UNINITIALIZED_ROW 1 83 | #endif 84 | /* End of material added at libpng-1.2.19/1.2.21 */ 85 | 86 | /* This is the size of the compression buffer, and thus the size of 87 | * an IDAT chunk. Make this whatever size you feel is best for your 88 | * machine. One of these will be allocated per png_struct. When this 89 | * is full, it writes the data to the disk, and does some other 90 | * calculations. Making this an extremely small size will slow 91 | * the library down, but you may want to experiment to determine 92 | * where it becomes significant, if you are concerned with memory 93 | * usage. Note that zlib allocates at least 32Kb also. For readers, 94 | * this describes the size of the buffer available to read the data in. 95 | * Unless this gets smaller than the size of a row (compressed), 96 | * it should not make much difference how big this is. 97 | */ 98 | 99 | #ifndef PNG_ZBUF_SIZE 100 | # define PNG_ZBUF_SIZE 8192 101 | #endif 102 | 103 | /* Enable if you want a write-only libpng */ 104 | 105 | #ifndef PNG_NO_READ_SUPPORTED 106 | # define PNG_READ_SUPPORTED 107 | #endif 108 | 109 | /* Enable if you want a read-only libpng */ 110 | 111 | #ifndef PNG_NO_WRITE_SUPPORTED 112 | # define PNG_WRITE_SUPPORTED 113 | #endif 114 | 115 | /* Enabled by default in 1.2.0. You can disable this if you don't need to 116 | support PNGs that are embedded in MNG datastreams */ 117 | #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES) 118 | # ifndef PNG_MNG_FEATURES_SUPPORTED 119 | # define PNG_MNG_FEATURES_SUPPORTED 120 | # endif 121 | #endif 122 | 123 | #ifndef PNG_NO_FLOATING_POINT_SUPPORTED 124 | # ifndef PNG_FLOATING_POINT_SUPPORTED 125 | # define PNG_FLOATING_POINT_SUPPORTED 126 | # endif 127 | #endif 128 | 129 | /* If you are running on a machine where you cannot allocate more 130 | * than 64K of memory at once, uncomment this. While libpng will not 131 | * normally need that much memory in a chunk (unless you load up a very 132 | * large file), zlib needs to know how big of a chunk it can use, and 133 | * libpng thus makes sure to check any memory allocation to verify it 134 | * will fit into memory. 135 | #define PNG_MAX_MALLOC_64K 136 | */ 137 | #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) 138 | # define PNG_MAX_MALLOC_64K 139 | #endif 140 | 141 | /* Special munging to support doing things the 'cygwin' way: 142 | * 'Normal' png-on-win32 defines/defaults: 143 | * PNG_BUILD_DLL -- building dll 144 | * PNG_USE_DLL -- building an application, linking to dll 145 | * (no define) -- building static library, or building an 146 | * application and linking to the static lib 147 | * 'Cygwin' defines/defaults: 148 | * PNG_BUILD_DLL -- (ignored) building the dll 149 | * (no define) -- (ignored) building an application, linking to the dll 150 | * PNG_STATIC -- (ignored) building the static lib, or building an 151 | * application that links to the static lib. 152 | * ALL_STATIC -- (ignored) building various static libs, or building an 153 | * application that links to the static libs. 154 | * Thus, 155 | * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and 156 | * this bit of #ifdefs will define the 'correct' config variables based on 157 | * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but 158 | * unnecessary. 159 | * 160 | * Also, the precedence order is: 161 | * ALL_STATIC (since we can't #undef something outside our namespace) 162 | * PNG_BUILD_DLL 163 | * PNG_STATIC 164 | * (nothing) == PNG_USE_DLL 165 | * 166 | * CYGWIN (2002-01-20): The preceding is now obsolete. With the advent 167 | * of auto-import in binutils, we no longer need to worry about 168 | * __declspec(dllexport) / __declspec(dllimport) and friends. Therefore, 169 | * we don't need to worry about PNG_STATIC or ALL_STATIC when it comes 170 | * to __declspec() stuff. However, we DO need to worry about 171 | * PNG_BUILD_DLL and PNG_STATIC because those change some defaults 172 | * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. 173 | */ 174 | #if defined(__CYGWIN__) 175 | # if defined(ALL_STATIC) 176 | # if defined(PNG_BUILD_DLL) 177 | # undef PNG_BUILD_DLL 178 | # endif 179 | # if defined(PNG_USE_DLL) 180 | # undef PNG_USE_DLL 181 | # endif 182 | # if defined(PNG_DLL) 183 | # undef PNG_DLL 184 | # endif 185 | # if !defined(PNG_STATIC) 186 | # define PNG_STATIC 187 | # endif 188 | # else 189 | # if defined (PNG_BUILD_DLL) 190 | # if defined(PNG_STATIC) 191 | # undef PNG_STATIC 192 | # endif 193 | # if defined(PNG_USE_DLL) 194 | # undef PNG_USE_DLL 195 | # endif 196 | # if !defined(PNG_DLL) 197 | # define PNG_DLL 198 | # endif 199 | # else 200 | # if defined(PNG_STATIC) 201 | # if defined(PNG_USE_DLL) 202 | # undef PNG_USE_DLL 203 | # endif 204 | # if defined(PNG_DLL) 205 | # undef PNG_DLL 206 | # endif 207 | # else 208 | # if !defined(PNG_USE_DLL) 209 | # define PNG_USE_DLL 210 | # endif 211 | # if !defined(PNG_DLL) 212 | # define PNG_DLL 213 | # endif 214 | # endif 215 | # endif 216 | # endif 217 | #endif 218 | 219 | /* This protects us against compilers that run on a windowing system 220 | * and thus don't have or would rather us not use the stdio types: 221 | * stdin, stdout, and stderr. The only one currently used is stderr 222 | * in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will 223 | * prevent these from being compiled and used. #defining PNG_NO_STDIO 224 | * will also prevent these, plus will prevent the entire set of stdio 225 | * macros and functions (FILE *, printf, etc.) from being compiled and used, 226 | * unless (PNG_DEBUG > 0) has been #defined. 227 | * 228 | * #define PNG_NO_CONSOLE_IO 229 | * #define PNG_NO_STDIO 230 | */ 231 | 232 | #if defined(_WIN32_WCE) 233 | # include 234 | /* Console I/O functions are not supported on WindowsCE */ 235 | # define PNG_NO_CONSOLE_IO 236 | # ifdef PNG_DEBUG 237 | # undef PNG_DEBUG 238 | # endif 239 | #endif 240 | 241 | #ifdef PNG_BUILD_DLL 242 | # ifndef PNG_CONSOLE_IO_SUPPORTED 243 | # ifndef PNG_NO_CONSOLE_IO 244 | # define PNG_NO_CONSOLE_IO 245 | # endif 246 | # endif 247 | #endif 248 | 249 | # ifdef PNG_NO_STDIO 250 | # ifndef PNG_NO_CONSOLE_IO 251 | # define PNG_NO_CONSOLE_IO 252 | # endif 253 | # ifdef PNG_DEBUG 254 | # if (PNG_DEBUG > 0) 255 | # include 256 | # endif 257 | # endif 258 | # else 259 | # if !defined(_WIN32_WCE) 260 | /* "stdio.h" functions are not supported on WindowsCE */ 261 | # include 262 | # endif 263 | # endif 264 | 265 | /* This macro protects us against machines that don't have function 266 | * prototypes (ie K&R style headers). If your compiler does not handle 267 | * function prototypes, define this macro and use the included ansi2knr. 268 | * I've always been able to use _NO_PROTO as the indicator, but you may 269 | * need to drag the empty declaration out in front of here, or change the 270 | * ifdef to suit your own needs. 271 | */ 272 | #ifndef PNGARG 273 | 274 | #ifdef OF /* zlib prototype munger */ 275 | # define PNGARG(arglist) OF(arglist) 276 | #else 277 | 278 | #ifdef _NO_PROTO 279 | # define PNGARG(arglist) () 280 | # ifndef PNG_TYPECAST_NULL 281 | # define PNG_TYPECAST_NULL 282 | # endif 283 | #else 284 | # define PNGARG(arglist) arglist 285 | #endif /* _NO_PROTO */ 286 | 287 | 288 | #endif /* OF */ 289 | 290 | #endif /* PNGARG */ 291 | 292 | /* Try to determine if we are compiling on a Mac. Note that testing for 293 | * just __MWERKS__ is not good enough, because the Codewarrior is now used 294 | * on non-Mac platforms. 295 | */ 296 | #ifndef MACOS 297 | # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ 298 | defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) 299 | # define MACOS 300 | # endif 301 | #endif 302 | 303 | /* enough people need this for various reasons to include it here */ 304 | #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) 305 | # include 306 | #endif 307 | 308 | #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) 309 | # define PNG_SETJMP_SUPPORTED 310 | #endif 311 | 312 | #ifdef PNG_SETJMP_SUPPORTED 313 | /* This is an attempt to force a single setjmp behaviour on Linux. If 314 | * the X config stuff didn't define _BSD_SOURCE we wouldn't need this. 315 | */ 316 | 317 | # ifdef __linux__ 318 | # ifdef _BSD_SOURCE 319 | # define PNG_SAVE_BSD_SOURCE 320 | # undef _BSD_SOURCE 321 | # endif 322 | # ifdef _SETJMP_H 323 | /* If you encounter a compiler error here, see the explanation 324 | * near the end of INSTALL. 325 | */ 326 | __pngconf.h__ already includes setjmp.h; 327 | __dont__ include it again.; 328 | # endif 329 | # endif /* __linux__ */ 330 | 331 | /* include setjmp.h for error handling */ 332 | # include 333 | 334 | # ifdef __linux__ 335 | # ifdef PNG_SAVE_BSD_SOURCE 336 | # ifndef _BSD_SOURCE 337 | # define _BSD_SOURCE 338 | # endif 339 | # undef PNG_SAVE_BSD_SOURCE 340 | # endif 341 | # endif /* __linux__ */ 342 | #endif /* PNG_SETJMP_SUPPORTED */ 343 | 344 | #ifdef BSD 345 | # include 346 | #else 347 | # include 348 | #endif 349 | 350 | /* Other defines for things like memory and the like can go here. */ 351 | #ifdef PNG_INTERNAL 352 | 353 | #include 354 | 355 | /* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which 356 | * aren't usually used outside the library (as far as I know), so it is 357 | * debatable if they should be exported at all. In the future, when it is 358 | * possible to have run-time registry of chunk-handling functions, some of 359 | * these will be made available again. 360 | #define PNG_EXTERN extern 361 | */ 362 | #define PNG_EXTERN 363 | 364 | /* Other defines specific to compilers can go here. Try to keep 365 | * them inside an appropriate ifdef/endif pair for portability. 366 | */ 367 | 368 | #if defined(PNG_FLOATING_POINT_SUPPORTED) 369 | # if defined(MACOS) 370 | /* We need to check that hasn't already been included earlier 371 | * as it seems it doesn't agree with , yet we should really use 372 | * if possible. 373 | */ 374 | # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) 375 | # include 376 | # endif 377 | # else 378 | # include 379 | # endif 380 | # if defined(_AMIGA) && defined(__SASC) && defined(_M68881) 381 | /* Amiga SAS/C: We must include builtin FPU functions when compiling using 382 | * MATH=68881 383 | */ 384 | # include 385 | # endif 386 | #endif 387 | 388 | /* Codewarrior on NT has linking problems without this. */ 389 | #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) 390 | # define PNG_ALWAYS_EXTERN 391 | #endif 392 | 393 | /* This provides the non-ANSI (far) memory allocation routines. */ 394 | #if defined(__TURBOC__) && defined(__MSDOS__) 395 | # include 396 | # include 397 | #endif 398 | 399 | /* I have no idea why is this necessary... */ 400 | #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ 401 | defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) 402 | # include 403 | #endif 404 | 405 | /* This controls how fine the dithering gets. As this allocates 406 | * a largish chunk of memory (32K), those who are not as concerned 407 | * with dithering quality can decrease some or all of these. 408 | */ 409 | #ifndef PNG_DITHER_RED_BITS 410 | # define PNG_DITHER_RED_BITS 5 411 | #endif 412 | #ifndef PNG_DITHER_GREEN_BITS 413 | # define PNG_DITHER_GREEN_BITS 5 414 | #endif 415 | #ifndef PNG_DITHER_BLUE_BITS 416 | # define PNG_DITHER_BLUE_BITS 5 417 | #endif 418 | 419 | /* This controls how fine the gamma correction becomes when you 420 | * are only interested in 8 bits anyway. Increasing this value 421 | * results in more memory being used, and more pow() functions 422 | * being called to fill in the gamma tables. Don't set this value 423 | * less then 8, and even that may not work (I haven't tested it). 424 | */ 425 | 426 | #ifndef PNG_MAX_GAMMA_8 427 | # define PNG_MAX_GAMMA_8 11 428 | #endif 429 | 430 | /* This controls how much a difference in gamma we can tolerate before 431 | * we actually start doing gamma conversion. 432 | */ 433 | #ifndef PNG_GAMMA_THRESHOLD 434 | # define PNG_GAMMA_THRESHOLD 0.05 435 | #endif 436 | 437 | #endif /* PNG_INTERNAL */ 438 | 439 | /* The following uses const char * instead of char * for error 440 | * and warning message functions, so some compilers won't complain. 441 | * If you do not want to use const, define PNG_NO_CONST here. 442 | */ 443 | 444 | #ifndef PNG_NO_CONST 445 | # define PNG_CONST const 446 | #else 447 | # define PNG_CONST 448 | #endif 449 | 450 | /* The following defines give you the ability to remove code from the 451 | * library that you will not be using. I wish I could figure out how to 452 | * automate this, but I can't do that without making it seriously hard 453 | * on the users. So if you are not using an ability, change the #define 454 | * to and #undef, and that part of the library will not be compiled. If 455 | * your linker can't find a function, you may want to make sure the 456 | * ability is defined here. Some of these depend upon some others being 457 | * defined. I haven't figured out all the interactions here, so you may 458 | * have to experiment awhile to get everything to compile. If you are 459 | * creating or using a shared library, you probably shouldn't touch this, 460 | * as it will affect the size of the structures, and this will cause bad 461 | * things to happen if the library and/or application ever change. 462 | */ 463 | 464 | /* Any features you will not be using can be undef'ed here */ 465 | 466 | /* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user 467 | * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS 468 | * on the compile line, then pick and choose which ones to define without 469 | * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED 470 | * if you only want to have a png-compliant reader/writer but don't need 471 | * any of the extra transformations. This saves about 80 kbytes in a 472 | * typical installation of the library. (PNG_NO_* form added in version 473 | * 1.0.1c, for consistency) 474 | */ 475 | 476 | /* The size of the png_text structure changed in libpng-1.0.6 when 477 | * iTXt support was added. iTXt support was turned off by default through 478 | * libpng-1.2.x, to support old apps that malloc the png_text structure 479 | * instead of calling png_set_text() and letting libpng malloc it. It 480 | * was turned on by default in libpng-1.3.0. 481 | */ 482 | 483 | #if defined(PNG_1_0_X) || defined (PNG_1_2_X) 484 | # ifndef PNG_NO_iTXt_SUPPORTED 485 | # define PNG_NO_iTXt_SUPPORTED 486 | # endif 487 | # ifndef PNG_NO_READ_iTXt 488 | # define PNG_NO_READ_iTXt 489 | # endif 490 | # ifndef PNG_NO_WRITE_iTXt 491 | # define PNG_NO_WRITE_iTXt 492 | # endif 493 | #endif 494 | 495 | #if !defined(PNG_NO_iTXt_SUPPORTED) 496 | # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt) 497 | # define PNG_READ_iTXt 498 | # endif 499 | # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt) 500 | # define PNG_WRITE_iTXt 501 | # endif 502 | #endif 503 | 504 | /* The following support, added after version 1.0.0, can be turned off here en 505 | * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility 506 | * with old applications that require the length of png_struct and png_info 507 | * to remain unchanged. 508 | */ 509 | 510 | #ifdef PNG_LEGACY_SUPPORTED 511 | # define PNG_NO_FREE_ME 512 | # define PNG_NO_READ_UNKNOWN_CHUNKS 513 | # define PNG_NO_WRITE_UNKNOWN_CHUNKS 514 | # define PNG_NO_READ_USER_CHUNKS 515 | # define PNG_NO_READ_iCCP 516 | # define PNG_NO_WRITE_iCCP 517 | # define PNG_NO_READ_iTXt 518 | # define PNG_NO_WRITE_iTXt 519 | # define PNG_NO_READ_sCAL 520 | # define PNG_NO_WRITE_sCAL 521 | # define PNG_NO_READ_sPLT 522 | # define PNG_NO_WRITE_sPLT 523 | # define PNG_NO_INFO_IMAGE 524 | # define PNG_NO_READ_RGB_TO_GRAY 525 | # define PNG_NO_READ_USER_TRANSFORM 526 | # define PNG_NO_WRITE_USER_TRANSFORM 527 | # define PNG_NO_USER_MEM 528 | # define PNG_NO_READ_EMPTY_PLTE 529 | # define PNG_NO_MNG_FEATURES 530 | # define PNG_NO_FIXED_POINT_SUPPORTED 531 | #endif 532 | 533 | /* Ignore attempt to turn off both floating and fixed point support */ 534 | #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ 535 | !defined(PNG_NO_FIXED_POINT_SUPPORTED) 536 | # define PNG_FIXED_POINT_SUPPORTED 537 | #endif 538 | 539 | #ifndef PNG_NO_FREE_ME 540 | # define PNG_FREE_ME_SUPPORTED 541 | #endif 542 | 543 | #if defined(PNG_READ_SUPPORTED) 544 | 545 | #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ 546 | !defined(PNG_NO_READ_TRANSFORMS) 547 | # define PNG_READ_TRANSFORMS_SUPPORTED 548 | #endif 549 | 550 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED 551 | # ifndef PNG_NO_READ_EXPAND 552 | # define PNG_READ_EXPAND_SUPPORTED 553 | # endif 554 | # ifndef PNG_NO_READ_SHIFT 555 | # define PNG_READ_SHIFT_SUPPORTED 556 | # endif 557 | # ifndef PNG_NO_READ_PACK 558 | # define PNG_READ_PACK_SUPPORTED 559 | # endif 560 | # ifndef PNG_NO_READ_BGR 561 | # define PNG_READ_BGR_SUPPORTED 562 | # endif 563 | # ifndef PNG_NO_READ_SWAP 564 | # define PNG_READ_SWAP_SUPPORTED 565 | # endif 566 | # ifndef PNG_NO_READ_PACKSWAP 567 | # define PNG_READ_PACKSWAP_SUPPORTED 568 | # endif 569 | # ifndef PNG_NO_READ_INVERT 570 | # define PNG_READ_INVERT_SUPPORTED 571 | # endif 572 | # ifndef PNG_NO_READ_DITHER 573 | # define PNG_READ_DITHER_SUPPORTED 574 | # endif 575 | # ifndef PNG_NO_READ_BACKGROUND 576 | # define PNG_READ_BACKGROUND_SUPPORTED 577 | # endif 578 | # ifndef PNG_NO_READ_16_TO_8 579 | # define PNG_READ_16_TO_8_SUPPORTED 580 | # endif 581 | # ifndef PNG_NO_READ_FILLER 582 | # define PNG_READ_FILLER_SUPPORTED 583 | # endif 584 | # ifndef PNG_NO_READ_GAMMA 585 | # define PNG_READ_GAMMA_SUPPORTED 586 | # endif 587 | # ifndef PNG_NO_READ_GRAY_TO_RGB 588 | # define PNG_READ_GRAY_TO_RGB_SUPPORTED 589 | # endif 590 | # ifndef PNG_NO_READ_SWAP_ALPHA 591 | # define PNG_READ_SWAP_ALPHA_SUPPORTED 592 | # endif 593 | # ifndef PNG_NO_READ_INVERT_ALPHA 594 | # define PNG_READ_INVERT_ALPHA_SUPPORTED 595 | # endif 596 | # ifndef PNG_NO_READ_STRIP_ALPHA 597 | # define PNG_READ_STRIP_ALPHA_SUPPORTED 598 | # endif 599 | # ifndef PNG_NO_READ_USER_TRANSFORM 600 | # define PNG_READ_USER_TRANSFORM_SUPPORTED 601 | # endif 602 | # ifndef PNG_NO_READ_RGB_TO_GRAY 603 | # define PNG_READ_RGB_TO_GRAY_SUPPORTED 604 | # endif 605 | #endif /* PNG_READ_TRANSFORMS_SUPPORTED */ 606 | 607 | #if !defined(PNG_NO_PROGRESSIVE_READ) && \ 608 | !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */ 609 | # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ 610 | #endif /* about interlacing capability! You'll */ 611 | /* still have interlacing unless you change the following line: */ 612 | 613 | #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */ 614 | 615 | #ifndef PNG_NO_READ_COMPOSITE_NODIV 616 | # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ 617 | # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ 618 | # endif 619 | #endif 620 | 621 | #if defined(PNG_1_0_X) || defined (PNG_1_2_X) 622 | /* Deprecated, will be removed from version 2.0.0. 623 | Use PNG_MNG_FEATURES_SUPPORTED instead. */ 624 | #ifndef PNG_NO_READ_EMPTY_PLTE 625 | # define PNG_READ_EMPTY_PLTE_SUPPORTED 626 | #endif 627 | #endif 628 | 629 | #endif /* PNG_READ_SUPPORTED */ 630 | 631 | #if defined(PNG_WRITE_SUPPORTED) 632 | 633 | # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ 634 | !defined(PNG_NO_WRITE_TRANSFORMS) 635 | # define PNG_WRITE_TRANSFORMS_SUPPORTED 636 | #endif 637 | 638 | #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED 639 | # ifndef PNG_NO_WRITE_SHIFT 640 | # define PNG_WRITE_SHIFT_SUPPORTED 641 | # endif 642 | # ifndef PNG_NO_WRITE_PACK 643 | # define PNG_WRITE_PACK_SUPPORTED 644 | # endif 645 | # ifndef PNG_NO_WRITE_BGR 646 | # define PNG_WRITE_BGR_SUPPORTED 647 | # endif 648 | # ifndef PNG_NO_WRITE_SWAP 649 | # define PNG_WRITE_SWAP_SUPPORTED 650 | # endif 651 | # ifndef PNG_NO_WRITE_PACKSWAP 652 | # define PNG_WRITE_PACKSWAP_SUPPORTED 653 | # endif 654 | # ifndef PNG_NO_WRITE_INVERT 655 | # define PNG_WRITE_INVERT_SUPPORTED 656 | # endif 657 | # ifndef PNG_NO_WRITE_FILLER 658 | # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */ 659 | # endif 660 | # ifndef PNG_NO_WRITE_SWAP_ALPHA 661 | # define PNG_WRITE_SWAP_ALPHA_SUPPORTED 662 | # endif 663 | # ifndef PNG_NO_WRITE_INVERT_ALPHA 664 | # define PNG_WRITE_INVERT_ALPHA_SUPPORTED 665 | # endif 666 | # ifndef PNG_NO_WRITE_USER_TRANSFORM 667 | # define PNG_WRITE_USER_TRANSFORM_SUPPORTED 668 | # endif 669 | #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ 670 | 671 | #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \ 672 | !defined(PNG_WRITE_INTERLACING_SUPPORTED) 673 | #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant 674 | encoders, but can cause trouble 675 | if left undefined */ 676 | #endif 677 | 678 | #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ 679 | !defined(PNG_WRITE_WEIGHTED_FILTER) && \ 680 | defined(PNG_FLOATING_POINT_SUPPORTED) 681 | # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 682 | #endif 683 | 684 | #ifndef PNG_NO_WRITE_FLUSH 685 | # define PNG_WRITE_FLUSH_SUPPORTED 686 | #endif 687 | 688 | #if defined(PNG_1_0_X) || defined (PNG_1_2_X) 689 | /* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ 690 | #ifndef PNG_NO_WRITE_EMPTY_PLTE 691 | # define PNG_WRITE_EMPTY_PLTE_SUPPORTED 692 | #endif 693 | #endif 694 | 695 | #endif /* PNG_WRITE_SUPPORTED */ 696 | 697 | #ifndef PNG_1_0_X 698 | # ifndef PNG_NO_ERROR_NUMBERS 699 | # define PNG_ERROR_NUMBERS_SUPPORTED 700 | # endif 701 | #endif /* PNG_1_0_X */ 702 | 703 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ 704 | defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) 705 | # ifndef PNG_NO_USER_TRANSFORM_PTR 706 | # define PNG_USER_TRANSFORM_PTR_SUPPORTED 707 | # endif 708 | #endif 709 | 710 | #ifndef PNG_NO_STDIO 711 | # define PNG_TIME_RFC1123_SUPPORTED 712 | #endif 713 | 714 | /* This adds extra functions in pngget.c for accessing data from the 715 | * info pointer (added in version 0.99) 716 | * png_get_image_width() 717 | * png_get_image_height() 718 | * png_get_bit_depth() 719 | * png_get_color_type() 720 | * png_get_compression_type() 721 | * png_get_filter_type() 722 | * png_get_interlace_type() 723 | * png_get_pixel_aspect_ratio() 724 | * png_get_pixels_per_meter() 725 | * png_get_x_offset_pixels() 726 | * png_get_y_offset_pixels() 727 | * png_get_x_offset_microns() 728 | * png_get_y_offset_microns() 729 | */ 730 | #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED) 731 | # define PNG_EASY_ACCESS_SUPPORTED 732 | #endif 733 | 734 | /* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 735 | * and removed from version 1.2.20. The following will be removed 736 | * from libpng-1.4.0 737 | */ 738 | 739 | #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE) 740 | # ifndef PNG_OPTIMIZED_CODE_SUPPORTED 741 | # define PNG_OPTIMIZED_CODE_SUPPORTED 742 | # endif 743 | #endif 744 | 745 | #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) 746 | # ifndef PNG_ASSEMBLER_CODE_SUPPORTED 747 | # define PNG_ASSEMBLER_CODE_SUPPORTED 748 | # endif 749 | 750 | # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4) 751 | /* work around 64-bit gcc compiler bugs in gcc-3.x */ 752 | # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) 753 | # define PNG_NO_MMX_CODE 754 | # endif 755 | # endif 756 | 757 | # if defined(__APPLE__) 758 | # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) 759 | # define PNG_NO_MMX_CODE 760 | # endif 761 | # endif 762 | 763 | # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh)) 764 | # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) 765 | # define PNG_NO_MMX_CODE 766 | # endif 767 | # endif 768 | 769 | # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) 770 | # define PNG_MMX_CODE_SUPPORTED 771 | # endif 772 | 773 | #endif 774 | /* end of obsolete code to be removed from libpng-1.4.0 */ 775 | 776 | #if !defined(PNG_1_0_X) 777 | #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) 778 | # define PNG_USER_MEM_SUPPORTED 779 | #endif 780 | #endif /* PNG_1_0_X */ 781 | 782 | /* Added at libpng-1.2.6 */ 783 | #if !defined(PNG_1_0_X) 784 | #ifndef PNG_SET_USER_LIMITS_SUPPORTED 785 | #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED) 786 | # define PNG_SET_USER_LIMITS_SUPPORTED 787 | #endif 788 | #endif 789 | #endif /* PNG_1_0_X */ 790 | 791 | /* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter 792 | * how large, set these limits to 0x7fffffffL 793 | */ 794 | #ifndef PNG_USER_WIDTH_MAX 795 | # define PNG_USER_WIDTH_MAX 1000000L 796 | #endif 797 | #ifndef PNG_USER_HEIGHT_MAX 798 | # define PNG_USER_HEIGHT_MAX 1000000L 799 | #endif 800 | 801 | /* These are currently experimental features, define them if you want */ 802 | 803 | /* very little testing */ 804 | /* 805 | #ifdef PNG_READ_SUPPORTED 806 | # ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED 807 | # define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED 808 | # endif 809 | #endif 810 | */ 811 | 812 | /* This is only for PowerPC big-endian and 680x0 systems */ 813 | /* some testing */ 814 | /* 815 | #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED 816 | # define PNG_READ_BIG_ENDIAN_SUPPORTED 817 | #endif 818 | */ 819 | 820 | /* Buggy compilers (e.g., gcc 2.7.2.2) need this */ 821 | /* 822 | #define PNG_NO_POINTER_INDEXING 823 | */ 824 | 825 | /* These functions are turned off by default, as they will be phased out. */ 826 | /* 827 | #define PNG_USELESS_TESTS_SUPPORTED 828 | #define PNG_CORRECT_PALETTE_SUPPORTED 829 | */ 830 | 831 | /* Any chunks you are not interested in, you can undef here. The 832 | * ones that allocate memory may be expecially important (hIST, 833 | * tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info 834 | * a bit smaller. 835 | */ 836 | 837 | #if defined(PNG_READ_SUPPORTED) && \ 838 | !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ 839 | !defined(PNG_NO_READ_ANCILLARY_CHUNKS) 840 | # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED 841 | #endif 842 | 843 | #if defined(PNG_WRITE_SUPPORTED) && \ 844 | !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ 845 | !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) 846 | # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED 847 | #endif 848 | 849 | #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED 850 | 851 | #ifdef PNG_NO_READ_TEXT 852 | # define PNG_NO_READ_iTXt 853 | # define PNG_NO_READ_tEXt 854 | # define PNG_NO_READ_zTXt 855 | #endif 856 | #ifndef PNG_NO_READ_bKGD 857 | # define PNG_READ_bKGD_SUPPORTED 858 | # define PNG_bKGD_SUPPORTED 859 | #endif 860 | #ifndef PNG_NO_READ_cHRM 861 | # define PNG_READ_cHRM_SUPPORTED 862 | # define PNG_cHRM_SUPPORTED 863 | #endif 864 | #ifndef PNG_NO_READ_gAMA 865 | # define PNG_READ_gAMA_SUPPORTED 866 | # define PNG_gAMA_SUPPORTED 867 | #endif 868 | #ifndef PNG_NO_READ_hIST 869 | # define PNG_READ_hIST_SUPPORTED 870 | # define PNG_hIST_SUPPORTED 871 | #endif 872 | #ifndef PNG_NO_READ_iCCP 873 | # define PNG_READ_iCCP_SUPPORTED 874 | # define PNG_iCCP_SUPPORTED 875 | #endif 876 | #ifndef PNG_NO_READ_iTXt 877 | # ifndef PNG_READ_iTXt_SUPPORTED 878 | # define PNG_READ_iTXt_SUPPORTED 879 | # endif 880 | # ifndef PNG_iTXt_SUPPORTED 881 | # define PNG_iTXt_SUPPORTED 882 | # endif 883 | #endif 884 | #ifndef PNG_NO_READ_oFFs 885 | # define PNG_READ_oFFs_SUPPORTED 886 | # define PNG_oFFs_SUPPORTED 887 | #endif 888 | #ifndef PNG_NO_READ_pCAL 889 | # define PNG_READ_pCAL_SUPPORTED 890 | # define PNG_pCAL_SUPPORTED 891 | #endif 892 | #ifndef PNG_NO_READ_sCAL 893 | # define PNG_READ_sCAL_SUPPORTED 894 | # define PNG_sCAL_SUPPORTED 895 | #endif 896 | #ifndef PNG_NO_READ_pHYs 897 | # define PNG_READ_pHYs_SUPPORTED 898 | # define PNG_pHYs_SUPPORTED 899 | #endif 900 | #ifndef PNG_NO_READ_sBIT 901 | # define PNG_READ_sBIT_SUPPORTED 902 | # define PNG_sBIT_SUPPORTED 903 | #endif 904 | #ifndef PNG_NO_READ_sPLT 905 | # define PNG_READ_sPLT_SUPPORTED 906 | # define PNG_sPLT_SUPPORTED 907 | #endif 908 | #ifndef PNG_NO_READ_sRGB 909 | # define PNG_READ_sRGB_SUPPORTED 910 | # define PNG_sRGB_SUPPORTED 911 | #endif 912 | #ifndef PNG_NO_READ_tEXt 913 | # define PNG_READ_tEXt_SUPPORTED 914 | # define PNG_tEXt_SUPPORTED 915 | #endif 916 | #ifndef PNG_NO_READ_tIME 917 | # define PNG_READ_tIME_SUPPORTED 918 | # define PNG_tIME_SUPPORTED 919 | #endif 920 | #ifndef PNG_NO_READ_tRNS 921 | # define PNG_READ_tRNS_SUPPORTED 922 | # define PNG_tRNS_SUPPORTED 923 | #endif 924 | #ifndef PNG_NO_READ_zTXt 925 | # define PNG_READ_zTXt_SUPPORTED 926 | # define PNG_zTXt_SUPPORTED 927 | #endif 928 | #ifndef PNG_NO_READ_UNKNOWN_CHUNKS 929 | # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 930 | # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED 931 | # define PNG_UNKNOWN_CHUNKS_SUPPORTED 932 | # endif 933 | # ifndef PNG_NO_HANDLE_AS_UNKNOWN 934 | # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED 935 | # endif 936 | #endif 937 | #if !defined(PNG_NO_READ_USER_CHUNKS) && \ 938 | defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) 939 | # define PNG_READ_USER_CHUNKS_SUPPORTED 940 | # define PNG_USER_CHUNKS_SUPPORTED 941 | # ifdef PNG_NO_READ_UNKNOWN_CHUNKS 942 | # undef PNG_NO_READ_UNKNOWN_CHUNKS 943 | # endif 944 | # ifdef PNG_NO_HANDLE_AS_UNKNOWN 945 | # undef PNG_NO_HANDLE_AS_UNKNOWN 946 | # endif 947 | #endif 948 | #ifndef PNG_NO_READ_OPT_PLTE 949 | # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ 950 | #endif /* optional PLTE chunk in RGB and RGBA images */ 951 | #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \ 952 | defined(PNG_READ_zTXt_SUPPORTED) 953 | # define PNG_READ_TEXT_SUPPORTED 954 | # define PNG_TEXT_SUPPORTED 955 | #endif 956 | 957 | #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */ 958 | 959 | #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED 960 | 961 | #ifdef PNG_NO_WRITE_TEXT 962 | # define PNG_NO_WRITE_iTXt 963 | # define PNG_NO_WRITE_tEXt 964 | # define PNG_NO_WRITE_zTXt 965 | #endif 966 | #ifndef PNG_NO_WRITE_bKGD 967 | # define PNG_WRITE_bKGD_SUPPORTED 968 | # ifndef PNG_bKGD_SUPPORTED 969 | # define PNG_bKGD_SUPPORTED 970 | # endif 971 | #endif 972 | #ifndef PNG_NO_WRITE_cHRM 973 | # define PNG_WRITE_cHRM_SUPPORTED 974 | # ifndef PNG_cHRM_SUPPORTED 975 | # define PNG_cHRM_SUPPORTED 976 | # endif 977 | #endif 978 | #ifndef PNG_NO_WRITE_gAMA 979 | # define PNG_WRITE_gAMA_SUPPORTED 980 | # ifndef PNG_gAMA_SUPPORTED 981 | # define PNG_gAMA_SUPPORTED 982 | # endif 983 | #endif 984 | #ifndef PNG_NO_WRITE_hIST 985 | # define PNG_WRITE_hIST_SUPPORTED 986 | # ifndef PNG_hIST_SUPPORTED 987 | # define PNG_hIST_SUPPORTED 988 | # endif 989 | #endif 990 | #ifndef PNG_NO_WRITE_iCCP 991 | # define PNG_WRITE_iCCP_SUPPORTED 992 | # ifndef PNG_iCCP_SUPPORTED 993 | # define PNG_iCCP_SUPPORTED 994 | # endif 995 | #endif 996 | #ifndef PNG_NO_WRITE_iTXt 997 | # ifndef PNG_WRITE_iTXt_SUPPORTED 998 | # define PNG_WRITE_iTXt_SUPPORTED 999 | # endif 1000 | # ifndef PNG_iTXt_SUPPORTED 1001 | # define PNG_iTXt_SUPPORTED 1002 | # endif 1003 | #endif 1004 | #ifndef PNG_NO_WRITE_oFFs 1005 | # define PNG_WRITE_oFFs_SUPPORTED 1006 | # ifndef PNG_oFFs_SUPPORTED 1007 | # define PNG_oFFs_SUPPORTED 1008 | # endif 1009 | #endif 1010 | #ifndef PNG_NO_WRITE_pCAL 1011 | # define PNG_WRITE_pCAL_SUPPORTED 1012 | # ifndef PNG_pCAL_SUPPORTED 1013 | # define PNG_pCAL_SUPPORTED 1014 | # endif 1015 | #endif 1016 | #ifndef PNG_NO_WRITE_sCAL 1017 | # define PNG_WRITE_sCAL_SUPPORTED 1018 | # ifndef PNG_sCAL_SUPPORTED 1019 | # define PNG_sCAL_SUPPORTED 1020 | # endif 1021 | #endif 1022 | #ifndef PNG_NO_WRITE_pHYs 1023 | # define PNG_WRITE_pHYs_SUPPORTED 1024 | # ifndef PNG_pHYs_SUPPORTED 1025 | # define PNG_pHYs_SUPPORTED 1026 | # endif 1027 | #endif 1028 | #ifndef PNG_NO_WRITE_sBIT 1029 | # define PNG_WRITE_sBIT_SUPPORTED 1030 | # ifndef PNG_sBIT_SUPPORTED 1031 | # define PNG_sBIT_SUPPORTED 1032 | # endif 1033 | #endif 1034 | #ifndef PNG_NO_WRITE_sPLT 1035 | # define PNG_WRITE_sPLT_SUPPORTED 1036 | # ifndef PNG_sPLT_SUPPORTED 1037 | # define PNG_sPLT_SUPPORTED 1038 | # endif 1039 | #endif 1040 | #ifndef PNG_NO_WRITE_sRGB 1041 | # define PNG_WRITE_sRGB_SUPPORTED 1042 | # ifndef PNG_sRGB_SUPPORTED 1043 | # define PNG_sRGB_SUPPORTED 1044 | # endif 1045 | #endif 1046 | #ifndef PNG_NO_WRITE_tEXt 1047 | # define PNG_WRITE_tEXt_SUPPORTED 1048 | # ifndef PNG_tEXt_SUPPORTED 1049 | # define PNG_tEXt_SUPPORTED 1050 | # endif 1051 | #endif 1052 | #ifndef PNG_NO_WRITE_tIME 1053 | # define PNG_WRITE_tIME_SUPPORTED 1054 | # ifndef PNG_tIME_SUPPORTED 1055 | # define PNG_tIME_SUPPORTED 1056 | # endif 1057 | #endif 1058 | #ifndef PNG_NO_WRITE_tRNS 1059 | # define PNG_WRITE_tRNS_SUPPORTED 1060 | # ifndef PNG_tRNS_SUPPORTED 1061 | # define PNG_tRNS_SUPPORTED 1062 | # endif 1063 | #endif 1064 | #ifndef PNG_NO_WRITE_zTXt 1065 | # define PNG_WRITE_zTXt_SUPPORTED 1066 | # ifndef PNG_zTXt_SUPPORTED 1067 | # define PNG_zTXt_SUPPORTED 1068 | # endif 1069 | #endif 1070 | #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS 1071 | # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED 1072 | # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED 1073 | # define PNG_UNKNOWN_CHUNKS_SUPPORTED 1074 | # endif 1075 | # ifndef PNG_NO_HANDLE_AS_UNKNOWN 1076 | # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 1077 | # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED 1078 | # endif 1079 | # endif 1080 | #endif 1081 | #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ 1082 | defined(PNG_WRITE_zTXt_SUPPORTED) 1083 | # define PNG_WRITE_TEXT_SUPPORTED 1084 | # ifndef PNG_TEXT_SUPPORTED 1085 | # define PNG_TEXT_SUPPORTED 1086 | # endif 1087 | #endif 1088 | 1089 | #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ 1090 | 1091 | /* Turn this off to disable png_read_png() and 1092 | * png_write_png() and leave the row_pointers member 1093 | * out of the info structure. 1094 | */ 1095 | #ifndef PNG_NO_INFO_IMAGE 1096 | # define PNG_INFO_IMAGE_SUPPORTED 1097 | #endif 1098 | 1099 | /* need the time information for reading tIME chunks */ 1100 | #if defined(PNG_tIME_SUPPORTED) 1101 | # if !defined(_WIN32_WCE) 1102 | /* "time.h" functions are not supported on WindowsCE */ 1103 | # include 1104 | # endif 1105 | #endif 1106 | 1107 | /* Some typedefs to get us started. These should be safe on most of the 1108 | * common platforms. The typedefs should be at least as large as the 1109 | * numbers suggest (a png_uint_32 must be at least 32 bits long), but they 1110 | * don't have to be exactly that size. Some compilers dislike passing 1111 | * unsigned shorts as function parameters, so you may be better off using 1112 | * unsigned int for png_uint_16. Likewise, for 64-bit systems, you may 1113 | * want to have unsigned int for png_uint_32 instead of unsigned long. 1114 | */ 1115 | 1116 | typedef unsigned long png_uint_32; 1117 | typedef long png_int_32; 1118 | typedef unsigned short png_uint_16; 1119 | typedef short png_int_16; 1120 | typedef unsigned char png_byte; 1121 | 1122 | /* This is usually size_t. It is typedef'ed just in case you need it to 1123 | change (I'm not sure if you will or not, so I thought I'd be safe) */ 1124 | #ifdef PNG_SIZE_T 1125 | typedef PNG_SIZE_T png_size_t; 1126 | # define png_sizeof(x) png_convert_size(sizeof (x)) 1127 | #else 1128 | typedef size_t png_size_t; 1129 | # define png_sizeof(x) sizeof (x) 1130 | #endif 1131 | 1132 | /* The following is needed for medium model support. It cannot be in the 1133 | * PNG_INTERNAL section. Needs modification for other compilers besides 1134 | * MSC. Model independent support declares all arrays and pointers to be 1135 | * large using the far keyword. The zlib version used must also support 1136 | * model independent data. As of version zlib 1.0.4, the necessary changes 1137 | * have been made in zlib. The USE_FAR_KEYWORD define triggers other 1138 | * changes that are needed. (Tim Wegner) 1139 | */ 1140 | 1141 | /* Separate compiler dependencies (problem here is that zlib.h always 1142 | defines FAR. (SJT) */ 1143 | #ifdef __BORLANDC__ 1144 | # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) 1145 | # define LDATA 1 1146 | # else 1147 | # define LDATA 0 1148 | # endif 1149 | /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ 1150 | # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) 1151 | # define PNG_MAX_MALLOC_64K 1152 | # if (LDATA != 1) 1153 | # ifndef FAR 1154 | # define FAR __far 1155 | # endif 1156 | # define USE_FAR_KEYWORD 1157 | # endif /* LDATA != 1 */ 1158 | /* Possibly useful for moving data out of default segment. 1159 | * Uncomment it if you want. Could also define FARDATA as 1160 | * const if your compiler supports it. (SJT) 1161 | # define FARDATA FAR 1162 | */ 1163 | # endif /* __WIN32__, __FLAT__, __CYGWIN__ */ 1164 | #endif /* __BORLANDC__ */ 1165 | 1166 | 1167 | /* Suggest testing for specific compiler first before testing for 1168 | * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, 1169 | * making reliance oncertain keywords suspect. (SJT) 1170 | */ 1171 | 1172 | /* MSC Medium model */ 1173 | #if defined(FAR) 1174 | # if defined(M_I86MM) 1175 | # define USE_FAR_KEYWORD 1176 | # define FARDATA FAR 1177 | # include 1178 | # endif 1179 | #endif 1180 | 1181 | /* SJT: default case */ 1182 | #ifndef FAR 1183 | # define FAR 1184 | #endif 1185 | 1186 | /* At this point FAR is always defined */ 1187 | #ifndef FARDATA 1188 | # define FARDATA 1189 | #endif 1190 | 1191 | /* Typedef for floating-point numbers that are converted 1192 | to fixed-point with a multiple of 100,000, e.g., int_gamma */ 1193 | typedef png_int_32 png_fixed_point; 1194 | 1195 | /* Add typedefs for pointers */ 1196 | typedef void FAR * png_voidp; 1197 | typedef png_byte FAR * png_bytep; 1198 | typedef png_uint_32 FAR * png_uint_32p; 1199 | typedef png_int_32 FAR * png_int_32p; 1200 | typedef png_uint_16 FAR * png_uint_16p; 1201 | typedef png_int_16 FAR * png_int_16p; 1202 | typedef PNG_CONST char FAR * png_const_charp; 1203 | typedef char FAR * png_charp; 1204 | typedef png_fixed_point FAR * png_fixed_point_p; 1205 | 1206 | #ifndef PNG_NO_STDIO 1207 | #if defined(_WIN32_WCE) 1208 | typedef HANDLE png_FILE_p; 1209 | #else 1210 | typedef FILE * png_FILE_p; 1211 | #endif 1212 | #endif 1213 | 1214 | #ifdef PNG_FLOATING_POINT_SUPPORTED 1215 | typedef double FAR * png_doublep; 1216 | #endif 1217 | 1218 | /* Pointers to pointers; i.e. arrays */ 1219 | typedef png_byte FAR * FAR * png_bytepp; 1220 | typedef png_uint_32 FAR * FAR * png_uint_32pp; 1221 | typedef png_int_32 FAR * FAR * png_int_32pp; 1222 | typedef png_uint_16 FAR * FAR * png_uint_16pp; 1223 | typedef png_int_16 FAR * FAR * png_int_16pp; 1224 | typedef PNG_CONST char FAR * FAR * png_const_charpp; 1225 | typedef char FAR * FAR * png_charpp; 1226 | typedef png_fixed_point FAR * FAR * png_fixed_point_pp; 1227 | #ifdef PNG_FLOATING_POINT_SUPPORTED 1228 | typedef double FAR * FAR * png_doublepp; 1229 | #endif 1230 | 1231 | /* Pointers to pointers to pointers; i.e., pointer to array */ 1232 | typedef char FAR * FAR * FAR * png_charppp; 1233 | 1234 | #if defined(PNG_1_0_X) || defined(PNG_1_2_X) 1235 | /* SPC - Is this stuff deprecated? */ 1236 | /* It'll be removed as of libpng-1.3.0 - GR-P */ 1237 | /* libpng typedefs for types in zlib. If zlib changes 1238 | * or another compression library is used, then change these. 1239 | * Eliminates need to change all the source files. 1240 | */ 1241 | typedef charf * png_zcharp; 1242 | typedef charf * FAR * png_zcharpp; 1243 | typedef z_stream FAR * png_zstreamp; 1244 | #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */ 1245 | 1246 | /* 1247 | * Define PNG_BUILD_DLL if the module being built is a Windows 1248 | * LIBPNG DLL. 1249 | * 1250 | * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. 1251 | * It is equivalent to Microsoft predefined macro _DLL that is 1252 | * automatically defined when you compile using the share 1253 | * version of the CRT (C Run-Time library) 1254 | * 1255 | * The cygwin mods make this behavior a little different: 1256 | * Define PNG_BUILD_DLL if you are building a dll for use with cygwin 1257 | * Define PNG_STATIC if you are building a static library for use with cygwin, 1258 | * -or- if you are building an application that you want to link to the 1259 | * static library. 1260 | * PNG_USE_DLL is defined by default (no user action needed) unless one of 1261 | * the other flags is defined. 1262 | */ 1263 | 1264 | #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) 1265 | # define PNG_DLL 1266 | #endif 1267 | /* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. 1268 | * When building a static lib, default to no GLOBAL ARRAYS, but allow 1269 | * command-line override 1270 | */ 1271 | #if defined(__CYGWIN__) 1272 | # if !defined(PNG_STATIC) 1273 | # if defined(PNG_USE_GLOBAL_ARRAYS) 1274 | # undef PNG_USE_GLOBAL_ARRAYS 1275 | # endif 1276 | # if !defined(PNG_USE_LOCAL_ARRAYS) 1277 | # define PNG_USE_LOCAL_ARRAYS 1278 | # endif 1279 | # else 1280 | # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) 1281 | # if defined(PNG_USE_GLOBAL_ARRAYS) 1282 | # undef PNG_USE_GLOBAL_ARRAYS 1283 | # endif 1284 | # endif 1285 | # endif 1286 | # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) 1287 | # define PNG_USE_LOCAL_ARRAYS 1288 | # endif 1289 | #endif 1290 | 1291 | /* Do not use global arrays (helps with building DLL's) 1292 | * They are no longer used in libpng itself, since version 1.0.5c, 1293 | * but might be required for some pre-1.0.5c applications. 1294 | */ 1295 | #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) 1296 | # if defined(PNG_NO_GLOBAL_ARRAYS) || \ 1297 | (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER) 1298 | # define PNG_USE_LOCAL_ARRAYS 1299 | # else 1300 | # define PNG_USE_GLOBAL_ARRAYS 1301 | # endif 1302 | #endif 1303 | 1304 | #if defined(__CYGWIN__) 1305 | # undef PNGAPI 1306 | # define PNGAPI __cdecl 1307 | # undef PNG_IMPEXP 1308 | # define PNG_IMPEXP 1309 | #endif 1310 | 1311 | /* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", 1312 | * you may get warnings regarding the linkage of png_zalloc and png_zfree. 1313 | * Don't ignore those warnings; you must also reset the default calling 1314 | * convention in your compiler to match your PNGAPI, and you must build 1315 | * zlib and your applications the same way you build libpng. 1316 | */ 1317 | 1318 | #if defined(__MINGW32__) && !defined(PNG_MODULEDEF) 1319 | # ifndef PNG_NO_MODULEDEF 1320 | # define PNG_NO_MODULEDEF 1321 | # endif 1322 | #endif 1323 | 1324 | #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF) 1325 | # define PNG_IMPEXP 1326 | #endif 1327 | 1328 | #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \ 1329 | (( defined(_Windows) || defined(_WINDOWS) || \ 1330 | defined(WIN32) || defined(_WIN32) || defined(__WIN32__) )) 1331 | 1332 | # ifndef PNGAPI 1333 | # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) 1334 | # define PNGAPI __cdecl 1335 | # else 1336 | # define PNGAPI _cdecl 1337 | # endif 1338 | # endif 1339 | 1340 | # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \ 1341 | 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */) 1342 | # define PNG_IMPEXP 1343 | # endif 1344 | 1345 | # if !defined(PNG_IMPEXP) 1346 | 1347 | # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol 1348 | # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol 1349 | 1350 | /* Borland/Microsoft */ 1351 | # if defined(_MSC_VER) || defined(__BORLANDC__) 1352 | # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) 1353 | # define PNG_EXPORT PNG_EXPORT_TYPE1 1354 | # else 1355 | # define PNG_EXPORT PNG_EXPORT_TYPE2 1356 | # if defined(PNG_BUILD_DLL) 1357 | # define PNG_IMPEXP __export 1358 | # else 1359 | # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in 1360 | VC++ */ 1361 | # endif /* Exists in Borland C++ for 1362 | C++ classes (== huge) */ 1363 | # endif 1364 | # endif 1365 | 1366 | # if !defined(PNG_IMPEXP) 1367 | # if defined(PNG_BUILD_DLL) 1368 | # define PNG_IMPEXP __declspec(dllexport) 1369 | # else 1370 | # define PNG_IMPEXP __declspec(dllimport) 1371 | # endif 1372 | # endif 1373 | # endif /* PNG_IMPEXP */ 1374 | #else /* !(DLL || non-cygwin WINDOWS) */ 1375 | # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) 1376 | # ifndef PNGAPI 1377 | # define PNGAPI _System 1378 | # endif 1379 | # else 1380 | # if 0 /* ... other platforms, with other meanings */ 1381 | # endif 1382 | # endif 1383 | #endif 1384 | 1385 | #ifndef PNGAPI 1386 | # define PNGAPI 1387 | #endif 1388 | #ifndef PNG_IMPEXP 1389 | # define PNG_IMPEXP 1390 | #endif 1391 | 1392 | #ifdef PNG_BUILDSYMS 1393 | # ifndef PNG_EXPORT 1394 | # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END 1395 | # endif 1396 | # ifdef PNG_USE_GLOBAL_ARRAYS 1397 | # ifndef PNG_EXPORT_VAR 1398 | # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT 1399 | # endif 1400 | # endif 1401 | #endif 1402 | 1403 | #ifndef PNG_EXPORT 1404 | # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol 1405 | #endif 1406 | 1407 | #ifdef PNG_USE_GLOBAL_ARRAYS 1408 | # ifndef PNG_EXPORT_VAR 1409 | # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type 1410 | # endif 1411 | #endif 1412 | 1413 | /* User may want to use these so they are not in PNG_INTERNAL. Any library 1414 | * functions that are passed far data must be model independent. 1415 | */ 1416 | 1417 | #ifndef PNG_ABORT 1418 | # define PNG_ABORT() abort() 1419 | #endif 1420 | 1421 | #ifdef PNG_SETJMP_SUPPORTED 1422 | # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) 1423 | #else 1424 | # define png_jmpbuf(png_ptr) \ 1425 | (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) 1426 | #endif 1427 | 1428 | #if defined(USE_FAR_KEYWORD) /* memory model independent fns */ 1429 | /* use this to make far-to-near assignments */ 1430 | # define CHECK 1 1431 | # define NOCHECK 0 1432 | # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) 1433 | # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) 1434 | # define png_snprintf _fsnprintf /* Added to v 1.2.19 */ 1435 | # define png_strlen _fstrlen 1436 | # define png_memcmp _fmemcmp /* SJT: added */ 1437 | # define png_memcpy _fmemcpy 1438 | # define png_memset _fmemset 1439 | #else /* use the usual functions */ 1440 | # define CVT_PTR(ptr) (ptr) 1441 | # define CVT_PTR_NOCHECK(ptr) (ptr) 1442 | # ifndef PNG_NO_SNPRINTF 1443 | # ifdef _MSC_VER 1444 | # define png_snprintf _snprintf /* Added to v 1.2.19 */ 1445 | # define png_snprintf2 _snprintf 1446 | # define png_snprintf6 _snprintf 1447 | # else 1448 | # define png_snprintf snprintf /* Added to v 1.2.19 */ 1449 | # define png_snprintf2 snprintf 1450 | # define png_snprintf6 snprintf 1451 | # endif 1452 | # else 1453 | /* You don't have or don't want to use snprintf(). Caution: Using 1454 | * sprintf instead of snprintf exposes your application to accidental 1455 | * or malevolent buffer overflows. If you don't have snprintf() 1456 | * as a general rule you should provide one (you can get one from 1457 | * Portable OpenSSH). */ 1458 | # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) 1459 | # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) 1460 | # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ 1461 | sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) 1462 | # endif 1463 | # define png_strlen strlen 1464 | # define png_memcmp memcmp /* SJT: added */ 1465 | # define png_memcpy memcpy 1466 | # define png_memset memset 1467 | #endif 1468 | /* End of memory model independent support */ 1469 | 1470 | /* Just a little check that someone hasn't tried to define something 1471 | * contradictory. 1472 | */ 1473 | #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) 1474 | # undef PNG_ZBUF_SIZE 1475 | # define PNG_ZBUF_SIZE 65536L 1476 | #endif 1477 | 1478 | /* Added at libpng-1.2.8 */ 1479 | #endif /* PNG_VERSION_INFO_ONLY */ 1480 | 1481 | #endif /* PNGCONF_H */ 1482 | --------------------------------------------------------------------------------