LRaspi  2022.1
A Lua Player for Rasberry Pi
lraspi.h
Go to the documentation of this file.
1 /*
2  * Lua Raspi 2022.1
3  *
4  * A general-purpose Lua Player for Raspberry Pi single-board computer
5  *
6  * This software is under MIT License
7  *
8  * Copyright (c) 2019 - Rafael Alcalde Azpiazu (NEKERAFA)
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in all
18  * copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.
27  *
28  * lraspi.h - NEKERAFA - 25th october 2021
29  * API functions and types definition
30  */
31 
32 #ifndef LRASPI_LIBRARY_H
33 #define LRASPI_LIBRARY_H
34 
35 #include <stdint.h>
36 #include <stdbool.h>
37 
41 #define LRASPI_LIB_VERSION "1.0.0"
42 
44 #define LRASPI_VERSION "2022.1"
45 
46 #define LRASPI_FONT_SIZE 12
47 #define LRASPI_FONT_FILE "OpenSans.ttf"
48 
59 void lraspi_init();
60 
64 void lraspi_close();
65 
77 typedef struct lraspi_Colour lraspi_Colour;
78 
87 lraspi_Colour* lraspi_colour_new(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
88 
95 
102 
109 void lraspi_colour_setredchannel(lraspi_Colour* colour, uint8_t red);
110 
117 
124 void lraspi_colour_setgreenchannel(lraspi_Colour* colour, uint8_t green);
125 
132 
139 void lraspi_colour_setbluechannel(lraspi_Colour* colour, uint8_t blue);
140 
147 
154 void lraspi_colour_setalphachannel(lraspi_Colour* colour, uint8_t alpha);
155 
162 
169 
176 
183 
188 
199 typedef struct lraspi_Image lraspi_Image;
200 
202 typedef enum {
203  LRASPI_FILTER_NEAREST = 0,
207 
214 lraspi_Image* lraspi_image_new(const char* image_file);
215 
222 
231 
238 
245 
254 
262 void lraspi_image_resize(lraspi_Image* image, int height, int width);
263 
270 
277 void lraspi_image_rotate(lraspi_Image* image, float angle);
278 
286 
293 void lraspi_image_vflip(lraspi_Image* image, bool vflip);
294 
302 
309 void lraspi_image_hflip(lraspi_Image* image, bool hflip);
310 
318 
326 
335 
344 void lraspi_image_setpixel(lraspi_Image* image, lraspi_Colour* colour, int x, int y);
345 
350 
367 
374 
381 
386 
390 void lraspi_screen_setfps(int frame_per_seconds);
391 
396 
401 
406 
415 
422 
440 void lraspi_draw_print(const char* text, int x, int y);
441 
449 void lraspi_draw_blit(lraspi_Image* image, int x, int y);
450 
462 typedef struct lraspi_Font lraspi_Font;
463 
471 lraspi_Font* lraspi_font_new(const char* font_file, int size);
472 
479 
486 
493 
498 
503 #endif // LRASPI_LIBRARY_H
504 
struct lraspi_Colour lraspi_Colour
Definition: lraspi.h:77
lraspi_Colour * lraspi_colour_getbackground()
Gets the default background colour.
void lraspi_colour_setalphachannel(lraspi_Colour *colour, uint8_t alpha)
Sets the alpha channel value.
uint8_t lraspi_colour_getgreenchannel(lraspi_Colour *colour)
Gets the green channel value.
const char * lraspi_colour_tostring(lraspi_Colour *colour)
Gets the string representation of the colour.
uint8_t lraspi_colour_getredchannel(lraspi_Colour *colour)
Gets the red channel value.
lraspi_Colour * lraspi_colour_getforeground()
Gets the default foreground colour.
void lraspi_colour_setforeground(lraspi_Colour *colour)
Sets the default foreground colour.
void lraspi_colour_setbackground(lraspi_Colour *colour)
Sets the default foreground colour.
void lraspi_colour_setredchannel(lraspi_Colour *colour, uint8_t red)
Sets the red channel value.
lraspi_Colour * lraspi_colour_new(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Creates a new colour object.
void lraspi_colour_free(lraspi_Colour *colour)
Releases the colour.
void lraspi_colour_setgreenchannel(lraspi_Colour *colour, uint8_t green)
Sets the green channel value.
uint8_t lraspi_colour_getbluechannel(lraspi_Colour *colour)
Gets the blue channel value.
void lraspi_colour_setbluechannel(lraspi_Colour *colour, uint8_t blue)
Sets the blue channel value.
uint8_t lraspi_colour_getalphachannel(lraspi_Colour *colour)
Gets the alpha channel value.
void lraspi_close()
Closes internal libraries and free internal state.
void lraspi_init()
Initializes internal libraries and state.
void lraspi_draw_blit(lraspi_Image *image, int x, int y)
Draws an image with default foreground colour.
void lraspi_draw_print(const char *text, int x, int y)
Draws a text with default font.
void lraspi_font_free(lraspi_Font *font)
Releases a font from memory.
struct lraspi_Font lraspi_Font
Definition: lraspi.h:462
void lraspi_font_setdefault(lraspi_Font *font)
Sets the current default font.
lraspi_Font * lraspi_font_getdefault()
Gets the current default font.
const char * lraspi_font_tostring(lraspi_Font *font)
Gets the string representation of the image.
lraspi_Font * lraspi_font_new(const char *font_file, int size)
Loads a font file onto the memory.
void lraspi_image_vflip(lraspi_Image *image, bool vflip)
Flips the image vertically.
void lraspi_image_resize(lraspi_Image *image, int height, int width)
Resizes the image.
void lraspi_image_free(lraspi_Image *image)
Releases an image from memory.
bool lraspi_image_isvflip(lraspi_Image *image)
Checks if the image is vertically flipped.
int lraspi_image_getwidth(lraspi_Image *image)
Gets the current width (in pixels) of the image.
void lraspi_image_hflip(lraspi_Image *image, bool hflip)
Flips the image vertically.
float lraspi_image_getrotation(lraspi_Image *image)
Gets the rotation angle (in radians) of the image.
int lraspi_image_getheight(lraspi_Image *image)
Gets the current height (in pixels) of the image.
const char * lraspi_image_tostring(lraspi_Image *image)
Gets the string representation of the image.
int lraspi_image_getinitialheight(lraspi_Image *image)
Gets the height (in pixels) of the image.
void lraspi_image_setpixel(lraspi_Image *image, lraspi_Colour *colour, int x, int y)
Sets the colour pixel of the image.
lraspi_Colour * lraspi_image_getpixel(lraspi_Image *image, int x, int y)
Gets the colour pixel of the image.
lraspi_FilterMode
Definition: lraspi.h:202
struct lraspi_Image lraspi_Image
Definition: lraspi.h:199
lraspi_FilterMode lraspi_image_getfilter(lraspi_Image *image)
Gets the image filter.
void lraspi_image_setfilter(lraspi_Image *image, lraspi_FilterMode filter)
Sets the image filter.
bool lraspi_image_ishflip(lraspi_Image *image)
Checks if the image is horizontally flipped.
lraspi_Image * lraspi_image_new(const char *image_file)
Loads an image file onto the memory.
void lraspi_image_rotate(lraspi_Image *image, float angle)
Rotates the image.
int lraspi_image_getinitialwidth(lraspi_Image *image)
Gets the width (in pixels) of the image.
@ LRASPI_FILTER_TRILINEAR
Definition: lraspi.h:205
@ LRASPI_FILTER_BILINEAR
Definition: lraspi.h:204
int lraspi_screen_getheight()
Gets the height of the screen.
int lraspi_screen_getfps()
Gets the frames per second.
void lraspi_screen_setdefault(lraspi_Image *image)
Sets the render target to a image object.
float lraspi_screen_getdeltatime()
Gets the time in seconds since the last screen update.
int lraspi_screen_getwidth()
Gets the width of the screen.
bool lraspi_screen_isclosing()
Checks if the program will be closed.
void lraspi_screen_setfps(int frame_per_seconds)
Sets the frames per second.
void lraspi_screen_flip()
Sets the library to stop drawing and show the buffer onto the screen.
void lraspi_screen_clear()
Clears the buffer using the default background colour and prepares the library to draw.
lraspi_Image * lraspi_screen_getdefault()
Gets the current render image.