parent
5784c387ec
commit
2c293b0a30
|
@ -21,8 +21,6 @@ LT_INIT
|
|||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
ani=yes
|
||||
|
||||
eet=no
|
||||
AC_ARG_ENABLE(eet,
|
||||
[ --enable-eet enable building the eet loader],
|
||||
|
@ -59,7 +57,6 @@ elif test "x$found_eet" = "xno" ; then
|
|||
eet=no
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_ANI_LOADER, test x$ani != xno)
|
||||
AM_CONDITIONAL(BUILD_EET_LOADER, test x$eet != xno)
|
||||
AM_CONDITIONAL(BUILD_XCF_LOADER, test x$xcf != xno)
|
||||
|
||||
|
@ -89,7 +86,6 @@ echo
|
|||
echo "Configuration Options Summary:"
|
||||
echo
|
||||
echo "Image loaders:"
|
||||
echo " ANI.....................: $ani"
|
||||
echo " EET.....................: $eet"
|
||||
echo " XCF.....................: $xcf"
|
||||
echo
|
||||
|
|
|
@ -4,9 +4,6 @@ AM_CFLAGS = $(CFLAGS_WARNINGS) $(CFLAGS_VISIBILITY)
|
|||
|
||||
pkgdir = $(libdir)/imlib2/loaders
|
||||
|
||||
if BUILD_ANI_LOADER
|
||||
ANI_L = ani.la
|
||||
endif
|
||||
if BUILD_EET_LOADER
|
||||
EET_L = eet.la
|
||||
endif
|
||||
|
@ -15,7 +12,6 @@ XCF_L = xcf.la
|
|||
endif
|
||||
|
||||
pkg_LTLIBRARIES = \
|
||||
$(ANI_L) \
|
||||
$(EET_L) \
|
||||
$(XCF_L)
|
||||
|
||||
|
@ -29,8 +25,3 @@ xcf_la_SOURCES = loader_xcf.c loader_xcf_pixelfuncs.c loader_xcf.h
|
|||
xcf_la_LDFLAGS = -module -avoid-version
|
||||
xcf_la_LIBADD =
|
||||
xcf_la_LIBTOOLFLAGS = --tag=disable-static
|
||||
|
||||
ani_la_SOURCES = loader_ani.c
|
||||
ani_la_LDFLAGS = -module -avoid-version
|
||||
ani_la_LIBADD =
|
||||
ani_la_LIBTOOLFLAGS = --tag=disable-static
|
||||
|
|
|
@ -1,264 +0,0 @@
|
|||
/*
|
||||
|
||||
Copyright (C) 2002 Christian Kreibich <cK@whoop.org>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies of the Software and its documentation and acknowledgment shall be
|
||||
given in the documentation and software packages that this Software was
|
||||
used.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
#include "Imlib2_Loader.h"
|
||||
|
||||
static const char *const _formats[] = { "ani" };
|
||||
|
||||
#define ANI_DBG 0
|
||||
#if ANI_DBG
|
||||
#define D(fmt...) printf("Imlib2 ANI loader: " fmt)
|
||||
#else
|
||||
#define D(fmt...)
|
||||
#endif
|
||||
|
||||
typedef struct _MsChunk {
|
||||
struct _MsChunk *next;
|
||||
uint32_t chunk_id;
|
||||
uint32_t chunk_size; /* Size of this chunk, starting from */
|
||||
uint8_t data; /* the following byte. Thus chunk_size = full size - 8 */
|
||||
} MsChunk;
|
||||
|
||||
typedef struct _MsAni {
|
||||
FILE *fp;
|
||||
uint32_t cp;
|
||||
|
||||
uint32_t riff_id; /* "RIFF" */
|
||||
uint32_t data_size;
|
||||
uint32_t chunk_id; /* "ACON" */
|
||||
|
||||
MsChunk *chunks;
|
||||
} MsAni;
|
||||
|
||||
static void ani_cleanup(MsAni * ani);
|
||||
|
||||
static int
|
||||
ani_read_int8(FILE * fp, uint8_t * data, int count)
|
||||
{
|
||||
int total;
|
||||
int bytes;
|
||||
|
||||
total = count;
|
||||
while (count > 0)
|
||||
{
|
||||
bytes = fread(data, 1, count, fp);
|
||||
if (bytes <= 0) /* something bad happened */
|
||||
break;
|
||||
count -= bytes;
|
||||
data += bytes;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
static int
|
||||
ani_read_int32(FILE * fp, uint32_t * data, int count)
|
||||
{
|
||||
int i, total;
|
||||
|
||||
total = count;
|
||||
if (count > 0)
|
||||
{
|
||||
ani_read_int8(fp, (uint8_t *) data, count * 4);
|
||||
for (i = 0; i < count; i++)
|
||||
data[i] = SWAP_LE_32(data[i]);
|
||||
}
|
||||
|
||||
return total * 4;
|
||||
}
|
||||
|
||||
static MsAni *
|
||||
ani_init(FILE * fp)
|
||||
{
|
||||
MsAni *ani;
|
||||
|
||||
if (!(ani = calloc(1, sizeof(MsAni))))
|
||||
return NULL;
|
||||
|
||||
ani->fp = fp;
|
||||
|
||||
ani->cp += ani_read_int32(ani->fp, &ani->riff_id, 1);
|
||||
ani->cp += ani_read_int32(ani->fp, &ani->data_size, 1);
|
||||
ani->cp += ani_read_int32(ani->fp, &ani->chunk_id, 1);
|
||||
|
||||
if (ani->riff_id != 0x46464952 || ani->chunk_id != 0x4E4F4341)
|
||||
goto bail;
|
||||
|
||||
return ani;
|
||||
|
||||
bail:
|
||||
ani_cleanup(ani);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
ani_cleanup(MsAni * ani)
|
||||
{
|
||||
MsChunk *c, *c_next;
|
||||
|
||||
D("Cleaning up\n");
|
||||
|
||||
if (!ani)
|
||||
return;
|
||||
|
||||
for (c = ani->chunks; c;)
|
||||
{
|
||||
c_next = c->next;
|
||||
free(c);
|
||||
c = c_next;
|
||||
}
|
||||
|
||||
free(ani);
|
||||
}
|
||||
|
||||
static MsChunk *
|
||||
ani_load_chunk(MsAni * ani)
|
||||
{
|
||||
uint32_t chunk_id, chunk_size, dummy;
|
||||
MsChunk *chunk;
|
||||
|
||||
if (ani->cp >= ani->data_size + 8)
|
||||
return NULL;
|
||||
|
||||
ani->cp += ani_read_int32(ani->fp, &chunk_id, 1);
|
||||
|
||||
while (chunk_id == 0x5453494C)
|
||||
{
|
||||
D("Skipping LIST chunk header ...\n");
|
||||
ani->cp += ani_read_int32(ani->fp, &dummy, 1);
|
||||
ani->cp += ani_read_int32(ani->fp, &dummy, 1);
|
||||
ani->cp += ani_read_int32(ani->fp, &chunk_id, 1);
|
||||
}
|
||||
|
||||
ani->cp += ani_read_int32(ani->fp, &chunk_size, 1);
|
||||
|
||||
/* Pad it up to word length */
|
||||
if (chunk_size % 2)
|
||||
chunk_size += (2 - (chunk_size % 2));
|
||||
|
||||
chunk = calloc(1, sizeof(MsChunk *) + 2 * sizeof(uint32_t) + chunk_size);
|
||||
if (!chunk)
|
||||
{
|
||||
D("Warning, failed to allocate ANI chunk of size %ld\n",
|
||||
sizeof(MsChunk *) + 2 * sizeof(uint32_t) + chunk_size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
chunk->chunk_id = chunk_id;
|
||||
chunk->chunk_size = chunk_size;
|
||||
|
||||
chunk_id = SWAP_LE_32(chunk_id);
|
||||
|
||||
D("Loaded chunk with ID '%c%c%c%c' and length %i\n",
|
||||
((char *)&chunk_id)[0], ((char *)&chunk_id)[1],
|
||||
((char *)&chunk_id)[2], ((char *)&chunk_id)[3], chunk_size);
|
||||
|
||||
ani->cp += ani_read_int8(ani->fp, &chunk->data, chunk_size);
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
static void
|
||||
ani_load(MsAni * ani)
|
||||
{
|
||||
MsChunk *last_chunk;
|
||||
MsChunk *chunk;
|
||||
|
||||
if (!ani)
|
||||
return;
|
||||
|
||||
ani->chunks = ani_load_chunk(ani);
|
||||
last_chunk = ani->chunks;
|
||||
if (!last_chunk)
|
||||
return;
|
||||
|
||||
while ((chunk = ani_load_chunk(ani)))
|
||||
{
|
||||
last_chunk->next = chunk;
|
||||
last_chunk = chunk;
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
ani_save_ico(MsChunk * chunk)
|
||||
{
|
||||
char tmp[] = "/tmp/imlib2_loader_ani-XXXXXX";
|
||||
int fd;
|
||||
|
||||
fd = mkstemp(tmp);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
write(fd, &chunk->data, chunk->chunk_size);
|
||||
close(fd);
|
||||
|
||||
return strdup(tmp);
|
||||
}
|
||||
|
||||
static int
|
||||
_load(ImlibImage * im, int load_data)
|
||||
{
|
||||
int rc;
|
||||
ImlibLoader *loader;
|
||||
MsAni *ani = NULL;
|
||||
MsChunk *chunk;
|
||||
|
||||
if (!im->fi->fp)
|
||||
return LOAD_FAIL;
|
||||
|
||||
loader = __imlib_FindBestLoader(NULL, "ico", 0);
|
||||
if (!loader)
|
||||
return LOAD_FAIL;
|
||||
|
||||
ani = ani_init(im->fi->fp);
|
||||
if (!ani)
|
||||
return LOAD_FAIL;
|
||||
|
||||
ani_load(ani);
|
||||
|
||||
rc = LOAD_FAIL;
|
||||
|
||||
for (chunk = ani->chunks; chunk; chunk = chunk->next)
|
||||
{
|
||||
if (chunk->chunk_id == 0x6E6F6369)
|
||||
{
|
||||
char *tmpfile;
|
||||
|
||||
if (!(tmpfile = ani_save_ico(chunk)))
|
||||
break;
|
||||
|
||||
rc = __imlib_LoadEmbedded(loader, im, tmpfile, load_data);
|
||||
|
||||
unlink(tmpfile);
|
||||
free(tmpfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ani_cleanup(ani);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
IMLIB_LOADER(_formats, _load, NULL);
|
Loading…
Reference in New Issue