Skip to content

Commit

Permalink
Fix Stories JPG issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck ALARY committed Nov 11, 2023
1 parent 2e06cb6 commit c98d7f2
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###########################################################

TARGET=Telmi Story Teller
VERSION=0.2.1
VERSION=0.2.2

###########################################################

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The story teller is compatible with stories exported from STUdio (v1 format).

### Download the installation files

You need to install Telmi v0.2.1.
You need to install Telmi v0.2.2.

- [Download the latest version of Telmi](https://github.com/DantSu/Telmi-story-teller/releases/download/0.2.1/TelmiOS_v0.2.1.zip)
- [Download the latest version of Telmi](https://github.com/DantSu/Telmi-story-teller/releases/download/0.2.2/TelmiOS_v0.2.2.zip)

### Install or upgrade

Expand Down
2 changes: 0 additions & 2 deletions src/bootScreen/bootScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ int main(int argc, char *argv[])
sleep(4); // for debugging purposes
#endif

sleep(1);

SDL_FreeSurface(screen);
SDL_FreeSurface(video);
SDL_Quit();
Expand Down
2 changes: 1 addition & 1 deletion src/storyTeller/app_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#define SYSTEM_RESOURCES "/mnt/SDCARD/.tmp_update/res/"
static const char appImages[2][32] = {"selectStories.png", "selectMusic.png"};
static char appImages[2][32] = {"selectStories.png", "selectMusic.png"};

static int appIndex = 0;
static bool appOpened = false;
Expand Down
2 changes: 1 addition & 1 deletion src/storyTeller/music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool musicplayer_home(void)

bool musicplayer_isMp3File(const char *fileName)
{
return strcmp((char *)fileName + strlen(fileName) - 4, ".mp3") == 0;
return strcmp((char *)fileName + strlen(fileName) - 4, ".mp3") == 0 || strcmp((char *)fileName + strlen(fileName) - 4, ".MP3") == 0;
}

void musicplayer_init(void)
Expand Down
49 changes: 34 additions & 15 deletions src/storyTeller/sdl_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,32 @@ static TTF_Font *font;
static SDL_Color color = {255, 255, 255};
static int fontPosition = 0;


void font_write(const char *text)
{
SDL_Surface *sdlText = TTF_RenderUTF8_Blended(font, text, color);
if (sdlText) {
fontPosition += 16;
SDL_BlitSurface(sdlText, NULL, screen, &(SDL_Rect){20, fontPosition});
SDL_FreeSurface(sdlText);
SDL_BlitSurface(screen, NULL, video, NULL);
SDL_Flip(video);
}
}


void video_audio_init(void)
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
IMG_Init(IMG_INIT_PNG);
TTF_Init();
if(Mix_OpenAudio(44000, 32784, 2, 2048) < 0) {
Mix_Volume(-1, MIX_MAX_VOLUME);
Mix_VolumeMusic(MIX_MAX_VOLUME);
}
video = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
screen = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 480, 32, 0, 0, 0, 0);
font = TTF_OpenFont(FALLBACK_FONT, 18);
font = TTF_OpenFont(FALLBACK_FONT, 14);
}


Expand All @@ -47,8 +62,25 @@ void video_audio_quit(void)
SDL_Quit();
}

void video_displayImage(const char *dir, const char *name)
void video_checkFilename(char *filename)
{
int length = strlen(filename);
if(strcmp((char *)filename + length - 4, ".jpg") == 0 || strcmp((char *)filename + length - 4, ".JPG") == 0) {
filename[length - 3] = 'p';
filename[length - 2] = 'n';
filename[length - 1] = 'g';
} else if (strcmp((char *)filename + length - 5, ".jpeg") == 0 || strcmp((char *)filename + length - 5, ".JPEG") == 0) {
filename[length - 4] = 'p';
filename[length - 3] = 'n';
filename[length - 2] = 'g';
filename[length - 1] = '\0';
}
}

void video_displayImage(const char *dir, char *name)
{
video_checkFilename(name);

char image_path[STR_MAX * 2];
sprintf(image_path, "%s%s", dir, name);
SDL_Surface *image = IMG_Load(image_path);
Expand Down Expand Up @@ -79,17 +111,4 @@ void audio_play(const char *dir, const char *name) {
}


void font_write(const char *text)
{
SDL_Surface *sdlText = TTF_RenderUTF8_Blended(font, text, color);
if (sdlText) {
fontPosition += 20;
SDL_BlitSurface(sdlText, NULL, screen, &(SDL_Rect){20, fontPosition});
SDL_FreeSurface(sdlText);
SDL_BlitSurface(screen, NULL, video, NULL);
SDL_Flip(video);
}
}


#endif // STORYTELLER_SDL_HELPER__
4 changes: 2 additions & 2 deletions src/storyTeller/stories_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ void stories_load(void)
} else if (storyIndex >= storiesCount) {
storyIndex = 0;
}

char story_path[STR_MAX];
sprintf(story_path, "%s%s/story.json", STORIES_RESOURCES, storiesList[storyIndex]);

storyJson = json_load(story_path);
if(storyJson == NULL) {
return;
}

stories_readStage();
}

Expand Down
30 changes: 19 additions & 11 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,14 @@ main() {
cd $sysdir
bootScreen "Boot"

# Start the key monitor
# keymon &

# Init
rm /tmp/.offOrder 2> /dev/null
HOME=/mnt/SDCARD/StoryTeller/

# Detect if MENU button is held
# detectKey 1
# menu_pressed=$?

# if [ $menu_pressed -eq 0 ]; then
# rm -f "$sysdir/cmd_to_run.sh" 2> /dev/null
# fi

storyteller_jpg2png

# start_networking
sleep 1
rm -rf /tmp/is_booting

launch_storyteller
Expand All @@ -71,6 +63,22 @@ main() {
done
}

storyteller_jpg2png() {
for directory in /mnt/SDCARD/Stories/*; do
if [ ! -d "$directory" ]; then
continue
fi

for file in "$directory"/assets/*.jpg "$directory"/assets/*.jpeg "$directory"/assets/*.JPG "$directory"/assets/*.JPEG; do
if [ ! -f "$file" ]; then
continue
fi
jpg2png "$file"
rm -f "$file" 2> /dev/null
done
done
}

set_prev_state() {
echo "$1" > /tmp/prev_state
}
Expand Down

0 comments on commit c98d7f2

Please sign in to comment.