Slightly improve QR code speed

This commit is contained in:
2017-09-08 23:26:49 -04:00
parent d3aa231c3f
commit 97ab2307f8
6 changed files with 56 additions and 59 deletions

View File

@@ -49,7 +49,7 @@ 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)

View File

@@ -29,8 +29,6 @@
#include "common.h"
struct quirc* context;
u16 *buf;
bool qr_mode;
void init_qr(void);

View File

@@ -35,7 +35,6 @@ void init_screens(void);
void exit_screens(void);
void draw_themext_error(void);
void draw_qr(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, int shuffle_theme_count);

View File

@@ -30,9 +30,11 @@
#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)
{
@@ -47,8 +49,6 @@ void init_qr(void)
CAMU_SetTrimming(PORT_CAM1, false);
CAMU_SetTrimming(PORT_CAM2, false);
buf = malloc(sizeof(u16) * 400 * 240 * 2);
CAMU_GetMaxBytes(&transfer_size, 400, 240);
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
@@ -69,14 +69,65 @@ void exit_qr(void)
CAMU_Activate(SELECT_NONE);
camExit();
quirc_destroy(context);
free(buf);
}
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, "/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);
CAMU_StopCapture(PORT_BOTH);
CAMU_Activate(SELECT_NONE);
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_end_draw();
free(rgba8_buf);
pp2d_free_texture(TEXTURE_QR);
scan_qr(buf);
free(buf);
CAMU_Activate(SELECT_OUT1_OUT2);
CAMU_StartCapture(PORT_BOTH);
}
/*

View File

@@ -73,57 +73,6 @@ void draw_themext_error(void)
throw_error("Theme extdata does not exist\nSet a default theme from the home menu", ERROR);
}
void draw_qr(void)
{
take_picture();
pp2d_begin_draw(GFX_TOP);
pp2d_free_texture(TEXTURE_QR);
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
for (int i = 0; i < 240 * 400; i++)
{
rgba8_buf[i] = RGB565_TO_RGBA8(buf[i]);
u8 *byte_pointer = (u8*)&rgba8_buf[i];
u8 r = *(byte_pointer+3);
u8 g = *(byte_pointer+2);
u8 b = *(byte_pointer+1);
u8 a = *(byte_pointer);
rgba8_buf[i] = RGBA8(r, g, b, a);
}
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
pp2d_draw_texture(TEXTURE_QR, 0, 0);
free(rgba8_buf);
pp2d_end_draw();
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, "/Themes/");
}
}
}
void draw_base_interface(void)
{
pp2d_begin_draw(GFX_TOP);

View File

@@ -105,7 +105,7 @@ int main(void)
if (qr_mode)
{
draw_qr();
take_picture();
} else if (!splash_mode)
{
draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode, shuffle_theme_count);