90 Commits

Author SHA1 Message Date
26d8c283b3 Add warning about splashes being disabled 2017-09-09 20:19:30 -04:00
4ceac06f0c improve no splashes interface 2017-09-09 20:12:10 -04:00
337693ca13 Improve no themes interface and create folders on boot 2017-09-09 20:10:36 -04:00
8ba1fed5d7 Change QR reader behavior, speed up 2017-09-09 11:33:54 -04:00
Helloman892
d99f1c97a0 fixes splash install
If splash.bin and/or splashbottom.bin didn't already exist, splashes would not install.

Also added a line break to separate splash_delete(), for consistency.
2017-09-09 13:07:31 +01:00
ZetaDesigns
1a1b3e25b0 Quick fix II - The sequel 2017-09-09 11:54:50 +02:00
c92c20d4e8 Quick fix 2017-09-09 00:26:40 -04:00
ef456c7e9e Splash previews 2017-09-09 00:12:16 -04:00
1103885baf Splash QR codes 2017-09-08 23:34:16 -04:00
5564ffe31b Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-08 23:26:59 -04:00
97ab2307f8 Slightly improve QR code speed 2017-09-08 23:26:49 -04:00
ZetaDesigns
47c64828a4 Merge branch 'master' of https://github.com/astronautlevel2/Anemone3DS 2017-09-08 23:18:41 +02:00
d3aa231c3f Update pp2d 2017-09-08 15:59:32 -04:00
Helloman892
3fb86c80be finally fixed everything
homebrew wasn't actually global, smh
2017-09-08 20:00:21 +01:00
ZetaDesigns
67566330a5 fix indentation and **properly** fix the compile error 2017-09-08 20:52:26 +02:00
68805337bf Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-08 14:04:53 -04:00
Helloman892
416cca88d3 fixing compile error
Upon attempting to build the previous commit, I discovered that Zeta was referring to a var that wasn't declared. Fixed.
2017-09-08 17:57:57 +01:00
2be3bde64d Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-08 07:21:34 -04:00
c46c5ff8cb More CAMU stuff 2017-09-08 07:21:31 -04:00
Helloman892
6b5b391d7b finally got theme deletion working + qr stuff
Theme deletion [SDMC] now works, although no button currently has it assigned. The QR reader now works properly with Unicode filenames.
2017-09-07 22:36:44 +01:00
ZetaDesigns
dc1cbda232 you saw nothing 2017-09-07 22:45:15 +02:00
ZetaDesigns
e63a4066a1 error codes now properly pause 2017-09-07 22:43:32 +02:00
2e71fc5954 Draw SMDH info 2017-09-07 13:55:52 -04:00
778e1a8331 maybe fix splashes 2017-09-07 13:35:56 -04:00
0871f4f30b Break QR code reader trying to make it faster 2017-09-07 13:08:38 -04:00
62f4356a17 Change splashes to support SMDH and zip files 2017-09-07 10:08:52 -04:00
ZetaDesigns
3e2c5994ca fix dabort when no theme data
themes still wont install like this
2017-09-06 18:33:23 +02:00
ZetaDesigns
674fa9d9bf add "downloading" text to qrcode scanning
i know it's not the prettiest idea to put it in draw_theme_install, but it seemed like the most fitting, and i didnt want to create another function for it
2017-09-06 17:49:10 +02:00
Nils P
897dc52424 Merge pull request #64 from saibotu/pr-bgmcrash
Fixed crash when installing themes without bgm
2017-09-06 17:03:51 +02:00
saibotu
379cea8db1 Fixed crash when installing themes without bgm 2017-09-06 15:36:02 +02:00
saibotu
e46783a3c4 Made buf_to_file always return Result 2017-09-06 15:35:31 +02:00
Helloman892
3fd4548d64 Merge pull request #62 from thedax/warning-fix
Fix potential bugs and two warnings relating to them
2017-09-06 10:19:07 +01:00
thedax
34ede05b93 Fix potential bugs and two warnings relating to them
Memset doesn't automatically set the entire size of each element, it's necessary to multiply by sizeof(<typename>) if it's larger than 1 byte, which in this case, u16, is (two bytes).
2017-09-06 05:01:42 -04:00
Helloman892
80b9aa9cdb Merge pull request #60 from Uyuiyu/master
Fix build warning
2017-09-06 09:20:46 +01:00
Uyuiyu
33cce81914 signed 2017-09-06 02:16:03 +02:00
Nils P
424fffd35f Merge pull request #57 from astronautlevel2/zeta-patch
Make Errorcodes great again (well, sorta)
2017-09-05 21:40:17 +02:00
ZetaDesigns
5b067cfac0 fixing some indentation 2017-09-05 21:37:48 +02:00
ZetaDesigns
539e95253c finish up basic errorcode functions 2017-09-05 21:31:50 +02:00
ZetaDesigns
a77b29da92 add errorcodes 2017-09-05 21:15:19 +02:00
Helloman892
dcac5401c1 several text drawing edits
All info.smdh fields now wrap after 300-odd pixels.
2017-09-05 13:10:43 +01:00
Helloman892
1467b1f72b Merge branch 'master' of https://github.com/astronautlevel2/Anemone3DS 2017-09-05 10:57:20 +01:00
Helloman892
9199936215 per PR #52 2017-09-05 10:56:00 +01:00
Helloman892
91fa4fa412 Resolves #22 (#52)
3 commits squashed and merged
2017-09-05 10:55:21 +01:00
Helloman892
1c6ae493d5 Merge pull request #51 from astronautlevel2/hm892
Fast paging [issue #14]
2017-09-05 01:30:33 +01:00
Helloman892
4eb969e84d fast page scrolling 2017-09-05 01:25:48 +01:00
Helloman892
70a40fae44 issue #14 commit for review (#50) 2017-09-04 19:25:52 -04:00
Helloman892
3d17509229 Merge pull request #49 from Helloman892/master
Resolving #35 as best as possible
2017-09-04 22:50:06 +01:00
Helloman892
a38508c30f undoes part of commit d3a8f79 2017-09-04 22:43:42 +01:00
Helloman892
0ddb35d3d7 see #35
percentage bar isn't practical.
counter was quite simple.
2017-09-04 22:41:26 +01:00
Helloman892
e03d150840 Merge pull request #45 from GreatWizard/optimiz_images
Clean battery images and reduce png size
2017-09-04 21:25:57 +01:00
Guillaume Gérard
4607885fe6 Clean battery images and reduce png size 2017-09-04 22:11:52 +02:00
Helloman892
d3a8f79958 beginnings of shuffled theme counter + a couple qr bugfixes 2017-09-04 20:13:09 +01:00
Helloman892
a08c032ccc Update main.c 2017-09-04 19:54:38 +01:00
Helloman892
bdaa8b52cc Update themes.c 2017-09-04 19:53:41 +01:00
Helloman892
8dc7f54f7e attempt to allow 10 themes to be installed 2017-09-04 19:46:55 +01:00
04ebe9e498 Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-04 14:40:28 -04:00
02526707a0 Fix invalid characters in QR codes 2017-09-04 14:40:20 -04:00
ZetaDesigns
494962dc88 ...and also block it in preview mode
i'm such a idiot
2017-09-04 20:07:49 +02:00
ZetaDesigns
d0979126f7 Merge branch 'master' of https://github.com/astronautlevel2/Anemone3DS 2017-09-04 20:07:10 +02:00
ZetaDesigns
57c4da7614 Block QRMode in Splashmode 2017-09-04 20:03:25 +02:00
9ab442c598 Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-04 13:40:41 -04:00
03497a79ef Fix green tint on CTR cameras 2017-09-04 13:40:33 -04:00
ZetaDesigns
1433002082 Merge branch 'master' of https://github.com/astronautlevel2/Anemone3DS 2017-09-04 19:31:47 +02:00
ZetaDesigns
242f10ec0a Add QRCode reference 2017-09-04 19:31:44 +02:00
Joel
292c100480 Implement fast scroll using circle pad. (#41)
Not too fast yet not too slow either.
2017-09-04 13:23:18 -04:00
Helloman892
cca45bff0f Resolves QR issue (#40)
Swaps b and g channels so they're proper
2017-09-04 09:56:51 -04:00
Helloman892
630cc41759 updating README.md (#38)
* correcting mild spelling mistake

* more readme edits
2017-09-04 08:31:33 -04:00
5fc499ff78 Automatically update themes list when a new theme is downloaded 2017-09-04 02:42:27 -04:00
3241544296 (Mostly) finish QR support 2017-09-04 02:03:58 -04:00
7aed454297 Increase stack size to decode larger QR codes properly 2017-09-03 15:53:41 -04:00
Nils P
c539fa239c Add Building section 2017-09-03 18:57:40 +02:00
Alex Taber
b7d15da092 Qr stuff (#32)
QRs are now scanned and decoded, but they aren't downloaded.
2017-09-03 12:52:02 -04:00
Nils P
9a34a17fe8 Changing all Battery related icons (#29) 2017-09-03 10:19:54 -04:00
4084408562 Fix arm11 dabort when switching apps through home menu, START no longer reboots in some cases 2017-09-02 23:07:47 -04:00
9afbe22df7 Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-02 17:26:10 -04:00
448a9ceb8a Fix no-smdh case 2017-09-02 17:25:59 -04:00
Laine
25aa02008e Update README.md (#25)
* fix readme

* fix?

* fix?

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md
2017-09-02 15:59:55 -04:00
49e6c6f827 Add splash uninstall screen 2017-09-02 12:16:17 -04:00
365ae87477 Merge branch 'master' of github.com:3dsfug/Anemone3DS 2017-09-02 11:57:18 -04:00
f461b3b5b5 Remove GPIO error on reboot, change battery % indicator to battery graphics 2017-09-02 11:57:02 -04:00
Nils P
6ea3904682 Adding splash deletion feature (#24)
* Adding splash deletion feature

* Add Mention for deleting splashes
2017-09-02 11:45:56 -04:00
aac093f466 Resolved merge conflicts 2017-09-02 10:08:52 -04:00
9442afb608 Change stuff with MCUHWC, reboot functionality 2017-09-02 10:05:42 -04:00
Helloman892
91f54ff22e Start button functionality (#21)
* srvPublishToSubscriber

Pressing Start from the app now sends the user to the Power Off screen.

* *hax check

As per Sono, checks whether the current environment is *hax. If it isn't, it goes to the home screen; otherwise, it restarts the console.

* Bugfixes

This may work?

* Revert "Bugfixes"

This reverts commit 7c382d719a.
2017-09-02 10:05:18 -04:00
pokecraft98
aa593c61a6 Added invite to theme plaza discord (#23) 2017-09-02 10:05:10 -04:00
Nils P
2a8e3176a8 Readme Overhaul (#20)
* Readme Overhaul

* Linking to Project_CTR for makerom
2017-09-02 09:23:48 -04:00
thedax
c84f40cf57 3dstool isn't really needed for romfs generation. (#19) 2017-09-01 19:33:24 -04:00
Alex Taber
45cbf0761b Add dependencies 2017-09-01 15:07:27 -04:00
8c7c409bca Update pp2d 2017-09-01 12:51:47 -04:00
d9ddd68d2e Change to using the homebrew logo I guess 2017-09-01 12:51:25 -04:00
32 changed files with 3915 additions and 170 deletions

View File

@@ -18,7 +18,7 @@ APP_AUTHOR := astronautlevel and daedreth
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
OUTDIR := out
BUILD := build
SOURCES := source source/pp2d/pp2d source/minizip
SOURCES := source source/pp2d/pp2d source/minizip source/quirc
INCLUDES := include
ROMFS := romfs
@@ -49,11 +49,13 @@ ICON_FLAGS := nosavebackups,visible
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -Wextra -mword-relocations \
CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
-ffunction-sections \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE
revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DVERSION="\"$(revision)\""
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
@@ -167,9 +169,9 @@ MAKEROM ?= makerom
MAKEROM_ARGS := -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)"
ifneq ($(strip $(ROMFS)),)
MAKEROM_ARGS += -romfs "$(BUILD)/romfs.bin"
endif
#ifneq ($(strip $(ROMFS)),)
# MAKEROM_ARGS += -romfs "$(BUILD)/romfs.bin"
#endif
ifneq ($(strip $(LOGO)),)
MAKEROM_ARGS += -logo "$(LOGO)"
endif
@@ -178,7 +180,7 @@ ifeq ($(strip $(ROMFS)),)
$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
$(MAKEROM) -f cia -o "$@" -target t -exefslogo $(MAKEROM_ARGS)
else
$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/romfs.bin $(BUILD)/banner.bnr $(BUILD)/icon.icn
$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
$(MAKEROM) -f cia -o "$@" -target t -exefslogo $(MAKEROM_ARGS)
endif
@@ -204,11 +206,6 @@ $(BUILD)/icon.icn : $(APP_ICON)
$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(APP_ICON)" -f "$(ICON_FLAGS)" -o "$@"
3DSTOOL ?= 3dstool
$(BUILD)/romfs.bin : $(ROMFS)
$(3DSTOOL) -ctf romfs "$@" --romfs-dir "$(ROMFS)"
#---------------------------------------------------------------------------------
else

View File

@@ -1,27 +1,34 @@
# Anemone3DS
A Theme Manager for the Nintendo3DS, written in C
![# Anemone3DS](https://github.com/astronautlevel2/Anemone3DS/blob/master/meta/banner.png)
A Theme and Splashscreen Manager for the Nintendo3DS, written in C.
# Dependencies
This depends on zlib. Get it from portlibs.
* zlib, which can be retrieved from the [3ds_portlibs](https://github.com/devkitPro/3ds_portlibs).
* [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools), which can be retrieved from [SteveIce10's](https://github.com/Steveice10) buildtools repo. These must be added to your PATH.
* [pp2d](https://github.com/BernardoGiordano/pp2d), which is included in the repo if you do a git clone --recursive.
* Git needs to be on your PATH, if building in a non-*nix environment.
# Building
First of all, make sure devkitPRO is properly installed and added to the PATH.
After that, open the directory you want to clone the repo into, and type: `git clone https://github.com/astronautlevel2/Anemone3DS/ --recursive`.
Instructions for installing zlib can be found on the [3ds_portlibs repo](https://github.com/devkitPro/3ds_portlibs) (its easy, just run `make` and `make install-zlib`). After also adding [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools) to your PATH, just enter your directory and run `make`. All built files will be in `/out/`.
# License
This project is licensed under the GNU GPLv3. See LICENSE.md for details. Additional terms 7b and 7c apply to this project.
# Credits
The following people contributed to Anemone3DS in some way. Without these people, Anemone3DS wouldn't exist, or wouldn't be as good as it is:
* Daedreth, who wrote the initial implementation of theme application code and SMDH parsing
* LiquidFenrir, who refactored a lot of my messy GUI code and wrote the image preview from zip code, as well as the icon code
* Sono, who wrote the BCSTM playback code
* Kenn (mattkenster) for designing the GUI, a number of sprites used in the application, and drawing the banner and icon.
* [Daedreth](https://github.com/daedreth), who wrote the initial implementation of theme application code and SMDH parsing.
* [LiquidFenrir](https://github.com/LiquidFenrir), who refactored a lot of my messy GUI code and wrote the image preview from zip code, as well as the icon code.
* [Sono](https://github.com/MarcuzD), who wrote the BCSTM playback code.
* [Kenn (mattkenster)](https://github.com/mattkenster), for designing the GUI, a number of sprites used in the application, and drawing the banner and icon.
Special thanks go to these people who, while not directly contributing, helped immensely:
* Rinnegatamante, whose code served as reference on theme installation.
* BernardoGiordano for making pp2d, and being super responsive to feature requests and just general help
* yellows8 for his home menu extdump tool, which was invaluable in debugging.
* the folks on #dev of Nintendo Homebrew, who helped with unicode shenanigans (especially Stary2001, Fenrir, and DanielKO).
* the maintainers for all used libraries, including ctrulib, zlib, citro3d, pp2d and minizip.
* [Rinnegatamante](https://github.com/Rinnegatamante), whose code served as reference on theme installation.
* [BernardoGiordano](https://github.com/BernardoGiordano) for making pp2d, and being super responsive to feature requests and just general help.
* [yellows8](https://github.com/yellows8) for his home menu extdump tool, which was invaluable in debugging.
* the folks on #dev of Nintendo Homebrew, who helped with unicode shenanigans (especially [Stary2001](https://github.com/Stary2001), [Fenrir](https://github.com/FenrirWolf), and DanielKO).
* the maintainers for all used libraries, including ctrulib, zlib, citro3d, pp2d, quirc and minizip.
* all the people who helped keep me going and motivated me to work. This includes, but is definitely not limited to:
* The members of the Nintendo Homebrew Discord
* The members of the Secret Shack Service Discord
* The members of the ThemePlaza Discord
+ The members of the [Nintendo Homebrew Discord](https://discord.gg/C29hYvh)
+ The members of the __Secret Shack Service Discord__
+ The members of the [ThemePlaza Discord](https://discord.gg/2hUQwXz)

39
include/camera.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* This file is part of Anemone3DS
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CAMERA_H
#define CAMERA_H
#include "common.h"
bool qr_mode;
void init_qr(void);
void exit_qr(void);
void take_picture(void);
Result http_get(char *url, char *path);
#endif

View File

@@ -35,16 +35,31 @@
#define THEMES_PATH "/Themes/"
#define SPLASHES_PATH "/Splashes/"
#define SINGLE_INSTALL 0
#define SHUFFLE_INSTALL 1
#define BGM_INSTALL 2
#define SINGLE_INSTALL 0
#define SHUFFLE_INSTALL 1
#define BGM_INSTALL 2
#define UNINSTALL 3
#define DOWNLOADING 3
#define ERROR 0
#define WARNING 1
static const int THEMES_PER_SCREEN = 4;
bool homebrew;
bool splash_mode;
enum TextureID {
TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font
TEXTURE_ARROW,
TEXTURE_SHUFFLE,
TEXTURE_BATTERY_1,
TEXTURE_BATTERY_2,
TEXTURE_BATTERY_3,
TEXTURE_BATTERY_4,
TEXTURE_BATTERY_5,
TEXTURE_BATTERY_CHARGE,
TEXTURE_QR,
TEXTURE_PREVIEW,
};

View File

@@ -29,13 +29,16 @@
#include "themes.h"
#include "splashes.h"
#include "camera.h"
void init_screens(void);
void exit_screens(void);
void draw_themext_error(void);
void draw_base_interface(void);
void draw_theme_install(int install_type);
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode);
void draw_splash_install(void);
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count);
void draw_splash_install(int install_type);
void draw_splash_interface(Splash_s *splashes_list, int splash_count, int selected_splash, bool preview_mode);
void throw_error(char* error, int error_type);
#endif

View File

@@ -39,7 +39,7 @@ Result close_archives(void);
u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf);
u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
void remake_file(char *path, FS_Archive archive, u32 size);
#endif

View File

@@ -30,12 +30,23 @@
#include "common.h"
typedef struct{
u16 name[0x106];
u16 top_path[0x106];
u16 bottom_path[0x106];
u16 name[0x40];
u16 desc[0x80];
u16 author[0x40];
u32 placeholder_color;
ssize_t icon_id;
u16 path[0x106];
bool is_zip;
} Splash_s;
Splash_s *splashes_list;
int splash_count;
Result get_splashes(Splash_s** splashes_list, int *splash_count);
void splash_install(Splash_s splash_to_install);
void splash_delete();
void load_splash_preview(Splash_s *splash);
#endif

View File

@@ -34,7 +34,7 @@ typedef struct {
u16 desc[0x80];
u16 author[0x40];
bool has_icon;
u32 placeholder_color;
ssize_t icon_id;
bool has_preview;
@@ -46,8 +46,12 @@ typedef struct {
bool in_shuffle;
} Theme_s;
Theme_s * themes_list;
int theme_count;
void load_theme_preview(Theme_s *theme);
Result get_themes(Theme_s **themes_list, int *theme_count);
void del_theme(u16 *path);
Result single_install(Theme_s theme);
Result shuffle_install(Theme_s *themes_list, int theme_count);
Result bgm_install(Theme_s bgm_to_install);

View File

@@ -3,7 +3,7 @@ BasicInfo:
CompanyCode : "00"
ProductCode : "CTR-P-ANEM"
ContentType : Application
Logo : Nintendo # Nintendo / Licensed / Distributed / iQue / iQueForSystem
Logo : Homebrew # Nintendo / Licensed / Distributed / iQue / iQueForSystem
TitleInfo:
UniqueId : 0xAFEN
@@ -33,6 +33,9 @@ SystemControlInfo:
RemasterVersion: 7
StackSize: 0x40000
RomFs:
RootPath : romfs
# DO NOT EDIT BELOW HERE OR PROGRAMS WILL NOT LAUNCH (most likely)
AccessControlInfo:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
romfs/battery1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

BIN
romfs/battery2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

BIN
romfs/battery3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
romfs/battery4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
romfs/battery5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
romfs/charging.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

After

Width:  |  Height:  |  Size: 466 B

280
source/camera.c Normal file
View File

@@ -0,0 +1,280 @@
/*
* This file is part of Anemone3DS
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "camera.h"
#include "quirc/quirc.h"
#include "draw.h"
#include "fs.h"
#include "themes.h"
#include "pp2d/pp2d/pp2d.h"
u32 transfer_size;
Handle event;
struct quirc* context;
void init_qr(void)
{
camInit();
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
CAMU_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_10);
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
CAMU_SetTrimming(PORT_CAM1, false);
CAMU_SetTrimming(PORT_CAM2, false);
CAMU_GetMaxBytes(&transfer_size, 400, 240);
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
CAMU_Activate(SELECT_OUT1_OUT2);
event = 0;
CAMU_ClearBuffer(PORT_BOTH);
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
CAMU_StartCapture(PORT_BOTH);
context = quirc_new();
quirc_resize(context, 400, 240);
}
void exit_qr(void)
{
CAMU_StopCapture(PORT_BOTH);
CAMU_Activate(SELECT_NONE);
camExit();
quirc_destroy(context);
}
void scan_qr(u16 *buf)
{
int w;
int h;
u8 *image = (u8*) quirc_begin(context, &w, &h);
for (ssize_t x = 0; x < w; x++)
{
for (ssize_t y = 0; y < h; y++)
{
u16 px = buf[y * 400 + x];
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
}
}
quirc_end(context);
if (quirc_count(context) > 0)
{
struct quirc_code code;
struct quirc_data data;
quirc_extract(context, 0, &code);
if (!quirc_decode(&code, &data))
{
qr_mode = false;
http_get((char*)data.payload, splash_mode ? "/Splashes/" : "/Themes/");
}
}
}
void take_picture(void)
{
u16 *buf = malloc(sizeof(u16) * 400 * 240 * 4);
if (buf == NULL) return;
CAMU_SetReceiving(&event, buf, PORT_CAM1, 240 * 400 * 2, transfer_size);
svcWaitSynchronization(event, U64_MAX);
svcCloseHandle(event);
pp2d_begin_draw(GFX_TOP);
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
if (rgba8_buf == NULL) return;
for (int i = 0; i < 240 * 400; i++)
{
rgba8_buf[i] = RGB565_TO_ABGR8(buf[i]);
}
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
pp2d_draw_texture(TEXTURE_QR, 0, 0);
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE005 To Quit");
pp2d_draw_rectangle(0, 0, 400, 24, RGBA8(55, 122, 168, 255));
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE004 To Scan");
pp2d_end_draw();
free(rgba8_buf);
pp2d_free_texture(TEXTURE_QR);
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown & KEY_L)
{
CAMU_StopCapture(PORT_BOTH);
CAMU_Activate(SELECT_NONE);
scan_qr(buf);
CAMU_Activate(SELECT_OUT1_OUT2);
CAMU_StartCapture(PORT_BOTH);
}
if (kDown & KEY_R)
{
exit_qr();
qr_mode = false;
}
free(buf);
}
/*
Putting this in camera because I'm too lazy to make a network.c
This'll probably get refactored later
*/
Result http_get(char *url, char *path)
{
Result ret;
httpcContext context;
char *new_url = NULL;
u32 status_code;
u32 content_size = 0;
u32 read_size = 0;
u32 size = 0;
u8 *buf;
u8 *last_buf;
do {
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
ret = httpcAddRequestHeaderField(&context, "User-Agent", "Anemone3DS/1.1.0");
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
draw_theme_install(DOWNLOADING);
ret = httpcBeginRequest(&context);
if (ret != 0)
{
httpcCloseContext(&context);
if (new_url != NULL) free(new_url);
return ret;
}
ret = httpcGetResponseStatusCode(&context, &status_code);
if(ret!=0){
httpcCloseContext(&context);
if(new_url!=NULL) free(new_url);
return ret;
}
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
{
if (new_url == NULL) new_url = malloc(0x1000);
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
url = new_url;
httpcCloseContext(&context);
}
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
if (status_code != 200)
{
httpcCloseContext(&context);
if (new_url != NULL) free(new_url);
return ret;
}
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
if (ret != 0)
{
httpcCloseContext(&context);
if (new_url != NULL) free(new_url);
return ret;
}
buf = malloc(0x1000);
if (buf == NULL)
{
httpcCloseContext(&context);
free(new_url);
return -2;
}
char *content_disposition = malloc(1024);
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
if (ret != 0)
{
free(content_disposition);
free(new_url);
free(buf);
}
char *filename;
filename = strtok(content_disposition, "\"");
filename = strtok(NULL, "\"");
char *illegal_characters = "\"?;:/\\+";
for (size_t i = 0; i < strlen(filename); i++)
{
for (size_t n = 0; n < strlen(illegal_characters); n++)
{
if (filename[i] == illegal_characters[n])
{
filename[i] = '-';
}
}
}
do {
ret = httpcDownloadData(&context, buf + size, 0x1000, &read_size);
size += read_size;
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
{
last_buf = buf;
buf = realloc(buf, size + 0x1000);
if (buf == NULL)
{
httpcCloseContext(&context);
free(last_buf);
return ret;
}
}
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
last_buf = buf;
buf = realloc(buf, size);
if (buf == NULL)
{
httpcCloseContext(&context);
free(last_buf);
return -1;
}
char path_to_file[0x106] = {0};
strcpy(path_to_file, path);
strcat(path_to_file, filename);
remake_file(path_to_file, ArchiveSD, size);
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
if (splash_mode) get_splashes(&splashes_list, &splash_count);
else get_themes(&themes_list, &theme_count);
exit_qr();
return 0;
}

View File

@@ -25,17 +25,22 @@
*/
#include "draw.h"
#include "common.h"
#include "pp2d/pp2d/pp2d.h"
#include "quirc/quirc.h"
#include <time.h>
enum Colors {
COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
COLOR_ACCENT = RGBA8(55, 122, 168, 255),
COLOR_WHITE = RGBA8(255, 255, 255, 255),
COLOR_CURSOR = RGBA8(200, 200, 200, 255),
COLOR_BLACK = RGBA8(0, 0, 0, 255),
COLOR_RED = RGBA8(200, 0, 0, 255),
COLOR_YELLOW = RGBA8(239, 220, 11, 255),
};
void init_screens(void)
@@ -47,6 +52,12 @@ void init_screens(void)
pp2d_load_texture_png(TEXTURE_ARROW, "romfs:/arrow.png");
pp2d_load_texture_png(TEXTURE_SHUFFLE, "romfs:/shuffle.png");
pp2d_load_texture_png(TEXTURE_BATTERY_1, "romfs:/battery1.png");
pp2d_load_texture_png(TEXTURE_BATTERY_2, "romfs:/battery2.png");
pp2d_load_texture_png(TEXTURE_BATTERY_3, "romfs:/battery3.png");
pp2d_load_texture_png(TEXTURE_BATTERY_4, "romfs:/battery4.png");
pp2d_load_texture_png(TEXTURE_BATTERY_5, "romfs:/battery5.png");
pp2d_load_texture_png(TEXTURE_BATTERY_CHARGE, "romfs:/charging.png");
}
void exit_screens(void)
@@ -54,24 +65,14 @@ void exit_screens(void)
pp2d_exit();
}
static Result MCUHWC_GetBatteryLevel(u8 *out) // Code taken from daedreth's fork of lpp-3ds
{
#define TRY(expr) if(R_FAILED(res = (expr))) { svcCloseHandle(mcuhwcHandle); return res; }
Result res;
Handle mcuhwcHandle;
TRY(srvGetServiceHandle(&mcuhwcHandle, "mcu::HWC"));
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x50000;
TRY(svcSendSyncRequest(mcuhwcHandle));
*out = (u8) cmdbuf[2];
svcCloseHandle(mcuhwcHandle);
return cmdbuf[1];
#undef TRY
}
static int theme_vertical_scroll = 0;
static int splash_vertical_scroll = 0;
void draw_themext_error(void)
{
throw_error("Theme extdata does not exist\nSet a default theme from the home menu", ERROR);
}
void draw_base_interface(void)
{
pp2d_begin_draw(GFX_TOP);
@@ -84,29 +85,72 @@ void draw_base_interface(void)
pp2d_draw_text(28, 2, 0.6, 0.6, COLOR_WHITE, (tm.tm_sec % 2 == 1) ? ":" : " ");
pp2d_draw_textf(34, 2, 0.6, 0.6, COLOR_WHITE, "%.2i", tm.tm_min);
u8 battery_val = 0;
MCUHWC_GetBatteryLevel(&battery_val);
pp2d_draw_textf(350, 2, 0.6, 0.6, COLOR_WHITE, "%i%%", battery_val);
u8 battery_charging;
PTMU_GetBatteryChargeState(&battery_charging);
u8 battery_status;
PTMU_GetBatteryLevel(&battery_status);
pp2d_draw_texture(2 + battery_status, 357, 2);
if (battery_charging)
pp2d_draw_texture(TEXTURE_BATTERY_CHARGE, 357, 2);
pp2d_draw_on(GFX_BOTTOM);
pp2d_draw_rectangle(0, 0, 320, 24, COLOR_ACCENT);
pp2d_draw_rectangle(0, 216, 320, 24, COLOR_ACCENT);
pp2d_draw_text(7, 219, 0.6, 0.6, COLOR_WHITE, VERSION);
pp2d_draw_on(GFX_TOP);
}
void throw_error(char* error, int error_type) {
switch (error_type) {
case ERROR:
while (aptMainLoop())
{
hidScanInput();
u32 kDown = hidKeysDown();
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 120, 0.6, 0.6, COLOR_RED, error);
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to shut down.");
pp2d_end_draw();
if (kDown & KEY_A) {
if (homebrew)
APT_HardwareResetAsync();
else {
srvPublishToSubscriber(0x202, 0);
}
}
}
case WARNING:
while (aptMainLoop())
{
hidScanInput();
u32 kDown = hidKeysDown();
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 120, 0.6, 0.6, COLOR_YELLOW, error);
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to continue.");
pp2d_end_draw();
if (kDown & KEY_A) break;
}
break;
}
pp2d_end_draw();
}
void draw_theme_install(int install_type)
{
draw_base_interface();
switch(install_type)
{
case 0:
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a single theme...");
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a single theme...");
break;
case 1:
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a shuffle theme...");
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a shuffle theme...");
break;
case 2:
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing BGM...");
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing BGM...");
break;
case 3:
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading...");
break;
default:
break;
@@ -114,13 +158,15 @@ void draw_theme_install(int install_type)
pp2d_end_draw();
}
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode)
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count)
{
if (themes_list == NULL)
{
pp2d_begin_draw(GFX_TOP);
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO THEMES FOUND");
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 80, 0.7, 0.7, COLOR_YELLOW, "No themes found!");
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_YELLOW, "Press \uE005 to download from QR");
pp2d_draw_text_center(GFX_TOP, 140, 0.7, 0.7, COLOR_YELLOW, "Or \uE045 to quit");
pp2d_end_draw();
return;
}
@@ -143,14 +189,14 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Theme mode");
wchar_t title[0x40] = {0};
utf16_to_utf32((u32*)title, current_theme.name, 0x40);
pp2d_draw_wtext(20, 30, 0.7, 0.7, COLOR_WHITE, title);
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
wchar_t author[0x40] = {0};
utf16_to_utf32((u32*)author, current_theme.author, 0x40);
pp2d_draw_text(20, 50, 0.5, 0.5, COLOR_WHITE, "By: ");
pp2d_draw_wtext(44, 50, 0.5, 0.5, COLOR_WHITE, author);
wchar_t description[0x80] = {0};
utf16_to_utf32((u32*)description, current_theme.desc, 0x80);
pp2d_draw_wtext(20, 65, 0.5, 0.5, COLOR_WHITE, description);
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
wchar_t description[0xa6] = {0};
utf16_to_utf32((u32*)description, current_theme.desc, 0xb0);
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
pp2d_draw_wtext(20, 150, 0.6, 0.6, COLOR_WHITE, L"\uE046 Install Shuffle Theme");
pp2d_draw_wtext(200, 150, 0.6, 0.6, COLOR_WHITE, L"\uE004 Switch to Splashes");
@@ -158,9 +204,11 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
pp2d_draw_wtext(200, 180, 0.6, 0.6, COLOR_WHITE, L"\uE001 Queue Shuffle");
pp2d_draw_wtext(20, 210, 0.6, 0.6, COLOR_WHITE, L"\uE002 Install BGM");
pp2d_draw_wtext(200, 210, 0.6, 0.6, COLOR_WHITE, L"\uE003 Preview Theme");
pp2d_draw_wtext(130, 120, 0.6, 0.6, COLOR_WHITE, L"\uE005 Scan QRCode");
pp2d_draw_on(GFX_BOTTOM);
pp2d_draw_textf(7, 3, 0.6, 0.6, COLOR_WHITE, "Selected: %i/10", shuffle_theme_count);
// Scroll the menu up or down if the selected theme is out of its bounds
//----------------------------------------------------------------
for (int i = 0; i < theme_count; i++) {
@@ -202,8 +250,10 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
}
pp2d_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
if (current_theme.has_icon)
if (!current_theme.placeholder_color)
pp2d_draw_texture(current_theme.icon_id, 0, 24 + vertical_offset);
else
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_theme.placeholder_color);
if (current_theme.in_shuffle)
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 280, 32 + vertical_offset, font_color);
@@ -213,10 +263,20 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
pp2d_end_draw();
}
void draw_splash_install(void)
void draw_splash_install(int install_type)
{
draw_base_interface();
pp2d_draw_textf(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
switch (install_type)
{
case SINGLE_INSTALL:
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
break;
case UNINSTALL:
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
break;
default:
break;
}
pp2d_end_draw();
}
@@ -224,22 +284,38 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
{
if (splashes_list == NULL)
{
pp2d_begin_draw(GFX_TOP);
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO SPLASHES FOUND");
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 80, 0.7, 0.7, COLOR_YELLOW, "No splashes found!");
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_YELLOW, "Press \uE005 to download from QR");
pp2d_draw_text_center(GFX_TOP, 140, 0.7, 0.7, COLOR_YELLOW, "Or \uE045 to quit");
pp2d_end_draw();
return;
}
Splash_s current_splash = splashes_list[selected_splash];
if (preview_mode)
{
// TODO: Splash Previews
pp2d_begin_draw(GFX_TOP);
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 0, 0, 400, 240);
pp2d_draw_on(GFX_BOTTOM);
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40, 240, 320, 240);
} else {
draw_base_interface();
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
wchar_t title[0x40] = {0};
utf16_to_utf32((u32*)title, current_splash.name, 0x40);
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
wchar_t author[0x40] = {0};
utf16_to_utf32((u32*)author, current_splash.author, 0x40);
pp2d_draw_text(20, 50, 0.5, 0.5, COLOR_WHITE, "By: ");
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
wchar_t description[0xa6] = {0};
utf16_to_utf32((u32*)description, current_splash.desc, 0xb0);
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
pp2d_draw_wtext_center(GFX_TOP, 210, 0.7, 0.7, COLOR_WHITE, L"\uE000 Install Splash \uE004 Switch to Themes");
pp2d_draw_wtext_center(GFX_TOP, 180, 0.7, 0.7, COLOR_WHITE, L"\uE000 Install Splash \uE004 Switch to Themes");
pp2d_draw_wtext_center(GFX_TOP, 210, 0.7, 0.7, COLOR_WHITE, L"\uE002 Delete current Splash");
pp2d_draw_wtext_center(GFX_TOP, 150, 0.7, 0.7, COLOR_WHITE, L"\uE003 Preview Splash \uE005 Scan QRCode");
pp2d_draw_wtext(130, 120, 0.6, 0.6, COLOR_WHITE, L"");
pp2d_draw_on(GFX_BOTTOM);
for (int i = 0; i < splash_count; i++) {
@@ -277,7 +353,12 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
font_color = COLOR_BLACK;
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
}
pp2d_draw_wtext(15, 40 + vertical_offset, 0.55, 0.55, font_color, name);
pp2d_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
if (!current_splash.placeholder_color)
pp2d_draw_texture(current_splash.icon_id, 0, 24 + vertical_offset);
else
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_splash.placeholder_color);
}
}
pp2d_end_draw();

View File

@@ -38,7 +38,7 @@ int filename_compare(__attribute__((unused)) unzFile file, const char *current_f
Result open_archives(void)
{
romfsInit();
u8 regionCode;
u32 archive1;
u32 archive2;
@@ -68,9 +68,13 @@ Result open_archives(void)
archive2 = 0x00;
}
retValue = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
if(R_FAILED(retValue)) return retValue;
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Themes"), FS_ATTRIBUTE_DIRECTORY);
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Splashes"), FS_ATTRIBUTE_DIRECTORY);
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
home.type = PATH_BINARY;
home.size = 0xC;
@@ -85,7 +89,11 @@ Result open_archives(void)
retValue = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme);
if(R_FAILED(retValue)) return retValue;
romfsInit();
Handle test_handle;
retValue = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0);
if(R_FAILED(retValue)) return retValue;
FSFILE_Close(test_handle);
return 0;
}
@@ -111,7 +119,7 @@ u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
u64 size;
FSFILE_GetSize(file, &size);
*buf = malloc(size);
*buf = calloc(1, size);
FSFILE_Read(file, NULL, 0, *buf, size);
FSFILE_Close(file);
return size;
@@ -135,7 +143,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
unz_file_info *file_info = malloc(sizeof(unz_file_info));
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
file_size = file_info->uncompressed_size;
*buf = malloc(file_size);
*buf = calloc(1, file_size);
unzOpenCurrentFile(zip_handle);
unzReadCurrentFile(zip_handle, *buf, file_size);
unzCloseCurrentFile(zip_handle);
@@ -151,17 +159,16 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
}
}
u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
{
Handle handle;
u32 bytes = 0;
Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
if (R_FAILED(res)) return res;
res = FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH);
res = FSFILE_Write(handle, NULL, 0, buf, size, FS_WRITE_FLUSH);
if (R_FAILED(res)) return res;
res = FSFILE_Close(handle);
if (R_FAILED(res)) return res;
return bytes;
return 0;
}
void remake_file(char *path, FS_Archive archive, u32 size)

View File

@@ -28,30 +28,51 @@
#include "themes.h"
#include "splashes.h"
#include "draw.h"
#include "common.h"
#include "camera.h"
#include <time.h>
int __stacksize__ = 64 * 1024;
Result archive_result;
int init_services(void)
{
cfguInit();
open_archives();
ptmSysmInit();
return 0;
ptmuInit();
httpcInit(0);
archive_result = open_archives();
homebrew = true;
if (!envIsHomebrew())
{
homebrew = false;
} else {
s64 out;
svcGetSystemInfo(&out, 0x10000, 0);
if (out)
{
homebrew = false;
}
}
return homebrew;
}
int exit_services(void)
{
close_archives();
cfguExit();
ptmuExit();
httpcExit();
return 0;
}
int main(void)
{
init_services();
srand(time(NULL));
bool homebrew = init_services();
init_screens();
int theme_count = 0;
Theme_s * themes_list = NULL;
themes_list = NULL;
theme_count = 0;
Result res = get_themes(&themes_list, &theme_count);
if (R_FAILED(res))
{
@@ -59,8 +80,8 @@ int main(void)
free(themes_list);
themes_list = NULL;
}
int splash_count = 0;
Splash_s *splashes_list = NULL;
splash_count = 0;
splashes_list = NULL;
res = get_splashes(&splashes_list, &splash_count);
if (R_FAILED(res))
{
@@ -69,7 +90,7 @@ int main(void)
splashes_list = NULL;
}
bool splash_mode = false;
splash_mode = false;
int selected_splash = 0;
int selected_theme = 0;
int previously_selected = 0;
@@ -80,22 +101,51 @@ int main(void)
{
hidScanInput();
u32 kDown = hidKeysDown();
u32 kHeld = hidKeysHeld();
if (!splash_mode) draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode);
else draw_splash_interface(splashes_list, splash_count, selected_splash, preview_mode);
if (qr_mode)
{
take_picture();
} else if (!splash_mode)
{
draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode, shuffle_theme_count);
} else {
draw_splash_interface(splashes_list, splash_count, selected_splash, preview_mode);
}
if (kDown & KEY_START)
{
exit_screens();
exit_services();
PTMSYSM_RebootAsync(0);
ptmSysmExit();
if (homebrew)
APT_HardwareResetAsync();
else {
srvPublishToSubscriber(0x202, 0);
}
}
else if (kDown & KEY_L)
{
splash_mode = !splash_mode;
}
if (R_FAILED(archive_result) && !splash_mode)
{
draw_themext_error();
continue;
}
if (kDown & KEY_R)
{
if (preview_mode) {
continue;
} else {
qr_mode = !qr_mode;
if (qr_mode) init_qr();
else exit_qr();
continue;
}
}
if (qr_mode) continue;
if (themes_list == NULL && !splash_mode)
continue;
@@ -109,10 +159,16 @@ int main(void)
{
if (!preview_mode)
{
if (!current_theme->has_preview)
load_theme_preview(current_theme);
if (!splash_mode)
{
if (!current_theme->has_preview)
load_theme_preview(current_theme);
preview_mode = current_theme->has_preview;
preview_mode = current_theme->has_preview;
} else {
load_splash_preview(current_splash);
preview_mode = true;
}
}
else
preview_mode = false;
@@ -125,20 +181,28 @@ int main(void)
// Actions
else if (kDown & KEY_X)
{
draw_theme_install(BGM_INSTALL);
bgm_install(*current_theme);
if (splash_mode) {
draw_splash_install(UNINSTALL);
splash_delete();
} else {
draw_theme_install(BGM_INSTALL);
bgm_install(*current_theme);
}
}
else if (kDown & KEY_A)
{
if (splash_mode)
{
draw_splash_install();
draw_splash_install(SINGLE_INSTALL);
splash_install(*current_splash);
svcSleepThread(5e8);
} else {
draw_theme_install(SINGLE_INSTALL);
single_install(*current_theme);
}
//these two are here just so I don't forget how to implement them - HM
//del_theme(current_theme->path);
//get_themes(&themes_list, &theme_count);
}
else if (kDown & KEY_B)
@@ -171,6 +235,7 @@ int main(void)
{
draw_theme_install(SHUFFLE_INSTALL);
shuffle_install(themes_list, theme_count);
shuffle_theme_count = 0;
}
}
}
@@ -225,6 +290,63 @@ int main(void)
if (selected_theme >= theme_count) selected_theme = theme_count-1;
}
}
// Fast scroll using circle pad
else if (kHeld & KEY_CPAD_UP)
{
svcSleepThread(100000000);
if (splash_mode)
{
selected_splash--;
if (selected_splash < 0)
selected_splash = splash_count - 1;
} else {
selected_theme--;
if (selected_theme < 0)
selected_theme = theme_count - 1;
}
}
else if (kHeld & KEY_CPAD_DOWN)
{
svcSleepThread(100000000);
if (splash_mode)
{
selected_splash++;
if (selected_splash >= splash_count)
selected_splash = 0;
} else {
selected_theme++;
if (selected_theme >= theme_count)
selected_theme = 0;
}
}
else if (kDown & KEY_CPAD_LEFT)
{
svcSleepThread(100000000);
if (splash_mode)
{
selected_splash -= 4;
if (selected_splash < 0) selected_splash = 0;
} else {
selected_theme -= 4;
if (selected_theme < 0) selected_theme = 0;
}
}
else if (kDown & KEY_CPAD_RIGHT)
{
svcSleepThread(100000000);
if (splash_mode)
{
selected_splash += 4;
if (selected_splash >= splash_count) selected_splash = splash_count-1;
} else {
selected_theme += 4;
if (selected_theme >= theme_count) selected_theme = theme_count-1;
}
}
if (!splash_mode && selected_theme != previously_selected)
{
@@ -232,8 +354,8 @@ int main(void)
previously_selected = selected_theme;
}
}
free(themes_list);
exit_screens();
exit_services();
return 0;
}

918
source/quirc/decode.c Normal file
View File

@@ -0,0 +1,918 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "quirc_internal.h"
#include <string.h>
#include <stdlib.h>
#define MAX_POLY 64
/************************************************************************
* Galois fields
*/
struct galois_field {
int p;
const uint8_t *log;
const uint8_t *exp;
};
static const uint8_t gf16_exp[16] = {
0x01, 0x02, 0x04, 0x08, 0x03, 0x06, 0x0c, 0x0b,
0x05, 0x0a, 0x07, 0x0e, 0x0f, 0x0d, 0x09, 0x01
};
static const uint8_t gf16_log[16] = {
0x00, 0x0f, 0x01, 0x04, 0x02, 0x08, 0x05, 0x0a,
0x03, 0x0e, 0x09, 0x07, 0x06, 0x0d, 0x0b, 0x0c
};
static const struct galois_field gf16 = {
.p = 15,
.log = gf16_log,
.exp = gf16_exp
};
static const uint8_t gf256_exp[256] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9,
0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35,
0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0,
0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc,
0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f,
0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88,
0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93,
0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9,
0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa,
0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e,
0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4,
0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e,
0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef,
0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5,
0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83,
0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x01
};
static const uint8_t gf256_log[256] = {
0x00, 0xff, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6,
0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81,
0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21,
0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9,
0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd,
0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd,
0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e,
0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b,
0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d,
0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c,
0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd,
0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e,
0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76,
0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa,
0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51,
0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8,
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
};
const static struct galois_field gf256 = {
.p = 255,
.log = gf256_log,
.exp = gf256_exp
};
/************************************************************************
* Polynomial operations
*/
static void poly_add(uint8_t *dst, const uint8_t *src, uint8_t c,
int shift, const struct galois_field *gf)
{
int i;
int log_c = gf->log[c];
if (!c)
return;
for (i = 0; i < MAX_POLY; i++) {
int p = i + shift;
uint8_t v = src[i];
if (p < 0 || p >= MAX_POLY)
continue;
if (!v)
continue;
dst[p] ^= gf->exp[(gf->log[v] + log_c) % gf->p];
}
}
static uint8_t poly_eval(const uint8_t *s, uint8_t x,
const struct galois_field *gf)
{
int i;
uint8_t sum = 0;
uint8_t log_x = gf->log[x];
if (!x)
return s[0];
for (i = 0; i < MAX_POLY; i++) {
uint8_t c = s[i];
if (!c)
continue;
sum ^= gf->exp[(gf->log[c] + log_x * i) % gf->p];
}
return sum;
}
/************************************************************************
* Berlekamp-Massey algorithm for finding error locator polynomials.
*/
static void berlekamp_massey(const uint8_t *s, int N,
const struct galois_field *gf,
uint8_t *sigma)
{
uint8_t C[MAX_POLY];
uint8_t B[MAX_POLY];
int L = 0;
int m = 1;
uint8_t b = 1;
int n;
memset(B, 0, sizeof(B));
memset(C, 0, sizeof(C));
B[0] = 1;
C[0] = 1;
for (n = 0; n < N; n++) {
uint8_t d = s[n];
uint8_t mult;
int i;
for (i = 1; i <= L; i++) {
if (!(C[i] && s[n - i]))
continue;
d ^= gf->exp[(gf->log[C[i]] +
gf->log[s[n - i]]) %
gf->p];
}
mult = gf->exp[(gf->p - gf->log[b] + gf->log[d]) % gf->p];
if (!d) {
m++;
} else if (L * 2 <= n) {
uint8_t T[MAX_POLY];
memcpy(T, C, sizeof(T));
poly_add(C, B, mult, m, gf);
memcpy(B, T, sizeof(B));
L = n + 1 - L;
b = d;
m = 1;
} else {
poly_add(C, B, mult, m, gf);
m++;
}
}
memcpy(sigma, C, MAX_POLY);
}
/************************************************************************
* Code stream error correction
*
* Generator polynomial for GF(2^8) is x^8 + x^4 + x^3 + x^2 + 1
*/
static int block_syndromes(const uint8_t *data, int bs, int npar, uint8_t *s)
{
int nonzero = 0;
int i;
memset(s, 0, MAX_POLY);
for (i = 0; i < npar; i++) {
int j;
for (j = 0; j < bs; j++) {
uint8_t c = data[bs - j - 1];
if (!c)
continue;
s[i] ^= gf256_exp[((int)gf256_log[c] +
i * j) % 255];
}
if (s[i])
nonzero = 1;
}
return nonzero;
}
static void eloc_poly(uint8_t *omega,
const uint8_t *s, const uint8_t *sigma,
int npar)
{
int i;
memset(omega, 0, MAX_POLY);
for (i = 0; i < npar; i++) {
const uint8_t a = sigma[i];
const uint8_t log_a = gf256_log[a];
int j;
if (!a)
continue;
for (j = 0; j + 1 < MAX_POLY; j++) {
const uint8_t b = s[j + 1];
if (i + j >= npar)
break;
if (!b)
continue;
omega[i + j] ^=
gf256_exp[(log_a + gf256_log[b]) % 255];
}
}
}
static quirc_decode_error_t correct_block(uint8_t *data,
const struct quirc_rs_params *ecc)
{
int npar = ecc->bs - ecc->dw;
uint8_t s[MAX_POLY];
uint8_t sigma[MAX_POLY];
uint8_t sigma_deriv[MAX_POLY];
uint8_t omega[MAX_POLY];
int i;
/* Compute syndrome vector */
if (!block_syndromes(data, ecc->bs, npar, s))
return QUIRC_SUCCESS;
berlekamp_massey(s, npar, &gf256, sigma);
/* Compute derivative of sigma */
memset(sigma_deriv, 0, MAX_POLY);
for (i = 0; i + 1 < MAX_POLY; i += 2)
sigma_deriv[i] = sigma[i + 1];
/* Compute error evaluator polynomial */
eloc_poly(omega, s, sigma, npar - 1);
/* Find error locations and magnitudes */
for (i = 0; i < ecc->bs; i++) {
uint8_t xinv = gf256_exp[255 - i];
if (!poly_eval(sigma, xinv, &gf256)) {
uint8_t sd_x = poly_eval(sigma_deriv, xinv, &gf256);
uint8_t omega_x = poly_eval(omega, xinv, &gf256);
uint8_t error = gf256_exp[(255 - gf256_log[sd_x] +
gf256_log[omega_x]) % 255];
data[ecc->bs - i - 1] ^= error;
}
}
if (block_syndromes(data, ecc->bs, npar, s))
return QUIRC_ERROR_DATA_ECC;
return QUIRC_SUCCESS;
}
/************************************************************************
* Format value error correction
*
* Generator polynomial for GF(2^4) is x^4 + x + 1
*/
#define FORMAT_MAX_ERROR 3
#define FORMAT_SYNDROMES (FORMAT_MAX_ERROR * 2)
#define FORMAT_BITS 15
static int format_syndromes(uint16_t u, uint8_t *s)
{
int i;
int nonzero = 0;
memset(s, 0, MAX_POLY);
for (i = 0; i < FORMAT_SYNDROMES; i++) {
int j;
s[i] = 0;
for (j = 0; j < FORMAT_BITS; j++)
if (u & (1 << j))
s[i] ^= gf16_exp[((i + 1) * j) % 15];
if (s[i])
nonzero = 1;
}
return nonzero;
}
static quirc_decode_error_t correct_format(uint16_t *f_ret)
{
uint16_t u = *f_ret;
int i;
uint8_t s[MAX_POLY];
uint8_t sigma[MAX_POLY];
/* Evaluate U (received codeword) at each of alpha_1 .. alpha_6
* to get S_1 .. S_6 (but we index them from 0).
*/
if (!format_syndromes(u, s))
return QUIRC_SUCCESS;
berlekamp_massey(s, FORMAT_SYNDROMES, &gf16, sigma);
/* Now, find the roots of the polynomial */
for (i = 0; i < 15; i++)
if (!poly_eval(sigma, gf16_exp[15 - i], &gf16))
u ^= (1 << i);
if (format_syndromes(u, s))
return QUIRC_ERROR_FORMAT_ECC;
*f_ret = u;
return QUIRC_SUCCESS;
}
/************************************************************************
* Decoder algorithm
*/
struct datastream {
uint8_t raw[QUIRC_MAX_PAYLOAD];
int data_bits;
int ptr;
uint8_t data[QUIRC_MAX_PAYLOAD];
};
static inline int grid_bit(const struct quirc_code *code, int x, int y)
{
int p = y * code->size + x;
return (code->cell_bitmap[p >> 3] >> (p & 7)) & 1;
}
static quirc_decode_error_t read_format(const struct quirc_code *code,
struct quirc_data *data, int which)
{
int i;
uint16_t format = 0;
uint16_t fdata;
quirc_decode_error_t err;
if (which) {
for (i = 0; i < 7; i++)
format = (format << 1) |
grid_bit(code, 8, code->size - 1 - i);
for (i = 0; i < 8; i++)
format = (format << 1) |
grid_bit(code, code->size - 8 + i, 8);
} else {
static const int xs[15] = {
8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0
};
static const int ys[15] = {
0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8
};
for (i = 14; i >= 0; i--)
format = (format << 1) | grid_bit(code, xs[i], ys[i]);
}
format ^= 0x5412;
err = correct_format(&format);
if (err)
return err;
fdata = format >> 10;
data->ecc_level = fdata >> 3;
data->mask = fdata & 7;
return QUIRC_SUCCESS;
}
static int mask_bit(int mask, int i, int j)
{
switch (mask) {
case 0: return !((i + j) % 2);
case 1: return !(i % 2);
case 2: return !(j % 3);
case 3: return !((i + j) % 3);
case 4: return !(((i / 2) + (j / 3)) % 2);
case 5: return !((i * j) % 2 + (i * j) % 3);
case 6: return !(((i * j) % 2 + (i * j) % 3) % 2);
case 7: return !(((i * j) % 3 + (i + j) % 2) % 2);
}
return 0;
}
static int reserved_cell(int version, int i, int j)
{
const struct quirc_version_info *ver = &quirc_version_db[version];
int size = version * 4 + 17;
int ai = -1, aj = -1, a;
/* Finder + format: top left */
if (i < 9 && j < 9)
return 1;
/* Finder + format: bottom left */
if (i + 8 >= size && j < 9)
return 1;
/* Finder + format: top right */
if (i < 9 && j + 8 >= size)
return 1;
/* Exclude timing patterns */
if (i == 6 || j == 6)
return 1;
/* Exclude version info, if it exists. Version info sits adjacent to
* the top-right and bottom-left finders in three rows, bounded by
* the timing pattern.
*/
if (version >= 7) {
if (i < 6 && j + 11 >= size)
return 1;
if (i + 11 >= size && j < 6)
return 1;
}
/* Exclude alignment patterns */
for (a = 0; a < QUIRC_MAX_ALIGNMENT && ver->apat[a]; a++) {
int p = ver->apat[a];
if (abs(p - i) < 3)
ai = a;
if (abs(p - j) < 3)
aj = a;
}
if (ai >= 0 && aj >= 0) {
a--;
if (ai > 0 && ai < a)
return 1;
if (aj > 0 && aj < a)
return 1;
if (aj == a && ai == a)
return 1;
}
return 0;
}
static void read_bit(const struct quirc_code *code,
struct quirc_data *data,
struct datastream *ds, int i, int j)
{
int bitpos = ds->data_bits & 7;
int bytepos = ds->data_bits >> 3;
int v = grid_bit(code, j, i);
if (mask_bit(data->mask, i, j))
v ^= 1;
if (v)
ds->raw[bytepos] |= (0x80 >> bitpos);
ds->data_bits++;
}
static void read_data(const struct quirc_code *code,
struct quirc_data *data,
struct datastream *ds)
{
int y = code->size - 1;
int x = code->size - 1;
int dir = -1;
while (x > 0) {
if (x == 6)
x--;
if (!reserved_cell(data->version, y, x))
read_bit(code, data, ds, y, x);
if (!reserved_cell(data->version, y, x - 1))
read_bit(code, data, ds, y, x - 1);
y += dir;
if (y < 0 || y >= code->size) {
dir = -dir;
x -= 2;
y += dir;
}
}
}
static quirc_decode_error_t codestream_ecc(struct quirc_data *data,
struct datastream *ds)
{
const struct quirc_version_info *ver =
&quirc_version_db[data->version];
const struct quirc_rs_params *sb_ecc = &ver->ecc[data->ecc_level];
struct quirc_rs_params lb_ecc;
int bc = ver->data_bytes / sb_ecc->bs;
int dst_offset = 0;
int lb_count = ver->data_bytes - bc * sb_ecc->bs;
int small_dw_total = bc * sb_ecc->dw;
int i;
memcpy(&lb_ecc, sb_ecc, sizeof(lb_ecc));
lb_ecc.dw++;
lb_ecc.bs++;
for (i = 0; i < bc; i++) {
uint8_t *dst = ds->data + dst_offset;
const struct quirc_rs_params *ecc = sb_ecc;
quirc_decode_error_t err;
int j = 0;
int k;
for (k = 0; k < sb_ecc->dw; k++)
dst[j++] = ds->raw[k * bc + i];
if (i + lb_count >= bc) {
dst[j++] = ds->raw[small_dw_total + i - lb_count];
ecc = &lb_ecc;
}
for (k = 0; k < sb_ecc->bs - sb_ecc->dw; k++)
dst[j++] = ds->raw[small_dw_total + lb_count + i +
k * bc];
err = correct_block(dst, ecc);
if (err)
return err;
dst_offset += ecc->dw;
}
ds->data_bits = dst_offset * 8;
return QUIRC_SUCCESS;
}
static inline int bits_remaining(const struct datastream *ds)
{
return ds->data_bits - ds->ptr;
}
static int take_bits(struct datastream *ds, int len)
{
int ret = 0;
while (len && (ds->ptr < ds->data_bits)) {
uint8_t b = ds->data[ds->ptr >> 3];
int bitpos = ds->ptr & 7;
ret <<= 1;
if ((b << bitpos) & 0x80)
ret |= 1;
ds->ptr++;
len--;
}
return ret;
}
static int numeric_tuple(struct quirc_data *data,
struct datastream *ds,
int bits, int digits)
{
int tuple;
int i;
if (bits_remaining(ds) < bits)
return -1;
tuple = take_bits(ds, bits);
for (i = digits - 1; i >= 0; i--) {
data->payload[data->payload_len + i] = tuple % 10 + '0';
tuple /= 10;
}
data->payload_len += digits;
return 0;
}
static quirc_decode_error_t decode_numeric(struct quirc_data *data,
struct datastream *ds)
{
int bits = 14;
int count;
if (data->version < 10)
bits = 10;
else if (data->version < 27)
bits = 12;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
while (count >= 3) {
if (numeric_tuple(data, ds, 10, 3) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 3;
}
if (count >= 2) {
if (numeric_tuple(data, ds, 7, 2) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 2;
}
if (count) {
if (numeric_tuple(data, ds, 4, 1) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count--;
}
return QUIRC_SUCCESS;
}
static int alpha_tuple(struct quirc_data *data,
struct datastream *ds,
int bits, int digits)
{
int tuple;
int i;
if (bits_remaining(ds) < bits)
return -1;
tuple = take_bits(ds, bits);
for (i = 0; i < digits; i++) {
static const char *alpha_map =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
data->payload[data->payload_len + digits - i - 1] =
alpha_map[tuple % 45];
tuple /= 45;
}
data->payload_len += digits;
return 0;
}
static quirc_decode_error_t decode_alpha(struct quirc_data *data,
struct datastream *ds)
{
int bits = 13;
int count;
if (data->version < 7)
bits = 9;
else if (data->version < 11)
bits = 10;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
while (count >= 2) {
if (alpha_tuple(data, ds, 11, 2) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 2;
}
if (count) {
if (alpha_tuple(data, ds, 6, 1) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count--;
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_byte(struct quirc_data *data,
struct datastream *ds)
{
int bits = 16;
int count;
int i;
if (data->version < 10)
bits = 8;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
if (bits_remaining(ds) < count * 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
for (i = 0; i < count; i++)
data->payload[data->payload_len++] = take_bits(ds, 8);
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_kanji(struct quirc_data *data,
struct datastream *ds)
{
int bits = 12;
int count;
int i;
if (data->version < 10)
bits = 8;
else if (data->version < 27)
bits = 10;
count = take_bits(ds, bits);
if (data->payload_len + count * 2 + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
if (bits_remaining(ds) < count * 13)
return QUIRC_ERROR_DATA_UNDERFLOW;
for (i = 0; i < count; i++) {
int d = take_bits(ds, 13);
uint16_t sjw;
if (d + 0x8140 >= 0x9ffc)
sjw = d + 0x8140;
else
sjw = d + 0xc140;
data->payload[data->payload_len++] = sjw >> 8;
data->payload[data->payload_len++] = sjw & 0xff;
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_eci(struct quirc_data *data,
struct datastream *ds)
{
if (bits_remaining(ds) < 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = take_bits(ds, 8);
if ((data->eci & 0xc0) == 0x80) {
if (bits_remaining(ds) < 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = (data->eci << 8) | take_bits(ds, 8);
} else if ((data->eci & 0xe0) == 0xc0) {
if (bits_remaining(ds) < 16)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = (data->eci << 16) | take_bits(ds, 16);
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_payload(struct quirc_data *data,
struct datastream *ds)
{
while (bits_remaining(ds) >= 4) {
quirc_decode_error_t err = QUIRC_SUCCESS;
int type = take_bits(ds, 4);
switch (type) {
case QUIRC_DATA_TYPE_NUMERIC:
err = decode_numeric(data, ds);
break;
case QUIRC_DATA_TYPE_ALPHA:
err = decode_alpha(data, ds);
break;
case QUIRC_DATA_TYPE_BYTE:
err = decode_byte(data, ds);
break;
case QUIRC_DATA_TYPE_KANJI:
err = decode_kanji(data, ds);
break;
case 7:
err = decode_eci(data, ds);
break;
default:
goto done;
}
if (err)
return err;
if (!(type & (type - 1)) && (type > data->data_type))
data->data_type = type;
}
done:
/* Add nul terminator to all payloads */
if (data->payload_len >= sizeof(data->payload))
data->payload_len--;
data->payload[data->payload_len] = 0;
return QUIRC_SUCCESS;
}
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
struct quirc_data *data)
{
quirc_decode_error_t err;
struct datastream ds;
if ((code->size - 17) % 4)
return QUIRC_ERROR_INVALID_GRID_SIZE;
memset(data, 0, sizeof(*data));
memset(&ds, 0, sizeof(ds));
data->version = (code->size - 17) / 4;
if (data->version < 1 ||
data->version > QUIRC_MAX_VERSION)
return QUIRC_ERROR_INVALID_VERSION;
/* Read format information -- try both locations */
err = read_format(code, data, 0);
if (err)
err = read_format(code, data, 1);
if (err)
return err;
read_data(code, data, &ds);
err = codestream_ecc(data, &ds);
if (err)
return err;
err = decode_payload(data, &ds);
if (err)
return err;
return QUIRC_SUCCESS;
}

1265
source/quirc/identify.c Normal file

File diff suppressed because it is too large Load Diff

91
source/quirc/quirc.c Normal file
View File

@@ -0,0 +1,91 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "quirc_internal.h"
const char *quirc_version(void)
{
return "1.0";
}
struct quirc *quirc_new(void)
{
struct quirc *q = malloc(sizeof(*q));
if (!q)
return NULL;
memset(q, 0, sizeof(*q));
return q;
}
void quirc_destroy(struct quirc *q)
{
if (q->image)
free(q->image);
if (sizeof(*q->image) != sizeof(*q->pixels))
free(q->pixels);
free(q);
}
int quirc_resize(struct quirc *q, int w, int h)
{
uint8_t *new_image = realloc(q->image, w * h);
if (!new_image)
return -1;
if (sizeof(*q->image) != sizeof(*q->pixels)) {
size_t new_size = w * h * sizeof(quirc_pixel_t);
quirc_pixel_t *new_pixels = realloc(q->pixels, new_size);
if (!new_pixels)
return -1;
q->pixels = new_pixels;
}
q->image = new_image;
q->w = w;
q->h = h;
return 0;
}
int quirc_count(const struct quirc *q)
{
return q->num_grids;
}
static const char *const error_table[] = {
[QUIRC_SUCCESS] = "Success",
[QUIRC_ERROR_INVALID_GRID_SIZE] = "Invalid grid size",
[QUIRC_ERROR_INVALID_VERSION] = "Invalid version",
[QUIRC_ERROR_FORMAT_ECC] = "Format data ECC failure",
[QUIRC_ERROR_DATA_ECC] = "ECC failure",
[QUIRC_ERROR_UNKNOWN_DATA_TYPE] = "Unknown data type",
[QUIRC_ERROR_DATA_OVERFLOW] = "Data overflow",
[QUIRC_ERROR_DATA_UNDERFLOW] = "Data underflow"
};
const char *quirc_strerror(quirc_decode_error_t err)
{
if (err >= 0 && err < sizeof(error_table) / sizeof(error_table[0]))
return error_table[err];
return "Unknown error";
}

165
source/quirc/quirc.h Normal file
View File

@@ -0,0 +1,165 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef QUIRC_H_
#define QUIRC_H_
#include <stdint.h>
struct quirc;
/* Obtain the library version string. */
const char *quirc_version(void);
/* Construct a new QR-code recognizer. This function will return NULL
* if sufficient memory could not be allocated.
*/
struct quirc *quirc_new(void);
/* Destroy a QR-code recognizer. */
void quirc_destroy(struct quirc *q);
/* Resize the QR-code recognizer. The size of an image must be
* specified before codes can be analyzed.
*
* This function returns 0 on success, or -1 if sufficient memory could
* not be allocated.
*/
int quirc_resize(struct quirc *q, int w, int h);
/* These functions are used to process images for QR-code recognition.
* quirc_begin() must first be called to obtain access to a buffer into
* which the input image should be placed. Optionally, the current
* width and height may be returned.
*
* After filling the buffer, quirc_end() should be called to process
* the image for QR-code recognition. The locations and content of each
* code may be obtained using accessor functions described below.
*/
uint8_t *quirc_begin(struct quirc *q, int *w, int *h);
void quirc_end(struct quirc *q);
/* This structure describes a location in the input image buffer. */
struct quirc_point {
int x;
int y;
};
/* This enum describes the various decoder errors which may occur. */
typedef enum {
QUIRC_SUCCESS = 0,
QUIRC_ERROR_INVALID_GRID_SIZE,
QUIRC_ERROR_INVALID_VERSION,
QUIRC_ERROR_FORMAT_ECC,
QUIRC_ERROR_DATA_ECC,
QUIRC_ERROR_UNKNOWN_DATA_TYPE,
QUIRC_ERROR_DATA_OVERFLOW,
QUIRC_ERROR_DATA_UNDERFLOW
} quirc_decode_error_t;
/* Return a string error message for an error code. */
const char *quirc_strerror(quirc_decode_error_t err);
/* Limits on the maximum size of QR-codes and their content. */
#define QUIRC_MAX_BITMAP 3917
#define QUIRC_MAX_PAYLOAD 8896
/* QR-code ECC types. */
#define QUIRC_ECC_LEVEL_M 0
#define QUIRC_ECC_LEVEL_L 1
#define QUIRC_ECC_LEVEL_H 2
#define QUIRC_ECC_LEVEL_Q 3
/* QR-code data types. */
#define QUIRC_DATA_TYPE_NUMERIC 1
#define QUIRC_DATA_TYPE_ALPHA 2
#define QUIRC_DATA_TYPE_BYTE 4
#define QUIRC_DATA_TYPE_KANJI 8
/* Common character encodings */
#define QUIRC_ECI_ISO_8859_1 1
#define QUIRC_ECI_IBM437 2
#define QUIRC_ECI_ISO_8859_2 4
#define QUIRC_ECI_ISO_8859_3 5
#define QUIRC_ECI_ISO_8859_4 6
#define QUIRC_ECI_ISO_8859_5 7
#define QUIRC_ECI_ISO_8859_6 8
#define QUIRC_ECI_ISO_8859_7 9
#define QUIRC_ECI_ISO_8859_8 10
#define QUIRC_ECI_ISO_8859_9 11
#define QUIRC_ECI_WINDOWS_874 13
#define QUIRC_ECI_ISO_8859_13 15
#define QUIRC_ECI_ISO_8859_15 17
#define QUIRC_ECI_SHIFT_JIS 20
#define QUIRC_ECI_UTF_8 26
/* This structure is used to return information about detected QR codes
* in the input image.
*/
struct quirc_code {
/* The four corners of the QR-code, from top left, clockwise */
struct quirc_point corners[4];
/* The number of cells across in the QR-code. The cell bitmap
* is a bitmask giving the actual values of cells. If the cell
* at (x, y) is black, then the following bit is set:
*
* cell_bitmap[i << 3] & (1 << (i & 7))
*
* where i = (y * size) + x.
*/
int size;
uint8_t cell_bitmap[QUIRC_MAX_BITMAP];
};
/* This structure holds the decoded QR-code data */
struct quirc_data {
/* Various parameters of the QR-code. These can mostly be
* ignored if you only care about the data.
*/
int version;
int ecc_level;
int mask;
/* This field is the highest-valued data type found in the QR
* code.
*/
int data_type;
/* Data payload. For the Kanji datatype, payload is encoded as
* Shift-JIS. For all other datatypes, payload is ASCII text.
*/
uint8_t payload[QUIRC_MAX_PAYLOAD];
int payload_len;
/* ECI assignment number */
uint32_t eci;
};
/* Return the number of QR-codes identified in the last processed
* image.
*/
int quirc_count(const struct quirc *q);
/* Extract the QR-code specified by the given index. */
void quirc_extract(const struct quirc *q, int index,
struct quirc_code *code);
/* Decode a QR-code, returning the payload data. */
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
struct quirc_data *data);
#endif

View File

@@ -0,0 +1,114 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef QUIRC_INTERNAL_H_
#define QUIRC_INTERNAL_H_
#include "quirc.h"
#define QUIRC_PIXEL_WHITE 0
#define QUIRC_PIXEL_BLACK 1
#define QUIRC_PIXEL_REGION 2
#ifndef QUIRC_MAX_REGIONS
#define QUIRC_MAX_REGIONS 254
#endif
#define QUIRC_MAX_CAPSTONES 32
#define QUIRC_MAX_GRIDS 8
#define QUIRC_PERSPECTIVE_PARAMS 8
#if QUIRC_MAX_REGIONS < UINT8_MAX
typedef uint8_t quirc_pixel_t;
#elif QUIRC_MAX_REGIONS < UINT16_MAX
typedef uint16_t quirc_pixel_t;
#else
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
#endif
struct quirc_region {
struct quirc_point seed;
int count;
int capstone;
};
struct quirc_capstone {
int ring;
int stone;
struct quirc_point corners[4];
struct quirc_point center;
double c[QUIRC_PERSPECTIVE_PARAMS];
int qr_grid;
};
struct quirc_grid {
/* Capstone indices */
int caps[3];
/* Alignment pattern region and corner */
int align_region;
struct quirc_point align;
/* Timing pattern endpoints */
struct quirc_point tpep[3];
int hscan;
int vscan;
/* Grid size and perspective transform */
int grid_size;
double c[QUIRC_PERSPECTIVE_PARAMS];
};
struct quirc {
uint8_t *image;
quirc_pixel_t *pixels;
int w;
int h;
int num_regions;
struct quirc_region regions[QUIRC_MAX_REGIONS];
int num_capstones;
struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES];
int num_grids;
struct quirc_grid grids[QUIRC_MAX_GRIDS];
};
/************************************************************************
* QR-code version information database
*/
#define QUIRC_MAX_VERSION 40
#define QUIRC_MAX_ALIGNMENT 7
struct quirc_rs_params {
int bs; /* Block size */
int dw; /* Data words */
int ce; /* Correctable errors */
};
struct quirc_version_info {
int data_bytes;
int apat[QUIRC_MAX_ALIGNMENT];
struct quirc_rs_params ecc[4];
};
extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1];
#endif

421
source/quirc/version_db.c Normal file
View File

@@ -0,0 +1,421 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "quirc_internal.h"
const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1] = {
{0},
{ /* Version 1 */
.data_bytes = 26,
.apat = {0},
.ecc = {
{.bs = 26, .dw = 16, .ce = 4},
{.bs = 26, .dw = 19, .ce = 2},
{.bs = 26, .dw = 9, .ce = 8},
{.bs = 26, .dw = 13, .ce = 6}
}
},
{ /* Version 2 */
.data_bytes = 44,
.apat = {6, 18, 0},
.ecc = {
{.bs = 44, .dw = 28, .ce = 8},
{.bs = 44, .dw = 34, .ce = 4},
{.bs = 44, .dw = 16, .ce = 14},
{.bs = 44, .dw = 22, .ce = 11}
}
},
{ /* Version 3 */
.data_bytes = 70,
.apat = {6, 22, 0},
.ecc = {
{.bs = 70, .dw = 44, .ce = 13},
{.bs = 70, .dw = 55, .ce = 7},
{.bs = 35, .dw = 13, .ce = 11},
{.bs = 35, .dw = 17, .ce = 9}
}
},
{ /* Version 4 */
.data_bytes = 100,
.apat = {6, 26, 0},
.ecc = {
{.bs = 50, .dw = 32, .ce = 9},
{.bs = 100, .dw = 80, .ce = 10},
{.bs = 25, .dw = 9, .ce = 8},
{.bs = 50, .dw = 24, .ce = 13}
}
},
{ /* Version 5 */
.data_bytes = 134,
.apat = {6, 30, 0},
.ecc = {
{.bs = 67, .dw = 43, .ce = 12},
{.bs = 134, .dw = 108, .ce = 13},
{.bs = 33, .dw = 11, .ce = 11},
{.bs = 33, .dw = 15, .ce = 9}
}
},
{ /* Version 6 */
.data_bytes = 172,
.apat = {6, 34, 0},
.ecc = {
{.bs = 43, .dw = 27, .ce = 8},
{.bs = 86, .dw = 68, .ce = 9},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 7 */
.data_bytes = 196,
.apat = {6, 22, 38, 0},
.ecc = {
{.bs = 49, .dw = 31, .ce = 9},
{.bs = 98, .dw = 78, .ce = 10},
{.bs = 39, .dw = 13, .ce = 13},
{.bs = 32, .dw = 14, .ce = 9}
}
},
{ /* Version 8 */
.data_bytes = 242,
.apat = {6, 24, 42, 0},
.ecc = {
{.bs = 60, .dw = 38, .ce = 11},
{.bs = 121, .dw = 97, .ce = 12},
{.bs = 40, .dw = 14, .ce = 13},
{.bs = 40, .dw = 18, .ce = 11}
}
},
{ /* Version 9 */
.data_bytes = 292,
.apat = {6, 26, 46, 0},
.ecc = {
{.bs = 58, .dw = 36, .ce = 11},
{.bs = 146, .dw = 116, .ce = 15},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 36, .dw = 16, .ce = 10}
}
},
{ /* Version 10 */
.data_bytes = 346,
.apat = {6, 28, 50, 0},
.ecc = {
{.bs = 69, .dw = 43, .ce = 13},
{.bs = 86, .dw = 68, .ce = 9},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 11 */
.data_bytes = 404,
.apat = {6, 30, 54, 0},
.ecc = {
{.bs = 80, .dw = 50, .ce = 15},
{.bs = 101, .dw = 81, .ce = 10},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 12 */
.data_bytes = 466,
.apat = {6, 32, 58, 0},
.ecc = {
{.bs = 58, .dw = 36, .ce = 11},
{.bs = 116, .dw = 92, .ce = 12},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 46, .dw = 20, .ce = 14}
}
},
{ /* Version 13 */
.data_bytes = 532,
.apat = {6, 34, 62, 0},
.ecc = {
{.bs = 59, .dw = 37, .ce = 11},
{.bs = 133, .dw = 107, .ce = 13},
{.bs = 33, .dw = 11, .ce = 11},
{.bs = 44, .dw = 20, .ce = 12}
}
},
{ /* Version 14 */
.data_bytes = 581,
.apat = {6, 26, 46, 66, 0},
.ecc = {
{.bs = 65, .dw = 41, .ce = 12},
{.bs = 109, .dw = 87, .ce = 11},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 15 */
.data_bytes = 655,
.apat = {6, 26, 48, 70, 0},
.ecc = {
{.bs = 65, .dw = 41, .ce = 12},
{.bs = 109, .dw = 87, .ce = 11},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 16 */
.data_bytes = 733,
.apat = {6, 26, 50, 74, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 122, .dw = 98, .ce = 12},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 17 */
.data_bytes = 815,
.apat = {6, 30, 54, 78, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 135, .dw = 107, .ce = 14},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 18 */
.data_bytes = 901,
.apat = {6, 30, 56, 82, 0},
.ecc = {
{.bs = 69, .dw = 43, .ce = 13},
{.bs = 150, .dw = 120, .ce = 15},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 19 */
.data_bytes = 991,
.apat = {6, 30, 58, 86, 0},
.ecc = {
{.bs = 70, .dw = 44, .ce = 13},
{.bs = 141, .dw = 113, .ce = 14},
{.bs = 39, .dw = 13, .ce = 13},
{.bs = 47, .dw = 21, .ce = 13}
}
},
{ /* Version 20 */
.data_bytes = 1085,
.apat = {6, 34, 62, 90, 0},
.ecc = {
{.bs = 67, .dw = 41, .ce = 13},
{.bs = 135, .dw = 107, .ce = 14},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 21 */
.data_bytes = 1156,
.apat = {6, 28, 50, 72, 92, 0},
.ecc = {
{.bs = 68, .dw = 42, .ce = 13},
{.bs = 144, .dw = 116, .ce = 14},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 22 */
.data_bytes = 1258,
.apat = {6, 26, 50, 74, 98, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 139, .dw = 111, .ce = 14},
{.bs = 37, .dw = 13, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 23 */
.data_bytes = 1364,
.apat = {6, 30, 54, 78, 102, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 24 */
.data_bytes = 1474,
.apat = {6, 28, 54, 80, 106, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 25 */
.data_bytes = 1588,
.apat = {6, 32, 58, 84, 110, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 132, .dw = 106, .ce = 13},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 26 */
.data_bytes = 1706,
.apat = {6, 30, 58, 86, 114, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 142, .dw = 114, .ce = 14},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 27 */
.data_bytes = 1828,
.apat = {6, 34, 62, 90, 118, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 53, .dw = 23, .ce = 15}
}
},
{ /* Version 28 */
.data_bytes = 1921,
.apat = {6, 26, 50, 74, 98, 122, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 29 */
.data_bytes = 2051,
.apat = {6, 30, 54, 78, 102, 126, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 146, .dw = 116, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 73, .dw = 45, .ce = 14}
}
},
{ /* Version 30 */
.data_bytes = 2185,
.apat = {6, 26, 52, 78, 104, 130, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 31 */
.data_bytes = 2323,
.apat = {6, 30, 56, 82, 108, 134, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 32 */
.data_bytes = 2465,
.apat = {6, 34, 60, 86, 112, 138, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 33 */
.data_bytes = 2611,
.apat = {6, 30, 58, 96, 114, 142, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 34 */
.data_bytes = 2761,
.apat = {6, 34, 62, 90, 118, 146, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 35 */
.data_bytes = 2876,
.apat = {6, 30, 54, 78, 102, 126, 150},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 36 */
.data_bytes = 3034,
.apat = {6, 24, 50, 76, 102, 128, 154},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 37 */
.data_bytes = 3196,
.apat = {6, 28, 54, 80, 106, 132, 158},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 38 */
.data_bytes = 3362,
.apat = {6, 32, 58, 84, 110, 136, 162},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 39 */
.data_bytes = 3532,
.apat = {6, 26, 54, 82, 110, 138, 166},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 40 */
.data_bytes = 3706,
.apat = {6, 30, 58, 86, 114, 142, 170},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 148, .dw = 118, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
}
};

View File

@@ -26,6 +26,126 @@
#include "splashes.h"
#include "unicode.h"
#include "fs.h"
#include "themes.h"
#include "pp2d/pp2d/pp2d.h"
#include "draw.h"
void load_splash_preview(Splash_s *splash)
{
//free the previously loaded preview. wont do anything if there wasnt one
pp2d_free_texture(TEXTURE_PREVIEW);
char *preview_buffer = NULL;
u64 size = 0;
if (!(splash->is_zip))
{
u16 path_to_preview[0x106] = {0};
strucat(path_to_preview, splash->path);
struacat(path_to_preview, "/preview.png");
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
} else {
size = zip_file_to_buf("preview.png", splash->path, &preview_buffer);
}
if (!size)
{
free(preview_buffer);
return;
}
u8 * image = NULL;
unsigned int width = 0, height = 0;
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
if (result == 0) // no error
{
for (u32 i = 0; i < width; i++)
{
for (u32 j = 0; j < height; j++)
{
u32 p = (i + j*width) * 4;
u8 r = *(u8*)(image + p);
u8 g = *(u8*)(image + p + 1);
u8 b = *(u8*)(image + p + 2);
u8 a = *(u8*)(image + p + 3);
*(image + p) = a;
*(image + p + 1) = b;
*(image + p + 2) = g;
*(image + p + 3) = r;
}
}
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
}
free(image);
free(preview_buffer);
}
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
{
char *info_buffer = NULL;
u64 size = 0;
if (!(splash->is_zip))
{
u16 path_to_smdh[0x106] = {0};
strucat(path_to_smdh, splash->path);
struacat(path_to_smdh, "/info.smdh");
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_smdh), ArchiveSD, &info_buffer);
} else {
size = zip_file_to_buf("info.smdh", splash->path, &info_buffer);
}
if (!size)
{
free(info_buffer);
memset(splash->name, 0, 0x80);
memset(splash->desc, 0, 0x100);
memset(splash->author, 0, 0x80);
memcpy(splash->name, splash_name, 0x80);
utf8_to_utf16(splash->desc, (u8*)"No description", 0x100);
utf8_to_utf16(splash->author, (u8*)"Unknown author", 0x80);
splash->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
return;
}
memcpy(splash->name, info_buffer + 0x08, 0x80);
memcpy(splash->desc, info_buffer + 0x88, 0x100);
memcpy(splash->author, info_buffer + 0x188, 0x80);
u16 *icon_data = malloc(0x1200);
memcpy(icon_data, info_buffer + 0x24C0, 0x1200);
const u32 width = 48, height = 48;
u32 *image = malloc(width*height*sizeof(u32));
for (u32 x = 0; x < width; x++)
{
for (u32 y = 0; y < height; y++)
{
unsigned int dest_pixel = (x + y*width);
unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3));
u8 r = ((icon_data[source_pixel] >> 11) & 0b11111) << 3;
u8 g = ((icon_data[source_pixel] >> 5) & 0b111111) << 2;
u8 b = (icon_data[source_pixel] & 0b11111) << 3;
u8 a = 0xFF;
image[dest_pixel] = (r << 24) | (g << 16) | (b << 8) | a;
}
}
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
splash->icon_id = textureID;
free(image);
free(icon_data);
free(info_buffer);
}
Result get_splashes(Splash_s** splashes_list, int *splash_count)
{
@@ -35,6 +155,13 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
if (R_FAILED(res))
return res;
if (*splashes_list != NULL)
{
free(*splashes_list);
*splashes_list = NULL;
*splash_count = 0;
}
u32 entries_read = 1;
while (entries_read)
{
@@ -43,7 +170,7 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
if (R_FAILED(res) || entries_read == 0)
break;
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY))
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(entry.shortExt, "ZIP"))
continue;
*splash_count += entries_read;
@@ -54,55 +181,90 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
Splash_s *current_splash = &(*splashes_list)[*splash_count-1];
memset(current_splash, 0, sizeof(Splash_s));
u16 splash_path[0x106] = {0};
u16 splash_path[0x106]= {0};
struacat(splash_path, SPLASHES_PATH);
strucat(splash_path, entry.name);
u16 top_path[0x106] = {0};
memcpy(top_path, splash_path, 0x106);
struacat(top_path, "/splash.bin");
u16 bottom_path[0x106] = {0};
memcpy(bottom_path, splash_path, 0x106);
struacat(bottom_path, "/splashbottom.bin");
char *temp_buf = NULL;
u32 bytes = file_to_buf(fsMakePath(PATH_UTF16, top_path), ArchiveSD, &temp_buf);
if (!bytes)
{
memset(top_path, 0, 0x106);
}
free(temp_buf);
temp_buf = NULL;
bytes = file_to_buf(fsMakePath(PATH_UTF16, bottom_path), ArchiveSD, &temp_buf);
if (!bytes)
{
memset(bottom_path, 0, 0x106);
}
free(temp_buf);
memcpy(current_splash->name, entry.name, 0x106);
memcpy(current_splash->top_path, top_path, 0x106);
memcpy(current_splash->bottom_path, bottom_path, 0x106);
char pathchar[0x106] = {0};
utf16_to_utf8((u8*) pathchar, splash_path, 0x106);
memcpy(current_splash->path, splash_path, 0x106 * sizeof(u16));
current_splash->is_zip = !strcmp(entry.shortExt, "ZIP");
ssize_t iconID = TEXTURE_PREVIEW + theme_count + *splash_count;
parse_smdh(current_splash, iconID, entry.name);
}
FSDIR_Close(dir_handle);
return res;
}
void splash_delete()
{
remove("/luma/splash.bin");
remove("/luma/splashbottom.bin");
}
void splash_install(Splash_s splash_to_install)
{
char *screen_buf;
u32 size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.top_path), ArchiveSD, &screen_buf);
if (size)
char *screen_buf = NULL;
u32 size = 0;
if (splash_to_install.is_zip)
{
remake_file("/luma/splash.bin", ArchiveSD, size);
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
free(screen_buf);
size = zip_file_to_buf("splash.bin", splash_to_install.path, &screen_buf);
if (size)
{
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
free(screen_buf);
screen_buf = NULL;
size = 0;
}
size = zip_file_to_buf("splashbottom.bin", splash_to_install.path, &screen_buf);
if (size)
{
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
free(screen_buf);
screen_buf = NULL;
size = 0;
}
} else {
u16 path[0x106] = {0};
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
struacat(path, "/splash.bin");
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
if (size)
{
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
free(screen_buf);
screen_buf = NULL;
size = 0;
}
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
struacat(path, "/splashbottom.bin");
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
if (size)
{
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
free(screen_buf);
screen_buf = NULL;
size = 0;
}
}
size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.bottom_path), ArchiveSD, &screen_buf);
char *config_buf;
size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/config.bin"), ArchiveSD, &config_buf);
if (size)
{
remake_file("/luma/splashbottom.bin", ArchiveSD, size);
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
free(screen_buf);
if (config_buf[0xC] == 0)
{
free(config_buf);
throw_error("WARNING: Splashes are disabled in Luma Config", WARNING);
}
}
}

View File

@@ -27,6 +27,7 @@
#include "themes.h"
#include "unicode.h"
#include "fs.h"
#include <time.h>
#include "pp2d/pp2d/pp2d.h"
#include "pp2d/pp2d/lodepng.h"
@@ -87,7 +88,7 @@ void load_theme_preview(Theme_s *theme)
free(preview_buffer);
}
static void parse_smdh(Theme_s *theme, ssize_t textureID)
static void parse_smdh(Theme_s *theme, ssize_t textureID, u16 *dir_name)
{
char *info_buffer = NULL;
u64 size = 0;
@@ -105,6 +106,13 @@ static void parse_smdh(Theme_s *theme, ssize_t textureID)
if (!size)
{
free(info_buffer);
memset(theme->name, 0, 0x80);
memset(theme->desc, 0, 0x100);
memset(theme->author, 0, 0x80);
memcpy(theme->name, dir_name, 0x80);
utf8_to_utf16(theme->desc, (u8*)"No description", 0x100);
utf8_to_utf16(theme->author, (u8*)"Unknown author", 0x80);
theme->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
return;
}
@@ -134,7 +142,6 @@ static void parse_smdh(Theme_s *theme, ssize_t textureID)
}
}
theme->has_icon = true;
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
theme->icon_id = textureID;
@@ -151,7 +158,15 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
if (R_FAILED(res))
return res;
if (*themes_list != NULL) //used for QR reading and also for theme deletion
{
free(*themes_list);
*themes_list = NULL;
*theme_count = 0;
}
u32 entries_read = 1;
while (entries_read)
{
FS_DirectoryEntry entry = {0};
@@ -181,7 +196,7 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
current_theme->is_zip = !strcmp(entry.shortExt, "ZIP");
ssize_t iconID = TEXTURE_PREVIEW + *theme_count;
parse_smdh(current_theme, iconID);
parse_smdh(current_theme, iconID, entry.name);
}
FSDIR_Close(dir_handle);
@@ -189,6 +204,20 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
return res;
}
void del_theme(u16 *path)
{
Handle dir_handle;
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_UTF16, path));
if (R_SUCCEEDED(res))
{
FSDIR_Close(dir_handle);
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, path));
} else
{
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, path));
}
}
Result bgm_install(Theme_s bgm_to_install)
{
char *savedata_buf;
@@ -202,9 +231,11 @@ Result bgm_install(Theme_s bgm_to_install)
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff;
u32 size = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if (!R_SUCCEEDED(result)) return result;
if (bgm_to_install.is_zip) // Same as above but this time with bgm
{
music_size = zip_file_to_buf("bgm.bcstm", bgm_to_install.path, &music);
@@ -217,7 +248,6 @@ Result bgm_install(Theme_s bgm_to_install)
if (music_size == 0)
{
free(music);
music = calloc(1, 3371008);
} else if (music_size > 3371008) {
free(music);
@@ -225,10 +255,10 @@ Result bgm_install(Theme_s bgm_to_install)
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
}
size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
free(music);
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
if (!R_SUCCEEDED(result)) return result;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1;
@@ -252,9 +282,11 @@ Result bgm_install(Theme_s bgm_to_install)
memset(&thememanage_buf[0x340], 0, 4);
memset(&thememanage_buf[0x360], 0, 4);
memset(&thememanage_buf[0x368], 0, 4);
size = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if (!R_SUCCEEDED(result)) return result;
return 0;
}
@@ -274,9 +306,11 @@ Result single_install(Theme_s theme_to_install)
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff;
u32 size = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if (!R_SUCCEEDED(result)) return result;
// Open body cache file. Test if theme is zipped
if (theme_to_install.is_zip)
{
@@ -297,10 +331,10 @@ Result single_install(Theme_s theme_to_install)
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
}
size = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
result = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
free(body);
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
if (!R_SUCCEEDED(result)) return result;
if (theme_to_install.is_zip) // Same as above but this time with bgm
{
@@ -314,7 +348,6 @@ Result single_install(Theme_s theme_to_install)
if (music_size == 0)
{
free(music);
music = calloc(1, 3371008);
} else if (music_size > 3371008) {
free(music);
@@ -322,10 +355,10 @@ Result single_install(Theme_s theme_to_install)
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
}
size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
free(music);
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
if (!R_SUCCEEDED(result)) return result;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1;
@@ -351,9 +384,11 @@ Result single_install(Theme_s theme_to_install)
memset(&thememanage_buf[0x340], 0, 4);
memset(&thememanage_buf[0x360], 0, 4);
memset(&thememanage_buf[0x368], 0, 4);
size = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if (!R_SUCCEEDED(result)) return result;
return 0;
}
@@ -365,10 +400,11 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
u32 bgm_sizes[10] = {0};
for (int i = 0; i < theme_count; i++)
{
if (count > 9) return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
if (count > 10) return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
if (themes_list[i].in_shuffle)
{
shuffle_themes[count++] = &themes_list[i];
themes_list[i].in_shuffle = false;
}
}
for (int i = 0; i < count; i++)
@@ -398,9 +434,11 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
}
}
buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
Result result = buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if (!R_SUCCEEDED(result)) return result;
remake_file("/BodyCache_rd.bin", ArchiveThemeExt, 0x150000 * 10); // Enough space for 10 theme files
Handle body_cache_handle;
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
@@ -497,8 +535,10 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
*bgmsizeloc = bgm_sizes[i];
}
buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if (!R_SUCCEEDED(result)) return result;
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_COMMON, RD_SUCCESS);
}