Skip to content

Commit

Permalink
enhancement: replaced nanojpeg with turbojpeg library (switchbrew#65) (
Browse files Browse the repository at this point in the history
…Closes switchbrew#7)

* enhancement: replaced nanojpeg with turbojpeg library
* added space after if ()
  • Loading branch information
NightlyFox authored and yellows8 committed Sep 30, 2018
1 parent d39efda commit 1c8a446
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1,008 deletions.
2 changes: 1 addition & 1 deletion Makefile.nx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := `freetype-config --libs` -lconfig
LIBS := `freetype-config --libs` -lconfig -lturbojpeg

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
4 changes: 2 additions & 2 deletions Makefile.pc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ endef
test : pc_main/main.cpp pc_main/pc_launch.c \
common/menu.c common/font.c common/language.c common/launch.c \
common/menu-entry.c common/menu-list.c common/message-box.c common/text.c \
common/nanojpeg.c common/ui.c common/math.c common/theme.c \
common/ui.c common/math.c common/theme.c \
common/netloader.c \
build_pc/invalid_icon.bin.o build_pc/folder_icon.bin.o \
build_pc/hbmenu_logo_light.bin.o build_pc/hbmenu_logo_dark.bin.o \
build_pc/theme_icon_dark.bin.o build_pc/theme_icon_light.bin.o \
#build_pc/tahoma24.o build_pc/tahoma12.o build_pc/interuimedium20.o build_pc/interuimedium30.o build_pc/interuiregular14.o build_pc/interuiregular18.o
gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@
gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig -lturbojpeg $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@

build_pc/tahoma12.o : data/tahoma12.nxfnt
mkdir -p $(dir $@)
Expand Down
2 changes: 1 addition & 1 deletion common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef union {
#include "text.h"
#include "ui.h"
#include "launch.h"
#include "nanojpeg.h"
#include <turbojpeg.h>
#include "math.h"
#include "theme.h"
#include "message-box.h"
Expand Down
45 changes: 23 additions & 22 deletions common/menu-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
*author = textGetString(StrId_DefaultPublisher),
*version = "1.0.0";

if(config_read_file(&cfg, me->path)) {
if (config_read_file(&cfg, me->path)) {
themeInfo = config_lookup(&cfg, "themeInfo");
if (themeInfo != NULL) {
if(config_setting_lookup_string(themeInfo, "name", &name))
Expand All @@ -322,42 +322,43 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
}

void menuEntryParseIcon(menuEntry_s* me) {
uint8_t *imageptr = NULL;
size_t imagesize = 256*256*3;

if (me->icon_size==0 || me->icon==NULL) return;

njInit();
int w,h,samp;
size_t imagesize = 256*256*3;
me->icon_gfx = (uint8_t*)malloc(imagesize);

if (njDecode(me->icon, me->icon_size) != NJ_OK) {
njDone();
return;
}
if (me->icon_gfx == NULL) return;

me->icon_size = 0;
free(me->icon);
me->icon = NULL;
tjhandle _jpegDecompressor = tjInitDecompress();

if ((njGetWidth() != 256 || njGetHeight() != 256 || (size_t)njGetImageSize() != imagesize) || njIsColor() != 1) {//The decoded image must be RGB and 256x256.
njDone();
if (_jpegDecompressor == NULL) {
free(me->icon_gfx);
me->icon_gfx = NULL;
return;
}

imageptr = njGetImage();
if (imageptr == NULL) {
njDone();
if (tjDecompressHeader2(_jpegDecompressor, me->icon, me->icon_size, &w, &h, &samp) == -1) {
free(me->icon_gfx);
me->icon_gfx = NULL;
tjDestroy(_jpegDecompressor);
return;
}

me->icon_gfx = (uint8_t*)malloc(imagesize);
if (me->icon_gfx == NULL) {
njDone();
if (w != 256 || h != 256 ) return;

if (tjDecompress2(_jpegDecompressor, me->icon, me->icon_size, me->icon_gfx, w, 0, h, TJPF_RGB, TJFLAG_ACCURATEDCT) == -1) {
free(me->icon_gfx);
me->icon_gfx = NULL;
tjDestroy(_jpegDecompressor);
return;
}

memcpy(me->icon_gfx, imageptr, imagesize);
me->icon_size = 0;
free(me->icon);
me->icon = NULL;

njDone();
tjDestroy(_jpegDecompressor);

me->icon_gfx_small = downscaleImg(me->icon_gfx, 256, 256, 140, 140, IMAGE_MODE_RGB24);
}
Expand Down
Loading

0 comments on commit 1c8a446

Please sign in to comment.