enhancement: replaced nanojpeg with turbojpeg library

This commit is contained in:
NightlyFox 2018-09-29 13:56:13 -05:00
parent 69e11599f4
commit 61da97a657
4 changed files with 15 additions and 24 deletions

View File

@ -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

View File

@ -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 $@)

View File

@ -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"

View File

@ -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);
}