graphics: Xcursor load from memory

This commit is contained in:
Edgaru089 2021-10-10 23:16:23 +08:00
parent bb5a8fbfb1
commit abb6a8ea08
2 changed files with 34 additions and 2 deletions

View 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;
}

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../../main.h" #include "../../main.h"
#include "../graphics.h" #include "../color.h"
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -11,6 +11,9 @@ extern "C" {
// XCursor file format - see man page xcursor(3) // XCursor file format - see man page xcursor(3)
// https://www.x.org/releases/X11R7.7/doc/man/man3/Xcursor.3.xhtml // https://www.x.org/releases/X11R7.7/doc/man/man3/Xcursor.3.xhtml
#define XCURSOR_MAGIC "Xcur"
#define XCURSOR_MAGIC_SIZE 4
// Header // Header
typedef struct { typedef struct {
char magic[4]; // Magic string "Xcur" char magic[4]; // Magic string "Xcur"
@ -56,7 +59,7 @@ typedef struct {
typedef struct { typedef struct {
uint32_t headerSize; // Size of the header uint32_t headerSize; // Size of the header
uint32_t type; // Type of the Chunk, matches the Entry Type in the TOC 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 version; // Version number of the chunk type, =1
uint32_t width, height; // Width/Height, <=0x7fff uint32_t width, height; // Width/Height, <=0x7fff
@ -66,6 +69,17 @@ typedef struct {
} PACKED xcursor_ChunkHeader_Image; } 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 #ifdef __cplusplus
} }
#endif #endif