Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24810a48ad | |||
|
|
5d2119344a | ||
|
|
492ea13ef6 | ||
|
|
f99f744000 | ||
| 4fb10029bb | |||
| 7644974705 | |||
|
|
b7379af2f3 | ||
| 26d8c283b3 | |||
| 4ceac06f0c | |||
| 337693ca13 | |||
| 8ba1fed5d7 | |||
|
|
d99f1c97a0 | ||
|
|
1a1b3e25b0 | ||
| c92c20d4e8 | |||
| ef456c7e9e | |||
| 1103885baf | |||
| 5564ffe31b | |||
| 97ab2307f8 | |||
|
|
47c64828a4 | ||
| d3aa231c3f | |||
|
|
3fb86c80be | ||
|
|
67566330a5 | ||
| 68805337bf | |||
|
|
416cca88d3 | ||
| 2be3bde64d | |||
| c46c5ff8cb | |||
|
|
6b5b391d7b | ||
|
|
dc1cbda232 | ||
|
|
e63a4066a1 | ||
| 2e71fc5954 | |||
| 778e1a8331 | |||
| 0871f4f30b | |||
| 62f4356a17 | |||
|
|
3e2c5994ca | ||
|
|
674fa9d9bf | ||
|
|
897dc52424 | ||
|
|
379cea8db1 | ||
|
|
e46783a3c4 | ||
|
|
3fd4548d64 | ||
|
|
34ede05b93 | ||
|
|
80b9aa9cdb | ||
|
|
33cce81914 | ||
|
|
424fffd35f | ||
|
|
5b067cfac0 | ||
|
|
539e95253c | ||
|
|
a77b29da92 | ||
|
|
dcac5401c1 | ||
|
|
1467b1f72b | ||
|
|
9199936215 | ||
|
|
91fa4fa412 | ||
|
|
1c6ae493d5 | ||
|
|
4eb969e84d | ||
|
|
70a40fae44 | ||
|
|
3d17509229 | ||
|
|
a38508c30f | ||
|
|
0ddb35d3d7 | ||
|
|
e03d150840 | ||
|
|
4607885fe6 | ||
|
|
d3a8f79958 | ||
|
|
a08c032ccc | ||
|
|
bdaa8b52cc | ||
|
|
8dc7f54f7e | ||
| 04ebe9e498 | |||
| 02526707a0 | |||
|
|
494962dc88 | ||
|
|
d0979126f7 | ||
|
|
57c4da7614 | ||
| 9ab442c598 | |||
| 03497a79ef | |||
|
|
1433002082 | ||
|
|
242f10ec0a | ||
|
|
292c100480 | ||
|
|
cca45bff0f | ||
|
|
630cc41759 | ||
| 5fc499ff78 | |||
| 3241544296 | |||
| 7aed454297 | |||
|
|
c539fa239c | ||
|
|
b7d15da092 | ||
|
|
9a34a17fe8 | ||
| 4084408562 |
8
Makefile
@@ -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
|
||||
|
||||
|
||||
15
README.md
@@ -1,12 +1,17 @@
|
||||

|
||||
|
||||
A Theme and Splashscreen Manager for the Nintendo3DS, written in C
|
||||
A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.\
|
||||
To-do list here: https://trello.com/b/F1YSa1VK
|
||||
|
||||
# Dependencies
|
||||
* zlib, which can be retrieved from the [3ds_portlibs](https://github.com/devkitPro/3ds_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.
|
||||
|
||||
@@ -19,10 +24,10 @@ The following people contributed to Anemone3DS in some way. Without these people
|
||||
|
||||
Special thanks go to these people who, while not directly contributing, helped immensely:
|
||||
* [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
|
||||
* [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 and minizip.
|
||||
* 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](https://discord.gg/C29hYvh)
|
||||
|
||||
39
include/camera.h
Normal 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
|
||||
@@ -40,9 +40,16 @@
|
||||
#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;
|
||||
int shuffle_theme_count;
|
||||
|
||||
enum TextureID {
|
||||
TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font
|
||||
TEXTURE_ARROW,
|
||||
@@ -53,6 +60,7 @@ enum TextureID {
|
||||
TEXTURE_BATTERY_4,
|
||||
TEXTURE_BATTERY_5,
|
||||
TEXTURE_BATTERY_CHARGE,
|
||||
TEXTURE_QR,
|
||||
TEXTURE_PREVIEW,
|
||||
};
|
||||
|
||||
|
||||
@@ -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_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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -30,11 +30,11 @@
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
u16 name[0x40];
|
||||
u16 desc[0x80];
|
||||
u16 author[0x40];
|
||||
u16 name[0x41];
|
||||
u16 desc[0x81];
|
||||
u16 author[0x41];
|
||||
|
||||
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);
|
||||
|
||||
BIN
meta/banner.png
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
meta/icon.png
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
BIN
romfs/arrow.png
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 271 B |
|
Before Width: | Height: | Size: 285 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 800 B After Width: | Height: | Size: 806 B |
|
Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 466 B |
280
source/camera.c
Normal 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;
|
||||
}
|
||||
121
source/draw.c
@@ -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)
|
||||
@@ -63,6 +68,11 @@ void exit_screens(void)
|
||||
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);
|
||||
@@ -87,22 +97,60 @@ void draw_base_interface(void)
|
||||
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;
|
||||
@@ -110,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;
|
||||
}
|
||||
@@ -137,16 +187,16 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
|
||||
{
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Theme mode");
|
||||
wchar_t title[0x40] = {0};
|
||||
wchar_t title[0x41] = {0};
|
||||
utf16_to_utf32((u32*)title, current_theme.name, 0x40);
|
||||
pp2d_draw_wtext(20, 30, 0.7, 0.7, COLOR_WHITE, title);
|
||||
wchar_t author[0x40] = {0};
|
||||
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
|
||||
wchar_t author[0x41] = {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};
|
||||
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
|
||||
wchar_t description[0x81] = {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(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");
|
||||
@@ -154,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++) {
|
||||
@@ -198,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);
|
||||
@@ -215,10 +269,10 @@ void draw_splash_install(int install_type)
|
||||
switch (install_type)
|
||||
{
|
||||
case SINGLE_INSTALL:
|
||||
pp2d_draw_textf(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
|
||||
break;
|
||||
case UNINSTALL:
|
||||
pp2d_draw_textf(20, 30, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -230,23 +284,39 @@ 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, 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, 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++) {
|
||||
if (splash_count <= THEMES_PER_SCREEN)
|
||||
@@ -283,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();
|
||||
|
||||
23
source/fs.c
@@ -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)
|
||||
|
||||
167
source/main.c
@@ -29,13 +29,32 @@
|
||||
#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();
|
||||
ptmuInit();
|
||||
open_archives();
|
||||
return 0;
|
||||
acInit();
|
||||
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)
|
||||
@@ -43,16 +62,19 @@ int exit_services(void)
|
||||
close_archives();
|
||||
cfguExit();
|
||||
ptmuExit();
|
||||
httpcExit();
|
||||
acExit();
|
||||
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))
|
||||
{
|
||||
@@ -60,8 +82,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))
|
||||
{
|
||||
@@ -70,30 +92,70 @@ 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;
|
||||
int shuffle_theme_count = 0;
|
||||
shuffle_theme_count = 0;
|
||||
bool preview_mode = false;
|
||||
|
||||
while(aptMainLoop())
|
||||
{
|
||||
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)
|
||||
{
|
||||
APT_HardwareResetAsync();
|
||||
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 {
|
||||
u32 out;
|
||||
ACU_GetWifiStatus(&out);
|
||||
if (out)
|
||||
{
|
||||
qr_mode = !qr_mode;
|
||||
if (qr_mode) init_qr();
|
||||
else exit_qr();
|
||||
continue;
|
||||
} else {
|
||||
throw_error("Please connect to Wi-Fi before scanning QR", WARNING);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qr_mode) continue;
|
||||
|
||||
if (themes_list == NULL && !splash_mode)
|
||||
continue;
|
||||
|
||||
@@ -107,10 +169,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;
|
||||
@@ -142,6 +210,13 @@ int main(void)
|
||||
draw_theme_install(SINGLE_INSTALL);
|
||||
single_install(*current_theme);
|
||||
}
|
||||
//these are here just so I don't forget how to implement them - HM
|
||||
//if (current_theme->in_shuffle) {
|
||||
// shuffle_theme_count--;
|
||||
// current_theme->in_shuffle = false;
|
||||
//}
|
||||
//del_theme(current_theme->path);
|
||||
//get_themes(&themes_list, &theme_count);
|
||||
}
|
||||
|
||||
else if (kDown & KEY_B)
|
||||
@@ -174,6 +249,7 @@ int main(void)
|
||||
{
|
||||
draw_theme_install(SHUFFLE_INSTALL);
|
||||
shuffle_install(themes_list, theme_count);
|
||||
shuffle_theme_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,6 +304,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)
|
||||
{
|
||||
@@ -235,4 +368,8 @@ int main(void)
|
||||
previously_selected = selected_theme;
|
||||
}
|
||||
}
|
||||
exit_screens();
|
||||
exit_services();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
918
source/quirc/decode.c
Normal 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
91
source/quirc/quirc.c
Normal 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
@@ -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
|
||||
114
source/quirc/quirc_internal.h
Normal 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
@@ -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}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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,59 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
@@ -111,6 +112,7 @@ static void parse_smdh(Theme_s *theme, ssize_t textureID, u16 *dir_name)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -140,7 +142,6 @@ static void parse_smdh(Theme_s *theme, ssize_t textureID, u16 *dir_name)
|
||||
}
|
||||
}
|
||||
|
||||
theme->has_icon = true;
|
||||
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
|
||||
theme->icon_id = textureID;
|
||||
|
||||
@@ -151,13 +152,22 @@ static void parse_smdh(Theme_s *theme, ssize_t textureID, u16 *dir_name)
|
||||
|
||||
Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
{
|
||||
shuffle_theme_count = 0;
|
||||
Result res = 0;
|
||||
Handle dir_handle;
|
||||
res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, THEMES_PATH));
|
||||
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};
|
||||
@@ -195,6 +205,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;
|
||||
@@ -208,9 +232,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);
|
||||
@@ -223,7 +249,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);
|
||||
@@ -231,10 +256,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;
|
||||
@@ -258,9 +283,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;
|
||||
}
|
||||
|
||||
@@ -280,9 +307,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)
|
||||
{
|
||||
@@ -303,10 +332,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
|
||||
{
|
||||
@@ -320,7 +349,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);
|
||||
@@ -328,10 +356,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;
|
||||
@@ -357,9 +385,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;
|
||||
}
|
||||
|
||||
@@ -371,10 +401,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++)
|
||||
@@ -404,9 +435,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);
|
||||
@@ -503,8 +536,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);
|
||||
}
|
||||
|
||||