diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-04 17:12:18 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-04 17:12:18 +0100 |
commit | 8413ae92969400c687e0dac404be0359bccc9aed (patch) | |
tree | a2d1a22ac53769efc6a39297d9b7d6f414e9d285 /src | |
download | yawa-8413ae92969400c687e0dac404be0359bccc9aed.tar.xz |
Import hsetroot-1.0.2.tar.gz
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/Makefile.in | 305 | ||||
-rw-r--r-- | src/hsetroot.c | 620 |
3 files changed, 932 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..c6a601c --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,7 @@ +bin_PROGRAMS = hsetroot + +AM_CFLAGS = @CFLAGS@ @IMLIB2_CFLAGS@ -Wall +LIBS = @IMLIB2_LIBS@ + +hsetroot_SOURCES = hsetroot.c + diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..52e75b3 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,305 @@ +# Makefile.in generated automatically by automake 1.5 from Makefile.am. + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +AMTAR = @AMTAR@ +AWK = @AWK@ +CC = @CC@ +DEPDIR = @DEPDIR@ +EXEEXT = @EXEEXT@ +IMLIB2_CFLAGS = @IMLIB2_CFLAGS@ +IMLIB2_LIBS = @IMLIB2_LIBS@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +MAINT = @MAINT@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ +am__include = @am__include@ +am__quote = @am__quote@ +imlib2config_cmd = @imlib2config_cmd@ +install_sh = @install_sh@ + +bin_PROGRAMS = hsetroot + +AM_CFLAGS = @CFLAGS@ @IMLIB2_CFLAGS@ -Wall +LIBS = @IMLIB2_LIBS@ + +hsetroot_SOURCES = hsetroot.c +subdir = src +mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config/config.h +CONFIG_CLEAN_FILES = +bin_PROGRAMS = hsetroot$(EXEEXT) +PROGRAMS = $(bin_PROGRAMS) + +am_hsetroot_OBJECTS = hsetroot.$(OBJEXT) +hsetroot_OBJECTS = $(am_hsetroot_OBJECTS) +hsetroot_LDADD = $(LDADD) +hsetroot_DEPENDENCIES = +hsetroot_LDFLAGS = + +DEFS = @DEFS@ +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +depcomp = $(SHELL) $(top_srcdir)/config/depcomp +@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/hsetroot.Po +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +CFLAGS = @CFLAGS@ +DIST_SOURCES = $(hsetroot_SOURCES) +DIST_COMMON = Makefile.am Makefile.in +SOURCES = $(hsetroot_SOURCES) + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && \ + CONFIG_HEADERS= CONFIG_LINKS= \ + CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(bindir) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + ; then \ + f=`echo $$p1|sed '$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ + rm -f $(DESTDIR)$(bindir)/$$f; \ + done + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) +hsetroot$(EXEEXT): $(hsetroot_OBJECTS) $(hsetroot_DEPENDENCIES) + @rm -f hsetroot$(EXEEXT) + $(LINK) $(hsetroot_LDFLAGS) $(hsetroot_OBJECTS) $(hsetroot_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) core *.core + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/hsetroot.Po@am__quote@ + +distclean-depend: + -rm -rf $(DEPDIR) + +.c.o: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `test -f $< || echo '$(srcdir)/'`$< + +.c.obj: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `cygpath -w $<` +CCDEPMODE = @CCDEPMODE@ +uninstall-info-am: + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || etags $(ETAGS_ARGS) $$tags $$unique $(LISP) + +GTAGS: + here=`CDPATH=: && cd $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH + +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + if test -f $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + $(mkinstalldirs) "$(distdir)/$$dir"; \ + fi; \ + if test -d $$d/$$file; then \ + cp -pR $$d/$$file $(distdir) \ + || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(bindir) + +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]* + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-compile distclean-depend \ + distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-binPROGRAMS + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +uninstall-am: uninstall-binPROGRAMS uninstall-info-am + +.PHONY: GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic distclean distclean-compile distclean-depend \ + distclean-generic distclean-tags distdir dvi dvi-am info \ + info-am install install-am install-binPROGRAMS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic tags uninstall uninstall-am \ + uninstall-binPROGRAMS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/hsetroot.c b/src/hsetroot.c new file mode 100644 index 0000000..9f0bdd1 --- /dev/null +++ b/src/hsetroot.c @@ -0,0 +1,620 @@ +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <Imlib2.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "config.h" + +typedef enum +{ Full, Fill, Center, Tile } ImageMode; + +void +usage (char *commandline) +{ + printf (PACKAGE_STRING " - " DESCRIPTION "\n" + "\n" + "Syntaxis: %s [command1 [arg1..]] [command2 [arg1..]]..." + "\n" + "Gradients:\n" + " -add <color> Add color to range using distance 1\n" + " -addd <color> <distance> Add color to range using custom distance\n" + " -gradient <angle> Render gradient using specified angle\n" + " -clear Clear the color range\n" + "\n" + "Solid:\n" + " -solid <color> Render a solid using the specified color\n" + "\n" + "Image files:\n" + " -center <image> Render an image centered on screen\n" + " -tile <image> Render an image tiled\n" + " -full <image> Render an image maximum aspect\n" + " -fill <image> Render an image strechted\n" + "\n" + "Manipulations:\n" + " -tint <color> Tint the current image\n" + " -blur <radius> Blur the current image\n" + " -sharpen <radius> Sharpen the current image\n" + " -contrast <amount> Adjust contrast of current image\n" + " -brightness <amount> Adjust brightness of current image\n" + " -gamma <amount> Adjust gamma level of current image\n" + " -flipv Flip the current image vertically\n" + " -fliph Flip the current image horizontally\n" + " -flipd Flip the current image diagonally\n" + "\n" + "Misc:\n" + " -alpha <amount> Adjust alpha level for colors and images\n" + " -write <filename> Write current image to file\n" + "\n" + "Colors are in the #rrbbgg or #rrggbbaa format.\n" + "\n" + "Send bugreports to: " PACKAGE_BUGREPORT "\n" "\n", commandline); +} + +// Globals: +Display *display; +int screen; + +// Adapted from fluxbox' bsetroot +int +setRootAtoms (Pixmap pixmap) +{ + Atom atom_root, atom_eroot, type; + unsigned char *data_root, *data_eroot; + int format; + unsigned long length, after; + + atom_root = XInternAtom (display, "_XROOTMAP_ID", True); + atom_eroot = XInternAtom (display, "ESETROOT_PMAP_ID", True); + + // doing this to clean up after old background + if (atom_root != None && atom_eroot != None) + { + XGetWindowProperty (display, RootWindow (display, screen), + atom_root, 0L, 1L, False, AnyPropertyType, + &type, &format, &length, &after, &data_root); + if (type == XA_PIXMAP) + { + XGetWindowProperty (display, RootWindow (display, screen), + atom_eroot, 0L, 1L, False, AnyPropertyType, + &type, &format, &length, &after, &data_eroot); + if (data_root && data_eroot && type == XA_PIXMAP && + *((Pixmap *) data_root) == *((Pixmap *) data_eroot)) + { + XKillClient (display, *((Pixmap *) data_root)); + } + } + } + + atom_root = XInternAtom (display, "_XROOTPMAP_ID", False); + atom_eroot = XInternAtom (display, "ESETROOT_PMAP_ID", False); + + if (atom_root == None || atom_eroot == None) + return 0; + + // setting new background atoms + XChangeProperty (display, RootWindow (display, screen), + atom_root, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *) &pixmap, 1); + XChangeProperty (display, RootWindow (display, screen), atom_eroot, + XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap, + 1); + + return 1; +} + +typedef struct +{ + int r, g, b, a; +} Color, *PColor; + +int +getHex (char c) +{ + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return c - '0'; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + return c - 'A' + 10; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return c - 'a' + 10; + default: + return 0; + } +} + +int +parse_color (char *arg, PColor c, int a) +{ + if (arg[0] != '#') + return 0; + + if ((strlen (arg) != 7) && (strlen (arg) != 9)) + return 0; + + c->r = getHex (arg[1]) * 16 + getHex (arg[2]); + c->g = getHex (arg[3]) * 16 + getHex (arg[4]); + c->b = getHex (arg[5]) * 16 + getHex (arg[6]); + c->a = a; + if (strlen (arg) == 9) + c->a = getHex (arg[7]) * 16 + getHex (arg[8]); + + return 1; +} + +int +load_image (ImageMode mode, const char *arg, int rootW, int rootH, int alpha, + Imlib_Image rootimg) +{ + int imgW, imgH, o; + Imlib_Image buffer = imlib_load_image (arg); + + if (!buffer) + return 0; + + imlib_context_set_image (buffer); + imgW = imlib_image_get_width (), imgH = imlib_image_get_height (); + + if (alpha < 255) + { + // Create alpha-override mask + imlib_image_set_has_alpha (1); + Imlib_Color_Modifier modifier = imlib_create_color_modifier (); + imlib_context_set_color_modifier (modifier); + + DATA8 red[256], green[256], blue[256], alph[256]; + imlib_get_color_modifier_tables (red, green, blue, alph); + for (o = 0; o < 256; o++) + alph[o] = (DATA8) alpha; + imlib_set_color_modifier_tables (red, green, blue, alph); + + imlib_apply_color_modifier (); + imlib_free_color_modifier (); + } + + imlib_context_set_image (rootimg); + if (mode == Fill) + { + imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, + 0, 0, rootW, rootH); + } + else if (mode == Full) + { + double aspect = ((double) rootW) / imgW; + int top, left; + if ((int) (imgH * aspect) > rootH) + aspect = (double) rootH / (double) imgH; + top = (rootH - (int) (imgH * aspect)) / 2; + left = (rootW - (int) (imgW * aspect)) / 2; + imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, + left, top, (int) (imgW * aspect), + (int) (imgH * aspect)); + } + else + { + int left = (rootW - imgW) / 2, top = (rootH - imgH) / 2; + + if (mode == Tile) + { + int x, y; + for (; left > 0; left -= imgW); + for (; top > 0; top -= imgH); + + for (x = left; x < rootW; x += imgW) + for (y = top; y < rootH; y += imgH) + imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, + x, y, imgW, imgH); + } + else + { + imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, + left, top, imgW, imgH); + } + } + + imlib_context_set_image (buffer); + imlib_free_image (); + + imlib_context_set_image (rootimg); + + return 1; +} + +int +main (int argc, char **argv) +{ + Visual *vis; + Colormap cm; + Display *_display; + Imlib_Context *context; + Imlib_Image image; + int width, height, depth, i, alpha; + Pixmap pixmap; + Imlib_Color_Modifier modifier = NULL; + _display = XOpenDisplay (NULL); + + for (screen = 0; screen < ScreenCount (_display); screen++) + { + display = XOpenDisplay (NULL); + + context = imlib_context_new (); + imlib_context_push (context); + + imlib_context_set_display (display); + vis = DefaultVisual (display, screen); + cm = DefaultColormap (display, screen); + width = DisplayWidth (display, screen); + height = DisplayHeight (display, screen); + depth = DefaultDepth (display, screen); + + pixmap = + XCreatePixmap (display, RootWindow (display, screen), width, height, + depth); + + imlib_context_set_visual (vis); + imlib_context_set_colormap (cm); + imlib_context_set_drawable (pixmap); + imlib_context_set_color_range (imlib_create_color_range ()); + + image = imlib_create_image (width, height); + imlib_context_set_image (image); + + imlib_context_set_color (0, 0, 0, 255); + imlib_image_fill_rectangle (0, 0, width, height); + + imlib_context_set_dither (1); + imlib_context_set_blend (1); + + alpha = 255; + + for (i = 1; i < argc; i++) + { + if (modifier != NULL) + { + imlib_apply_color_modifier (); + imlib_free_color_modifier (); + } + modifier = imlib_create_color_modifier (); + imlib_context_set_color_modifier (modifier); + + if (strcmp (argv[i], "-alpha") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing alpha\n"); + continue; + } + if (sscanf (argv[i], "%i", &alpha) == 0) + { + fprintf (stderr, "Bad alpha (%s)\n", argv[i]); + continue; + } + + } + else if (strcmp (argv[i], "-solid") == 0) + { + Color c; + if ((++i) >= argc) + { + fprintf (stderr, "Missing color\n"); + continue; + } + if (parse_color (argv[i], &c, alpha) == 0) + { + fprintf (stderr, "Bad color (%s)\n", argv[i]); + continue; + } + imlib_context_set_color (c.r, c.g, c.b, c.a); + imlib_image_fill_rectangle (0, 0, width, height); + } + else if (strcmp (argv[i], "-clear") == 0) + { + imlib_free_color_range (); + imlib_context_set_color_range (imlib_create_color_range ()); + } + else if (strcmp (argv[i], "-add") == 0) + { + Color c; + if ((++i) >= argc) + { + fprintf (stderr, "Missing color\n"); + continue; + } + if (parse_color (argv[i], &c, alpha) == 0) + { + fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); + continue; + } + imlib_context_set_color (c.r, c.g, c.b, c.a); + imlib_add_color_to_color_range (1); + } + else if (strcmp (argv[i], "-addd") == 0) + { + Color c; + int distance; + if ((++i) >= argc) + { + fprintf (stderr, "Missing color\n"); + continue; + } + if ((++i) >= argc) + { + fprintf (stderr, "Missing distance\n"); + continue; + } + if (parse_color (argv[i - 1], &c, alpha) == 0) + { + fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); + continue; + } + if (sscanf (argv[i], "%i", &distance) == 0) + { + fprintf (stderr, "Bad distance (%s)\n", argv[i]); + continue; + } + imlib_context_set_color (c.r, c.g, c.b, c.a); + imlib_add_color_to_color_range (distance); + } + else if (strcmp (argv[i], "-gradient") == 0) + { + int angle; + if ((++i) >= argc) + { + fprintf (stderr, "Missing angle\n"); + continue; + } + if (sscanf (argv[i], "%i", &angle) == 0) + { + fprintf (stderr, "Bad angle (%s)\n", argv[i]); + continue; + } + imlib_image_fill_color_range_rectangle (0, 0, width, height, + angle); + } + else if (strcmp (argv[i], "-fill") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing image\n"); + continue; + } + if (load_image (Fill, argv[i], width, height, alpha, image) == + 0) + { + fprintf (stderr, "Bad image (%s)\n", argv[i]); + continue; + } + } + else if (strcmp (argv[i], "-full") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing image\n"); + continue; + } + if (load_image (Full, argv[i], width, height, alpha, image) == + 0) + { + fprintf (stderr, "Bad image (%s)\n", argv[i]); + continue; + } + } + else if (strcmp (argv[i], "-tile") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing image\n"); + continue; + } + if (load_image (Tile, argv[i], width, height, alpha, image) == + 0) + { + fprintf (stderr, "Bad image (%s)\n", argv[i]); + continue; + } + } + else if (strcmp (argv[i], "-center") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing image\n"); + continue; + } + if (load_image (Center, argv[i], width, height, alpha, image) == + 0) + { + fprintf (stderr, "Bad image (%s)\n", argv[i]); + continue; + } + } + else if (strcmp (argv[i], "-tint") == 0) + { + Color c; + DATA8 r[256], g[256], b[256], a[256]; + int j; + + if ((++i) >= argc) + { + fprintf (stderr, "Missing color\n"); + continue; + } + if (parse_color (argv[i], &c, 255) == 0) + { + fprintf (stderr, "Bad color\n"); + continue; + } + + imlib_get_color_modifier_tables (r, g, b, a); + + for (j = 0; j < 256; j++) + { + r[j] = (DATA8) (((double) r[j] / 255.0) * (double) c.r); + g[j] = (DATA8) (((double) g[j] / 255.0) * (double) c.g); + b[j] = (DATA8) (((double) b[j] / 255.0) * (double) c.b); + } + + imlib_set_color_modifier_tables (r, g, b, a); + } + else if (strcmp (argv[i], "-blur") == 0) + { + int intval; + if ((++i) >= argc) + { + fprintf (stderr, "Missing value\n"); + continue; + } + if (sscanf (argv[i], "%i", &intval) == 0) + { + fprintf (stderr, "Bad value (%s)\n", argv[i]); + continue; + } + imlib_image_blur (intval); + } + else if (strcmp (argv[i], "-sharpen") == 0) + { + int intval; + if ((++i) >= argc) + { + fprintf (stderr, "Missing value\n"); + continue; + } + if (sscanf (argv[i], "%i", &intval) == 0) + { + fprintf (stderr, "Bad value (%s)\n", argv[i]); + continue; + } + imlib_image_sharpen (intval); + } + else if (strcmp (argv[i], "-contrast") == 0) + { + double dblval; + if ((++i) >= argc) + { + fprintf (stderr, "Missing value\n"); + continue; + } + if (sscanf (argv[i], "%lf", &dblval) == 0) + { + fprintf (stderr, "Bad value (%s)\n", argv[i]); + continue; + } + imlib_modify_color_modifier_contrast (dblval); + } + else if (strcmp (argv[i], "-brightness") == 0) + { + double dblval; + if ((++i) >= argc) + { + fprintf (stderr, "Missing value\n"); + continue; + } + if (sscanf (argv[i], "%lf", &dblval) == 0) + { + fprintf (stderr, "Bad value (%s)\n", argv[i]); + continue; + } + imlib_modify_color_modifier_brightness (dblval); + } + else if (strcmp (argv[i], "-gamma") == 0) + { + double dblval; + if ((++i) >= argc) + { + fprintf (stderr, "Missing value\n"); + continue; + } + if (sscanf (argv[i], "%lf", &dblval) == 0) + { + fprintf (stderr, "Bad value (%s)\n", argv[i]); + continue; + } + imlib_modify_color_modifier_gamma (dblval); + } + else if (strcmp (argv[i], "-flipv") == 0) + { + imlib_image_flip_vertical (); + } + else if (strcmp (argv[i], "-fliph") == 0) + { + imlib_image_flip_horizontal (); + } + else if (strcmp (argv[i], "-flipd") == 0) + { + imlib_image_flip_diagonal (); + } + else if (strcmp (argv[i], "-write") == 0) + { + if ((++i) >= argc) + { + fprintf (stderr, "Missing filename\n"); + continue; + } + imlib_save_image (argv[i]); + } + else + { + usage (argv[0]); + imlib_free_image (); + imlib_free_color_range (); + if (modifier != NULL) + { + imlib_context_set_color_modifier (modifier); + imlib_free_color_modifier (); + modifier = NULL; + } + XFreePixmap (display, pixmap); + exit (1); + } + } + + if (modifier != NULL) + { + imlib_context_set_color_modifier (modifier); + imlib_apply_color_modifier (); + imlib_free_color_modifier (); + modifier = NULL; + } + imlib_render_image_on_drawable (0, 0); + imlib_free_image (); + imlib_free_color_range (); + + if (setRootAtoms (pixmap) == 0) + fprintf (stderr, "Couldn't create atoms...\n"); + + XKillClient (display, AllTemporary); + XSetCloseDownMode (display, RetainTemporary); + + XSetWindowBackgroundPixmap (display, RootWindow (display, screen), + pixmap); + XClearWindow (display, RootWindow (display, screen)); + + XFlush (display); + XSync (display, False); + + imlib_context_pop (); + imlib_context_free (context); + } + + return 0; +} |