diff --git a/graphics/xcursor/xcursor.c b/graphics/xcursor/xcursor.c new file mode 100644 index 0000000..6412963 --- /dev/null +++ b/graphics/xcursor/xcursor.c @@ -0,0 +1,18 @@ + +#include "xcursor.h" +#include + + +void xcursor_LoadMemory(xcursor_Xcursor *cursor, void *file, uintptr_t fileSize) { + cursor->header = 0; + xcursor_Header *head = file; + + if (memcmp(head->magic, XCURSOR_MAGIC, XCURSOR_MAGIC_SIZE) != 0) + return; // magic mismatch + + cursor->size = fileSize; + cursor->n = head->numTOC; + cursor->toc = file + head->headerSize; + + cursor->header = head; +} diff --git a/graphics/xcursor/xcursor.h b/graphics/xcursor/xcursor.h index 302a983..b638501 100644 --- a/graphics/xcursor/xcursor.h +++ b/graphics/xcursor/xcursor.h @@ -1,7 +1,7 @@ #pragma once #include "../../main.h" -#include "../graphics.h" +#include "../color.h" #include #ifdef __cplusplus @@ -11,6 +11,9 @@ extern "C" { // XCursor file format - see man page xcursor(3) // https://www.x.org/releases/X11R7.7/doc/man/man3/Xcursor.3.xhtml +#define XCURSOR_MAGIC "Xcur" +#define XCURSOR_MAGIC_SIZE 4 + // Header typedef struct { char magic[4]; // Magic string "Xcur" @@ -56,7 +59,7 @@ typedef struct { typedef struct { uint32_t headerSize; // Size of the header uint32_t type; // Type of the Chunk, matches the Entry Type in the TOC - uint32_t subtype; // Type specific subtype, Copyright, License or Other + uint32_t subtype; // Type specific subtype, Image size uint32_t version; // Version number of the chunk type, =1 uint32_t width, height; // Width/Height, <=0x7fff @@ -66,6 +69,17 @@ typedef struct { } PACKED xcursor_ChunkHeader_Image; +typedef struct { + xcursor_Header * header; + uintptr_t size; // size of the file in bytes + uintptr_t n; // number of Chunks/TOC Entries + xcursor_TOCEntry *toc; // array of TOC Entries +} xcursor_Xcursor; + +// cursor->header is 0 if the open failed. +void xcursor_LoadMemory(xcursor_Xcursor *cursor, void *file, uintptr_t fileSize); + + #ifdef __cplusplus } #endif