summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerm <term@NOSPAM-THANKSusers.sourceforge.net>2000-12-28 06:45:14 +0000
committerTerm <term@NOSPAM-THANKSusers.sourceforge.net>2000-12-28 06:45:14 +0000
commit365f241ba0f4d85d6689e313e89e26eeb974c1dd (patch)
tree6212db95cb565c0a683311c2e655506b02ec6520
parenta8ccf132b8ee9eeb323f64b5841e4b1ff94c2caf (diff)
downloadimlib2-365f241ba0f4d85d6689e313e89e26eeb974c1dd.tar.gz
Added imconvert, which stems from a conversation with raster about
importing/exporting binary data (specifically imlib images from edb files, like the ebits files). This allows the user to export and import image data in and out of edb files, as well as arbitrary conversions to and from any format Imlib2 can handle. SVN revision: 4049
-rw-r--r--AUTHORS1
-rw-r--r--demo/Makefile.am4
-rw-r--r--demo/imconvert.c79
3 files changed, 82 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index 419a4f0..63b0698 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -16,3 +16,4 @@ Steve Langasek <vorlon@dodds.net>
Christophe Tronche <ch.tronche@computer.org>
Nathan Ingersoll <ningerso@d.umn.edu>
Masa(Masahiko) Mori <masa@engr.sgi.com>
+Term (Lyle Kempler) <term@kempler.net>
diff --git a/demo/Makefile.am b/demo/Makefile.am
index 3635d0d..7e1444e 100644
--- a/demo/Makefile.am
+++ b/demo/Makefile.am
@@ -11,7 +11,7 @@ INCLUDES = -I/usr/X11R6/include -I$(top_srcdir)/libltdl \
-I. -I$(top_srcdir) -I$(top_srcdir)/src \
-I$(top_srcdir)/loaders
-bin_PROGRAMS = imlib2_view
-imlib2_view_SOURCES = view.c
+bin_PROGRAMS = imlib2_view imconvert
+imlib2_view_SOURCES = view.c imconvert.c
imlib2_view_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
$(x_libs) -lttf -lImlib2
diff --git a/demo/imconvert.c b/demo/imconvert.c
new file mode 100644
index 0000000..848c37b
--- /dev/null
+++ b/demo/imconvert.c
@@ -0,0 +1,79 @@
+/* Convert images between formats, using Imlib2's API. Smart enough to know
+ * about edb files; defaults to jpg's.
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <X11/Xlib.h>
+#include <Imlib2.h>
+
+int
+main(int argc,
+ char **argv)
+{
+ char *dot, *colon, *n, *oldn;
+ Imlib_Image im;
+ int usage;
+
+ usage = 0;
+ /* I'm just plain being lazy here.. get our basename. */
+ for (oldn = n = argv[0]; n; oldn = n) n = strchr(++oldn, '/');
+ if (argc < 3 || !strcmp(argv[1], "-h")) usage = 1;
+ else im = imlib_load_image(argv[1]);
+ if (!usage && im)
+ {
+ /* we only care what format the export format is. */
+ imlib_context_set_image(im);
+ /* hopefully the last one will be the one we want.. */
+ dot = strrchr(argv[2], '.');
+ /* if there's a format, snarf it and set the format. */
+ if (dot && *(dot + 1))
+ {
+ colon = strrchr(++dot, ':');
+ /* if a db file with a key, export it to a db. */
+ if (colon && *(colon + 1))
+ {
+ *colon = 0;
+ /* beats having to look for strcasecmp() */
+ if (!strncmp(dot, "db", 2) || !strncmp(dot, "dB", 2) ||
+ !strncmp(dot, "DB", 2) || !strncmp(dot, "Db", 2))
+ {
+ imlib_image_set_format("db");
+ }
+ *colon = ':';
+ }
+ else
+ {
+ char *p, *q;
+
+ /* max length of 8 for format name. seems reasonable. */
+ q = p = malloc(8);
+ memset(p, 0, 8);
+ strncpy(p, dot, (strlen(dot) < 9) ? strlen(dot) : 8);
+ /* Imlib2 only recognizes lowercase formats. convert it. */
+ for (q[8] = 0; *q; q++) *q = tolower(*q);
+ imlib_image_set_format(p);
+ free(p);
+ }
+ dot--;
+ }
+ else imlib_image_set_format("jpg");
+ imlib_save_image(argv[2]);
+ }
+ else
+ {
+ /* usage stuff. */
+ fprintf(stderr, "%s: Convert images between formats (part of the " \
+ "Imlib2 package)\n\n" \
+ "Usage: %s [ -h | <image1> <image2[.fmt]> ]\n" \
+ " <fmt> defaults to jpg if not provided; images in " \
+ "edb files are supported via\n" \
+ " the file.db:/key/name convention.\n" \
+ " -h shows this help.\n\n", argv[0], argv[0]);
+ exit(-1);
+ }
+ return 0;
+}