#define _GNU_SOURCE
#include "xcursor.h"
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define XCURSOR_FILE_TOC_LEN (3 * 4)
typedef struct _XcursorFileToc {
- XcursorUInt type; /* chunk type */
- XcursorUInt subtype; /* subtype (size for images) */
- XcursorUInt position; /* absolute position in file */
+ uint32_t type; /* chunk type */
+ uint32_t subtype; /* subtype (size for images) */
+ uint32_t position; /* absolute position in file */
} XcursorFileToc;
typedef struct _XcursorFileHeader {
- XcursorUInt magic; /* magic number */
- XcursorUInt header; /* byte length of header */
- XcursorUInt version; /* file version number */
- XcursorUInt ntoc; /* number of toc entries */
+ uint32_t magic; /* magic number */
+ uint32_t header; /* byte length of header */
+ uint32_t version; /* file version number */
+ uint32_t ntoc; /* number of toc entries */
XcursorFileToc *tocs; /* table of contents */
} XcursorFileHeader;
#define XCURSOR_CHUNK_HEADER_LEN (4 * 4)
typedef struct _XcursorChunkHeader {
- XcursorUInt header; /* bytes in chunk header */
- XcursorUInt type; /* chunk type */
- XcursorUInt subtype; /* chunk subtype (size for images) */
- XcursorUInt version; /* version of this type */
+ uint32_t header; /* bytes in chunk header */
+ uint32_t type; /* chunk type */
+ uint32_t subtype; /* chunk subtype (size for images) */
+ uint32_t version; /* version of this type */
} XcursorChunkHeader;
/*
#define XCURSOR_COMMENT_MAX_LEN 0x100000
typedef struct _XcursorComment {
- XcursorUInt version;
- XcursorUInt comment_type;
+ uint32_t version;
+ uint32_t comment_type;
char *comment;
} XcursorComment;
return NULL;
image = malloc (sizeof (XcursorImage) +
- width * height * sizeof (XcursorPixel));
+ width * height * sizeof (uint32_t));
if (!image)
return NULL;
image->version = XCURSOR_IMAGE_VERSION;
- image->pixels = (XcursorPixel *) (image + 1);
+ image->pixels = (uint32_t *) (image + 1);
image->size = width > height ? width : height;
image->width = width;
image->height = height;
images->name = new;
}
-static XcursorBool
-_XcursorReadUInt (XcursorFile *file, XcursorUInt *u)
+static bool
+_XcursorReadUInt (XcursorFile *file, uint32_t *u)
{
unsigned char bytes[4];
if ((*file->read) (file, bytes, 4) != 4)
return XcursorFalse;
- *u = ((XcursorUInt)(bytes[0]) << 0) |
- ((XcursorUInt)(bytes[1]) << 8) |
- ((XcursorUInt)(bytes[2]) << 16) |
- ((XcursorUInt)(bytes[3]) << 24);
+ *u = ((uint32_t)(bytes[0]) << 0) |
+ ((uint32_t)(bytes[1]) << 8) |
+ ((uint32_t)(bytes[2]) << 16) |
+ ((uint32_t)(bytes[3]) << 24);
return XcursorTrue;
}
}
static XcursorFileHeader *
-_XcursorFileHeaderCreate (XcursorUInt ntoc)
+_XcursorFileHeaderCreate (uint32_t ntoc)
{
XcursorFileHeader *fileHeader;
_XcursorReadFileHeader (XcursorFile *file)
{
XcursorFileHeader head, *fileHeader;
- XcursorUInt skip;
+ uint32_t skip;
unsigned int n;
if (!file)
return fileHeader;
}
-static XcursorBool
+static bool
_XcursorSeekToToc (XcursorFile *file,
XcursorFileHeader *fileHeader,
int toc)
return XcursorTrue;
}
-static XcursorBool
+static bool
_XcursorFileReadChunkHeader (XcursorFile *file,
XcursorFileHeader *fileHeader,
int toc,
#define dist(a,b) ((a) > (b) ? (a) - (b) : (b) - (a))
-static XcursorDim
+static uint32_t
_XcursorFindBestSize (XcursorFileHeader *fileHeader,
- XcursorDim size,
+ uint32_t size,
int *nsizesp)
{
unsigned int n;
int nsizes = 0;
- XcursorDim bestSize = 0;
- XcursorDim thisSize;
+ uint32_t bestSize = 0;
+ uint32_t thisSize;
if (!fileHeader || !nsizesp)
return 0;
static int
_XcursorFindImageToc (XcursorFileHeader *fileHeader,
- XcursorDim size,
+ uint32_t size,
int count)
{
unsigned int toc;
- XcursorDim thisSize;
+ uint32_t thisSize;
if (!fileHeader)
return 0;
XcursorImage head;
XcursorImage *image;
int n;
- XcursorPixel *p;
+ uint32_t *p;
if (!file || !fileHeader)
return NULL;
XcursorXcFileLoadImages (XcursorFile *file, int size)
{
XcursorFileHeader *fileHeader;
- XcursorDim bestSize;
+ uint32_t bestSize;
int nsize;
XcursorImages *images;
int n;
fileHeader = _XcursorReadFileHeader (file);
if (!fileHeader)
return NULL;
- bestSize = _XcursorFindBestSize (fileHeader, (XcursorDim) size, &nsize);
+ bestSize = _XcursorFindBestSize (fileHeader, (uint32_t) size, &nsize);
if (!bestSize)
{
_XcursorFileHeaderDestroy (fileHeader);
#include <stdint.h>
-typedef int XcursorBool;
-typedef uint32_t XcursorUInt;
-
-typedef XcursorUInt XcursorDim;
-typedef XcursorUInt XcursorPixel;
-
typedef struct _XcursorImage {
- XcursorUInt version; /* version of the image data */
- XcursorDim size; /* nominal size for matching */
- XcursorDim width; /* actual width */
- XcursorDim height; /* actual height */
- XcursorDim xhot; /* hot spot x (must be inside image) */
- XcursorDim yhot; /* hot spot y (must be inside image) */
- XcursorUInt delay; /* animation delay to next frame (ms) */
- XcursorPixel *pixels; /* pointer to pixels */
+ uint32_t version; /* version of the image data */
+ uint32_t size; /* nominal size for matching */
+ uint32_t width; /* actual width */
+ uint32_t height; /* actual height */
+ uint32_t xhot; /* hot spot x (must be inside image) */
+ uint32_t yhot; /* hot spot y (must be inside image) */
+ uint32_t delay; /* animation delay to next frame (ms) */
+ uint32_t *pixels; /* pointer to pixels */
} XcursorImage;
/*