slideshow with sdl2 plus ken burns effect

User projects written in or related to FreeBASIC.
Post Reply
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

slideshow with sdl2 plus ken burns effect

Post by thrive4 »

description
More of a mini app then a project never the less
a 'meat and potato' slideshow with sdl2 and sdl2_image.

Effects include a pan scan zoom aka the
'ken burns' effect plus fade in and cross fade.
Special support for .mp3 this will extract the
cover art from a mp3 and display it if present.

The slideshow has most of the basics in terms of navigation:
f11 : toggle fullscreen
esc : close application

Other basic features are:
- generates a playlist from a folder
- supports most common imagetypes .bmp, .gif, .jpg, .png, .pcx, .jpeg, .tff
> plus .mp3 coverart only
- if present cover art is extracted from mp3 and
> written to a thumb file (thumb.jpg or thumb.png)
- minimal configuration / localization via .ini files

usage
slideshow.exe "path to file or folder" optional "fullscreen" parameter
if a file or path is specified the folder will be scanned for an image file
if the folder has subfolder(s) these will be scanned for image files as well.

Intended use is mostly educational but might
be useful to some as bare bones slideshow.

Tested and compiled on windows 7 / 10 as 32bit app

release (32bit windows):
https://github.com/thrive4/app.fb.slideshow/releases

source
https://github.com/thrive4/app.fb.slideshow

requirements
sdl2 version
sdl2.dll (32bit) v2.24.2.0
https://www.libsdl.org
and
sdl2_image.dll (32bit) v2.6.2.0
https://github.com/libsdl-org/SDL_image/releases

special thanks
TwinklebearDev SDL 2.0 Tutorial Lesson 3
Tutorial translating to FreeBASIC by Michael "h4tt3n" Schmidt Nissen
split or explode by delimiter return elements in array
based on viewtopic.php?t=31691 code by grindstone
text substitution
found at https://freebasic.net/forum/viewtopic.p ... ing#p86259

and fxm for the contributions to:
viewtopic.php?t=32212&hilit=timer&start=210
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

Re: slideshow with sdl2 plus ken burns effect

Post by thrive4 »

Some possibly useful information regarding using non
alpha image types (jpeg, bmp, etc) with sdl to manipulate
alpha when needed.

Two methods, old method brute force very inefficient,
new method the royal route but with a 'gottcha' regarding
memory leaks.

More info see:
https://wiki.libsdl.org/SDL2_image/IMG_LoadTexture
'If the loaded image has transparency or a colorkey,
a texture with an alpha channel will be created.'
(jpeg and bmp do not have alpha)

An attempt to address this:
https://github.com/libsdl-org/SDL_image/issues/372

old method:
read jpg > write jpg as png > read png > crossfade alpha

Code: Select all

        ' bookmark previous image for crossfade
        dummy = filename

        pip.x = slideshow.x
        pip.y = slideshow.y
        pip.w = slideshow.w
        pip.h = slideshow.h
        SDL_DestroyTexture(temp_surface)

        getimage(filename, mp3file, mp3chk, playtype)
        SDL_DestroyTexture(background_surface)
        background_surface = IMG_LoadTexture(renderer, filename)

        temp_surface       = IMG_Load(dummy)
        IMG_SavePNG(temp_surface, exepath + "\dummy.png")
        SDL_FreeSurface(temp_surface)
        temp_surface       = IMG_LoadTexture(renderer, exepath + "\dummy.png")
new method:
read jpg > SetSurfaceAlphaMod > ConvertSurfaceFormat > CreateTextureFromSurface > crossfade
note dsurf and esurf as temporary surfaces are needed otherwise
memory leaks occur! (also essential use FreeSurface)

Code: Select all

   
        ' bookmark previous image for crossfade
        dummy = filename

        pip.x = slideshow.x
        pip.y = slideshow.y
        pip.w = slideshow.w
        pip.h = slideshow.h
        SDL_DestroyTexture(temp_surface)
        SDL_DestroyTexture(background_surface)

        getimage(filename, mp3file, mp3chk, playtype)
        background_surface = IMG_LoadTexture(renderer, filename)

        ' add alpha for crossfade
        dsurf = IMG_Load(dummy)
        SDL_SetSurfaceAlphaMod(dsurf, 0)
        esurf = SDL_ConvertSurfaceFormat(dsurf, SDL_PIXELFORMAT_RGBA32, 0)
        temp_surface = SDL_CreateTextureFromSurface(renderer, esurf)
        SDL_FreeSurface(dsurf)
        SDL_FreeSurface(esurf)
Post Reply