MLX42 1.0
MLX42
|
#include "MLX42/MLX42_Int.h"
Go to the source code of this file.
Functions | |
static uint8_t | mlx_parse_hex_channel (char *channel) |
static bool | mlx_insert_xpm_entry (xpm_t *xpm, char *line, uint32_t *ctable, size_t s) |
static bool | mlx_read_data (xpm_t *xpm, FILE *file, uint32_t *ctable, size_t s) |
static bool | mlx_read_table (xpm_t *xpm, FILE *file) |
static bool | mlx_read_xpm_header (xpm_t *xpm, FILE *file) |
xpm_t * | mlx_load_xpm42 (const char *path) |
void | mlx_delete_xpm42 (xpm_t *xpm) |
Deletes an XPM42 texture by freeing its allocated data.
This will not remove any already drawn XPMs, it simply deletes the XPM buffer.
[in] | xpm | The xpm texture to delete. |
Definition at line 203 of file mlx_xpm42.c.
Parses the XPM color value entry e.g: ".X #00FF00FF" into the color table while also verifying the format.
xpm | The XPM. |
line | The line to parse. |
ctable | The color hash table. |
s | Size of the hash table |
Definition at line 64 of file mlx_xpm42.c.
Loads an XPM42 texture from the given file path.
[in] | path | The file path to the XPM texture. |
Definition at line 181 of file mlx_xpm42.c.
XPM is an obscure image format which can't seem to make up its mind whether it wants to be written in C code or not.
https://en.wikipedia.org/wiki/X_PixMap
This might anger some but instead I decided to write my own image format, very similar to XPM2, which seems to be the better option between the 3 versions. The only difference is in the header which carries the file type, width, height, color count and finally color type aka 'c' for RGBA8 or 'm' for monochrome output.
The changes, in my opinion, very much simplify the XPM format into something literally anybody can use without much guessing as to what does what.
Additionally with the C style format, the idea is that you simply include it directly into the compilation of the program (since it's just C).
As convenient as this is, I just find it hideous especially the XPM3 variant. By sticking to the XPM style format, conversion should be very easy and straightforward to this format however. Parses HEX color channel e.g: "0F"
channel | The 2 character string to parse. |
Definition at line 48 of file mlx_xpm42.c.
Retrieves the pixel data line by line and then processes each pixel by hashing the characters and looking it up from the color table.
xpm | The XPM. |
file | The filepath to the XPM42 file. |
ctable | The color hash table. |
s | Size of the hash table. |
Definition at line 96 of file mlx_xpm42.c.
For quick lookups we basically create a stack allocated lookup table with every ascii character in it. This should help avoid a O(n) case and give us a O(1) for very fast look ups.
Downside is we still need to iterate over each pixel to solve its color. So I hope this makes it at least a bit faster.
TODO: This buffer might be way to big! Do actual collision checks, for now just straight up raw dog this.
Definition at line 132 of file mlx_xpm42.c.
Reads the XPM42 file header which usually consists of a file type declaration of "!XPM42" followed by the next line containing image information such as width, height, unique color count and finally the color mode. Which is either c for Color or m for Monochrome.
Definition at line 156 of file mlx_xpm42.c.