diff --git a/AUTHORS b/AUTHORS index 8252548..29fd645 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,3 +2,5 @@ XCF loader: Christian Kreibich , based on code from the Gimp (www.gimp.org). +DB loader: The rasterman , packaged by + Tom Gilbert diff --git a/COPYING.loader_db b/COPYING.loader_db new file mode 100644 index 0000000..0b959c1 --- /dev/null +++ b/COPYING.loader_db @@ -0,0 +1,20 @@ +Copyright (C) 1999 Carsten Haitzler and various contributors + +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, its documentation and marketing & publicity +materials, and acknowledgment shall be given in the documentation, materials +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. diff --git a/COPYING b/COPYING.loader_xcf similarity index 100% rename from COPYING rename to COPYING.loader_xcf diff --git a/autogen.sh b/autogen.sh index 5cec221..bc701e6 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,10 +1,5 @@ #! /bin/sh -if [ "$USER" = "root" ]; then - echo "You cannot do this as "$USER" please use a normal user account" - exit -fi - echo echo echo "NOTE:" @@ -19,7 +14,6 @@ THEDIR="`pwd`" cd "$srcdir" DIE=0 -set -x autoheader libtoolize --ltdl --force --copy aclocal diff --git a/config.h.in b/config.h.in index b4676c2..cfa8a6b 100644 --- a/config.h.in +++ b/config.h.in @@ -1,14 +1,7 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ +/* config.h.in. Generated automatically from configure.ac by autoheader. */ -/* Define to empty if the keyword does not work. */ -#undef const - -/* Define if your processor stores words with the most significant - byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN - -/* Define if the X Window System is missing or not being used. */ -#undef X_DISPLAY_MISSING +/* Define if you have the header file. */ +#undef HAVE_DLFCN_H /* Name of package */ #undef PACKAGE @@ -16,3 +9,12 @@ /* Version number of package */ #undef VERSION +/* Define if your processor stores words with the most significant byte first + (like Motorola and SPARC, unlike Intel and VAX). */ +#undef WORDS_BIGENDIAN + +/* Define if the X Window System is missing or not being used. */ +#undef X_DISPLAY_MISSING + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..ad23843 --- /dev/null +++ b/configure.ac @@ -0,0 +1,56 @@ +dnl Process this file with autoconf to create configure. + +AC_INIT +AC_CONFIG_SRCDIR([src/loader_xcf.c]) +AM_INIT_AUTOMAKE(imlib2_loaders, 0.0.1) +AM_CONFIG_HEADER(config.h) + +AC_C_BIGENDIAN + +AC_PROG_CC +AM_PROG_CC_STDC +AC_C_CONST + +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AM_PROG_LIBTOOL + +AC_PATH_X +AC_PATH_XTRA + +dnl Check for Imlib2.h +AC_CHECK_HEADER(Imlib2.h, , AC_MSG_ERROR([Imlib2.h not found.])) + +# Test for libedb +AC_CHECK_LIB(edb, e_db_open, + edb_ok=yes, + edb_ok=no + AC_MSG_WARN(*** Native EDB support will not be built (EDB library not found) ***), $EXTRA_LIBS -lz) +if test "$edb_ok" = yes; then + AC_MSG_CHECKING([for Edb.h]) + AC_TRY_CPP( + [#include + #undef PACKAGE + #undef VERSION + #include ], + edb_ok=yes, + edb_ok=no) + AC_MSG_RESULT($edb_ok) + if test "$edb_ok" = yes; then + EDBLIBS="-ledb" + else + AC_MSG_WARN(*** Native EDB support will not be built (EDB header file not found) ***) + fi +fi + +AM_CONDITIONAL(EDB_LOADER, test "$edb_ok" = yes) + +AC_SUBST(EDBLIBS) + +AC_CONFIG_FILES([ +Makefile +src/Makefile +debian/Makefile +imlib2_loaders.spec +]) +AC_OUTPUT diff --git a/configure.in b/configure.in index 147855e..58fd068 100644 --- a/configure.in +++ b/configure.in @@ -20,6 +20,32 @@ AC_PATH_XTRA dnl Check for Imlib2.h AC_CHECK_HEADER(Imlib2.h, , AC_MSG_ERROR([Imlib2.h not found.])) +# Test for libedb +AC_CHECK_LIB(edb, e_db_open, + edb_ok=yes, + edb_ok=no + AC_MSG_WARN(*** Native EDB support will not be built (EDB library not found) ***), $EXTRA_LIBS -lz) +if test "$edb_ok" = yes; then + AC_MSG_CHECKING([for Edb.h]) + AC_TRY_CPP( + [#include + #undef PACKAGE + #undef VERSION + #include ], + edb_ok=yes, + edb_ok=no) + AC_MSG_RESULT($edb_ok) + if test "$edb_ok" = yes; then + EDBLIBS="-ledb" + else + AC_MSG_WARN(*** Native EDB support will not be built (EDB header file not found) ***) + fi +fi + +AM_CONDITIONAL(EDB_LOADER, test "$edb_ok" = yes) + +AC_SUBST(EDBLIBS) + AC_OUTPUT([ Makefile src/Makefile diff --git a/imlib2_loaders.spec.in b/imlib2_loaders.spec.in index 11e865b..44a72b2 100644 --- a/imlib2_loaders.spec.in +++ b/imlib2_loaders.spec.in @@ -13,7 +13,7 @@ Source: ftp://ftp.enlightenment.org/enlightenment/e17/libs/%{name}-%{ver}.tar.gz BuildRoot: %{_tmppath}/%{name}-root Packager: Mark Bainter URL: http://www.rasterman.com/raster/imlib.html -Requires: imlib2 +Requires: imlib2 edb Prefix: %{prefix} %description @@ -30,10 +30,6 @@ distributed with Imlib2 directly. if [ -f configure ]; then ./configure --prefix=%{prefix} else - # can't build as root? gah. ;) - sed autogen.sh1 - mv -f autogen.sh1 autogen.sh - chmod 0700 autogen.sh ./autogen.sh --prefix=%{prefix} fi @@ -59,6 +55,8 @@ rm -rf $RPM_BUILD_ROOT %attr(755,root,root) %{prefix}/lib/loaders/image/* %changelog +* Sun Aug 21 2001 Tom Gilbert +- Added db loader. * Wed Jul 04 2001 Mark Bainter - Corrected ftp location. * Wed Jun 28 2001 Mark Bainter diff --git a/src/Makefile.am b/src/Makefile.am index ce8c32d..3f55902 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,10 +5,15 @@ AUTOMAKE_OPTIONS = 1.4 foreign # A list of all the files in the current directory which can be regenerated MAINTAINERCLEANFILES = Makefile.in Makefile -INCLUDES = $(X_CFLAGS) -W -Wall +INCLUDES = -I.. $(X_CFLAGS) -W -Wall pkgdir = $(libdir)/loaders/image -pkg_LTLIBRARIES = xcf.la + +if EDB_LOADER +EDB_L = db.la +endif + +pkg_LTLIBRARIES = xcf.la $(EDB_L) xcf_la_SOURCES = \ loader_xcf.c \ @@ -18,3 +23,10 @@ xcf_la_SOURCES = \ color_values.h xcf_la_LDFLAGS = -no-undefined -module -avoid-version xcf_la_LIBADD = + +db_la_SOURCES = \ + loader_db.c \ + common.h \ + image.h +db_la_LDFLAGS = -no-undefined -module -avoid-version +db_la_LIBADD = -ledb diff --git a/src/loader_db.c b/src/loader_db.c new file mode 100644 index 0000000..fd44f3e --- /dev/null +++ b/src/loader_db.c @@ -0,0 +1,403 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "common.h" +#include +#include +#include +#include +#include "image.h" + +char load (ImlibImage *im, ImlibProgressFunction progress, + char progress_granularity, char immediate_load); +char save (ImlibImage *im, ImlibProgressFunction progress, + char progress_granularity); +void formats (ImlibLoader *l); + +#define SWAP32(x) (x) = \ +((((x) & 0x000000ff ) << 24) |\ + (((x) & 0x0000ff00 ) << 8) |\ + (((x) & 0x00ff0000 ) >> 8) |\ + (((x) & 0xff000000 ) >> 24)) +#include +#include +#include +#include +#include +#include +#include + +static int +permissions(char *file) +{ + struct stat st; + + if (stat(file, &st) < 0) + return 0; + return st.st_mode; +} + +static int +exists(char *file) +{ + struct stat st; + + if (stat(file, &st) < 0) + return 0; + return 1; +} + +static int +can_read(char *file) +{ +#ifndef __EMX__ + if (!(permissions(file) & (S_IRUSR | S_IRGRP | S_IROTH))) +#else + if (!(permissions(file))) +#endif + return 0; + return (1 + access(file, R_OK)); +} + +static int +can_write(char *file) +{ +#ifndef __EMX__ + if (!(permissions(file) & (S_IWUSR | S_IWGRP | S_IWOTH))) +#else + if (!(permissions(file))) +#endif + return 0; + return (1 + access(file, W_OK)); +} + +char +load (ImlibImage *im, ImlibProgressFunction progress, + char progress_granularity, char immediate_load) +{ + int w, h, alpha, compression, size; + E_DB_File *db; + char file[4096], key[4096]; + DATA32 *ret; + DATA32 *body; + if (im->data) + return 0; + if ((!im->file) || (!im->real_file) || (!im->key)) + return 0; + strcpy(file, im->real_file); + strcpy(key, im->key); + if (!can_read(file)) return 0; + db = e_db_open_read(file); + if (!db) + return 0; + ret = e_db_data_get(db, key, &size); + if (!ret) + { + e_db_close(db); + return 0; + } + /* header */ + { + DATA32 header[8]; + + if (size < 32) + { + free(ret); + e_db_close(db); + return 0; + } + memcpy(header, ret, 32); +#ifdef WORDS_BIGENDIAN + { + int i; + for (i = 0; i < 8; i++) + SWAP32(header[i]); + } +#endif + if (header[0] != 0xac1dfeed) + { + free(ret); + e_db_close(db); + return 0; + } + w = header[1]; + h = header[2]; + alpha = header[3]; + compression = header[4]; + if ((w > 8192) || (h > 8192)) + { + free(ret); + e_db_close(db); + return 0; + } + if ((compression == 0) && (size < ((w * h * 4) + 32))) + { + free(ret); + e_db_close(db); + return 0; + } + im->w = w; + im->h = h; + if (!im->format) + { + if (alpha) + SET_FLAG(im->flags, F_HAS_ALPHA); + else + UNSET_FLAG(im->flags, F_HAS_ALPHA); + im->format = strdup("db"); + } + } + if (((!im->data) && (im->loader)) || (immediate_load) || (progress)) + { + DATA32 *ptr; + int y, pl = 0; + char pper = 0; + + body = &(ret[8]); + /* must set the im->data member before callign progress function */ + if (!compression) + { + if (progress) + { + char per; + int l; + + ptr = im->data = malloc(w * h * sizeof(DATA32)); + if (!im->data) + { + free(ret); + e_db_close(db); + return 0; + } + for (y = 0; y < h; y++) + { +#ifdef WORDS_BIGENDIAN + { + int x; + + memcpy(ptr, &(body[y * w]), im->w * sizeof(DATA32)); + for (x = 0; x < im->w; x++) + SWAP32(ptr[x]); + } +#else + memcpy(ptr, &(body[y * w]), im->w * sizeof(DATA32)); +#endif + ptr += im->w; + + per = (char)((100 * y) / im->h); + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) + { + l = y - pl; + if(!progress(im, per, 0, (y - l), im->w, l)) + { + free(ret); + e_db_close(db); + return 2; + } + pper = per; + pl = y; + } + } + } + else + { + ptr = im->data = malloc(w * h * sizeof(DATA32)); + if (!im->data) + { + free(ret); + e_db_close(db); + return 0; + } +#ifdef WORDS_BIGENDIAN + { + int x; + + memcpy(ptr, body, im->w * im->h * sizeof(DATA32)); + for (x = 0; x < (im->w * im->h); x++) + SWAP32(ptr[x]); + } +#else + memcpy(ptr, body, im->w * im->h * sizeof(DATA32)); +#endif + } + } + else + { + uLongf dlen; + + dlen = w * h * sizeof(DATA32); + im->data = malloc(w * h * sizeof(DATA32)); + if (!im->data) + { + free(ret); + e_db_close(db); + return 0; + } + uncompress((Bytef *)im->data, &dlen, (Bytef *)body, (uLongf)(size - 32)); +#ifdef WORDS_BIGENDIAN + { + int x; + + for (x = 0; x < (im->w * im->h); x++) + SWAP32(im->data[x]); + } +#endif + if (progress) + progress(im, 100, 0, 0, im->w, im->h); + } + } + free(ret); + e_db_close(db); + return 1; +} + +char +save (ImlibImage *im, ImlibProgressFunction progress, + char progress_granularity) +{ + int alpha = 0; + char file[4096], key[4096], *tmp; + DATA32 *header; + DATA32 *buf; + E_DB_File *db; + int compression = 0, size = 0; + DATA32 *ret; + + + /* no image data? abort */ + if (!im->data) + return 0; + if (im->flags & F_HAS_ALPHA) + alpha = 1; + if ((!im->file) || (!im->real_file)) + return 0; + strcpy(file, im->real_file); + + tmp = strrchr(file, ':'); + if(!tmp) + return 0; + *tmp++ = '\0'; + if(!*tmp) + return 0; + strcpy(key, tmp); + + if (exists(file)) + { + if (!can_write(file)) return 0; + if (!can_read(file)) return 0; + } + db = e_db_open(file); + if (!db) + return 0; + + /* account for space for compression */ + buf = (DATA32 *) malloc((((im->w * im->h * 101) / 100) + 3 + 8) * sizeof(DATA32)); + header = buf; + header[0] = 0xac1dfeed; + header[1] = im->w; + header[2] = im->h; + header[3] = alpha; + { + ImlibImageTag *tag; + + tag = __imlib_GetTag(im, "compression"); + if (!tag) + header[4] = 0; + else + { + compression = tag->val; + if (compression < 0) + compression = 0; + else if (compression > 9) + compression = 9; + header[4] = compression; + } + } + if (compression > 0) + { + DATA32 *compressed; + int retr; + uLongf buflen; + + compressed = &(buf[8]); + buflen = ((im->w * im->h * sizeof(DATA32) * 101) / 100) + 12; +#ifdef WORDS_BIGENDIAN + { + DATA32 *buf2; + + buf2 = malloc((((im->w * im->h * 101) / 100) + 3) * sizeof(DATA32)); + if (buf2) + { + int y; + + memcpy(buf2, im->data, im->w * im->h * sizeof(DATA32)); + for (y = 0; y < (im->w * im->h) + 8; y++) + SWAP32(buf2[y]); + retr = compress2((Bytef *)compressed, &buflen, + (Bytef *)buf2, + (uLong)(im->w * im->h * sizeof(DATA32)), + compression); + free(buf2); + } + else + retr = Z_MEM_ERROR; + } +#else + retr = compress2((Bytef *)compressed, &buflen, + (Bytef *)im->data, + (uLong)(im->w * im->h * sizeof(DATA32)), + compression); +#endif + if (retr != Z_OK) + compressed = 0; + else + { + if (buflen >= (im->w * im->h * sizeof(DATA32))) + compressed = 0; + else + size = (8 * sizeof(DATA32)) + buflen; + } + } + else + { + memcpy(&(buf[8]), im->data, im->w * im->h * sizeof(DATA32)); + header[4] = compression; +#ifdef WORDS_BIGENDIAN + { + int y; + + for (y = 0; y < (im->w * im->h) + 8; y++) + SWAP32(buf[y]); + } +#endif + size = ((im->w * im->h) + 8) * sizeof(DATA32); + } + ret = buf; + e_db_data_set(db, key, ret, size); + free(buf); + if (progress) + progress(im, 100, 0, 0, im->w, im->h); + /* finish off */ + e_db_close(db); + return 1; + progress_granularity = 0; +} + +void +formats (ImlibLoader *l) +{ + char *list_formats[] = + { "db" }; + + { + int i; + + l->num_formats = (sizeof(list_formats) / sizeof (char *)); + l->formats = malloc(sizeof(char *) * l->num_formats); + for (i = 0; i < l->num_formats; i++) + l->formats[i] = strdup(list_formats[i]); + } +} +