3rdparty: Reformat xcursor.{h,c}
This commit is contained in:
parent
586a775d5b
commit
e678ebef29
2 changed files with 248 additions and 264 deletions
80
src/3rdparty/xcursor.c
vendored
80
src/3rdparty/xcursor.c
vendored
|
@ -25,10 +25,10 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "xcursor.h"
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
|
||||
/*
|
||||
* From libXcursor/include/X11/extensions/Xcursor.h
|
||||
|
@ -78,9 +78,7 @@
|
|||
#define XCURSOR_LIB_MAJOR 1
|
||||
#define XCURSOR_LIB_MINOR 1
|
||||
#define XCURSOR_LIB_REVISION 13
|
||||
#define XCURSOR_LIB_VERSION ((XCURSOR_LIB_MAJOR * 10000) + \
|
||||
(XCURSOR_LIB_MINOR * 100) + \
|
||||
(XCURSOR_LIB_REVISION))
|
||||
#define XCURSOR_LIB_VERSION ((XCURSOR_LIB_MAJOR * 10000) + (XCURSOR_LIB_MINOR * 100) + (XCURSOR_LIB_REVISION))
|
||||
|
||||
/*
|
||||
* This version number is stored in cursor files; changes to the
|
||||
|
@ -92,13 +90,15 @@
|
|||
#define XCURSOR_FILE_HEADER_LEN (4 * 4)
|
||||
#define XCURSOR_FILE_TOC_LEN (3 * 4)
|
||||
|
||||
typedef struct _XcursorFileToc {
|
||||
typedef struct _XcursorFileToc
|
||||
{
|
||||
XcursorUInt type; /* chunk type */
|
||||
XcursorUInt subtype; /* subtype (size for images) */
|
||||
XcursorUInt position; /* absolute position in file */
|
||||
} XcursorFileToc;
|
||||
|
||||
typedef struct _XcursorFileHeader {
|
||||
typedef struct _XcursorFileHeader
|
||||
{
|
||||
XcursorUInt magic; /* magic number */
|
||||
XcursorUInt header; /* byte length of header */
|
||||
XcursorUInt version; /* file version number */
|
||||
|
@ -124,7 +124,8 @@ typedef struct _XcursorFileHeader {
|
|||
|
||||
#define XCURSOR_CHUNK_HEADER_LEN (4 * 4)
|
||||
|
||||
typedef struct _XcursorChunkHeader {
|
||||
typedef struct _XcursorChunkHeader
|
||||
{
|
||||
XcursorUInt header; /* bytes in chunk header */
|
||||
XcursorUInt type; /* chunk type */
|
||||
XcursorUInt subtype; /* chunk subtype (size for images) */
|
||||
|
@ -153,7 +154,8 @@ typedef struct _XcursorChunkHeader {
|
|||
#define XCURSOR_COMMENT_OTHER 3
|
||||
#define XCURSOR_COMMENT_MAX_LEN 0x100000
|
||||
|
||||
typedef struct _XcursorComment {
|
||||
typedef struct _XcursorComment
|
||||
{
|
||||
XcursorUInt version;
|
||||
XcursorUInt comment_type;
|
||||
char *comment;
|
||||
|
@ -180,7 +182,8 @@ typedef struct _XcursorComment {
|
|||
#define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5 * 4))
|
||||
#define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */
|
||||
|
||||
typedef struct _XcursorComments {
|
||||
typedef struct _XcursorComments
|
||||
{
|
||||
int ncomment; /* number of comments */
|
||||
XcursorComment **comments; /* array of XcursorComment pointers */
|
||||
} XcursorComments;
|
||||
|
@ -199,8 +202,7 @@ XcursorImageCreate (int width, int height)
|
|||
if (width > XCURSOR_IMAGE_MAX_SIZE || height > XCURSOR_IMAGE_MAX_SIZE)
|
||||
return NULL;
|
||||
|
||||
image = malloc (sizeof (XcursorImage) +
|
||||
width * height * sizeof (XcursorPixel));
|
||||
image = malloc(sizeof(XcursorImage) + width * height * sizeof(XcursorPixel));
|
||||
if (!image)
|
||||
return NULL;
|
||||
image->version = XCURSOR_IMAGE_VERSION;
|
||||
|
@ -223,8 +225,7 @@ XcursorImagesCreate (int size)
|
|||
{
|
||||
XcursorImages *images;
|
||||
|
||||
images = malloc (sizeof (XcursorImages) +
|
||||
size * sizeof (XcursorImage *));
|
||||
images = malloc(sizeof(XcursorImages) + size * sizeof(XcursorImage *));
|
||||
if (!images)
|
||||
return NULL;
|
||||
images->nimage = 0;
|
||||
|
@ -232,8 +233,7 @@ XcursorImagesCreate (int size)
|
|||
return images;
|
||||
}
|
||||
|
||||
void
|
||||
XcursorImagesDestroy (XcursorImages *images)
|
||||
void XcursorImagesDestroy(XcursorImages *images)
|
||||
{
|
||||
int n;
|
||||
|
||||
|
@ -256,10 +256,7 @@ _XcursorReadUInt (XcursorFile *file, XcursorUInt *u)
|
|||
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 = ((XcursorUInt)(bytes[0]) << 0) | ((XcursorUInt)(bytes[1]) << 8) | ((XcursorUInt)(bytes[2]) << 16) | ((XcursorUInt)(bytes[3]) << 24);
|
||||
return XcursorTrue;
|
||||
}
|
||||
|
||||
|
@ -276,8 +273,7 @@ _XcursorFileHeaderCreate (XcursorUInt ntoc)
|
|||
|
||||
if (ntoc > 0x10000)
|
||||
return NULL;
|
||||
fileHeader = malloc (sizeof (XcursorFileHeader) +
|
||||
ntoc * sizeof (XcursorFileToc));
|
||||
fileHeader = malloc(sizeof(XcursorFileHeader) + ntoc * sizeof(XcursorFileToc));
|
||||
if (!fileHeader)
|
||||
return NULL;
|
||||
fileHeader->magic = XCURSOR_MAGIC;
|
||||
|
@ -319,8 +315,7 @@ _XcursorReadFileHeader (XcursorFile *file)
|
|||
fileHeader->header = head.header;
|
||||
fileHeader->version = head.version;
|
||||
fileHeader->ntoc = head.ntoc;
|
||||
for (n = 0; n < fileHeader->ntoc; n++)
|
||||
{
|
||||
for (n = 0; n < fileHeader->ntoc; n++) {
|
||||
if (!_XcursorReadUInt(file, &fileHeader->tocs[n].type))
|
||||
break;
|
||||
if (!_XcursorReadUInt(file, &fileHeader->tocs[n].subtype))
|
||||
|
@ -328,8 +323,7 @@ _XcursorReadFileHeader (XcursorFile *file)
|
|||
if (!_XcursorReadUInt(file, &fileHeader->tocs[n].position))
|
||||
break;
|
||||
}
|
||||
if (n != fileHeader->ntoc)
|
||||
{
|
||||
if (n != fileHeader->ntoc) {
|
||||
_XcursorFileHeaderDestroy(fileHeader);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -365,8 +359,7 @@ _XcursorFileReadChunkHeader (XcursorFile *file,
|
|||
if (!_XcursorReadUInt(file, &chunkHeader->version))
|
||||
return XcursorFalse;
|
||||
/* sanity check */
|
||||
if (chunkHeader->type != fileHeader->tocs[toc].type ||
|
||||
chunkHeader->subtype != fileHeader->tocs[toc].subtype)
|
||||
if (chunkHeader->type != fileHeader->tocs[toc].type || chunkHeader->subtype != fileHeader->tocs[toc].subtype)
|
||||
return XcursorFalse;
|
||||
return XcursorTrue;
|
||||
}
|
||||
|
@ -386,17 +379,14 @@ _XcursorFindBestSize (XcursorFileHeader *fileHeader,
|
|||
if (!fileHeader || !nsizesp)
|
||||
return 0;
|
||||
|
||||
for (n = 0; n < fileHeader->ntoc; n++)
|
||||
{
|
||||
for (n = 0; n < fileHeader->ntoc; n++) {
|
||||
if (fileHeader->tocs[n].type != XCURSOR_IMAGE_TYPE)
|
||||
continue;
|
||||
thisSize = fileHeader->tocs[n].subtype;
|
||||
if (!bestSize || dist (thisSize, size) < dist (bestSize, size))
|
||||
{
|
||||
if (!bestSize || dist(thisSize, size) < dist(bestSize, size)) {
|
||||
bestSize = thisSize;
|
||||
nsizes = 1;
|
||||
}
|
||||
else if (thisSize == bestSize)
|
||||
} else if (thisSize == bestSize)
|
||||
nsizes++;
|
||||
}
|
||||
*nsizesp = nsizes;
|
||||
|
@ -414,8 +404,7 @@ _XcursorFindImageToc (XcursorFileHeader *fileHeader,
|
|||
if (!fileHeader)
|
||||
return 0;
|
||||
|
||||
for (toc = 0; toc < fileHeader->ntoc; toc++)
|
||||
{
|
||||
for (toc = 0; toc < fileHeader->ntoc; toc++) {
|
||||
if (fileHeader->tocs[toc].type != XCURSOR_IMAGE_TYPE)
|
||||
continue;
|
||||
thisSize = fileHeader->tocs[toc].subtype;
|
||||
|
@ -457,8 +446,7 @@ _XcursorReadImage (XcursorFile *file,
|
|||
if (!_XcursorReadUInt(file, &head.delay))
|
||||
return NULL;
|
||||
/* sanity check data */
|
||||
if (head.width > XCURSOR_IMAGE_MAX_SIZE ||
|
||||
head.height > XCURSOR_IMAGE_MAX_SIZE)
|
||||
if (head.width > XCURSOR_IMAGE_MAX_SIZE || head.height > XCURSOR_IMAGE_MAX_SIZE)
|
||||
return NULL;
|
||||
if (head.width == 0 || head.height == 0)
|
||||
return NULL;
|
||||
|
@ -477,10 +465,8 @@ _XcursorReadImage (XcursorFile *file,
|
|||
image->delay = head.delay;
|
||||
n = image->width * image->height;
|
||||
p = image->pixels;
|
||||
while (n--)
|
||||
{
|
||||
if (!_XcursorReadUInt (file, p))
|
||||
{
|
||||
while (n--) {
|
||||
if (!_XcursorReadUInt(file, p)) {
|
||||
XcursorImageDestroy(image);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -505,19 +491,16 @@ XcursorXcFileLoadImages (XcursorFile *file, int size)
|
|||
if (!fileHeader)
|
||||
return NULL;
|
||||
bestSize = _XcursorFindBestSize(fileHeader, (XcursorDim)size, &nsize);
|
||||
if (!bestSize)
|
||||
{
|
||||
if (!bestSize) {
|
||||
_XcursorFileHeaderDestroy(fileHeader);
|
||||
return NULL;
|
||||
}
|
||||
images = XcursorImagesCreate(nsize);
|
||||
if (!images)
|
||||
{
|
||||
if (!images) {
|
||||
_XcursorFileHeaderDestroy(fileHeader);
|
||||
return NULL;
|
||||
}
|
||||
for (n = 0; n < nsize; n++)
|
||||
{
|
||||
for (n = 0; n < nsize; n++) {
|
||||
toc = _XcursorFindImageToc(fileHeader, bestSize, n);
|
||||
if (toc < 0)
|
||||
break;
|
||||
|
@ -528,8 +511,7 @@ XcursorXcFileLoadImages (XcursorFile *file, int size)
|
|||
images->nimage++;
|
||||
}
|
||||
_XcursorFileHeaderDestroy(fileHeader);
|
||||
if (images->nimage != nsize)
|
||||
{
|
||||
if (images->nimage != nsize) {
|
||||
XcursorImagesDestroy(images);
|
||||
images = NULL;
|
||||
}
|
||||
|
|
12
src/3rdparty/xcursor.h
vendored
12
src/3rdparty/xcursor.h
vendored
|
@ -38,7 +38,8 @@ typedef uint32_t XcursorUInt;
|
|||
typedef XcursorUInt XcursorDim;
|
||||
typedef XcursorUInt XcursorPixel;
|
||||
|
||||
typedef struct _XcursorImage {
|
||||
typedef struct _XcursorImage
|
||||
{
|
||||
XcursorUInt version; /* version of the image data */
|
||||
XcursorDim size; /* nominal size for matching */
|
||||
XcursorDim width; /* actual width */
|
||||
|
@ -52,14 +53,16 @@ typedef struct _XcursorImage {
|
|||
/*
|
||||
* Other data structures exposed by the library API
|
||||
*/
|
||||
typedef struct _XcursorImages {
|
||||
typedef struct _XcursorImages
|
||||
{
|
||||
int nimage; /* number of images */
|
||||
XcursorImage **images; /* array of XcursorImage pointers */
|
||||
} XcursorImages;
|
||||
|
||||
typedef struct _XcursorFile XcursorFile;
|
||||
|
||||
struct _XcursorFile {
|
||||
struct _XcursorFile
|
||||
{
|
||||
void *closure;
|
||||
int (*read)(XcursorFile *file, uint8_t *buf, int len);
|
||||
XcursorBool (*skip)(XcursorFile *file, long offset);
|
||||
|
@ -69,8 +72,7 @@ struct _XcursorFile {
|
|||
XcursorImages *
|
||||
XcursorXcFileLoadImages(XcursorFile *file, int size);
|
||||
|
||||
void
|
||||
XcursorImagesDestroy (XcursorImages *images);
|
||||
void XcursorImagesDestroy(XcursorImages *images);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue