graphics: Xcursor load from memory
This commit is contained in:
parent
bb5a8fbfb1
commit
abb6a8ea08
18
graphics/xcursor/xcursor.c
Normal file
18
graphics/xcursor/xcursor.c
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#include "xcursor.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../main.h"
|
||||
#include "../graphics.h"
|
||||
#include "../color.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user