DungeonCrawl
Loading...
Searching...
No Matches
media_output_handler.h
Go to the documentation of this file.
1
5#ifndef MEDIA_OUTPUT_HANDLER_H
6#define MEDIA_OUTPUT_HANDLER_H
7
8#include <notcurses/notcurses.h>
9#include <stdbool.h>
10
11// Scale types for display functions
12typedef enum {
13 SCALE_NONE, // No scaling, use original size
14 SCALE_PRESERVE, // Scale preserving aspect ratio
15 SCALE_STRETCH, // Stretch to exact dimensions
16 SCALE_CELL, // Scale to fit in a single cell
17 SCALE_FULLSCREEN// Scale to fill the entire screen
18} scale_type_t;
19
20// Media types enumeration
21typedef enum {
22 MEDIA_PNG,
23 MEDIA_GIF,
24 MEDIA_MP4,
25 MEDIA_UNSUPPORTED
26} media_type_t;
27
31typedef enum media_blitter {
32 MEDIA_BLITTER_DEFAULT = NCBLIT_DEFAULT,// Use terminal's best option
33 MEDIA_BLITTER_ASCII = NCBLIT_1x1, // Use ASCII only
34 MEDIA_BLITTER_HALF = NCBLIT_2x1, // Use half blocks (▀ ▄)
35 MEDIA_BLITTER_QUAD = NCBLIT_2x2, // Use quadrant blocks (▖ ▗ ▘ ▙)
36 MEDIA_BLITTER_BRAILLE = NCBLIT_BRAILLE,// Use braille (⠀⠁⠂⠃...)
37 MEDIA_BLITTER_PIXEL = NCBLIT_PIXEL, // Use pixel graphics if available
39
40/* =========================================================================
41 * CONSTANTS AND DEFINITIONS
42 * ========================================================================= */
43
49
50typedef struct loaded_visual_s {
51 struct ncvisual* visual; // The Notcurses visual
52 struct ncplane* plane; // The plane for rendering the visual
53 struct ncvisual_options options;// Display options
54 media_type_t media_type; // Type of media (PNG, GIF, MP4)
55 unsigned int og_width; // Original width
56 unsigned int og_height; // Original height
57 unsigned int frames; // Number of frames (for animations)
58 bool is_playing; // Whether an animation is currently playing
59 bool is_loaded; // Whether the visual is loaded
60 char* path; // Path to the file (for reloading)
62
63/* =========================================================================
64 * INITIALIZATION AND CLEANUP
65 * ========================================================================= */
66
74bool init_media_output(void);
75
81void shutdown_media_output(void);
82
83/***
84 * @brief Clean up all loaded media resources
85 *
86 * Frees all loaded media resources and resets the handler.
87 */
88void media_cleanup(void);
89
96
102bool refresh_media_display(void);
103
104/* =========================================================================
105 * LOAD AND READY FUNCTIONS
106 * ========================================================================= */
107
115loaded_visual_t* load_media(const char* filename);
116
128loaded_visual_t* ready_media(const char* filename, int x, int y, int height, int width, scale_type_t scale_type);
129
130/* =========================================================================
131 * RESOURCE MANAGEMENT FUNCTIONS
132 * ========================================================================= */
133
140bool unload_media(const char* filename);
141
148bool preload_media(const char* filename);
149
156
157
158/* =========================================================================
159 * REENDERING AND DISPLAY FUNCTIONS
160 * ========================================================================= */
161
168
175
181
187
188/* =========================================================================
189 * SCALING FUNCTIONS
190 * ========================================================================= */
191
200void setup_scaling_options(loaded_visual_t* visual, scale_type_t scale_type, int target_width, int target_height);
201
202/* =========================================================================
203 * FILE AND PATH HANDLING FUNCTIONS
204 * ========================================================================= */
205
211bool directory_exists(const char* path);
212
219media_type_t get_file_type(const char* filename);
220
228bool is_file_extension(const char* filename, const char* extension);
229
237char* build_filepath(const char* filename, media_type_t media_type);
238
239#endif /* MEDIA_OUTPUT_HANDLER_H */
media_type_t get_file_type(const char *filename)
Get the media type based on the file extension.
char * build_filepath(const char *filename, media_type_t media_type)
Build a file path for the specified media type.
void destroy_media(loaded_visual_t *media)
Frees the memory associated with a loaded media resource.
media_blitter
Media blitter options (rendering method)
bool media_output_can_display_images(void)
Check if the notcurses implementation supports image loading.
void shutdown_media_output(void)
Shutdown the media output handler.
bool media_output_render_next_frame(loaded_visual_t *media)
Display the next frame of an animation or video.
bool media_output_can_display_videos(void)
Check if the notcurses implementation supports video loading.
enum media_blitter media_blitter_t
Media blitter options (rendering method)
bool refresh_media_display(void)
Force a refresh of the media display.
bool unload_media(const char *filename)
Unload a specific media resource.
bool media_output_render(loaded_visual_t *media)
Display a loaded media file on its assigned plane.
bool init_media_output(void)
Initialize the media output handler.
bool preload_media(const char *filename)
Preload a media file into memory.
bool reload_media_after_resize(void)
Reload media after terminal resize.
loaded_visual_t * ready_media(const char *filename, int x, int y, int height, int width, scale_type_t scale_type)
Prepares a media resource for display.
struct loaded_visual_s loaded_visual_t
Structure to represent a loaded visual.
bool directory_exists(const char *path)
checks if a directory exists
void setup_scaling_options(loaded_visual_t *visual, scale_type_t scale_type, int target_width, int target_height)
Enable different scaling options for the loaded visual.
bool is_file_extension(const char *filename, const char *extension)
Check if a filename has a specific extension.
loaded_visual_t * load_media(const char *filename)
load a media resource from file they can be different types (PNG, GIF, MP4)
Structure to represent a loaded visual.