diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2007-04-05 11:28:17 +1000 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2007-04-05 15:47:38 +1000 |
commit | 63c703333a4f211401fa0403783771106b32ae76 (patch) | |
tree | 13a7968b54b287c03d9000d53f9699b82104fc98 | |
parent | 73b1b6aa2d81d1e0df90bf490321dee2a3e4deb6 (diff) |
Add gzip support for cursors
The cursors used by twin compress well, so allow twin_cursor to load a
compressed cursor file when zlib is present. In both cases,
uncomressed cursors still work.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r-- | configure.ac | 22 | ||||
-rw-r--r-- | libtwin/twin_cursor.c | 38 |
2 files changed, 50 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index 6e1c323..dadcd78 100644 --- a/configure.ac +++ b/configure.ac @@ -81,6 +81,24 @@ AC_ARG_ENABLE(linux-mouse, [Disable linux mouse support (default=enabled)]), twin_mouse="$enableval", twin_mouse="yes") +# zlib +AC_ARG_ENABLE(zlib, + AC_HELP_STRING([--disable-zlib], + [Disable zlib support (default=enabled)]), + twin_zlib="$enableval", twin_zlib="yes") +AH_TEMPLATE(HAVE_ZLIB, [Define if the zlib compression library is available]) + +if test "x$twin_zlib" = "zlib" +then + AC_CHECK_HEADER(zlib.h, twin_zlib="yes", twin_zlib="no") +fi + +if test "x$twin_zlib" = "xyes" +then + Z_LIBS=-lz + AC_DEFINE([HAVE_ZLIB]) +fi + # png support AC_ARG_ENABLE(png, AC_HELP_STRING([--disable-png], @@ -156,13 +174,14 @@ AC_SUBST(ALTIVEC_CFLAGS) # TWIN_DEP_*FLAGS define all flags required by dependencies of libtwin -TWIN_DEP_LDFLAGS="$X_LIBS $PNG_LIBS $JPEG_LIBS -lm" +TWIN_DEP_LDFLAGS="$X_LIBS $PNG_LIBS $JPEG_LIBS $Z_LIBS -lm" TWIN_DEPCFLAGS="$X_CFLAGS $PNG_CFLAGS" AC_SUBST(TWIN_DEP_CFLAGS) AC_SUBST(TWIN_DEP_LDFLAGS) AM_CONDITIONAL(TWIN_X11, test x$twin_x11 = xyes) AM_CONDITIONAL(TWIN_FB, test x$twin_fb = xyes) +AM_CONDITIONAL(TWIN_ZLIB, test x$twin_zlib = xyes) AM_CONDITIONAL(TWIN_PNG, test x$twin_png = xyes) AM_CONDITIONAL(TWIN_JPEG, test x$twin_jpeg = xyes) AM_CONDITIONAL(TWIN_TTF, test x$twin_ttf = xyes) @@ -170,6 +189,7 @@ AM_CONDITIONAL(TWIN_MOUSE, test x$twin_mouse = xyes) AC_MSG_NOTICE([x11 support: $twin_x11]) AC_MSG_NOTICE([fbdev support: $twin_fb]) +AC_MSG_NOTICE([zlib support: $twin_zlib]) AC_MSG_NOTICE([png support: $twin_png]) AC_MSG_NOTICE([jpeg support: $twin_jpeg]) AC_MSG_NOTICE([twin_ttf tool: $twin_ttf]) diff --git a/libtwin/twin_cursor.c b/libtwin/twin_cursor.c index f0e5fc3..aa7c710 100644 --- a/libtwin/twin_cursor.c +++ b/libtwin/twin_cursor.c @@ -19,6 +19,8 @@ * Boston, MA 02111-1307, USA. */ +#include <twin_def.h> + #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -31,6 +33,23 @@ #include <byteswap.h> #include <endian.h> +#ifdef HAVE_ZLIB +#include <zlib.h> + +#define fdtype gzFile +#define cursor_open(file) gzopen(file, "rb") +#define cursor_read gzread +#define cursor_seek gzseek +#define cursor_close gzclose + +#else +#define fdtype int +#define cursor_open(file) open(file, O_RDONLY) +#define cursor_read read +#define cursor_seek lseek +#define cursor_close close +#endif + #include "twin.h" /* Make something better here ! */ @@ -138,11 +157,11 @@ twin_pixmap_t *twin_get_default_cursor(int *hx, int *hy) #define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5*4)) #define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */ -static inline int twin_read_header(int fd, uint32_t *buf, int size) +static inline int twin_read_header(fdtype fd, uint32_t *buf, int size) { int i, len; - len = read(fd, buf, size); + len = cursor_read(fd, buf, size); if (len != size) return 0; @@ -156,11 +175,12 @@ static inline int twin_read_header(int fd, uint32_t *buf, int size) twin_pixmap_t *twin_load_X_cursor(const char *file, int index, int *hx, int *hy) { - int fd, img, i, toccnt; + fdtype fd; + int img, i, toccnt; uint32_t buffer[32], filepos, size; twin_pixmap_t *cur = NULL; - fd = open(file, O_RDONLY); + fd = cursor_open(file); if (fd < 0) return NULL; if (!twin_read_header(fd, buffer, XCURSOR_FILE_HEADER_LEN)) @@ -178,7 +198,7 @@ twin_pixmap_t *twin_load_X_cursor(const char *file, int index, toccnt = buffer[3]; /* seek to first toc entry (header len) */ - lseek(fd, buffer[1] , SEEK_SET); + cursor_seek(fd, buffer[1] , SEEK_SET); /* look for the index'th image in TOC */ img = 0; @@ -197,7 +217,7 @@ twin_pixmap_t *twin_load_X_cursor(const char *file, int index, goto bail; /* seek to image header and read it */ - lseek(fd, filepos, SEEK_SET); + cursor_seek(fd, filepos, SEEK_SET); if (!twin_read_header(fd, buffer, XCURSOR_IMAGE_HEADER_LEN)) goto bail; @@ -220,8 +240,8 @@ twin_pixmap_t *twin_load_X_cursor(const char *file, int index, /* load pixels */ size = buffer[4] * buffer[5] * 4; - lseek(fd, filepos + buffer[0], SEEK_SET); - if (read(fd, cur->p.v, size) != size) { + cursor_seek(fd, filepos + buffer[0], SEEK_SET); + if (cursor_read(fd, cur->p.v, size) != size) { twin_pixmap_destroy(cur); goto bail; } @@ -232,7 +252,7 @@ twin_pixmap_t *twin_load_X_cursor(const char *file, int index, #endif bail: - close(fd); + cursor_close(fd); return cur; } |