From 61da97a6572c7cdca6a2cf916c5bf7cc3d87f2e7 Mon Sep 17 00:00:00 2001 From: NightlyFox Date: Sat, 29 Sep 2018 13:56:13 -0500 Subject: [PATCH] enhancement: replaced nanojpeg with turbojpeg library --- Makefile.nx | 2 +- Makefile.pc | 2 +- common/common.h | 2 +- common/menu-entry.c | 33 ++++++++++++--------------------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Makefile.nx b/Makefile.nx index f86a0c0..386eea4 100644 --- a/Makefile.nx +++ b/Makefile.nx @@ -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 diff --git a/Makefile.pc b/Makefile.pc index 3e3d415..42145ba 100644 --- a/Makefile.pc +++ b/Makefile.pc @@ -27,7 +27,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c \ 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 $@) diff --git a/common/common.h b/common/common.h index 0207f37..35bcbfa 100644 --- a/common/common.h +++ b/common/common.h @@ -54,7 +54,7 @@ typedef union { #include "text.h" #include "ui.h" #include "launch.h" -#include "nanojpeg.h" +#include #include "math.h" #include "theme.h" #include "message-box.h" diff --git a/common/menu-entry.c b/common/menu-entry.c index f783807..57b6d5c 100644 --- a/common/menu-entry.c +++ b/common/menu-entry.c @@ -322,42 +322,33 @@ 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; + unsigned char imageptr[imagesize]; + int w,h,samp; if (me->icon_size==0 || me->icon==NULL) return; - njInit(); + tjhandle _jpegDecompressor = tjInitDecompress(); - if (njDecode(me->icon, me->icon_size) != NJ_OK) { - njDone(); + if(tjDecompressHeader2(_jpegDecompressor, me->icon, me->icon_size, &w, &h, &samp)==-1) return; + + if (w != 256 || h != 256 ) return; //The decoded image must be 256x256. + + if(tjDecompress2(_jpegDecompressor, me->icon, me->icon_size, imageptr, w, 0/*pitch*/, h, TJPF_RGB, TJFLAG_ACCURATEDCT)==-1)//The decoded image must be RGB return; - } me->icon_size = 0; free(me->icon); me->icon = NULL; - if ((njGetWidth() != 256 || njGetHeight() != 256 || (size_t)njGetImageSize() != imagesize) || njIsColor() != 1) {//The decoded image must be RGB and 256x256. - njDone(); - return; - } - - imageptr = njGetImage(); - if (imageptr == NULL) { - njDone(); - return; - } + if (imageptr[0] == 0) return; me->icon_gfx = (uint8_t*)malloc(imagesize); - if (me->icon_gfx == NULL) { - njDone(); - return; - } + + if (me->icon_gfx == NULL) return; memcpy(me->icon_gfx, imageptr, imagesize); - - njDone(); + tjDestroy(_jpegDecompressor); me->icon_gfx_small = downscaleImg(me->icon_gfx, 256, 256, 140, 140, IMAGE_MODE_RGB24); }